@occluze/umber 0.2.1 → 0.4.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.
- package/LICENSE.md +21 -0
- package/README.md +126 -50
- package/THIRD-PARTY-NOTICES.md +33 -0
- package/dist/chunks/badge.js +2 -0
- package/dist/chunks/basis.js +2 -0
- package/dist/chunks/basis_transcoder.js +2 -0
- package/dist/chunks/basis_transcoder.wasm +0 -0
- package/dist/chunks/batches.js +2 -0
- package/dist/chunks/capture.js +2 -2
- package/dist/chunks/covers.js +2 -2
- package/dist/chunks/curves.js +2 -0
- package/dist/chunks/flip.js +2 -2
- package/dist/chunks/fx.js +2 -102
- package/dist/chunks/gl.js +2 -180
- package/dist/chunks/glsl.js +2 -239
- package/dist/chunks/glyphs.js +2 -0
- package/dist/chunks/inspect.js +2 -6
- package/dist/chunks/instances.js +2 -93
- package/dist/chunks/layers.js +2 -21
- package/dist/chunks/licence.js +2 -2
- package/dist/chunks/morph.js +2 -2
- package/dist/chunks/pace.js +2 -0
- package/dist/chunks/patch.js +2 -0
- package/dist/chunks/prepared.js +2 -0
- package/dist/chunks/profiler.js +2 -0
- package/dist/chunks/recheck.js +2 -0
- package/dist/chunks/resize.js +2 -0
- package/dist/chunks/restore.js +2 -2
- package/dist/chunks/shapes.js +2 -2
- package/dist/chunks/sim.js +2 -22
- package/dist/chunks/text.js +2 -52
- package/dist/chunks/video.js +2 -2
- package/dist/chunks/vocabulary.js +2 -0
- package/dist/chunks/warm.js +2 -2
- package/dist/modules/debug.js +2 -36
- package/dist/modules/debug.mjs +2 -36
- package/dist/modules/handoff.js +2 -2
- package/dist/modules/handoff.mjs +2 -2
- package/dist/modules/input.js +2 -2
- package/dist/modules/input.mjs +2 -2
- package/dist/modules/scrollfx.js +2 -0
- package/dist/modules/scrollfx.mjs +2 -0
- package/dist/modules/scrub.js +2 -8
- package/dist/modules/scrub.mjs +2 -8
- package/dist/modules/three.js +2 -0
- package/dist/modules/three.mjs +2 -0
- package/dist/node/assets.mjs +11 -0
- package/dist/node/astro.mjs +55 -0
- package/dist/node/cli.mjs +162 -0
- package/dist/node/shared-P6KINBNR.mjs +2113 -0
- package/dist/node/shared-VQKZUUXF.mjs +289 -0
- package/dist/node/vite.mjs +14 -0
- package/dist/prepared.mjs +2 -0
- package/dist/umber.css +2 -2
- package/dist/umber.js +2 -2
- package/dist/umber.mjs +2 -2
- package/docs/AI-quick.md +104 -86
- package/docs/AI.md +2299 -1692
- package/docs/npm.md +40 -32
- package/package.json +176 -24
- package/types/assets.d.ts +192 -0
- package/types/astro.d.ts +40 -0
- package/types/debug.d.ts +18 -17
- package/types/esm.d.ts +13 -17
- package/types/global.d.ts +17 -0
- package/types/handoff.d.ts +26 -25
- package/types/input.d.ts +63 -55
- package/types/loop.d.ts +87 -0
- package/types/module.d.ts +106 -0
- package/types/scrollfx.d.ts +44 -0
- package/types/scrub.d.ts +33 -32
- package/types/three.d.ts +251 -0
- package/types/umber.d.ts +705 -432
- package/types/vite.d.ts +33 -0
- package/dist/chunks/views.js +0 -2
- package/dist/modules/router-swap.js +0 -13
- package/dist/modules/router.js +0 -2
- package/dist/modules/router.mjs +0 -2
- package/dist/modules/scroll.js +0 -2
- package/dist/modules/scroll.mjs +0 -2
- package/types/router.d.ts +0 -181
- package/types/scroll.d.ts +0 -132
package/dist/chunks/sim.js
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
/*! Umber v0.
|
|
2
|
-
var S={info(){},warn:(a,...t)=>console.warn("[umber]",a,...t),once:(a,...t)=>console.warn("[umber]",a,...t),error:(a,...t)=>console.error("[umber]",a,...t)},h=S;function v(a){a&&(h=a)}var p=class{constructor(t=60){this.hz=t;this.ia=0;this.na=!1}advance(t){this.ia+=t>0?t:0;let e=Math.floor(this.ia*this.hz+.5);return e>4?(e=4,this.ia=0):!e&&this.na?(e=1,this.ia=0):this.ia-=e/this.hz,this.na=!1,e}due(){this.na=!0,this.ia=Math.min(this.ia,0)}},P=1/255;function y(a){return a<=0?1:a>=1?1/0:Math.ceil(Math.log(P)/Math.log(a))}function m(a,t,e){return Array.isArray(a)?+a[Math.max(0,Math.min(a.length-1,t))]||e:a!=null&&+a>0?+a:e}var d=16,A=/^[A-Za-z_]\w*$/,g=(a,t)=>/\bvoid\s+main\s*\(/.test(a)?a:`${a}
|
|
3
|
-
void main() { outColor = ${t}(vUv); }`;function k(a){let t=a.read;a.read=a.write,a.write=t}var w=class{constructor(t,e,s){this.sims=t;this.o=e;this.fields=new Map;this.Sa=[];this.passes=[];this.Fa=[];this.brushes=[];this.steps=0;this.idle=0;this.awake=!1;this.released=!1;this.ok=!1;this.aspect=0;this.clock=new p(Math.max(1,+e.hz||60));let i=t.fx;this.uniforms={...e.uniforms||{},uDt:1/this.clock.hz,uStep:0,uPointer:new Float32Array([-1,-1])};let n=e.fields||{state:{init:e.init}};for(let r in n){let u=n[r]||{},l=u.type||e.type||"half",f={...this.dims(u.size,s),type:l,msaa:0,attachments:1,quiet:!0},F=i.make(f),M=i.make(f),c={name:r,read:F,write:M,size:u.size,init:u.init,type:l,holder:{get texture(){return c.read.texture}}};this.fields.set(r,c),this.Sa.push(c.holder),this.uniforms[r]=c.holder}this.out=this.fields.get(e.output)||this.fields.values().next().value;let o=e.passes||[{into:this.out.name,next:e.next}];for(let r of o){let u=this.fields.get(r.into);this.passes.push({into:u,source:g(r.next,"next"),iterations:Math.max(1,Math.round(m(r.iterations,s,1))),program:null})}for(let r of this.fields.values())r.init&&this.Fa.push({field:r,program:null});this.pointer=this.passes.some(r=>/\buPointer\b/.test(r.source)),this.own=!!this.Fa.length||e.settle===!1||this.passes.some(r=>/\bu(Time|Step)\b/.test(r.source)),this.compile(),this.start()}dims(t,e){let s=this.sims.fx.stage,i=s.gl.getParameter(s.gl.MAX_TEXTURE_SIZE)||4096,n=Math.min(i,Math.max(1,Math.round(m(t??this.o.size,e,128))));this.aspect=s.viewport.height/Math.max(1,s.viewport.width);let o=this.o.shape==="square"?n:Math.min(i,Math.max(1,Math.round(n*this.aspect)));return{width:n,height:o}}compile(){let t=this.sims.fx.passes,e=!0;for(let s of this.passes)e=!!(s.program=t.program(s.source,this.uniforms))&&e;for(let s of this.Fa)e=!!(s.program=t.program(g(s.field.init,"init"),this.uniforms))&&e;return(this.ok=e)||(this.awake=!1,h.warn("gl.sim(): a pass did not compile (the shader log is above); this sim stays still.")),e}start(){let t=this.sims.fx.stage;for(let e of this.fields.values())e.read.clear(),e.write.clear();for(let e of this.Fa)e.program&&this.draw(e.program,e.field);t.gl.bindFramebuffer(t.gl.FRAMEBUFFER,null),t.renderer.reset(),this.steps=this.uniforms.uStep=0,this.own?this.wake():this.awake=!1}draw(t,e){let s=this.sims.fx.stage,i=e.write.b;i&&(s.gl.bindFramebuffer(s.gl.FRAMEBUFFER,i.draw),this.sims.fx.passes.draw(t,i.spec.width,i.spec.height,this.uniforms,s.time),k(e))}run(t){let e=this.sims.fx.stage;this.o.shape!=="square"&&Math.abs(e.viewport.height/Math.max(1,e.viewport.width)-this.aspect)>.01&&this.fit();let s=this.clock.advance(t);for(let i=0;i<s;i++)this.step();if(s){e.gl.bindFramebuffer(e.gl.FRAMEBUFFER,null),e.renderer.reset();let i=this.o.settle;i!==!1&&(typeof i=="function"?i(this):this.idle>=(i??2)-1e-6)&&(this.awake=!1)}return s>0}step(){let t=this.uniforms,e=this.sims.fx.stage;t.uStep=++this.steps,this.idle+=1/this.clock.hz,t.uPointer[0]=e.pointer.x<0?-1:e.pointer.x/e.viewport.width,t.uPointer[1]=e.pointer.y<0?-1:e.pointer.y/e.viewport.height;for(let s of this.brushes)s.apply();for(let s of this.passes)if(s.program)for(let i=0;i<s.iterations;i++)this.draw(s.program,s.into)}fit(){let t=this.sims.level;for(let e of this.fields.values()){let{width:s,height:i}=this.dims(e.size,t);e.read.resize(s,i),e.write.resize(s,i)}this.start()}get texture(){return this.released?null:this.out.read.texture}get width(){return this.out.read.width}get height(){return this.out.read.height}get type(){return this.out.read.type}field(t){let e=this.fields.get(t);return e||h.warn(`sim.field("${t}"): this sim has no field "${t}"; its fields are ${[...this.fields.keys()].join(", ")}.`),e?e.holder:null}wake(){return this.released?this:(this.idle=0,(!this.awake||!this.steps)&&this.clock.due(),this.awake=this.ok,this.sims.fx.stage.request(),this)}set(t,e){return this.uniforms[t]=e,this.wake()}reset(){return this.released||this.start(),this}brush(t){return this.released?null:new b(this,t||{})}seen(){let t=this.sims.fx.stage,e=this.sims.flowSim===this?t.flow:null,s=t.planes,i=this.Sa,n=!1;if(this.byPass)return!0;for(let o=0;o<i.length;o++)if(i[o].byPass)return!0;for(let o=0;o<s.length;o++){let r=s[o];if(r._layer&&(r.soon||r.visible))return!0;for(let u in r.uniforms){let l=r.uniforms[u].value;if(!(l!==this&&(!l||l!==e)&&!this.Sa.includes(l))){if(r.soon||r.visible)return!0;n=!0}}}return!n}release(){let t=this.sims;if(!this.released){if(t.flowSim===this){if(t.fx.stage.planes.some(e=>e.uniforms.uFlow))return;t.flowSim=t.flowBrush=null}this.released=!0,this.awake=!1;for(let e of this.fields.values())e.read.release(),e.write.release();this.brushes.length=0,t.list.delete(this)}}},b=class{constructor(t,e){this.sim=t;this.o=e;this.stamps=new Float32Array(d*4);this.count=0;this.last=[NaN,NaN];this.released=!1;let s=t.fields.get(e.field||"")||t.fields.values().next().value;e.field&&!t.fields.has(e.field)&&h.warn(`gl.brush(): this sim has no field "${e.field}"; it paints "${s.name}".`),this.field=s;let i=t.sims.fx.stage,n=e.color||[1,1,1,1];this.u={[s.name]:s.holder,uStamps:this.stamps,uCount:0,uBrushRadius:Math.max(.5,+e.radius||24),uColor:new Float32Array([+n[0]||0,+n[1]||0,+n[2]||0,n[3]==null?1:+n[3]]),uMotion:+e.motion||0,uView:new Float32Array([i.viewport.width,i.viewport.height]),uMix:e.mode==="mix"?1:0},this.source=g(z.replace("FIELD",s.name),"next"),t.brushes.push(this)}paint(t,e,s=0,i=0){if(this.released||this.count>=d)return this;let n=this.sim.sims.fx.stage,o=this.stamps,r=this.count++*4;return o[r]=t/n.viewport.width,o[r+1]=e/n.viewport.height,o[r+2]=s,o[r+3]=i,this.sim.wake(),this}follow(t,e){let[s,i]=this.last;if(this.last[0]=t,this.last[1]=e,s!==s||t===s&&e===i)return;let n=t-s,o=e-i,r=Math.min(d-this.count,Math.max(1,Math.ceil(Math.hypot(n,o)/(this.u.uBrushRadius*.5))));for(let u=1;u<=r;u++)this.paint(s+n*u/r,i+o*u/r,n/r,o/r)}apply(){let t=this.sim.sims.fx.stage;if(this.o.pointer!==!1&&t.pointer.x>=0&&this.follow(t.pointer.x,t.pointer.y),!this.count)return;this.program===void 0&&(this.program=this.sim.sims.fx.passes.program(this.source,this.u));let e=this.u.uView;e[0]=t.viewport.width,e[1]=t.viewport.height,this.u.uCount=this.count,this.count=0;let s=this.field,i=s.write.b;!this.program||!i||(t.gl.bindFramebuffer(t.gl.FRAMEBUFFER,i.draw),this.sim.sims.fx.passes.draw(this.program,i.spec.width,i.spec.height,this.u,t.time),k(s),this.sim.idle=0)}lost(){this.program=void 0}release(){this.released=!0;let t=this.sim.brushes,e=t.indexOf(this);e>=0&&t.splice(e,1)}},z=`uniform vec4 uStamps[16];
|
|
4
|
-
vec4 next(vec2 uv){
|
|
5
|
-
vec4 c=texture(FIELD,uv);
|
|
6
|
-
for(int i=0;i<16;i++){
|
|
7
|
-
if(float(i)>=uCount)break;
|
|
8
|
-
vec2 d=(uv-uStamps[i].xy)*uView;
|
|
9
|
-
float k=exp(-dot(d,d)/(uBrushRadius*uBrushRadius));
|
|
10
|
-
vec4 v=uColor+vec4(uStamps[i].zw*uMotion,0.0,0.0);
|
|
11
|
-
c=uMix>0.5?mix(c,v,k*uColor.a):c+v*k;
|
|
12
|
-
}
|
|
13
|
-
return c;
|
|
14
|
-
}`,E=`vec4 next(vec2 uv){
|
|
15
|
-
vec2 v=texture(push,uv).xy;
|
|
16
|
-
float l=length(v);
|
|
17
|
-
return vec4(l<1.0/255.0?vec2(0.0):v/max(l,1.0)*uFade,0.0,1.0);
|
|
18
|
-
}`,T=`vec4 next(vec2 uv){
|
|
19
|
-
vec2 v=texture(push,uv).xy;
|
|
20
|
-
float l=length(v);
|
|
21
|
-
return vec4(l>0.0?v/l*0.5+0.5:vec2(0.5),1.0,min(l,1.0));
|
|
22
|
-
}`,R=a=>a.o.pointer!==!1,x=class{constructor(t){this.fx=t;this.list=new Set;this.flowSim=null;this.flowBrush=null;this.tick=t=>{let e=this.fx.stage;if(e.inactive)return;let s=!1,i=!1;for(let n of this.list)if(n.awake){if(!n.seen()){for(let o of n.brushes)o.last[0]=NaN;continue}s=n.run(t.dt)||s,i||=n.awake}s?e.markDirty():i&&e.request()};let e=t.stage;e.subsystems.push(this),e.cleanups.push(e.host.ticker.add(this.tick,{phase:"render",order:-1}));let s=n=>{let o=n,r=n.type==="pointerdown";r&&(e.pointer.x=o.clientX,e.pointer.y=o.clientY);let u=r||n.type==="pointerout"&&!o.relatedTarget;for(let l of this.list)if(u)for(let f of l.brushes)f.last[0]=NaN;else n.type==="pointermove"&&(l.pointer||l.brushes.some(R))&&l.seen()&&l.wake()},i=["pointermove","pointerdown","pointerout"];for(let n of i)addEventListener(n,s,{passive:!0});e.cleanups.push(()=>{for(let n of i)removeEventListener(n,s);this.list.clear()})}get level(){return this.fx.stage.stats.gpu?.level??4}sim(t,e=!1){if(!t||typeof t.next!="string"&&!Array.isArray(t.passes))return h.warn("gl.sim(options) needs `next` (GLSL: vec4 next(vec2 uv) { ... }) or `passes` ([{ into, next }])."),null;let s=Object.keys(t.fields||{state:0}),i=s.find(o=>!A.test(o))||(t.passes||[]).map(o=>o.into).find(o=>!s.includes(o));if(i)return h.warn(`gl.sim(): "${i}" is not one of its fields (${s.join(", ")}), or not a GLSL name; nothing was made.`),null;let n=new w(this,t,this.level);this.list.add(n);for(let o of n.fields.values()){let r=o.read.type;if(r==="float"&&o.read.b?.format.filter===this.fx.gl.NEAREST&&h.once(`gl.sim(): this GPU can't filter "float" targets, so texture() gives the nearest texel (smooth sampling turns blocky; texelFetch() is fine). Ask for type: "half" to sample smoothly.`),!(e||r===o.type)){if(r==="u8"){h.once(`gl.sim(): this GPU can't render to "${o.type}" targets, so sims run in 8 bits: values clip to 0..1 and slow fades stop short of 0. Ask for type: "u8" to skip this message.`);break}(t.fields?.[o.name]?.type||t.type)&&h.once(`gl.sim(): this GPU can't render to "${o.type}" targets, so this sim runs in "${r}": values round to about 3 digits (particle positions jitter). Ask for type: "${r}" to skip this message.`)}}return n}flow(t={}){let e=this.fx.stage,s=e.viewport.width,i=Math.min(.999,Math.max(0,t.fade??.92));if(this.flowSim===null){let o=this.sim({size:t.size??[32,48,64,64,96,128],fields:{push:{},flow:{}},output:"flow",passes:[{into:"push",next:E},{into:"flow",next:T}],uniforms:{uFade:i},settle:r=>r.idle*r.clock.hz>=y(r.uniforms.uFade)+2},!0);if(o.type==="u8"){o.release(),this.flowSim=!1;let r=e.host.engine.touch?.({fade:i,radius:(t.radius??s*.08)/s});return this.patch(()=>r?.texture),r?h.once("uFlow: this GPU can't render to half-float targets, so the flowmap is the input module's gl.touch() texture (drawn on the CPU, 8-bit)."):h.warn("uFlow: this GPU can't render to half-float targets, which the flowmap needs. Add the input module (modules/input.js, or gl.use(Input)) and uFlow falls back to its gl.touch() texture; until then uFlow stays still."),null}return this.flowSim=o,this.flowBrush=o.brush({field:"push",radius:t.radius??s*.08,motion:t.motion??.04}),this.patch(()=>o.texture),o}let n=this.flowSim;return n?(t.fade!=null&&(n.uniforms.uFade=i),t.radius!=null&&(this.flowBrush.u.uBrushRadius=Math.max(.5,t.radius)),t.motion!=null&&(this.flowBrush.u.uMotion=t.motion),t.size!=null&&t.size!==n.o.size&&(n.o.size=t.size,n.fit()),this.patch(()=>n.texture),n):null}patch(t){let e=this.fx.stage;e.flow||={texture:null},Object.defineProperty(e.flow,"texture",{configurable:!0,get:()=>t()||e.renderer.blank.texture})}lost(){for(let t of this.list)for(let e of t.brushes)e.lost()}restored(){for(let t of this.list)t.compile()&&t.reset()}};function U(a){return v(a.stage.host.log),new x(a)}export{b as Brush,w as Sim,x as Sims,U as sims};
|
|
1
|
+
/*! Umber v0.4.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
var t=()=>{};var e=()=>Promise.reject(new Error("no words"));var s={configure:t,debug:!1,warnings:!1,info:t,warn:t,error:t,report:t,words:e},i=s;function r(t){i=t}var h=class{constructor(t=60){this.hz=t;this.Fh=0;this.Xe=!1}advance(t){this.Fh+=t>0?t:0;let e=Math.floor(this.Fh*this.hz+.5);return e>4?(e=4,this.Fh=0):!e&&this.Xe?(e=1,this.Fh=0):this.Fh-=e/this.hz,this.Xe=!1,e}due(){this.Xe=!0,this.Fh=Math.min(this.Fh,0)}},o=1/255;function n(t){return t<=0?1:t>=1?1/0:Math.ceil(Math.log(o)/Math.log(t))}function a(t,e){return t===void 0||t===0||Number.isNaN(t)?e:t}function l(t,e,s){if(Array.isArray(t)){let i=t[Math.max(0,Math.min(t.length-1,e))];return a(i,s)}return t!=null&&t>0?t:s}var u=16,f=/^[A-Za-z_]\w*$/;function p(t){return Array.isArray(t.passes)?t.passes:typeof t.next=="string"?[{into:null,next:t.next}]:null}var m=(t,e)=>/\bvoid\s+main\s*\(/.test(t)?t:`${t}\nvoid main() { outColor = ${e}(vUv); }`;function d(t){for(let e of t.values())return e;throw new Error("umber.sim(): a sim has no fields")}function c(t,e){let s=t.get(e);if(!s)throw new Error(`umber.sim(): no field "${e}"`);return s}function g(t){let e=t.read;t.read=t.write,t.write=e}var v=class{constructor(t,e,s,i){this.sims=t;this.options=e;this.fields=new Map;this.df=[];this.passes=[];this.ni=[];this.brushes=[];this.steps=0;this.idle=0;this.awake=!1;this.released=!1;this.ok=!1;this.aspect=0;this.clock=new h(Math.max(1,a(e.hz,60))),this.uniforms={...e.uniforms,uDt:1/this.clock.hz,uStep:0,uPointer:new Float32Array([-1,-1])};let r=e.fields??{state:{init:e.init}};for(let[t,e]of Object.entries(r))this.sc(t,e,s);this.out=(e.output===void 0?void 0:this.fields.get(e.output))??d(this.fields);for(let t of i)this.passes.push({into:t.into===null?this.out:c(this.fields,t.into),source:m(t.next,"next"),iterations:Math.max(1,Math.round(l(t.iterations,s,1))),program:null});for(let t of this.fields.values())t.init&&this.ni.push({field:t,source:t.init,program:null});this.pointer=this.passes.some(t=>/\buPointer\b/.test(t.source)),this.own=!!this.ni.length||e.settle===!1||this.passes.some(t=>/\bu(Time|Step)\b/.test(t.source)),this.compile(),this.start()}sc(t,e,s){let i=e.type??this.options.type??"half",r={...this.Wd(e.size,s),type:i,msaa:0,attachments:1,quiet:!0},h=this.sims.fx,o={name:t,read:h.make(r),write:h.make(r),size:e.size,init:e.init,type:i,holder:{get texture(){return o.read.texture}}};this.fields.set(t,o),this.df.push(o.holder),this.uniforms[t]=o.holder}Wd(t,e){let s=this.sims.fx.stage,i=s.gpu.gl.getParameter(s.gpu.gl.MAX_TEXTURE_SIZE)??4096,r=Math.min(i,Math.max(1,Math.round(l(t??this.options.size,e,128))));this.aspect=s.canvasHost.viewport.height/Math.max(1,s.canvasHost.viewport.width);let h=this.options.shape==="square"?r:Math.min(i,Math.max(1,Math.round(r*this.aspect)));return{width:r,height:h}}compile(){let t=this.sims.fx.passes,e=!0;for(let s of this.passes)s.program=t.program(s.source,this.uniforms),s.program||(e=!1);for(let s of this.ni)s.program=t.program(m(s.source,"init"),this.uniforms),s.program||(e=!1);return this.ok=e,e||(this.awake=!1,this.sims.fx.stage.env.lib.say("simCompile",[])),e}start(){let t=this.sims.fx.stage;for(let t of this.fields.values())t.read.clear(),t.write.clear();for(let t of this.ni)t.program&&this.draw(t.program,t.field);t.gpu.gl.bindFramebuffer(t.gpu.gl.FRAMEBUFFER,null),t.gpu.renderer.reset(),this.steps=0,this.uniforms.uStep=0,this.own?this.wake():this.awake=!1}draw(t,e){let s=this.sims.fx.stage,i=e.write.b;i&&(s.gpu.gl.bindFramebuffer(s.gpu.gl.FRAMEBUFFER,i.draw),this.sims.fx.passes.draw(t,i.spec,this.uniforms),g(e))}run(t){let e=this.sims.fx.stage,s=e.canvasHost.viewport;this.options.shape!=="square"&&Math.abs(s.height/Math.max(1,s.width)-this.aspect)>.01&&this.fit();let i=this.clock.advance(t);for(let t=0;t<i;t++)this.step();if(i){e.gpu.gl.bindFramebuffer(e.gpu.gl.FRAMEBUFFER,null),e.gpu.renderer.reset();let t=this.options.settle;t!==!1&&(typeof t=="function"?t(this):this.idle>=(t??2)-1e-6)&&(this.awake=!1)}return i>0}step(){let t=this.uniforms,e=this.sims.fx.stage,s=e.env.frame.pointer;this.steps++,t.uStep=this.steps,this.idle+=1/this.clock.hz,t.uPointer[0]=s.x<0?-1:s.x/e.canvasHost.viewport.width,t.uPointer[1]=s.y<0?-1:s.y/e.canvasHost.viewport.height;for(let t of this.brushes)t.apply();for(let t of this.passes)if(t.program)for(let e=0;e<t.iterations;e++)this.draw(t.program,t.into)}fit(){let t=this.sims.level;for(let e of this.fields.values()){let{width:s,height:i}=this.Wd(e.size,t);e.read.resize(s,i),e.write.resize(s,i)}this.start()}get texture(){return this.released?null:this.out.read.texture}get width(){return this.out.read.width}get height(){return this.out.read.height}get type(){return this.out.read.type}field(t){let e=this.fields.get(t);return e||this.sims.fx.stage.env.lib.say("simField",[t,[...this.fields.keys()]]),e?e.holder:null}wake(){return this.released?this:(this.idle=0,(!this.awake||!this.steps)&&this.clock.due(),this.awake=this.ok,this.sims.fx.stage.scheduler.request(),this)}set(t,e){return this.uniforms[t]=e,this.wake()}reset(){return this.released||this.start(),this}brush(t){return this.released?null:new w(this,t??{})}seen(){if(this.Z)return!0;for(let t of this.df)if(t.Z)return!0;let t=this.sims.fx.stage,e=this.sims.sh===this?t.chunks.flow:null;if(e?.Z)return!0;let s=!1;for(let i of t.planes.all){let t=i.zone.soon||i.visible;if(i.layer&&t)return!0;if(this.sg(i.uniforms,e)){if(t)return!0;s=!0}}return!s}sg(t,e){for(let s in t){let i=t[s];if(!i)continue;let r=i.value;if(r===this||e!==null&&r===e||this.holds(r))return!0}return!1}holds(t){for(let e of this.df)if(e===t)return!0;return!1}release(){let t=this.sims;if(!this.released){if(t.sh===this){if(t.fx.stage.planes.all.some(t=>"uFlow"in t.uniforms))return;t.sh=null,t.Db=null}this.released=!0,this.awake=!1;for(let t of this.fields.values())t.read.release(),t.write.release();this.brushes.length=0,t.list.delete(this)}}},w=class{constructor(t,e){this.sim=t;this.options=e;this.stamps=new Float32Array(u*4);this.count=0;this.last=[NaN,NaN];this.released=!1;let s=e.field===void 0?void 0:t.fields.get(e.field),i=s??d(t.fields);e.field&&!s&&t.sims.fx.stage.env.lib.say("brushField",[e.field,i.name]),this.field=i;let r=t.sims.fx.stage.canvasHost.viewport,h=e.color??[1,1,1,1];this.uniforms={[i.name]:i.holder,uStamps:this.stamps,uCount:0,uBrushRadius:Math.max(.5,a(e.radius,24)),uColor:new Float32Array([a(h[0],0),a(h[1],0),a(h[2],0),h[3]??1]),uMotion:a(e.motion,0),uView:new Float32Array([r.width,r.height]),uMix:e.mode==="mix"?1:0},this.source=m(x.replace("FIELD",i.name),"next"),t.brushes.push(this)}paint(t,e,s=0,i=0){if(this.released||this.count>=u)return this;let r=this.sim.sims.fx.stage.canvasHost.viewport,h=this.stamps,o=this.count++*4;return h[o]=t/r.width,h[o+1]=e/r.height,h[o+2]=s,h[o+3]=i,this.sim.wake(),this}follow(t,e){let[s,i]=this.last;if(this.last[0]=t,this.last[1]=e,s!==s||t===s&&e===i)return;let r=t-s,h=e-i,o=Math.min(u-this.count,Math.max(1,Math.ceil(Math.hypot(r,h)/(this.uniforms.uBrushRadius*.5))));for(let t=1;t<=o;t++)this.paint(s+r*t/o,i+h*t/o,r/o,h/o)}apply(){let t=this.sim.sims.fx.stage,e=t.env.frame.pointer;if(this.options.pointer!==!1&&e.x>=0&&this.follow(e.x,e.y),!this.count)return;this.program===void 0&&(this.program=this.sim.sims.fx.passes.program(this.source,this.uniforms));let s=this.uniforms.uView;s[0]=t.canvasHost.viewport.width,s[1]=t.canvasHost.viewport.height,this.uniforms.uCount=this.count,this.count=0;let i=this.field,r=i.write.b;!this.program||!r||(t.gpu.gl.bindFramebuffer(t.gpu.gl.FRAMEBUFFER,r.draw),this.sim.sims.fx.passes.draw(this.program,r.spec,this.uniforms),g(i),this.sim.idle=0)}lost(){this.program=void 0}release(){this.released=!0;let t=this.sim.brushes,e=t.indexOf(this);e>=0&&t.splice(e,1)}},x=`uniform vec4 uStamps[16];\nvec4 next(vec2 uv){\nvec4 c=texture(FIELD,uv);\nfor(int i=0;i<16;i++){\nif(float(i)>=uCount)break;\nvec2 d=(uv-uStamps[i].xy)*uView;\nfloat k=exp(-dot(d,d)/(uBrushRadius*uBrushRadius));\nvec4 v=uColor+vec4(uStamps[i].zw*uMotion,0.0,0.0);\nc=uMix>0.5?mix(c,v,k*uColor.a):c+v*k;\n}\nreturn c;\n}`,b=`vec4 next(vec2 uv){\nvec2 v=texture(push,uv).xy;\nfloat l=length(v);\nreturn vec4(l<1.0/255.0?vec2(0.0):v/max(l,1.0)*uFade,0.0,1.0);\n}`,y=`vec4 next(vec2 uv){\nvec2 v=texture(push,uv).xy;\nfloat l=length(v);\nreturn vec4(l>0.0?v/l*0.5+0.5:vec2(0.5),1.0,min(l,1.0));\n}`,k=t=>t.options.pointer!==!1,F=class{constructor(t){this.fx=t;this.list=new Set;this.sh=null;this.Db=null;this.tick=t=>{let e=this.fx.stage;if(e.scheduler.inactive)return;let s=!1,i=!1;for(let e of this.list)if(e.awake){if(!e.seen()){for(let t of e.brushes)t.last[0]=NaN;continue}s=e.run(t.dt)||s,i||=e.awake}s?e.scheduler.markDirty():i&&e.scheduler.request()};let e=t.stage;e.gpu.subsystems.push(this),e.env.cleanups.push(e.env.host.ticker.add(this.tick,{phase:"render",order:-1}));let s=t=>{let s=t,i=t.type==="pointerdown";i&&(e.env.frame.pointer.x=s.clientX,e.env.frame.pointer.y=s.clientY);let r=i||t.type==="pointerout"&&!s.relatedTarget;for(let e of this.list)if(r)for(let t of e.brushes)t.last[0]=NaN;else t.type==="pointermove"&&(e.pointer||e.brushes.some(k))&&e.seen()&&e.wake()},i=["pointermove","pointerdown","pointerout"];for(let t of i)addEventListener(t,s,{passive:!0});e.env.cleanups.push(()=>{for(let t of i)removeEventListener(t,s);this.list.clear()})}get level(){return this.fx.stage.env.stats.gpu?.level??4}sim(t){let e=t?p(t):null;if(!t||!e)return this.fx.stage.env.lib.say("simNext",[]),null;let s=Object.keys(t.fields??{state:0});if(!s.length)return this.fx.stage.env.lib.say("simFields",[]),null;let i=s.find(t=>!f.test(t))??e.map(t=>t.into).find(t=>t!==null&&!s.includes(t));return i!=null?(this.fx.stage.env.lib.say("simName",[i,s]),null):this.make(t,e)}make(t,e,{quiet:s=!1}={}){let r=new v(this,t,this.level,e);this.list.add(r);for(let e of r.fields.values()){let r=e.read.type;if(r==="float"&&e.read.b?.format.filter===this.fx.gl.NEAREST&&i.warn(`umber.sim(): this GPU can't filter "float" targets, so texture() gives the nearest texel (smooth sampling turns blocky; texelFetch() is fine). Ask for type: "half" to sample smoothly.`),!(s||r===e.type)){if(r==="u8"){i.warn(`umber.sim(): this GPU can't render to "${e.type}" targets, so sims run in 8 bits: values clip to 0..1 and slow fades stop short of 0. Ask for type: "u8" to skip this message.`);break}(t.fields?.[e.name]?.type??t.type)&&i.warn(`umber.sim(): this GPU can't render to "${e.type}" targets, so this sim runs in "${r}": values round to about 3 digits (particle positions jitter). Ask for type: "${r}" to skip this message.`)}}return r}flow(t={}){let e=Math.min(.999,Math.max(0,t.fade??.92));if(this.sh===null)return this.He(t,e);let s=this.sh;if(!s)return null;t.fade!=null&&(s.uniforms.uFade=e);let i=this.Db;return i&&t.radius!=null&&(i.uniforms.uBrushRadius=Math.max(.5,t.radius)),i&&t.motion!=null&&(i.uniforms.uMotion=t.motion),t.size!=null&&t.size!==s.options.size&&(s.options.size=t.size,s.fit()),this.patch(()=>s.texture),s}He(t,e){let s=this.fx.stage.canvasHost.viewport.width,i=t.radius??s*.08,r=[{into:"push",next:b},{into:"flow",next:y}],h=this.make({size:t.size??[32,48,64,64,96,128],fields:{push:{},flow:{}},output:"flow",passes:r,uniforms:{uFade:e},settle:t=>t.idle*t.clock.hz>=n(t.uniforms.uFade)+2},r,{quiet:!0});return h.type==="u8"?(h.release(),this.sh=!1,this._b(e,i/s),null):(this.sh=h,this.Db=h.brush({field:"push",radius:i,motion:t.motion??.04}),this.patch(()=>h.texture),h)}_b(t,e){let s=this.fx.stage.env.host.engine.touch?.({fade:t,radius:e});this.patch(()=>s?.texture),s?i.warn("uFlow: this GPU can't render to half-float targets, so the flowmap is the input module's umber.touch() texture (drawn on the CPU, 8-bit)."):i.warn("uFlow: this GPU can't render to half-float targets, which the flowmap needs. Add the input module (modules/input.js, or umber.use(Input)) and uFlow falls back to its umber.touch() texture; until then uFlow stays still.")}patch(t){let e=this.fx.stage;e.chunks.flow??={texture:null},Object.defineProperty(e.chunks.flow,"texture",{configurable:!0,get:()=>t()??e.gpu.renderer.blank.texture})}lost(){for(let t of this.list)for(let e of t.brushes)e.lost()}restored(){for(let t of this.list)t.compile()&&t.reset()}};function M(t){return r(t.stage.env.host.log),new F(t)}export{w as Brush,v as Sim,F as Sims,M as sims};
|
package/dist/chunks/text.js
CHANGED
|
@@ -1,52 +1,2 @@
|
|
|
1
|
-
/*! Umber v0.
|
|
2
|
-
var Ce={info(){},warn:(e,...t)=>console.warn("[umber]",e,...t),once:(e,...t)=>console.warn("[umber]",e,...t),error:(e,...t)=>console.error("[umber]",e,...t)},nt=Ce;function te(e){e&&(nt=e)}var st=class{constructor(t,r){this.gl=t;this.format=r;this.width=1;this.height=1;this.ready=!1;this.texture=t.createTexture(),this.upload(1,1,r==="uint"?new Uint16Array(1):new Float32Array(4)),this.ready=!1}get bytes(){return this.ready?this.width*this.height*(this.format==="uint"?2:16):0}upload(t,r,i){let n=this.gl;n.bindTexture(n.TEXTURE_2D,this.texture),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.pixelStorei(n.UNPACK_ALIGNMENT,1),this.format==="uint"?n.texImage2D(n.TEXTURE_2D,0,n.R16UI,t,r,0,n.RED_INTEGER,n.UNSIGNED_SHORT,i):n.texImage2D(n.TEXTURE_2D,0,n.RGBA32F,t,r,0,n.RGBA,n.FLOAT,i),n.pixelStorei(n.UNPACK_ALIGNMENT,4),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),this.width=t,this.height=r,this.ready=!0}dispose(){this.texture&&this.gl.deleteTexture(this.texture),this.texture=null,this.ready=!1}};var Ge={used:/\bglyph\s*\(/,defined:/\bGlyph\s+glyph\s*\(/,code:`struct Glyph{
|
|
3
|
-
float line;
|
|
4
|
-
float word;
|
|
5
|
-
float char;
|
|
6
|
-
float lines;
|
|
7
|
-
float words;
|
|
8
|
-
float chars;
|
|
9
|
-
vec4 lineBox;
|
|
10
|
-
vec4 wordBox;
|
|
11
|
-
vec4 charBox;
|
|
12
|
-
float ink;
|
|
13
|
-
vec4 lineValue;
|
|
14
|
-
vec4 wordValue;
|
|
15
|
-
vec4 charValue;
|
|
16
|
-
};
|
|
17
|
-
uniform highp usampler2D uGlyphIndex;
|
|
18
|
-
uniform highp sampler2D uGlyphData;
|
|
19
|
-
vec4 umberGlyphRow(highp int i){
|
|
20
|
-
highp int w=textureSize(uGlyphData,0).x;
|
|
21
|
-
return texelFetch(uGlyphData,ivec2(i%w,i/w),0);
|
|
22
|
-
}
|
|
23
|
-
Glyph glyph(vec2 uv){
|
|
24
|
-
Glyph g=Glyph(0.0,0.0,0.0,1.0,1.0,1.0,vec4(0.0,0.0,1.0,1.0),vec4(0.0,0.0,1.0,1.0),vec4(0.0,0.0,1.0,1.0),0.0,vec4(0.0),vec4(0.0),vec4(0.0));
|
|
25
|
-
#ifdef UMBER_FRAGMENT
|
|
26
|
-
g.ink=sampleImage(uv).a;
|
|
27
|
-
#endif
|
|
28
|
-
vec4 head=umberGlyphRow(0);
|
|
29
|
-
if(head.x<0.5)return g;
|
|
30
|
-
highp ivec2 size=textureSize(uGlyphIndex,0);
|
|
31
|
-
highp ivec2 p=clamp(ivec2(floor(uv*vec2(size))),ivec2(0),size-1);
|
|
32
|
-
highp int c=int(texelFetch(uGlyphIndex,p,0).r)-1;
|
|
33
|
-
if(c<0)return g;
|
|
34
|
-
highp int chars=int(head.x+0.5);
|
|
35
|
-
highp int words=int(head.y+0.5);
|
|
36
|
-
vec4 info=umberGlyphRow(1+2*c);
|
|
37
|
-
g.line=info.x;
|
|
38
|
-
g.word=info.y;
|
|
39
|
-
g.char=float(c);
|
|
40
|
-
g.chars=head.x;
|
|
41
|
-
g.words=head.y;
|
|
42
|
-
g.lines=head.z;
|
|
43
|
-
g.charBox=umberGlyphRow(2+2*c);
|
|
44
|
-
g.wordBox=umberGlyphRow(1+2*chars+int(info.y+0.5));
|
|
45
|
-
g.lineBox=umberGlyphRow(1+2*chars+words+int(info.x+0.5));
|
|
46
|
-
highp int lines=int(head.z+0.5);
|
|
47
|
-
highp int values=1+2*chars+words+lines;
|
|
48
|
-
g.lineValue=umberGlyphRow(values+int(info.x+0.5));
|
|
49
|
-
g.wordValue=umberGlyphRow(values+lines+int(info.y+0.5));
|
|
50
|
-
g.charValue=umberGlyphRow(values+lines+words+c);
|
|
51
|
-
return g;
|
|
52
|
-
}`},De=65534,ee=(e,t)=>{e.l=Math.min(e.l,t.x),e.t=Math.min(e.t,t.y),e.r=Math.max(e.r,t.x+t.w),e.b=Math.max(e.b,t.y+t.h)},Ut=e=>({l:e.x,t:e.y,r:e.x+e.w,b:e.y+e.h});function Ft(e,t=e.length){let r=new Int32Array(t),i=new Int32Array(t),n=[],a=[];for(let s=0;s<t;s++){let o=e[s],l=n[n.length-1],f=s>0?e[s-1]:null,d=o.y+o.h/2,c=!!f&&(o.rtl?o.x+o.w/2>f.x+f.w:o.x+o.w/2<f.x),A=!l||(o.unit!==void 0&&f?.unit!==void 0?o.unit!==f.unit:d>l.b||c&&o.y>=(l.t+l.b)/2);A?n.push({...Ut(o),chars:[]}):ee(l,o),n[n.length-1].chars.push(s),A||o.wordStart||!a.length?a.push(Ut(o)):ee(a[a.length-1],o),r[s]=n.length-1,i[s]=a.length-1}return{lineOf:r,wordOf:i,lines:n,words:a}}function ne(e,t,r,i=2048){let n=Math.min(e.length,De);if(!n||!(t>0)||!(r>0))return null;let{lineOf:a,wordOf:s,lines:o,words:l}=Ft(e,n),f=Math.min(1,i/Math.max(t,r)),d=Math.max(1,Math.ceil(t*f)),c=Math.max(1,Math.ceil(r*f)),A=(u,b)=>Math.max(0,Math.min(b,Math.round(u*f))),E=o.map(u=>{let b=new Uint16Array(d),M=new Float32Array(d).fill(1/0),R=new Float32Array(d).fill(-1/0),G=u.chars.slice().sort((B,L)=>e[B].x+e[B].w/2-(e[L].x+e[L].w/2)),W=0;for(let B=0;B<G.length;B++){let L=e[G[B]],Y=B+1<G.length?e[G[B+1]]:null,J=Y?Math.max(W,(L.x+L.w+Y.x)/2):t,ot=A(W,d),at=Y?A(J,d):d;at>ot&&b.fill(G[B]+1,ot,at),W=J;let K=L.ink||{l:L.x,t:L.y,r:L.x+L.w,b:L.y+L.h};for(let Z=A(K.l-1,d-1),bt=A(K.r+1,d-1);Z<=bt;Z++)K.t-1<M[Z]&&(M[Z]=K.t-1),K.b+1>R[Z]&&(R[Z]=K.b+1)}return{owner:b,inkTop:M,inkBottom:R}}),F=o.slice(0,-1).map((u,b)=>{let M=o[b+1],R=(u.b+M.t)/2,G=new Float32Array(d),W=E[b],B=E[b+1];for(let L=0;L<d;L++){let Y=W.inkBottom[L],J=B.inkTop[L];G[L]=Y>J?(Y+J)/2:Math.min(Math.max(R,Y),J)}return G}),I=new Uint16Array(d*c);for(let u=0;u<d;u++){let b=0;for(let M=0;M<o.length;M++){let R=M<F.length?Math.max(b,A(F[M][u],c)):c,G=E[M].owner[u];for(let W=b;W<R;W++)I[W*d+u]=G;b=R}}let _=1+2*n+l.length+o.length,h=_+n+l.length+o.length,g=Math.min(h,512),S=Math.ceil(h/g),P=new Float32Array(g*S*4),$=(u,b,M,R,G)=>{P.set([b,M,R,G],u*4)},et=(u,b)=>$(u,b.l/t,b.t/r,(b.r-b.l)/t,(b.b-b.t)/r);$(0,n,l.length,o.length,0);for(let u=0;u<n;u++)$(1+2*u,a[u],s[u],0,0),et(2+2*u,Ut(e[u]));return l.forEach((u,b)=>et(1+2*n+b,u)),o.forEach((u,b)=>et(1+2*n+l.length+b,u)),{chars:n,words:l.length,lines:o.length,index:I,width:d,height:c,data:P,dataWidth:g,dataHeight:S,values:_}}var Bt=[1,0,0,1,0,0];function tt(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}var Ie=(e,t,r)=>[e[0]*t+e[2]*r+e[4],e[1]*t+e[3]*r+e[5]];function re(e,t,r){let i=e[0]*e[3]-e[2]*e[1];return Math.abs(i)<1e-6?null:[(e[3]*t-e[2]*r)/i,(e[0]*r-e[1]*t)/i]}function ie(e,t,r){let i=Bt,n=!1,a=e.translate;if(a&&a!=="none"){let[c="0",A="0",E]=a.split(" ");if(E&&parseFloat(E))return!1;let F=(I,_)=>I.endsWith("%")?parseFloat(I)/100*_:parseFloat(I)||0;i=tt(i,[1,0,0,1,F(c,t),F(A,r)]),n=!0}let s=e.rotate;if(s&&s!=="none"){if(s.trim().includes(" "))return!1;let c=parseFloat(s)*Math.PI/(s.endsWith("rad")?Math.PI:s.endsWith("turn")?.5:180);i=tt(i,[Math.cos(c),Math.sin(c),-Math.sin(c),Math.cos(c),0,0]),n=!0}let o=e.scale;if(o&&o!=="none"){let[c,A=c,E]=o.split(" ").map(parseFloat);if(E!==void 0&&E!==1)return!1;i=tt(i,[c,0,0,A,0,0]),n=!0}let l=e.transform;if(l&&l!=="none"){let c=(l.slice(l.indexOf("(")).match(/-?[\d.]+(?:e-?\d+)?/g)||[]).map(Number);if(l.startsWith("matrix3d")){if(c.length!==16||c[2]||c[3]||c[6]||c[7]||c[8]||c[9]||c[11]||c[14]||c[10]!==1||c[15]!==1)return!1;i=tt(i,[c[0],c[1],c[4],c[5],c[12],c[13]])}else c.length===6&&(i=tt(i,c));n=!0}if(!n||i.every((c,A)=>Math.abs(c-Bt[A])<1e-6))return null;let[f=0,d=0]=e.transformOrigin.split(" ").map(parseFloat);return tt([1,0,0,1,f,d],tt(i,[1,0,0,1,-f,-d]))}function se(e,t,r,i,n,a){let s=e||Bt,o=1/0,l=1/0;for(let[d,c]of[[0,0],[i,0],[0,n],[i,n]]){let[A,E]=Ie(t,d,c),F=s[0]*A+s[2]*E,I=s[1]*A+s[3]*E;F<o&&(o=F),I<l&&(l=I)}let f=re(s,r.x-s[4]-o,r.y-s[5]-l);return f?(a&&a.splice(0,2,f[0],f[1]),tt(s,tt([1,0,0,1,f[0],f[1]],tt(t,[1,0,0,1,-f[0],-f[1]])))):null}function Nt(e,t){let r=re(t,e.x+e.w/2-t[4],e.y+e.h/2-t[5]);if(!r)return null;let i=Math.abs(t[0]),n=Math.abs(t[2]),a=Math.abs(t[1]),s=Math.abs(t[3]),o=i*s-n*a,l,f;return Math.abs(o)>.3*(i*s+n*a)?(l=(e.w*s-n*e.h)/o,f=(i*e.h-a*e.w)/o):(l=e.w/Math.hypot(t[0],t[1]),f=e.h/Math.hypot(t[2],t[3])),{x:r[0]-l/2,y:r[1]-f/2,w:l,h:f}}var oe=new Map;function ke(e){let t=oe.get(e);if(t===void 0){let r=typeof Intl<"u"?Intl.Segmenter:null;try{t=r?new r(e||void 0,{granularity:"word"}):null}catch{t=r?new r(void 0,{granularity:"word"}):null}oe.set(e,t)}return t}function ae(e,t="",r=ke(t)){let i=new Uint8Array(e.length+1),n=!0;if(!r){for(let s=0;s<e.length;s++){let o=/\s/.test(e[s]);!o&&n&&(i[s]=1),n=o}return i}let a=!1;for(let{segment:s,index:o,isWordLike:l}of r.segment(e)){if(!s.trim()){n=!0,a=!1;continue}(n||l&&a)&&(i[o]=1),n=!1,a=!!l}return i}function ct(e){let t=e.length;if(t<2)return{rect:e[0],hyphen:void 0};let r=e[t-1],i=t-1;for(;i>0&&Math.abs(e[i-1].top-r.top)<r.height/2;)i--;let n=i<t-1?e[i+1]:void 0;return{rect:e[i],hyphen:n&&n.width>0?n:void 0}}var Ue=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,Fe=/[\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}\p{sc=Hangul}]/u,Ot=/[\p{L}\p{N}]/u,Ht=e=>!!e&&!/^(inline|contents)/.test(e),Be=/[\u0600-\u08FF\u0900-\u0DFF\u0E00-\u0FFF\u1000-\u109F\u1780-\u17FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function fe(e){if(Be.test(e.textContent||""))return"a script that needs letter shaping";let t=[e,...Array.from(e.querySelectorAll("*"))],r=e.matches('[data-gl-status="ready"],[data-gl-status="loading"][data-gl-play],[data-gl-morphing]');for(let i of t){let n=getComputedStyle(i);if(parseFloat(n.webkitTextStrokeWidth||"0")>0)return"-webkit-text-stroke";if(!r&&n.textShadow&&n.textShadow!="none")return"text-shadow";let a=n.getPropertyValue("-webkit-text-fill-color");if(!r&&a&&a!=n.color&&!/^currentcolor$/i.test(a))return"a -webkit-text-fill-color other than its color";if(/discretionary|historical/.test(n.fontVariantLigatures))return"discretionary or historical ligatures";if(n.backgroundClip==="text"||n.webkitBackgroundClip==="text")return"background-clip: text";if(Oe(n.fontFeatureSettings))return"font-feature-settings";if(n.fontVariationSettings&&n.fontVariationSettings!=="normal")return"font-variation-settings";if(n.textDecorationLine&&n.textDecorationLine!=="none")return"text-decoration (underline / line-through)";if(n.writingMode&&n.writingMode!=="horizontal-tb")return"vertical writing-mode";if(n.textOverflow==="ellipsis")return"text-overflow: ellipsis";if(n.webkitLineClamp&&n.webkitLineClamp!=="none")return"line-clamp";if(n.fontSizeAdjust&&n.fontSizeAdjust!=="none")return"font-size-adjust";if(/full-/.test(n.textTransform))return`text-transform: ${n.textTransform}`;for(let s of[n.fontVariantNumeric,n.fontVariantAlternates,n.fontVariantEastAsian,n.fontVariantPosition])if(s&&s!=="normal")return"font-variant";if(n.fontVariantCaps&&!/^(normal|small-caps)$/.test(n.fontVariantCaps)&&!(typeof CanvasRenderingContext2D<"u"&&"fontVariantCaps"in CanvasRenderingContext2D.prototype))return"font-variant-caps";if(de(n.fontStretch)===void 0)return"a font-stretch between the keyword widths";for(let s of["::before","::after"]){let o=getComputedStyle(i,s).content;if(o&&!/^(none|normal|"\s*")$/.test(o))return`${s} content`}if(n.display.includes("list-item")&&n.listStyleType!=="none")return"a list marker";if(i==e||Ht(n.display))for(let s of["::first-letter","::first-line"]){let o=getComputedStyle(i,s);for(let l of["fontSize","fontFamily","fontWeight","fontStyle","color","letterSpacing","textTransform","fontVariantCaps"])if(o[l]&&o[l]!==n[l])return`a styled ${s}`}}return""}var Ne=new Set(["kern","liga","clig","calt"]);function Oe(e){if(!e||e==="normal")return!1;let t=e.match(/["'][\w ]{4}["']/g)||[];return!t.length||t.some(r=>!Ne.has(r.slice(1,5)))}var le=["color","opacity","font","letterSpacing","wordSpacing","textTransform"];function zt(e,t){let r=t.length!==e.length*le.length,i=0;for(let n of e)for(let a of le)t[i]!==n[a]&&(t[i]=n[a],r=!0),i++;return r}var ue=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"grapheme"}):null;function*We(e){if(ue){yield*ue.segment(e);return}let t=0;for(let r of e)yield{segment:r,index:t},t+=r.length}function ce(e,t,r){try{return r?e.toLocaleUpperCase(t||void 0):e.toLocaleLowerCase(t||void 0)}catch{return r?e.toUpperCase():e.toLowerCase()}}function He(e,t,r,i=""){return t==="uppercase"||t==="capitalize"&&r?ce(e,i,!0):t==="lowercase"?ce(e,i,!1):e}var Wt={"50%":"ultra-condensed","62.5%":"extra-condensed","75%":"condensed","87.5%":"semi-condensed","100%":"",normal:"","112.5%":"semi-expanded","125%":"expanded","150%":"extra-expanded","200%":"ultra-expanded"};function de(e=""){return e?e in Wt?Wt[e]:Object.values(Wt).includes(e)?e:void 0:""}function ze(e,t,r){return e.position==="absolute"&&t<=1&&r<=1&&e.overflow!=="visible"}var he=new WeakSet,ht={hidden:[]};function me(e,t,r,i,n=!1,a){ht.hidden=[];let s=e.getBoundingClientRect();if(s.width<1||s.height<1)return null;let o=e.offsetWidth||s.width,l=e.offsetHeight||s.height,f=Math.abs(s.width-o)<1?1:s.width/o,d=Math.abs(s.height-l)<1?1:s.height/l,c=a?a.width:s.width/f,A=a?a.height:s.height/d,E=[0,0,0,0,0,0],F=getComputedStyle(e),I=parseFloat(F.fontSize)||16,_=Math.ceil(I*.35),h=c+_*2,g=A+_*2,S=Math.min(t,r/Math.max(h,g)),P=i||document.createElement("canvas"),$=Math.max(1,Math.ceil(h*S)),et=Math.max(1,Math.ceil(g*S));P.width!==$&&(P.width=$),P.height!==et&&(P.height=et);let u=P.getContext("2d");if(!u)return null;u.setTransform(1,0,0,1,0,0),u.clearRect(0,0,P.width,P.height),u.setTransform(S,0,0,S,0,0),u.textBaseline="alphabetic",u.textAlign="left";let b=(y,H,V)=>{if(!a)return{x:(y.left-s.left)/f,y:(y.top-s.top)/d,w:y.width/f,h:y.height/d};a.toLocal(y.left+y.width/2,y.top+y.height/2,E);let v=Math.abs(E[2]),x=Math.abs(E[4]),q=Math.abs(E[3]),z=Math.abs(E[5]),N=v*z-x*q,D=H(),j=V;return Math.abs(N)>.3*(v*z+x*q)&&(D=(y.width*z-x*y.height)/N,j=(v*y.height-q*y.width)/N),{x:E[0]-D/2,y:E[1]-j/2,w:D,h:j}},M=y=>a?y:(Math.round((s.top+(y-_)*d)*t)/t-s.top)/d+_,R=new Map,G=y=>{let H=R.get(y);if(H)return H;let V=y===e?F:getComputedStyle(y),v=y===e||!y.parentElement?null:G(y.parentElement);if(!v)H={cs:V,lang:e.closest("[lang]")?.lang||"",hidden:!1,m:null,rest:null,unit:null,alpha:1,faded:null};else{let x=y.offsetWidth||0,q=y.offsetHeight||0,z=v.m,N=v.rest,D=V.display==="inline"?null:ie(V,x,q);if(D===!1)nt.once(`data-gl="text": a 3D transform inside it is painted as drawn now (GL can't undo it). Animate with a glyph() effect instead.`,y);else if(D&&!N){let pt=[0,0];z=se(v.m,D,b(y.getBoundingClientRect(),()=>x,q),x,q,pt)||z,z&&Math.abs(z[0]*z[3]-z[1]*z[2])<1e-6&&(N={x:pt[0],y:pt[1],h:q,adv:0})}let j=parseFloat(V.opacity);H={cs:V,lang:y.getAttribute("lang")??v.lang,hidden:v.hidden||ze(V,x,q),m:z,rest:N,unit:y.hasAttribute("data-line")?y:v.unit,alpha:v.alpha*(j>=0?j:1),faded:j<1?y:v.faded}}return R.set(y,H),H},W=document.createRange(),B=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),L=[],Y="";for(;B.nextNode();)L.push(B.currentNode),Y+=B.currentNode.nodeValue||"";let J=[],ot=ae(Y,G(e).lang),at=new Map,K=[e],Z=!1,bt=!1,Xt=!1,rt=!0,mt=!0,$t=0,Kt=0;for(let y of L){let H=y.nodeValue||"",V=$t;if($t+=H.length,!H.trim()){H&&(rt=mt=!0);continue}let v=y.parentElement;if(!v)continue;let{cs:x,lang:q,hidden:z,m:N,rest:D,unit:j,alpha:pt,faded:Lt}=G(v),Yt=x.textTransform;if(Yt=="capitalize")for(let m=y;m!=e;m=m.parentNode){let w=m.previousSibling;if(w){(w.nodeName=="BR"||w.nodeType==1&&Ht(getComputedStyle(w).display))&&(mt=!0);break}Ht(G(m.parentElement).cs.display)&&(mt=!0)}if(x.visibility==="hidden"||x.display==="none"||z){x.visibility==="hidden"&&!ht.hidden.includes(v)&&ht.hidden.push(v);continue}v!==e&&x.display!=="inline"&&Kt++,!K.includes(v)&&(v===e||v.closest("a, button")||x.color!==G(v.parentElement||e).cs.color)&&K.push(v),Lt&&!K.includes(Lt)&&K.push(Lt);let Re=x.fontVariantCaps==="small-caps"?"small-caps ":"";u.font=`${x.fontStyle} ${Re}${x.fontWeight} ${de(x.fontStretch)||""} ${x.fontSize} ${x.fontFamily}`,"fontVariantCaps"in u&&(u.fontVariantCaps=x.fontVariantCaps||"normal");let gt=x.direction==="rtl";u.direction=gt?"rtl":"ltr",u.fillStyle=x.color,u.globalAlpha=pt,"fontKerning"in u&&(u.fontKerning=x.fontKerning||"auto");let qt=u.measureText("Hg"),lt=qt.fontBoundingBoxAscent??I*.8,wt=qt.fontBoundingBoxDescent??I*.2,_t=(x.hyphenateCharacter||"auto").replace(/^auto$|["']/g,"")||"-",jt=(x.hyphens||x.webkitHyphens)==="auto",Pt=parseFloat(x.letterSpacing)||0,Ct=parseFloat(x.wordSpacing)||0,Qt=(m,w)=>{let p=u;"letterSpacing"in p&&(p.letterSpacing=`${m}px`,p.wordSpacing=`${w}px`)},yt=m=>u.measureText(m).width+Pt,Gt=(m,w)=>{let p;D?(p={x:D.x+D.adv,y:D.y,w:yt(m),h:D.h},D.adv+=p.w):(p=b(w,()=>yt(m),lt+wt),N&&(p=Nt(p,N)||p));let C=p.x+_,k=p.y+_,T=M(k+(p.h-(lt+wt))/2+lt);return u.fillText(m,C,T),Z=!0,Jt(C,p.w,T),{x:C,top:k,baseline:T,b:p}},Jt=(m,w,p)=>bt||=(Xt||=p-lt<-.5||p+wt>g+.5)||m<-.5||m+w>h+.5,Me=j?at.get(j)??at.set(j,at.size).size-1:void 0,Zt=(m,w,p,C,k,T)=>{let O=n?u.measureText(m.p):null,ut=O&&typeof O.actualBoundingBoxAscent=="number"?{l:w-O.actualBoundingBoxLeft,t:T-O.actualBoundingBoxAscent,r:w+O.actualBoundingBoxRight,b:T+O.actualBoundingBoxDescent}:void 0;J.push({x:w,y:p,w:C,h:k,wordStart:rt,ink:ut,rtl:gt,at:V+m.i,ca:m.s.length,unit:Me}),rt=!1},X=[];for(let{segment:m,index:w}of We(H)){let p=!m.trim(),C=Ot.test(m);X.push({i:w,s:m,p:p?m:He(m,Yt,mt&&C,q),sp:p}),(p||C)&&(mt=p)}let Et=(m,w)=>(W.setStart(y,X[m].i),W.setEnd(y,X[w-1].i+X[w-1].s.length),W.getClientRects()),Dt=(m,w)=>{Qt(0,0);let p;for(let C=m;C<w;C++){let k=X[C];if(ot[V+k.i]&&(rt=!0),k.sp){D&&(D.adv+=yt(k.s)+Ct),rt=!0,p=void 0;continue}let{rect:T,hyphen:O}=ct(Et(C,C+1));if(O)Gt(_t,O);else if(p&&T&&jt&&T.top>p.top+p.height/2&&!ot[V+k.i]&&Ot.test(k.s)&&Ot.test(X[C-1].s)&&!Fe.test(X[C-1].s+k.s)){let it=yt(_t)*f,U=p.left+p.width-(p.width-yt(X[C-1].p)*f>it/2?it:0);Gt(_t,{left:U,top:p.top,width:it,height:p.height})}if(p=O||gt?void 0:T,!D&&(!T||T.width<=0))continue;let{x:ut,top:xt,baseline:Tt,b:St}=Gt(k.p,T);Zt(k,ut,xt,St.w,St.h,Tt)}},Le=/^(normal|nowrap|pre-line)$/.test(x.whiteSpace||"normal"),_e=(m,w,p)=>{Qt(Pt,Ct);let C=X.slice(m,w).map((U,Q)=>Le&&U.sp?Q&&X[m+Q-1].sp?"":" ":U.p),k=C.join(""),T=b(p,()=>0,0);if(N&&(T=Nt(T,N)||T),Math.abs(u.measureText(k).width-T.w)>.5)return!1;let O=gt;if(w-m>1&&(gt||Ue.test(k))){let U=ct(Et(m,m+1)).rect,Q=ct(Et(w-1,w)).rect;if(!U||!Q)return!1;O=U.left>Q.left}let ut=T.y+_,xt=M(ut+(T.h-(lt+wt))/2+lt);u.fillText(k,T.x+_,xt),Z=!0,Jt(T.x+_,T.w,xt);let Tt=C.map(U=>U?u.measureText(U).width:0),St=T.w/(Tt.reduce((U,Q)=>U+Q,0)||1),it=T.x+_+(O?T.w:0);for(let U=m;U<w;U++){let Q=X[U],kt=Tt[U-m]*St;ot[V+Q.i]&&(rt=!0),O&&(it-=kt),Q.sp?rt=!0:Zt(Q,it,ut,kt,T.h,xt),O||(it+=kt)}return!0},Pe=!a&&!D&&(!N||!N[1]&&!N[2])&&("letterSpacing"in u||!Pt&&!Ct)&&!/none|no-/.test(x.fontVariantLigatures||"")&&!/["'](liga|clig|calt)["']\s+(0|off)/.test(x.fontFeatureSettings||"")&&!jt&&!x.textAlign.startsWith("justify")&&!H.includes("\xAD")?Ve(X,Et):null,It=0;for(let[m,w,p]of Pe||[])Dt(It,m),_e(m,w,p)||Dt(m,w),It=w;Dt(It,X.length)}if(W.detach?.(),!Z)return null;Kt>=8&&!he.has(e)&&(he.add(e),nt.info('data-gl="text" is split in the DOM: GL paints it at rest and its DOM units stay transparent. Animate with a glyph() effect; keep the DOM animation for when GL is off.',e));let Ae=n?ne(J,P.width/S,P.height/S):void 0;return{canvas:P,pad:_,layoutWidth:c,layoutHeight:A,colorEls:K,boxes:J,text:Y,glyphs:Ae,over:bt,down:Xt}}function Ve(e,t){let r=[];e.forEach((a,s)=>a.sp||r.push(s));let i=t(r[0],r[r.length-1]+1);if(i.length===1)return[[r[0],r[r.length-1]+1,i[0]]];let n=[];for(let a=0;a<r.length;){let s=ct(t(r[a],r[a]+1)).rect;if(!s||s.width<=0)return null;let o=a,l=r.length-1;for(;o<l;){let d=o+l+1>>1,c=ct(t(r[d],r[d]+1)).rect;c&&Math.abs(c.top-s.top)<s.height/2?o=d:l=d-1}let f=t(r[a],r[o]+1);if(f.length!==1)return null;n.push([r[a],r[o]+1,f[0]]),a=o+1}return n}var Xe=["lines","words","chars"],At=class{constructor(t,r,i){this.owner=t;this.level=r;this.index=i;this.text="";this.box={x:0,y:0,w:0,h:0};this.dead=!1}get slot(){return this.owner.base[this.level]+this.index}tween(t,r){let i=this,n=(this.mc||={})[t]||={get value(){return i[t]},set value(a){i[t]=a}};return this.owner.stage.tweens.to(n,r)}};["t","x","y","z"].forEach((e,t)=>Object.defineProperty(At.prototype,e,{get(){return this.dead?0:this.owner.values[this.slot*4+t]||0},set(r){this.dead||this.owner.write(this.slot*4+t,+r)}}));var vt=(e,t)=>Math.abs(e-t)<.01,pe=e=>e.replace(/\s+/g," ").trim(),ge={top:0,center:.5,middle:.5,bottom:1};function ye(e,t){return e.trim().replace(/^(top|center|middle|bottom|-?[\d.]+%|-?[\d.]+(?:px)?)(?=[\s+-]|$)/i,r=>{let i=r.toLowerCase(),n=i in ge?ge[i]*t.h:i.endsWith("%")?parseFloat(i)/100*t.h:parseFloat(i);return`${Math.round((t.y+n)*100)/100}px`})}var ft,$e=0,Rt=class{constructor(t,r){this.plane=t;this.stage=r;this.lines=[];this.words=[];this.chars=[];this.version=0;this.values=new Float32Array(0);this.base=[0,0,0];this.dirty=!1;this.changed=!1;this.rule=null}write(t,r){this.values[t]===r||t>=this.values.length||(this.values[t]=r,(this.plane.usesGlyph||this.plane._inst)&&(this.dirty=!0,this.stage.markDirty()))}update(t,r,i){let{lineOf:n,wordOf:a,lines:s,words:o}=Ft(t),l=[this.lines,this.words,this.chars],f=[s.length,o.length,t.length],d=l.some((h,g)=>h.length!==f[g]),c=[0,f[0],f[0]+f[1]],A=new Float32Array(4*(c[2]+f[2]));l.forEach((h,g)=>A.set(this.values.subarray(this.base[g]*4,(this.base[g]+Math.min(h.length,f[g]))*4),c[g]*4)),this.values=A,this.base=c;let E=new Int32Array(o.length).fill(-1),F=new Int32Array(o.length);for(let h=0;h<t.length;h++)E[a[h]]<0&&(E[a[h]]=h),F[a[h]]=h;let I=(h,g)=>r.slice(t[h].at??0,(t[g].at??0)+(t[g].ca??0)),_=(h,g,S,P,$,et,u)=>{let b=l[h],M=b[g]||=new At(this,h,g),R=M.box;return(M.text!==S||!vt(R.x,P-i)||!vt(R.y,$-i)||!vt(R.w,et)||!vt(R.h,u))&&(d=!0),M.text=S,R.x=P-i,R.y=$-i,R.w=et,R.h=u,M};return s.forEach((h,g)=>{let S=h.chars[0],P=h.chars[h.chars.length-1],$=_(0,g,pe(I(S,P)),h.l,h.t,h.r-h.l,h.b-h.t);$.chars=[S,P],$.words=[a[S],a[P]]}),o.forEach((h,g)=>{let S=_(1,g,pe(I(E[g],F[g])),h.l,h.t,h.r-h.l,h.b-h.t);S.chars=[E[g],F[g]],S.line=n[E[g]]}),t.forEach((h,g)=>{let S=_(2,g,I(g,g),h.x,h.y,h.w,h.h);S.line=n[g],S.word=a[g]}),l.forEach((h,g)=>{for(let S=f[g];S<h.length;S++)h[S].dead=!0;h.length=f[g]}),d&&(this.version++,this.changed=!0),d}progress(t,r={}){if(t!=="lines"&&t!=="words")return nt.warn(`plane.text.progress("${t}"): one per line or word only ("lines" or "words"); a character takes its word's (chars[i].word).`,this.plane.el),[];let i=this.stage.host.engine;return this[t].map(n=>i.progress(this.plane.el,{...r,start:ye(r.start||"top bottom",n.box),end:ye(r.end||"bottom top",n.box)}))}get countsGone(){return!!this.rule&&!this.rule.parentStyleSheet?.ownerNode?.isConnected}writeCounts(){let t=this.plane.el;if(ft?.ownerNode?.isConnected||(ft=document.head.appendChild(document.createElement("style")).sheet),this.rule?.parentStyleSheet!==ft){let r=t.getAttribute("data-gl-css");r||t.setAttribute("data-gl-css",r=`t${++$e}`),this.rule=ft.cssRules[ft.insertRule(`[data-gl-css="${r}"]{}`,ft.cssRules.length)]}for(let r of Xe)this.rule.style.setProperty(`--gl-${r}`,`${this[r].length}`)}dispose(){let t=this.rule,r=t?.parentStyleSheet;r&&!this.plane.el.isConnected&&r.deleteRule([...r.cssRules].indexOf(t)),this.rule=null}};var xe=()=>{let e=typeof window<"u"&&window.occluzeCapture;return e?.version==1?e:null},be=()=>new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=e,t.port2.postMessage(0)});var Ke=e=>xe()?be().then(e):"requestIdleCallback"in window?requestIdleCallback(e,{timeout:2e3}):setTimeout(e,200);function we(e){let t=!1,r=()=>{if(t=!1,e.destroyed||e.lost||e.stats.textureMB*2**21>e.textureBudget)return;let n=e.pageY+e.screen.height/2,a=null,s=1/0;for(let o of e.planes){if(o.kind!=="text"||o.textureState!=="none"||o.status==="error"||o._raster?.empty)continue;let l=o.measured?Math.abs(o.doc.y+o.doc.h/2-n):1e9+o.index;l<s&&(s=l,a=o)}a&&(e.loadMedia(a),i())},i=()=>{t||(t=!0,Ke(r))};return i}var Ee="its words or letters are animating: its DOM shows until they hold still (GL animates them with glyph())",Ye=150,Te=2e3,Se=e=>(e||"").replace(/--[\w-]+\s*:[^;]*;?/g,"").replace(/\s/g,""),ve=/opacity|transform|translate|rotate|scale|filter|clip|visibility/;function Vt(e){if(typeof e.getAnimations!="function")return!1;for(let t of e.getAnimations({subtree:!0})){let r=t.effect;if(!r||r.target===e||r.pseudoElement||t.playState!=="running"||r.getTiming?.().iterations===1/0||t.timeline&&typeof DocumentTimeline<"u"&&!(t.timeline instanceof DocumentTimeline))continue;let i=t.transitionProperty;if(i?ve.test(i):r.getKeyframes().some(n=>Object.keys(n).some(a=>ve.test(a))))return!0}return!1}var Mt=class{constructor(t){this.stage=t;this.changed=new WeakMap;this.ahead=we(t);for(let i of t.planes)i.kind=="text"&&this.units(i);let r=()=>{if(t.scrolled)return;let i=performance.now()+500,n=!1;for(let a of t.planes)a.kind=="text"&&a.soon&&a._raster&&(a._raster.colorUntil=i,n=!0);n&&t.request()};for(let i of["pointerover","pointerout"])t.listen(document,i,r)}blank(t){return{index:new st(t,"uint"),data:new st(t,"float")}}units(t){if(t.text)return;let r=new Rt(t,this.stage);Object.defineProperty(t,"text",{value:r,configurable:!0,enumerable:!0}),t._mods.list.push({name:"text",binding:{update:()=>this.frame(t,r),destroy:()=>r.dispose()}})}load(t){let r=this.stage;this.watch(t),this.units(t),t.textureState="loading";let i=()=>{t.textReason&&(t.textureState="none"),!(!r.planes.includes(t)||r.lost||t.status==="error")&&(this.rasterize(t)||(t.textureState="none"))},n=document.fonts;n?.status==="loading"?Promise.race([n.ready,new Promise(a=>setTimeout(a,1500))]).then(i):i(),this.ahead()}rasterize(t){let r=this.stage,i=t._raster||=new dt;if(t.status==="error")return!1;let n=d=>(d=`data-gl="text" stays normal DOM text: ${d}`,nt.once(d,t.el),i.textDirty=!1,t.textureState="error",t.setStatus("error",d),!1),a=fe(t.el);if(a)return n(`it uses ${a}, which GL text cannot paint. Remove data-gl="text" or that style.`);if(Vt(t.el))return this.hold(t),!1;let s=i.textCanvas||=document.createElement("canvas");s.isConnected||(s.setAttribute("data-gl-canvas","text"),s.style.display="none",r.hostEl.appendChild(s));let o=getComputedStyle(t.el);for(let d of["-webkit-font-smoothing","-moz-osx-font-smoothing"])s.style.setProperty(d,o.getPropertyValue(d));let l=me(t.el,r.dpr,r.maxTexture,s,t.usesGlyph,r.turnedText(t));if(!l)return!i.empty&&(t.textureState=="ready"||t.textureState=="queued")&&(s.width=1,r.media.queueUpload(t,s),t.text?.update([],"",0)),i.colorEls=[],i.colors=[],i.empty=!0,(i.hidden=o.visibility=="hidden")&&(t.opacity=0),i.unitsHidden=i.hidden?[]:ht.hidden,i.textDirty=!1,i.wantKey="",i.rasterKey=this.key(t),!1;if(l.over)return n(l.down?'its text runs past its box, down, and GL paints only the box. Let its height follow its lines (no fixed height), or put data-gl="text" on an element as tall as its text.':'its text runs past its box, and GL paints only the box. Let it wrap (overflow-wrap: anywhere), or put data-gl="text" on an element as wide as its text.');i.empty=i.hidden=!1,i.unitsHidden=ht.hidden,i.textCanvas=l.canvas,i.pending=!0,t.pad=l.pad,t.layoutW=l.layoutWidth,t.layoutH=l.layoutHeight,i.colorEls=l.colorEls.map(d=>getComputedStyle(d)),zt(i.colorEls,i.colors=[]),i.rasterKey=this.key(t),i.wantKey="",i.textDirty=!1,t.textureState=t.texture?.ready?"ready":"queued",t.usesGlyph&&(i.glyphPending=i.table=l.glyphs||null);let f=t.text;return f&&(f.update(l.boxes,l.text,l.pad),f.dirty||=!!i.table),r.media.queueUpload(t,l.canvas),r.markDirty(),!0}frame(t,r){r.changed?(r.changed=!1,r.writeCounts(),t.emit("text")):r.countsGone&&r.writeCounts();let i=t._raster,n=i?.table;return!r.dirty||!n?!1:(r.dirty=!1,n.data.set(r.values.subarray(0,(n.lines+n.words+n.chars)*4),n.values*4),i.glyphPending!==n&&i.glyphData?.ready&&i.glyphData.upload(n.dataWidth,n.dataHeight,n.data),!0)}key(t){let r=t.el,i=t._raster||=new dt;return(t.stale||i.wantKey||!i.size)&&(i.size=`${r.offsetWidth||Math.round(t.doc.w)}x${r.offsetHeight||Math.round(t.doc.h)}`),`${i.size}@${this.stage.dpr}`}check(t,r,i){let n=t._raster||=new dt,a=this.key(t);if(n.hidden&&t.opacity>0)return void this.rasterize(t);if(n.unitsHidden.length&&(t.stale||i||r<n.colorUntil)){for(let o of n.unitsHidden)if(getComputedStyle(o).visibility!=="hidden")return void this.rasterize(t)}if(n.textDirty&&!n.rasterKey){this.rasterize(t);return}if(!n.textDirty&&a===n.rasterKey)n.wantKey="";else{a!==n.wantKey&&(n.wantKey=a,n.wantSince=r),t.soon&&(a===n.rasterKey||r-n.wantSince>=150)&&r-(this.changed.get(t)||0)>=100&&this.rasterize(t);return}let s=i||t.stale||r<n.colorUntil;r<n.colorUntil&&this.stage.request(),t.soon&&s&&n.colorEls.length&&zt(n.colorEls,n.colors)&&(n.colorUntil=r+400,this.rasterize(t))}watch(t){let r=t._raster||=new dt;r.textObserver||(r.textObserver=new MutationObserver(i=>{let n=!1,a=!1,s=!1;for(let o of i)if(o.type!=="attributes")n=!0;else{if(o.target===t.el)continue;o.attributeName=="class"?s=!0:o.attributeName=="style"?a||=Se(o.oldValue)!==Se(o.target.getAttribute("style")):!o.attributeName.startsWith("data-gl")&&o.oldValue!==o.target.getAttribute(o.attributeName)&&(n=!0)}n&&(r.textDirty=!0,r.empty=!1,this.changed.set(t,performance.now()),t.stale=!0,this.stage.markDirty()),a||s&&Vt(t.el)?this.hold(t):s&&(r.colorUntil=performance.now()+400,this.stage.markDirty())}),r.textObserver.observe(t.el,{characterData:!0,childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0}))}hold(t){let r=t._raster;clearTimeout(r.quiet),r.quiet=setTimeout(()=>this.settle(t),Ye),!t.textReason&&(t.warned.add(Ee),t.textReason=Ee,this.stage.decide(t))}settle(t){let r=t._raster;if(!(!r||!this.stage.planes.includes(t))){if(r.quiet=0,Vt(t.el))return this.hold(t);t.texture&&(t.texture.ready=!1),r.textDirty=!0,this.changed.set(t,0),t.stale=!0,!t.program&&!this.stage.lost&&this.stage.programs.prepare(t),t.textReason=null,this.stage.decide(t),this.stage.markDirty()}}},dt=class{constructor(){this.textDirty=!0;this.empty=!1;this.hidden=!1;this.unitsHidden=[];this.rasterKey="";this.size="";this.colorEls=[];this.colors=[];this.colorUntil=0;this.wantKey="";this.wantSince=0;this.textCanvas=null;this.pending=!1;this.fresh=!1;this.freeTimer=0;this.textObserver=null;this.quiet=0;this.glyphPending=null;this.table=null;this.glyphIndex=null;this.glyphData=null;this.free=()=>{this.freeTimer=this.fresh||this.pending?setTimeout(this.free,Te):0,this.fresh=!1,!this.freeTimer&&this.textCanvas&&(this.textCanvas.width=1)}}upload(t){this.pending=!1,this.fresh=!0,this.freeTimer||=setTimeout(this.free,Te);let r=this.glyphPending;r&&(this.glyphPending=null,this.glyphIndex||=new st(t,"uint"),this.glyphData||=new st(t,"float"),this.glyphIndex.upload(r.width,r.height,r.index),this.glyphData.upload(r.dataWidth,r.dataHeight,r.data))}lost(){this.glyphIndex=this.glyphData=this.glyphPending=null}dispose(t){clearTimeout(this.quiet),clearTimeout(this.freeTimer),t?.textReason&&(t.textReason=null,t.el.removeAttribute("data-gl-status")),this.textCanvas?.remove(),this.textObserver?.disconnect(),this.textObserver=null,this.glyphIndex?.dispose(),this.glyphData?.dispose(),this.lost()}};function wn(e,t){te(e.host.log),e.text=new Mt(e),e.remake(e.glyphWaiting);let r=[...e.textWaiting];e.textWaiting.clear();for(let i of r)!e.planes.includes(i)||i.textureState!=="loading"||(i.textureState="none",e.loadMedia(i));t&&e.remake(new Set(e.planes.filter(i=>i.kind==="text"&&i.textureState==="error")))}export{Ge as GLYPH_HELPER,wn as textPlanes};
|
|
1
|
+
/*! Umber v0.4.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
var t=()=>{};var e=()=>Promise.reject(new Error("no words"));var i={configure:t,debug:!1,warnings:!1,info:t,warn:t,error:t,report:t,words:e},r=i;function s(t){r=t}var n=(t,e)=>t[e]??NaN;var a=class{constructor(t,e){this.gl=t;this.format=e;this.width=1;this.height=1;this.ready=!1;this.texture=t.createTexture(),this.upload(1,1,e==="uint"?new Uint16Array(1):new Float32Array(4)),this.ready=!1}get bytes(){return this.ready?this.width*this.height*(this.format==="uint"?2:16):0}upload(t,e,i){let r=this.gl;r.bindTexture(r.TEXTURE_2D,this.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.pixelStorei(r.UNPACK_ALIGNMENT,1),this.format==="uint"?r.texImage2D(r.TEXTURE_2D,0,r.R16UI,t,e,0,r.RED_INTEGER,r.UNSIGNED_SHORT,i):r.texImage2D(r.TEXTURE_2D,0,r.RGBA32F,t,e,0,r.RGBA,r.FLOAT,i),r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),this.width=t,this.height=e,this.ready=!0}dispose(){this.texture&&this.gl.deleteTexture(this.texture),this.texture=null,this.ready=!1}};var l=class{constructor(t,e,i){this.canvas=t;this.ctx=e;this.layout=i;this.local=[0,0,0,0,0,0];this.joins=3;this.start=!0;this.fills=t?null:[]}fill(t,e,i){let{ctx:r,fills:s}=this;if(!s){r.fillText(t,e,i);return}let n=r;s.push({text:t,x:e,y:i,font:r.font,letterSpacing:n.letterSpacing??"0px",wordSpacing:n.wordSpacing??"0px",kerning:n.fontKerning??"auto",caps:n.fontVariantCaps??"normal",rtl:r.direction==="rtl",color:typeof r.fillStyle=="string"?r.fillStyle:"#000000",alpha:r.globalAlpha,joins:this.joins,start:this.start}),this.start=!0}ia(t,e,i){let{box:r,scaleX:s,scaleY:n,turned:a}=this.layout;if(!a)return{x:(t.left-r.left)/s,y:(t.top-r.top)/n,w:t.width/s,h:t.height/n};let l=this.local;a.toLocal(t.left+t.width/2,t.top+t.height/2,l);let h=Math.abs(l[2]),o=Math.abs(l[4]),u=Math.abs(l[3]),d=Math.abs(l[5]),c=h*d-o*u,f=e(),g=i;return Math.abs(c)>.3*(h*d+o*u)&&(f=(t.width*d-o*t.height)/c,g=(h*t.height-u*t.width)/c),{x:l[0]-f/2,y:l[1]-g/2,w:f,h:g}}snap(t){let{box:e,scaleY:i,pad:r,deviceScale:s,turned:n,top:a}=this.layout;return n?t:(Math.round((e.top+(t-r)*i)*s)/s-a)/i+r}};function h(t,e,i,r){let s=r.turned??null,n=t.offsetWidth||e.width,a=t.offsetHeight||e.height,h=Math.abs(e.width-n)<1?1:e.width/n,d=Math.abs(e.height-a)<1?1:e.height/a,f=s?s.width:e.width/h,g=s?s.height:e.height/d,p=Math.ceil(i*.35),x=o(s,h,d,r.scale),m=f+p*2,y=g+p*2,b=Math.min(r.scale,r.maxSize/Math.max(m,y)),w=Math.max(1,Math.ceil(m*b)),v=Math.max(1,Math.ceil(y*b)),T=null,E;if(r.record){if(E=c(),!E)return null;E.setTransform(1,0,0,1,0,0),E.globalAlpha=1}else{if(T=r.canvas??document.createElement("canvas"),T.width!==w&&(T.width=w),T.height!==v&&(T.height=v),E=T.getContext("2d"),!E)return null;E.setTransform(1,0,0,1,0,0),E.clearRect(0,0,T.width,T.height),E.setTransform(b,0,0,b,0,0)}return E.textBaseline="alphabetic",E.textAlign="left",new l(T,E,{box:e,scaleX:h,scaleY:d,scale:b,deviceScale:r.scale,pad:p,layoutWidth:f,layoutHeight:g,width:m,height:y,pixelWidth:w,pixelHeight:v,turned:s,grid:x,top:u(e.top,x)})}var o=(t,e,i,r)=>!t&&e===1&&i===1?r:0,u=(t,e)=>e?Math.round(t*e)/e:t,d;function c(){return d===void 0&&(d=document.createElement("canvas").getContext("2d")),d}var f=3,g=4,p=1024,x=4096,m=64,y=16,b=new RegExp("\\p{Extended_Pictographic}|\\p{Regional_Indicator}","u"),w=t=>Math.ceil(t/g)*g,v=class{constructor(t,e){this.gl=t;this.color=e;this.texture=null;this.size=0;this.Bl=[];this.bottom=0}get bytes(){return this.texture?this.size*this.size*(this.color?4:1)*1.3125:0}open(t){let e=this.gl;this.texture&&e.deleteTexture(this.texture),this.texture=e.createTexture(),this.size=t,this.Bl=[],this.bottom=0,e.bindTexture(e.TEXTURE_2D,this.texture),e.texStorage2D(e.TEXTURE_2D,3,this.color?e.RGBA8:e.R8,t,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAX_LEVEL,2)}pack(t,e){if(t>this.size||e>this.size)return null;let i=null;for(let r of this.Bl)r.h>=e&&r.h<=e*1.5+g&&r.x+t<=this.size&&(!i||r.h<i.h)&&(i=r);if(!i){if(this.bottom+e>this.size)return null;i={y:this.bottom,h:e,x:0},this.Bl.push(i),this.bottom+=e}let r=[i.x,i.y];return i.x+=t,r}close(){this.texture&&this.gl.deleteTexture(this.texture),this.forget(),this.Bl=[],this.bottom=0}forget(){this.texture=null,this.size=0}};function T(t){let e=/^#([\da-f]{6})$/i.exec(t)?.[1];if(e){let t=parseInt(e,16);return[(t>>16)/255,(t>>8&255)/255,(t&255)/255,1]}let i=/^rgba?\(([^)]*)\)$/.exec(t)?.[1]?.split(/[\s,/]+/).filter(Boolean).map(Number);if(!i||i.length<3||i.some(t=>!Number.isFinite(t)))return null;let[r=0,s=0,n=0,a=1]=i;return[r/255,s/255,n/255,a]}var E=new Map,k;function S(t){let e=E.get(t)??T(t);if(e)return e;if(k??=document.createElement("canvas").getContext("2d",{willReadFrequently:!0}),e=[0,0,0,1],k){k.clearRect(0,0,1,1),k.fillStyle=t,k.fillRect(0,0,1,1);let[i=0,r=0,s=0,n=255]=k.getImageData(0,0,1,1).data;e=[i/255,r/255,s/255,n/255]}return E.set(t,e),e}var M=([t,e,i])=>`rgb(${Math.round(t*255)}, ${Math.round(e*255)}, ${Math.round(i*255)})`,R=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/;function A(t,e){let i=[];if(e||R.test(t))return t.trim()&&i.push([0,t]),i;for(let e of t.matchAll(/\S+/g))i.push([e.index,e[0]]);return i}function C(t,e){t.font=e.font,"letterSpacing"in t&&(t.letterSpacing=e.letterSpacing,t.wordSpacing=e.wordSpacing),"fontKerning"in t&&(t.fontKerning=e.kerning),"fontVariantCaps"in t&&(t.fontVariantCaps=e.caps),t.direction=e.rtl?"rtl":"ltr",t.textAlign="left",t.textBaseline="alphabetic"}var F=/^f[filt]$/,U=new RegExp("^(?:\\u200d|[\\ufe0e\\ufe0f]|\\p{Emoji_Modifier}|\\p{Mark})","u");function _(t,e){let i=[],r=0;for(let s of t){let t=i.at(-1),n=e&&!!t&&F.test(t[1]+s);t&&(U.test(s)||t[1].endsWith("\u200d")||n)?t[1]+=s:i.push([r,s]),r+=s.length}return i}function L(t,e){let i=t[e],r=0;for(;i;r++){let s=t[e+r];if(!s||s.rtl||Array.from(s.text).length!==1||r&&(s.start||s.font!==i.font||s.y!==i.y||s.joins!==i.joins))break}return Math.max(1,r)}var P=2048;function B(t){let e=[],i=0,r=0,s=0,n=1;for(let a of t)i&&i+a.w>P&&(i=0,r+=s,s=0),e.push([i,r]),i+=a.w,s=Math.max(s,a.h),n=Math.max(n,i);return{spots:e,width:n,height:Math.max(1,r+s)}}function D(t,e,i,[r,s]){let n=t.page?4:1,a=new Uint8Array(t.w*t.h*n);for(let l=0;l<t.h;l++){let h=((s+l)*i+r)*4;for(let i=0;i<t.w;i++){let r=h+i*4,s=e[r+3]??0,o=(l*t.w+i)*n;if(n===1){a[o]=s;continue}for(let t=0;t<3;t++)a[o+t]=(e[r+t]??0)*s/255;a[o+3]=s}}return a}var I=2e3,z=class{constructor(t,e,i){this.gl=t;this.host=e;this.maxTexture=i;this.color=null;this.entries=new Map;this.fresh=[];this.users=new Set;this.Qg=!1;this.canvas=null;this.ctx=null;this.mono=new v(t,!1)}texture(t){return t?this.color?.texture??null:this.mono.texture}get bytes(){return this.mono.bytes+(this.color?.bytes??0)}get size(){return this.entries.size}place(t,e,i,r=null){let s=this.Ha(i);if(!s)return null;let n=[],a=t=>({fill:t,rgba:S(t.color),scale:e,smoothing:i.join(",")});for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;C(s,i);let l=r?.draw?L(t,e):1,h=l>1&&i.caps==="normal"?r?.fonts.find(i.font):null,o=h?r?.fonts.letters(h,t.slice(e,e+l).map(a)):null;if(o){n.push(...o),e+=l-1;continue}let u=a(i);if(!this.Af(s,u,r,n))return this.release(n),this.flush(),null}return this.flush(),n}Af(t,e,i,r){let{fill:s}=e,n=s.rtl||s.caps!=="normal"?null:i?.fonts.find(s.font),a=e=>e?t.measureText(s.text.slice(0,e)).width:0;for(let[l,h]of A(s.text,s.rtl)){let o=n&&i?.draw?i.fonts.word(t,n,e,{text:h,advance:a(l)}):null,u=(s.joins&2)>0,d=(i?.letters||!u)&&!R.test(h)?_(h,u):[[0,h]],c=(e,i)=>e?a(l+e+i.length)-t.measureText(i).width:a(l),f=o??d.map(([i,r])=>this.word(t,e,r,c(i,r)));for(let t of f)t&&r.push(t);if(f.includes(null))return!1}return!0}release(t){for(let{entry:e}of t)e.refs=Math.max(0,e.refs-1);if(this.fresh.length)return;let e=!1;for(let t of[0,1]){let i=t?this.color:this.mono;if(!(!i?.texture||this.live(t).length)){for(let[e,i]of this.entries)i.page===t&&this.entries.delete(e);i.close(),e=!0}}if(e)for(let t of this.users)t.refresh()}word(t,e,i,r){let{fill:s,rgba:n,scale:a}=e,l=Math.round((s.x+r)*a*m)/m,h=Math.round(s.y*a*y)/y,o=Math.floor(l),u=Math.floor(h),d=l-o,c=h-u,f=b.test(i),g={text:i,font:s.font,letterSpacing:s.letterSpacing,wordSpacing:s.wordSpacing,kerning:s.kerning,caps:s.caps,rtl:s.rtl,color:f?s.color:M(n),scale:a},p=[i,g.font,g.letterSpacing,g.wordSpacing,g.kerning,g.caps,g.rtl,g.color,a,d,c,e.smoothing].join("\x01"),x=this.entries.get(p)??this.make(t,{key:p,paint:g,page:f?1:0,fx:d,fy:c});if(!x)return null;x.refs++;let w=n[3]*s.alpha;return{entry:x,x:o-Math.floor(x.ox),y:u-Math.floor(x.oy),tint:f?[1,1,1,w]:[n[0],n[1],n[2],w]}}make(t,{key:e,paint:i,page:r,fx:s,fy:n}){let a=t.measureText(i.text),l=parseFloat(/(\d*\.?\d+)px/.exec(i.font)?.[1]??"16")||16,{scale:h}=i,o=t=>Math.max(0,Math.ceil(t*h)),u=o(a.actualBoundingBoxLeft??l*.3),d=o(a.actualBoundingBoxRight??(a.width??l)+l*.3),c=o(a.actualBoundingBoxAscent??l),g=o(a.actualBoundingBoxDescent??l*.4),p=f+1,x=p+u,m=p+c,y={key:e,page:r,x:0,y:0,w:w(x+d+p),h:w(m+g+p),ox:x+s,oy:m+n,ink:[p-1,p-1,x+d+1,m+g+1],refs:0,paint:i};return this.fit(y)?(this.entries.set(e,y),this.fresh.push(y),y):null}fit(t){let e=this.Fg(t.page);e.texture||e.open(p);let i=Math.max(p,Math.min(x,this.maxTexture));if(t.w>i||t.h>i)return!1;let r=e.pack(t.w,t.h),s=e.size,n=!1;for(;!r;){let a=this.mk(t.page)>this.live(t.page).length;if(n||!a){if(s>=i)return!1;s=Math.min(i,s*2)}n=!0,this.Ch(t.page,s),r=e.pack(t.w,t.h)}return[t.x,t.y]=r,!0}Fg(t){return t?this.color??=new v(this.gl,!0):this.mono}live(t){let e=new Set(this.fresh);return[...this.entries.values()].filter(i=>i.page===t&&(i.refs>0||e.has(i)))}mk(t){let e=0;for(let i of this.entries.values())i.page===t&&e++;return e}Ch(t,e){let i=this.Fg(t),r=this.live(t).sort((t,e)=>e.h-t.h),s=new Set(r),n=new Set(this.fresh);for(let[e,i]of this.entries)i.page===t&&!s.has(i)&&this.entries.delete(e);i.open(e);for(let t of r){let e=i.pack(t.w,t.h);if(!e){this.entries.delete(t.key);continue}[t.x,t.y]=e,n.has(t)||this.fresh.push(t)}this.Qg=!0}Ha(t){this.canvas||(this.canvas=document.createElement("canvas"),this.canvas.setAttribute("data-umber-canvas","text"),this.canvas.style.display="none",this.ctx=this.canvas.getContext("2d",{willReadFrequently:!0}));let e=this.canvas,[i="",r=""]=t;return e.style.getPropertyValue("-webkit-font-smoothing")!==i&&e.style.setProperty("-webkit-font-smoothing",i),e.style.getPropertyValue("-moz-osx-font-smoothing")!==r&&e.style.setProperty("-moz-osx-font-smoothing",r),this.ctx}flush(){let t=this.fresh;if(this.fresh=[],t.length){let e=this.canvas;e&&this.host.appendChild(e);for(let e=0;e<t.length;){let i=e+1,r=t[e]?.h??0;for(;i<t.length&&r+(t[i]?.h??0)<=P;)r+=t[i++]?.h??0;this.paint(t.slice(e,i)),e=i}e?.remove()}if(this.Qg){this.Qg=!1;for(let t of this.users)t.refresh()}}paint(t){let{ctx:e,canvas:i,gl:r}=this;if(!e||!i)return;let{spots:s,width:n,height:a}=B(t);(i.width<n||i.height<a)&&(i.width=Math.max(i.width,n),i.height=Math.max(i.height,a)),e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,n,a),t.forEach((t,i)=>{let[r=0,n=0]=s[i]??[];C(e,t.paint),e.fillStyle=t.paint.color,e.globalAlpha=1,e.setTransform(t.paint.scale,0,0,t.paint.scale,r+t.ox,n+t.oy),e.fillText(t.paint.text,0,0)}),e.setTransform(1,0,0,1,0,0);let l=e.getImageData(0,0,n,a).data;r.pixelStorei(r.UNPACK_ALIGNMENT,1),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);let h=new Set;t.forEach((t,e)=>{let i=this.Fg(t.page),a=s[e];if(!i.texture||!a)return;r.bindTexture(r.TEXTURE_2D,i.texture);let o=i.color?r.RGBA:r.RED,u=D(t,l,n,a);r.texSubImage2D(r.TEXTURE_2D,0,t.x,t.y,t.w,t.h,o,r.UNSIGNED_BYTE,u),h.add(i)}),r.pixelStorei(r.UNPACK_ALIGNMENT,4);for(let t of h)r.bindTexture(r.TEXTURE_2D,t.texture),r.generateMipmap(r.TEXTURE_2D);clearTimeout(this.Cc),this.Cc=setTimeout(()=>{i.width=1,i.height=1},I)}lost(){this.mono.forget(),this.color?.forget(),this.entries.clear(),this.fresh=[],this.users.clear()}};var W=t=>fetch(t,t.startsWith(location.origin+"/")?{mode:"no-cors",credentials:"include"}:{});function $(t,e){let i=e.get(t);return i||(i=W(t).then(t=>t.ok?t.json():null).catch(()=>null),e.set(t,i)),i}function N(t){let e=/(\d*\.?\d+)px(?:\s*\/\s*\S+)?\s+(.+)$/.exec(t);if(!e)return{keys:[],px:0};let i=t.slice(0,e.index),r=/\b([1-9]00)\b/.exec(i)?.[1]??(/\bbold\b/.test(i)?"700":"400"),s=/\b(italic|oblique)\b/.test(i)?"italic":"normal";return{keys:(e[2]??"").split(",").map(t=>t.trim().replace(/^["']|["']$/g,"").toLowerCase()).map(t=>`${t}|${r}|${s}`),px:Number(e[1])}}var V=5e3,j=t=>Promise.race([t,new Promise(t=>setTimeout(t,V))]),H=class{constructor(t,e,i,r=new Map){this.gl=t;this.arrived=e;this.missing=i;this.reads=r;this.chunk=null;this.tables=null;this.manifest=null;this.loading=null;this.loaded=new Map;this.asked=new Set;this.meta=document.querySelector('meta[name="umber-assets"]')?.content;this.loadChunk=()=>import(new URL("./curves.js",import.meta.url).href)}get waiting(){return this.asked.size>this.loaded.size}ahead(){return this.meta?j(this.Il().then(t=>t&&this.shader())).catch(t):null}async shader(){let t=await(this.loading??=this.loadChunk());return this.tables?this.tables:(this.chunk=t,this.tables=new t.CurveTables(this.gl),this.arrived(!0),this.tables)}find(t){if(!this.meta)return null;let{keys:e,px:i}=N(t);for(let t of e){let e=this.loaded.get(t);if(e)return{font:e,px:i};if(e!==null)return this.asked.has(t)||(this.asked.add(t),this.fetch(t)),null}return null}word(t,e,i,r){return this.chunk?.curveWord(t,e,i,r)??null}letters(t,e){return this.chunk?.curveLetters(t,e)??null}Il(){return this.manifest??=(async()=>{let t=new URL(this.meta??"",document.baseURI),e=await $(t.href,this.reads);return e?.v===1&&e.fonts?{url:t,fonts:e.fonts}:null})(),this.manifest}async fetch(t){let e=null;try{let i=await this.Il(),r=i?.fonts[t];if(i&&r){let t=W(new URL(`${r}.glyphs`,i.url).href).then(t=>{if(!t.ok||!t.body)throw new Error(`HTTP ${t.status}`);return new Response(t.body.pipeThrough(new DecompressionStream("deflate"))).arrayBuffer()}),s=await j(Promise.all([this.shader(),t]));s&&(e=s[0].add(s[1]))}else if(i){let e=Object.keys(i.fonts).filter(e=>e.startsWith(t.slice(0,t.indexOf("|")+1)));e[0]&&this.missing?.(t,e)}}catch{}this.loaded.set(t,e),this.arrived(!1)}};var G=4,X=32,q=4,O=2,K=1024;function Y(t,e,i){for(let r=X;r>=q;r/=2){let s=Z(t,e,i,r);if(s)return Q(t,[e,i,r],s)}return null}function Z(t,e,i,r){let s=Math.max(1,Math.ceil(e/r)),n=Math.max(1,Math.ceil(i/r)),a=Array.from({length:s*n},()=>[]);for(let[e,{entry:i,x:l,y:h}]of t.entries()){let[t,o,u,d]=i.ink,c=Math.max(0,Math.floor((l+t-O)/r)),f=Math.max(0,Math.floor((h+o-O)/r)),g=Math.min(s-1,Math.floor((l+u+O-1)/r)),p=Math.min(n-1,Math.floor((h+d+O-1)/r));for(let t=f;t<=p;t++)for(let i=c;i<=g;i++){let r=a[t*s+i];if(r){if(r.length>=G)return null;r.push(e+1)}}}return{across:s,cells:a}}function Q(t,[e,i,r],{across:s,cells:n}){let a=2+3*t.length,l=a+n.length,h=Math.min(K,l),o=Math.ceil(l/h),u=new Float32Array(h*o*4);return u.set([e,i,s,r,2,a,0,0],0),t.forEach(({entry:t,x:e,y:i,tint:r},s)=>{let n=(2+3*s)*4,a=t.curve?[t.x,t.y,-t.curve[1],t.curve[0]]:[t.x,t.y,t.page,0];u.set([e,i,t.w,t.h,...a,...r],n)}),n.forEach((t,e)=>{u.set(t,(a+e)*4)}),{data:u,width:h,height:o}}var J=class{constructor(t,e){this.atlas=e;this.width=1;this.height=1;this.ready=!1;this.refs=0;this.box=[];this.$g=[];this.revision=0;this.texture=e.texture(0),this.layout=new a(t,"float"),e.users.add(this)}get placed(){return this.$g}get Rc(){return this.atlas.texture(1)}get bytes(){let t;for(let e of this.atlas.users){t=e;break}return(this.ready?this.layout.bytes:0)+(t===this?this.atlas.bytes:0)}upload(){return!1}adopt(){}angle(){}show(t,e,i){let r=Y(t,e,i);return r?(this.atlas.release(this.$g),this.$g=t,this.width=e,this.height=i,this.layout.upload(r.width,r.height,r.data),this.texture=this.atlas.texture(0),this.ready=!0,this.revision++,!0):(this.atlas.release(t),!1)}refresh(){if(this.texture=this.atlas.texture(0),this.revision++,!this.ready)return;let t=Y(this.$g,this.width,this.height);t&&this.layout.upload(t.width,t.height,t.data)}dispose(){this.atlas.release(this.$g),this.$g=[],this.atlas.users.delete(this),this.layout.dispose(),this.texture=null,this.ready=!1}},tt={used:/\bumberText\s*\(/,defined:/\bvec4\s+umberText\s*\(\s*vec2\s+\w+\s*\)\s*\{/,code:it("float umberCurveGlyph(vec2 l,vec4 a,vec2 p){return 0.0;}")};function et(t){tt.code=it(t)}function it(t){return t+`\nuniform highp sampler2D uUmberTextLayout;\nuniform sampler2D uUmberTextColor;\nvec4 umberTextRow(highp int i){\nreturn texelFetch(uUmberTextLayout,ivec2(i&1023,i>>10),0);\n}\nvoid umberTextWord(float id,highp int first,vec2 p,float lod,vec2 pxPer,inout vec4 sum){\nhighp int q=first+3*(int(id+0.5)-1);\nvec4 r=umberTextRow(q);\nvec2 l=p-r.xy;\nif(l.x<0.0||l.y<0.0||l.x>=r.z||l.y>=r.w)return;\nvec4 a=umberTextRow(q+1);\nvec4 tint=umberTextRow(q+2);\nvec4 s;\nif(a.z<0.0)s=vec4(tint.rgb,1.0)*(umberCurveGlyph(l,a,pxPer)*tint.a);\nelse if(a.z>0.5)s=textureLod(uUmberTextColor,(a.xy+l)/vec2(textureSize(uUmberTextColor,0)),lod)*tint.a;\nelse s=vec4(tint.rgb,1.0)*(textureLod(uImage,(a.xy+l)/vec2(textureSize(uImage,0)),lod).r*tint.a);\nsum=s+sum*(1.0-s.a);\n}\nvec4 umberText(vec2 f){\nvec4 head=umberTextRow(0);\nvec2 p=f*head.xy;\nvec2 dx=dFdx(p);\nvec2 dy=dFdy(p);\nif(head.z<0.5)return texture(uImage,f);\nif(f.x<0.0||f.y<0.0||f.x>=1.0||f.y>=1.0)return vec4(0.0);\n#ifdef UMBER_TEXT_FLAT\nfloat lod=0.0;\n#else\nfloat lod=max(0.0,0.5*log2(max(dot(dx,dx),dot(dy,dy))));\n#endif\nvec4 info=umberTextRow(1);\nhighp ivec2 cell=ivec2(p/head.w);\nvec4 ids=umberTextRow(int(info.y+0.5)+cell.y*int(head.z+0.5)+cell.x);\nhighp int first=int(info.x+0.5);\nvec4 sum=vec4(0.0);\nvec2 pxPer=1.0/max(vec2(length(vec2(dx.x,dy.x)),length(vec2(dx.y,dy.y))),vec2(1e-4));\nfor(int k=0;k<4;k++){\nif(ids[k]<0.5)break;\numberTextWord(ids[k],first,p,lod,pxPer,sum);\n}\nreturn sum;\n}`}var rt=/\bvec4 umberText\(vec2 f\) ?\{/,st=["umberInkBox","umberGlyphRow","umberTint"],nt=`${st.map((t,e)=>`layout(location = ${e+1}) in vec4 ${t};\n`).join("")}uniform highp sampler2D uUmberTextLayout;\nuniform float uUmberQuads;\nflat out vec4 vUmberInk;\nflat out vec4 vUmberRow;\nflat out vec4 vUmberTint;\n`,at=`\nif(uUmberQuads>0.5){\nuv=(umberInkBox.xy+aPosition*umberInkBox.zw)/texelFetch(uUmberTextLayout,ivec2(0),0).xy;\nvUv=uv;\n}\nvUmberInk=umberInkBox;\nvUmberRow=umberGlyphRow;\nvUmberTint=umberTint;\n`,lt=`uniform float uUmberQuads;\nflat in vec4 vUmberInk;\nflat in vec4 vUmberRow;\nflat in vec4 vUmberTint;\n`,ht=`\nvec4 umberText(vec2 f){\nif(uUmberQuads<0.5)return umberTextWhole(f);\nvec2 p=f*umberTextRow(0).xy;\nvec2 dx=dFdx(p);\nvec2 dy=dFdy(p);\nvec2 l=p-vUmberInk.xy;\nif(l.x<0.0||l.y<0.0||l.x>=vUmberInk.z||l.y>=vUmberInk.w)return vec4(0.0);\nvec2 pxPer=1.0/max(vec2(length(vec2(dx.x,dy.x)),length(vec2(dx.y,dy.y))),vec2(1e-4));\nreturn vec4(vUmberTint.rgb,1.0)*(umberCurveGlyph(l,vUmberRow,pxPer)*vUmberTint.a);\n}\n`,ot=class{constructor(t,e){this.stage=t;this.plane=e;this.spec={mode:"quads"};this.grid=null;this.vao=null;this.buffers=[];this.data=st.map(()=>new Float32Array(4));this.count=0;this.revision=-1;this.dirty=!0;this.outlines=!1}get key(){return this.plain?"":"|q"}get plain(){return this.plane.effects.length>0||!!this.plane.shader}build(t){if(this.plain)return t;let e=t.chunks??{vertex:"",fragment:""};return{...t,effects:[{name:"quads",def:{vertex:{main:at}}}],chunks:{vertex:`// glyph quads\n${nt}\n${e.vertex}`,fragment:`// glyph quads\n${lt}${tt.code.replace(rt,"vec4 umberTextWhole(vec2 f) {")}${ht}\n${e.fragment}`}}}wrap(t){return this.grid!==t&&this.drop(),this.grid=t,this}fill(){let t=this.plane.texture;if(!(t instanceof J)||!t.ready){this.outlines=!1;return}if(t.revision===this.revision)return;this.revision=t.revision;let e=t.placed;if(this.outlines=e.length>0&&e.every(t=>t.entry.curve),!this.outlines)return;this.count=e.length;let[i,r,s]=this.data.map(t=>t.length===this.count*4?t:new Float32Array(this.count*4));!i||!r||!s||(this.data=[i,r,s],e.forEach(({entry:t,x:e,y:n,tint:a},l)=>{let[h=0,o=1]=t.curve??[];i.set([e,n,t.w,t.h],l*4),r.set([t.x,t.y,-o,h],l*4),s.set(a,l*4)}),this.dirty=!0)}draw(){let t=this.stage.gpu.gl,e=this.grid,i=this.plane.program;if(!e||!i)return;if(this.plain||!i.uniforms.has("uUmberQuads")){e.draw();return}this.fill(),this.vao||this.Df(e),this.dirty&&(this.dirty=!1,this.data.forEach((e,i)=>{t.bindBuffer(t.ARRAY_BUFFER,this.buffers[i]??null),t.bufferData(t.ARRAY_BUFFER,e,t.DYNAMIC_DRAW)}));let r=this.outlines&&this.plane.opacity>=1;i.set("uUmberQuads",r?1:0),t.bindVertexArray(this.vao),t.drawElementsInstanced(t.TRIANGLES,e.count,t.UNSIGNED_SHORT,0,r?this.count:1)}Df(t){let e=this.stage.gpu.gl;this.vao=e.createVertexArray(),e.bindVertexArray(this.vao),e.bindBuffer(e.ARRAY_BUFFER,t.buffers[0]??null),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.buffers[1]??null),this.buffers=st.map((t,i)=>{let r=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,r),e.enableVertexAttribArray(i+1),e.vertexAttribPointer(i+1,4,e.FLOAT,!1,0,0),e.vertexAttribDivisor(i+1,1),r}),this.dirty=!0}drop(){let t=this.stage.gpu.gl;if(this.vao&&!this.stage.gpu.context.gone){t.deleteVertexArray(this.vao);for(let e of this.buffers)t.deleteBuffer(e)}this.vao=null}};var ut=["color","opacity","font","letterSpacing","wordSpacing","textTransform"];function dt(t,e){let i=e.length!==t.length*ut.length,r=0;for(let s of t)for(let t of ut)e[r]!==s[t]&&(e[r]=s[t],i=!0),r++;return i}var ct=t=>(t??"").replace(/--[\w-]+\s*:[^;]*;?/g,"").replace(/\s/g,""),ft=/opacity|transform|translate|rotate|scale|filter|clip|visibility/;function gt(t){if(typeof t.getAnimations!="function")return!1;for(let e of t.getAnimations({subtree:!0})){let i=e.effect;if(!i||i.target===t||i.pseudoElement||e.playState!=="running"||i.getTiming().iterations===1/0)continue;let{timeline:r}=e;if(r&&typeof DocumentTimeline<"u"&&!(r instanceof DocumentTimeline))continue;let s=e.transitionProperty;if(s?ft.test(s):i.getKeyframes().some(t=>Object.keys(t).some(t=>ft.test(t))))return!0}return!1}var pt=[1,0,0,1,0,0];function xt(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}var mt=(t,e,i)=>[t[0]*e+t[2]*i+t[4],t[1]*e+t[3]*i+t[5]];function yt(t,e,i){let r=t[0]*t[3]-t[2]*t[1];return Math.abs(r)<1e-6?null:[(t[3]*e-t[2]*i)/r,(t[0]*i-t[1]*e)/r]}function bt(t,e,i){if(!t||t==="none")return null;let[r="0",s="0",n]=t.split(" ");if(n&&parseFloat(n))return!1;let a=(t,e)=>t.endsWith("%")?parseFloat(t)/100*e:parseFloat(t)||0;return[1,0,0,1,a(r,e),a(s,i)]}function wt(t){return t.endsWith("rad")?Math.PI:t.endsWith("turn")?.5:180}function vt(t){if(!t||t==="none")return null;if(t.trim().includes(" "))return!1;let e=parseFloat(t)*Math.PI/wt(t);return[Math.cos(e),Math.sin(e),-Math.sin(e),Math.cos(e),0,0]}function Tt(t){if(!t||t==="none")return null;let[e=NaN,i=e,r]=t.split(" ").map(parseFloat);return r!==void 0&&r!==1?!1:[e,0,0,i,0,0]}function Et(t){if(!t||t==="none")return null;let e=(t.slice(t.indexOf("(")).match(/-?[\d.]+(?:e-?\d+)?/g)??[]).map(Number);return t.startsWith("matrix3d")?e.length!==16||e[2]||e[3]||e[6]||e[7]||e[8]||e[9]||e[11]||e[14]||e[10]!==1||e[15]!==1?!1:[n(e,0),n(e,1),n(e,4),n(e,5),n(e,12),n(e,13)]:e.length===6?e:pt}function kt(t,e,i){let r=[bt(t.translate,e,i),vt(t.rotate),Tt(t.scale),Et(t.transform)];if(r.includes(!1))return!1;let s=pt;for(let t of r)t&&(s=xt(s,t));if(s.every((t,e)=>Math.abs(t-n(pt,e))<1e-6))return null;let[a=0,l=0]=t.transformOrigin.split(" ").map(parseFloat);return xt([1,0,0,1,a,l],xt(s,[1,0,0,1,-a,-l]))}function St(t,e,i,r){let s=t??pt,{w:n,h:a}=r,l=1/0,h=1/0,o=[[0,0],[n,0],[0,a],[n,a]];for(let[t,i]of o){let[r,n]=mt(e,t,i),a=s[0]*r+s[2]*n,o=s[1]*r+s[3]*n;a<l&&(l=a),o<h&&(h=o)}let u=yt(s,i.x-s[4]-l,i.y-s[5]-h);if(!u)return null;let[d,c]=u;return{matrix:xt(s,xt([1,0,0,1,d,c],xt(e,[1,0,0,1,-d,-c]))),x:d,y:c}}function Mt(t,e){let i=yt(e,t.x+t.w/2-e[4],t.y+t.h/2-e[5]);if(!i)return null;let r=Math.abs(e[0]),s=Math.abs(e[2]),n=Math.abs(e[1]),a=Math.abs(e[3]),l=r*a-s*n,h,o;return Math.abs(l)>.3*(r*a+s*n)?(h=(t.w*a-s*t.h)/l,o=(r*t.h-n*t.w)/l):(h=t.w/Math.hypot(e[0],e[1]),o=t.h/Math.hypot(e[2],e[3])),{x:i[0]-h/2,y:i[1]-o/2,w:h,h:o}}function Rt(t,e,i){return t.position==="absolute"&&e<=1&&i<=1&&t.overflow!=="visible"}var At=class{constructor(t,e,i,r){this.el=t;this.De=e;this.surface=i;this.say=r;this.known=new Map}of(t){let e=this.known.get(t);if(e)return e;let i=t===this.el||!t.parentElement?null:this.of(t.parentElement);return e=i?this.read(t,i):this.root(t),this.known.set(t,e),e}root(t){return{style:t===this.el?this.De:getComputedStyle(t),lang:this.el.closest("[lang]")?.lang??"",hidden:!1,matrix:null,rest:null,line:null,alpha:1,faded:null}}read(t,e){let i=getComputedStyle(t),r=t.offsetWidth||0,s=t.offsetHeight||0,n=e.matrix,a=e.rest,l=i.display==="inline"?null:kt(i,r,s);if(l===!1)this.say("text3d",[],t);else if(l&&!a){let i=this.surface.ia(t.getBoundingClientRect(),()=>r,s),h=St(e.matrix,l,i,{w:r,h:s});h&&(n=h.matrix,Math.abs(n[0]*n[3]-n[1]*n[2])<1e-6&&(a={x:h.x,y:h.y,height:s,advance:0}))}let h=parseFloat(i.opacity);return{style:i,lang:t.getAttribute("lang")??e.lang,hidden:e.hidden||Rt(i,r,s),matrix:n,rest:a,line:t.hasAttribute("data-line")?t:e.line,alpha:e.alpha*(h>=0?h:1),faded:h<1?t:e.faded}}};var Ct=new Map;function Ft(t){let e=Ct.get(t);if(e!==void 0)return e;let i=null;if(typeof Intl<"u"&&"Segmenter"in Intl)try{i=new Intl.Segmenter(t||void 0,{granularity:"word"})}catch{i=new Intl.Segmenter(void 0,{granularity:"word"})}return Ct.set(t,i),i}function Ut(t,e="",i=Ft(e)){let r=new Uint8Array(t.length+1),s=!0;if(!i){for(let e=0;e<t.length;e++){let i=/\s/.test(t.charAt(e));!i&&s&&(r[e]=1),s=i}return r}let n=!1;for(let{segment:e,index:a,isWordLike:l}of i.segment(t)){if(!e.trim()){s=!0,n=!1;continue}(s||l&&n)&&(r[a]=1),s=!1,n=!!l}return r}function _t(t){let e=t.length,i=t[e-1];if(e<2||!i)return{rect:t[0],hyphen:void 0};let r=e-1;for(;r>0;){let e=t[r-1];if(!e||!(Math.abs(e.top-i.top)<i.height/2))break;r--}let s=r<e-1?t[r+1]:void 0;return{rect:t[r],hyphen:s&&s.width>0?s:void 0}}var Lt=typeof Intl<"u"&&"Segmenter"in Intl?new Intl.Segmenter(void 0,{granularity:"grapheme"}):null;function*Pt(t){if(Lt){yield*Lt.segment(t);return}let e=0;for(let i of t)yield{segment:i,index:e},e+=i.length}function Bt(t,e){try{return t.toLocaleUpperCase(e||void 0)}catch{return t.toUpperCase()}}function Dt(t,e){try{return t.toLocaleLowerCase(e||void 0)}catch{return t.toLowerCase()}}function It(t,e,i,r=""){return e==="uppercase"||e==="capitalize"&&i?Bt(t,r):e==="lowercase"?Dt(t,r):t}function zt(t,e,i,r){return("letterSpacing"in i||!r)&&!/none|no-/.test(t.fontVariantLigatures)&&!/["'](liga|clig|calt)["']\s+(0|off)/.test(t.fontFeatureSettings)&&!t.textAlign.startsWith("justify")&&!e.includes("\xad")}function Wt(t,e,i){return!i||!t.isSpace?t.painted:e?"":" "}function $t(t,e){let i=[];t.forEach((t,e)=>t.isSpace||i.push(e));let[r]=i,s=i.at(-1);if(r===void 0||s===void 0)return null;let a=e(r,s+1),l=a[0];if(a.length===1&&l)return[[r,s+1,l]];let h=[];for(let t=0;t<i.length;){let r=n(i,t),s=_t(e(r,r+1)).rect;if(!s||s.width<=0)return null;let a=t,l=i.length-1;for(;a<l;){let t=a+l+1>>1,r=n(i,t),h=_t(e(r,r+1)).rect;h&&Math.abs(h.top-s.top)<s.height/2?a=t:l=t-1}let o=n(i,a)+1,u=e(r,o),d=u[0];if(u.length!==1||!d)return null;h.push([r,o,d]),t=a+1}return h}var Nt=/[\u0600-\u08FF\u0900-\u0DFF\u0E00-\u0FFF\u1000-\u109F\u1780-\u17FF\uFB50-\uFDFF\uFE70-\uFEFF]/,Vt=t=>!!t&&!/^(inline|contents)/.test(t);function jt(t){if(Nt.test(t.textContent))return"a script that needs letter shaping";let e=[t,...Array.from(t.querySelectorAll("*"))],i=t.matches('[data-umber-status="ready"],[data-umber-status="loading"][data-umber-play],[data-umber-morphing]');for(let r of e){let e=getComputedStyle(r),s=Ht(e,i)||Gt(e)||Xt(e)||qt(r,t,e);if(s)return s}return""}function Ht(t,e){if(parseFloat(t.webkitTextStrokeWidth||"0")>0)return"-webkit-text-stroke";if(!e&&t.textShadow&&t.textShadow!=="none")return"text-shadow";let i=t.getPropertyValue("-webkit-text-fill-color");return!e&&i&&i!==t.color&&!/^currentcolor$/i.test(i)?"a -webkit-text-fill-color other than its color":/discretionary|historical/.test(t.fontVariantLigatures)?"discretionary or historical ligatures":t.backgroundClip==="text"||t.getPropertyValue("-webkit-background-clip")==="text"?"background-clip: text":Zt(t.fontFeatureSettings)?"font-feature-settings":t.fontVariationSettings&&t.fontVariationSettings!=="normal"?"font-variation-settings":t.textDecorationLine&&t.textDecorationLine!=="none"?"text-decoration (underline / line-through)":""}function Gt(t){return t.writingMode&&t.writingMode!=="horizontal-tb"?"vertical writing-mode":t.textOverflow==="ellipsis"?"text-overflow: ellipsis":t.webkitLineClamp&&t.webkitLineClamp!=="none"?"line-clamp":""}function Xt(t){if(t.fontSizeAdjust&&t.fontSizeAdjust!=="none")return"font-size-adjust";if(t.textTransform.includes("full-"))return`text-transform: ${t.textTransform}`;for(let e of[t.fontVariantNumeric,t.fontVariantAlternates,t.fontVariantEastAsian,t.fontVariantPosition])if(e&&e!=="normal")return"font-variant";return t.fontVariantCaps&&!/^(normal|small-caps)$/.test(t.fontVariantCaps)&&!(typeof CanvasRenderingContext2D<"u"&&"fontVariantCaps"in CanvasRenderingContext2D.prototype)?"font-variant-caps":Jt(t.getPropertyValue("font-stretch"))===void 0?"a font-stretch between the keyword widths":""}function qt(t,e,i){for(let e of["::before","::after"]){let i=getComputedStyle(t,e).content;if(i&&!/^(none|normal|"\s*")$/.test(i))return`${e} content`}if(i.display.includes("list-item")&&i.listStyleType!=="none")return"a list marker";if(t!==e&&!Vt(i.display))return"";for(let e of["::first-letter","::first-line"])if(Kt(getComputedStyle(t,e),i))return`a styled ${e}`;return""}var Ot=["fontSize","fontFamily","fontWeight","fontStyle","color","letterSpacing","textTransform","fontVariantCaps"],Kt=(t,e)=>Ot.some(i=>t[i]&&t[i]!==e[i]),Yt=new Set(["kern","liga","clig","calt","rlig"]);function Zt(t){if(!t||t==="normal")return!1;let e=t.match(/["'][\w ]{4}["']/g)??[];return!e.length||e.some(t=>!Yt.has(t.slice(1,5)))}var Qt={"50%":"ultra-condensed","62.5%":"extra-condensed","75%":"condensed","87.5%":"semi-condensed","100%":"",normal:"","112.5%":"semi-expanded","125%":"expanded","150%":"extra-expanded","200%":"ultra-expanded"};function Jt(t=""){if(!t)return"";let e=Qt[t];return e!==void 0?e:Object.values(Qt).includes(t)?t:void 0}var te=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,ee=/[\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}\p{sc=Hangul}]/u,ie=/[\p{L}\p{N}]/u;function re(t,e,i){let r=!1;for(let s=t;s&&s!==e;s=s.parentNode){let t=s.previousSibling;if(t){(t.nodeName==="BR"||t.nodeType===1&&Vt(getComputedStyle(t).display))&&(r=!0);break}s.parentElement&&i(s.parentElement)&&(r=!0)}return r}function se(t,e,i=e.fontSize){let r=e.fontVariantCaps==="small-caps"?"small-caps ":"",s=Jt(e.getPropertyValue("font-stretch"))??"";t.font=`${e.fontStyle} ${r}${e.fontWeight} ${s} ${i} ${e.fontFamily}`,"fontVariantCaps"in t&&(t.fontVariantCaps=e.fontVariantCaps||"normal"),"fontKerning"in t&&(t.fontKerning=e.fontKerning||"auto")}function ne(t,e){let i=t.fontFeatureSettings,r=t=>new RegExp(`["']${t}["']\\s*(0|off)`).test(i),s=!/none|no-common-ligatures/.test(t.fontVariantLigatures)&&!r("liga")&&!parseFloat(t.letterSpacing);return(r("rlig")&&e()?0:1)|(s?2:0)}function ae(t,e,i){let r=document.createRange();r.selectNodeContents(e);let s=0;for(let t of r.getClientRects())s+=t.width;return Math.abs(s-t.measureText(i).width)>.5}function le(t,e,i){se(t,e);let r=e.direction==="rtl";t.direction=r?"rtl":"ltr",t.fillStyle=e.color;let s=e=>{let r=t.measureText("Hg"),s=i/e;return[(r.fontBoundingBoxAscent??e*.8)*s,(r.fontBoundingBoxDescent??e*.2)*s]},[n,a]=s(i),l;return{rtl:r,ascent:n,descent:a,fine(){return l||(se(t,e,`${i*16}px`),l=s(i*16),se(t,e)),l},letter:parseFloat(e.letterSpacing)||0,word:parseFloat(e.wordSpacing)||0}}function he(t,e,i){let r=[t.ascent,t.descent],s=t=>Math.abs(i-t[0]-t[1]);if(s(r)>1/64){let e=t.fine();s(e)<=1/8&&s(e)<s(r)&&(r=e)}return e+(i-r[0]-r[1])/2+r[0]}function oe(t){let e=t,i=(t.hyphenateCharacter||"").replace(/^auto$|["']/g,"")||"-",r=(t.hyphens||(e.webkitHyphens??""))==="auto";return{hyphen:i,hyphenates:r}}var ue=new WeakSet,de=[],ce=!1,fe=class{constructor(t,e,i,r){this.ancestry=t;this.starts=e;this.na=i;this.fontSize=r;this.boxes=[];this.hidden=[];this.drew=!1;this.over=!1;this.down=!1;this.units=0;this.lg=!0;this.qg=!0;this.lines=new Map;this.range=document.createRange();this.el=t.el,this.surface=t.surface,this.Cb=[t.el]}space(){this.lg=!0,this.qg=!0}Wh(t,e,i){let r=t.parentElement;if(!r)return;let s=this.ancestry.of(r),{style:n}=s,a=n.textTransform;if(a==="capitalize"&&re(t,this.el,t=>Vt(this.ancestry.of(t).style.display))&&(this.qg=!0),this.unseen(r,s))return;r!==this.el&&n.display!=="inline"&&this.units++,this.Fj(r,s);let{ctx:l}=this.surface;l.globalAlpha=s.alpha;let h=le(l,n,this.fontSize);this.surface.joins=ne(n,()=>ae(l,t,i));let o={node:t,at:e,info:s,font:h,...oe(n),line:s.line?this.ac(s.line):void 0,glyphs:this.bb(i,a,s.lang)},{matrix:u}=s,d=!this.surface.layout.turned&&!s.rest&&(!u||!u[1]&&!u[2])&&!o.hyphenates&&zt(n,i,l,h.letter||h.word)?$t(o.glyphs,(t,e)=>this.read(o,t,e)):null,c=0;for(let[t,e,i]of d??[])this.letters(o,c,t),this.run(o,t,e,i)||this.letters(o,t,e),c=e;this.letters(o,c,o.glyphs.length)}unseen(t,e){let{visibility:i,display:r}=e.style;return i==="hidden"&&!this.hidden.includes(t)&&this.hidden.push(t),i==="hidden"&&!ce||r==="none"||e.hidden}Fj(t,e){(t===this.el||!!t.closest("a, button")||e.style.color!==this.ancestry.of(t.parentElement??this.el).style.color)&&!this.Cb.includes(t)&&this.Cb.push(t),e.faded&&!this.Cb.includes(e.faded)&&this.Cb.push(e.faded)}ac(t){let e=this.lines.get(t);return e!==void 0?e:(this.lines.set(t,this.lines.size),this.lines.size-1)}bb(t,e,i){let r=[];for(let{segment:s,index:n}of Pt(t)){let t=!s.trim(),a=ie.test(s),l=t?s:It(s,e,this.qg&&a,i);r.push({index:n,text:s,painted:l,isSpace:t}),(t||a)&&(this.qg=t)}return r}read(t,e,i){let r=t.glyphs[e],s=t.glyphs[i-1];return!r||!s?de:(this.range.setStart(t.node,r.index),this.range.setEnd(t.node,s.index+s.text.length),this.range.getClientRects())}spacing(t,e){let{ctx:i}=this.surface;"letterSpacing"in i&&(i.letterSpacing=`${t}px`,i.wordSpacing=`${e}px`)}advance(t,e){return this.surface.ctx.measureText(e).width+t.font.letter}Wa(t,e,i){let{rest:r,matrix:s}=t.info,{ascent:n,descent:a}=t.font,l;if(r)l={x:r.x+r.advance,y:r.y,w:this.advance(t,e),h:r.height},r.advance+=l.w;else{if(!i)return null;l=this.surface.ia(i,()=>this.advance(t,e),n+a),s&&(l=Mt(l,s)??l)}let{pad:h}=this.surface.layout,o={x:l.x+h,y:l.y+h,w:l.w,h:l.h},u=this.surface.snap(he(t.font,o.y,l.h));return this.surface.fill(e,o.x,u),this.drew=!0,this.Wb(t,o.x,l.w,u),{box:o,baseline:u}}Wb(t,e,i,r){if(this.over)return;let{width:s,height:n}=this.surface.layout;this.down||=r-t.font.ascent<-.5||r+t.font.descent>n+.5,this.over=this.down||e<-.5||e+i>s+.5}push(t,e,i,r){let s=this.na?this.surface.ctx.measureText(e.painted):null,n=s&&typeof s.actualBoundingBoxAscent=="number"?{l:i.x-s.actualBoundingBoxLeft,t:r-s.actualBoundingBoxAscent,r:i.x+s.actualBoundingBoxRight,b:r+s.actualBoundingBoxDescent}:void 0;this.boxes.push({x:i.x,y:i.y,w:i.w,h:i.h,lg:this.lg,ink:n,rtl:t.font.rtl,at:t.at+e.index,len:e.text.length,unit:t.line}),this.lg=!1}letters(t,e,i){this.spacing(0,0);let r;for(let s=e;s<i;s++)r=this.letter(t,s,r)}letter(t,e,i){let r=t.glyphs[e];if(!r)return;let{rest:s}=t.info;if(this.starts[t.at+r.index]&&(this.lg=!0),r.isSpace){s&&(s.advance+=this.advance(t,r.text)+t.font.word),this.lg=!0;return}let{rect:n,hyphen:a}=_t(this.read(t,e,e+1)),l=!a&&i&&n?this.R(t,e,i,n):null;a?this.Wa(t,t.hyphen,a):l&&i&&this.Bg(t,l,i);let h=a||t.font.rtl?void 0:n;if(!s&&(!n||n.width<=0))return h;this.surface.start=this.lg;let o=this.Wa(t,r.painted,n);return o&&this.push(t,r,o.box,o.baseline),h}R(t,e,i,r){let s=t.glyphs[e],n=t.glyphs[e-1];return!s||!n?null:t.hyphenates&&r.top>i.top+i.height/2&&!this.starts[t.at+s.index]&&ie.test(s.text)&&ie.test(n.text)&&!ee.test(n.text+s.text)?n:null}Bg(t,e,i){let{scaleX:r}=this.surface.layout,s=this.advance(t,t.hyphen)*r,n=i.left+i.width-(i.width-this.advance(t,e.painted)*r>s/2?s:0);this.Wa(t,t.hyphen,{left:n,top:i.top,width:s,height:i.height})}run(t,e,i,r){let{ctx:s,layout:a}=this.surface,{glyphs:l,font:h,info:o}=t;this.spacing(h.letter,h.word);let u=/^(normal|nowrap|pre-line)$/.test(o.style.whiteSpace||"normal"),d=l.slice(e,i),c=d.map((t,e)=>Wt(t,u&&(d[e-1]?.isSpace??!1),u)),f=c.join(""),g=this.surface.ia(r,()=>0,0);if(o.matrix&&(g=Mt(g,o.matrix)??g),Math.abs(s.measureText(f).width-g.w)>.5)return!1;let p=this.backwards(t,e,i,f);if(p===null)return!1;let x=g.y+a.pad,m=this.surface.snap(he(h,x,g.h));this.surface.fill(f,g.x+a.pad,m),this.drew=!0,this.Wb(t,g.x+a.pad,g.w,m);let y=c.map(t=>t?s.measureText(t).width:0),b=g.w/(y.reduce((t,e)=>t+e,0)||1),w=g.x+a.pad+(p?g.w:0);for(let[e,i]of d.entries()){let r=n(y,e)*b;this.starts[t.at+i.index]&&(this.lg=!0),p&&(w-=r),i.isSpace?this.lg=!0:this.push(t,i,{x:w,y:x,w:r,h:g.h},m),p||(w+=r)}return!0}backwards(t,e,i,r){let{rtl:s}=t.font;if(i-e<=1||!(s||te.test(r)))return s;let n=_t(this.read(t,e,e+1)).rect,a=_t(this.read(t,i-1,i)).rect;return!n||!a?null:n.left>a.left}};function ge(t){let e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),i=[],r="";for(;e.nextNode();){let t=e.currentNode;i.push(t),r+=t.nodeValue??""}return{nodes:i,text:r}}function pe(t,e){let i=t.getBoundingClientRect();if(i.width<1||i.height<1)return{drawn:!1,canvas:null,hidden:[]};let s=getComputedStyle(t),n=parseFloat(s.fontSize)||16,a=h(t,i,n,e);if(!a)return{drawn:!1,canvas:null,hidden:[]};let l=new At(t,s,a,e.say),{nodes:o,text:u}=ge(t),d=Ut(u,l.of(t).lang),c=new fe(l,d,!!e.glyphs,n);ce=!!e.unhide;let f=0;for(let t of o){let e=t.nodeValue??"",i=f;f+=e.length,e.trim()?c.Wh(t,i,e):e&&c.space()}if(!c.drew)return{drawn:!1,canvas:null,hidden:c.hidden};c.units>=8&&!ue.has(t)&&(ue.add(t),r.debug&&e.tell?.("textSplit",[],r.info,t));let{canvas:g,fills:p}=a,{scale:x,pad:m,grid:y,layoutWidth:b,layoutHeight:w,pixelWidth:v,pixelHeight:T}=a.layout;return{drawn:!0,canvas:g,fills:p,pixelWidth:v,pixelHeight:T,scale:x,pad:m,grid:y,layoutWidth:b,layoutHeight:w,Cb:c.Cb,boxes:c.boxes,text:u,glyphs:e.glyphs?.(c.boxes,v/x,T/x),over:c.over,down:c.down,hidden:c.hidden}}var xe=2e3,me=class{constructor(){this.Ze=!0;this.waits=!1;this.empty=!1;this.hidden=!1;this.Ke=[];this.bg="";this.size="";this.Cb=[];this.colors=[];this.U=0;this.Bc="";this.lj=0;this.zd=null;this.Kd=!1;this.pending=!1;this.fresh=!1;this.nb=null;this.gd=!1;this.paintZoom=1;this.Ld=1;this.drawnSpot=0;this.mh=null;this.table=null;this.jd=null;this.Ck=null;this.free=()=>{this.Cc=this.fresh||this.pending?setTimeout(this.free,xe):void 0,this.fresh=!1,!this.Cc&&this.zd&&(this.zd.width=1)}}upload(t){this.pending=!1,this.fresh=!0,this.Cc??=setTimeout(this.free,xe);let e=this.mh;e&&(this.mh=null,this.jd??=new a(t,"uint"),this.Ck??=new a(t,"float"),this.jd.upload(e.width,e.height,e.index),this.Ck.upload(e.dataWidth,e.dataHeight,e.data))}lost(){this.jd=null,this.Ck=null,this.mh=null}dispose(t){clearTimeout(this.quiet),clearTimeout(this.Cc),t?._t&&(t._t=null,t.el.removeAttribute("data-umber-status")),this.zd?.remove(),this.nb?.disconnect(),this.nb=null,this.jd?.dispose(),this.Ck?.dispose(),this.lost()}};var ye=(t,e)=>{t.l=Math.min(t.l,e.x),t.t=Math.min(t.t,e.y),t.r=Math.max(t.r,e.x+e.w),t.b=Math.max(t.b,e.y+e.h)},be=t=>({l:t.x,t:t.y,r:t.x+t.w,b:t.y+t.h}),we=t=>t.x+t.w/2;function ve(t,e,i){if(t.unit!==void 0&&e?.unit!==void 0)return t.unit!==e.unit;let r=!!e&&(t.rtl?we(t)>e.x+e.w:we(t)<e.x);return t.y+t.h/2>i.b||r&&t.y>=(i.t+i.b)/2}function Te(t,e=t.length){let i=new Int32Array(e),r=new Int32Array(e),s=[],n=[],a=null,l,h;for(let o=0;o<e;o++){let e=t[o];if(!e)break;let u=!l||ve(e,a,l);u||!l?(l={...be(e),chars:[]},s.push(l)):ye(l,e),l.chars.push(o),u||e.lg||!h?(h=be(e),n.push(h)):ye(h,e),i[o]=s.length-1,r[o]=n.length-1,a=e}return{ac:i,wordOf:r,lines:s,words:n}}var Ee=["lines","words","chars"],ke=[0,1,2],Se=class{constructor(t,e,i){this.owner=t;this.level=e;this.index=i;this.text="";this.box={x:0,y:0,w:0,h:0};this.dead=!1}get slot(){return this.owner.base[this.level]+this.index}hd(t){return this.dead?0:n(this.owner.values,this.slot*4+t)||0}nk(t,e){this.dead||this.owner.write(this.slot*4+t,e)}tween(t,e){let i=()=>this[t],r=e=>{this[t]=e},s=this.bh??={},n=s[t]??={get value(){return i()},set value(t){r(t)}};return this.owner.stage.env.tweens.to(n,e)}};["t","x","y","z"].forEach((t,e)=>Object.defineProperty(Se.prototype,t,{get(){return this.hd(e)},set(t){this.nk(e,t)}}));var Me=(t,e)=>Math.abs(t-e)<.01,Re=t=>t.replace(/\s+/g," ").trim(),Ae={top:0,center:.5,middle:.5,bottom:1};function Ce(t,e){return t.trim().replace(/^(top|center|middle|bottom|-?[\d.]+%|-?[\d.]+(?:px)?)(?=[\s+-]|$)/i,t=>{let i=Fe(t.toLowerCase(),e.h);return`${Math.round((e.y+i)*100)/100}px`})}function Fe(t,e){let i=Ae[t];return i!==void 0?i*e:t.endsWith("%")?parseFloat(t)/100*e:parseFloat(t)}var Ue=t=>({x:t.l,y:t.t,w:t.r-t.l,h:t.b-t.t});function _e(t,e,i,r){let{box:s}=t,n=i.x-r,a=i.y-r,l=t.text!==e||!Me(s.x,n)||!Me(s.y,a)||!Me(s.w,i.w)||!Me(s.h,i.h);return t.text=e,s.x=n,s.y=a,s.w=i.w,s.h=i.h,l}function Le(t,e){let i=new Int32Array(e).fill(-1),r=new Int32Array(e);return t.forEach((t,e)=>{n(i,t)<0&&(i[t]=e),r[t]=e}),{first:i,last:r}}var Pe=0,Be=class{constructor(t,e){this.plane=t;this.stage=e;this.lines=[];this.words=[];this.chars=[];this.version=0;this.values=new Float32Array(0);this.base=[0,0,0];this.dirty=!1;this.changed=!1;this.rule=null}write(t,e){this.values[t]===e||t>=this.values.length||(this.values[t]=e,(this.plane._z||this.plane.instancing)&&(this.dirty=!0,this.stage.scheduler.markDirty()))}update(t,e,i){let{ac:r,wordOf:s,lines:a,words:l}=Te(t),h=[this.lines,this.words,this.chars],o=[a.length,l.length,t.length],u=ke.some(t=>h[t].length!==o[t]);this.ud(h,o);let{first:d,last:c}=Le(s,l.length),f=(i,r)=>e.slice(t[i]?.at??0,(t[r]?.at??0)+(t[r]?.len??0)),g=(t,e)=>{let i=h[t],r=i[e]??new Se(this,t,e);return i[e]=r,r};a.forEach((t,e)=>{let[r=0]=t.chars,a=t.chars.at(-1)??r,l=g(0,e);u=_e(l,Re(f(r,a)),Ue(t),i)||u,l.chars=[r,a],l.words=[n(s,r),n(s,a)]}),l.forEach((t,e)=>{let s=g(1,e),a=n(d,e),l=n(c,e);u=_e(s,Re(f(a,l)),Ue(t),i)||u,s.chars=[a,l],s.line=n(r,a)}),t.forEach((t,e)=>{let a=g(2,e);u=_e(a,f(e,e),t,i)||u,a.line=n(r,e),a.word=n(s,e)});for(let t of ke)for(let e of h[t].splice(o[t]))e.dead=!0;return u&&(this.version++,this.changed=!0),u}ud(t,e){let i=[0,e[0],e[0]+e[1]],r=new Float32Array(4*(i[2]+e[2]));for(let s of ke){let n=Math.min(t[s].length,e[s]);r.set(this.values.subarray(this.base[s]*4,(this.base[s]+n)*4),i[s]*4)}this.values=r,this.base=i}progress(t,e={}){if(t!=="lines"&&t!=="words")return this.stage.env.lib.say("unitProgress",[t],this.plane.el),[];let i=this.stage.env.host.engine;return this[t].map(t=>i.progress(this.plane.el,{...e,start:Ce((e.start??"")||"top bottom",t.box),end:Ce((e.end??"")||"bottom top",t.box)}))}fi(){if(!this.rule){let t=this.plane.el,e=t.getAttribute("data-umber-css");e||t.setAttribute("data-umber-css",e=`t${++Pe}`),this.rule=this.stage.env.lib.elementRule(e)}for(let t of Ee)this.rule.style.setProperty(`--umber-${t}`,`${this[t].length}`)}dispose(){this.plane.el.isConnected||this.stage.env.lib.dropRule(this.rule),this.rule=null}};function De(t){let e=!1,i=()=>{if(e=!1,t.env.destroyed||t.gpu.context.gone||t.env.stats.textureMB*2**21>t.gpu.tier.textureBudget)return;let i=t.env.frame.pageY+t.env.frame.screen.height/2,s=null,n=1/0;for(let e of t.planes.all){if(e.kind!=="text"||e.textureState!=="none"||e.status==="error"||e.raster?.empty||e._t)continue;let t=e.measured?Math.abs(e.doc.y+e.doc.h/2-i):1e9;t<n&&(n=t,s=e)}s&&(t.factory.load(s),r())},r=()=>{e||(e=!0,t.gpu.media.idle(i))};return r}var Ie={textUnsupported:t=>`data-umber="text" stays normal DOM text: it uses ${t}, which GL text cannot paint. Remove data-umber="text" or that style.`,textOverflow:t=>`data-umber="text" stays normal DOM text: its text runs past its box${t?", down":""}, and GL paints only the box. Let ${t?"its height follow its lines (no fixed height)":"it wrap (overflow-wrap: anywhere)"}, or put data-umber="text" on an element as ${t?"tall":"wide"} as its text.`};var ze={load:()=>import(new URL("./glyphs.js",import.meta.url).href),pending:null,get(){return this.pending??=this.load().catch(t=>{throw this.pending=null,t})}},We=class{constructor(t){this.stage=t;this.chunk=null;this.asked=!1}builder(t){return t._z?this.chunk?.buildGlyphs:void 0}ready(){if(this.chunk)return!0;if(!this.asked){this.asked=!0;let t=this.stage.chunks;t.load({load:()=>ze.get(),file:"glyphs",made:e=>{this.chunk=e,t.jb(e.GLYPH_HELPER,e.withoutUnreadInk)},failed:()=>{t.Jl(t.ae,{failed:!0})}})}return!1}};var $e="its words or letters are animating: its DOM shows until they hold still (GL animates them with glyph())",Ne=150,Ve=4,je=4e6,He=1e6,Ge="|curves",Xe=t=>t.programKey.endsWith(Ge),qe=(t,e)=>e.visibility==="hidden"&&t.zone.near,Oe=new WeakSet,Ke=class{constructor(t){this.stage=t;this.changed=new WeakMap;this.wf=-1;this.shared=null;this.oe=null;this.bound={layout:{texture:null},color:{texture:null}};this.yk=new We(t),this.ahead=De(t);for(let e of t.planes.all)e.kind==="text"&&this.units(e);let e=()=>{if(t.env.frame.scrolled)return;let e=performance.now()+500,i=!1;for(let r of t.planes.all)r.kind==="text"&&r.zone.soon&&r.raster&&(r.raster.U=e,i=!0);i&&t.scheduler.request()};for(let i of["pointerover","pointerout"])t.env.listen(document,i,e)}get curves(){return this.oe??=new H(this.stage.gpu.gl,t=>{this.qh(t)},(t,e)=>{this.stage.env.lib.say("fontNotPrepared",[t,e])},this.stage.gpu.media.manifests)}get curveTables(){return this.oe?.tables??null}qh(t){let e=this.stage,i=this.curveTables,r=this.oe?.chunk?.CURVE_GLSL;if(t&&i&&r){e.gpu.subsystems.push({restored:()=>{i.restore()}}),et(r),e.gpu.programs.textKey=Ge;return}for(let t of e.planes.all){let e=t.raster;!e||!Xe(t)||(e.Ze=!0,e.waits&&(e.waits=!1,this.rg(t)||(t.textureState="none")))}e.factory.invalidate()}Qj(t,e){if(!Xe(t))return!1;for(let t of e)!t.rtl&&t.caps==="normal"&&this.curves.find(t.font);return this.curves.waiting}glyphs(t){let e=t.texture;if(!(e instanceof J)||!e.ready)return null;let i=e.placed;return i.length?i.some(t=>t.entry.paint.rtl)?(this.stage.env.lib.say("lettersWhole",[],t.el),null):i:null}get glsl(){return tt.code}get atlas(){if(this.shared)return this.shared;let{gpu:t,canvasHost:e}=this.stage,i=new z(t.gl,e.el,t.tier.maxTexture);return t.subsystems.push({lost:()=>{i.lost()}}),this.shared=i,i}blank(t){return{index:new a(t,"uint"),data:new a(t,"float")}}samplers(t){let e=t.texture;return e instanceof J?(this.bound.layout.texture=e.layout.texture,this.bound.color.texture=e.Rc,this.bound):null}units(t){if(t.text)return;let e=this.quads(t),i=new Be(t,this.stage);Object.defineProperty(t,"text",{value:i,configurable:!0,enumerable:!0}),t.modules.list.push({name:"text",binding:{update:()=>this.frame(t,i),destroy:()=>{i.dispose(),e?.drop()}}})}quads(t){if(t.instancing||t.effects.length||t.shader||t.el.hasAttribute("data-umber-instances"))return null;let e=new ot(this.stage,t);return t.instancing=e,t.program&&!t.texture?.ready&&this.stage.gpu.programs.prepare(t),e}load(t){let e=this.stage;this.watch(t),this.units(t),t.textureState="loading";let i=()=>{t._t&&(t.textureState="none"),!(!e.planes.all.includes(t)||e.gpu.context.gone||t.status==="error")&&(this.rg(t)||(t.textureState="none"))},r="fonts"in document?document.fonts:null;r?.status==="loading"?Promise.race([r.ready,new Promise(t=>setTimeout(t,1500))]).then(i):i(),this.ahead()}rg(t){let e=this.stage,i=t.raster??=new me;if(t.status==="error")return!1;if(i.waits)return!0;let r=jt(t.el);if(r)return this.refuse(t,i,"textUnsupported",[r]);if(gt(t.el))return this.hold(t),!1;let s=getComputedStyle(t.el),n=qe(t,s),a=!i.Kd&&t.instancing?.spec.mode!=="ink",l=pe(t.el,{scale:e.canvasHost.dpr*i.paintZoom,maxSize:e.gpu.tier.maxTexture,canvas:a?void 0:this.ce(i,s),record:a,glyphs:this.yk.builder(t),turned:e.chunks.shapes?.yc(t)??null,say:e.env.lib.say,tell:e.env.lib.tell,unhide:n});return i.zd?.remove(),l.drawn?l.over?this.refuse(t,i,"textOverflow",[l.down]):l.fills&&this.Qj(t,l.fills)?(i.waits=!0,!0):l.fills&&!this.placed(t,l,s)?(i.Kd=!0,t.texture instanceof J&&this.stage.gpu.media.release(t),this.rg(t)):(this.painted(t,i,l,n),!0):(this.Xh(t,i,l.hidden,s),!1)}placed(t,e,i){let r=this.stage;if(!e.fills)return!1;let s=["-webkit-font-smoothing","-moz-osx-font-smoothing"].map(t=>i.getPropertyValue(t)),n={fonts:this.curves,draw:Xe(t),letters:t.instancing?.spec.mode==="chars"},a=this.atlas.place(e.fills,e.scale,s,n);if(r.gpu.renderer.reset(),!a)return!1;let l=(t.texture instanceof J?t.texture:this.bi(t)).show(a,e.pixelWidth,e.pixelHeight);return r.gpu.renderer.reset(),t.raster&&l&&(t.raster.gd=a.some(t=>!t.entry.curve)),l}refuse(t,e,i,r){this.stage.env.lib.say(i,r,t.el),e.Ze=!1,e.gd=!1,t.textureState="error";let s=Ie[i];return t.setStatus("error",s(...r)),!1}ce(t,e){let i=t.zd??=document.createElement("canvas");i.isConnected||(i.setAttribute("data-umber-canvas","text"),i.style.display="none",this.stage.canvasHost.el.appendChild(i));for(let t of["-webkit-font-smoothing","-moz-osx-font-smoothing"])i.style.setProperty(t,e.getPropertyValue(t));return i}Xh(t,e,i,r){let s=e.zd,n=!e.empty&&(t.textureState==="ready"||t.textureState==="queued");n&&t.texture instanceof J?(t.texture.show([],1,1),this.stage.gpu.renderer.reset(),t.text?.update([],"",0)):s&&n&&(s.width=1,this.stage.gpu.media.Yh(t,s),t.text?.update([],"",0)),e.Cb=[],e.colors=[],e.empty=!0,e.gd=!1,e.hidden=r.visibility==="hidden",e.hidden&&(t.opacity=0),e.Ke=e.hidden?[]:i,e.Ze=!1,e.Bc="",e.bg=this.key(t)}painted(t,e,i,r){e.empty=!1,e.hidden=!1,r?(Oe.add(e),t.opacity=0):Oe.delete(e),e.Ke=i.hidden,i.canvas&&(e.zd=i.canvas),e.pending=!!i.canvas,t.pad=i.pad,t.pixelGrid=i.grid,t.rounding=[i.pixelWidth/i.scale-i.layoutWidth-2*i.pad,i.pixelHeight/i.scale-i.layoutHeight-2*i.pad],t.layoutW=i.layoutWidth,t.layoutH=i.layoutHeight,e.Cb=i.Cb.map(t=>getComputedStyle(t)),dt(e.Cb,e.colors=[]),e.bg=this.key(t),e.Ld=e.paintZoom,e.Bc="",e.Ze=!1,t.textureState=t.texture?.ready?"ready":"queued",t._z&&(e.table=i.glyphs??null,e.mh=e.table);let s=t.text;s&&(s.update(i.boxes,i.text,i.pad),s.dirty||=!!e.table),i.canvas?this.stage.gpu.media.Yh(t,i.canvas):this.landed(t,e),this.stage.scheduler.markDirty()}bi(t){t.texture&&this.stage.gpu.media.release(t);let e=new J(this.stage.gpu.gl,this.atlas);return t.texture=e,e}landed(t,e){e.upload(this.stage.gpu.gl),this.stage.gpu.renderer.reset(),t.textureState!=="error"&&(t.textureState="ready",t._o())}frame(t,e){e.changed&&(e.changed=!1,e.fi(),t.emit("text"));let i=t.raster,r=i?.table;return!e.dirty||!r?!1:(e.dirty=!1,r.data.set(e.values.subarray(0,(r.lines+r.words+r.chars)*4),r.values*4),i.mh!==r&&i.Ck?.ready&&i.Ck.upload(r.dataWidth,r.dataHeight,r.data),!0)}key(t){let e=t.el,i=t.raster??=new me;return(t.stale||i.Bc||!i.size)&&(i.size=`${e.offsetWidth||Math.round(t.doc.w)}x${e.offsetHeight||Math.round(t.doc.h)}`),`${i.size}@${this.stage.canvasHost.dpr*i.paintZoom}`}sj(t,e,i){if(!e.gd)return;let r=t.size[0],s=r/t.layoutW,n=this.stage.canvasHost.dpr,a=t.layoutW*t.layoutH*n*n,l=Math.max(1,Math.min(Ve,Math.sqrt(je/a),Math.ceil(s*2-.5)/2));l>1&&e.paintZoom===1&&this.stage.env.lib.say("textSoft",[s],t.el);let h=e.Ld;e.paintZoom=l<h&&a*h*h<He?h:l;let o=t.doc.x+t.doc.y+r,u=Math.abs(o-e.drawnSpot)>1;u&&(e.drawnSpot=o);let d=i-e.lj>=150&&e.paintZoom!==h;u||d&&this.wf===i?e.lj=i-(u?0:140):d&&(this.wf=i)}check(t,e,i){let r=t.raster??=new me;this.sj(t,r,e);let s=this.key(t);if(this.Vg(t,r,e,i)){this.rg(t);return}if(r.Ze&&!r.bg){this.rg(t);return}if(!r.Ze&&s===r.bg)r.Bc="";else{s!==r.Bc&&(r.Bc=s,r.lj=e),t.zone.soon&&(s===r.bg||e-r.lj>=150)&&e-(this.changed.get(t)??0)>=100&&this.rg(t);return}let n=i||t.stale||e<r.U;e<r.U&&this.stage.scheduler.request(),t.zone.soon&&n&&r.Cb.length&&dt(r.Cb,r.colors)&&(r.U=e+400,this.rg(t))}Vg(t,e,i,r){return e.hidden&&t.opacity>0?!0:Oe.has(e)?t.opacity>0?(Oe.delete(e),e.Ke.some(t=>getComputedStyle(t).visibility==="hidden")?!0:(e.Ke=[],!1)):!1:!e.Ke.length||!(t.stale||r||i<e.U)?!1:e.Ke.some(t=>getComputedStyle(t).visibility!=="hidden")}watch(t){let e=t.raster??=new me;e.nb||(e.nb=new MutationObserver(i=>{let r=!1,s=!1,n=!1;for(let e of i){let i=e.attributeName??"",a=e.target;if(e.type!=="attributes")r=!0;else{if(a===t.el)continue;i==="class"?n=!0:i==="style"?s||=ct(e.oldValue)!==ct(a.getAttribute("style")):!i.startsWith("data-umber")&&e.oldValue!==a.getAttribute(i)&&(r=!0)}}r&&(e.Ze=!0,e.empty=!1,this.changed.set(t,performance.now()),t.stale=!0,this.stage.scheduler.markDirty()),s||n&>(t.el)?this.hold(t):n&&(e.U=performance.now()+400,this.stage.scheduler.markDirty())}),e.nb.observe(t.el,{characterData:!0,childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0}))}hold(t){let e=t.raster;e&&(clearTimeout(e.quiet),e.quiet=setTimeout(()=>{this.settle(t)},Ne),!t._t&&(t.warned.add($e),t._t=$e,this.stage.fallbacks.decide(t)))}settle(t){let e=t.raster;if(!(!e||!this.stage.planes.all.includes(t))){if(e.quiet=void 0,gt(t.el)){this.hold(t);return}t.texture&&(t.texture.ready=!1),e.Ze=!0,this.changed.set(t,0),t.stale=!0,!t.program&&!this.stage.gpu.context.gone&&this.stage.gpu.programs.prepare(t),t._t=null,this.stage.fallbacks.decide(t),this.stage.scheduler.markDirty()}}};var Ye=/\bglyph\s*\(/;var Ze=t=>{for(let e of t)if(Ye.test(JSON.stringify(e))){ze.get().catch(Boolean);return}};function Qe(t,e){s(t.env.host.log);let i=new Ke(t),r=()=>{t.chunks.text=i,t.chunks.Jl(t.chunks.ae);let r=[...t.chunks.gh];t.chunks.gh.clear();for(let e of r)!t.planes.all.includes(e)||e.textureState!=="loading"||(e.textureState="none",t.factory.load(e));e&&t.chunks.Jl(new Set(t.planes.all.filter(t=>t.kind==="text"&&t.textureState==="error")))},n=i.curves.ahead();n?n.then(r):r()}export{tt as TEXT_HELPER,Ze as preloadGlyphs,Qe as textPlanes};
|
package/dist/chunks/video.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! Umber v0.
|
|
2
|
-
var R={info(){},warn:(i,...e)=>console.warn("[umber]",i,...e),once:(i,...e)=>console.warn("[umber]",i,...e),error:(i,...e)=>console.error("[umber]",i,...e)},f=R;function v(i){let e=i;return[e.displayWidth||e.videoWidth||e.naturalWidth||e.width||0,e.displayHeight||e.videoHeight||e.naturalHeight||e.height||0]}var P=i=>i instanceof HTMLVideoElement||"displayWidth"in i,d=class{constructor(e){this.gl=e;this.width=1;this.height=1;this.ready=!1;this.refs=0;this.box=[];this.mipmaps=!1;this.texture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.texture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array(4)),this.params(!1)}params(e){let r=this.gl;r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,e?r.LINEAR_MIPMAP_LINEAR:r.LINEAR)}get bytes(){return this.ready?this.width*this.height*4*(this.mipmaps?4/3:1):0}upload(e,r={}){let t=this.gl,s=r.mipmaps??!P(e),[o,n]=v(e);return!o||!n?!1:(t.bindTexture(t.TEXTURE_2D,this.texture),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,t.BROWSER_DEFAULT_WEBGL),this.ready&&o===this.width&&n===this.height&&(!s||this.mipmaps)?t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,e):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),s&&t.generateMipmap(t.TEXTURE_2D),(s!==this.mipmaps||!this.ready)&&this.params(s),this.mipmaps=s,this.width=o,this.height=n,this.ready=!0,!0)}dispose(){this.texture&&this.gl.deleteTexture(this.texture),this.texture=null,this.ready=!1}};var U=3,S=i=>!!i&&typeof i.close=="function",p=class{constructor(e,r,t){this.gl=e;this.ma=t;this.textures=new Map;this.queue=new Map;this.closing=[];this.a=-1;this.b=-1;this.amount=0;this.center=0;this.drawn=null;this.ra=null;this.error=null;this.cap=1/0;this.budget=r}put(e,r,t=!1){let s=this.queue.get(e);s&&s.image!==r&&s.close&&S(s.image)&&s.image.close(),this.queue.set(e,{image:r,close:t}),this.ma()}has(e){return this.queue.has(e)||!!this.textures.get(e)?.ready}ready(e){return!!this.textures.get(e)?.ready}show(e,r=-1,t=0){(r===e||t<=0)&&(r=-1,t=0),!(e===this.a&&r===this.b&&t===this.amount)&&(this.a=e,this.b=r,this.amount=t,this.ma())}focus(e){this.center=e}get bytes(){let e=0;return this.textures.forEach(r=>e+=r.bytes),e}get size(){return this.textures.size}get pending(){return this.queue.size+this.closing.length}keys(){return[...this.textures.keys()].filter(e=>this.textures.get(e).ready)}capacity(e,r){return Math.max(1,Math.floor(this.limit/Math.max(1,e*r*4)))}flush(){for(let t of this.closing)t.close();if(this.closing.length=0,!this.queue.size)return 0;let e=[...this.queue.keys()].sort((t,s)=>this.Nb(t)-this.Nb(s)),r=0;for(let t of e){if(r>=U&&t!==this.a&&t!==this.b)break;let s=this.queue.get(t);this.queue.delete(t);let[o,n]=v(s.image);if(o&&n){let a=this.textures.get(t)||new d(this.gl);try{a.upload(s.image,{mipmaps:!1}),this.textures.set(t,a),r++}catch(u){a.dispose(),this.textures.delete(t),this.error=u}}s.close&&S(s.image)&&this.closing.push(s.image)}return this.wb(),(this.queue.size||this.closing.length)&&this.ma(),r}Nb(e){return e===this.a?-2:e===this.b?-1:Math.abs(e-this.center)}fit(e){let r=this.bytes;return this.cap=Math.max(2*(this.drawn?.bytes||0),e),this.wb(),r-this.bytes}get limit(){return Math.min(this.budget,this.cap)}holds(e){for(let r of this.textures.values())if(r===e)return!0;return!1}wb(){let e=this.bytes;if(e<=this.limit)return;let r=[...this.textures.keys()].filter(t=>t!==this.a&&t!==this.b&&t!==this.center&&this.textures.get(t)!==this.drawn&&this.textures.get(t)!==this.ra).sort((t,s)=>Math.abs(s-this.center)-Math.abs(t-this.center));for(let t of r){if(e<=this.limit)break;let s=this.textures.get(t);e-=s.bytes,s.dispose(),this.textures.delete(t)}}get texture(){let e=this.textures.get(this.a);return e?.ready?this.drawn=e:this.drawn&&!this.drawn.ready&&(this.drawn=null),this.drawn}get next(){let e=this.b>=0&&this.drawn===this.textures.get(this.a)?this.textures.get(this.b):void 0;return this.ra=e?.ready?e:null,this.ra}get mix(){return this.ra?this.amount:0}get shown(){for(let[e,r]of this.textures)if(r===this.drawn)return e;return-1}pick(e){let r=this.texture;if(!r||e.texture===r)return!1;let t=e.texture;return e.texture=r,e.textureState!=="error"&&e.textureState!=="ready"&&(e.textureState="ready",e.resolveLoaded()),!t||t.width!==r.width||t.height!==r.height}clear(e=!1){let r=e?this.drawn:null,t=-1;this.textures.forEach((s,o)=>{s===r?t=o:s.dispose()}),this.forget(),r&&t>=0&&(this.textures.set(t,r),this.drawn=r)}forget(){this.textures.clear();for(let e of this.queue.values())e.close&&S(e.image)&&e.image.close();this.queue.clear();for(let e of this.closing)e.close();this.closing.length=0,this.drawn=null,this.ra=null}dispose(){this.clear()}};var I="[data-gl]",D=new Set(["data-gl","data-gl-effect","data-gl-shader","data-gl-layer","data-gl-instances"]),W=[...D,"style","class","hidden","media","disabled","data-gl-src","src","srcset","sizes","data-gl-occlude","data-gl-pass","data-gl-under"];var N="[data-gl-occlude]",V=I+","+N;function E(i){i.hasAttribute("data-gl-media")&&i.removeAttribute("data-gl-media"),i.querySelectorAll("[data-gl-media]").forEach(e=>e.removeAttribute("data-gl-media"))}var w=(i,e)=>i.muted&&(i.loop||i.autoplay)&&!i.controls&&e.dataset.glVideoAutopause!=="false"&&!e.hasAttribute("data-gl-scrub");function m(i){if(!i||typeof i.tagName!="string")return"<?>";let e=i.tagName.toLowerCase();if(i.id)return`<${e}#${i.id}>`;let r=typeof i.className=="string"?i.className.trim().split(/\s+/)[0]:"";return r?`<${e}.${r}>`:`<${e}>`}var k={high:128,mid:48,low:32},C={high:8,mid:2,low:1},G=3e3,x=i=>i.getAttribute("src")||i.querySelector("source")?.getAttribute("src")||"",b=class{constructor(e){this.stage=e;this.blocked=new Set;this.zb=!1;this.wa=new WeakMap;this.Qa=0;this.at=-1;this.left=0;this.na=0;this.oldest=0;this.first=0;this.waited=0;this.ta=0;this.Ja=0;this.Ob=new WeakMap;this.since=new WeakMap;this.retry=()=>{this.Ub();for(let e of this.blocked){let r=this.stage.planes.find(t=>t.media===e);r?.soon&&!r.destroyed&&e.play().catch(()=>{})}this.blocked.clear()};this.Ub=()=>{removeEventListener("pointerdown",this.retry),removeEventListener("touchstart",this.retry)}}upload(e){if(!e.videoFrame||!e.texture)return!0;let r=e.media;if(r.readyState<2)return!0;let t=this.stage,s=t.stats.renders;if(this.at!==s){let a=this.at===s-1;this.at=s,this.left=t.cap?1/0:C[t.tier],this.na=a?this.waited:0,this.oldest=this.ta,this.first=this.Ja,this.waited=this.Ja=0,this.ta=s}let o=this.Ob.get(e)??-2;if(o===s)return t.markDirty(),!0;let n=o===s-1?this.since.get(e):s;if(this.left<=(n===this.oldest?0:n<s?this.first:this.na))return n===s&&this.since.set(e,s),this.Ob.set(e,s),this.waited++,n<this.ta&&(this.ta=n,this.Ja=0),n===this.ta&&this.Ja++,t.markDirty(),!0;this.left--,n<s&&(this.na--,n===this.oldest&&this.first--);try{let a=e.texture,u=a.width,l=a.height;a.upload(r,{mipmaps:!1}),this.stage.stats.uploads++,(a.width!==u||a.height!==l)&&this.stage.media.place(e),e.textureState="ready",e.status!=="ready"&&e.readyFrame===-1&&e.resolveLoaded()}catch(a){return f.warn(`${m(e.el)}: the browser blocked its video as a texture (a cross-origin video without CORS headers?), so the DOM video shows. Serve it with Access-Control-Allow-Origin, or from this site's own domain.`,a),e.textureState="error",e.setStatus("error"),e.videoCleanup?.(),e.videoCleanup=null,!1}return e.videoFrame=!1,!0}release(e){if(e.kind!=="video"||!(e.media instanceof HTMLVideoElement))return;let r=e.media;r.pause(),r.removeAttribute("src"),r.querySelectorAll("source").forEach(t=>t.removeAttribute("src")),r.load()}renew(e,r){let t=e.media;if(!t)return;let s=this.wa.get(t);if(s===void 0)return void this.wa.set(t,x(t));let o=x(t);o===s||e._mods.feed?.src?.()===!1||(this.wa.set(t,o),this.stage.removePlane(e),r.push(e.el))}feed(e){let r=e._mods.frames,t=this.stage,s=r.flush();if(t.stats.uploads+=s,s){let o=this.frameBytes();t.stats.textureMB*2**20+(t.fx?.pool.bytes||0)+o<=t.textureBudget?this.Qa=0:o>this.Qa&&(this.Qa=o,t.media.evictFar())}return r.error&&(f.warn(`${m(e.el)}: its video frames can't become a texture (a video on another domain without CORS headers?), so the DOM video shows. Serve it with Access-Control-Allow-Origin, or from this site's own domain.`,e.el,r.error),r.error=null,e.textureState="error",e.setStatus("error"),E(e.el),r.clear()),s>0}frameBytes(){let e=0;for(let r of this.stage.planes){let t=r._mods.frames;t&&(e+=t.bytes-(t.holds(r.texture)?r.texture.bytes:0))}return e}fit(e){let r=0;for(let s of this.stage.planes)r+=s._mods.frames?.budget||0;let t=0;if(r)for(let s of this.stage.planes){let o=s._mods.frames;o&&(t+=o.fit(e*o.budget/r))}return t}frames(e){let r=this.stage;return new p(r.gl,e,()=>r.markDirty())}bind(e){let r=this.stage,t=r.host.log;for(let[o,n]of r.modulesOf(e.el)){let a=null;try{a=n.module.plane(this.context(e,o,n.options))}catch(u){t.error(`module "${o}" failed on this element; it is drawn without it.`,e.el,u)}a&&(e._mods.list.push({name:o,binding:a}),a.api!==void 0&&(o in e?r.host.lib.say("own",[o]):Object.defineProperty(e,o,{value:a.api,configurable:!0,enumerable:!0})),a.source&&!e._mods.feed&&(e._mods.feed=a))}let s=e.media;e._mods.feed&&s instanceof HTMLVideoElement&&this.wa.set(s,x(s))}context(e,r,t){let s=this.stage,o=s.host.log;return{el:e.el,plane:e,engine:s.host.engine,media:e.media,options:t,get frames(){return e._mods.frames||=s.video.frames(k[s.tier]*2**20)},tier:s.tier,maxTexture:s.maxTexture,isTouch:s.host.env.isTouch,get reducedMotion(){return s.reducedMotion},scrollKind:s.host.scroll.kind,log:o,busy(n){n!==e.busyReasons.has(r)&&(n?e.busyReasons.add(r):e.busyReasons.delete(r),s.markDirty())},wake(){s.markDirty()},fail(n){n&&o.warn(n,e.el),e.textureState="error",e.setStatus("error"),E(e.el),e._mods.frames?.clear(),s.markDirty()}}}load(e){let r=this.stage,t=e.media;if(!t){e.textureState="error",e.setStatus("error");return}this.wa.set(t,x(t)),e.textureState="loading";let s=t.currentSrc||t.src||t.querySelector("source")?.src||"",o=!1;try{o=!!s&&new URL(s,location.href).origin!==location.origin}catch{o=!1}if(o&&!t.crossOrigin){fetch(s,{method:"HEAD",mode:"cors",credentials:"omit"}).then(n=>{if(!n.ok)throw new Error(`HTTP ${n.status}`);if(r.lost||e.textureState!="loading"||!r.planes.includes(e))return;let a=!t.paused||t.autoplay&&!t.played?.length,u=t.currentTime,l=!a&&t.autoplay;t.crossOrigin="anonymous",l&&(t.autoplay=!1),t.load(),a||t.pause(),l&&(t.autoplay=!0),u&&(t.currentTime=u),a&&t.play().catch(()=>{}),this.start(e,t)}).catch(n=>{f.warn(`${m(e.el)}: the video at ${s} is on another domain that sends no CORS headers, so it can't become a texture and the DOM video shows. Serve it with Access-Control-Allow-Origin (Webflow's CDN and Bunny do), or from this site's own domain.`,n),e.textureState="error",e.setStatus("error")});return}this.start(e,t)}start(e,r){let t=this.stage,s=r.requestVideoFrameCallback?.bind(r),o=0,n=!1,a=()=>{},u=0,l=()=>{u=0;let h=e.loadingSince;if(n||e.textureState!=="loading"||!e.inView||!h)return;let c=h+G-performance.now();c<=0?t.markDirty():u=setTimeout(l,c)},y=()=>{u||l()},A=e.on("wait",y),M=e.on("enter",y),T=()=>{n||e.textureState=="error"||!(r.error||r.networkState==3)||(f.warn(`${m(e.el)}: the browser can't play its video ${r.currentSrc||r.src} (MediaError ${r.error?.code}), so the DOM video shows. Check the file, its codec (H.264) and that the server answers Range requests.`),e.textureState="error",e.setStatus("error"),E(e.el),t.markDirty())};r.addEventListener("error",T,!0);let L=()=>{n||(e.soon&&e.status!=="error"&&(e.videoFrame=!0,t.markDirty()),o=s(L))},g=()=>{n||(e.textureState==="error"&&!t.inactive&&!e.domReason&&(e.textureState="loading",e.setStatus("loading"),e.loadingSince=0,e.texture||=new d(t.gl),r.setAttribute("data-gl-media","")),e.videoFrame=!0,e.soon&&t.markDirty())};r.addEventListener("seeked",g),r.addEventListener("loadeddata",g);let _=()=>{r.removeEventListener("seeked",g),r.removeEventListener("loadeddata",g)};if(s)o=s(L);else{let h=()=>e.busyReasons.add("video"),c=()=>e.busyReasons.delete("video");r.addEventListener("playing",h),r.addEventListener("pause",c),r.addEventListener("ended",c),r.paused||h(),a=()=>{r.removeEventListener("playing",h),r.removeEventListener("pause",c),r.removeEventListener("ended",c)}}e.videoCleanup=()=>{n=!0,o&&r.cancelVideoFrameCallback?.(o),u&&clearTimeout(u),r.removeEventListener("error",T,!0),a(),_(),A(),M()},e.texture=new d(t.gl),e.videoFrame=r.readyState>=2,y(),T()}autoPause(e,r){let t=e.media;if(!(!(t instanceof HTMLVideoElement)||!w(t,e.el))){if(!r){t.paused||(t.pause(),e.autoPaused=!0);return}!e.autoPaused||this.stage.host.env.reducedMotion||(e.autoPaused=!1,t.play().catch(s=>{s?.name!=="NotAllowedError"||this.blocked.has(t)||(this.blocked.size||(addEventListener("pointerdown",this.retry,{once:!0,passive:!0}),addEventListener("touchstart",this.retry,{once:!0,passive:!0})),this.blocked.add(t),this.zb||this.stage.cleanups.push(this.Ub),this.zb=!0)}))}}};function te(i){i.video=new b(i),i.remake(i.videoWaiting)}export{te as video};
|
|
1
|
+
/*! Umber v0.4.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
var e=()=>{};var t=()=>Promise.reject(new Error("no words"));var s={configure:e,debug:!1,warnings:!1,info:e,warn:e,error:e,report:e,words:t},r=s;function i(e){r=e}var a=e=>e;var h=(...e)=>e.find(e=>!!e)??0;function l(e){let t=e;return[h(t.displayWidth,t.videoWidth,t.naturalWidth,t.width),h(t.displayHeight,t.videoHeight,t.naturalHeight,t.height)]}var n=e=>e instanceof HTMLVideoElement||"displayWidth"in e,o=class{constructor(e){this.gl=e;this.width=1;this.height=1;this.ready=!1;this.packed=0;this.il=1;this.refs=0;this.box=[];this.mipmaps=!1;this.texture=a(e.createTexture()),e.bindTexture(e.TEXTURE_2D,this.texture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array(4)),this.params(!1)}params(e){let t=this.gl;t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e?t.LINEAR_MIPMAP_LINEAR:t.LINEAR)}get bytes(){return this.ready?this.packed||this.width*this.height*4*(this.mipmaps?4/3:1):0}adopt(e,t){this.texture!==e&&this.gl.deleteTexture(this.texture),this.texture=e,this.width=t.width,this.height=t.height,this.packed=t.bytes,this.mipmaps=t.mipmaps,this.il=1,this.ready=!0}upload(e,t={}){let s=this.gl,r=t.mipmaps??!n(e),[i,h]=l(e);return!i||!h||!this.texture||this.packed&&(s.deleteTexture(this.texture),this.texture=a(s.createTexture()),this.packed=0,this.il=1,this.ready=!1,!this.texture)?!1:(s.bindTexture(s.TEXTURE_2D,this.texture),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!t.straight),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.BROWSER_DEFAULT_WEBGL),this.ready&&i===this.width&&h===this.height&&(!r||this.mipmaps)?s.texSubImage2D(s.TEXTURE_2D,0,0,0,s.RGBA,s.UNSIGNED_BYTE,e):s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,e),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r&&s.generateMipmap(s.TEXTURE_2D),(r!==this.mipmaps||!this.ready)&&this.params(r),this.mipmaps=r,this.width=i,this.height=h,this.ready=!0,!0)}angle(e){e===this.il||!this.mipmaps||!this.ready||(this.il=e,this.gl.texParameterf(this.gl.TEXTURE_2D,u,e))}dispose(){this.texture&&this.gl.deleteTexture(this.texture),this.texture=null,this.ready=!1}},u=34046;var d=3,c=e=>!!e&&typeof e.close=="function",m=class{constructor(e,t,s){this.gl=e;this.ya=s;this.textures=new Map;this.queue=new Map;this.closing=[];this.xb=-1;this.td=-1;this.amount=0;this.center=0;this.drawn=null;this.drawnNext=null;this.error=null;this.cap=1/0;this.budget=t}put(e,t,s=!1){let r=this.queue.get(e);r&&r.image!==t&&r.close&&c(r.image)&&r.image.close(),this.queue.set(e,{image:t,close:s}),this.ya()}has(e){return this.queue.has(e)||!!this.textures.get(e)?.ready}ready(e){return!!this.textures.get(e)?.ready}show(e,t=-1,s=0){(t===e||s<=0)&&(t=-1,s=0),!(e===this.xb&&t===this.td&&s===this.amount)&&(this.xb=e,this.td=t,this.amount=s,this.ya())}focus(e){this.center=e}get bytes(){let e=0;return this.textures.forEach(t=>e+=t.bytes),e}get size(){return this.textures.size}get pending(){return this.queue.size+this.closing.length}keys(){return[...this.textures].filter(([,e])=>e.ready).map(([e])=>e)}capacity(e,t){return Math.max(1,Math.floor(this.limit/Math.max(1,e*t*4)))}flush(){for(let e of this.closing)e.close();if(this.closing.length=0,!this.queue.size)return 0;let e=[...this.queue].sort(([e],[t])=>this.rank(e)-this.rank(t)),t=0;for(let[s,r]of e){if(t>=d&&s!==this.xb&&s!==this.td)break;this.queue.delete(s),this.upload(s,r.image)&&t++,r.close&&c(r.image)&&this.closing.push(r.image)}return this.Oj(),(this.queue.size||this.closing.length)&&this.ya(),t}upload(e,t){let[s,r]=l(t);if(!s||!r)return!1;let i=this.textures.get(e)??new o(this.gl);try{return i.upload(t,{mipmaps:!1}),this.textures.set(e,i),!0}catch(t){return i.dispose(),this.textures.delete(e),this.error=t,!1}}rank(e){return e===this.xb?-2:e===this.td?-1:Math.abs(e-this.center)}fit(e){let t=this.bytes;return this.cap=Math.max(2*(this.drawn?.bytes??0),e),this.Oj(),t-this.bytes}get limit(){return Math.min(this.budget,this.cap)}holds(e){for(let t of this.textures.values())if(t===e)return!0;return!1}Oj(){let e=this.bytes;if(e<=this.limit)return;let t=[...this.textures].filter(([e,t])=>e!==this.xb&&e!==this.td&&e!==this.center&&t!==this.drawn&&t!==this.drawnNext).sort(([e],[t])=>Math.abs(t-this.center)-Math.abs(e-this.center));for(let[s,r]of t){if(e<=this.limit)break;e-=r.bytes,r.dispose(),this.textures.delete(s)}}get texture(){let e=this.textures.get(this.xb);return e?.ready?this.drawn=e:this.drawn&&!this.drawn.ready&&(this.drawn=null),this.drawn}get next(){let e=this.td>=0&&this.drawn===this.textures.get(this.xb)?this.textures.get(this.td):void 0;return this.drawnNext=e?.ready?e:null,this.drawnNext}get mix(){return this.drawnNext?this.amount:0}get shown(){for(let[e,t]of this.textures)if(t===this.drawn)return e;return-1}pick(e){let t=this.texture;if(!t||e.texture===t)return!1;let s=e.texture;return e.texture=t,e.textureState!=="error"&&e.textureState!=="ready"&&(e.textureState="ready",e._o()),s?.width!==t.width||s.height!==t.height}clear(e=!1){let t=e?this.drawn:null,s=-1;this.textures.forEach((e,r)=>{e===t?s=r:e.dispose()}),this.forget(),t&&s>=0&&(this.textures.set(s,t),this.drawn=t)}forget(){this.textures.clear();for(let e of this.queue.values())e.close&&c(e.image)&&e.image.close();this.queue.clear();for(let e of this.closing)e.close();this.closing.length=0,this.drawn=null,this.drawnNext=null}dispose(){this.clear()}};var g=8*2**20;var p=(e,t)=>e.muted&&(e.loop||e.autoplay)&&!e.controls&&t.dataset.umberVideoAutopause!=="false"&&!t.hasAttribute("data-umber-scrub");var f=["image","video","text","shader","layer","model","group"],x=`:is(${f.map(e=>`[data-umber~=${e}]`).join()})`;var b=new Set(["data-umber","data-umber-effect","data-umber-shader","data-umber-layer","data-umber-instances"]),v=[...b,"style","class","hidden","media","disabled","data-umber-src","src","srcset","sizes","data-umber-occlude","data-umber-pass","data-umber-under","data-umber-order"];var y="[data-umber-occlude]",E=x+","+y;var w=`${x}:not([data-umber-status="error"]),[data-umber-occlude]`;function T(e){e.hasAttribute("data-umber-media")&&e.removeAttribute("data-umber-media"),e.querySelectorAll("[data-umber-media]").forEach(e=>{e.removeAttribute("data-umber-media")})}var k={high:128,mid:48,low:32},_={high:8,mid:2,low:1},A=3e3;function S(e){let t=e.getAttribute("src");return t||(e.querySelector("source")?.getAttribute("src")??"")}var L=()=>{};function R(e,t,s){t.textureState!=="error"||e.scheduler.inactive||t.domReason||(t.textureState="loading",t.setStatus("loading"),t._N(),t.texture??=new o(e.gpu.gl),s.setAttribute("data-umber-media",""))}function M(e,t){let s=()=>e._U.add("video"),r=()=>e._U.delete("video");return t.addEventListener("playing",s),t.addEventListener("pause",r),t.addEventListener("ended",r),t.paused||s(),()=>{t.removeEventListener("playing",s),t.removeEventListener("pause",r),t.removeEventListener("ended",r)}}var U=class{constructor(e){this.stage=e;this.blocked=new Set;this.hooked=!1;this.pb=new WeakMap;this.emptied=new WeakMap;this.ql=!1;this.Ak=0;this.at=-1;this.left=0;this.Xe=0;this.oldest=0;this.first=0;this.waited=0;this.Jk=0;this.ke=0;this.Vd=new WeakMap;this.since=new WeakMap;this.retry=()=>{this.G();for(let e of this.blocked){let t=this.stage.planes.all.find(t=>t.media===e);t?.zone.soon&&!t.destroyed&&e.play().catch(L)}this.blocked.clear()};this.G=()=>{removeEventListener("pointerdown",this.retry),removeEventListener("touchstart",this.retry)}}upload(e){let t=e.texture;if(!e.videoFrame||!t)return!0;let s=e.media;if(s.readyState<2)return!0;let r=this.stage,i=r.env.stats.renders;this.at!==i&&this.Te(i);let a=this.Vd.get(e)??-2;if(a===i)return r.scheduler.markDirty(),!0;let h=a===i-1?this.since.get(e)??i:i;return this.left<=this.Wc(h,i)?(this.lc(e,h,i),!0):(this.left--,h<i&&(this.Xe--,h===this.oldest&&this.first--),this.Tc(e,s,t)?(e.videoFrame=!1,!0):!1)}Te(e){let t=this.stage,s=this.at===e-1;this.at=e,this.left=t.chunks.vl?1/0:_[t.gpu.tier.tier],this.Xe=s?this.waited:0,this.oldest=this.Jk,this.first=this.ke,this.waited=0,this.ke=0,this.Jk=e}lc(e,t,s){t===s&&this.since.set(e,s),this.Vd.set(e,s),this.waited++,t<this.Jk&&(this.Jk=t,this.ke=0),t===this.Jk&&this.ke++,this.stage.scheduler.markDirty()}Tc(e,t,s){let r=this.stage;try{let i=s.width,a=s.height;return s.upload(t,{mipmaps:!1}),r.env.stats.uploads++,(s.width!==i||s.height!==a)&&r.gpu.media.place(e),e.textureState="ready",(e.state.status==="error"||e.state.status==="loading"&&e.state.drawnFrame===null)&&e._o(),!0}catch(t){return r.env.lib.say("videoBlocked",[e.el],t),e.textureState="error",e.setStatus("error"),e._E?.(),e._E=null,!1}}release(e){if(e.kind!=="video"||!(e.media instanceof HTMLVideoElement))return;let t=e.media;if(t.pause(),this.emptied.has(t))return;let s=[];t.querySelectorAll("source").forEach(e=>{let t=e.getAttribute("src");t!==null&&(s.push([e,t]),e.removeAttribute("src"))});let r=t.getAttribute("src");r===null&&!s.length||(this.emptied.set(t,{own:r,sources:s}),this.ql=!0,t.removeAttribute("src"),t.load())}Lk(e){if(!this.ql)return;let t=e instanceof HTMLVideoElement?[e]:e.querySelectorAll("video");for(let e of t){let t=this.emptied.get(e);if(!(!t||!e.isConnected)){this.emptied.delete(e);for(let[e,s]of t.sources)e.setAttribute("src",s);t.own!==null?e.setAttribute("src",t.own):e.load()}}}Ie(e,t){let s=e.media;if(!s)return;let r=this.pb.get(s);if(r===void 0)return void this.pb.set(s,S(s));let i=S(s);i===r||e.modules.feed?.src?.()===!1||(this.pb.set(s,i),this.stage.planes.remove(e),t.push(e.el))}Wc(e,t){return e===this.oldest?0:e<t?this.first:this.Xe}feed(e){let t=e.modules.frames;if(!t)return!1;let s=this.stage,r=t.flush();return s.env.stats.uploads+=r,r&&this.Bb(),t.error&&(s.env.lib.say("videoFrames",[e.el],e.el,t.error),t.error=null,e.textureState="error",e.setStatus("error"),T(e.el),t.clear()),r>0}Bb(){let e=this.stage,t=this.Kl();e.env.stats.textureMB*2**20+(e.chunks.fx?.pool.bytes??0)+t<=e.gpu.tier.textureBudget?this.Ak=0:t>this.Ak&&(this.Ak=t,e.gpu.media.Ea())}Kl(){let e=0;for(let t of this.stage.planes.all){let s=t.modules.frames;s&&(e+=s.bytes-(s.holds(t.texture)?t.texture?.bytes??0:0))}return e}fit(e){let t=0;for(let e of this.stage.planes.all)t+=e.modules.frames?.budget??0;let s=0;if(t)for(let r of this.stage.planes.all){let i=r.modules.frames;i&&(s+=i.fit(e*i.budget/t))}return s}frames(e){let t=this.stage;return new m(t.gpu.gl,e,()=>{t.scheduler.markDirty()})}bind(e){let t=this.stage,s=t.env.host.log;for(let[r,i]of t.factory.zb(e.el)){let t=null;try{t=i.module.plane?.(this.context(e,r,i.options))}catch(t){s.error(`module "${r}" failed on this element; it is drawn without it.`,e.el,t)}t&&this.bound(e,r,t)}let r=e.media;e.modules.feed&&r instanceof HTMLVideoElement&&this.pb.set(r,S(r))}bound(e,t,s){e.modules.list.push({name:t,binding:s}),s.api!==void 0&&(t in e?this.stage.env.lib.say("own",[t]):Object.defineProperty(e,t,{value:s.api,configurable:!0,enumerable:!0})),s.source&&!e.modules.feed&&(e.modules.feed=s)}context(e,t,s){let r=this.stage,i=()=>this.frames(k[r.gpu.tier.tier]*2**20),a=r.env.host.log;return{el:e.el,plane:e,engine:r.env.host.engine,media:e.media,options:s,get frames(){return e.modules.frames??=i()},tier:r.gpu.tier.tier,maxTexture:r.gpu.tier.maxTexture,isTouch:r.env.host.env.isTouch,get reducedMotion(){return r.env.reducedMotion},log:a,busy(s){s!==e._U.has(t)&&(s?e._U.add(t):e._U.delete(t),r.scheduler.markDirty())},wake(){r.scheduler.markDirty()},fail(t){t&&a.warn(t,e.el),e.textureState="error",e.setStatus("error"),T(e.el),e.modules.frames?.clear(),r.scheduler.markDirty()}}}load(e){let t=this.stage,s=e.media;if(!s){e.textureState="error",e.setStatus("error");return}this.pb.set(s,S(s)),e.textureState="loading";let r=s.currentSrc||s.src||(s.querySelector("source")?.src??""),i;try{i=!!r&&new URL(r,location.href).origin!==location.origin}catch{i=!1}if(i&&!s.crossOrigin){let i=new AbortController;fetch(r,{mode:"cors",credentials:"omit",signal:i.signal}).then(r=>{if(i.abort(),!r.ok)throw new Error(`HTTP ${r.status}`);if(t.gpu.context.gone||e.textureState!=="loading"||!t.planes.all.includes(e))return;let a=!s.paused||s.autoplay&&!s.played.length,h=s.currentTime,l=!a&&s.autoplay;s.crossOrigin="anonymous",l&&(s.autoplay=!1),s.load(),a||s.pause(),l&&(s.autoplay=!0),h&&(s.currentTime=h),a&&s.play().catch(L),this.start(e,s)}).catch(t=>{this.stage.env.lib.say("videoCors",[e.el,r],t),e.textureState="error",e.setStatus("error")});return}this.start(e,s)}start(e,t){let s=this.stage,r="requestVideoFrameCallback"in t?e=>t.requestVideoFrameCallback(e):null,i=0,a=!1,h=()=>{},l,n=()=>{l=void 0;let t=e.state.status==="loading"?e.state.waitingSince:null;if(a||e.textureState!=="loading"||!e.zone.screen||!t)return;let r=t+A-performance.now();r<=0?s.scheduler.markDirty():l=setTimeout(n,r)},u=()=>{l||n()},d=e.on("wait",u),c=e.on("enter",u),m=()=>{a||e.textureState==="error"||!(t.error||t.networkState===3)||(s.env.lib.say("videoPlay",[e.el,t.currentSrc||t.src,t.error?.code]),e.textureState="error",e.setStatus("error"),T(e.el),s.scheduler.markDirty())};t.addEventListener("error",m,!0);let g=()=>{a||(e.zone.soon&&e.status!=="error"&&(e.videoFrame=!0,s.scheduler.markDirty()),r&&(i=r(g)))},p=()=>{a||(R(s,e,t),e.videoFrame=!0,e.zone.soon&&s.scheduler.markDirty())};t.addEventListener("seeked",p),t.addEventListener("loadeddata",p);let f=()=>{t.removeEventListener("seeked",p),t.removeEventListener("loadeddata",p)};r?i=r(g):h=M(e,t),e._E=()=>{a=!0,i&&t.cancelVideoFrameCallback(i),l&&clearTimeout(l),t.removeEventListener("error",m,!0),h(),f(),d(),c()},e.texture=new o(s.gpu.gl),e.videoFrame=t.readyState>=2,u(),m()}Rh(e,t){let s=e.media;if(!(!(s instanceof HTMLVideoElement)||!p(s,e.el))){if(!t){s.paused||(s.pause(),e._j=!0);return}!e._j||this.stage.env.host.env.reducedMotion||(e._j=!1,s.play().catch(e=>{(typeof e=="object"&&e!==null&&"name"in e?e.name:void 0)!=="NotAllowedError"||this.blocked.has(s)||(this.blocked.size||(addEventListener("pointerdown",this.retry,{once:!0,passive:!0}),addEventListener("touchstart",this.retry,{once:!0,passive:!0})),this.blocked.add(s),this.hooked||this.stage.env.cleanups.push(this.G),this.hooked=!0)}))}}};function D(e){i(e.env.host.log),e.chunks.video=new U(e),e.chunks.Jl(e.chunks.Ml)}export{D as video};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.4.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
var e=(e,t)=>e[t]??NaN;function t(e){if(!e||typeof e.tagName!="string")return"<?>";let t=e.tagName.toLowerCase();if(e.id)return`<${t}#${e.id}>`;let o=typeof e.className=="string"?e.className.trim().split(/\s+/)[0]:"";return o?`<${t}.${o}>`:`<${t}>`}var o=2;function n(e,t){let n="",a=o+1;for(let o of t){let t=r(e.toLowerCase(),o.toLowerCase());t<a&&(n=o,a=t)}return n}function r(t,o){let n=Array.from({length:o.length+1},(e,t)=>t);for(let r=1;r<=t.length;r++){let a=r-1;n[0]=r;for(let i=1;i<=o.length;i++){let l=e(n,i);n[i]=Math.min(l+1,e(n,i-1)+1,a+(t[r-1]===o[i-1]?0:1)),a=l}}return e(n,o.length)}var a={image:["plane","core"],video:["plane","core"],text:["plane","core"],shader:["plane","core"],layer:["plane","core"],model:["plane","three"],group:["plane","core"],scroller:["kind","core"],pin:["long","scrollfx"],horizontal:["behaviour","scrollfx"],inview:["long","scrollfx"],above:["behaviour","core"]},i=e=>Object.hasOwn(a,e)?a[e]:void 0,l=e=>e==="plane"||e==="kind";var s=e=>fetch(e,e.startsWith(location.origin+"/")?{mode:"no-cors",credentials:"include"}:{});function u(e,t){let o=t.get(e);return o||(o=s(e).then(e=>e.ok?e.json():null).catch(()=>null),t.set(e,o)),o}var d=1024*512;function h(e,t,o){let n=Math.round(t*o*4*1.3333333333333333/1048576);return`The picture ${e} is read as a uniform and was decoded from its own file (${t} x ${o}: ${n} MB on the GPU), though this site's build prepared it. A uniform draws a prepared file only for a picture the build was told to: pictures: ["${e.replace(/^\//,"")}"] in the asset tool's options (the Vite plugin, the Astro integration, --pictures). A picture that holds data (a depth or normal map, a mask) takes a floor of its own, { file: "${e.replace(/^\//,"")}", quality: 50 }: block compression at the default quality shows there.`}function c(e){let t=document.querySelector('meta[name="umber-assets"]')?.content;if(!t)return()=>{};let o=null;u(new URL(t,document.baseURI).href,e.gpu.media.manifests).then(e=>o=e?.images??{});let n=new Set,r=e.env.host.ticker.add(()=>{if(e.env.destroyed){r();return}if(o)for(let[t,r]of e.gpu.media.Ef){let a=t.width*t.height;if(!t.ready||t.bytes<a*4||a<d||n.has(r))continue;n.add(r);let i=new URL(r,document.baseURI),l=i.origin===location.origin?o[i.pathname]:void 0;l&&!(l[5]&64)&&e.env.host.log.warn(h(i.pathname,t.width,t.height))}},{phase:"render",order:1/0,always:!1,label:"umber"});return r}var f=300,m=/for\s*\([^;)]*;[^;)]*[<>]=?\s*(?:\d+|[A-Z][A-Z0-9_]*)\s*;[^)]*\)/g;function p(e){let t=[],o=e=>{typeof e=="string"?t.push(e):e&&typeof e=="object"&&Object.values(e).forEach(o)},{head:n,fragment:r,vertex:a}=e;return[n,r,a].forEach(o),t.join(`\n`)}function $(e){let t=[e.shader,...e.effects].map(e=>e?p(e.def):"").join(`\n`);return[...new Set([...t.matchAll(m)].map(e=>e[0].replace(/\s+/g," ")))].slice(0,3)}function g(e,o){let n=$(e);return`The ${e.shader?`shader "${e.shader.name}"`:`program "${e.programKey}"`} on ${t(e.el)} took ${Math.round(o)} ms to compile on this computer, and its DOM showed until then (a first visit only: the browser keeps the compiled program). `+(n.length?`Its GLSL has ${n.length>1?"loops":"a loop"} with a fixed bound: ${n.join(", ")}. Direct3D (Windows) compiles such a loop as one copy of its body a turn, for every call of its function; with the bound in a uniform (uniform int uSteps; i < uSteps) it stays a loop and compiles in a fraction of the time.`:"Loops with a fixed bound, and functions with loops called from many places, are what usually cost this.")}function w(e,t=()=>performance.now()){let o=e.env.host.log.warn,n=new Map,r=e.env.host.ticker.add(()=>{if(e.env.destroyed){r();return}for(let r of e.planes.all){let e=r.program;if(!e?.started)continue;let a=n.get(e);e.state==="pending"?a===void 0&&n.set(e,t()):a!==void 0&&(n.delete(e),e.state==="ok"&&t()-a>f&&o(g(r,t()-a),r.el))}},{phase:"render",order:1/0,always:!1,label:"umber"});return r}function b(e){w(e),c(e)}var y=Object.keys(a),v=y.filter(e=>l(i(e)?.[0])),k=Object.entries(a).flatMap(([e,[t,o]])=>t==="long"?[{word:e,owner:o}]:[]),j=["[data-umber]",...k.map(({word:e})=>`[data-umber-${e}]`)].join(),A=e=>`Load it with data-umber-modules="${e}" on the umber.js tag, or umber.use() it from "@occluze/umber/${e}".`;function x(e,o,r){let a=`data-umber="${o}" on ${t(e)}`,s=o.split(/\s+/).filter(Boolean);if(!s.length)return[`data-umber on ${t(e)} says nothing: name what it is (${v.join(", ")}) or how it behaves.`];let u=[],d=s.filter(e=>l(i(e)?.[0]));d.length>1&&u.push(`${a} names ${d.length} kinds (${d.join(", ")}): an element is one. Keep one.`);for(let e of s){let t=i(e)?.[1];if(t)t!=="core"&&!r.has(t)&&u.push(`${a}: "${e}" is the ${t} add-on's, which isn't loaded. ${A(t)}`);else{let t=n(e,y);u.push(`${a}: "${e}" is not a word Umber knows${t?` (did you mean "${t}"?)`:""}. The words: ${y.join(", ")}. A setting has its own attribute, data-umber-${e}="...".`)}}return u}function L(e,o,n){let r=[],a=t(e),i=(o??"").split(/\s+/);for(let{word:t,owner:l}of k){let s=e.getAttribute(`data-umber-${t}`);s!==null&&(s.trim()?i.includes(t)?r.push(`data-umber="${o}" and data-umber-${t}="${s}" on ${a} say the same: keep data-umber-${t}="${s}" alone.`):n.has(l)||r.push(`data-umber-${t} on ${a} is the ${l} add-on's, which isn't loaded. ${A(l)}`):r.push(`data-umber-${t} on ${a} has no value: without one, write data-umber="${t}".`))}return r}function S(e,t){let o=[];for(let n of e){if(!n.isConnected)continue;let e=n.matches(j)?[n,...n.querySelectorAll(j)]:n.querySelectorAll(j);for(let n of e){let e=n.getAttribute("data-umber"),r=[...e===null?[]:x(n,e,t),...L(n,e,t)];for(let e of r)o.push([e,n])}}return o}export{S as checkWords,b as watch};
|
package/dist/chunks/warm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! Umber v0.
|
|
2
|
-
var D={info(){},warn:(s,...e)=>console.warn("[umber]",s,...e),once:(s,...e)=>console.warn("[umber]",s,...e),error:(s,...e)=>console.error("[umber]",s,...e)},g=D;function _(s){s&&(g=s)}var M=/\b(umberHash|noise|fbm|rotate2d|screenUv|screenPx|samplePrev)\s*\(|\buScreen\b/;var A=/\bglyph\s*\(/;var L=/\b(?:(?:quad|cubic|quart|quint|sine|expo|circ)(?:In|Out|B)|stagger|[sp]noise|cellular|sd[A-Z]|op[A-Z]|aa|blend[A-Z]|bayer|blueNoise|dither|srgbTo|linearTo|oklabTo|mixOklab|umber[A-Z])\w*\s*\(/;var x=s=>e=>Math.pow(e,s),Z={quad:x(2),cubic:x(3),quart:x(4),quint:x(5),sine:s=>1-Math.cos(s*Math.PI/2),expo:s=>s===0?0:Math.pow(2,10*s-10),circ:s=>1-Math.sqrt(1-s*s)};var R="umber";var T={duration:1.4,delay:0,ease:R,start:"top 90%",trigger:"auto"};function N(s){let e=[],t=/[\s,]*(\S+)([^,]*)/g;for(let r;(r=t.exec(s||""))&&r[1];){let n=r[1].replace(/,+$/,"");n!==r[1]&&(t.lastIndex=r.index+r[0].indexOf(r[1])+r[1].length),e.push([n,n!==r[1]?"1x":r[2].trim()||"1x"])}return e}function y(s){let e=/^calc\((.+)\)$/.exec(s);if(e){let n=e[1].trim().split(/\s+([+-])\s+/),o=y(n[0]);for(let i=1;i<n.length;i+=2)o+=(n[i]==="-"?-1:1)*y(n[i+1]);return o}let t=/^([\d.]+)(vw|px|r?em)$/.exec(s),r=t?Number(t[1]):NaN;return t?t[2]==="vw"?innerWidth*r/100:t[2]==="px"?r:r*16:innerWidth}function w(s){let e=[],t=0,r=0;for(let n=0;n<=s.length;n++){let o=s[n];o==="("?t++:o===")"?t--:!t&&(o===","||o===void 0)&&(e.push(s.slice(r,n).trim()),r=n+1)}for(let n of e){let o=-1;for(let a=0,u=0;a<n.length;a++)n[a]==="("?u++:n[a]===")"?u--:!u&&/\s/.test(n[a])&&(o=a);let i=o>0?n.slice(0,o):"";if(n&&(!i||matchMedia(i).matches))return y(n.slice(o+1))}return innerWidth}function E(s){let e=s.ownerDocument?.baseURI||document.baseURI,t=a=>a?new URL(a,e).href:"",r=N(s.getAttribute("srcset")).map(([a,u])=>({url:a,n:parseFloat(u)||1,w:u.endsWith("w")})),n=s.getAttribute("src");if(n&&!r.some(a=>a.w||a.n==1)&&r.push({url:n,n:1,w:!1}),!r.length)return"";let o=window.devicePixelRatio||1,i=o;return r[0].w&&(i=w(s.getAttribute("sizes")||"")*o),r.sort((a,u)=>a.n-u.n),t((r.find(a=>a.n>=i)||r[r.length-1]).url)}function H(s){if(!s.href||s.hasAttribute("download")||s.target&&s.target!=="_self")return"";let e=new URL(s.href,location.href);e.hash="";let t=new URL(location.href);return t.hash="",e.origin===location.origin&&e.href!==t.href&&/^https?:$/.test(e.protocol)?e.href:""}function C(s,e,t=0){let r=navigator.connection;if(r?.saveData||/2g/.test(r?.effectiveType||""))return()=>{};let n=new Set,o=null,i,a=0,u=0,f=0,c=()=>{let p=o?H(o):"";if(p&&!n.has(p)){n.add(p);let m=()=>t&&setTimeout(()=>n.delete(p),t);Promise.resolve(e(p)).then(m,m)}},l=()=>{clearTimeout(i),i=setTimeout(c,65)},d=p=>{let m=p,h=m.target.closest?.(s);h!==o&&(clearTimeout(i),o=h&&h.href!==void 0?h:null,o&&(a=m.clientX,u=m.clientY,f=m.timeStamp,m.pointerType&&m.pointerType!=="mouse"?c():l()))},v=p=>{let m=p,h=m.timeStamp-f;if(!o||h<=0)return;let B=Math.hypot(m.clientX-a,m.clientY-u)/h>.5;a=m.clientX,u=m.clientY,f=m.timeStamp,B&&l()},S=p=>{p.relatedTarget||(clearTimeout(i),o=null)},b={passive:!0};return document.addEventListener("pointerover",d,b),document.addEventListener("pointermove",v,b),document.addEventListener("pointerout",S,b),()=>{clearTimeout(i),document.removeEventListener("pointerover",d),document.removeEventListener("pointermove",v),document.removeEventListener("pointerout",S)}}function I(s,e,t){let r=[e-1<<4|t-1],n=-1;for(let o=0;o<e*t*4;o++){if((o&3)===3)continue;let i=Math.round(s[o]/17);n<0?n=i:(r.push(n<<4|i),n=-1)}return n>=0&&r.push(n<<4),btoa(String.fromCharCode(...r)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function O(s){let e;try{e=atob(s.trim().replace(/-/g,"+").replace(/_/g,"/"))}catch{return null}let t=(e.charCodeAt(0)>>4)+1,r=(e.charCodeAt(0)&15)+1;if(!e||e.length<1+Math.ceil(t*r*3/2))return null;let n=new Uint8ClampedArray(t*r*4);for(let o=0,i=0;o<n.length;o++)if((o&3)===3)n[o]=255;else{let a=e.charCodeAt(1+(i>>1));n[o]=(i++&1?a&15:a>>4)*17}return{w:t,h:r,data:n}}function U(s){let e=O(s);if(!e)return"";let t=document.createElement("canvas");return t.width=e.w,t.height=e.h,t.getContext("2d")?.putImageData(new ImageData(e.data,e.w,e.h),0,0),t.toDataURL()}var k=()=>{let s=typeof window<"u"&&window.occluzeCapture;return s?.version==1?s:null},z=()=>new Promise(s=>{let e=new MessageChannel;e.port1.onmessage=s,e.port2.postMessage(0)});var $=2e4,j=8e3,V=/^data:image\/|\.(avif|webp|jpe?g|png|gif|svg)([?#]|$)/i,X=()=>k()?z():new Promise(s=>"requestIdleCallback"in window?requestIdleCallback(()=>s(),{timeout:300}):setTimeout(s,16)),W=s=>s.ownerDocument!==document||!s.isConnected,P=class{constructor(e){this.stage=e;this.buf=null;this.runs=0;this.Va=null;e.cleanups.push(()=>this.hover(!1))}preload(e){let t=e.what;return t&&typeof t=="object"&&"hover"in t?this.hover(t.hover):this.run(e,this.collect(t))}warm(e){let t=this.stage,r=e.what,n=typeof r=="string"?document.querySelector(r):r;return this.run(e,t.planes.filter(o=>o.kind!=="layer"&&o.status!=="error"&&(!n||n.contains(o.el))).map(o=>this.fx().then(i=>i?.whenReady(o).then(a=>a?this.draw(o):void 0))))}async placeholder(e){let t=this.stage,r=typeof e=="string"?null:e,n=r&&(t.host.lib.findMedia(r)||r),o=typeof e=="string"?e:n?.currentSrc||n&&E(n);if(!o)return null;try{let i=await t.bitmap(o,t.maxTexture),a=6/Math.max(i.width,i.height),u=Math.max(1,Math.round(i.width*a)),f=Math.max(1,Math.round(i.height*a)),c=await createImageBitmap(i,{resizeWidth:u,resizeHeight:f,resizeQuality:"high"});"close"in i&&i.close();let l=document.createElement("canvas");l.width=u,l.height=f;let d=l.getContext("2d");return d.drawImage(c,0,0),c.close(),I(d.getImageData(0,0,u,f).data,u,f)}catch(i){return g.warn(`gl.placeholder(): ${o} could not be read (not found, or another domain without CORS headers).`,i),null}}paint(e){let t=this.stage.host.lib.findMedia(e),r=e.getAttribute("data-gl-placeholder")||"";if(!t||t.tagName!=="IMG"||t.complete&&t.naturalWidth||t.style.backgroundImage)return;let n=U(r);if(!n)return g.warn(`data-gl-placeholder="${r}" is not a placeholder Umber can read; make one with gl.placeholder(src).`,e);let o=t.style;o.backgroundImage=`url(${n})`,o.backgroundSize="cover",o.backgroundPosition="center",t.addEventListener("load",()=>o.backgroundImage=o.backgroundSize=o.backgroundPosition="",{once:!0})}note(e,t){let r=this.stage;if(e)return g.warn(`${e} is ${t[2]}x${t[3]} px, over this GPU's ${r.maxTexture} px: it is drawn shrunk, so softer. Crop it, or point data-gl-src at a smaller file.`);let n=r.planes.filter(o=>o.texture?.ready).sort((o,i)=>i.texture.bytes-o.texture.bytes);g.warn(`Images near the screen take ${t[0]>>20} MB of GPU memory${t[1]?`, render targets and video frames ${t[1]>>20} MB more`:""}, over this device's ${r.textureBudget>>20} MB (gl.info.gpuMB). The largest images: ${n.slice(0,3).map(o=>`${r.host.lib.describe(o.el)} (${o.texture.width}x${o.texture.height})`).join(", ")}. Serve smaller files (srcset and sizes, or data-gl-src).`)}collect(e,t=[]){if(!e)return t;if(typeof e=="string"||e instanceof URL){let r=new URL(String(e),document.baseURI).href;t.push(V.test(r)?this.image(r):this.page(r).then(n=>n&&this.run({},this.collect(n))))}else if(Array.isArray(e)||e instanceof NodeList)for(let r of e)this.collect(r,t);else if(typeof e.querySelectorAll=="function"){let r=e,n=[...r.querySelectorAll("[data-gl]")];r.matches?.("[data-gl]")&&n.unshift(r);for(let o of n)t.push(this.element(o))}else if(typeof e=="object"){let r=e;this.collect(r.container||r.html&&F(r.html,document.baseURI)||(typeof r.url=="object"?r.url?.href:r.url),t)}return t}page(e){return fetch(e,{credentials:"same-origin"}).then(t=>t.ok?t.text():"").then(t=>t?F(t,e):null).catch(t=>(g.info("preload: page not fetched",e,t),null))}async element(e){let t=this.stage,r=t.host.lib.findMedia(e);e.hasAttribute("data-gl-placeholder")&&W(e)&&this.paint(e);let n=null,o=(e.getAttribute("data-gl")||"").trim().toLowerCase();if(!/^(shader|text|layer|video)$/.test(o)&&r?.tagName==="IMG"){let u=e.getAttribute("data-gl-src");(u||!r.parentElement?.querySelector("source"))&&(n=this.image(u||E(r),u?new URL(u,e.ownerDocument.baseURI).href:void 0,r))}let i=this.recipe(e);if(!i||!t.programs.prepare(i))return n;let a=await q(()=>i.program.ready()||i.program.failed,t);if(i.program.failed)return t.programs.failed(i,t.planes);i.texture=await n||null,a&&await this.draw(i)}async image(e,t=e,r){let n=this.stage,o=n.media.images,i=o.get(e)||o.get(t);if(i)return await q(()=>i.ready,n)?i:null;let a=new n.Texture(n.gl);n.renderer.reset(),o.set(e,a).set(t,a);let u=()=>o.forEach((f,c)=>f===a&&o.delete(c));try{let f=r?.getAttribute("sizes"),c=await n.bitmap(t,n.maxTexture,()=>n.media.cap(a.box,f&&f!=="auto"?w(f):0));if(await X(),n.lost||n.destroyed||o.get(e)!==a)return"close"in c&&c.close(),null;a.upload(c),"close"in c&&c.close(),n.renderer.reset(),n.stats.uploads++}catch(f){g.info("preload: image not loaded",t,f),u();for(let c of n.planes)c.texture===a&&(c.texture=null,c.textureState="none",n.loadMedia(c));return a.dispose(),null}for(let f of n.planes)f.texture===a&&(f.textureState="ready",f.resolveLoaded(),n.media.sharpen(f),n.markDirty());return setTimeout(()=>{a.refs||o.get(e)!==a||(u(),a.dispose())},$),a}recipe(e){let t=this.stage,r=t.host.lib,n=(e.getAttribute("data-gl")||"").trim().toLowerCase(),o=n==="shader"||n==="text"||n==="layer"?n:n==="video"||!n&&r.findMedia(e)?.tagName==="VIDEO"?"video":"image";if(o==="layer"||t.modulesOf(e).length)return null;let i=new t.Plane(e,o,-1,t),a=1,u="";for(let c of r.attr.list(e,"data-gl-effect")){let l=t.registry.effects.get(c);if(!l)return null;let d=l.play||"",v=t.readOptions(e,`data-gl-${c}`,d?{...T,...l.options||{}}:l.options||{});t.addUniforms(i,l.uniforms||{}),d&&!i.uniforms[d]&&t.addUniforms(i,{[d]:0}),t.optionUniforms(i,c,v),l.reduced&&t.reducedMotion&&t.addUniforms(i,l.reduced),a=Math.max(a,l.segments||1),u+=JSON.stringify([l.vertex,l.fragment]),i.effects.push({name:c,def:l,options:v,ctx:null})}if(o==="shader"){let c=e.getAttribute("data-gl-shader")||"",l=t.registry.shaders.get(c);if(!l)return null;let d=t.readOptions(e,"data-gl-shader",l.options||{});t.addUniforms(i,l.uniforms||{}),t.optionUniforms(i,"",d),u+=l.fragment+(l.head||""),i.shader={name:c,def:l,options:d,ctx:null}}let f=i.shader?.def.head?1:0;for(let{def:c}of i.effects)(c.vertex?.head||c.fragment?.head)&&f++;return i.glsl=f>1||u.includes("#include")||M.test(u)||L.test(u),i.usesVelocity=u.includes("uScrollVelocity"),i.usesTime=u.includes("uTime"),i.usesProgress=u.includes("uProgress"),i.usesGlyph=A.test(u),u.includes("uBackdrop")&&t.addUniforms(i,{uBackdrop:i.backdrop={texture:null}}),i.segments=a,i.glsl&&!t.programs.glsl||i.usesGlyph&&!t.text?null:i}fx(){return this.stage.loadFx()}async draw(e){let t=this.stage,r=await this.fx();if(!r||t.lost||!e.program?.ready()||!e.grid)return;let n=this.buf||=r.pool.acquire({width:4,height:4,type:"u8",msaa:0,attachments:1}),o=e.rect,i=o.slice();o[2]>0&&o[3]>0||o.set([0,0,4,4]),e.size[0]>0||e.size.set([o[2],o[3]]);try{r.into(n,o[0],o[1],o[2],o[3],()=>t.renderer.drawPlane(e,!0))}finally{o.set(i)}}async run(e,t){let r=0;this.runs++;let n=()=>{let o=++r/t.length;e.set?.(o),e.fn?.(o)};await Promise.all(t.map(o=>o.catch(()=>{}).then(n))),!--this.runs&&this.buf&&(this.stage.fx?.pool.release(this.buf),this.buf=null)}hover(e){this.Va?.();let t=this.Va=e?C(typeof e=="string"?e:"a[href]",r=>this.run({},this.collect(r)),$):null;return t&&(()=>this.Va===t&&this.hover(!1))}};function F(s,e){let t=new DOMParser().parseFromString(s,"text/html");if(!t.querySelector("base")){let r=t.createElement("base");r.href=e,t.head.prepend(r)}return t}function q(s,e){let t=performance.now();return new Promise(r=>{let n=()=>s()?r(!0):e.destroyed||performance.now()-t>j?r(!1):setTimeout(n,30);n()})}function pe(s){return _(s.host.log),new P(s)}export{$ as KEEP_MS,P as Warm,W as ahead,pe as warm};
|
|
1
|
+
/*! Umber v0.4.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
var e=()=>{};var t=()=>Promise.reject(new Error("no words"));var r={configure:e,debug:!1,warnings:!1,info:e,warn:e,error:e,report:e,words:t},n=r;function i(e){n=e}var a="model",l=e=>e===a?"layer":e;var s=e=>(e>3?192:96)*2**20;function o(e,t,r=navigator.deviceMemory??5,n=""){let i=e>3&&!t?Math.min(4,Math.max(1,r/2)):1;return s(e)*(u.test(n)?Math.max(1,i/2):i)}var u=/intel(?!.*arc\(tm\) [ab]\d)|radeon(?!.*\b(rx|r9|pro)\b)/i;var h=(e,t)=>e[t]??NaN;var c=e=>t=>Math.pow(t,e),d={quad:c(2),cubic:c(3),quart:c(4),quint:c(5),sine:e=>1-Math.cos(e*Math.PI/2),expo:e=>e===0?0:Math.pow(2,10*e-10),circ:e=>1-Math.sqrt(1-e*e)};var g="umber";var f={duration:1.4,delay:0,ease:g,start:"top 90%",trigger:"auto",repeat:"",hide:!0};function m(e){let t=[],r=e??"",n=/[\s,]*(\S+)([^,]*)/g;for(let e=n.exec(r);e;e=n.exec(r)){let[r,i,a=""]=e;if(!i)break;let l=i.replace(/,+$/,"");l!==i&&(n.lastIndex=e.index+r.indexOf(i)+i.length),t.push([l,l!==i?"1x":a.trim()||"1x"])}return t}function p(e){let t=/^calc\((.+)\)$/.exec(e)?.[1];if(t!==void 0){let[e="",...r]=t.trim().split(/\s+([+-])\s+/),n=p(e);for(let e=0;e<r.length;e+=2)n+=(r[e]==="-"?-1:1)*p(r[e+1]??"");return n}let r=/^([\d.]+)(vw|px|r?em)$/.exec(e);if(!r)return innerWidth;let[,n="",i]=r,a=Number(n);return i==="vw"?innerWidth*a/100:i==="px"?a:a*16}function b(e){for(let t of v(e)){let e=w(t),r=e>0?t.slice(0,e):"";if(t&&(!r||matchMedia(r).matches))return p(t.slice(e+1))}return innerWidth}function v(e){let t=[],r=0,n=0;for(let i=0;i<=e.length;i++){let a=e.charAt(i);a==="("?r++:a===")"?r--:!r&&(a===","||i===e.length)&&(t.push(e.slice(n,i).trim()),n=i+1)}return t}function w(e){let t=-1;for(let r=0,n=0;r<e.length;r++){let i=e.charAt(r);i==="("?n++:i===")"?n--:!n&&/\s/.test(i)&&(t=r)}return t}function x(e){let t=e.ownerDocument.baseURI||document.baseURI,r=e=>e?new URL(e,t).href:"",n=m(e.getAttribute("srcset")).map(([e,t])=>({url:e,size:parseFloat(t)||1,width:t.endsWith("w")})),i=e.getAttribute("src");i&&!n.some(e=>e.width||e.size===1)&&n.push({url:i,size:1,width:!1});let[a]=n;if(!a)return"";let l=window.devicePixelRatio||1,s=l;return a.width&&(s=b(e.getAttribute("sizes")??"")*l),n.sort((e,t)=>e.size-t.size),r((n.find(e=>e.size>=s)??n.at(-1)??a).url)}function y(e){if(!e.href||e.hasAttribute("download")||e.target&&e.target!=="_self")return"";let t=new URL(e.href,location.href);t.hash="";let r=new URL(location.href);return r.hash="",t.origin===location.origin&&t.href!==r.href&&/^https?:$/.test(t.protocol)?t.href:""}function M(e,t,r=0){let n=navigator.connection;if(n?.saveData||(n?.effectiveType??"").includes("2g"))return()=>{};let i=new Set,a=null,l,s=0,o=0,u=0,h=()=>{let e=a?y(a):"";if(e&&!i.has(e)){i.add(e);let n=()=>r&&setTimeout(()=>i.delete(e),r);Promise.resolve(t(e)).then(n,n)}},c=()=>{clearTimeout(l),l=setTimeout(h,65)},d=t=>{let r=t,n=r.target.closest(e),i=n instanceof HTMLAnchorElement||n instanceof HTMLAreaElement?n:null;i!==a&&(clearTimeout(l),a=i,a&&(s=r.clientX,o=r.clientY,u=r.timeStamp,r.pointerType&&r.pointerType!=="mouse"?h():c()))},g=e=>{let t=e,r=t.timeStamp-u;if(!a||r<=0)return;let n=Math.hypot(t.clientX-s,t.clientY-o)/r>.5;s=t.clientX,o=t.clientY,u=t.timeStamp,n&&c()},f=e=>{e.relatedTarget||(clearTimeout(l),a=null)},m={passive:!0};return document.addEventListener("pointerover",d,m),document.addEventListener("pointermove",g,m),document.addEventListener("pointerout",f,m),()=>{clearTimeout(l),document.removeEventListener("pointerover",d),document.removeEventListener("pointermove",g),document.removeEventListener("pointerout",f)}}var k=6;function z(e,t,r){let n=[t-1<<4|r-1],i=-1;for(let a=0;a<t*r*4;a++){if((a&3)===3)continue;let t=Math.round(h(e,a)/17);i<0?i=t:(n.push(i<<4|t),i=-1)}return i>=0&&n.push(i<<4),btoa(String.fromCharCode(...n)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function A(e){let t;try{t=atob(e.trim().replace(/-/g,"+").replace(/_/g,"/"))}catch{return null}let r=(t.charCodeAt(0)>>4)+1,n=(t.charCodeAt(0)&15)+1;if(!t||t.length<1+Math.ceil(r*n*3/2))return null;let i=new Uint8ClampedArray(r*n*4);for(let e=0,r=0;e<i.length;e++)if((e&3)===3)i[e]=255;else{let n=t.charCodeAt(1+(r>>1));i[e]=(r++&1?n&15:n>>4)*17}return{w:r,h:n,data:i}}function S(e){let t=A(e);if(!t)return"";let r=document.createElement("canvas");return r.width=t.w,r.height=t.h,r.getContext("2d")?.putImageData(new ImageData(t.data,t.w,t.h),0,0),r.toDataURL()}var T=()=>{let e=typeof window<"u"?window.occluzeCapture:void 0;return e?.version===1?e:null},E=()=>new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=e,t.port2.postMessage(0)});var I=2e4,L=8e3,R=/^data:image\/|\.(avif|webp|jpe?g|png|gif|svg)([?#]|$)/i,P=()=>T()?E():new Promise(e=>"requestIdleCallback"in window?requestIdleCallback(()=>{e()},{timeout:300}):setTimeout(e,16)),U=e=>e.ownerDocument!==document||!e.isConnected,C=class{constructor(e){this.stage=e;this.buf=null;this.runs=0;this.mj=null;e.env.cleanups.push(()=>this.hover(!1))}Hj(){let{media:e,tier:t}=this.stage.gpu,r=/[?&]umber-gpu-budget=(\d+)/.exec(location.search),n=this.stage.env.host;t.textureBudget=r?+(r[1]??0)*2**20:Math.max(t.textureBudget,o(t.level,n.env.isTouch,void 0,t.renderer));let i=e.Ea.bind(e);e.Ea=()=>{this.room()<0&&this.trim(),i()}}wb(e,t){let r=this.stage,n=r.env.frame,i=n.scrollX+n.screen.width/2,a=n.scrollY+n.screen.height/2,l=e=>Math.abs(e.doc.x+e.doc.w/2-i)+Math.abs(e.doc.y+e.doc.h/2-a)+(e.zone.near?0:1e9),s=r.planes.all.filter(e=>e.kind==="image"&&!e.zone.soon&&!e.zone.screen&&e.texture?.ready).sort((e,t)=>l(t)-l(e));for(let n of s){if(e<=t)break;let i=n.texture?.bytes??0;r.gpu.media.release(n)&&(e-=i),n.textureState!=="error"&&(n.textureState="none"),n.status!=="error"&&(n.setStatus(null),n.wait())}return e}preload(e){let t=e.what;return t&&typeof t=="object"&&"hover"in t?this.hover(t.hover):this.run(e,this.collect(t))}warm(e){let t=this.stage,r=e.what,n=typeof r=="string"?document.querySelector(r):r;return this.run(e,t.planes.list().filter(e=>e.kind!=="layer"&&e.status!=="error"&&(!n||n.contains(e.el))).map(e=>this.fx().then(t=>t?.Bf(e).then(t=>t?this.draw(e):void 0))))}pick(e){return x(e)}async placeholder(e){let t=this.stage,r=typeof e=="string"?null:e,n=r&&(this.stage.env.lib.findMedia(r)??r),i=typeof e=="string"?e:n&&(n.currentSrc||x(n));if(!i)return null;try{let e=await t.env.kit.bitmap(i,t.gpu.tier.maxTexture),r=k/Math.max(e.width,e.height),n=Math.max(1,Math.round(e.width*r)),a=Math.max(1,Math.round(e.height*r)),l=await createImageBitmap(e,{resizeWidth:n,resizeHeight:a,resizeQuality:"high"});"close"in e&&e.close();let s=document.createElement("canvas");s.width=n,s.height=a;let o=s.getContext("2d");return o?(o.drawImage(l,0,0),l.close(),z(o.getImageData(0,0,n,a).data,n,a)):null}catch(e){return this.stage.env.lib.say("placeholderRead",[i],e),null}}paint(e){let t=this.stage.env.lib.findMedia(e),r=e.getAttribute("data-umber-placeholder")??"";if(t?.tagName!=="IMG"||t.complete&&t.naturalWidth||t.style.backgroundImage)return;let n=S(r);if(!n){this.stage.env.lib.say("placeholder",[r],e);return}let i=t.style;i.backgroundImage=`url(${n})`,i.backgroundSize="cover",i.backgroundPosition="center";let a=()=>{i.backgroundImage="",i.backgroundSize="",i.backgroundPosition=""};t.addEventListener("load",a,{once:!0})}note(e,t){let r=this.stage,[n=0,i=0,a=0,l=0]=t;if(e){r.env.lib.say("imageSize",[e,a,l,r.gpu.tier.maxTexture]);return}let s=r.planes.all.filter(e=>e.texture?.ready).sort((e,t)=>(t.texture?.bytes??0)-(e.texture?.bytes??0));r.env.lib.say("imageBudget",[n>>20,i>>20,r.gpu.tier.textureBudget>>20,s.slice(0,3).map(e=>`${r.env.lib.describe(e.el)} (${e.texture?.width??0}x${e.texture?.height??0})`)])}collect(e,t=[]){return this.gather(e,t),t}gather(e,t){if(e){if(typeof e=="string"||e instanceof URL)t.push(this.address(new URL(String(e),document.baseURI).href));else if(Array.isArray(e)||e instanceof NodeList)for(let r of e)this.gather(r,t);else if(typeof e=="object"&&"querySelectorAll"in e)this.Qi(e,t);else if(typeof e=="object"){let r=e,n=typeof r.url=="object"?r.url.href:r.url;this.gather(r.container??(r.html?$(r.html,document.baseURI):void 0)??n,t)}}}address(e){return R.test(e)?this.image(e):this.page(e).then(e=>e&&this.run({},this.collect(e)))}Qi(e,t){let r=this.stage.env.lib,n=0;for(let i of r.findGL(e)){let e=this.xe(i,r.findMedia(i));t.push(this.element(i,n<1?e:null)),e&&(n+=j(e))}}page(e){return fetch(e,{credentials:"same-origin"}).then(e=>e.ok?e.text():"").then(t=>t?$(t,e):null).catch(t=>(n.info("preload: page not fetched",e,t),null))}async element(e,t){let r=this.stage;e.hasAttribute("data-umber-placeholder")&&U(e)&&this.paint(e);let n=t&&this.wd(e,t),i=this.recipe(e);if(!i||!r.gpu.programs.prepare(i))return n;let a=i.program;if(!a)return n;let l=await q(()=>a.ready()||a.failed,r);if(a.failed){r.gpu.programs.failed(i,r.planes.all);return}i.texture=await n??null,l&&await this.draw(i)}ba(e){for(let t of this.stage.planes.all)t.texture===e&&(t.texture=null,t.textureState="none",this.stage.factory.load(t));e.dispose()}xe(e,t){return/^(shader|text|layer|video)$/.test(this.stage.env.lib.kindOf(e))||t?.tagName!=="IMG"?null:e.getAttribute("data-umber-src")||!t.parentElement?.querySelector("source")?t:null}wd(e,t){let r=e.getAttribute("data-umber-src");return this.image((r??"")||x(t),r?new URL(r,e.ownerDocument.baseURI).href:void 0,t)}async image(e,t=e,r){let i=this.stage,a=i.gpu.media.images,l=a.get(e)??a.get(t);if(l)return await q(()=>l.ready,i)?l:null;if(this.room()<=0)return null;let s=new i.env.kit.Texture(i.gpu.gl);i.gpu.renderer.reset(),a.set(e,s).set(t,s);let o=()=>{for(let[e,t]of a)t===s&&a.delete(e)};try{let n=r?.getAttribute("sizes"),l=await i.env.kit.bitmap(t,i.gpu.tier.maxTexture,()=>i.gpu.media.cap(s.box,n&&n!=="auto"?b(n):0));if(await P(),i.gpu.context.gone||i.env.destroyed||a.get(e)!==s)return"close"in l&&l.close(),null;if(this.room()<l.width*l.height*16/3)throw"close"in l&&l.close(),new Error("over the GPU memory budget");s.upload(l),"close"in l&&l.close(),i.gpu.renderer.reset(),i.env.stats.uploads++}catch(e){return n.info("preload: image not loaded",t,e),o(),this.ba(s),null}for(let e of i.planes.all)e.texture===s&&(e.textureState="ready",e._o(),i.gpu.media.sharpen(e),i.scheduler.markDirty());return setTimeout(()=>{s.refs||a.get(e)!==s||(o(),s.dispose())},I),s}room(){let e=this.stage,t=e.gpu.media.vc+(e.chunks.fx?.pool.bytes??0)+(e.chunks.video?.Kl()??0);for(let r of e.planes.all)r.texture?.refs||(t+=r.texture?.bytes??0);return e.gpu.tier.textureBudget-t}trim(){let e=this.stage.gpu.media.images;for(let[t,r]of e)r.refs||!r.ready&&r.texture||(e.delete(t),r.dispose())}recipe(e){let t=this.stage,r=this.al(e);if(r==="layer"||t.factory.zb(e).length)return null;let n=new t.env.kit.Plane(e,r,t),i=this.Rg(n,e);if(i===null)return null;let a=r==="shader"?this.Kf(n,e):"";if(a===null)return null;let l=i+a;return n._R(l),l.includes("uBackdrop")&&(n.backdrop={texture:null},t.factory.th(n,{uBackdrop:n.backdrop})),n.glsl&&!t.gpu.programs.glsl||(n._z||r==="text")&&!t.chunks.text||n._z&&!t.chunks.text?.yk.chunk?null:n}al(e){return l(this.stage.env.lib.kindOf(e)||"image")}Rg(e,t){let r=this.stage,n="";for(let i of this.stage.env.lib.attr.list(t,"data-umber-effect")){let a=r.env.registry.effects.get(i);if(!a)return null;let l=a.play??"",s=a.options??{},o=r.env.lib.config(t,`data-umber-${i}`,l?{...f,...s}:s);r.factory.th(e,a.uniforms??{}),l&&!e._r(l)&&r.factory.th(e,{[l]:0}),r.factory.wh(e,i,o),a.reduced&&r.env.reducedMotion&&r.factory.th(e,a.reduced),e.segments=Math.max(e.segments,a.segments??1),n+=JSON.stringify([a.vertex,a.fragment]),e.effects.push({name:i,def:a,options:o,ctx:null})}return n}Kf(e,t){let r=this.stage,n=t.getAttribute("data-umber-shader")??"",i=r.env.registry.shaders.get(n);if(!i)return null;let a=r.env.lib.config(t,"data-umber-shader",i.options??{});return r.factory.th(e,i.uniforms??{}),r.factory.wh(e,"",a),e.shader={name:n,def:i,options:a,ctx:null},i.fragment+(i.head??"")}fx(){return this.stage.chunks.loadFx()}async draw(e){let t=this.stage,r=await this.fx();if(!r||t.gpu.context.gone||!e.program?.ready()||!e.grid)return;let n=this.buf??=r.pool.acquire({width:4,height:4,type:"u8",msaa:0,attachments:1}),i=e.rect,a=i.slice();i[2]>0&&i[3]>0||i.set([0,0,4,4]),e.size[0]>0||e.size.set([i[2],i[3]]);try{r.into(n,i,()=>{t.gpu.renderer.drawPlane(e,!0)})}finally{i.set(a)}}async run(e,t){let r=0;this.runs++;let n=()=>{let n=++r/t.length;e.set?.(n),e.fn?.(n)};await Promise.all(t.map(e=>e.catch(()=>{}).then(n))),! --this.runs&&this.buf&&(this.stage.chunks.fx?.pool.release(this.buf),this.buf=null)}hover(e){this.mj?.();let t=this.mj=e?M(typeof e=="string"?e:"a[href]",e=>this.run({},this.collect(e)),I):null;return t&&(()=>{this.mj===t&&this.hover(!1)})}};function j(e){let t=e.getAttribute("sizes"),r=Math.min(t&&t!=="auto"?b(t):innerWidth,innerWidth),n=r*Number(e.getAttribute("height"))/Number(e.getAttribute("width"));return r*(n>0?Math.min(n,innerHeight):innerHeight)/(innerWidth*innerHeight)}function $(e,t){let r=(new DOMParser).parseFromString(e,"text/html");if(!r.querySelector("base")){let e=r.createElement("base");e.href=t,r.head.prepend(e)}return r}function q(e,t){let r=performance.now();return new Promise(n=>{let i=()=>{e()?n(!0):t.env.destroyed||performance.now()-r>L?n(!1):setTimeout(i,30)};i()})}function D(e){i(e.env.host.log);let t=new C(e);return t.Hj(),t}export{I as KEEP_MS,C as Warm,U as ahead,D as warm};
|