{"version":3,"file":"pfe-readtime.min.js","sources":["../_temp/pfe-readtime.js"],"sourcesContent":["/*!\n * PatternFly Elements: PfeReadtime 1.12.3\n * @license\n * Copyright 2021 Red Hat, Inc.\n * \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n * \n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n * \n*/\n\nimport PFElement from \"../../pfelement/dist/pfelement.js\";\n\nfunction getEstimatedWPM(language) {\n switch (language) {\n case \"en\": // 228 wpm\n case \"ko\": // for Korean, we were able to locate 7 studies in five articles: 5 with silent reading and 2 with reading aloud. Silent reading rate was 226 wpm, reading aloud 133 wpm.\n return 228;\n case \"zh\": // 158 wpm\n return 158;\n case \"fr\": // 195 wpm\n return 195;\n case \"ja\": // 193 wpm\n return 193;\n case \"de\":\n return 179;\n case \"it\": // 188 wpm\n return 188;\n case \"pt-br\": // 181 wpm\n return 181;\n case \"es\":\n return 218;\n default:\n return 228;\n }\n}\n\nclass PfeReadtime extends PFElement {\n\n // Injected at build-time\n static get version() {\n return \"1.12.3\";\n }\n\n // Injected at build-time\n get html() {\n return `\n<style>:host{font-size:1rem;font-size:var(--pfe-readtime--FontSize,var(--pf-global--FontSize--md,1rem))}:host([hidden]){display:none} /*# sourceMappingURL=pfe-readtime.min.css.map */</style>\n<span class=\"pfe-readtime__text\">${this.readString}</span>`;\n }\n\n static get tag() {\n return \"pfe-readtime\";\n }\n\n static get meta() {\n return {\n title: \"Readtime\",\n description:\n \"This element will collect a word count on a given section and calculate the readtime based on that count.\",\n };\n }\n\n get templateUrl() {\n return \"pfe-readtime.html\";\n }\n\n get styleUrl() {\n return \"pfe-readtime.scss\";\n }\n\n // Declare the type of this component\n static get PfeType() {\n return PFElement.PfeTypes.Content;\n }\n\n static get properties() {\n return {\n wpm: {\n title: \"Words per minute\",\n type: Number,\n default: (el) => getEstimatedWPM(el._lang),\n observer: `render`,\n },\n wordCount: {\n title: \"Number of words in the content\",\n type: Number,\n default: 0,\n observer: `render`,\n },\n templateString: {\n title: \"Template for printing the readtime\",\n description:\n \"Translatable string for printing out the readtime in a readable format. Use %t as a stand-in for the calculated value.\",\n attr: \"template\",\n type: String,\n default: (el) => el.textContent.trim() || \"%t-minute readtime\",\n observer: `render`,\n },\n _lang: {\n title: \"Language of content\",\n type: String,\n attr: \"lang\",\n enum: [\"en\", \"ko\", \"zh\", \"fr\", \"ja\", \"de\", \"it\", \"pt-br\", \"es\"],\n default: () => document.documentElement.lang || \"en\",\n observer: `_langChangedHandler`,\n },\n for: {\n title: \"Element containing content\",\n //This is the unique selector of the target\n type: String,\n observer: \"_forChangeHandler\",\n },\n };\n }\n\n get readtime() {\n return Math.floor(this.wordCount / this.wpm) || 0;\n }\n\n get readString() {\n if (this.readtime <= 0) {\n this.setAttribute(\"hidden\", \"\");\n return;\n }\n\n this.removeAttribute(\"hidden\");\n\n if (this.templateString && this.templateString.match(/%t/)) {\n return this.templateString.replace(\"%t\", this.readtime);\n } else {\n return `${this.readtime}${this.templateString}`;\n }\n }\n\n constructor() {\n // Note: Delay render is important here for the timing of variable definitions\n // we want to render after all the inputs have been read in and parsed\n super(PfeReadtime, { type: PfeReadtime.PfeType, delayRender: true });\n\n this._forChangeHandler = this._forChangeHandler.bind(this);\n this._langChangedHandler = this._langChangedHandler.bind(this);\n }\n\n connectedCallback() {\n super.connectedCallback();\n\n this.render();\n }\n\n // disconnectedCallback() {}\n\n _forChangeHandler(oldVal, newVal) {\n if (newVal === oldVal) return;\n\n const target = document.querySelector(newVal) || document.querySelector(`#${newVal}`);\n if (target) {\n this.content = target;\n\n if (target.hasAttribute(\"word-count\")) {\n const wcAttr = target.getAttribute(\"word-count\");\n if (Number(wcAttr) >= 0) {\n this.wordCount = Number(wcAttr);\n }\n } else if (target.textContent.trim()) {\n this.wordCount = target.textContent.split(/\\b\\w+\\b/).length;\n }\n\n // If a new target element is identified, re-render\n this.render();\n }\n }\n\n _langChangedHandler(oldVal, newVal) {\n if (newVal === oldVal) return;\n\n this.wpm = getEstimatedWPM(newVal);\n this.render();\n }\n}\n\nPFElement.create(PfeReadtime);\n\nexport default PfeReadtime;\n"],"names":["getEstimatedWPM","language","PfeReadtime","PFElement","version","html","this","readString","tag","meta","title","description","templateUrl","styleUrl","PfeType","PfeTypes","Content","properties","wpm","type","Number","default","el","_lang","observer","wordCount","templateString","attr","String","textContent","trim","enum","document","documentElement","lang","for","readtime","Math","floor","removeAttribute","match","replace","setAttribute","[object Object]","super","delayRender","_forChangeHandler","bind","_langChangedHandler","connectedCallback","render","oldVal","newVal","target","querySelector","content","hasAttribute","wcAttr","getAttribute","split","length","create"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EA2BA,SAASA,EAAgBC,GACvB,OAAQA,GACN,IAAK,KACL,IAAK,KACH,OAAO,IACT,IAAK,KACH,OAAO,IACT,IAAK,KACH,OAAO,IACT,IAAK,KACH,OAAO,IACT,IAAK,KACH,OAAO,IACT,IAAK,KACH,OAAO,IACT,IAAK,QACH,OAAO,IACT,IAAK,KACH,OAAO,IACT,QACE,OAAO,KAIb,MAAMC,UAAoBC,EAGxBC,qBACE,M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