@nuniapp/widget 0.1.2 → 0.1.4

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.
@@ -0,0 +1,66 @@
1
+ //#region ../shared/src/id.ts
2
+ const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
3
+ const PROJECT_ID_PATTERN = new RegExp(`^nuni_[${ALPHABET}]{22}$`);
4
+ /** Random base58 string using the platform CSPRNG (browser, Node, Convex). */
5
+ function randomBase58(length) {
6
+ const bytes = new Uint8Array(length);
7
+ crypto.getRandomValues(bytes);
8
+ let out = "";
9
+ for (const byte of bytes) {
10
+ let b = byte;
11
+ while (b >= 232) {
12
+ const retry = /* @__PURE__ */ new Uint8Array(1);
13
+ crypto.getRandomValues(retry);
14
+ b = retry[0];
15
+ }
16
+ out += ALPHABET[b % 58];
17
+ }
18
+ return out;
19
+ }
20
+ function isProjectId(value) {
21
+ return typeof value === "string" && PROJECT_ID_PATTERN.test(value);
22
+ }
23
+ /** Secret used by anonymous commenters to edit/delete their own comments. */
24
+ function generateSecret() {
25
+ return randomBase58(32);
26
+ }
27
+ //#endregion
28
+ //#region ../shared/src/limits.ts
29
+ const LIMITS = {
30
+ bodyMaxLength: 2e3,
31
+ nameMaxLength: 50,
32
+ unclaimedCommentCap: 500,
33
+ maxOriginsPerProject: 20,
34
+ sessionTtlMs: 2592e6,
35
+ anchorTextMaxLength: 120,
36
+ /** Per page, the widget loads this many newest open and resolved comments. */
37
+ pageOpenLimit: 1e3,
38
+ pageResolvedLimit: 200,
39
+ /** Most console or network entries kept with one comment. */
40
+ contextEntryMax: 20,
41
+ contextMessageMaxLength: 500,
42
+ /** Trimmed outerHTML of the commented element. */
43
+ domSnippetMaxLength: 4e3,
44
+ screenshotMaxBytes: 6e5,
45
+ /** How long after posting the author can still attach the screenshot. */
46
+ screenshotUploadWindowMs: 3e5
47
+ };
48
+ //#endregion
49
+ //#region ../shared/src/privacy.ts
50
+ /**
51
+ * Site owners mark private areas with this attribute. Their text never
52
+ * reaches Nuni: not in the pin anchor (which is public), the markup snippet
53
+ * or the screenshot.
54
+ */
55
+ const MASK_ATTRIBUTE = "data-nuni-mask";
56
+ const MASK_SELECTOR = `[${MASK_ATTRIBUTE}]`;
57
+ //#endregion
58
+ //#region src/mark.ts
59
+ /**
60
+ * Marks Nuni's own screenshot requests (fonts and images it inlines), so the
61
+ * network collector can skip them without muting the page. `Symbol.for` is
62
+ * shared by the widget and the separately loaded screenshot script.
63
+ */
64
+ const CAPTURE_MARK = Symbol.for("nuni.capture");
65
+ //#endregion
66
+ export { generateSecret as a, LIMITS as i, MASK_ATTRIBUTE as n, isProjectId as o, MASK_SELECTOR as r, CAPTURE_MARK as t };
@@ -0,0 +1,14 @@
1
+ (function(){let e={bodyMaxLength:2e3,nameMaxLength:50,unclaimedCommentCap:500,maxOriginsPerProject:20,sessionTtlMs:2592e6,anchorTextMaxLength:120,pageOpenLimit:1e3,pageResolvedLimit:200,contextEntryMax:20,contextMessageMaxLength:500,domSnippetMaxLength:4e3,screenshotMaxBytes:6e5,screenshotUploadWindowMs:3e5},t=`data-nuni-mask`,n=`[modern-screenshot]`,r=typeof window<`u`,i=r&&`Worker`in window;r&&`atob`in window,r&&`btoa`in window;let a=r?window.navigator?.userAgent:``,o=a.includes(`Chrome`),s=a.includes(`AppleWebKit`)&&!o,c=a.includes(`Firefox`),l=e=>e&&`__CONTEXT__`in e,u=e=>e.constructor.name===`CSSFontFaceRule`,d=e=>e.constructor.name===`CSSImportRule`,f=e=>e.constructor.name===`CSSLayerBlockRule`,p=e=>e.nodeType===1,m=e=>typeof e.className==`object`,h=e=>e.tagName===`image`,g=e=>e.tagName===`use`,_=e=>p(e)&&e.style!==void 0&&!m(e),v=e=>e.nodeType===8,y=e=>e.nodeType===3,b=e=>e.tagName===`IMG`,x=e=>e.tagName===`VIDEO`,S=e=>e.tagName===`CANVAS`,C=e=>e.tagName===`TEXTAREA`,ee=e=>e.tagName===`INPUT`,te=e=>e.tagName===`STYLE`,ne=e=>e.tagName===`SCRIPT`,w=e=>e.tagName===`SELECT`,re=e=>e.tagName===`SLOT`,ie=e=>e.tagName===`IFRAME`,ae=(...e)=>console.warn(n,...e);function oe(e){let t=e?.createElement?.(`canvas`);return t&&(t.height=t.width=1),!!t&&`toDataURL`in t&&!!t.toDataURL(`image/webp`).includes(`image/webp`)}let T=e=>e.startsWith(`data:`);function E(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(r&&e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i)||!r)return e;let n=D().implementation.createHTMLDocument(),i=n.createElement(`base`),a=n.createElement(`a`);return n.head.appendChild(i),n.body.appendChild(a),t&&(i.href=t),a.href=e,a.href}function D(e){return(e&&p(e)?e?.ownerDocument:e)??window.document}let O=`http://www.w3.org/2000/svg`;function se(e,t,n){let r=D(n).createElementNS(O,`svg`);return r.setAttributeNS(null,`width`,e.toString()),r.setAttributeNS(null,`height`,t.toString()),r.setAttributeNS(null,`viewBox`,`0 0 ${e} ${t}`),r}function ce(e,t){let n=new XMLSerializer().serializeToString(e);return t&&(n=n.replace(/[\u0000-\u0008\v\f\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/gu,``)),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}function le(e,t){return new Promise((n,r)=>{let i=new FileReader;i.onload=()=>n(i.result),i.onerror=()=>r(i.error),i.onabort=()=>r(/* @__PURE__ */ Error(`Failed read blob to ${t}`)),t===`dataUrl`?i.readAsDataURL(e):t===`arrayBuffer`&&i.readAsArrayBuffer(e)})}let ue=e=>le(e,`dataUrl`);function k(e,t){let n=D(t).createElement(`img`);return n.decoding=`sync`,n.loading=`eager`,n.src=e,n}function A(e,t){return new Promise(n=>{let{timeout:r,ownerDocument:i,onError:a,onWarn:o}=t??{},s=typeof e==`string`?k(e,D(i)):e,c=null,l=null;function u(){n(s),c&&clearTimeout(c),l?.()}if(r&&(c=setTimeout(u,r)),x(s)){let e=s.currentSrc||s.src;if(!e)return s.poster?A(s.poster,t).then(n):u();if(s.readyState>=2)return u();let r=u,i=t=>{o?.(`Failed video load`,e,t),a?.(t),u()};l=()=>{s.removeEventListener(`loadeddata`,r),s.removeEventListener(`error`,i)},s.addEventListener(`loadeddata`,r,{once:!0}),s.addEventListener(`error`,i,{once:!0})}else{let e=h(s)?s.href.baseVal:s.currentSrc||s.src;if(!e)return u();let t=async()=>{if(b(s)&&`decode`in s)try{await s.decode()}catch(t){o?.(`Failed to decode image, trying to render anyway`,s.dataset.originalSrc||e,t)}u()},n=t=>{o?.(`Failed image load`,s.dataset.originalSrc||e,t),u()};if(b(s)&&s.complete)return t();l=()=>{s.removeEventListener(`load`,t),s.removeEventListener(`error`,n)},s.addEventListener(`load`,t,{once:!0}),s.addEventListener(`error`,n,{once:!0})}})}async function de(e,t){_(e)&&(b(e)||x(e)?await A(e,t):await Promise.all([`img`,`video`].flatMap(n=>Array.from(e.querySelectorAll(n)).map(e=>A(e,t)))))}let j=/* @__PURE__ */ function(){let e=0,t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)}();function M(e){return e?.split(`,`).map(e=>e.trim().replace(/"|'/g,``).toLowerCase()).filter(Boolean)}let N=0;function fe(e){let t=`${n}[#${N}]`;return N++,{time:n=>e&&console.time(`${t} ${n}`),timeEnd:n=>e&&console.timeEnd(`${t} ${n}`),warn:(...t)=>e&&ae(...t)}}function pe(e){return{cache:e?`no-cache`:`force-cache`}}async function P(e,t){return l(e)?e:me(e,{...t,autoDestruct:!0})}async function me(e,t){let{scale:n=1,workerUrl:a,workerNumber:o=1}=t||{},s=!!t?.debug,c=t?.features??!0,l=e.ownerDocument??(r?window.document:void 0),u=e.ownerDocument?.defaultView??(r?window:void 0),d=/* @__PURE__ */ new Map,f={width:0,height:0,quality:1,type:`image/png`,scale:n,backgroundColor:null,style:null,filter:null,maximumCanvasSize:0,timeout:3e4,progress:null,debug:s,fetch:{requestInit:pe(t?.fetch?.bypassingCache),placeholderImage:`data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7`,bypassingCache:!1,...t?.fetch},fetchFn:null,font:{},drawImageInterval:100,workerUrl:null,workerNumber:o,onCloneEachNode:null,onCloneNode:null,onEmbedNode:null,onCreateForeignObjectSvg:null,includeStyleProperties:null,autoDestruct:!1,...t,__CONTEXT__:!0,log:fe(s),node:e,ownerDocument:l,ownerWindow:u,dpi:n===1?null:96*n,svgStyleElement:F(l),svgDefsElement:l?.createElementNS(O,`defs`),svgStyles:/* @__PURE__ */ new Map,defaultComputedStyles:/* @__PURE__ */ new Map,workers:[...Array.from({length:i&&a&&o?o:0})].map(()=>{try{let e=new Worker(a);return e.onmessage=async e=>{let{url:t,result:n}=e.data;n?d.get(t)?.resolve?.(n):d.get(t)?.reject?.(/* @__PURE__ */ Error(`Error receiving message from worker: ${t}`))},e.onmessageerror=e=>{let{url:t}=e.data;d.get(t)?.reject?.(/* @__PURE__ */ Error(`Error receiving message from worker: ${t}`))},e}catch(e){return f.log.warn(`Failed to new Worker`,e),null}}).filter(Boolean),fontFamilies:/* @__PURE__ */ new Map,fontCssTexts:/* @__PURE__ */ new Map,acceptOfImage:`${[oe(l)&&`image/webp`,`image/svg+xml`,`image/*`,`*/*`].filter(Boolean).join(`,`)};q=0.8`,requests:d,drawImageCount:0,tasks:[],features:c,isEnable:e=>e===`restoreScrollPosition`?typeof c==`boolean`?!1:c[e]??!1:typeof c==`boolean`?c:c[e]??!0,shadowRoots:[]};f.log.time(`wait until load`),await de(e,{timeout:f.timeout,onWarn:f.log.warn}),f.log.timeEnd(`wait until load`);let{width:p,height:m}=he(e,f);return f.width=p,f.height=m,f}function F(e){if(!e)return;let t=e.createElement(`style`),n=t.ownerDocument.createTextNode(`
2
+ .______background-clip--text {
3
+ background-clip: text;
4
+ -webkit-background-clip: text;
5
+ }
6
+ `);return t.appendChild(n),t}function he(e,t){let{width:n,height:r}=t;if(p(e)&&(!n||!r)){let t=e.getBoundingClientRect();n=n||t.width||Number(e.getAttribute(`width`))||0,r=r||t.height||Number(e.getAttribute(`height`))||0}return{width:n,height:r}}async function ge(e,t){let{log:n,timeout:r,drawImageCount:i,drawImageInterval:a}=t;n.time(`image to canvas`);let o=await A(e,{timeout:r,onWarn:t.log.warn}),{canvas:s,context2d:c}=_e(e.ownerDocument,t),l=()=>{try{c?.drawImage(o,0,0,s.width,s.height)}catch(e){t.log.warn(`Failed to drawImage`,e)}};if(l(),t.isEnable(`fixSvgXmlDecode`))for(let e=0;e<i;e++)await new Promise(t=>{setTimeout(()=>{c?.clearRect(0,0,s.width,s.height),l(),t()},e+a)});return t.drawImageCount=0,n.timeEnd(`image to canvas`),s}function _e(e,t){let{width:n,height:r,scale:i,backgroundColor:a,maximumCanvasSize:o}=t,s=e.createElement(`canvas`);s.width=Math.floor(n*i),s.height=Math.floor(r*i),s.style.width=`${n}px`,s.style.height=`${r}px`,o&&(s.width>o||s.height>o)&&(s.width>o&&s.height>o?s.width>s.height?(s.height*=o/s.width,s.width=o):(s.width*=o/s.height,s.height=o):s.width>o?(s.height*=o/s.width,s.width=o):(s.width*=o/s.height,s.height=o));let c=s.getContext(`2d`);return c&&a&&(c.fillStyle=a,c.fillRect(0,0,s.width,s.height)),{canvas:s,context2d:c}}function I(e,t){if(e.ownerDocument)try{let t=e.toDataURL();if(t!==`data:,`)return k(t,e.ownerDocument)}catch(e){t.log.warn(`Failed to clone canvas`,e)}let n=e.cloneNode(!1),r=e.getContext(`2d`),i=n.getContext(`2d`);try{return r&&i&&i.putImageData(r.getImageData(0,0,e.width,e.height),0,0),n}catch(e){t.log.warn(`Failed to clone canvas`,e)}return n}function ve(e,t){try{if(e?.contentDocument?.documentElement)return H(e.contentDocument.documentElement,t)}catch(e){t.log.warn(`Failed to clone iframe`,e)}return e.cloneNode(!1)}function ye(e){let t=e.cloneNode(!1);return e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=``),t.loading===`lazy`&&(t.loading=`eager`),t}async function be(e,t){if(e.ownerDocument&&!e.currentSrc&&e.poster)return k(e.poster,e.ownerDocument);let n=e.cloneNode(!1);n.crossOrigin=`anonymous`,e.currentSrc&&e.currentSrc!==e.src&&(n.src=e.currentSrc);let r=n.ownerDocument;if(r){let i=!0;if(await A(n,{onError:()=>i=!1,onWarn:t.log.warn}),!i)return e.poster?k(e.poster,e.ownerDocument):n;n.currentTime=e.currentTime,await new Promise(e=>{n.addEventListener(`seeked`,e,{once:!0})});let a=r.createElement(`canvas`);a.width=e.offsetWidth,a.height=e.offsetHeight;try{let e=a.getContext(`2d`);e&&e.drawImage(n,0,0,a.width,a.height)}catch(r){return t.log.warn(`Failed to clone video`,r),e.poster?k(e.poster,e.ownerDocument):n}return I(a,t)}return n}function xe(e,t){return S(e)?I(e,t):ie(e)?ve(e,t):b(e)?ye(e):x(e)?be(e,t):e.cloneNode(!1)}function Se(e){let t=e.sandbox;if(!t){let{ownerDocument:n}=e;try{n&&(t=n.createElement(`iframe`),t.id=`__SANDBOX__${j()}`,t.width=`0`,t.height=`0`,t.style.visibility=`hidden`,t.style.position=`fixed`,n.body.appendChild(t),t.srcdoc=`<!DOCTYPE html><meta charset="UTF-8"><title></title><body>`,e.sandbox=t)}catch(t){e.log.warn(`Failed to getSandBox`,t)}}return t}let Ce=[`width`,`height`,`-webkit-text-fill-color`],we=[`stroke`,`fill`];function L(e,t,n){let{defaultComputedStyles:r}=n,i=e.nodeName.toLowerCase(),a=m(e)&&i!==`svg`,o=a?we.map(t=>[t,e.getAttribute(t)]).filter(([,e])=>e!==null):[],s=[a&&`svg`,i,o.map((e,t)=>`${e}=${t}`).join(`,`),t].filter(Boolean).join(`:`);if(r.has(s))return r.get(s);let c=Se(n)?.contentWindow;if(!c)return/* @__PURE__ */ new Map;let l=c?.document,u,d;a?(u=l.createElementNS(O,`svg`),d=u.ownerDocument.createElementNS(u.namespaceURI,i),o.forEach(([e,t])=>{d.setAttributeNS(null,e,t)}),u.appendChild(d)):u=d=l.createElement(i),d.textContent=` `,l.body.appendChild(u);let f=c.getComputedStyle(d,t),p=/* @__PURE__ */ new Map;for(let e=f.length,t=0;t<e;t++){let e=f.item(t);Ce.includes(e)||p.set(e,f.getPropertyValue(e))}return l.body.removeChild(u),r.set(s,p),p}function R(e,t,n){let r=/* @__PURE__ */ new Map,i=[],a=/* @__PURE__ */ new Map;if(n)for(let e of n)o(e);else for(let t=e.length,n=0;n<t;n++)o(e.item(n));for(let e=i.length,t=0;t<e;t++)a.get(i[t])?.forEach((e,t)=>r.set(t,e));function o(n){let o=e.getPropertyValue(n),s=e.getPropertyPriority(n),c=n.lastIndexOf(`-`),l=c>-1?n.substring(0,c):void 0;if(l){let e=a.get(l);e||(e=/* @__PURE__ */ new Map,a.set(l,e)),e.set(n,[o,s])}(t.get(n)!==o||s)&&(l?i.push(l):r.set(n,[o,s]))}return r}function Te(e,t,n,r){let{ownerWindow:i,includeStyleProperties:a,currentParentNodeStyle:s}=r,c=t.style,l=i.getComputedStyle(e),u=L(e,null,r);s?.forEach((e,t)=>{u.delete(t)});let d=R(l,u,a);d.delete(`transition-property`),d.delete(`all`),d.delete(`d`),d.delete(`content`),n&&(d.delete(`position`),d.delete(`margin-top`),d.delete(`margin-right`),d.delete(`margin-bottom`),d.delete(`margin-left`),d.delete(`margin-block-start`),d.delete(`margin-block-end`),d.delete(`margin-inline-start`),d.delete(`margin-inline-end`),d.set(`box-sizing`,[`border-box`,``])),d.get(`background-clip`)?.[0]===`text`&&t.classList.add(`______background-clip--text`),o&&(d.has(`font-kerning`)||d.set(`font-kerning`,[`normal`,``]),(d.get(`overflow-x`)?.[0]===`hidden`||d.get(`overflow-y`)?.[0]===`hidden`)&&d.get(`text-overflow`)?.[0]===`ellipsis`&&e.scrollWidth===e.clientWidth&&d.set(`text-overflow`,[`clip`,``]));for(let e=c.length,t=0;t<e;t++)c.removeProperty(c.item(t));return d.forEach(([e,t],n)=>{c.setProperty(n,e,t)}),d}function Ee(e,t){(C(e)||ee(e)||w(e))&&t.setAttribute(`value`,e.value)}let De=[`::before`,`::after`],Oe=[`::-webkit-scrollbar`,`::-webkit-scrollbar-button`,`::-webkit-scrollbar-thumb`,`::-webkit-scrollbar-track`,`::-webkit-scrollbar-track-piece`,`::-webkit-scrollbar-corner`,`::-webkit-resizer`];function ke(e,t,n,r,i){let{ownerWindow:a,svgStyleElement:o,svgStyles:s,currentNodeStyle:c}=r;if(!o||!a)return;function l(n){let o=a.getComputedStyle(e,n),l=o.getPropertyValue(`content`);if(!l||l===`none`)return;i?.(l),l=l.replace(/(')|(")|(counter\(.+\))/g,``);let u=[j()],d=L(e,n,r);c?.forEach((e,t)=>{d.delete(t)});let f=R(o,d,r.includeStyleProperties);f.delete(`content`),f.delete(`-webkit-locale`),f.get(`background-clip`)?.[0]===`text`&&t.classList.add(`______background-clip--text`);let p=[`content: '${l}';`];if(f.forEach(([e,t],n)=>{p.push(`${n}: ${e}${t?` !important`:``};`)}),p.length===1)return;try{t.className=[t.className,...u].join(` `)}catch(e){r.log.warn(`Failed to copyPseudoClass`,e);return}let m=p.join(`
7
+ `),h=s.get(m);h||(h=[],s.set(m,h)),h.push(`.${u[0]}${n}`)}De.forEach(l),n&&Oe.forEach(l)}let z=/* @__PURE__ */ new Set([`symbol`]);async function B(e,t,n,r,i){if(p(n)&&(te(n)||ne(n))||r.filter&&!r.filter(n))return;r.currentParentNodeStyle=z.has(t.nodeName)||z.has(n.nodeName)?void 0:r.currentNodeStyle;let a=await H(n,r,!1,i);r.isEnable(`restoreScrollPosition`)&&Ae(e,a),t.appendChild(a)}async function V(e,t,n,r){let i=e.firstChild;p(e)&&e.shadowRoot&&(i=e.shadowRoot?.firstChild,n.shadowRoots.push(e.shadowRoot));for(let a=i;a;a=a.nextSibling)if(!v(a)){if(p(a)&&re(a)&&typeof a.assignedNodes==`function`){let i=a.assignedNodes();for(let a=0;a<i.length;a++)await B(e,t,i[a],n,r)}else await B(e,t,a,n,r)}}function Ae(e,t){if(!_(e)||!_(t))return;let{scrollTop:n,scrollLeft:r}=e;if(!n&&!r)return;let{transform:i}=t.style,a=new DOMMatrix(i),{a:o,b:s,c,d:l}=a;a.a=1,a.b=0,a.c=0,a.d=1,a.translateSelf(-r,-n),a.a=o,a.b=s,a.c=c,a.d=l,t.style.transform=a.toString()}function je(e,t){let{backgroundColor:n,width:r,height:i,style:a}=t,o=e.style;if(n&&o.setProperty(`background-color`,n,`important`),r&&o.setProperty(`width`,`${r}px`,`important`),i&&o.setProperty(`height`,`${i}px`,`important`),a)for(let e in a)o[e]=a[e]}let Me=/^[\w-:]+$/;async function H(e,t,n=!1,r){let{ownerDocument:i,ownerWindow:a,fontFamilies:o,onCloneEachNode:s}=t;if(i&&y(e))return r&&/\S/.test(e.data)&&r(e.data),i.createTextNode(e.data);if(i&&a&&p(e)&&(_(e)||m(e))){let r=await xe(e,t);if(t.isEnable(`removeAbnormalAttributes`)){let e=r.getAttributeNames();for(let t=e.length,n=0;n<t;n++){let t=e[n];Me.test(t)||r.removeAttribute(t)}}let i=t.currentNodeStyle=Te(e,r,n,t);n&&je(r,t);let a=!1;if(t.isEnable(`copyScrollbar`)){let t=[i.get(`overflow-x`)?.[0],i.get(`overflow-y`)?.[0]];a=t.includes(`scroll`)||(t.includes(`auto`)||t.includes(`overlay`))&&(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)}let c=i.get(`text-transform`)?.[0],l=M(i.get(`font-family`)?.[0]),u=l?e=>{c===`uppercase`?e=e.toUpperCase():c===`lowercase`?e=e.toLowerCase():c===`capitalize`&&(e=e[0].toUpperCase()+e.substring(1)),l.forEach(t=>{let n=o.get(t);n||o.set(t,n=/* @__PURE__ */ new Set),e.split(``).forEach(e=>n.add(e))})}:void 0;return ke(e,r,a,t,u),Ee(e,r),x(e)||await V(e,r,t,u),await s?.(r),r}let c=e.cloneNode(!1);return await V(e,c,t),await s?.(c),c}function U(e){if(e.ownerDocument=void 0,e.ownerWindow=void 0,e.svgStyleElement=void 0,e.svgDefsElement=void 0,e.svgStyles.clear(),e.defaultComputedStyles.clear(),e.sandbox){try{e.sandbox.remove()}catch(t){e.log.warn(`Failed to destroyContext`,t)}e.sandbox=void 0}e.workers=[],e.fontFamilies.clear(),e.fontCssTexts.clear(),e.requests.clear(),e.tasks=[],e.shadowRoots=[]}function Ne(e){let{url:t,timeout:n,responseType:r,...i}=e,a=new AbortController,o=n?setTimeout(()=>a.abort(),n):void 0;return fetch(t,{signal:a.signal,...i}).then(e=>{if(!e.ok)throw Error(`Failed fetch, not 2xx response`,{cause:e});switch(r){case`arrayBuffer`:return e.arrayBuffer();case`dataUrl`:return e.blob().then(ue);default:return e.text()}}).finally(()=>clearTimeout(o))}function W(e,t){let{url:n,requestType:r=`text`,responseType:i=`text`,imageDom:a}=t,o=n,{timeout:l,acceptOfImage:u,requests:d,fetchFn:f,fetch:{requestInit:p,bypassingCache:m,placeholderImage:h},font:g,workers:_,fontFamilies:v}=e;r===`image`&&(s||c)&&e.drawImageCount++;let y=d.get(n);if(!y){m&&m instanceof RegExp&&m.test(o)&&(o+=(/\?/.test(o)?`&`:`?`)+(/* @__PURE__ */ new Date()).getTime());let t=r.startsWith(`font`)&&g&&g.minify,c=/* @__PURE__ */ new Set;t&&r.split(`;`)[1].split(`,`).forEach(e=>{v.has(e)&&v.get(e).forEach(e=>c.add(e))});let b=t&&c.size,x={url:o,timeout:l,responseType:b?`arrayBuffer`:i,headers:r===`image`?{accept:u}:void 0,...p};y={type:r,resolve:void 0,reject:void 0,response:null},y.response=(async()=>{if(f&&r===`image`){let e=await f(n);if(e)return e}return!s&&n.startsWith(`http`)&&_.length?new Promise((e,t)=>{_[d.size&_.length-1].postMessage({rawUrl:n,...x}),y.resolve=e,y.reject=t}):Ne(x)})().catch(t=>{if(d.delete(n),r===`image`&&h)return e.log.warn(`Failed to fetch image base64, trying to use placeholder image`,o),typeof h==`string`?h:h(a);throw t}),d.set(n,y)}return y.response}async function G(e,t,n,r){if(!K(e))return e;for(let[i,a]of Pe(e,t))try{let t=await W(n,{url:a,requestType:r?`image`:`text`,responseType:`dataUrl`});e=e.replace(Fe(i),`$1${t}$3`)}catch(e){n.log.warn(`Failed to fetch css data url`,i,e)}return e}function K(e){return/url\((['"]?)([^'"]+?)\1\)/.test(e)}let q=/url\((['"]?)([^'"]+?)\1\)/g;function Pe(e,t){let n=[];return e.replace(q,(e,r,i)=>(n.push([i,E(i,t)]),e)),n.filter(([e])=>!T(e))}function Fe(e){let t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,`\\$1`);return RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,`g`)}let Ie=[`background-image`,`border-image-source`,`-webkit-border-image`,`-webkit-mask-image`,`list-style-image`];function Le(e,t){return Ie.map(n=>{let r=e.getPropertyValue(n);return!r||r===`none`?null:((s||c)&&t.drawImageCount++,G(r,null,t,!0).then(t=>{t&&r!==t&&e.setProperty(n,t,e.getPropertyPriority(n))}))}).filter(Boolean)}function Re(e,t){if(b(e)){let n=e.currentSrc||e.src;if(!T(n))return[W(t,{url:n,imageDom:e,requestType:`image`,responseType:`dataUrl`}).then(t=>{t&&(e.srcset=``,e.dataset.originalSrc=n,e.src=t||``)})];(s||c)&&t.drawImageCount++}else if(m(e)&&!T(e.href.baseVal)){let n=e.href.baseVal;return[W(t,{url:n,imageDom:e,requestType:`image`,responseType:`dataUrl`}).then(t=>{t&&(e.dataset.originalSrc=n,e.href.baseVal=t||``)})]}return[]}function ze(e,t){let{ownerDocument:n,svgDefsElement:r}=t,i=e.getAttribute(`href`)??e.getAttribute(`xlink:href`);if(!i)return[];let[a,o]=i.split(`#`);if(o){let i=`#${o}`,s=t.shadowRoots.reduce((e,t)=>e??t.querySelector(`svg ${i}`),n?.querySelector(`svg ${i}`));if(a&&e.setAttribute(`href`,i),r?.querySelector(i))return[];if(s)return r?.appendChild(s.cloneNode(!0)),[];if(a)return[W(t,{url:a,responseType:`text`}).then(e=>{r?.insertAdjacentHTML(`beforeend`,e)})]}return[]}function J(e,t){let{tasks:n}=t;p(e)&&((b(e)||h(e))&&n.push(...Re(e,t)),g(e)&&n.push(...ze(e,t))),_(e)&&n.push(...Le(e.style,t)),e.childNodes.forEach(e=>{J(e,t)})}async function Be(e,t){let{ownerDocument:n,svgStyleElement:r,fontFamilies:i,fontCssTexts:a,tasks:o,font:s}=t;if(n&&r&&i.size){if(s&&s.cssText){let e=X(s.cssText,t);r.appendChild(n.createTextNode(`${e}
8
+ `))}else{let e=Array.from(n.styleSheets).filter(e=>{try{return`cssRules`in e&&!!e.cssRules.length}catch(n){return t.log.warn(`Error while reading CSS rules from ${e.href}`,n),!1}}),s=n.implementation.createHTMLDocument(``),c=s.createElement(`style`);s.head.appendChild(c);let l=c.sheet;await Promise.all(e.flatMap(e=>Array.from(e.cssRules).map(async e=>{if(d(e)){let n=e.href,r=``;try{r=await W(t,{url:n,requestType:`text`,responseType:`text`})}catch(e){t.log.warn(`Error fetch remote css import from ${n}`,e)}let i=r.replace(q,(e,t,r)=>e.replace(r,E(r,n)));for(let e of He(i))try{l.insertRule(e,l.cssRules.length)}catch(n){t.log.warn(`Error inserting rule from remote css import`,{rule:e,error:n})}}}))),l.cssRules.length&&e.push(l);let f=[];e.forEach(e=>{Z(e.cssRules,f)}),f.filter(e=>u(e)&&K(e.style.getPropertyValue(`src`))&&M(e.style.getPropertyValue(`font-family`))?.some(e=>i.has(e))).forEach(e=>{let i=e,s=a.get(i.cssText);s?r.appendChild(n.createTextNode(`${s}
9
+ `)):o.push(G(i.cssText,i.parentStyleSheet?i.parentStyleSheet.href:null,t).then(e=>{e=X(e,t),a.set(i.cssText,e),r.appendChild(n.createTextNode(`${e}
10
+ `))}))})}}}let Ve=/(\/\*[\s\S]*?\*\/)/g,Y=/((@.*?keyframes [\s\S]*?){([\s\S]*?}\s*?)})/gi;function He(e){if(e==null)return[];let t=[],n=e.replace(Ve,``);for(;;){let e=Y.exec(n);if(!e)break;t.push(e[0])}n=n.replace(Y,``);let r=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,i=/* @__PURE__ */ RegExp(`((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})`,`gi`);for(;;){let e=r.exec(n);if(e)i.lastIndex=r.lastIndex;else if(e=i.exec(n),e)r.lastIndex=i.lastIndex;else break;t.push(e[0])}return t}let Ue=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,We=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function X(e,t){let{font:n}=t,r=n?n?.preferredFormat:void 0;return r?e.replace(We,e=>{for(;;){let[t,,n]=Ue.exec(e)||[];if(!n)return``;if(n===r)return`src: ${t};`}}):e}function Z(e,t=[]){for(let n of Array.from(e))f(n)?t.push(...Z(n.cssRules)):`cssRules`in n?Z(n.cssRules,t):t.push(n);return t}let Ge=/\bx?link:?href\s*=\s*["'](?!data:)[^"']+["']/i;function Ke(e){return Ge.test(e.innerHTML)}async function qe(e,t){let n=await P(e,t);if(p(n.node)&&m(n.node)&&!Ke(n.node))return n.node;let{ownerDocument:r,log:i,tasks:a,svgStyleElement:o,svgDefsElement:s,svgStyles:c,font:l,progress:u,autoDestruct:d,onCloneNode:f,onEmbedNode:h,onCreateForeignObjectSvg:g}=n;i.time(`clone node`);let _=await H(n.node,n,!0);if(o&&r){let e=``;c.forEach((t,n)=>{e+=`${t.join(`,
11
+ `)} {
12
+ ${n}
13
+ }
14
+ `}),o.appendChild(r.createTextNode(e))}i.timeEnd(`clone node`),await f?.(_),l!==!1&&p(_)&&(i.time(`embed web font`),await Be(_,n),i.timeEnd(`embed web font`)),i.time(`embed node`),J(_,n);let v=a.length,y=0,b=async()=>{for(;;){let e=a.pop();if(!e)break;try{await e}catch(e){n.log.warn(`Failed to run task`,e)}u?.(++y,v)}};u?.(y,v),await Promise.all([...Array.from({length:4})].map(b)),i.timeEnd(`embed node`),await h?.(_);let x=Je(_,n);return s&&x.insertBefore(s,x.children[0]),o&&x.insertBefore(o,x.children[0]),d&&U(n),await g?.(x),x}function Je(e,t){let{width:n,height:r}=t,i=se(n,r,e.ownerDocument),a=i.ownerDocument.createElementNS(i.namespaceURI,`foreignObject`);return a.setAttributeNS(null,`x`,`0%`),a.setAttributeNS(null,`y`,`0%`),a.setAttributeNS(null,`width`,`100%`),a.setAttributeNS(null,`height`,`100%`),a.append(e),i.appendChild(a),i}async function Ye(e,t){let n=await P(e,t),r=await qe(n),i=ce(r,n.isEnable(`removeControlCharacter`));return n.autoDestruct||(n.svgStyleElement=F(n.ownerDocument),n.svgDefsElement=n.ownerDocument?.createElementNS(O,`defs`),n.svgStyles.clear()),await ge(k(i,r.ownerDocument),n)}let Xe=Symbol.for(`nuni.capture`),Q=4096,Ze=/* @__PURE__ */ new Set([`text`,`file`,`email`,`tel`,`url`,`search`,`password`,`number`,`date`,`datetime-local`,`month`,`week`,`time`]),$=e=>({left:e.left-48,top:e.top-48,right:e.right+48,bottom:e.bottom+48});function Qe(e){let t=e.ownerDocument,n=$(e.getBoundingClientRect()),r=e;for(;r.parentElement&&r.parentElement!==t.body;){let e=r.getBoundingClientRect();if(e.left<=n.left&&e.top<=n.top&&e.right>=n.right&&e.bottom>=n.bottom)break;r=r.parentElement}return r}function $e(e,t){let{display:n}=getComputedStyle(e),r=n===`block`||n===`list-item`,i=e.getAttribute(`style`);r&&e.setAttribute(`style`,`${i?`${i};`:``}display: flow-root !important`);try{let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=$(r);return{box:n,target:r,masks:tt(e),crop:{left:Math.max(n.left,i.left),top:Math.max(n.top,i.top),right:Math.min(n.right,i.right),bottom:Math.min(n.bottom,i.bottom)}}}finally{r&&(i===null?e.removeAttribute(`style`):e.setAttribute(`style`,i))}}function et(e){let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=e=>parseFloat(e)||0;return{left:t.left+r(n.borderLeftWidth)+r(n.paddingLeft),top:t.top+r(n.borderTopWidth)+r(n.paddingTop),right:t.right-r(n.borderRightWidth)-r(n.paddingRight),bottom:t.bottom-r(n.borderBottomWidth)-r(n.paddingBottom)}}function tt(e){let n=[],r=e.querySelectorAll(`input, textarea, select, [${t}]`),i=e.closest(`[${t}]`);if(i)return[i.getBoundingClientRect()];for(let t of[e,...Array.from(r)]){if(t.hasAttribute(`data-nuni-mask`)){n.push(t.getBoundingClientRect());continue}let e=t.tagName;(t instanceof HTMLInputElement&&Ze.has(t.type)||e===`TEXTAREA`||e===`SELECT`)&&n.push(et(t))}return n}function nt(e,t,n){return new Promise(r=>e.toBlob(r,t,n))}window.__nuniScreenshot=async(t,n)=>{let r=Qe(t),{box:i,target:a,masks:o,crop:s}=$e(r,t),c=s.right-s.left,l=s.bottom-s.top;if(c<1||l<1)return null;let u=Math.min(window.devicePixelRatio||1,1280/c,1600/l,Q/i.width,Q/i.height),d=getComputedStyle(t.ownerDocument.body).backgroundColor||`rgb(255, 255, 255)`,f=await Ye(r,{width:i.width,height:i.height,scale:u,backgroundColor:d===`rgba(0, 0, 0, 0)`?`rgb(255, 255, 255)`:d,filter:e=>e!==n.exclude,timeout:8e3,fetch:{requestInit:{cache:`force-cache`,[Xe]:!0}}}),p=t.ownerDocument.createElement(`canvas`);p.width=Math.max(1,Math.round(c*u)),p.height=Math.max(1,Math.round(l*u));let m=p.getContext(`2d`);if(!m)return null;m.drawImage(f,(s.left-i.left)*u,(s.top-i.top)*u,p.width,p.height,0,0,p.width,p.height);let h=e=>({x:(e.left-s.left)*u,y:(e.top-s.top)*u,w:(e.right-e.left)*u,h:(e.bottom-e.top)*u});m.fillStyle=`#a1a1aa`;for(let e of o){let{x:t,y:n,w:r,h:i}=h(e);r>0&&i>0&&m.fillRect(t,n,r,i)}let g=Math.max(2,3*u),_=g/2,v=4*u,y=h(a),b=Math.max(_,y.x-v),x=Math.max(_,y.y-v),S=Math.min(p.width-_,y.x+y.w+v),C=Math.min(p.height-_,y.y+y.h+v);m.strokeStyle=n.accent,m.lineWidth=g,S>b&&C>x&&m.strokeRect(b,x,S-b,C-x);for(let[t,n]of[[`image/webp`,.82],[`image/jpeg`,.8],[`image/jpeg`,.55]]){let r=await nt(p,t,n);if(r&&r.type===t&&r.size<=e.screenshotMaxBytes)return r}return null}})();