8 lines
9.8 KiB
Plaintext
8 lines
9.8 KiB
Plaintext
{
|
|
"version": 3,
|
|
"sources": ["src/templates/assets/javascripts/polyfills/index.ts", "src/templates/assets/javascripts/integrations/search/worker/main/index.ts"],
|
|
"sourcesContent": ["/*\n * Copyright (c) 2016-2023 Martin Donath <martin.donath@squidfunk.com>\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\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell 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 NON-INFRINGEMENT. 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\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\n/* ----------------------------------------------------------------------------\n * Polyfills\n * ------------------------------------------------------------------------- */\n\n/* Polyfill `Object.entries` */\nif (!Object.entries)\n Object.entries = function (obj: object) {\n const data: [string, string][] = []\n for (const key of Object.keys(obj))\n // @ts-expect-error - ignore property access warning\n data.push([key, obj[key]])\n\n /* Return entries */\n return data\n }\n\n/* Polyfill `Object.values` */\nif (!Object.values)\n Object.values = function (obj: object) {\n const data: string[] = []\n for (const key of Object.keys(obj))\n // @ts-expect-error - ignore property access warning\n data.push(obj[key])\n\n /* Return values */\n return data\n }\n\n/* ------------------------------------------------------------------------- */\n\n/* Polyfills for `Element` */\nif (typeof Element !== \"undefined\") {\n\n /* Polyfill `Element.scrollTo` */\n if (!Element.prototype.scrollTo)\n Element.prototype.scrollTo = function (\n x?: ScrollToOptions | number, y?: number\n ): void {\n if (typeof x === \"object\") {\n this.scrollLeft = x.left!\n this.scrollTop = x.top!\n } else {\n this.scrollLeft = x!\n this.scrollTop = y!\n }\n }\n\n /* Polyfill `Element.replaceWith` */\n if (!Element.prototype.replaceWith)\n Element.prototype.replaceWith = function (\n ...nodes: Array<string | Node>\n ): void {\n const parent = this.parentNode\n if (parent) {\n if (nodes.length === 0)\n parent.removeChild(this)\n\n /* Replace children and create text nodes */\n for (let i = nodes.length - 1; i >= 0; i--) {\n let node = nodes[i]\n if (typeof node === \"string\")\n node = document.createTextNode(node)\n else if (node.parentNode)\n node.parentNode.removeChild(node)\n\n /* Replace child or insert before previous sibling */\n if (!i)\n parent.replaceChild(node, this)\n else\n parent.insertBefore(this.previousSibling!, node)\n }\n }\n }\n}\n", "/*\n * Copyright (c) 2016-2023 Martin Donath <martin.donath@squidfunk.com>\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\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell 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 RTICULAR PURPOSE AND NON-INFRINGEMENT. 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\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\nimport type { SearchResult, SearchItem } from \"../../_\";\nimport \"~/polyfills\"\n\nimport {\n SearchMessage,\n SearchMessageType\n} from \"../message\"\n\n/* ----------------------------------------------------------------------------\n * Types\n * ------------------------------------------------------------------------- */\n\n/**\n * Add support for `iframe-worker` shim\n *\n * While `importScripts` is synchronous when executed inside of a web worker,\n * it's not possible to provide a synchronous shim implementation. The cool\n * thing is that awaiting a non-Promise will convert it into a Promise, so\n * extending the type definition to return a `Promise` shouldn't break anything.\n *\n * @see https://bit.ly/2PjDnXi - GitHub comment\n *\n * @param urls - Scripts to load\n *\n * @returns Promise resolving with no result\n */\ndeclare global {\n function importScripts(...urls: string[]): Promise<void> | void\n}\n\n/* ----------------------------------------------------------------------------\n * Data\n * ------------------------------------------------------------------------- */\n\nlet searchEndpoint: string;\n\n/* ----------------------------------------------------------------------------\n * Helper functions\n * ------------------------------------------------------------------------- */\n\nasync function handleSearch(keyword: string): Promise<SearchResult> {\n keyword = keyword.trim();\n if (!keyword) return { items: [] };\n\n interface OiWikiSearchServerResponseBody {\n url: string;\n title: string;\n highlight: string[];\n }\n\n const response = await fetch(\n `${searchEndpoint}?s=${keyword}`,\n {\n credentials: \"same-origin\"\n }\n );\n const responseBody: OiWikiSearchServerResponseBody[] = await response.json();\n\n let score = 1e6;\n return {\n items: responseBody.map<SearchItem[]>(item =>\n (item.highlight || [\"\"]).map(match => ({\n title: item.title,\n location: item.url.startsWith(\"/\") ? item.url.slice(1) : item.url,\n terms: { [keyword]: true },\n text: match.split(\"<em>\").join(\"<mark>\").split(\"</em>\").join(\"</mark>\"),\n score: --score\n }))\n )\n };\n}\n\n/* ----------------------------------------------------------------------------\n * Functions\n * ------------------------------------------------------------------------- */\n\n/**\n * Message handler\n *\n * @param message - Source message\n *\n * @returns Target message\n */\nexport async function handler(\n message: SearchMessage\n): Promise<SearchMessage> {\n switch (message.type) {\n\n /* Search setup message */\n case SearchMessageType.SETUP:\n searchEndpoint = message.data as any as string;\n return {\n type: SearchMessageType.READY\n }\n\n /* Search query message */\n case SearchMessageType.QUERY:\n return {\n type: SearchMessageType.RESULT,\n data: await handleSearch(message.data)\n }\n\n /* All other messages */\n default:\n throw new TypeError(\"Invalid message type\")\n }\n}\n\n/* ----------------------------------------------------------------------------\n * Worker\n * ------------------------------------------------------------------------- */\n\n/* Handle messages */\naddEventListener(\"message\", async ev => {\n postMessage(await handler(ev.data))\n})\n"],
|
|
"mappings": "gOA2BK,OAAO,UACV,OAAO,QAAU,SAAUA,EAAa,CACtC,IAAMC,EAA2B,CAAC,EAClC,QAAWC,KAAO,OAAO,KAAKF,CAAG,EAE/BC,EAAK,KAAK,CAACC,EAAKF,EAAIE,CAAG,CAAC,CAAC,EAG3B,OAAOD,CACT,GAGG,OAAO,SACV,OAAO,OAAS,SAAUD,EAAa,CACrC,IAAMC,EAAiB,CAAC,EACxB,QAAWC,KAAO,OAAO,KAAKF,CAAG,EAE/BC,EAAK,KAAKD,EAAIE,CAAG,CAAC,EAGpB,OAAOD,CACT,GAKE,OAAO,SAAY,cAGhB,QAAQ,UAAU,WACrB,QAAQ,UAAU,SAAW,SAC3BE,EAA8BC,EACxB,CACF,OAAOD,GAAM,UACf,KAAK,WAAaA,EAAE,KACpB,KAAK,UAAYA,EAAE,MAEnB,KAAK,WAAaA,EAClB,KAAK,UAAYC,EAErB,GAGG,QAAQ,UAAU,cACrB,QAAQ,UAAU,YAAc,YAC3BC,EACG,CACN,IAAMC,EAAS,KAAK,WACpB,GAAIA,EAAQ,CACND,EAAM,SAAW,GACnBC,EAAO,YAAY,IAAI,EAGzB,QAASC,EAAIF,EAAM,OAAS,EAAGE,GAAK,EAAGA,IAAK,CAC1C,IAAIC,EAAOH,EAAME,CAAC,EACd,OAAOC,GAAS,SAClBA,EAAO,SAAS,eAAeA,CAAI,EAC5BA,EAAK,YACZA,EAAK,WAAW,YAAYA,CAAI,EAG7BD,EAGHD,EAAO,aAAa,KAAK,gBAAkBE,CAAI,EAF/CF,EAAO,aAAaE,EAAM,IAAI,CAGlC,CACF,CACF,ICtCJ,IAAIC,EAMJ,SAAeC,EAAaC,EAAwC,QAAAC,EAAA,sBAElE,GADAD,EAAUA,EAAQ,KAAK,EACnB,CAACA,EAAS,MAAO,CAAE,MAAO,CAAC,CAAE,EAcjC,IAAME,EAAiD,MANtC,MAAM,MACrB,GAAGJ,CAAc,MAAME,CAAO,GAC9B,CACE,YAAa,aACf,CACF,GACsE,KAAK,EAEvEG,EAAQ,IACZ,MAAO,CACL,MAAOD,EAAa,IAAkBE,IACnCA,EAAK,WAAa,CAAC,EAAE,GAAG,IAAIC,IAAU,CACrC,MAAOD,EAAK,MACZ,SAAUA,EAAK,IAAI,WAAW,GAAG,EAAIA,EAAK,IAAI,MAAM,CAAC,EAAIA,EAAK,IAC9D,MAAO,CAAE,CAACJ,CAAO,EAAG,EAAK,EACzB,KAAMK,EAAM,MAAM,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,EAAE,KAAK,SAAS,EACtE,MAAO,EAAEF,CACX,EAAE,CACJ,CACF,CACF,GAaA,SAAsBG,EACpBC,EACwB,QAAAN,EAAA,sBACxB,OAAQM,EAAQ,KAAM,CAGpB,OACE,OAAAT,EAAiBS,EAAQ,KAClB,CACL,MACF,EAGF,OACE,MAAO,CACL,OACA,KAAM,MAAMR,EAAaQ,EAAQ,IAAI,CACvC,EAGF,QACE,MAAM,IAAI,UAAU,sBAAsB,CAC9C,CACF,GAOA,iBAAiB,UAAiBC,GAAMP,EAAA,wBACtC,YAAY,MAAMK,EAAQE,EAAG,IAAI,CAAC,CACpC,EAAC",
|
|
"names": ["obj", "data", "key", "x", "y", "nodes", "parent", "i", "node", "searchEndpoint", "handleSearch", "keyword", "__async", "responseBody", "score", "item", "match", "handler", "message", "ev"]
|
|
}
|