vendor: 6,131 bytes, lines 1-189
1/** 2 * @license Hyphenopoly_Loader 5.0.0-beta.3 - client side hyphenation 3 * ©2022 Mathias Nater, Güttingen (mathiasnater at gmail dot com) 4 * https://github.com/mnater/Hyphenopoly 5 * 6 * Released under the MIT license 7 * http://mnater.github.io/Hyphenopoly/LICENSE 8 */ 9/* globals Hyphenopoly:readonly */ 10window.Hyphenopoly = {}; 11 12((w, d, H, o) => { 13 "use strict"; 14 15 /** 16 * Shortcut for new Map 17 * @param {any} init - initialiser for new Map 18 * @returns {Map} 19 */ 20 const mp = (init) => { 21 return new Map(init); 22 }; 23 24 const scriptName = "Hyphenopoly_Loader.js"; 25 const thisScript = d.currentScript.src; 26 const store = sessionStorage; 27 let mainScriptLoaded = false; 28 29 /** 30 * The main function runs the feature test and loads Hyphenopoly if 31 * necessary. 32 */ 33 const main = (() => { 34 const shortcuts = { 35 "ac": "appendChild", 36 "ce": "createElement", 37 "ct": "createTextNode" 38 }; 39 40 /** 41 * Create deferred Promise 42 * 43 * From http://lea.verou.me/2016/12/resolve-promises-externally-with- 44 * this-one-weird-trick/ 45 * @return {promise} 46 */ 47 const defProm = () => { 48 let res = null; 49 let rej = null; 50 const promise = new Promise((resolve, reject) => { 51 res = resolve; 52 rej = reject; 53 }); 54 promise.resolve = res; 55 promise.reject = rej; 56 return promise; 57 }; 58 59 let stylesNode = null; 60 61 /** 62 * Define function H.hide. 63 * This function hides (state = 1) or unhides (state = 0) 64 * the whole document (mode == 0) or 65 * each selected element (mode == 1) or 66 * text of each selected element (mode == 2) or 67 * nothing (mode == -1) 68 * @param {integer} state - State 69 * @param {integer} mode - Mode 70 */ 71 H.hide = (state, mode) => { 72 if (state === 0) { 73 if (stylesNode) { 74 stylesNode.remove(); 75 } 76 } else { 77 let vis = "{visibility:hidden!important}"; 78 stylesNode = d[shortcuts.ce]("style"); 79 let myStyle = ""; 80 if (mode === 0) { 81 myStyle = "html" + vis; 82 } else if (mode !== -1) { 83 if (mode === 2) { 84 vis = "{color:transparent!important}"; 85 } 86 o.keys(H.s.selectors).forEach((sel) => { 87 myStyle += sel + vis; 88 }); 89 } 90 stylesNode[shortcuts.ac](d[shortcuts.ct](myStyle)); 91 d.head[shortcuts.ac](stylesNode); 92 } 93 }; 94 95 const tester = (() => { 96 let fakeBody = null; 97 return { 98 99 /** 100 * Append fakeBody with tests to document 101 * @returns {Object|null} The body element or null, if no tests 102 */ 103 "ap": () => { 104 if (fakeBody) { 105 d.documentElement[shortcuts.ac](fakeBody); 106 return fakeBody; 107 } 108 return null; 109 }, 110 111 /** 112 * Remove fakeBody 113 * @returns {undefined} 114 */ 115 "cl": () => { 116 if (fakeBody) { 117 fakeBody.remove(); 118 } 119 }, 120 121 /** 122 * Create and append div with CSS-hyphenated word 123 * @param {string} lang Language 124 * @returns {undefined} 125 */ 126 "cr": (lang) => { 127 if (H.cf.langs.has(lang)) { 128 return; 129 } 130 fakeBody = fakeBody || d[shortcuts.ce]("body"); 131 const testDiv = d[shortcuts.ce]("div"); 132 const ha = "hyphens:auto"; 133 testDiv.lang = lang; 134 testDiv.style.cssText = `visibility:hidden;-webkit-${ha};-ms-${ha};${ha};width:48px;font-size:12px;line-height:12px;border:none;padding:0;word-wrap:normal`; 135 testDiv[shortcuts.ac]( 136 d[shortcuts.ct](H.lrq.get(lang).wo.toLowerCase()) 137 ); 138 fakeBody[shortcuts.ac](testDiv); 139 } 140 }; 141 })(); 142 143 /** 144 * Checks if hyphens (ev.prefixed) is set to auto for the element. 145 * @param {Object} elm - the element 146 * @returns {Boolean} result of the check 147 */ 148 const checkCSSHyphensSupport = (elmStyle) => { 149 const h = elmStyle.hyphens || 150 elmStyle.webkitHyphens || 151 elmStyle.msHyphens; 152 return (h === "auto"); 153 }; 154 155 H.res = { 156 "he": mp() 157 }; 158 159 /** 160 * Load hyphenEngines to H.res.he 161 * 162 * Make sure each .wasm is loaded exactly once, even for fallbacks 163 * Store a list of languages to by hyphenated with each .wasm 164 * @param {string} lang The language 165 * @returns {undefined} 166 */ 167 const loadhyphenEngine = (lang) => { 168 const fn = H.lrq.get(lang).fn; 169 H.cf.pf = true; 170 H.cf.langs.set(lang, "H9Y"); 171 if (H.res.he.has(fn)) { 172 H.res.he.get(fn).l.push(lang); 173 } else { 174 H.res.he.set( 175 fn, 176 { 177 "l": [lang], 178 "w": w.fetch(H.paths.patterndir + fn + ".wasm", {"credentials": H.s.CORScredentials}) 179 } 180 ); 181 } 182 }; 183 H.lrq.forEach((value, lang) => { 184 if (value.wo === "FORCEHYPHENOPOLY" || H.cf.langs.get(lang) === "H9Y") { 185 loadhyphenEngine(lang); 186 } else { 187 tester.cr(lang); 188 } 189 });
190 const testContainer = tester.ap(); 191 if (testContainer) { 192 testContainer.querySelectorAll("div").forEach((n) => { 193 if (checkCSSHyphensSupport(n.style) && n.offsetHeight > 12) { 194 H.cf.langs.set(n.lang, "CSS"); 195 } else { 196 loadhyphenEngine(n.lang); 197 } 198 }); 199 tester.cl(); 200 } 201 const hev = H.hev; 202 if (H.cf.pf) { 203 H.res.DOM = new Promise((res) => { 204 if (d.readyState === "loading") { 205 d.addEventListener( 206 "DOMContentLoaded", 207 res, 208 { 209 "once": true, 210 "passive": true 211 } 212 ); 213 } else { 214 res(); 215 } 216 }); 217 H.hide(1, H.s.hide); 218 H.timeOutHandler = w.setTimeout(() => { 219 H.hide(0, null); 220 // eslint-disable-next-line no-console 221 console.info(scriptName + " timed out."); 222 }, H.s.timeout); 223 if (mainScriptLoaded) { 224 H.main(); 225 } else { 226 // Load main script 227 const script = d[shortcuts.ce]("script"); 228 script.src = H.paths.maindir + "Hyphenopoly.js"; 229 d.head[shortcuts.ac](script); 230 mainScriptLoaded = true; 231 } 232 H.hy6ors = mp();
vendor: 3,033 bytes, lines 233-331
233 H.cf.langs.forEach((langDef, lang) => { 234 if (langDef === "H9Y") { 235 H.hy6ors.set(lang, defProm()); 236 } 237 }); 238 H.hy6ors.set("HTML", defProm()); 239 H.hyphenators = new Proxy(H.hy6ors, { 240 "get": (target, key) => { 241 return target.get(key); 242 }, 243 "set": () => { 244 // Inhibit setting of hyphenators 245 return true; 246 } 247 }); 248 (() => { 249 if (hev && hev.polyfill) { 250 hev.polyfill(); 251 } 252 })(); 253 } else { 254 (() => { 255 if (hev && hev.tearDown) { 256 hev.tearDown(); 257 } 258 w.Hyphenopoly = null; 259 })(); 260 } 261 (() => { 262 if (H.cft) { 263 store.setItem(scriptName, JSON.stringify( 264 { 265 "langs": [...H.cf.langs.entries()], 266 "pf": H.cf.pf 267 } 268 )); 269 } 270 })(); 271 }); 272 273 H.config = (c) => { 274 /** 275 * Sets default properties for an Object 276 * @param {object} obj - The object to set defaults to 277 * @param {object} defaults - The defaults to set 278 * @returns {object} 279 */ 280 const setDefaults = (obj, defaults) => { 281 if (obj) { 282 o.entries(defaults).forEach(([k, v]) => { 283 // eslint-disable-next-line security/detect-object-injection 284 obj[k] = obj[k] || v; 285 }); 286 return obj; 287 } 288 return defaults; 289 }; 290 291 H.cft = Boolean(c.cacheFeatureTests); 292 if (H.cft && store.getItem(scriptName)) { 293 H.cf = JSON.parse(store.getItem(scriptName)); 294 H.cf.langs = mp(H.cf.langs); 295 } else { 296 H.cf = { 297 "langs": mp(), 298 "pf": false 299 }; 300 } 301 302 const maindir = thisScript.slice(0, (thisScript.lastIndexOf("/") + 1)); 303 const patterndir = maindir + "patterns/"; 304 H.paths = setDefaults(c.paths, { 305 maindir, 306 patterndir 307 }); 308 H.s = setDefaults(c.setup, { 309 "CORScredentials": "include", 310 "hide": "all", 311 "selectors": {".hyphenate": {}}, 312 "timeout": 1000 313 }); 314 // Change mode string to mode int 315 H.s.hide = ["all", "element", "text"].indexOf(H.s.hide); 316 if (c.handleEvent) { 317 H.hev = c.handleEvent; 318 } 319 320 const fallbacks = mp(o.entries(c.fallbacks || {})); 321 H.lrq = mp(); 322 o.entries(c.require).forEach(([lang, wo]) => { 323 H.lrq.set(lang.toLowerCase(), { 324 "fn": fallbacks.get(lang) || lang, 325 wo 326 }); 327 }); 328 329 main(); 330 }; 331})(window, document, Hyphenopoly, Object);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.