@qaiddev/thumbs-embed 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +20 -12
  2. package/dist/chunks/{annotate-1zompTEi.js → annotate-Dvrfeb8k.js} +2 -2
  3. package/dist/chunks/{annotate-1zompTEi.js.map → annotate-Dvrfeb8k.js.map} +1 -1
  4. package/dist/chunks/core-C36Mpll9.js +26 -0
  5. package/dist/chunks/core-C36Mpll9.js.map +1 -0
  6. package/dist/chunks/modal-CXZZ6LG0.js +2 -0
  7. package/dist/chunks/modal-CXZZ6LG0.js.map +1 -0
  8. package/dist/chunks/recording-D_iYhxpC.js +2 -0
  9. package/dist/chunks/recording-D_iYhxpC.js.map +1 -0
  10. package/dist/chunks/send-o4flR35U.js +2 -0
  11. package/dist/chunks/{send-C3IvslZA.js.map → send-o4flR35U.js.map} +1 -1
  12. package/dist/chunks/{targeting-Bpbt68Pp.js → targeting-Jjo_Jyqy.js} +2 -2
  13. package/dist/chunks/{targeting-Bpbt68Pp.js.map → targeting-Jjo_Jyqy.js.map} +1 -1
  14. package/dist/embed-loader.d.ts +18 -5
  15. package/dist/embed.d.ts +4 -4
  16. package/dist/embed.js +1 -1
  17. package/dist/embed.js.map +1 -1
  18. package/dist/index.js +1563 -1479
  19. package/dist/index.js.map +1 -1
  20. package/dist/integrity-probe.js +2 -0
  21. package/dist/loader.js +1 -1
  22. package/dist/modal.d.ts +7 -2
  23. package/dist/network-capture.d.ts +4 -0
  24. package/dist/qaid.umd.cjs +15 -15
  25. package/dist/qaid.umd.cjs.map +1 -1
  26. package/dist/quest-config.d.ts +3 -3
  27. package/dist/redact.d.ts +40 -0
  28. package/dist/send.d.ts +2 -2
  29. package/dist/trusted-types.d.ts +7 -0
  30. package/dist/types.d.ts +13 -0
  31. package/package.json +1 -1
  32. package/dist/chunks/core-vu1EieDc.js +0 -26
  33. package/dist/chunks/core-vu1EieDc.js.map +0 -1
  34. package/dist/chunks/modal-5G2DhiUE.js +0 -2
  35. package/dist/chunks/modal-5G2DhiUE.js.map +0 -1
  36. package/dist/chunks/recording-CVwPTtB0.js +0 -2
  37. package/dist/chunks/recording-CVwPTtB0.js.map +0 -1
  38. package/dist/chunks/send-C3IvslZA.js +0 -2
@@ -20,11 +20,24 @@
20
20
  * (Distinct from `loader.ts`/`loader.js`, the ESM-only progressive entry this
21
21
  * one delegates to on modern browsers.)
22
22
  *
23
- * Pinned with Subresource Integrity (`integrity="sha384-…"` on this tag), it
24
- * loads the single-file UMD bundle instead, with that file's own sha384 baked
25
- * in at build time (vite.config.embed.ts). `import()` can't carry a hash, so
26
- * the code-split ESM build's lazy chunks could not be checked; the one-file
27
- * bundle can, so every byte of the embed's JavaScript is verified.
23
+ * Pinned with Subresource Integrity (`integrity="sha384-…"` on this tag),
24
+ * every file it loads after itself is hash-checked too, with hashes baked in
25
+ * at build time (vite.config.embed.ts):
26
+ *
27
+ * - Where the browser enforces import-map `integrity` (Chrome 127+,
28
+ * Safari 18+, Firefox 138+), it adds an import map listing the sha384 of
29
+ * loader.js and every lazy chunk, then loads the small progressive build.
30
+ * The browser refuses any chunk whose bytes differ.
31
+ * - Everywhere else it loads the single-file UMD bundle with its own hash.
32
+ *
33
+ * No browser lets a page ask whether import-map integrity is enforced, so it
34
+ * finds out: the map also lists integrity-probe.js under a hash that can never
35
+ * match, and it loads that file first. A browser that enforces the map refuses
36
+ * it (onerror: take the progressive build); one that ignores the map, or a
37
+ * page whose CSP blocks the inline map, runs it (onload: take the UMD bundle).
38
+ * A refusal means the check is live, never that it is missing, so a pinned tag
39
+ * never loads an unchecked file. The cost is one tiny request and one console
40
+ * line about the probe's digest.
28
41
  *
29
42
  * IMPORTANT: this file must stay ES5-clean and dependency-free. It is the one
30
43
  * script that also runs on the legacy browsers we fall back for, so it can't
