UNPKG

5.35 kBJavaScriptView Raw
1(()=>{function x(){return Array.from({length:16},()=>Math.floor(Math.random()*256).toString(16)).join("")}var d;(function(o){o[o.MinWidth=0]="MinWidth",o[o.MaxWidth=1]="MaxWidth",o[o.MinHeight=2]="MinHeight",o[o.MaxHeight=3]="MaxHeight"})(d||(d={}));var L=new Map([[3,(e,n)=>e.blockSize<=n],[2,(e,n)=>e.blockSize>=n],[1,(e,n)=>e.inlineSize<=n],[0,(e,n)=>e.inlineSize>=n]]);function z(e,n){let t;if("borderBoxSize"in n)t=n.borderBoxSize?.[0]??n.borderBoxSize;else{let r=getComputedStyle(n.target);t={blockSize:n.contentRect.height,inlineSize:n.contentRect.width},t.blockSize+=parseInt(r.paddingBlockStart.slice(0,-2))+parseInt(r.paddingBlockEnd.slice(0,-2)),t.inlineSize+=parseInt(r.paddingInlineStart.slice(0,-2))+parseInt(r.paddingInlineEnd.slice(0,-2))}return L.get(e.measurement)(t,e.threshold)}function N(e,n){for(;e;)if(e=e.parentElement,!!u.has(e)&&!(n&&!u.get(e).includes(n)))return e;return null}var u=new WeakMap;function g(e,n){S.observe(e),u.has(e)||u.set(e,[]),u.get(e).push(n)}var b=[];function R(e){b.push(e)}var S=new ResizeObserver(e=>{let n=new Map(e.map(t=>[t.target,t]));for(let t of b)for(let{selector:r}of t.rules){let o=document.querySelectorAll(r);for(let i of o){let s=N(i,t.name);if(!s||!n.has(s))continue;let l=n.get(s);i.classList.toggle(t.className,z(t.breakPoint,l))}}}),k=[],B=new MutationObserver(e=>{for(let n of e){for(let t of n.removedNodes)t instanceof HTMLElement&&S.unobserve(t);for(let t of n.addedNodes)if(t instanceof HTMLElement)for(let r of k)t.matches(r.selector)&&g(t,r.name)}});B.observe(document.documentElement,{childList:!0,subtree:!0});function f(e){let n={sheetSrc:e,index:0};for(;c(n),!(n.index>=n.sheetSrc.length);){for(;h("/*",n);)q(n),c(n);if(h("@container",n)){let{query:t,startIndex:r,endIndex:o}=$(n),i=D(t);y(r,o,i,n),R(t)}else{let t=E(n);if(!t)continue;H(t,n)}}return n.sheetSrc}function H(e,n){let t=e.block.contents.includes("container-"),r=e.block.contents.includes("container:");if(!t&&!r)return;let o,i;t&&(o=/container-name: ([^;]+);/.exec(e.block.contents)?.[1],e.block.contents=e.block.contents.replace("container-type","contain")),r&&([i,o]=(/container: ([^;]+);/.exec(e.block.contents)?.[1]).split("/").map(l=>l.trim()),e.block.contents=e.block.contents.replace(/container: ([^;]+);/,`contain: ${i};`)),o||(o=x()),y(e.block.startIndex,e.block.endIndex,e.block.contents,n),k.push({name:o,selector:e.selector});for(let s of document.querySelectorAll(e.selector))g(s,o)}function y(e,n,t,r){if(r.sheetSrc=r.sheetSrc.slice(0,e)+t+r.sheetSrc.slice(n),r.index>=n){let o=r.index-n;r.index=e+t.length+o}}function q(e){a(e,"/*"),w("*/",e),a(e,"*/")}function m(e){if(e.index++,e.index>=e.sheetSrc.length)throw Error("Advanced beyond the end")}function w(e,n){let t=n.index;for(;!h(e,n);)m(n);return n.sheetSrc.slice(t,n.index)}function h(e,n){return n.sheetSrc.substr(n.index,e.length)==e}function O(e){let n=e.index;for(;/[\sa-zA-Z0-9:_\.,()#\[\]=+~*-]/.test(e.sheetSrc[e.index]);)m(e);if(!h("{",e)){w(`
2`,e),c(e);return}return e.sheetSrc.slice(n,e.index)}function E(e){let n=e.index,t=O(e);if(!t)return;let r=U(e),o=e.index;return{selector:t,block:r,startIndex:n,endIndex:o}}function a(e,n){if(e.sheetSrc.substr(e.index,n.length)!=n)throw Error(`Did not find expected sequence ${n}`);e.index+=n.length}var I=/\s*/g;function c(e){I.lastIndex=e.index;let n=I.exec(e.sheetSrc);n&&(e.index+=n[0].length)}function P(e){return e.sheetSrc[e.index]}var A=/[\w\@_-]+/g;function M(e){A.lastIndex=e.index;let n=A.exec(e.sheetSrc);if(!n)throw Error("Expected an identifier");return e.index+=n[0].length,n[0]}function T(e){return e.replace(/-(\w)/,(t,r)=>r.toUpperCase()).replace(/^\w/,t=>t.toUpperCase())}function Q(e){let n=T(M(e).toLowerCase());if(!(n in d))throw Error(`Unknown query ${n}`);return d[n]}var C=/[0-9.]*/g;function W(e){C.lastIndex=e.index;let n=C.exec(e.sheetSrc);if(!n)throw Error("Expected a number");e.index+=n[0].length,a(e,"px");let t=parseFloat(n[0]);if(Number.isNaN(t))throw Error(`${n[0]} is not a valid number`);return t}function U(e){let n=e.index;a(e,"{");let t=1;for(;t!=0;)e.sheetSrc[e.index]==="{"?t++:e.sheetSrc[e.index]==="}"&&t--,m(e);let r=e.index,o=e.sheetSrc.slice(n,r);return{startIndex:n,endIndex:r,contents:o}}function $(e){let n=e.index;a(e,"@container"),c(e);let t="";P(e)!=="("&&(t=M(e),c(e)),a(e,"("),c(e);let r=Q(e);c(e),a(e,":"),c(e);let o=W(e);c(e),a(e,")"),c(e),a(e,"{"),c(e);let i=[];for(;P(e)!=="}";)i.push(E(e)),c(e);a(e,"}");let s=e.index;c(e);let l=`cq_${x()}`;return{query:{breakPoint:{measurement:r,threshold:o},className:l,name:t,rules:i},startIndex:n,endIndex:s}}function D(e){return e.rules.map(n=>`:is(${n.selector}).${e.className} ${n.block.contents}`).join(`
3`)}var p={};function j(){new MutationObserver(r=>{for(let o of r)for(let i of o.addedNodes)i instanceof HTMLStyleElement&&n(i),i instanceof HTMLLinkElement&&t(i)}).observe(document.documentElement,{childList:!0,subtree:!0});function n(r){let o=f(r.innerHTML);r.innerHTML=o}async function t(r){if(r.rel!=="stylesheet")return;let o=new URL(r.href,p.url);if(o.origin!==location.origin)return;let i=await fetch(o.toString()).then(v=>v.text()),s=f(i),l=new Blob([s],{type:"text/css"});r.href=URL.createObjectURL(l)}document.querySelectorAll("style").forEach(r=>n(r)),document.querySelectorAll("link").forEach(r=>t(r))}var _="container"in document.documentElement.style;_||j();})();