@occluze/umber 0.2.0 → 0.3.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 +78 -48
- 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/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/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/patch.js +2 -0
- package/dist/chunks/prepared.js +2 -0
- package/dist/chunks/profiler.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/views.js +2 -2
- package/dist/chunks/vocabulary.js +2 -0
- package/dist/chunks/warm.js +2 -2
- package/dist/frameworks/astro.mjs +2 -0
- package/dist/frameworks/react.mjs +2 -0
- package/dist/frameworks/svelte.mjs +2 -0
- package/dist/frameworks/vue.mjs +2 -0
- 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/router-swap.js +2 -13
- package/dist/modules/router.js +2 -2
- package/dist/modules/router.mjs +2 -2
- package/dist/modules/scroll-more.js +2 -0
- package/dist/modules/scroll-touch.js +2 -0
- package/dist/modules/scroll.js +2 -2
- package/dist/modules/scroll.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 +9 -0
- package/dist/node/astro.mjs +47 -0
- package/dist/node/cli.mjs +109 -0
- package/dist/node/shared-3Q24RNIF.mjs +602 -0
- package/dist/node/shared-4FIU6DYP.mjs +200 -0
- package/dist/node/vite.mjs +10 -0
- package/dist/umber.css +2 -2
- package/dist/umber.js +2 -2
- package/dist/umber.mjs +2 -2
- package/docs/AI-quick.md +240 -0
- package/docs/AI.md +3130 -0
- package/docs/npm.md +37 -26
- package/package.json +183 -12
- package/types/assets.d.ts +87 -0
- package/types/astro.d.ts +43 -0
- package/types/debug.d.ts +17 -16
- package/types/esm.d.ts +12 -12
- 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 +75 -0
- package/types/module.d.ts +108 -0
- package/types/react.d.ts +15 -0
- package/types/router.d.ts +87 -45
- package/types/scroll.d.ts +96 -38
- package/types/scrollfx.d.ts +80 -0
- package/types/scrub.d.ts +33 -32
- package/types/svelte.d.ts +16 -0
- package/types/three.d.ts +226 -0
- package/types/umber.d.ts +633 -357
- package/types/vite.d.ts +33 -0
- package/types/vue.d.ts +14 -0
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.3.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 a=class{constructor(t=60){this.hz=t;this.ta=0;this.Qa=!1}advance(t){this.ta+=t>0?t:0;let e=Math.floor(this.ta*this.hz+.5);return e>4?(e=4,this.ta=0):!e&&this.Qa?(e=1,this.ta=0):this.ta-=e/this.hz,this.Qa=!1,e}due(){this.Qa=!0,this.ta=Math.min(this.ta,0)}},o=1/255;function h(t){return t<=0?1:t>=1?1/0:Math.ceil(Math.log(o)/Math.log(t))}function n(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 n(i,s)}return t!=null&&t>0?t:s}var u=16,f=/^[A-Za-z_]\w*$/;function m(t){return Array.isArray(t.passes)?t.passes:typeof t.next=="string"?[{into:null,next:t.next}]:null}var p=(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.na=[];this.passes=[];this.yb=[];this.brushes=[];this.steps=0;this.idle=0;this.awake=!1;this.released=!1;this.ok=!1;this.aspect=0;this.clock=new a(Math.max(1,n(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.af(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:p(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.yb.push({field:t,source:t.init,program:null});this.pointer=this.passes.some(t=>/\buPointer\b/.test(t.source)),this.own=!!this.yb.length||e.settle===!1||this.passes.some(t=>/\bu(Time|Step)\b/.test(t.source)),this.compile(),this.start()}af(t,e,s){let i=e.type??this.options.type??"half",r={...this.dims(e.size,s),type:i,msaa:0,attachments:1,quiet:!0},a=this.sims.fx,o={name:t,read:a.make(r),write:a.make(r),size:e.size,init:e.init,type:i,holder:{get texture(){return o.read.texture}}};this.fields.set(t,o),this.na.push(o.holder),this.uniforms[t]=o.holder}dims(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 a=this.options.shape==="square"?r:Math.min(i,Math.max(1,Math.round(r*this.aspect)));return{width:r,height:a}}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.yb)s.program=t.program(p(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.yb)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.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||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.Rb)return!0;for(let t of this.na)if(t.Rb)return!0;let t=this.sims.fx.stage,e=this.sims.ya===this?t.chunks.flow:null,s=!1;for(let i of t.planes.all){let t=i.zone.soon||i.visible;if(i.layer&&t)return!0;if(this.ih(i.uniforms,e)){if(t)return!0;s=!0}}return!s}ih(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.na)if(e===t)return!0;return!1}release(){let t=this.sims;if(!this.released){if(t.ya===this){if(t.fx.stage.planes.all.some(t=>"uFlow"in t.uniforms))return;t.ya=null,t.$b=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,a=e.color??[1,1,1,1];this.uniforms={[i.name]:i.holder,uStamps:this.stamps,uCount:0,uBrushRadius:Math.max(.5,n(e.radius,24)),uColor:new Float32Array([n(a[0],0),n(a[1],0),n(a[2],0),a[3]??1]),uMotion:n(e.motion,0),uView:new Float32Array([r.width,r.height]),uMix:e.mode==="mix"?1:0},this.source=p(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,a=this.stamps,o=this.count++*4;return a[o]=t/r.width,a[o+1]=e/r.height,a[o+2]=s,a[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,a=e-i,o=Math.min(u-this.count,Math.max(1,Math.ceil(Math.hypot(r,a)/(this.uniforms.uBrushRadius*.5))));for(let t=1;t<=o;t++)this.paint(s+r*t/o,i+a*t/o,r/o,a/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,M=class{constructor(t){this.fx=t;this.list=new Set;this.ya=null;this.$b=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?m(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.ya===null)return this.Bg(t,e);let s=this.ya;if(!s)return null;t.fade!=null&&(s.uniforms.uFade=e);let i=this.$b;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}Bg(t,e){let s=this.fx.stage.canvasHost.viewport.width,i=t.radius??s*.08,r=[{into:"push",next:b},{into:"flow",next:y}],a=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>=h(t.uniforms.uFade)+2},r,{quiet:!0});return a.type==="u8"?(a.release(),this.ya=!1,this.Th(e,i/s),null):(this.ya=a,this.$b=a.brush({field:"push",radius:i,motion:t.motion??.04}),this.patch(()=>a.texture),a)}Th(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 F(t){return r(t.stage.env.host.log),new M(t)}export{w as Brush,v as Sim,M as Sims,F 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.3.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 n(t){r=t}var s=(t,e)=>t[e]??NaN;var a=t=>t;var l=(...t)=>t.find(t=>!!t)??0;function h(t){let e=t;return[l(e.displayWidth,e.videoWidth,e.naturalWidth,e.width),l(e.displayHeight,e.videoHeight,e.naturalHeight,e.height)]}var o=t=>t instanceof HTMLVideoElement||"displayWidth"in t,u=class{constructor(t){this.gl=t;this.width=1;this.height=1;this.ready=!1;this.packed=0;this.ua=1;this.refs=0;this.box=[];this.mipmaps=!1;this.texture=a(t.createTexture()),t.bindTexture(t.TEXTURE_2D,this.texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array(4)),this.params(!1)}params(t){let e=this.gl;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,t?e.LINEAR_MIPMAP_LINEAR:e.LINEAR)}get bytes(){return this.ready?this.packed||this.width*this.height*4*(this.mipmaps?4/3:1):0}adopt(t,e){this.texture!==t&&this.gl.deleteTexture(this.texture),this.texture=t,this.width=e.width,this.height=e.height,this.packed=e.bytes,this.mipmaps=e.mipmaps,this.ua=1,this.ready=!0}upload(t,e={}){let i=this.gl,r=e.mipmaps??!o(t),[n,s]=h(t);return!n||!s||!this.texture||this.packed&&(i.deleteTexture(this.texture),this.texture=a(i.createTexture()),this.packed=0,this.ua=1,this.ready=!1,!this.texture)?!1:(i.bindTexture(i.TEXTURE_2D,this.texture),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!1),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!e.straight),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.BROWSER_DEFAULT_WEBGL),this.ready&&n===this.width&&s===this.height&&(!r||this.mipmaps)?i.texSubImage2D(i.TEXTURE_2D,0,0,0,i.RGBA,i.UNSIGNED_BYTE,t):i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r&&i.generateMipmap(i.TEXTURE_2D),(r!==this.mipmaps||!this.ready)&&this.params(r),this.mipmaps=r,this.width=n,this.height=s,this.ready=!0,!0)}angle(t){t===this.ua||!this.mipmaps||!this.ready||(this.ua=t,this.gl.texParameterf(this.gl.TEXTURE_2D,d,t))}dispose(){this.texture&&this.gl.deleteTexture(this.texture),this.texture=null,this.ready=!1}},d=34046;var c=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 f=new RegExp("\\p{Extended_Pictographic}|\\p{Regional_Indicator}","u"),p=t=>Math.ceil(t/4)*4,g=class{constructor(t,e){this.gl=t;this.color=e;this.texture=null;this.size=0;this.Kb=[];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.Kb=[],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.Kb)r.h>=e&&r.h<=e*1.5+4&&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.Kb.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.Kb=[],this.bottom=0}forget(){this.texture=null,this.size=0}};function x(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,n=0,s=0,a=1]=i;return[r/255,n/255,s/255,a]}var m=new Map,y;function w(t){let e=m.get(t)??x(t);if(e)return e;if(y??=document.createElement("canvas").getContext("2d",{willReadFrequently:!0}),e=[0,0,0,1],y){y.clearRect(0,0,1,1),y.fillStyle=t,y.fillRect(0,0,1,1);let[i=0,r=0,n=0,s=255]=y.getImageData(0,0,1,1).data;e=[i/255,r/255,n/255,s/255]}return m.set(t,e),e}var b=([t,e,i])=>`rgb(${Math.round(t*255)}, ${Math.round(e*255)}, ${Math.round(i*255)})`,v=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/;function T(t,e){let i=[];if(e||v.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 E(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 M=2048;function S(t){let e=[],i=0,r=0,n=0,s=1;for(let a of t)i&&i+a.w>M&&(i=0,r+=n,n=0),e.push([i,r]),i+=a.w,n=Math.max(n,a.h),s=Math.max(s,i);return{spots:e,width:s,height:Math.max(1,r+n)}}function R(t,e,i,[r,n]){let s=t.page?4:1,a=new Uint8Array(t.w*t.h*s);for(let l=0;l<t.h;l++){let h=((n+l)*i+r)*4;for(let i=0;i<t.w;i++){let r=h+i*4,n=e[r+3]??0,o=(l*t.w+i)*s;if(s===1){a[o]=n;continue}for(let t=0;t<3;t++)a[o+t]=(e[r+t]??0)*n/255;a[o+3]=n}}return a}var _=2e3,k=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.Fc=!1;this.canvas=null;this.ctx=null;this.mono=new g(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 n=this.Vg(i);if(!n)return null;let s=[];for(let a of t){E(n,a);let t={fill:a,rgba:w(a.color),scale:e,smoothing:i.join(",")};if(!this.eh(n,t,r,s))return this.release(s),this.flush(),null}return this.flush(),s}eh(t,e,i,r){let{fill:n}=e,s=n.rtl||n.caps!=="normal"?null:i?.fonts.find(n.font);for(let[a,l]of T(n.text,n.rtl)){let h=a?t.measureText(n.text.slice(0,a)).width:0,o=s&&i?.draw?i.fonts.word(t,s,e,{text:l,advance:h}):null;if(o){r.push(...o);continue}let u=this.word(t,e,l,h);if(!u)return!1;r.push(u)}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:n,rgba:s,scale:a}=e,l=(n.x+r)*a,h=n.y*a,o=Math.floor(l),u=Math.floor(h),d=Math.round((l-o)*64)/64,c=Math.round((h-u)*16)/16,p=f.test(i),g={text:i,font:n.font,letterSpacing:n.letterSpacing,wordSpacing:n.wordSpacing,kerning:n.kerning,caps:n.caps,rtl:n.rtl,color:p?n.color:b(s),scale:a},x=[i,g.font,g.letterSpacing,g.wordSpacing,g.kerning,g.caps,g.rtl,g.color,a,d,c,e.smoothing].join("\x01"),m=this.entries.get(x)??this.make(t,{key:x,paint:g,page:p?1:0,fx:d,fy:c});if(!m)return null;m.refs++;let y=s[3]*n.alpha;return{entry:m,x:o-Math.floor(m.ox),y:u-Math.floor(m.oy),tint:p?[1,1,1,y]:[s[0],s[1],s[2],y]}}make(t,{key:e,paint:i,page:r,fx:n,fy:s}){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),f=o(a.actualBoundingBoxDescent??l*.4),g=4,x=g+u,m=g+c,y={key:e,page:r,x:0,y:0,w:p(x+d+g),h:p(m+f+g),ox:x+n,oy:m+s,ink:[g-1,g-1,x+d+1,m+f+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.pageOf(t.page);e.texture||e.open(1024);let i=Math.max(1024,Math.min(4096,this.maxTexture));if(t.w>i||t.h>i)return!1;let r=e.pack(t.w,t.h),n=e.size,s=!1;for(;!r;){let a=this.Kf(t.page)>this.live(t.page).length;if(s||!a){if(n>=i)return!1;n=Math.min(i,n*2)}s=!0,this.qh(t.page,n),r=e.pack(t.w,t.h)}return[t.x,t.y]=r,!0}pageOf(t){return t?this.color??=new g(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)))}Kf(t){let e=0;for(let i of this.entries.values())i.page===t&&e++;return e}qh(t,e){let i=this.pageOf(t),r=this.live(t).sort((t,e)=>e.h-t.h),n=new Set(r),s=new Set(this.fresh);for(let[e,i]of this.entries)i.page===t&&!n.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,s.has(t)||this.fresh.push(t)}this.Fc=!0}Vg(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;e.isConnected||this.host.appendChild(e);let[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)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)<=M;)r+=t[i++]?.h??0;this.paint(t.slice(e,i)),e=i}if(this.Fc){this.Fc=!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:n,width:s,height:a}=S(t);(i.width<s||i.height<a)&&(i.width=Math.max(i.width,s),i.height=Math.max(i.height,a)),e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,s,a),t.forEach((t,i)=>{let[r=0,s=0]=n[i]??[];E(e,t.paint),e.fillStyle=t.paint.color,e.globalAlpha=1,e.setTransform(t.paint.scale,0,0,t.paint.scale,r+t.ox,s+t.oy),e.fillText(t.paint.text,0,0)}),e.setTransform(1,0,0,1,0,0);let l=e.getImageData(0,0,s,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.pageOf(t.page),a=n[e];if(!i.texture||!a)return;r.bindTexture(r.TEXTURE_2D,i.texture);let o=i.color?r.RGBA:r.RED,u=R(t,l,s,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.Ja),this.Ja=setTimeout(()=>{i.width=1,i.height=1},_)}lost(){this.mono.forget(),this.color?.forget(),this.entries.clear(),this.fresh=[],this.users.clear()}};function A(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"),n=/\b(italic|oblique)\b/.test(i)?"italic":"normal";return{keys:(e[2]??"").split(",").map(t=>t.trim().replace(/^["']|["']$/g,"").toLowerCase()).map(t=>`${t}|${r}|${n}`),px:Number(e[1])}}var U=class{constructor(t,e){this.gl=t;this.arrived=e;this.chunk=null;this.tables=null;this.manifest=null;this.loading=null;this.loaded=new Map;this.asked=new Set;this.loadChunk=()=>import(new URL("./curves.js",import.meta.url).href)}find(t){let{keys:e,px:i}=A(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}Dg(){return this.manifest??=(async()=>{let t=document.querySelector('meta[name="umber-assets"]')?.content;if(!t)return null;let e=new URL(t,document.baseURI),i=await fetch(e.href,{credentials:"same-origin"}),r=i.ok?await i.json():null;return r?.v===1&&r.fonts?{url:e,fonts:r.fonts}:null})().catch(()=>null),this.manifest}async fetch(t){try{let e=await this.Dg(),i=e?.fonts[t];if(!e||!i){this.loaded.set(t,null);return}this.loading??=this.loadChunk();let r=fetch(new URL(`${i}.glyphs`,e.url).href,{credentials:"same-origin"}).then(t=>{if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.arrayBuffer()}),[n,s]=await Promise.all([this.loading,r]),a=!this.tables;this.chunk=n,this.tables??=new n.CurveTables(this.gl),this.loaded.set(t,this.tables.add(s)),this.arrived(a)}catch{this.loaded.set(t,null)}}};var L=4,C=32,F=4,P=2,D=1024;function B(t,e,i){for(let r=C;r>=F;r/=2){let n=I(t,e,i,r);if(n)return G(t,[e,i,r],n)}return null}function I(t,e,i,r){let n=Math.max(1,Math.ceil(e/r)),s=Math.max(1,Math.ceil(i/r)),a=Array.from({length:n*s},()=>[]);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-P)/r)),f=Math.max(0,Math.floor((h+o-P)/r)),p=Math.min(n-1,Math.floor((l+u+P-1)/r)),g=Math.min(s-1,Math.floor((h+d+P-1)/r));for(let t=f;t<=g;t++)for(let i=c;i<=p;i++){let r=a[t*n+i];if(r){if(r.length>=L)return null;r.push(e+1)}}}return{across:n,cells:a}}function G(t,[e,i,r],{across:n,cells:s}){let a=2+3*t.length,l=a+s.length,h=Math.min(D,l),o=Math.ceil(l/h),u=new Float32Array(h*o*4);return u.set([e,i,n,r,2,a,0,0],0),t.forEach(({entry:t,x:e,y:i,tint:r},n)=>{let s=(2+3*n)*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],s)}),s.forEach((t,e)=>{u.set(t,(a+e)*4)}),{data:u,width:h,height:o}}var N=class extends u{constructor(t,e){super(t);this.atlas=e;this.eb=[];this.texture&&t.deleteTexture(this.texture),this.texture=e.texture(0),this.layout=new c(t,"float"),e.users.add(this)}get Ff(){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}show(t,e,i){let r=B(t,e,i);return r?(this.atlas.release(this.eb),this.eb=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,!0):(this.atlas.release(t),!1)}refresh(){if(this.texture=this.atlas.texture(0),!this.ready)return;let t=B(this.eb,this.width,this.height);t&&this.layout.upload(t.width,t.height,t.data)}dispose(){this.atlas.release(this.eb),this.eb=[],this.atlas.users.delete(this),this.layout.dispose(),this.texture=null,this.ready=!1}},W={used:/\bumberText\s*\(/,defined:/\bvec4\s+umberText\s*\(\s*vec2\s+\w+\s*\)\s*\{/,code:X("float umberCurveGlyph(vec2 l,vec4 a,vec2 p){return 0.0;}")};function z(t){W.code=X(t)}function X(t){return t+`uniform highp sampler2D uUmberTextLayout;\nuniform sampler2D uUmberTextColor;\nvec4 umberTextRow(highp int i){\nhighp int w=textureSize(uUmberTextLayout,0).x;\nreturn texelFetch(uUmberTextLayout,ivec2(i%w,i/w),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 $=["color","opacity","font","letterSpacing","wordSpacing","textTransform"];function H(t,e){let i=e.length!==t.length*$.length,r=0;for(let n of t)for(let t of $)e[r]!==n[t]&&(e[r]=n[t],i=!0),r++;return i}var V=t=>(t??"").replace(/--[\w-]+\s*:[^;]*;?/g,"").replace(/\s/g,""),O=/opacity|transform|translate|rotate|scale|filter|clip|visibility/;function K(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 n=e.transitionProperty;if(n?O.test(n):i.getKeyframes().some(t=>Object.keys(t).some(t=>O.test(t))))return!0}return!1}var j={used:/\bglyph\s*\(/,defined:/\bGlyph\s+glyph\s*\(/,code:`struct Glyph{\nfloat line;\nfloat word;\nfloat char;\nfloat lines;\nfloat words;\nfloat chars;\nvec4 lineBox;\nvec4 wordBox;\nvec4 charBox;\nfloat ink;\nvec4 lineValue;\nvec4 wordValue;\nvec4 charValue;\n};\nuniform highp usampler2D uGlyphIndex;\nuniform highp sampler2D uGlyphData;\nvec4 umberGlyphRow(highp int i){\nhighp int w=textureSize(uGlyphData,0).x;\nreturn texelFetch(uGlyphData,ivec2(i%w,i/w),0);\n}\nGlyph glyph(vec2 uv){\nGlyph 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));\n#ifdef UMBER_FRAGMENT\ng.ink=sampleImage(uv).a;\n#endif\nvec4 head=umberGlyphRow(0);\nif(head.x<0.5)return g;\nhighp ivec2 size=textureSize(uGlyphIndex,0);\nhighp ivec2 p=clamp(ivec2(floor(uv*vec2(size))),ivec2(0),size-1);\nhighp int c=int(texelFetch(uGlyphIndex,p,0).r)-1;\nif(c<0)return g;\nhighp int chars=int(head.x+0.5);\nhighp int words=int(head.y+0.5);\nvec4 info=umberGlyphRow(1+2*c);\ng.line=info.x;\ng.word=info.y;\ng.char=float(c);\ng.chars=head.x;\ng.words=head.y;\ng.lines=head.z;\ng.charBox=umberGlyphRow(2+2*c);\ng.wordBox=umberGlyphRow(1+2*chars+int(info.y+0.5));\ng.lineBox=umberGlyphRow(1+2*chars+words+int(info.x+0.5));\nhighp int lines=int(head.z+0.5);\nhighp int values=1+2*chars+words+lines;\ng.lineValue=umberGlyphRow(values+int(info.x+0.5));\ng.wordValue=umberGlyphRow(values+lines+int(info.y+0.5));\ng.charValue=umberGlyphRow(values+lines+words+c);\nreturn g;\n}`},q=65534,Y=(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)},J=t=>({l:t.x,t:t.y,r:t.x+t.w,b:t.y+t.h}),Z=t=>t.x+t.w/2;function Q(t,e,i){if(t.unit!==void 0&&e?.unit!==void 0)return t.unit!==e.unit;let r=!!e&&(t.rtl?Z(t)>e.x+e.w:Z(t)<e.x);return t.y+t.h/2>i.b||r&&t.y>=(i.t+i.b)/2}function tt(t,e=t.length){let i=new Int32Array(e),r=new Int32Array(e),n=[],s=[],a=null,l,h;for(let o=0;o<e;o++){let e=t[o];if(!e)break;let u=!l||Q(e,a,l);u||!l?(l={...J(e),chars:[]},n.push(l)):Y(l,e),l.chars.push(o),u||e.sa||!h?(h=J(e),s.push(h)):Y(h,e),i[o]=n.length-1,r[o]=s.length-1,a=e}return{xg:i,wordOf:r,lines:n,words:s}}var et=(t,e,i)=>Math.max(0,Math.min(i,Math.round(e*t.scale)));function it(t,e,i,r=2048){let n=Math.min(t.length,q);if(!n||!(e>0)||!(i>0))return null;let s=tt(t,n),a=Math.min(1,r/Math.max(e,i)),l={scale:a,width:Math.max(1,Math.ceil(e*a)),height:Math.max(1,Math.ceil(i*a))},h=s.lines.map(i=>rt(t,i,l,e)),o=lt(t,s,e,i);return{chars:n,words:s.words.length,lines:s.lines.length,index:at(st(h),h,l),width:l.width,height:l.height,data:o.data,dataWidth:o.dataWidth,dataHeight:o.dataHeight,values:o.values}}function rt(t,e,i,r){let n={line:e,owner:new Uint16Array(i.width),inkTop:new Float32Array(i.width).fill(1/0),inkBottom:new Float32Array(i.width).fill(-1/0)},s=e.chars.flatMap(e=>{let i=t[e];return i?[{at:e,glyph:i}]:[]}).sort((t,e)=>Z(t.glyph)-Z(e.glyph)),a=0;for(let[t,{at:e,glyph:l}]of s.entries()){let h=s[t+1]?.glyph,o=h?Math.max(a,(l.x+l.w+h.x)/2):r,u=et(i,a,i.width),d=h?et(i,o,i.width):i.width;d>u&&n.owner.fill(e+1,u,d),a=o,nt(n,l,i)}return n}function nt(t,e,i){let r=e.ink??{l:e.x,t:e.y,r:e.x+e.w,b:e.y+e.h},{inkTop:n,inkBottom:a}=t;for(let t=et(i,r.l-1,i.width-1),e=et(i,r.r+1,i.width-1);t<=e;t++)r.t-1<s(n,t)&&(n[t]=r.t-1),r.b+1>s(a,t)&&(a[t]=r.b+1)}function st(t){let e=[],i;for(let r of t){if(i){let t=(i.line.b+r.line.t)/2,{inkTop:n}=r;e.push(i.inkBottom.map((e,i)=>{let r=s(n,i);return e>r?(e+r)/2:Math.min(Math.max(t,e),r)}))}i=r}return e}function at(t,e,i){let r=new Uint16Array(i.width*i.height);for(let n=0;n<i.width;n++){let a=0;for(let[l,h]of e.entries()){let e=t[l],o=e?Math.max(a,et(i,s(e,n),i.height)):i.height,u=s(h.owner,n);for(let t=a;t<o;t++)r[t*i.width+n]=u;a=o}}return r}function lt(t,e,i,r){let{xg:n,wordOf:a,lines:l,words:h}=e,o=n.length,u=1+2*o+h.length+l.length,d=u+o+h.length+l.length,c=Math.min(d,512),f=Math.ceil(d/c),p=new Float32Array(c*f*4),g=(t,e)=>{p.set(e,t*4)},x=(t,e)=>{g(t,[e.l/i,e.t/r,(e.r-e.l)/i,(e.b-e.t)/r])};g(0,[o,h.length,l.length,0]);for(let[e,i]of t.slice(0,o).entries())g(1+2*e,[s(n,e),s(a,e),0,0]),x(2+2*e,J(i));return h.forEach((t,e)=>{x(1+2*o+e,t)}),l.forEach((t,e)=>{x(1+2*o+h.length+e,t)}),{values:u,data:p,dataWidth:c,dataHeight:f}}var ht=[1,0,0,1,0,0];function ot(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 ut=(t,e,i)=>[t[0]*e+t[2]*i+t[4],t[1]*e+t[3]*i+t[5]];function dt(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 ct(t,e,i){if(!t||t==="none")return null;let[r="0",n="0",s]=t.split(" ");if(s&&parseFloat(s))return!1;let a=(t,e)=>t.endsWith("%")?parseFloat(t)/100*e:parseFloat(t)||0;return[1,0,0,1,a(r,e),a(n,i)]}function ft(t){return t.endsWith("rad")?Math.PI:t.endsWith("turn")?.5:180}function pt(t){if(!t||t==="none")return null;if(t.trim().includes(" "))return!1;let e=parseFloat(t)*Math.PI/ft(t);return[Math.cos(e),Math.sin(e),-Math.sin(e),Math.cos(e),0,0]}function gt(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 xt(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:[s(e,0),s(e,1),s(e,4),s(e,5),s(e,12),s(e,13)]:e.length===6?e:ht}function mt(t,e,i){let r=[ct(t.translate,e,i),pt(t.rotate),gt(t.scale),xt(t.transform)];if(r.includes(!1))return!1;let n=ht;for(let t of r)t&&(n=ot(n,t));if(n.every((t,e)=>Math.abs(t-s(ht,e))<1e-6))return null;let[a=0,l=0]=t.transformOrigin.split(" ").map(parseFloat);return ot([1,0,0,1,a,l],ot(n,[1,0,0,1,-a,-l]))}function yt(t,e,i,r){let n=t??ht,{w:s,h:a}=r,l=1/0,h=1/0,o=[[0,0],[s,0],[0,a],[s,a]];for(let[t,i]of o){let[r,s]=ut(e,t,i),a=n[0]*r+n[2]*s,o=n[1]*r+n[3]*s;a<l&&(l=a),o<h&&(h=o)}let u=dt(n,i.x-n[4]-l,i.y-n[5]-h);if(!u)return null;let[d,c]=u;return{matrix:ot(n,ot([1,0,0,1,d,c],ot(e,[1,0,0,1,-d,-c]))),x:d,y:c}}function wt(t,e){let i=dt(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]),n=Math.abs(e[2]),s=Math.abs(e[1]),a=Math.abs(e[3]),l=r*a-n*s,h,o;return Math.abs(l)>.3*(r*a+n*s)?(h=(t.w*a-n*t.h)/l,o=(r*t.h-s*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 bt(t,e,i){return t.position==="absolute"&&e<=1&&i<=1&&t.overflow!=="visible"}var vt=class{constructor(t,e,i,r){this.el=t;this.$f=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.$f: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,n=t.offsetHeight||0,s=e.matrix,a=e.rest,l=i.display==="inline"?null:mt(i,r,n);if(l===!1)this.say("text3d",[],t);else if(l&&!a){let i=this.surface.Hc(t.getBoundingClientRect(),()=>r,n),h=yt(e.matrix,l,i,{w:r,h:n});h&&(s=h.matrix,Math.abs(s[0]*s[3]-s[1]*s[2])<1e-6&&(a={x:h.x,y:h.y,height:n,advance:0}))}let h=parseFloat(i.opacity);return{style:i,lang:t.getAttribute("lang")??e.lang,hidden:e.hidden||bt(i,r,n),matrix:s,rest:a,line:t.hasAttribute("data-line")?t:e.line,alpha:e.alpha*(h>=0?h:1),faded:h<1?t:e.faded}}};var Tt=new Map;function Et(t){let e=Tt.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 Tt.set(t,i),i}function Mt(t,e="",i=Et(e)){let r=new Uint8Array(t.length+1),n=!0;if(!i){for(let e=0;e<t.length;e++){let i=/\s/.test(t.charAt(e));!i&&n&&(r[e]=1),n=i}return r}let s=!1;for(let{segment:e,index:a,isWordLike:l}of i.segment(t)){if(!e.trim()){n=!0,s=!1;continue}(n||l&&s)&&(r[a]=1),n=!1,s=!!l}return r}function St(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 n=r<e-1?t[r+1]:void 0;return{rect:t[r],hyphen:n&&n.width>0?n:void 0}}var Rt=typeof Intl<"u"&&"Segmenter"in Intl?new Intl.Segmenter(void 0,{granularity:"grapheme"}):null;function*_t(t){if(Rt){yield*Rt.segment(t);return}let e=0;for(let i of t)yield{segment:i,index:e},e+=i.length}function kt(t,e){try{return t.toLocaleUpperCase(e||void 0)}catch{return t.toUpperCase()}}function At(t,e){try{return t.toLocaleLowerCase(e||void 0)}catch{return t.toLowerCase()}}function Ut(t,e,i,r=""){return e==="uppercase"||e==="capitalize"&&i?kt(t,r):e==="lowercase"?At(t,r):t}function Lt(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 Ct(t,e,i){return!i||!t.isSpace?t.painted:e?"":" "}function Ft(t,e){let i=[];t.forEach((t,e)=>t.isSpace||i.push(e));let[r]=i,n=i.at(-1);if(r===void 0||n===void 0)return null;let a=e(r,n+1),l=a[0];if(a.length===1&&l)return[[r,n+1,l]];let h=[];for(let t=0;t<i.length;){let r=s(i,t),n=St(e(r,r+1)).rect;if(!n||n.width<=0)return null;let a=t,l=i.length-1;for(;a<l;){let t=a+l+1>>1,r=s(i,t),h=St(e(r,r+1)).rect;h&&Math.abs(h.top-n.top)<n.height/2?a=t:l=t-1}let o=s(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 Pt=/[\u0600-\u08FF\u0900-\u0DFF\u0E00-\u0FFF\u1000-\u109F\u1780-\u17FF\uFB50-\uFDFF\uFE70-\uFEFF]/,Dt=t=>!!t&&!/^(inline|contents)/.test(t);function Bt(t){if(Pt.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),n=It(e,i)||Gt(e)||Nt(e)||Wt(r,t,e);if(n)return n}return""}function It(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":Ht(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 Nt(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":Ot(t.getPropertyValue("font-stretch"))===void 0?"a font-stretch between the keyword widths":""}function Wt(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&&!Dt(i.display))return"";for(let e of["::first-letter","::first-line"])if(Xt(getComputedStyle(t,e),i))return`a styled ${e}`;return""}var zt=["fontSize","fontFamily","fontWeight","fontStyle","color","letterSpacing","textTransform","fontVariantCaps"],Xt=(t,e)=>zt.some(i=>t[i]&&t[i]!==e[i]),$t=new Set(["kern","liga","clig","calt"]);function Ht(t){if(!t||t==="normal")return!1;let e=t.match(/["'][\w ]{4}["']/g)??[];return!e.length||e.some(t=>!$t.has(t.slice(1,5)))}var Vt={"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 Ot(t=""){if(!t)return"";let e=Vt[t];return e!==void 0?e:Object.values(Vt).includes(t)?t:void 0}var Kt=class{constructor(t,e,i){this.canvas=t;this.ctx=e;this.layout=i;this.local=[0,0,0,0,0,0];this.fills=t?null:[]}fill(t,e,i){let{ctx:r,fills:n}=this;if(!n){r.fillText(t,e,i);return}let s=r;n.push({text:t,x:e,y:i,font:r.font,letterSpacing:s.letterSpacing??"0px",wordSpacing:s.wordSpacing??"0px",kerning:s.fontKerning??"auto",caps:s.fontVariantCaps??"normal",rtl:r.direction==="rtl",color:typeof r.fillStyle=="string"?r.fillStyle:"#000000",alpha:r.globalAlpha})}Hc(t,e,i){let{box:r,scaleX:n,scaleY:s,turned:a}=this.layout;if(!a)return{x:(t.left-r.left)/n,y:(t.top-r.top)/s,w:t.width/n,h:t.height/s};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(),p=i;return Math.abs(c)>.3*(h*d+o*u)&&(f=(t.width*d-o*t.height)/c,p=(h*t.height-u*t.width)/c),{x:l[0]-f/2,y:l[1]-p/2,w:f,h:p}}snap(t){let{box:e,scaleY:i,pad:r,deviceScale:n,turned:s}=this.layout;return s?t:(Math.round((e.top+(t-r)*i)*n)/n-e.top)/i+r}};function jt(t,e,i,r){let n=r.turned??null,s=t.offsetWidth||e.width,a=t.offsetHeight||e.height,l=Math.abs(e.width-s)<1?1:e.width/s,h=Math.abs(e.height-a)<1?1:e.height/a,o=n?n.width:e.width/l,u=n?n.height:e.height/h,d=Math.ceil(i*.35),c=o+d*2,f=u+d*2,p=Math.min(r.scale,r.maxSize/Math.max(c,f)),g=Math.max(1,Math.ceil(c*p)),x=Math.max(1,Math.ceil(f*p)),m=null,y;if(r.record){if(y=Yt(),!y)return null;y.setTransform(1,0,0,1,0,0),y.globalAlpha=1}else{if(m=r.canvas??document.createElement("canvas"),m.width!==g&&(m.width=g),m.height!==x&&(m.height=x),y=m.getContext("2d"),!y)return null;y.setTransform(1,0,0,1,0,0),y.clearRect(0,0,m.width,m.height),y.setTransform(p,0,0,p,0,0)}return y.textBaseline="alphabetic",y.textAlign="left",new Kt(m,y,{box:e,scaleX:l,scaleY:h,scale:p,deviceScale:r.scale,pad:d,layoutWidth:o,layoutHeight:u,width:c,height:f,pixelWidth:g,pixelHeight:x,turned:n})}var qt;function Yt(){return qt===void 0&&(qt=document.createElement("canvas").getContext("2d")),qt}var Jt=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,Zt=/[\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}\p{sc=Hangul}]/u,Qt=/[\p{L}\p{N}]/u;function te(t,e,i){let r=!1;for(let n=t;n&&n!==e;n=n.parentNode){let t=n.previousSibling;if(t){(t.nodeName==="BR"||t.nodeType===1&&Dt(getComputedStyle(t).display))&&(r=!0);break}n.parentElement&&i(n.parentElement)&&(r=!0)}return r}function ee(t,e){let i=e.fontVariantCaps==="small-caps"?"small-caps ":"",r=Ot(e.getPropertyValue("font-stretch"))??"";t.font=`${e.fontStyle} ${i}${e.fontWeight} ${r} ${e.fontSize} ${e.fontFamily}`,"fontVariantCaps"in t&&(t.fontVariantCaps=e.fontVariantCaps||"normal"),"fontKerning"in t&&(t.fontKerning=e.fontKerning||"auto")}function ie(t,e,i){ee(t,e);let r=e.direction==="rtl";t.direction=r?"rtl":"ltr",t.fillStyle=e.color;let n=t.measureText("Hg");return{rtl:r,ascent:n.fontBoundingBoxAscent??i*.8,descent:n.fontBoundingBoxDescent??i*.2,letter:parseFloat(e.letterSpacing)||0,word:parseFloat(e.wordSpacing)||0}}function re(t){let e=t,i=(t.hyphenateCharacter||"").replace(/^auto$|["']/g,"")||"-",r=(t.hyphens||(e.webkitHyphens??""))==="auto";return{hyphen:i,hyphenates:r}}var ne=new WeakSet,se=[],ae=class{constructor(t,e,i,r){this.ancestry=t;this.starts=e;this.ti=i;this.fontSize=r;this.boxes=[];this.hidden=[];this.drew=!1;this.over=!1;this.down=!1;this.units=0;this.sa=!0;this.sb=!0;this.lines=new Map;this.range=document.createRange();this.el=t.el,this.surface=t.surface,this.fa=[t.el]}space(){this.sa=!0,this.sb=!0}Xg(t,e,i){let r=t.parentElement;if(!r)return;let n=this.ancestry.of(r),{style:s}=n,a=s.textTransform;if(a==="capitalize"&&te(t,this.el,t=>Dt(this.ancestry.of(t).style.display))&&(this.sb=!0),this.unseen(r,n))return;r!==this.el&&s.display!=="inline"&&this.units++,this.qi(r,n);let{ctx:l}=this.surface;l.globalAlpha=n.alpha;let h=ie(l,s,this.fontSize),o={node:t,at:e,info:n,font:h,...re(s),line:n.line?this.xg(n.line):void 0,glyphs:this.ng(i,a,n.lang)},{matrix:u}=n,d=!this.surface.layout.turned&&!n.rest&&(!u||!u[1]&&!u[2])&&!o.hyphenates&&Lt(s,i,l,h.letter||h.word)?Ft(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"||r==="none"||e.hidden}qi(t,e){(t===this.el||!!t.closest("a, button")||e.style.color!==this.ancestry.of(t.parentElement??this.el).style.color)&&!this.fa.includes(t)&&this.fa.push(t),e.faded&&!this.fa.includes(e.faded)&&this.fa.push(e.faded)}xg(t){let e=this.lines.get(t);return e!==void 0?e:(this.lines.set(t,this.lines.size),this.lines.size-1)}ng(t,e,i){let r=[];for(let{segment:n,index:s}of _t(t)){let t=!n.trim(),a=Qt.test(n),l=t?n:Ut(n,e,this.sb&&a,i);r.push({index:s,text:n,painted:l,isSpace:t}),(t||a)&&(this.sb=t)}return r}read(t,e,i){let r=t.glyphs[e],n=t.glyphs[i-1];return!r||!n?se:(this.range.setStart(t.node,r.index),this.range.setEnd(t.node,n.index+n.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}wc(t,e,i){let{rest:r,matrix:n}=t.info,{ascent:s,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.Hc(i,()=>this.advance(t,e),s+a),n&&(l=wt(l,n)??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(o.y+(l.h-(s+a))/2+s);return this.surface.fill(e,o.x,u),this.drew=!0,this.yd(t,o.x,l.w,u),{box:o,baseline:u}}yd(t,e,i,r){if(this.over)return;let{width:n,height:s}=this.surface.layout;this.down||=r-t.font.ascent<-.5||r+t.font.descent>s+.5,this.over=this.down||e<-.5||e+i>n+.5}push(t,e,i,r){let n=this.ti?this.surface.ctx.measureText(e.painted):null,s=n&&typeof n.actualBoundingBoxAscent=="number"?{l:i.x-n.actualBoundingBoxLeft,t:r-n.actualBoundingBoxAscent,r:i.x+n.actualBoundingBoxRight,b:r+n.actualBoundingBoxDescent}:void 0;this.boxes.push({x:i.x,y:i.y,w:i.w,h:i.h,sa:this.sa,ink:s,rtl:t.font.rtl,at:t.at+e.index,len:e.text.length,unit:t.line}),this.sa=!1}letters(t,e,i){this.spacing(0,0);let r;for(let n=e;n<i;n++)r=this.letter(t,n,r)}letter(t,e,i){let r=t.glyphs[e];if(!r)return;let{rest:n}=t.info;if(this.starts[t.at+r.index]&&(this.sa=!0),r.isSpace){n&&(n.advance+=this.advance(t,r.text)+t.font.word),this.sa=!0;return}let{rect:s,hyphen:a}=St(this.read(t,e,e+1)),l=!a&&i&&s?this.pg(t,e,i,s):null;a?this.wc(t,t.hyphen,a):l&&i&&this.Wg(t,l,i);let h=a||t.font.rtl?void 0:s;if(!n&&(!s||s.width<=0))return h;let o=this.wc(t,r.painted,s);return o&&this.push(t,r,o.box,o.baseline),h}pg(t,e,i,r){let n=t.glyphs[e],s=t.glyphs[e-1];return!n||!s?null:t.hyphenates&&r.top>i.top+i.height/2&&!this.starts[t.at+n.index]&&Qt.test(n.text)&&Qt.test(s.text)&&!Zt.test(s.text+n.text)?s:null}Wg(t,e,i){let{scaleX:r}=this.surface.layout,n=this.advance(t,t.hyphen)*r,s=i.left+i.width-(i.width-this.advance(t,e.painted)*r>n/2?n:0);this.wc(t,t.hyphen,{left:s,top:i.top,width:n,height:i.height})}run(t,e,i,r){let{ctx:n,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)=>Ct(t,u&&(d[e-1]?.isSpace??!1),u)),f=c.join(""),p=this.surface.Hc(r,()=>0,0);if(o.matrix&&(p=wt(p,o.matrix)??p),Math.abs(n.measureText(f).width-p.w)>.5)return!1;let g=this.backwards(t,e,i,f);if(g===null)return!1;let x=p.y+a.pad,m=this.surface.snap(x+(p.h-(h.ascent+h.descent))/2+h.ascent);this.surface.fill(f,p.x+a.pad,m),this.drew=!0,this.yd(t,p.x+a.pad,p.w,m);let y=c.map(t=>t?n.measureText(t).width:0),w=p.w/(y.reduce((t,e)=>t+e,0)||1),b=p.x+a.pad+(g?p.w:0);for(let[e,i]of d.entries()){let r=s(y,e)*w;this.starts[t.at+i.index]&&(this.sa=!0),g&&(b-=r),i.isSpace?this.sa=!0:this.push(t,i,{x:b,y:x,w:r,h:p.h},m),g||(b+=r)}return!0}backwards(t,e,i,r){let{rtl:n}=t.font;if(i-e<=1||!(n||Jt.test(r)))return n;let s=St(this.read(t,e,e+1)).rect,a=St(this.read(t,i-1,i)).rect;return!s||!a?null:s.left>a.left}};function le(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 he(t,e){let i=t.getBoundingClientRect();if(i.width<1||i.height<1)return{drawn:!1,canvas:null,hidden:[]};let n=getComputedStyle(t),s=parseFloat(n.fontSize)||16,a=jt(t,i,s,e);if(!a)return{drawn:!1,canvas:null,hidden:[]};let l=new vt(t,n,a,e.say),{nodes:h,text:o}=le(t),u=Mt(o,l.of(t).lang),d=new ae(l,u,!!e.glyphs,s),c=0;for(let t of h){let e=t.nodeValue??"",i=c;c+=e.length,e.trim()?d.Xg(t,i,e):e&&d.space()}if(!d.drew)return{drawn:!1,canvas:null,hidden:d.hidden};d.units>=8&&!ne.has(t)&&(ne.add(t),r.info('data-umber="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.',t));let{canvas:f,fills:p}=a,{scale:g,pad:x,layoutWidth:m,layoutHeight:y,pixelWidth:w,pixelHeight:b}=a.layout;return{drawn:!0,canvas:f,fills:p,pixelWidth:w,pixelHeight:b,scale:g,pad:x,layoutWidth:m,layoutHeight:y,fa:d.fa,boxes:d.boxes,text:o,glyphs:e.glyphs?it(d.boxes,w/g,b/g):void 0,over:d.over,down:d.down,hidden:d.hidden}}var oe=2e3,ue=class{constructor(){this.ja=!0;this.empty=!1;this.hidden=!1;this.Mb=[];this.gb="";this.size="";this.fa=[];this.colors=[];this.xa=0;this.Ca="";this.Zd=0;this.Ua=null;this.Cd=!1;this.pending=!1;this.fresh=!1;this.lb=null;this.$a=null;this.table=null;this.Ka=null;this.ma=null;this.free=()=>{this.Ja=this.fresh||this.pending?setTimeout(this.free,oe):void 0,this.fresh=!1,!this.Ja&&this.Ua&&(this.Ua.width=1)}}upload(t){this.pending=!1,this.fresh=!0,this.Ja??=setTimeout(this.free,oe);let e=this.$a;e&&(this.$a=null,this.Ka??=new c(t,"uint"),this.ma??=new c(t,"float"),this.Ka.upload(e.width,e.height,e.index),this.ma.upload(e.dataWidth,e.dataHeight,e.data))}lost(){this.Ka=null,this.ma=null,this.$a=null}dispose(t){clearTimeout(this.quiet),clearTimeout(this.Ja),t?._j&&(t._j=null,t.el.removeAttribute("data-umber-status")),this.Ua?.remove(),this.lb?.disconnect(),this.lb=null,this.Ka?.dispose(),this.ma?.dispose(),this.lost()}};function de(t=""){let e=new CSSStyleSheet;return e.replaceSync(t),document.adoptedStyleSheets=[...document.adoptedStyleSheets,e],e}var ce=(t,e)=>t.cssRules[t.insertRule(`${e}{}`,t.cssRules.length)];function fe(t){let e=t?.parentStyleSheet;if(!e)return;let i=[...e.cssRules].indexOf(t);i>=0&&e.deleteRule(i)}var pe=["lines","words","chars"],ge=[0,1,2],xe=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}Bf(t){return this.dead?0:s(this.owner.values,this.slot*4+t)||0}Dh(t,e){this.dead||this.owner.write(this.slot*4+t,e)}tween(t,e){let i=()=>this[t],r=e=>{this[t]=e},n=this.hh??={},s=n[t]??={get value(){return i()},set value(t){r(t)}};return this.owner.stage.env.tweens.to(s,e)}};["t","x","y","z"].forEach((t,e)=>Object.defineProperty(xe.prototype,t,{get(){return this.Bf(e)},set(t){this.Dh(e,t)}}));var me=(t,e)=>Math.abs(t-e)<.01,ye=t=>t.replace(/\s+/g," ").trim(),we={top:0,center:.5,middle:.5,bottom:1};function be(t,e){return t.trim().replace(/^(top|center|middle|bottom|-?[\d.]+%|-?[\d.]+(?:px)?)(?=[\s+-]|$)/i,t=>{let i=ve(t.toLowerCase(),e.h);return`${Math.round((e.y+i)*100)/100}px`})}function ve(t,e){let i=we[t];return i!==void 0?i*e:t.endsWith("%")?parseFloat(t)/100*e:parseFloat(t)}var Te=t=>({x:t.l,y:t.t,w:t.r-t.l,h:t.b-t.t});function Ee(t,e,i,r){let{box:n}=t,s=i.x-r,a=i.y-r,l=t.text!==e||!me(n.x,s)||!me(n.y,a)||!me(n.w,i.w)||!me(n.h,i.h);return t.text=e,n.x=s,n.y=a,n.w=i.w,n.h=i.h,l}function Me(t,e){let i=new Int32Array(e).fill(-1),r=new Int32Array(e);return t.forEach((t,e)=>{s(i,t)<0&&(i[t]=e),r[t]=e}),{first:i,last:r}}var Se,Re=0,_e=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._k||this.plane.instancing)&&(this.dirty=!0,this.stage.scheduler.markDirty()))}update(t,e,i){let{xg:r,wordOf:n,lines:a,words:l}=tt(t),h=[this.lines,this.words,this.chars],o=[a.length,l.length,t.length],u=ge.some(t=>h[t].length!==o[t]);this.sg(h,o);let{first:d,last:c}=Me(n,l.length),f=(i,r)=>e.slice(t[i]?.at??0,(t[r]?.at??0)+(t[r]?.len??0)),p=(t,e)=>{let i=h[t],r=i[e]??new xe(this,t,e);return i[e]=r,r};a.forEach((t,e)=>{let[r=0]=t.chars,a=t.chars.at(-1)??r,l=p(0,e);u=Ee(l,ye(f(r,a)),Te(t),i)||u,l.chars=[r,a],l.words=[s(n,r),s(n,a)]}),l.forEach((t,e)=>{let n=p(1,e),a=s(d,e),l=s(c,e);u=Ee(n,ye(f(a,l)),Te(t),i)||u,n.chars=[a,l],n.line=s(r,a)}),t.forEach((t,e)=>{let a=p(2,e);u=Ee(a,f(e,e),t,i)||u,a.line=s(r,e),a.word=s(n,e)});for(let t of ge)for(let e of h[t].splice(o[t]))e.dead=!0;return u&&(this.version++,this.changed=!0),u}sg(t,e){let i=[0,e[0],e[0]+e[1]],r=new Float32Array(4*(i[2]+e[2]));for(let n of ge){let s=Math.min(t[n].length,e[n]);r.set(this.values.subarray(this.base[n]*4,(this.base[n]+s)*4),i[n]*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:be((e.start??"")||"top bottom",t.box),end:be((e.end??"")||"bottom top",t.box)}))}ui(){if(!this.rule){let t=this.plane.el,e=t.getAttribute("data-umber-css");e||t.setAttribute("data-umber-css",e=`t${++Re}`),this.rule=ce(Se??=de(),`[data-umber-css="${e}"]`)}for(let t of pe)this.rule.style.setProperty(`--umber-${t}`,`${this[t].length}`)}dispose(){this.plane.el.isConnected||fe(this.rule),this.rule=null}};var ke=()=>{let t=typeof window<"u"?window.occluzeCapture:void 0;return t?.version===1?t:null},Ae=()=>new Promise(t=>{let e=new MessageChannel;e.port1.onmessage=t,e.port2.postMessage(0)});function Ue(t){ke()?Ae().then(t):"requestIdleCallback"in window?requestIdleCallback(t,{timeout:2e3}):setTimeout(t,200)}function Le(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,n=null,s=1/0;for(let e of t.planes.all){if(e.kind!=="text"||e.textureState!=="none"||e.status==="error"||e.raster?.empty)continue;let t=e.measured?Math.abs(e.doc.y+e.doc.h/2-i):1e9+e.index;t<s&&(s=t,n=e)}n&&(t.factory.load(n),r())},r=()=>{e||(e=!0,Ue(i))};return r}var Ce={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: ${t?'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-umber="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-umber="text" on an element as wide as its text.'}`};var Fe="its words or letters are animating: its DOM shows until they hold still (GL animates them with glyph())",Pe=150,De="|curves",Be=t=>t.programKey.endsWith(De),Ie=class{constructor(t){this.stage=t;this.changed=new WeakMap;this.shared=null;this.Ub=null;this.Ec=new WeakMap;this.bound={layout:{texture:null},color:{texture:null}};this.ahead=Le(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.xa=e,i=!0);i&&t.scheduler.request()};for(let i of["pointerover","pointerout"])t.env.listen(document,i,e)}get curves(){return this.Ub??=new U(this.stage.gpu.gl,t=>{this.Mf(t)})}get curveTables(){return this.Ub?.tables??null}Mf(t){let e=this.stage,i=this.curveTables,r=this.Ub?.chunk?.CURVE_GLSL;if(t&&i&&r){e.gpu.subsystems.push({restored:()=>{i.restore()}}),z(r),e.gpu.programs.textKey=De;for(let t of e.planes.all)t.kind==="text"&&this.Md(t)}for(let t of e.planes.all)t.raster&&Be(t)&&(t.raster.ja=!0);e.factory.invalidate()}Md(t){let{program:e,programKey:i}=t;if(!e||Be(t)||!this.stage.gpu.programs.prepare(t))return;let r=t.program;!r||!e.started||!e.ready()||(this.Ec.set(t,[r,t.programKey]),t.program=e,t.programKey=i)}get atlas(){if(this.shared)return this.shared;let{gpu:t,canvasHost:e}=this.stage,i=new k(t.gl,e.el,t.tier.maxTexture);return t.subsystems.push({lost:()=>{i.lost()}}),this.shared=i,i}blank(t){return{index:new c(t,"uint"),data:new c(t,"float")}}samplers(t){let e=t.texture;return e instanceof N?(this.bound.layout.texture=e.layout.texture,this.bound.color.texture=e.Ff,this.bound):null}units(t){if(t.text)return;let e=new _e(t,this.stage);Object.defineProperty(t,"text",{value:e,configurable:!0,enumerable:!0}),t.modules.list.push({name:"text",binding:{update:()=>this.frame(t,e),destroy:()=>{e.dispose()}}})}load(t){let e=this.stage;this.watch(t),this.units(t),t.textureState="loading";let i=()=>{t._j&&(t.textureState="none"),!(!e.planes.all.includes(t)||e.gpu.context.gone||t.status==="error")&&(this.Ra(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()}Ra(t){let e=this.stage,i=t.raster??=new ue;if(t.status==="error")return!1;let r=Bt(t.el);if(r)return this.refuse(t,i,"textUnsupported",[r]);if(K(t.el))return this.hold(t),!1;let n=getComputedStyle(t.el),s=!i.Cd&&t.instancing?.spec.mode!=="ink",a=he(t.el,{scale:e.canvasHost.dpr,maxSize:e.gpu.tier.maxTexture,canvas:s?void 0:this.Af(i,n),record:s,glyphs:t._k,turned:e.chunks.shapes?.Uh(t)??null,say:e.env.lib.say});return a.drawn?a.over?this.refuse(t,i,"textOverflow",[a.down]):a.fills&&!this.placed(t,a,n)?(i.Cd=!0,t.texture instanceof N&&this.stage.gpu.media.release(t),this.Ra(t)):(this.painted(t,i,a),!0):(this.Ug(t,i,a.hidden,n),!1)}placed(t,e,i){let r=this.stage;if(!e.fills)return!1;let n=["-webkit-font-smoothing","-moz-osx-font-smoothing"].map(t=>i.getPropertyValue(t)),s={fonts:this.curves,draw:Be(t)},a=this.atlas.place(e.fills,e.scale,n,s);if(r.gpu.renderer.reset(),!a)return!1;let l=(t.texture instanceof N?t.texture:this.$g(t)).show(a,e.pixelWidth,e.pixelHeight);return r.gpu.renderer.reset(),l}refuse(t,e,i,r){this.stage.env.lib.say(i,r,t.el),e.ja=!1,t.textureState="error";let n=Ce[i];return t.setStatus("error",n(...r)),!1}Af(t,e){let i=t.Ua??=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}Ug(t,e,i,r){let n=e.Ua,s=!e.empty&&(t.textureState==="ready"||t.textureState==="queued");s&&t.texture instanceof N?(t.texture.show([],1,1),this.stage.gpu.renderer.reset(),t.text?.update([],"",0)):n&&s&&(n.width=1,this.stage.gpu.media.Ac(t,n),t.text?.update([],"",0)),e.fa=[],e.colors=[],e.empty=!0,e.hidden=r.visibility==="hidden",e.hidden&&(t.opacity=0),e.Mb=e.hidden?[]:i,e.ja=!1,e.Ca="",e.gb=this.key(t)}painted(t,e,i){e.empty=!1,e.hidden=!1,e.Mb=i.hidden,i.canvas&&(e.Ua=i.canvas),e.pending=!!i.canvas,t.pad=i.pad,t.layoutW=i.layoutWidth,t.layoutH=i.layoutHeight,e.fa=i.fa.map(t=>getComputedStyle(t)),H(e.fa,e.colors=[]),e.gb=this.key(t),e.Ca="",e.ja=!1,t.textureState=t.texture?.ready?"ready":"queued",t._k&&(e.table=i.glyphs??null,e.$a=e.table);let r=t.text;r&&(r.update(i.boxes,i.text,i.pad),r.dirty||=!!e.table),i.canvas?this.stage.gpu.media.Ac(t,i.canvas):this.landed(t,e),this.stage.scheduler.markDirty()}$g(t){t.texture&&this.stage.gpu.media.release(t);let e=new N(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._i())}frame(t,e){let i=this.Ec.get(t);i&&(i[0].ready()?(this.Ec.delete(t),[t.program,t.programKey]=i,t.raster&&(t.raster.ja=!0),this.stage.factory.invalidate(t.el)):this.stage.scheduler.request()),e.changed&&(e.changed=!1,e.ui(),t.emit("text"));let r=t.raster,n=r?.table;return!e.dirty||!n?!1:(e.dirty=!1,n.data.set(e.values.subarray(0,(n.lines+n.words+n.chars)*4),n.values*4),r.$a!==n&&r.ma?.ready&&r.ma.upload(n.dataWidth,n.dataHeight,n.data),!0)}key(t){let e=t.el,i=t.raster??=new ue;return(t.stale||i.Ca||!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}`}check(t,e,i){let r=t.raster??=new ue,n=this.key(t);if(this.Hh(t,r,e,i)){this.Ra(t);return}if(r.ja&&!r.gb){this.Ra(t);return}if(!r.ja&&n===r.gb)r.Ca="";else{n!==r.Ca&&(r.Ca=n,r.Zd=e),t.zone.soon&&(n===r.gb||e-r.Zd>=150)&&e-(this.changed.get(t)??0)>=100&&this.Ra(t);return}let s=i||t.stale||e<r.xa;e<r.xa&&this.stage.scheduler.request(),t.zone.soon&&s&&r.fa.length&&H(r.fa,r.colors)&&(r.xa=e+400,this.Ra(t))}Hh(t,e,i,r){return e.hidden&&t.opacity>0?!0:!e.Mb.length||!(t.stale||r||i<e.xa)?!1:e.Mb.some(t=>getComputedStyle(t).visibility!=="hidden")}watch(t){let e=t.raster??=new ue;e.lb||(e.lb=new MutationObserver(i=>{let r=!1,n=!1,s=!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"?s=!0:i==="style"?n||=V(e.oldValue)!==V(a.getAttribute("style")):!i.startsWith("data-umber")&&e.oldValue!==a.getAttribute(i)&&(r=!0)}}r&&(e.ja=!0,e.empty=!1,this.changed.set(t,performance.now()),t.stale=!0,this.stage.scheduler.markDirty()),n||s&&K(t.el)?this.hold(t):s&&(e.xa=performance.now()+400,this.stage.scheduler.markDirty())}),e.lb.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)},Pe),!t._j&&(t.warned.add(Fe),t._j=Fe,this.stage.fallbacks.decide(t)))}settle(t){let e=t.raster;if(!(!e||!this.stage.planes.all.includes(t))){if(e.quiet=void 0,K(t.el)){this.hold(t);return}t.texture&&(t.texture.ready=!1),e.ja=!0,this.changed.set(t,0),t.stale=!0,!t.program&&!this.stage.gpu.context.gone&&this.stage.gpu.programs.prepare(t),t._j=null,this.stage.fallbacks.decide(t),this.stage.scheduler.markDirty()}}};function Ge(t,e){n(t.env.host.log),t.chunks.text=new Ie(t),t.chunks.pa(t.chunks.La);let i=[...t.chunks.mb];t.chunks.mb.clear();for(let e of i)!t.planes.all.includes(e)||e.textureState!=="loading"||(e.textureState="none",t.factory.load(e));e&&t.chunks.pa(new Set(t.planes.all.filter(t=>t.kind==="text"&&t.textureState==="error")))}export{j as GLYPH_HELPER,W as TEXT_HELPER,Ge 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.3.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.ua=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.ua=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.ua=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.ua||!this.mipmaps||!this.ready||(this.ua=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.Pa=s;this.textures=new Map;this.queue=new Map;this.closing=[];this.Da=-1;this.Ea=-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.Pa()}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.Da&&t===this.Ea&&s===this.amount)&&(this.Da=e,this.Ea=t,this.amount=s,this.Pa())}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.Da&&s!==this.Ea)break;this.queue.delete(s),this.upload(s,r.image)&&t++,r.close&&c(r.image)&&this.closing.push(r.image)}return this.ed(),(this.queue.size||this.closing.length)&&this.Pa(),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.Da?-2:e===this.Ea?-1:Math.abs(e-this.center)}fit(e){let t=this.bytes;return this.cap=Math.max(2*(this.drawn?.bytes??0),e),this.ed(),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}ed(){let e=this.bytes;if(e<=this.limit)return;let t=[...this.textures].filter(([e,t])=>e!==this.Da&&e!==this.Ea&&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.Da);return e?.ready?this.drawn=e:this.drawn&&!this.drawn.ready&&(this.drawn=null),this.drawn}get next(){let e=this.Ea>=0&&this.drawn===this.textures.get(this.Da)?this.textures.get(this.Ea):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._i()),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"],b=`:is(${f.map(e=>`[data-umber~=${e}]`).join()})`;var x=new Set(["data-umber","data-umber-effect","data-umber-shader","data-umber-layer","data-umber-instances"]),v=[...x,"style","class","hidden","media","disabled","data-umber-src","src","srcset","sizes","data-umber-occlude","data-umber-pass","data-umber-under"];var E="[data-umber-occlude]",y=b+","+E;var w=`${b}: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 _={high:128,mid:48,low:32},k={high:8,mid:2,low:1},S=3e3;function A(e){let t=e.getAttribute("src");return t||(e.querySelector("source")?.getAttribute("src")??"")}var L=()=>{};function D(e,t,s){t.textureState!=="error"||e.scheduler.inactive||t.domReason||(t.textureState="loading",t.setStatus("loading"),t._G(),t.texture??=new o(e.gpu.gl),s.setAttribute("data-umber-media",""))}function R(e,t){let s=()=>e._a.add("video"),r=()=>e._a.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 P=class{constructor(e){this.stage=e;this.blocked=new Set;this.hooked=!1;this.ib=new WeakMap;this.emptied=new WeakMap;this.Pc=!1;this.Zb=0;this.at=-1;this.left=0;this.Qa=0;this.oldest=0;this.first=0;this.waited=0;this.bb=0;this.Cb=0;this.Jd=new WeakMap;this.since=new WeakMap;this.retry=()=>{this.Xd();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.Xd=()=>{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.Qg(i);let a=this.Jd.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.ug(h,i)?(this.oh(e,h,i),!0):(this.left--,h<i&&(this.Qa--,h===this.oldest&&this.first--),this.bi(e,s,t)?(e.videoFrame=!1,!0):!1)}Qg(e){let t=this.stage,s=this.at===e-1;this.at=e,this.left=t.chunks.za?1/0:k[t.gpu.tier.tier],this.Qa=s?this.waited:0,this.oldest=this.bb,this.first=this.Cb,this.waited=0,this.Cb=0,this.bb=e}oh(e,t,s){t===s&&this.since.set(e,s),this.Jd.set(e,s),this.waited++,t<this.bb&&(this.bb=t,this.Cb=0),t===this.bb&&this.Cb++,this.stage.scheduler.markDirty()}bi(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._i(),!0}catch(t){return r.env.lib.say("videoBlocked",[e.el],t),e.textureState="error",e.setStatus("error"),e._l?.(),e._l=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.Pc=!0,t.removeAttribute("src"),t.load())}wh(e){if(!this.Pc)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()}}}Md(e,t){let s=e.media;if(!s)return;let r=this.ib.get(s);if(r===void 0)return void this.ib.set(s,A(s));let i=A(s);i===r||e.modules.feed?.src?.()===!1||(this.ib.set(s,i),this.stage.planes.remove(e),t.push(e.el))}ug(e,t){return e===this.oldest?0:e<t?this.first:this.Qa}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.ag(),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}ag(){let e=this.stage,t=this.ac();e.env.stats.textureMB*2**20+(e.chunks.fx?.pool.bytes??0)+t<=e.gpu.tier.textureBudget?this.Zb=0:t>this.Zb&&(this.Zb=t,e.gpu.media.Wb())}ac(){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.qc(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.ib.set(r,A(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(_[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},scrollKind:r.env.host.scroll.kind,log:a,busy(s){s!==e._a.has(t)&&(s?e._a.add(t):e._a.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.ib.set(s,A(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+S-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||(D(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=R(e,t),e._l=()=>{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()}kf(e,t){let s=e.media;if(!(!(s instanceof HTMLVideoElement)||!p(s,e.el))){if(!t){s.paused||(s.pause(),e._B=!0);return}!e._B||this.stage.env.host.env.reducedMotion||(e._B=!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.Xd),this.hooked=!0)}))}}};function M(e){i(e.env.host.log),e.chunks.video=new P(e),e.chunks.pa(e.chunks.ob)}export{M as video};
|
package/dist/chunks/views.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! Umber v0.
|
|
2
|
-
var
|
|
1
|
+
/*! Umber v0.3.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},i=r;function n(e){i=e}var a=[1,.85,.7,.55],s={high:2,mid:1.5,low:1},o=.8;function d({option:e,tier:t,width:r,height:i,budget:n=12e6,wide:a=1/0}){let d=0,h;typeof e=="number"&&e>0?h=e:Array.isArray(e)?(d=Math.max(0,e[0]||0),h=e[1]||s[t]):h=(e&&typeof e=="object"?e[t]:void 0)??s[t],r>a&&(h=Math.min(h,o));let l=Math.max(d,Math.min(typeof devicePixelRatio=="number"&&devicePixelRatio||1,h)),c=r*i;return c*l*l>n&&(l=Math.sqrt(n/Math.max(c,1))),l}function h(e,t,r){return e<0?r?45/150:1:e>t*.6?1:0}var l=class{constructor(){this.scale=1;this.index=0;this.settle=30;this.Sa=0;this.Ya=0;this.hd=[];this.Cc=150;this.rd=-1}frame(e,t,r,i){let n=e.frame-this.rd===1;this.rd=e.frame;let s=this.hd;s.push(e.dt),s.length>120&&s.shift();let o=e.dt*60;if(this.settle>0||t)return this.settle=Math.max(0,this.settle-o),!1;if(!n||s.length<30)return!1;let d=1/0;for(let e of s)e<d&&(d=e);e.dt>Math.max(d*1.5,1/40)?(this.Sa+=h(r,d*1e3,i),this.Ya=0):e.dt<d*1.2&&(this.Ya+=o,this.Sa=Math.max(0,this.Sa-o));let l=i?45:150;return this.Sa>l&&this.index<a.length-1?(this.Cc=Math.min(this.Cc*2,2400),this.Pd(this.index+1),!0):this.Ya>this.Cc&&this.index>0?(this.Pd(this.index-1),!0):!1}onResize(){this.settle=30,this.Sa=0,this.Ya=0}rest(e){this.settle=Math.max(this.settle,e)}reset(){this.hd.length=0,this.settle=30}Pd(e){let t=a[e];t!==void 0&&(this.index=e,this.scale=t,this.Sa=0,this.Ya=0,this.settle=30)}};function c(e){if(!(!e||typeof navigator<"u"&&/apple/i.test(navigator.vendor||"")))try{e.isContextLost()||e.getExtension("WEBGL_lose_context")?.loseContext()}catch{}}var u=/(swiftshader|llvmpipe|software|basic render)|mali-4|mali-t|adreno \(tm\) [2-5]|powervr|intel\(r\) hd graphics [2-5]/i,f=[1400,1600];function p(e){return e<2?"low":e<4?"mid":"high"}var m=e=>typeof e=="string"?e:"";function g(e){let t=/^(m?)([0-5])$|^(low|mid|high)$/.exec(e.trim().toLowerCase());if(!t)return null;let[,r,i="",n]=t;return n?{level:"lmh".indexOf(n.charAt(0))*2+1,mobile:!1}:{level:+i,mobile:!!r}}function w(e){let t=m(e.getParameter(e.RENDERER));if(!t||/^(webkit webgl|mozilla|webgl)$/i.test(t.trim())){let r=e.getExtension("WEBGL_debug_renderer_info");r&&(t=m(e.getParameter(r.UNMASKED_RENDERER_WEBGL))||t)}return t}function v(e){let t=u.exec(e);return t?[t[1]?0:1,`rule: ${t[0]}`]:[2,"default"]}function x(e,t){let r=w(t),i=e.env.isTouch&&Math.min(screen.width,screen.height)<820,n,a="url",s=e.gpu?g(e.gpu):null;if(e.gpu&&!s&&e.lib.say("gpu",[e.gpu]),s)({level:n,mobile:i}=s);else{let[e,t]=v(r);n=e<2?e:e+(i?0:2),a=t}let o=n>3;return{level:n,tier:p(n),mobile:i,renderer:r,reason:a,maxTexture:Math.min(t.getParameter(t.MAX_TEXTURE_SIZE),o?4096:2048),textureBudget:(o?192:96)*2**20,wide:(i?void 0:f[n])??1/0}}function y(e){return typeof e=="object"&&e!==null&&"isPerspectiveCamera"in e&&!!e.isPerspectiveCamera}function b(e,t){let{options:r,el:i}=t,{renderer:n}=r,a=n.domElement??null,s=M(i,a),o=z(n),h=o?x(e,o).tier:"high",u=r.pixelBudget??e.options.pixelBudget??12e6,f={host:e,state:t,options:r,renderer:n,camera:r.camera,sizer:a&&a.isConnected&&!i.contains(a)?a:i,adaptive:new l,adapts:(r.adaptive??e.options.adaptive)!==!1,ratioFor:(t,i)=>d({option:r.dpr??e.options.dpr,tier:h,width:t,height:i,budget:u}),frame:S(t,r.scene,r.camera),wanted:Math.max(1,t.wanted),needsSize:!0,width:0,height:0,dpr:0,offs:[]},p={started:!1,done:!r.setup,cleanup:void 0};return C(f),k(f,a),f.offs.push(e.ticker.add(e=>{T(f,p,e)},{phase:"render",order:100})),E(f),j(f,p,()=>{if(r.dispose!==!1){try{n.dispose?.()}catch(t){e.log.error("umber.attach(): renderer.dispose() threw",t)}s&&a?.remove(),a&&!a.isConnected&&c(o)}})}function M(e,t){return!t||t.isConnected?!1:(t.style.display="block",t.style.width="100%",t.style.height="100%",e.appendChild(t),!0)}function z(e){try{return e.getContext?.()??null}catch{return null}}function S(e,t,r){return{time:0,dt:0,ratio:1,frame:0,width:0,height:0,dpr:1,rect:e.tracker.rect,progress:0,velocity:0,reducedMotion:!1,renderer:e.options.renderer,scene:t,camera:r,view:e.view}}function E(e){!e.state.destroyed&&!e.failed&&!e.lost&&e.host.ticker.wake(1)}function R(e,t,r,i){t&&(t.addEventListener(r,i),e.offs.push(()=>{t.removeEventListener(r,i)}))}function C(e){if(typeof ResizeObserver>"u")return;let t=new ResizeObserver(t=>{for(let r of t)r.target===e.sizer&&(e.box={w:r.contentRect.width,h:r.contentRect.height},e.needsSize=!0);E(e)});t.observe(e.sizer),e.offs.push(()=>{t.disconnect()})}function k(e,t){let{state:r}=e;R(e,t,"webglcontextlost",()=>{e.lost=!0,e.drawnOnce=!1,r.setStatus("lost"),r.emit("lost")}),R(e,t,"webglcontextrestored",()=>{e.lost=!1,e.sizeKey=void 0,e.needsSize=!0,e.adaptive.reset(),e.wanted=Math.max(e.wanted,2),r.emit("restored"),E(e)}),R(e,typeof document<"u"?document:null,"visibilitychange",()=>{document.hidden||(e.adaptive.rest(30),E(e))}),e.offs.push(r.tracker.on("enter",()=>{E(e)}))}function P(e,t,r){e.failed||(e.failed=!0,e.host.log.error(`umber.attach(): ${t} threw; Umber stopped drawing this view (its element stays as it is).`,r),e.state.setStatus("error",t))}function $(e,t,r){let{state:i,renderer:n,camera:a}=e,s;try{s=r({el:i.el,renderer:n,scene:e.frame.scene,camera:a,view:i.view})}catch(t){P(e,"setup",t);return}Promise.resolve(s).then(r=>{let n=typeof r=="function"?r:void 0;if(i.destroyed){_(e,n);return}t.cleanup=n,t.done=!0,E(e)},t=>{P(e,"setup",t)})}function _(e,t){try{t?.()}catch(t){e.host.log.error("umber.attach(): the setup cleanup threw",t)}}function B(e){let t=getComputedStyle(e),r=e=>parseFloat(e)||0,i=e.clientWidth-r(t.paddingLeft)-r(t.paddingRight),n=e.clientHeight-r(t.paddingTop)-r(t.paddingBottom);return{w:Math.max(0,i),h:Math.max(0,n)}}function L(e,t){let{host:r,state:i}=e,n=e.frame;return n.time=t.time,n.dt=t.dt,n.ratio=t.ratio,n.frame=t.frame,n.width=e.width,n.height=e.height,n.dpr=e.dpr,n.rect=i.tracker.rect,n.progress=i.tracker.progress,n.velocity=t.scroll.velocity,n.reducedMotion=r.options.reducedMotion!=="off"&&r.env.reducedMotion,n}function O(e,t){let{renderer:r,camera:i,adaptive:n,options:a}=e;e.needsSize=!1,e.box??=B(e.sizer);let s=Math.round(e.box.w),o=Math.round(e.box.h),d=e.ratioFor(s,o)*(e.adapts?n.scale:1),h=`${s}x${o}@${d}`;if(h===e.sizeKey||(e.sizeKey=h,e.width=s,e.height=o,e.dpr=d,!s||!o))return!1;r.setPixelRatio?.(d),r.setSize?.(s,o,!1),a.aspect!==!1&&y(i)&&(i.aspect=s/o,i.updateProjectionMatrix?.()),n.onResize();try{a.resize?.(L(e,t))}catch(t){return P(e,"resize",t),!1}return e.state.emit("resize"),!0}function Y(e,t){let{options:r}=e,i=L(e,t);try{let t=r.animate?.(i);e.keep=t===!0&&!i.reducedMotion,r.render?r.render(i):e.renderer.render?.(i.scene,i.camera)}catch(t){P(e,r.render?"render":"animate",t);return}e.drawnOnce||(e.drawnOnce=!0,e.state.setStatus("ready")),e.adapts&&e.adaptive.frame(t,!1,-1,!1)&&(e.needsSize=!0,e.host.log.info(`umber.attach(): render scale ${e.adaptive.scale}`))}function A(e,t){let{state:r}=e;if(r.destroyed||e.failed||e.lost||!r.tracker.near)return!1;let i=e.options.setup;return i&&!t.started?(t.started=!0,$(e,t,i),!1):!t.done||typeof document<"u"&&document.hidden?!1:r.tracker.inView}function T(e,t,r){if(!A(e,t))return;let i=e.needsSize&&O(e,r);if(!e.width||!e.height)return;let n=e.state.busy.size>0;(i||e.wanted>0||e.keep||n)&&(e.wanted>0&&e.wanted--,Y(e,r),(e.wanted>0||e.keep||e.state.busy.size>0||e.needsSize)&&E(e))}function j(e,t,r){let{state:i,sizer:n}=e;return{wake(t){e.wanted=Math.max(e.wanted,t),E(e)},busy(){E(e)},get width(){return e.width},get height(){return e.height},get dpr(){return e.dpr},frame(){if(n===i.el)return null;let e=n.getBoundingClientRect();return{left:e.left,top:e.top,width:e.width,height:e.height}},destroy(){e.offs.forEach(e=>{e()}),e.offs.length=0,_(e,t.cleanup),t.cleanup=void 0,r()}}}function K(e,t){return n(e.log),b(e,t)}export{K as attach};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.3.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 r=typeof e.className=="string"?e.className.trim().split(/\s+/)[0]:"";return r?`<${t}.${r}>`:`<${t}>`}var r=2;function o(e,t){let o="",a=r+1;for(let r of t){let t=n(e.toLowerCase(),r.toLowerCase());t<a&&(o=r,a=t)}return o}function n(t,r){let o=Array.from({length:r.length+1},(e,t)=>t);for(let n=1;n<=t.length;n++){let a=n-1;o[0]=n;for(let l=1;l<=r.length;l++){let i=e(o,l);o[l]=Math.min(i+1,e(o,l-1)+1,a+(t[n-1]===r[l-1]?0:1)),a=i}}return e(o,r.length)}var a={image:["plane","core"],video:["plane","core"],text:["plane","core"],shader:["plane","core"],layer:["plane","core"],model:["plane","three"],group:["plane","core"],wrapper:["kind","router"],container:["kind","router"],scroller:["kind","core"],pin:["long","scrollfx"],horizontal:["behaviour","scrollfx"],inview:["long","scrollfx"],above:["behaviour","core"],skip:["behaviour","router"],nested:["behaviour","scroll"]},l=e=>Object.hasOwn(a,e)?a[e]:void 0,i=e=>e==="plane"||e==="kind";var s=Object.keys(a),u=s.filter(e=>i(l(e)?.[0])),d=Object.entries(a).flatMap(([e,[t,r]])=>t==="long"?[{word:e,owner:r}]:[]),h=["[data-umber]",...d.map(({word:e})=>`[data-umber-${e}]`)].join(),$=e=>`Load it with data-umber-modules="${e}" on the umber.js tag, or umber.use() it from "@occluze/umber/${e}".`;function c(e,r,n){let a=`data-umber="${r}" on ${t(e)}`,d=r.split(/\s+/).filter(Boolean);if(!d.length)return[`data-umber on ${t(e)} says nothing: name what it is (${u.join(", ")}) or how it behaves.`];let h=[],c=d.filter(e=>i(l(e)?.[0]));c.length>1&&h.push(`${a} names ${c.length} kinds (${c.join(", ")}): an element is one. Keep one.`);for(let e of d){let t=l(e)?.[1];if(t)t!=="core"&&!n.has(t)&&h.push(`${a}: "${e}" is the ${t} add-on's, which isn't loaded. ${$(t)}`);else{let t=o(e,s);h.push(`${a}: "${e}" is not a word Umber knows${t?` (did you mean "${t}"?)`:""}. The words: ${s.join(", ")}. A setting has its own attribute, data-umber-${e}="...".`)}}return h}function m(e,r,o){let n=[],a=t(e),l=(r??"").split(/\s+/);for(let{word:t,owner:i}of d){let s=e.getAttribute(`data-umber-${t}`);s!==null&&(s.trim()?l.includes(t)?n.push(`data-umber="${r}" and data-umber-${t}="${s}" on ${a} say the same: keep data-umber-${t}="${s}" alone.`):o.has(i)||n.push(`data-umber-${t} on ${a} is the ${i} add-on's, which isn't loaded. ${$(i)}`):n.push(`data-umber-${t} on ${a} has no value: without one, write data-umber="${t}".`))}return n}function f(e,t){let r=[];for(let o of e){if(!o.isConnected)continue;let e=o.matches(h)?[o,...o.querySelectorAll(h)]:o.querySelectorAll(h);for(let o of e){let e=o.getAttribute("data-umber"),n=[...e===null?[]:c(o,e,t),...m(o,e,t)];for(let e of n)r.push([e,o])}}return r}export{f as checkWords};
|
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.3.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 a(e){n=e}var i="model",l=e=>e===i?"layer":e;var s=(e,t)=>e[t]??NaN;var o=e=>t=>Math.pow(t,e),u={quad:o(2),cubic:o(3),quart:o(4),quint:o(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 c="umber";var h={duration:1.4,delay:0,ease:c,start:"top 90%",trigger:"auto",repeat:""};function d(e){let t=[],r=e??"",n=/[\s,]*(\S+)([^,]*)/g;for(let e=n.exec(r);e;e=n.exec(r)){let[r,a,i=""]=e;if(!a)break;let l=a.replace(/,+$/,"");l!==a&&(n.lastIndex=e.index+r.indexOf(a)+a.length),t.push([l,l!==a?"1x":i.trim()||"1x"])}return t}function g(e){let t=/^calc\((.+)\)$/.exec(e)?.[1];if(t!==void 0){let[e="",...r]=t.trim().split(/\s+([+-])\s+/),n=g(e);for(let e=0;e<r.length;e+=2)n+=(r[e]==="-"?-1:1)*g(r[e+1]??"");return n}let r=/^([\d.]+)(vw|px|r?em)$/.exec(e);if(!r)return innerWidth;let[,n="",a]=r,i=Number(n);return a==="vw"?innerWidth*i/100:a==="px"?i:i*16}function f(e){for(let t of p(e)){let e=m(t),r=e>0?t.slice(0,e):"";if(t&&(!r||matchMedia(r).matches))return g(t.slice(e+1))}return innerWidth}function p(e){let t=[],r=0,n=0;for(let a=0;a<=e.length;a++){let i=e.charAt(a);i==="("?r++:i===")"?r--:!r&&(i===","||a===e.length)&&(t.push(e.slice(n,a).trim()),n=a+1)}return t}function m(e){let t=-1;for(let r=0,n=0;r<e.length;r++){let a=e.charAt(r);a==="("?n++:a===")"?n--:!n&&/\s/.test(a)&&(t=r)}return t}function b(e){let t=e.ownerDocument.baseURI||document.baseURI,r=e=>e?new URL(e,t).href:"",n=d(e.getAttribute("srcset")).map(([e,t])=>({url:e,size:parseFloat(t)||1,width:t.endsWith("w")})),a=e.getAttribute("src");a&&!n.some(e=>e.width||e.size===1)&&n.push({url:a,size:1,width:!1});let[i]=n;if(!i)return"";let l=window.devicePixelRatio||1,s=l;return i.width&&(s=f(e.getAttribute("sizes")??"")*l),n.sort((e,t)=>e.size-t.size),r((n.find(e=>e.size>=s)??n.at(-1)??i).url)}function v(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 w(e,t,r=0){let n=navigator.connection;if(n?.saveData||(n?.effectiveType??"").includes("2g"))return()=>{};let a=new Set,i=null,l,s=0,o=0,u=0,c=()=>{let e=i?v(i):"";if(e&&!a.has(e)){a.add(e);let n=()=>r&&setTimeout(()=>a.delete(e),r);Promise.resolve(t(e)).then(n,n)}},h=()=>{clearTimeout(l),l=setTimeout(c,65)},d=t=>{let r=t,n=r.target.closest(e),a=n instanceof HTMLAnchorElement||n instanceof HTMLAreaElement?n:null;a!==i&&(clearTimeout(l),i=a,i&&(s=r.clientX,o=r.clientY,u=r.timeStamp,r.pointerType&&r.pointerType!=="mouse"?c():h()))},g=e=>{let t=e,r=t.timeStamp-u;if(!i||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&&h()},f=e=>{e.relatedTarget||(clearTimeout(l),i=null)},p={passive:!0};return document.addEventListener("pointerover",d,p),document.addEventListener("pointermove",g,p),document.addEventListener("pointerout",f,p),()=>{clearTimeout(l),document.removeEventListener("pointerover",d),document.removeEventListener("pointermove",g),document.removeEventListener("pointerout",f)}}var y=6;function x(e,t,r){let n=[t-1<<4|r-1],a=-1;for(let i=0;i<t*r*4;i++){if((i&3)===3)continue;let t=Math.round(s(e,i)/17);a<0?a=t:(n.push(a<<4|t),a=-1)}return a>=0&&n.push(a<<4),btoa(String.fromCharCode(...n)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function k(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 a=new Uint8ClampedArray(r*n*4);for(let e=0,r=0;e<a.length;e++)if((e&3)===3)a[e]=255;else{let n=t.charCodeAt(1+(r>>1));a[e]=(r++&1?n&15:n>>4)*17}return{w:r,h:n,data:a}}function M(e){let t=k(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 A=()=>{let e=typeof window<"u"?window.occluzeCapture:void 0;return e?.version===1?e:null},I=()=>new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=e,t.port2.postMessage(0)});var S=2e4,L=8e3,T=/^data:image\/|\.(avif|webp|jpe?g|png|gif|svg)([?#]|$)/i,z=()=>A()?I():new Promise(e=>"requestIdleCallback"in window?requestIdleCallback(()=>{e()},{timeout:300}):setTimeout(e,16)),E=e=>e.ownerDocument!==document||!e.isConnected,R=class{constructor(e){this.stage=e;this.buf=null;this.runs=0;this.gc=null;e.env.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.all.filter(e=>e.kind!=="layer"&&e.status!=="error"&&(!n||n.contains(e.el))).map(e=>this.fx().then(t=>t?.Nc(e).then(t=>t?this.draw(e):void 0))))}pick(e){return b(e)}async placeholder(e){let t=this.stage,r=typeof e=="string"?null:e,n=r&&(this.stage.env.lib.findMedia(r)??r),a=typeof e=="string"?e:n&&(n.currentSrc||b(n));if(!a)return null;try{let e=await t.env.kit.bitmap(a,t.gpu.tier.maxTexture),r=y/Math.max(e.width,e.height),n=Math.max(1,Math.round(e.width*r)),i=Math.max(1,Math.round(e.height*r)),l=await createImageBitmap(e,{resizeWidth:n,resizeHeight:i,resizeQuality:"high"});"close"in e&&e.close();let s=document.createElement("canvas");s.width=n,s.height=i;let o=s.getContext("2d");return o?(o.drawImage(l,0,0),l.close(),x(o.getImageData(0,0,n,i).data,n,i)):null}catch(e){return this.stage.env.lib.say("placeholderRead",[a],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=M(r);if(!n){this.stage.env.lib.say("placeholder",[r],e);return}let a=t.style;a.backgroundImage=`url(${n})`,a.backgroundSize="cover",a.backgroundPosition="center";let i=()=>{a.backgroundImage="",a.backgroundSize="",a.backgroundPosition=""};t.addEventListener("load",i,{once:!0})}note(e,t){let r=this.stage,[n=0,a=0,i=0,l=0]=t;if(e){r.env.lib.say("imageSize",[e,i,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,a>>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.bc(e,t),t}bc(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.bc(r,t);else if(typeof e=="object"&&"querySelectorAll"in e)this.lg(e,t);else if(typeof e=="object"){let r=e,n=typeof r.url=="object"?r.url.href:r.url;this.bc(r.container??(r.html?C(r.html,document.baseURI):void 0)??n,t)}}}address(e){return T.test(e)?this.image(e):this.page(e).then(e=>e&&this.run({},this.collect(e)))}lg(e,t){for(let r of this.stage.env.lib.findGL(e))t.push(this.element(r))}page(e){return fetch(e,{credentials:"same-origin"}).then(e=>e.ok?e.text():"").then(t=>t?C(t,e):null).catch(t=>(n.info("preload: page not fetched",e,t),null))}async element(e){let t=this.stage,r=this.stage.env.lib.findMedia(e);e.hasAttribute("data-umber-placeholder")&&E(e)&&this.paint(e);let n=this.ah(e,r),a=this.recipe(e);if(!a||!t.gpu.programs.prepare(a))return n;let i=a.program;if(!i)return n;let l=await P(()=>i.ready()||i.failed,t);if(i.failed){t.gpu.programs.failed(a,t.planes.all);return}a.texture=await n??null,l&&await this.draw(a)}Vh(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()}ah(e,t){if(/^(shader|text|layer|video)$/.test(this.stage.env.lib.kindOf(e))||t?.tagName!=="IMG")return null;let r=e.getAttribute("data-umber-src");return!r&&t.parentElement?.querySelector("source")?null:this.image((r??"")||b(t),r?new URL(r,e.ownerDocument.baseURI).href:void 0,t)}async image(e,t=e,r){let a=this.stage,i=a.gpu.media.images,l=i.get(e)??i.get(t);if(l)return await P(()=>l.ready,a)?l:null;let s=new a.env.kit.Texture(a.gpu.gl);a.gpu.renderer.reset(),i.set(e,s).set(t,s);let o=()=>{for(let[e,t]of i)t===s&&i.delete(e)};try{let n=r?.getAttribute("sizes"),l=await a.env.kit.bitmap(t,a.gpu.tier.maxTexture,()=>a.gpu.media.cap(s.box,n&&n!=="auto"?f(n):0));if(await z(),a.gpu.context.gone||a.env.destroyed||i.get(e)!==s)return"close"in l&&l.close(),null;s.upload(l),"close"in l&&l.close(),a.gpu.renderer.reset(),a.env.stats.uploads++}catch(e){return n.info("preload: image not loaded",t,e),o(),this.Vh(s),null}for(let e of a.planes.all)e.texture===s&&(e.textureState="ready",e._i(),a.gpu.media.sharpen(e),a.scheduler.markDirty());return setTimeout(()=>{s.refs||i.get(e)!==s||(o(),s.dispose())},S),s}recipe(e){let t=this.stage,r=this.fh(e);if(r==="layer"||t.factory.qc(e).length)return null;let n=new t.env.kit.Plane(e,r,-1,t),a=this.Ye(n,e);if(a===null)return null;let i=r==="shader"?this.bf(n,e):"";if(i===null)return null;let l=a+i;return n._L(l),l.includes("uBackdrop")&&(n.backdrop={texture:null},t.factory.ba(n,{uBackdrop:n.backdrop})),n.glsl&&!t.gpu.programs.glsl||(n._k||r==="text")&&!t.chunks.text?null:n}fh(e){return l(this.stage.env.lib.kindOf(e)||"image")}Ye(e,t){let r=this.stage,n="";for(let a of this.stage.env.lib.attr.list(t,"data-umber-effect")){let i=r.env.registry.effects.get(a);if(!i)return null;let l=i.play??"",s=i.options??{},o=r.env.lib.config(t,`data-umber-${a}`,l?{...h,...s}:s);r.factory.ba(e,i.uniforms??{}),l&&!e._o(l)&&r.factory.ba(e,{[l]:0}),r.factory.db(e,a,o),i.reduced&&r.env.reducedMotion&&r.factory.ba(e,i.reduced),e.segments=Math.max(e.segments,i.segments??1),n+=JSON.stringify([i.vertex,i.fragment]),e.effects.push({name:a,def:i,options:o,ctx:null})}return n}bf(e,t){let r=this.stage,n=t.getAttribute("data-umber-shader")??"",a=r.env.registry.shaders.get(n);if(!a)return null;let i=r.env.lib.config(t,"data-umber-shader",a.options??{});return r.factory.ba(e,a.uniforms??{}),r.factory.db(e,"",i),e.shader={name:n,def:a,options:i,ctx:null},a.fragment+(a.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}),a=e.rect,i=a.slice();a[2]>0&&a[3]>0||a.set([0,0,4,4]),e.size[0]>0||e.size.set([a[2],a[3]]);try{r.into(n,a,()=>{t.gpu.renderer.Ia(e,!0)})}finally{a.set(i)}}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.gc?.();let t=this.gc=e?w(typeof e=="string"?e:"a[href]",e=>this.run({},this.collect(e)),S):null;return t&&(()=>{this.gc===t&&this.hover(!1)})}};function C(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 P(e,t){let r=performance.now();return new Promise(n=>{let a=()=>{e()?n(!0):t.env.destroyed||performance.now()-r>L?n(!1):setTimeout(a,30)};a()})}function U(e){return a(e.env.host.log),new R(e)}export{S as KEEP_MS,R as Warm,E as ahead,U as warm};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
function e(e){return(e??globalThis.__umber?.engine)?.scroll??null}function t(t){let r=()=>{e(t)?.stop()},n=()=>{let r=e(t);r?.start(),r?.resize()};return document.addEventListener("astro:before-swap",r),document.addEventListener("astro:after-swap",n),()=>{document.removeEventListener("astro:before-swap",r),document.removeEventListener("astro:after-swap",n)}}export{t as astroScroll};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
import{useEffect as e,useState as l}from"react";function r(e){return(e??globalThis.__umber?.engine)?.scroll??null}function t(t,n=[],o){let[u,s]=l(null);return e(()=>{let e=r(o);return s(e),t&&e?e.on("scroll",t):void 0},[o,...n]),u}export{t as useScroll};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! Umber v0.3.0 | (c) Ravi Klaassens | UNLICENSED */
|
|
2
|
+
import{onBeforeUnmount as l,onMounted as n,shallowRef as o}from"vue";function e(l){return(l??globalThis.__umber?.engine)?.scroll??null}function u(u,r){let s=o(null),t;return n(()=>{s.value=e(r),u&&(t=s.value?.on("scroll",u))}),l(()=>{t?.()}),s}export{u as useScroll};
|