package/dist/embed.d.ts CHANGED
@@ -22,11 +22,11 @@ export declare class QaidFeedback {
22
22
  private feedbackData;
23
23
  private selectedBounds;
24
24
  /**
25
- * This feedback's record id, once its POST answers (null if it failed).
26
- * The message box and a linked quest open without waiting for it; the
27
- * PATCHes that need the id wait on this instead.
25
+ * This feedback's record (id + edit token), once its POST answers (null
26
+ * if it failed). The message box and a linked quest open without waiting
27
+ * for it; the PATCHes that need it wait on this instead.
28
28
  */
29
- private feedbackIdPromise;
29
+ private feedbackRecordPromise;
30
30
  private questsPrewarmed;
31
31
  private activeQuest;
32
32
  private isMobile;
package/dist/embed.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(){"use strict";var v="qaid-embed",f="__qaidEmbedTrustedTypes";function y(){if(typeof window=="undefined")return null;var r=window,e=r.trustedTypes;if(!e||typeof e.createPolicy!="function")return null;var i=r[f];if(i)return i;var a=Object.create(null),t=null;try{t=e.createPolicy(v,{createScriptURL:function(n){if(a[n]===!0)return n;throw new TypeError("qaid-embed: refused script URL "+n)}})}catch(n){t=null}var u={policy:t,allowed:a};try{Object.defineProperty(r,f,{value:u,configurable:!0})}catch(n){}return u}function b(r){var e=y();return!e||!e.policy?r:(e.allowed[r]=!0,e.policy.createScriptURL(r))}var h="__qaidThumbsOrigin";(function(){if(typeof document=="undefined")return;function r(){var c=document.currentScript;if(c&&c.src)return c;for(var l=document.getElementsByTagName("script"),s=l.length-1;s>=0;s--){var m=l[s].src||"";if(m.indexOf("thumbs-embed")!==-1&&/\/embed(\.min)?\.js(\?|#|$)/.test(m))return l[s]}return null}var e=r();if(!(!e||!e.src)){for(var i=e.src.substring(0,e.src.lastIndexOf("/")+1),a=("noModule"in HTMLScriptElement.prototype),t=document.createElement("script"),u=e.attributes,n=0;n<u.length;n++){var o=u[n];o.name.indexOf("data-")===0&&t.setAttribute(o.name,o.value)}t[h]=e;var g="sha384-dvYrFdNJc4RgJa2keZAWIhtUM2OuLw6x42BhJx0ROKwuXj552zn+YPCxCHqJ4qru",p=!!e.getAttribute("integrity")&&!0,d;a&&!p?(t.type="module",d=i+"loader.js"):(t.defer=!0,d=i+"qaid.umd.cjs",p&&(t.integrity=g,t.crossOrigin="anonymous"));try{t.src=b(d)}catch(c){typeof console!="undefined"&&console.warn("[thumbs-embed] Trusted Types blocked "+d+". Add `trusted-types qaid-embed` to the page's CSP.");return}(document.head||document.documentElement).appendChild(t)}})()})();
1
+ (function(){"use strict";var N="qaid-embed",g="__qaidEmbedTrustedTypes";function j(){if(typeof window=="undefined")return null;var n=window,e=n.trustedTypes;if(!e||typeof e.createPolicy!="function")return null;var c=n[g];if(c)return c;var m=Object.create(null),r=Object.create(null),u=null;try{u=e.createPolicy(N,{createScriptURL:function(i){if(m[i]===!0)return i;throw new TypeError("qaid-embed: refused script URL "+i)},createScript:function(i){if(r[i]===!0)return i;throw new TypeError("qaid-embed: refused inline script")}})}catch(i){u=null}var d={policy:u,allowed:m,allowedScripts:r};try{Object.defineProperty(n,g,{value:d,configurable:!0})}catch(i){}return d}function w(n){var e=j();return!e||!e.policy?n:(e.allowed[n]=!0,e.policy.createScriptURL(n))}function C(n){var e=j();if(!e||!e.policy)return n;if(!e.allowedScripts||typeof e.policy.createScript!="function")throw new TypeError("qaid-embed: this page's policy cannot sign scripts");return e.allowedScripts[n]=!0,e.policy.createScript(n)}var T="__qaidThumbsOrigin",v={"loader.js":"sha384-O1+Y2RhMmEtC8CCbd4onyjeKe1Qe+wji7WVLR7MG+nn4DMgklVxnyQVWvmDGhDlh","chunks/annotate-Dvrfeb8k.js":"sha384-aeWzp3H/iOGiiy3e56hMWJKmnnMYsMaGJLA6LQKXp6jzpLfJVjFcRgyNYOEGxIwp","chunks/core-C36Mpll9.js":"sha384-NBSkr2+51LEwgn5qtbC644mMS9apiEDoqc+SR5b2RJUTAZfToEBDzLaFD8n2n+/J","chunks/dom-kdwHduNo.js":"sha384-mmXNhl4XzelgmyQD3XHa/3kWOlsNm/ow6MqGzev47BHjb+to6amzytvwGM7fc/aG","chunks/html2canvas.esm-Csbr1w14.js":"sha384-6MW8rZoxyLmfs5uD4VA0Bxw4e69KwtsimOHDkt/QsDQvFxQDLQd5ljmGjjSAaygi","chunks/modal-CXZZ6LG0.js":"sha384-/oXMalk7mRljteHxJMzD4n73ibH1iJuyviaLdvzkLU0FTK2BIxsvVwkDeqs/BMHS","chunks/recording-D_iYhxpC.js":"sha384-C1ZTvLArsfuJ169VmDGmwukhPNns4aWG95u0DcHtYZFqm6ebUNZhJkSalbkNiVZN","chunks/screenshot-CNe1irEz.js":"sha384-b6vBhmHLg6hQ5rdkVg9UHEcxE9tbYLZdWkO4z3PYM6kCQ0f3Mo8/PLPAUb72k2Am","chunks/screenshot-dom-DO-0UlOz.js":"sha384-QShbeObHMdCj3xAQQjpJ+XV4MAmv8dsByIEOZf7XpXLKTYY7WrdPWDW/qIVP1yb0","chunks/send-o4flR35U.js":"sha384-CSjrZpjNWzcMy+YAqPvUGv3u/FmzR1VFCG+ixaiYbLTDr1DF5//mX4ZvCxDC7Ro8","chunks/targeting-Jjo_Jyqy.js":"sha384-KNgSEiHQBo5qY8BUGcZtmiciKlIqVWsf1T+rcDtOaE3U3ckVnLmW65KnNIKiAE9u","chunks/video-BSP4s2te.js":"sha384-U6PurxQ6ugA7semvNHgyrjd8pDoYY60XG+e7za26M8mol8vmb2kGRUwIj0It78j3"},M="integrity-probe.js";(function(){if(typeof document=="undefined")return;function n(){var t=document.currentScript;if(t&&t.src)return t;for(var s=document.getElementsByTagName("script"),a=s.length-1;a>=0;a--){var l=s[a].src||"";if(l.indexOf("thumbs-embed")!==-1&&/\/embed(\.min)?\.js(\?|#|$)/.test(l))return s[a]}return null}var e=n();if(!e||!e.src)return;for(var c=e.src.substring(0,e.src.lastIndexOf("/")+1),m=("noModule"in HTMLScriptElement.prototype),r=document.createElement("script"),u=e.attributes,d=0;d<u.length;d++){var i=u[d];i.name.indexOf("data-")===0&&r.setAttribute(i.name,i.value)}r[T]=e;var p="sha384-X8qLzKhuubJJcl7N0tjBaxgXJKF31PJiw9bITL98VapCyQ5P6IygJNzxMe2eZe/n",h=typeof v=="object"&&v?v:null,k="sha384-/1OlEapvbDTqaD7Kh2wuedM8GLdPNC4GDz+iVHqB7AOskCLf5AQeL56v6tmeljkL",E=!!e.getAttribute("integrity")&&!0;function q(t){typeof console!="undefined"&&console.warn("[thumbs-embed] "+t)}function L(t,s){try{return t.src=w(s),!0}catch(a){return q("Trusted Types blocked "+s+". Add `trusted-types qaid-embed` to the page's CSP."),!1}}function y(t){(document.head||document.documentElement).appendChild(t)}function O(t){r.type="module",t&&(r.integrity=t,r.crossOrigin="anonymous"),L(r,c+"loader.js")&&y(r)}function f(t){r.defer=!0,t&&(r.integrity=t,r.crossOrigin="anonymous"),L(r,c+"qaid.umd.cjs")&&y(r)}function G(){var t=HTMLScriptElement;return typeof t.supports=="function"&&t.supports("importmap")}function I(){var t=h,s={integrity:{}};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(s.integrity[c+a]=t[a]);s.integrity[c+M]=k;var l=document.createElement("script");l.type="importmap";try{l.text=C(JSON.stringify(s))}catch(b){f(p);return}y(l);var o=document.createElement("script");o.type="module",o.crossOrigin="anonymous";var D=!1;function S(b){D||(D=!0,o.parentNode&&o.parentNode.removeChild(o),b?O(t["loader.js"]):f(p))}o.onerror=function(){S(!0)},o.onload=function(){S(!1)};try{o.src=w(c+M)}catch(b){f(p);return}y(o)}m?E?h&&h["loader.js"]&&k&&G()?I():f(p):O(""):f(E?p:"")})()})();
2
2
  //# sourceMappingURL=embed.js.map
package/dist/embed.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"embed.js","sources":["../src/trusted-types.ts","../src/origin-key.ts","../src/embed-loader.ts"],"sourcesContent":["/**\n * The embed's one Trusted Types policy, `qaid-embed`.\n *\n * On a page that sets `require-trusted-types-for 'script'`, assigning a plain\n * string to `script.src` throws. The embed computes every script URL it sets\n * itself (its own stage-two file, the quests module), so it passes each one\n * through this policy, which only signs URLs the embed registered a moment\n * before. A partner allows it with `trusted-types qaid-embed`.\n *\n * The policy is created once per page and kept on `window`, because embed.js,\n * the bundle it loads, and quests-embed (which keeps its own copy of this\n * file) all want the same name, and a page's `trusted-types` directive\n * refuses a second policy of one name unless it says `'allow-duplicates'`.\n *\n * When the browser has no Trusted Types, or the page's directive does not\n * list `qaid-embed`, the URL comes back as a plain string. The assignment\n * then works or throws exactly as it would have; callers catch it.\n *\n * ES5-clean on purpose: embed.js, which runs on the oldest browsers we\n * support, bundles this file too.\n */\n\ninterface ScriptUrlPolicy {\n createScriptURL(url: string): unknown;\n}\n\ninterface SharedPolicy {\n policy: ScriptUrlPolicy | null;\n allowed: Record<string, boolean>;\n}\n\ninterface TrustedTypesFactory {\n createPolicy(\n name: string,\n rules: { createScriptURL: (url: string) => string }\n ): ScriptUrlPolicy;\n}\n\nexport var POLICY_NAME = \"qaid-embed\";\nvar KEY = \"__qaidEmbedTrustedTypes\";\n\nfunction shared(): SharedPolicy | null {\n if (typeof window === \"undefined\") return null;\n var w = window as unknown as Record<string, unknown>;\n var tt = w.trustedTypes as TrustedTypesFactory | undefined;\n if (!tt || typeof tt.createPolicy !== \"function\") return null;\n var existing = w[KEY] as SharedPolicy | undefined;\n if (existing) return existing;\n\n var allowed: Record<string, boolean> = Object.create(null);\n var policy: ScriptUrlPolicy | null = null;\n try {\n policy = tt.createPolicy(POLICY_NAME, {\n createScriptURL: function (url: string): string {\n if (allowed[url] === true) return url;\n throw new TypeError(\"qaid-embed: refused script URL \" + url);\n },\n });\n } catch (e) {\n // The page's trusted-types directive does not list qaid-embed.\n policy = null;\n }\n var state: SharedPolicy = { policy: policy, allowed: allowed };\n try {\n Object.defineProperty(w, KEY, { value: state, configurable: true });\n } catch (e) {\n /* frozen window: keep it local */\n }\n return state;\n}\n\n/**\n * A value for `script.src`: a TrustedScriptURL from the `qaid-embed` policy\n * when one exists, else the string itself.\n */\nexport function trustedScriptUrl(url: string): string {\n var s = shared();\n if (!s || !s.policy) return url;\n s.allowed[url] = true;\n return s.policy.createScriptURL(url) as string;\n}\n\n/** @internal Test seam: forget the page's policy. */\nexport function _resetTrustedTypes(): void {\n if (typeof window === \"undefined\") return;\n try {\n delete (window as unknown as Record<string, unknown>)[KEY];\n } catch (e) {\n /* nothing to forget */\n }\n}\n","/**\n * The property embed.js sets on the tag it injects, pointing back at the\n * customer's own `<script src=\".../embed.js\">`. An expando, not an attribute:\n * markup injected into the page can't forge it. Its own module so embed.js\n * (ES5, tiny) can share it with the bootstrap without pulling the bootstrap in.\n */\nexport var ORIGIN_KEY_NAME = \"__qaidThumbsOrigin\";\n","/**\n * Single-tag embed loader (`dist/embed.js`).\n *\n * A drop-in classic `<script>` that works in every browser. It feature-detects\n * ES-module support and injects the right build, so the page author never has\n * to think about compatibility:\n *\n * - modern browsers → the progressive ESM loader (`loader.js`): a small core,\n * with screenshot / video / annotation / targeting loading on demand.\n * - older browsers → the all-in-one UMD bundle (`qaid.umd.cjs`).\n *\n * The injected build initializes itself from the `data-*` attributes copied\n * across from this tag (or from a `<script type=\"application/json\">` config\n * block already on the page), so exactly one embed is created either way.\n *\n * Usage:\n * <script src=\"https://unpkg.com/@qaiddev/thumbs-embed/dist/embed.js\"\n * data-endpoint=\"/api/feedback\"></script>\n *\n * (Distinct from `loader.ts`/`loader.js`, the ESM-only progressive entry this\n * one delegates to on modern browsers.)\n *\n * Pinned with Subresource Integrity (`integrity=\"sha384-…\"` on this tag), it\n * loads the single-file UMD bundle instead, with that file's own sha384 baked\n * in at build time (vite.config.embed.ts). `import()` can't carry a hash, so\n * the code-split ESM build's lazy chunks could not be checked; the one-file\n * bundle can, so every byte of the embed's JavaScript is verified.\n *\n * IMPORTANT: this file must stay ES5-clean and dependency-free. It is the one\n * script that also runs on the legacy browsers we fall back for, so it can't\n * use syntax (arrow fns, const/let, template literals) they'd choke on before\n * the fallback ever loads. Written with var/function on purpose.\n */\n\nimport { trustedScriptUrl } from \"./trusted-types\";\nimport { ORIGIN_KEY_NAME } from \"./origin-key\";\n\n/** sha384 of qaid.umd.cjs, set by vite.config.embed.ts. Empty in tests. */\ndeclare const __QAID_UMD_INTEGRITY__: string | undefined;\n\n(function () {\n if (typeof document === \"undefined\") return;\n\n // Locate this script tag: prefer document.currentScript (valid for a plain\n // classic script), else find the last <script> whose src looks like embed.js.\n function findSelf(): HTMLScriptElement | null {\n var cur = document.currentScript as HTMLScriptElement | null;\n if (cur && cur.src) return cur;\n var scripts = document.getElementsByTagName(\"script\");\n for (var i = scripts.length - 1; i >= 0; i--) {\n var src = scripts[i].src || \"\";\n if (src.indexOf(\"thumbs-embed\") !== -1 && /\\/embed(\\.min)?\\.js(\\?|#|$)/.test(src)) {\n return scripts[i];\n }\n }\n return null;\n }\n\n var self = findSelf();\n if (!self || !self.src) return;\n\n // Base = the directory that holds embed.js, e.g.\n // \"https://unpkg.com/@qaiddev/thumbs-embed/dist/\". loader.js's own relative\n // chunk imports then resolve against the same (CDN-versioned) base.\n var base = self.src.substring(0, self.src.lastIndexOf(\"/\") + 1);\n\n var supportsModules = \"noModule\" in HTMLScriptElement.prototype;\n\n var entry = document.createElement(\"script\");\n\n // Carry the config across so the injected build's auto-init sees it.\n var attrs = self.attributes;\n for (var j = 0; j < attrs.length; j++) {\n var a = attrs[j];\n if (a.name.indexOf(\"data-\") === 0) entry.setAttribute(a.name, a.value);\n }\n\n // Lets the injected build find this tag, for the JSON config block beside\n // it. A property, not an attribute, so page markup can't fake it.\n (entry as unknown as Record<string, unknown>)[ORIGIN_KEY_NAME] = self;\n\n var umdIntegrity = typeof __QAID_UMD_INTEGRITY__ === \"string\" ? __QAID_UMD_INTEGRITY__ : \"\";\n var pinned = !!self.getAttribute(\"integrity\") && !!umdIntegrity;\n\n var url: string;\n if (supportsModules && !pinned) {\n entry.type = \"module\";\n url = base + \"loader.js\";\n } else {\n // Classic bundle: defer so it runs after the document is parsed, matching\n // the module entry's deferred timing.\n entry.defer = true;\n url = base + \"qaid.umd.cjs\";\n if (pinned) {\n entry.integrity = umdIntegrity;\n entry.crossOrigin = \"anonymous\";\n }\n }\n\n try {\n entry.src = trustedScriptUrl(url);\n } catch (e) {\n // A Trusted Types page that doesn't allow the qaid-embed policy.\n if (typeof console !== \"undefined\") {\n console.warn(\"[thumbs-embed] Trusted Types blocked \" + url + \". Add `trusted-types qaid-embed` to the page's CSP.\");\n }\n return;\n }\n\n (document.head || document.documentElement).appendChild(entry);\n})();\n"],"names":["POLICY_NAME","KEY","shared","w","tt","existing","allowed","policy","url","e","state","trustedScriptUrl","s","ORIGIN_KEY_NAME","findSelf","cur","scripts","i","src","self","base","supportsModules","entry","attrs","j","a","umdIntegrity","pinned"],"mappings":"yBAsCO,IAAIA,EAAc,aACrBC,EAAM,0BAEV,SAASC,GAA8B,CACrC,GAAI,OAAO,QAAW,YAAa,OAAO,KAC1C,IAAIC,EAAI,OACJC,EAAKD,EAAE,aACX,GAAI,CAACC,GAAM,OAAOA,EAAG,cAAiB,WAAY,OAAO,KACzD,IAAIC,EAAWF,EAAEF,CAAG,EACpB,GAAII,EAAU,OAAOA,EAErB,IAAIC,EAAmC,OAAO,OAAO,IAAI,EACrDC,EAAiC,KACrC,GAAI,CACFA,EAASH,EAAG,aAAaJ,EAAa,CACpC,gBAAiB,SAAUQ,EAAqB,CAC9C,GAAIF,EAAQE,CAAG,IAAM,GAAM,OAAOA,EAClC,MAAM,IAAI,UAAU,kCAAoCA,CAAG,CAC7D,CAAA,CACD,CACH,OAASC,EAAG,CAEVF,EAAS,IACX,CACA,IAAIG,EAAsB,CAAE,OAAAH,EAAgB,QAAAD,CAAA,EAC5C,GAAI,CACF,OAAO,eAAeH,EAAGF,EAAK,CAAE,MAAOS,EAAO,aAAc,GAAM,CACpE,OAASD,EAAG,CAEZ,CACA,OAAOC,CACT,CAMO,SAASC,EAAiBH,EAAqB,CACpD,IAAII,EAAIV,EAAA,EACR,MAAI,CAACU,GAAK,CAACA,EAAE,OAAeJ,GAC5BI,EAAE,QAAQJ,CAAG,EAAI,GACVI,EAAE,OAAO,gBAAgBJ,CAAG,EACrC,CC1EO,IAAIK,EAAkB,sBCkC5B,UAAY,CACX,GAAI,OA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.js","sources":["../src/trusted-types.ts","../src/origin-key.ts","../src/embed-loader.ts"],"sourcesContent":["/**\n * The embed's one Trusted Types policy, `qaid-embed`.\n *\n * On a page that sets `require-trusted-types-for 'script'`, assigning a plain\n * string to `script.src` throws. The embed computes every script URL it sets\n * itself (its own stage-two file, the quests module), so it passes each one\n * through this policy, which only signs URLs the embed registered a moment\n * before. A partner allows it with `trusted-types qaid-embed`.\n *\n * The policy is created once per page and kept on `window`, because embed.js,\n * the bundle it loads, and quests-embed (which keeps its own copy of this\n * file) all want the same name, and a page's `trusted-types` directive\n * refuses a second policy of one name unless it says `'allow-duplicates'`.\n *\n * When the browser has no Trusted Types, or the page's directive does not\n * list `qaid-embed`, the URL comes back as a plain string. The assignment\n * then works or throws exactly as it would have; callers catch it.\n *\n * ES5-clean on purpose: embed.js, which runs on the oldest browsers we\n * support, bundles this file too.\n */\n\ninterface ScriptUrlPolicy {\n createScriptURL(url: string): unknown;\n /** Absent on a policy an older embed release created on this page. */\n createScript?: (text: string) => unknown;\n}\n\ninterface SharedPolicy {\n policy: ScriptUrlPolicy | null;\n allowed: Record<string, boolean>;\n /** Inline script texts (embed.js's import map) registered a moment before. */\n allowedScripts?: Record<string, boolean>;\n}\n\ninterface TrustedTypesFactory {\n createPolicy(\n name: string,\n rules: {\n createScriptURL: (url: string) => string;\n createScript: (text: string) => string;\n }\n ): ScriptUrlPolicy;\n}\n\nexport var POLICY_NAME = \"qaid-embed\";\nvar KEY = \"__qaidEmbedTrustedTypes\";\n\nfunction shared(): SharedPolicy | null {\n if (typeof window === \"undefined\") return null;\n var w = window as unknown as Record<string, unknown>;\n var tt = w.trustedTypes as TrustedTypesFactory | undefined;\n if (!tt || typeof tt.createPolicy !== \"function\") return null;\n var existing = w[KEY] as SharedPolicy | undefined;\n if (existing) return existing;\n\n var allowed: Record<string, boolean> = Object.create(null);\n var allowedScripts: Record<string, boolean> = Object.create(null);\n var policy: ScriptUrlPolicy | null = null;\n try {\n policy = tt.createPolicy(POLICY_NAME, {\n createScriptURL: function (url: string): string {\n if (allowed[url] === true) return url;\n throw new TypeError(\"qaid-embed: refused script URL \" + url);\n },\n createScript: function (text: string): string {\n if (allowedScripts[text] === true) return text;\n throw new TypeError(\"qaid-embed: refused inline script\");\n },\n });\n } catch (e) {\n // The page's trusted-types directive does not list qaid-embed.\n policy = null;\n }\n var state: SharedPolicy = { policy: policy, allowed: allowed, allowedScripts: allowedScripts };\n try {\n Object.defineProperty(w, KEY, { value: state, configurable: true });\n } catch (e) {\n /* frozen window: keep it local */\n }\n return state;\n}\n\n/**\n * A value for `script.src`: a TrustedScriptURL from the `qaid-embed` policy\n * when one exists, else the string itself.\n */\nexport function trustedScriptUrl(url: string): string {\n var s = shared();\n if (!s || !s.policy) return url;\n s.allowed[url] = true;\n return s.policy.createScriptURL(url) as string;\n}\n\n/**\n * A value for an inline script's `text`: a TrustedScript from the `qaid-embed`\n * policy when one exists, else the string itself. Only embed.js's import map\n * uses it. Throws when the page's policy can't sign scripts (one an older\n * release created); the caller then takes its fallback.\n */\nexport function trustedScript(text: string): string {\n var s = shared();\n if (!s || !s.policy) return text;\n if (!s.allowedScripts || typeof s.policy.createScript !== \"function\") {\n throw new TypeError(\"qaid-embed: this page's policy cannot sign scripts\");\n }\n s.allowedScripts[text] = true;\n return s.policy.createScript(text) as string;\n}\n\n/** @internal Test seam: forget the page's policy. */\nexport function _resetTrustedTypes(): void {\n if (typeof window === \"undefined\") return;\n try {\n delete (window as unknown as Record<string, unknown>)[KEY];\n } catch (e) {\n /* nothing to forget */\n }\n}\n","/**\n * The property embed.js sets on the tag it injects, pointing back at the\n * customer's own `<script src=\".../embed.js\">`. An expando, not an attribute:\n * markup injected into the page can't forge it. Its own module so embed.js\n * (ES5, tiny) can share it with the bootstrap without pulling the bootstrap in.\n */\nexport var ORIGIN_KEY_NAME = \"__qaidThumbsOrigin\";\n","/**\n * Single-tag embed loader (`dist/embed.js`).\n *\n * A drop-in classic `<script>` that works in every browser. It feature-detects\n * ES-module support and injects the right build, so the page author never has\n * to think about compatibility:\n *\n * - modern browsers → the progressive ESM loader (`loader.js`): a small core,\n * with screenshot / video / annotation / targeting loading on demand.\n * - older browsers → the all-in-one UMD bundle (`qaid.umd.cjs`).\n *\n * The injected build initializes itself from the `data-*` attributes copied\n * across from this tag (or from a `<script type=\"application/json\">` config\n * block already on the page), so exactly one embed is created either way.\n *\n * Usage:\n * <script src=\"https://unpkg.com/@qaiddev/thumbs-embed/dist/embed.js\"\n * data-endpoint=\"/api/feedback\"></script>\n *\n * (Distinct from `loader.ts`/`loader.js`, the ESM-only progressive entry this\n * one delegates to on modern browsers.)\n *\n * Pinned with Subresource Integrity (`integrity=\"sha384-…\"` on this tag),\n * every file it loads after itself is hash-checked too, with hashes baked in\n * at build time (vite.config.embed.ts):\n *\n * - Where the browser enforces import-map `integrity` (Chrome 127+,\n * Safari 18+, Firefox 138+), it adds an import map listing the sha384 of\n * loader.js and every lazy chunk, then loads the small progressive build.\n * The browser refuses any chunk whose bytes differ.\n * - Everywhere else it loads the single-file UMD bundle with its own hash.\n *\n * No browser lets a page ask whether import-map integrity is enforced, so it\n * finds out: the map also lists integrity-probe.js under a hash that can never\n * match, and it loads that file first. A browser that enforces the map refuses\n * it (onerror: take the progressive build); one that ignores the map, or a\n * page whose CSP blocks the inline map, runs it (onload: take the UMD bundle).\n * A refusal means the check is live, never that it is missing, so a pinned tag\n * never loads an unchecked file. The cost is one tiny request and one console\n * line about the probe's digest.\n *\n * IMPORTANT: this file must stay ES5-clean and dependency-free. It is the one\n * script that also runs on the legacy browsers we fall back for, so it can't\n * use syntax (arrow fns, const/let, template literals) they'd choke on before\n * the fallback ever loads. Written with var/function on purpose.\n */\n\nimport { trustedScript, trustedScriptUrl } from \"./trusted-types\";\nimport { ORIGIN_KEY_NAME } from \"./origin-key\";\n\n/** sha384 of qaid.umd.cjs, set by vite.config.embed.ts. Empty in tests. */\ndeclare const __QAID_UMD_INTEGRITY__: string | undefined;\n/** sha384 of loader.js and every chunk, keyed by path under dist/. Empty in tests. */\ndeclare const __QAID_MODULE_INTEGRITY__: Record<string, string> | undefined;\n/** A sha384 integrity-probe.js never has. */\ndeclare const __QAID_PROBE_MISMATCH__: string | undefined;\n\n/** The probe file, beside embed.js. */\nvar PROBE_FILE = \"integrity-probe.js\";\n\n(function () {\n if (typeof document === \"undefined\") return;\n\n // Locate this script tag: prefer document.currentScript (valid for a plain\n // classic script), else find the last <script> whose src looks like embed.js.\n function findSelf(): HTMLScriptElement | null {\n var cur = document.currentScript as HTMLScriptElement | null;\n if (cur && cur.src) return cur;\n var scripts = document.getElementsByTagName(\"script\");\n for (var i = scripts.length - 1; i >= 0; i--) {\n var src = scripts[i].src || \"\";\n if (src.indexOf(\"thumbs-embed\") !== -1 && /\\/embed(\\.min)?\\.js(\\?|#|$)/.test(src)) {\n return scripts[i];\n }\n }\n return null;\n }\n\n var self = findSelf();\n if (!self || !self.src) return;\n\n // Base = the directory that holds embed.js, e.g.\n // \"https://unpkg.com/@qaiddev/thumbs-embed/dist/\". loader.js's own relative\n // chunk imports then resolve against the same (CDN-versioned) base.\n var base = self.src.substring(0, self.src.lastIndexOf(\"/\") + 1);\n\n var supportsModules = \"noModule\" in HTMLScriptElement.prototype;\n\n var entry = document.createElement(\"script\");\n\n // Carry the config across so the injected build's auto-init sees it.\n var attrs = self.attributes;\n for (var j = 0; j < attrs.length; j++) {\n var a = attrs[j];\n if (a.name.indexOf(\"data-\") === 0) entry.setAttribute(a.name, a.value);\n }\n\n // Lets the injected build find this tag, for the JSON config block beside\n // it. A property, not an attribute, so page markup can't fake it.\n (entry as unknown as Record<string, unknown>)[ORIGIN_KEY_NAME] = self;\n\n var umdIntegrity = typeof __QAID_UMD_INTEGRITY__ === \"string\" ? __QAID_UMD_INTEGRITY__ : \"\";\n var moduleIntegrity =\n typeof __QAID_MODULE_INTEGRITY__ === \"object\" && __QAID_MODULE_INTEGRITY__ ? __QAID_MODULE_INTEGRITY__ : null;\n var probeMismatch = typeof __QAID_PROBE_MISMATCH__ === \"string\" ? __QAID_PROBE_MISMATCH__ : \"\";\n var pinned = !!self.getAttribute(\"integrity\") && !!umdIntegrity;\n\n function warn(message: string): void {\n if (typeof console !== \"undefined\") console.warn(\"[thumbs-embed] \" + message);\n }\n\n function setSrc(el: HTMLScriptElement, url: string): boolean {\n try {\n el.src = trustedScriptUrl(url);\n return true;\n } catch (e) {\n // A Trusted Types page that doesn't allow the qaid-embed policy.\n warn(\"Trusted Types blocked \" + url + \". Add `trusted-types qaid-embed` to the page's CSP.\");\n return false;\n }\n }\n\n function append(el: HTMLElement): void {\n (document.head || document.documentElement).appendChild(el);\n }\n\n function loadModules(hash: string): void {\n entry.type = \"module\";\n if (hash) {\n entry.integrity = hash;\n entry.crossOrigin = \"anonymous\";\n }\n if (setSrc(entry, base + \"loader.js\")) append(entry);\n }\n\n function loadUmd(hash: string): void {\n // Classic bundle: defer so it runs after the document is parsed, matching\n // the module entry's deferred timing.\n entry.defer = true;\n if (hash) {\n entry.integrity = hash;\n entry.crossOrigin = \"anonymous\";\n }\n if (setSrc(entry, base + \"qaid.umd.cjs\")) append(entry);\n }\n\n function canMapImports(): boolean {\n var S = HTMLScriptElement as unknown as { supports?: (type: string) => boolean };\n return typeof S.supports === \"function\" && S.supports(\"importmap\");\n }\n\n // Pinned on a module browser: try the hashed progressive build, else UMD.\n function loadPinned(): void {\n var hashes = moduleIntegrity as Record<string, string>;\n var map: { integrity: Record<string, string> } = { integrity: {} };\n for (var path in hashes) {\n if (Object.prototype.hasOwnProperty.call(hashes, path)) map.integrity[base + path] = hashes[path];\n }\n map.integrity[base + PROBE_FILE] = probeMismatch;\n\n var importMap = document.createElement(\"script\");\n importMap.type = \"importmap\";\n try {\n importMap.text = trustedScript(JSON.stringify(map));\n } catch (e) {\n loadUmd(umdIntegrity);\n return;\n }\n append(importMap);\n\n var probe = document.createElement(\"script\");\n probe.type = \"module\";\n probe.crossOrigin = \"anonymous\";\n var settled = false;\n function settle(enforced: boolean): void {\n if (settled) return;\n settled = true;\n if (probe.parentNode) probe.parentNode.removeChild(probe);\n if (enforced) loadModules(hashes[\"loader.js\"]);\n else loadUmd(umdIntegrity);\n }\n probe.onerror = function () {\n settle(true);\n };\n probe.onload = function () {\n settle(false);\n };\n try {\n probe.src = trustedScriptUrl(base + PROBE_FILE);\n } catch (e) {\n loadUmd(umdIntegrity);\n return;\n }\n append(probe);\n }\n\n if (!supportsModules) {\n loadUmd(pinned ? umdIntegrity : \"\");\n } else if (!pinned) {\n loadModules(\"\");\n } else if (moduleIntegrity && moduleIntegrity[\"loader.js\"] && probeMismatch && canMapImports()) {\n loadPinned();\n } else {\n loadUmd(umdIntegrity);\n }\n})();\n"],"names":["POLICY_NAME","KEY","shared","w","tt","existing","allowed","allowedScripts","policy","url","text","e","state","trustedScriptUrl","s","trustedScript","ORIGIN_KEY_NAME","PROBE_FILE","findSelf","cur","scripts","i","src","self","base","supportsModules","entry","attrs","j","a","umdIntegrity","moduleIntegrity","define_QAID_MODULE_INTEGRITY_default","probeMismatch","pinned","warn","message","setSrc","el","append","loadModules","hash","loadUmd","canMapImports","S","loadPinned","hashes","map","path","importMap","probe","settled","settle","enforced"],"mappings":"yBA6CO,IAAIA,EAAc,aACrBC,EAAM,0BAEV,SAASC,GAA8B,CACrC,GAAI,OAAO,QAAW,YAAa,OAAO,KAC1C,IAAIC,EAAI,OACJC,EAAKD,EAAE,aACX,GAAI,CAACC,GAAM,OAAOA,EAAG,cAAiB,WAAY,OAAO,KACzD,IAAIC,EAAWF,EAAEF,CAAG,EACpB,GAAII,EAAU,OAAOA,EAErB,IAAIC,EAAmC,OAAO,OAAO,IAAI,EACrDC,EAA0C,OAAO,OAAO,IAAI,EAC5DC,EAAiC,KACrC,GAAI,CACFA,EAASJ,EAAG,aAAaJ,EAAa,CACpC,gBAAiB,SAAUS,EAAqB,CAC9C,GAAIH,EAAQG,CAAG,IAAM,GAAM,OAAOA,EAClC,MAAM,IAAI,UAAU,kCAAoCA,CAAG,CAC7D,EAC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