textmode.synth.js 1.0.0-beta.1 → 1.0.0-beta.3
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 +661 -0
- package/README.md +104 -121
- package/dist/textmode.synth.esm.js +491 -410
- package/dist/textmode.synth.umd.js +31 -52
- package/dist/types/api/index.d.ts +7 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/sources.d.ts +327 -0
- package/dist/types/api/sources.d.ts.map +1 -0
- package/dist/types/augmentations/index.d.ts +7 -0
- package/dist/types/augmentations/index.d.ts.map +1 -0
- package/dist/types/augmentations/textmode.d.ts +65 -0
- package/dist/types/augmentations/textmode.d.ts.map +1 -0
- package/dist/types/bootstrap.d.ts +11 -0
- package/dist/types/bootstrap.d.ts.map +1 -0
- package/dist/types/compiler/ExternalLayerManager.d.ts +60 -0
- package/dist/types/compiler/ExternalLayerManager.d.ts.map +1 -0
- package/dist/types/compiler/FeedbackTracker.d.ts +53 -0
- package/dist/types/compiler/FeedbackTracker.d.ts.map +1 -0
- package/dist/types/compiler/GLSLGenerator.d.ts +2 -2
- package/dist/types/compiler/GLSLGenerator.d.ts.map +1 -1
- package/dist/types/compiler/SynthCompiler.d.ts +7 -1
- package/dist/types/compiler/SynthCompiler.d.ts.map +1 -1
- package/dist/types/compiler/TransformCodeGenerator.d.ts +77 -0
- package/dist/types/compiler/TransformCodeGenerator.d.ts.map +1 -0
- package/dist/types/compiler/UniformManager.d.ts.map +1 -1
- package/dist/types/compiler/index.d.ts +14 -3
- package/dist/types/compiler/index.d.ts.map +1 -1
- package/dist/types/compiler/types.d.ts +7 -7
- package/dist/types/compiler/types.d.ts.map +1 -1
- package/dist/types/core/GlobalState.d.ts +30 -0
- package/dist/types/core/GlobalState.d.ts.map +1 -0
- package/dist/types/core/ISynthSource.d.ts +173 -202
- package/dist/types/core/ISynthSource.d.ts.map +1 -1
- package/dist/types/core/SynthChain.d.ts +0 -2
- package/dist/types/core/SynthChain.d.ts.map +1 -1
- package/dist/types/core/SynthSource.d.ts +4 -3
- package/dist/types/core/SynthSource.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +9 -3
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +57 -4
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/extensions/index.d.ts +10 -0
- package/dist/types/extensions/index.d.ts.map +1 -0
- package/dist/types/extensions/textmodelayer.d.ts +22 -0
- package/dist/types/extensions/textmodelayer.d.ts.map +1 -0
- package/dist/types/extensions/textmodifier.d.ts +11 -0
- package/dist/types/extensions/textmodifier.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -364
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lifecycle/index.d.ts +10 -0
- package/dist/types/lifecycle/index.d.ts.map +1 -0
- package/dist/types/lifecycle/synthDispose.d.ts +11 -0
- package/dist/types/lifecycle/synthDispose.d.ts.map +1 -0
- package/dist/types/lifecycle/synthRender.d.ts +11 -0
- package/dist/types/lifecycle/synthRender.d.ts.map +1 -0
- package/dist/types/{SynthPlugin.d.ts → plugin/SynthPlugin.d.ts} +1 -1
- package/dist/types/plugin/SynthPlugin.d.ts.map +1 -0
- package/dist/types/plugin/constants.d.ts +5 -0
- package/dist/types/plugin/constants.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +10 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/transforms/TransformDefinition.d.ts +0 -12
- package/dist/types/transforms/TransformDefinition.d.ts.map +1 -1
- package/dist/types/transforms/TransformFactory.d.ts +4 -7
- package/dist/types/transforms/TransformFactory.d.ts.map +1 -1
- package/dist/types/transforms/TransformRegistry.d.ts +3 -6
- package/dist/types/transforms/TransformRegistry.d.ts.map +1 -1
- package/dist/types/transforms/categories/colors.d.ts +1 -1
- package/dist/types/transforms/categories/colors.d.ts.map +1 -1
- package/dist/types/transforms/categories/combine.d.ts.map +1 -1
- package/dist/types/transforms/categories/index.d.ts +3 -4
- package/dist/types/transforms/categories/index.d.ts.map +1 -1
- package/dist/types/transforms/categories/sources.d.ts.map +1 -1
- package/dist/types/{lib → utils}/ArrayUtils.d.ts +20 -5
- package/dist/types/utils/ArrayUtils.d.ts.map +1 -0
- package/dist/types/utils/CharacterResolver.d.ts.map +1 -1
- package/dist/types/utils/collectExternalLayerRefs.d.ts +7 -0
- package/dist/types/utils/collectExternalLayerRefs.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +12 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +16 -9
- package/dist/types/SynthPlugin.d.ts.map +0 -1
- package/dist/types/lib/ArrayUtils.d.ts.map +0 -1
- package/dist/types/transforms/categories/charModifiers.d.ts +0 -16
- package/dist/types/transforms/categories/charModifiers.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(g,
|
|
2
|
-
${
|
|
3
|
-
${
|
|
4
|
-
}`;return{...
|
|
1
|
+
(function(g,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):T((g=typeof globalThis<"u"?globalThis:g||self).TextmodeSynth={})})(this,function(g){"use strict";const T={src:{returnType:"vec4",args:[{type:"vec2",name:"_st"}]},coord:{returnType:"vec2",args:[{type:"vec2",name:"_st"}]},color:{returnType:"vec4",args:[{type:"vec4",name:"_c0"}]},combine:{returnType:"vec4",args:[{type:"vec4",name:"_c0"},{type:"vec4",name:"_c1"}]},combineCoord:{returnType:"vec2",args:[{type:"vec2",name:"_st"},{type:"vec4",name:"_c0"}]}},L=new class{_transforms=new Map;_processedCache=new Map;register(t){this._transforms.has(t.name)&&console.warn(`[TransformRegistry] Overwriting existing transform: ${t.name}`),this._transforms.set(t.name,t),this._processedCache.delete(t.name)}registerMany(t){for(const e of t)this.register(e)}get(t){return this._transforms.get(t)}getProcessed(t){let e=this._processedCache.get(t);if(!e){const r=this._transforms.get(t);r&&(e=(function(a){const n=T[a.type],o=[...n.args,...a.inputs.map(s=>({type:s.type,name:s.name}))].map(s=>`${s.type} ${s.name}`).join(", "),c=`
|
|
2
|
+
${n.returnType} ${a.name}(${o}) {
|
|
3
|
+
${a.glsl}
|
|
4
|
+
}`;return{...a,glslFunction:c}})(r),this._processedCache.set(t,e))}return e}has(t){return this._transforms.has(t)}getByType(t){return Array.from(this._transforms.values()).filter(e=>e.type===t)}getNames(){return Array.from(this._transforms.keys())}getAll(){return Array.from(this._transforms.values())}getSourceTransforms(){return this.getByType("src")}remove(t){return this._processedCache.delete(t),this._transforms.delete(t)}clear(){this._transforms.clear(),this._processedCache.clear()}get size(){return this._transforms.size}},Y=new Set(["src"]),B=new class{_generatedFunctions={};_synthSourceClass=null;setSynthSourceClass(t){this._synthSourceClass=t}injectMethods(t){const e=L.getAll();for(const r of e)this._injectMethod(t,r)}_injectMethod(t,e){const{name:r,inputs:a,type:n}=e;t[r]=n==="combine"||n==="combineCoord"?function(o,...c){const s=a.map((l,f)=>c[f]??l.default);return this.addCombineTransform(r,o,s)}:function(...o){const c=a.map((s,l)=>o[l]??s.default);return this.addTransform(r,c)}}generateStandaloneFunctions(){if(!this._synthSourceClass)throw new Error("[TransformFactory] SynthSource class not set. Call setSynthSourceClass first.");const t={},e=L.getAll(),r=this._synthSourceClass;for(const a of e)if(Y.has(a.type)){const{name:n,inputs:o}=a;t[n]=(...c)=>{const s=new r,l=o.map((f,m)=>c[m]??f.default);return s.addTransform(n,l)}}return this._generatedFunctions=t,t}getGeneratedFunctions(){return this._generatedFunctions}addTransform(t,e){if(L.register(t),e&&this._injectMethod(e,t),Y.has(t.type)&&this._synthSourceClass){const r=this._synthSourceClass,{name:a,inputs:n}=t;this._generatedFunctions[a]=(...o)=>{const c=new r,s=n.map((l,f)=>o[f]??l.default);return c.addTransform(a,s)}}}},E=[{name:"osc",type:"src",inputs:[{name:"frequency",type:"float",default:60},{name:"sync",type:"float",default:.1},{name:"offset",type:"float",default:0}],glsl:`
|
|
5
5
|
vec2 st = _st;
|
|
6
6
|
float r = sin((st.x - offset/frequency + time*sync) * frequency) * 0.5 + 0.5;
|
|
7
7
|
float g = sin((st.x + time*sync) * frequency) * 0.5 + 0.5;
|
|
@@ -44,7 +44,7 @@ ${n.glsl}
|
|
|
44
44
|
`,description:"Generate polygon shape"},{name:"solid",type:"src",inputs:[{name:"r",type:"float",default:0},{name:"g",type:"float",default:0},{name:"b",type:"float",default:0},{name:"a",type:"float",default:1}],glsl:`
|
|
45
45
|
return vec4(r, g, b, a);
|
|
46
46
|
`,description:"Generate solid color"},{name:"src",type:"src",inputs:[],glsl:`
|
|
47
|
-
return texture(
|
|
47
|
+
return texture(prevCharColorBuffer, fract(_st));
|
|
48
48
|
`,description:"Sample the previous frame for feedback effects. Context-aware: automatically samples the appropriate texture based on where it is used (char, charColor, or cellColor context)."},{name:"rotate",type:"coord",inputs:[{name:"angle",type:"float",default:10},{name:"speed",type:"float",default:0}],glsl:`
|
|
49
49
|
vec2 xy = _st - vec2(0.5);
|
|
50
50
|
float ang = angle + speed * time;
|
|
@@ -151,7 +151,7 @@ ${n.glsl}
|
|
|
151
151
|
v = pow(v, vec3(1.0 / gamma));
|
|
152
152
|
v = mix(vec3(outMin), vec3(outMax), v);
|
|
153
153
|
return vec4(v, _c0.a);
|
|
154
|
-
`,description:"Adjust input/output levels and gamma"},{name:"
|
|
154
|
+
`,description:"Adjust input/output levels and gamma"},{name:"clamp",type:"color",inputs:[{name:"min",type:"float",default:0},{name:"max",type:"float",default:1}],glsl:`
|
|
155
155
|
return vec4(clamp(_c0.rgb, vec3(min), vec3(max)), _c0.a);
|
|
156
156
|
`,description:"Clamp color values to a range"},{name:"add",type:"combine",inputs:[{name:"amount",type:"float",default:1}],glsl:`
|
|
157
157
|
return (_c0 + _c1) * amount + _c0 * (1.0 - amount);
|
|
@@ -215,42 +215,29 @@ ${n.glsl}
|
|
|
215
215
|
return fract(st);
|
|
216
216
|
`,description:"Modulate Y repeat with another source"},{name:"modulateHue",type:"combineCoord",inputs:[{name:"amount",type:"float",default:1}],glsl:`
|
|
217
217
|
return _st + (vec2(_c0.g - _c0.r, _c0.b - _c0.g) * amount * 1.0 / resolution);
|
|
218
|
-
`,description:"Modulate coordinates based on hue differences"},{name:"
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
flags = flags | 4;
|
|
228
|
-
}
|
|
229
|
-
return vec4(_char.rg, float(flags) / 255.0, _char.a);
|
|
230
|
-
`,description:"Flip characters vertically"},{name:"charInvert",type:"charModify",inputs:[{name:"toggle",type:"float",default:1}],glsl:`
|
|
231
|
-
int flags = int(_char.b * 255.0 + 0.5);
|
|
232
|
-
if (toggle > 0.5) {
|
|
233
|
-
flags = flags | 1;
|
|
234
|
-
}
|
|
235
|
-
return vec4(_char.rg, float(flags) / 255.0, _char.a);
|
|
236
|
-
`,description:"Invert character colors"},{name:"charRotate",type:"charModify",inputs:[{name:"angle",type:"float",default:.25},{name:"speed",type:"float",default:0}],glsl:`
|
|
237
|
-
float rotation = fract(angle + time * speed);
|
|
238
|
-
return vec4(_char.rgb, rotation);
|
|
239
|
-
`,description:"Rotate characters"}];class M{_transforms;constructor(e){this._transforms=e}static empty(){return new M([])}static from(e){return new M([...e])}get transforms(){return this._transforms}push(e){this._transforms.push(e)}get length(){return this._transforms.length}get isEmpty(){return this._transforms.length===0}append(e){return new M([...this._transforms,e])}get(e){return this._transforms[e]}[Symbol.iterator](){return this._transforms[Symbol.iterator]()}}class C{_chain;_charMapping;_nestedSources;_externalLayerRefs;_colorSource;_cellColorSource;_charSource;_charCount;constructor(e){this._chain=e?.chain??M.empty(),this._charMapping=e?.charMapping,this._colorSource=e?.colorSource,this._cellColorSource=e?.cellColorSource,this._charSource=e?.charSource,this._charCount=e?.charCount,this._nestedSources=e?.nestedSources??new Map,this._externalLayerRefs=e?.externalLayerRefs??new Map}addTransform(e,a){const n={name:e,userArgs:a};return this._chain.push(n),this}addCombineTransform(e,a,n){const r=this._chain.length;return this._nestedSources.set(r,a),this.addTransform(e,n)}addExternalLayerRef(e){const a=this._chain.length;return this._externalLayerRefs.set(a,e),this.addTransform("src",[])}charMap(e){const a=Array.from(e),n=[];for(const r of a)n.push(r.codePointAt(0)??32);return this._charMapping={chars:e,indices:n},this}charColor(e){return this._colorSource=e,this}char(e,a){return this._charSource=e,this._charCount=a,this}cellColor(e){return this._cellColorSource=e,this}paint(e){return this._colorSource=e,this._cellColorSource=e,this}clone(){const e=new Map;for(const[n,r]of this._nestedSources)e.set(n,r.clone());const a=new Map;for(const[n,r]of this._externalLayerRefs)a.set(n,{...r});return new C({chain:M.from(this._chain.transforms),charMapping:this._charMapping,colorSource:this._colorSource?.clone(),cellColorSource:this._cellColorSource?.clone(),charSource:this._charSource?.clone(),charCount:this._charCount,nestedSources:e,externalLayerRefs:a})}get transforms(){return this._chain.transforms}get charMapping(){return this._charMapping}get colorSource(){return this._colorSource}get cellColorSource(){return this._cellColorSource}get charSource(){return this._charSource}get charCount(){return this._charCount}get nestedSources(){return this._nestedSources}get externalLayerRefs(){return this._externalLayerRefs}}const Y={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>t*(2-t),easeInOutQuad:t=>t<.5?2*t*t:(4-2*t)*t-1,easeInCubic:t=>t*t*t,easeOutCubic:t=>--t*t*t+1,easeInOutCubic:t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,easeInQuart:t=>t*t*t*t,easeOutQuart:t=>1- --t*t*t*t,easeInOutQuart:t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t,easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>1+--t*t*t*t*t,easeInOutQuint:t=>t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t,sin:t=>(1+Math.sin(Math.PI*t-Math.PI/2))/2};function V(t,e){return(t%e+e)%e}class D{_uniforms=new Map;_dynamicUpdaters=new Map;processArgument(e,a,n){if((function(r){return Array.isArray(r)&&r.length>0&&typeof r[0]=="number"})(e)){const r=`${n}_${a.name}`,o={name:r,type:a.type,value:a.default??0,isDynamic:!0},u=i=>(function(s,f){const h=s._speed??1,p=s._smooth??0;let d=f.time*h*1+(s._offset??0);if(p!==0){const _=s._ease??Y.linear,m=d-p/2,y=s[Math.floor(V(m,s.length))],c=s[Math.floor(V(m+1,s.length))];return _(Math.min(V(m,1)/p,1))*(c-y)+y}return s[Math.floor(V(d,s.length))]})(e,i);return this._uniforms.set(r,o),this._dynamicUpdaters.set(r,u),{glslValue:r,uniform:o,updater:u}}if(typeof e=="function"){const r=`${n}_${a.name}`,o={name:r,type:a.type,value:a.default??0,isDynamic:!0};return this._uniforms.set(r,o),this._dynamicUpdaters.set(r,e),{glslValue:r,uniform:o,updater:e}}if(typeof e=="number")return{glslValue:x(e)};if(Array.isArray(e)&&typeof e[0]=="number"){const r=e;if(r.length===2)return{glslValue:`vec2(${x(r[0])}, ${x(r[1])})`};if(r.length===3)return{glslValue:`vec3(${x(r[0])}, ${x(r[1])}, ${x(r[2])})`};if(r.length===4)return{glslValue:`vec4(${x(r[0])}, ${x(r[1])}, ${x(r[2])}, ${x(r[3])})`}}return this.processDefault(a)}processDefault(e){const a=e.default;return typeof a=="number"?{glslValue:x(a)}:Array.isArray(a)?{glslValue:`vec${a.length}(${a.map(x).join(", ")})`}:{glslValue:"0.0"}}getUniforms(){return new Map(this._uniforms)}getDynamicUpdaters(){return new Map(this._dynamicUpdaters)}clear(){this._uniforms.clear(),this._dynamicUpdaters.clear()}}function x(t){const e=t.toString();return e.includes(".")?e:e+".0"}function B(t){return new q().compile(t)}class q{_varCounter=0;_uniformManager=new D;_glslFunctions=new Set;_mainCode=[];_usesFeedback=!1;_usesCharFeedback=!1;_usesCellColorFeedback=!1;_currentTarget="main";_externalLayers=new Map;_externalLayerCounter=0;_layerIdToPrefix=new Map;compile(e){this._varCounter=0,this._uniformManager.clear(),this._glslFunctions.clear(),this._mainCode.length=0,this._usesFeedback=!1,this._usesCharFeedback=!1,this._usesCellColorFeedback=!1,this._externalLayers.clear(),this._externalLayerCounter=0,this._layerIdToPrefix.clear();const a=this._compileChain(e,"main","vec4(1.0, 1.0, 1.0, 1.0)","v_uv","main");let n,r=a.charVar;if(e.charSource){const f=this._compileChain(e.charSource,"charSrc","vec4(1.0, 1.0, 1.0, 1.0)","v_uv","char");r="charFromSource_"+this._varCounter++,n=e.charCount??256,this._mainCode.push(" // Convert charSource color to character index"),this._mainCode.push(` float charLum_${r} = _luminance(${f.colorVar}.rgb);`),this._mainCode.push(` int charIdx_${r} = int(charLum_${r} * ${n.toFixed(1)});`),this._mainCode.push(` vec4 ${r} = vec4(float(charIdx_${r} % 256) / 255.0, float(charIdx_${r} / 256) / 255.0, 0.0, 0.0);`)}let o=a.colorVar;e.colorSource&&(o=this._compileChain(e.colorSource,"charColor","vec4(1.0, 1.0, 1.0, 1.0)","v_uv","charColor").colorVar);let u="vec4(0.0, 0.0, 0.0, 0.0)";e.cellColorSource&&(u=this._compileChain(e.cellColorSource,"cellColor","vec4(0.0, 0.0, 0.0, 0.0)","v_uv","cellColor").colorVar);const i=(function(f,h,p){return f?`
|
|
218
|
+
`,description:"Modulate coordinates based on hue differences"}];class k{_transforms;constructor(e){this._transforms=e}static empty(){return new k([])}static from(e){return new k([...e])}get transforms(){return this._transforms}push(e){this._transforms.push(e)}get length(){return this._transforms.length}get isEmpty(){return this._transforms.length===0}append(e){return new k([...this._transforms,e])}get(e){return this._transforms[e]}[Symbol.iterator](){return this._transforms[Symbol.iterator]()}}class S{_chain;_charMapping;_nestedSources;_externalLayerRefs;_colorSource;_cellColorSource;_charSource;_charCount;constructor(e){this._chain=e?.chain??k.empty(),this._charMapping=e?.charMapping,this._colorSource=e?.colorSource,this._cellColorSource=e?.cellColorSource,this._charSource=e?.charSource,this._charCount=e?.charCount,this._nestedSources=e?.nestedSources??new Map,this._externalLayerRefs=e?.externalLayerRefs??new Map}addTransform(e,r){const a={name:e,userArgs:r};return this._chain.push(a),this}addCombineTransform(e,r,a){const n=this._chain.length;return this._nestedSources.set(n,r),this.addTransform(e,a)}addExternalLayerRef(e){const r=this._chain.length;return this._externalLayerRefs.set(r,e),this.addTransform("src",[])}charMap(e){const r=Array.from(e),a=[];for(const n of r)a.push(n.codePointAt(0)??32);return this._charMapping={chars:e,indices:a},this}charColor(e){return this._colorSource=e,this}char(e,r){return this._charSource=e,this._charCount=r,this}cellColor(e){return this._cellColorSource=e,this}paint(e){return this._colorSource=e,this._cellColorSource=e,this}clone(){const e=new Map;for(const[a,n]of this._nestedSources)e.set(a,n.clone());const r=new Map;for(const[a,n]of this._externalLayerRefs)r.set(a,{...n});return new S({chain:k.from(this._chain.transforms),charMapping:this._charMapping,colorSource:this._colorSource?.clone(),cellColorSource:this._cellColorSource?.clone(),charSource:this._charSource?.clone(),charCount:this._charCount,nestedSources:e,externalLayerRefs:r})}get transforms(){return this._chain.transforms}get charMapping(){return this._charMapping}get colorSource(){return this._colorSource}get cellColorSource(){return this._cellColorSource}get charSource(){return this._charSource}get charCount(){return this._charCount}get nestedSources(){return this._nestedSources}get externalLayerRefs(){return this._externalLayerRefs}}const R={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>t*(2-t),easeInOutQuad:t=>t<.5?2*t*t:(4-2*t)*t-1,easeInCubic:t=>t*t*t,easeOutCubic:t=>--t*t*t+1,easeInOutCubic:t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,easeInQuart:t=>t*t*t*t,easeOutQuart:t=>1- --t*t*t*t,easeInOutQuart:t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t,easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>1+--t*t*t*t*t,easeInOutQuint:t=>t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t,sin:t=>(1+Math.sin(Math.PI*t-Math.PI/2))/2};function U(t,e){return(t%e+e)%e}"fast"in Array.prototype||(Array.prototype.fast=function(t=1){return this._speed=t,this},Array.prototype.smooth=function(t=1){return this._smooth=t,this},Array.prototype.ease=function(t="linear"){return typeof t=="function"?(this._smooth=1,this._ease=t):R[t]&&(this._smooth=1,this._ease=R[t]),this},Array.prototype.offset=function(t=.5){return this._offset=t%1,this},Array.prototype.fit=function(t=0,e=1){const r=Math.min(...this),a=Math.max(...this),n=this.map(o=>(function(c,s,l,f,m){return(c-s)*(m-f)/(l-s)+f})(o,r,a,t,e));return n._speed=this._speed,n._smooth=this._smooth,n._ease=this._ease,n._offset=this._offset,n}),L.registerMany(E),B.setSynthSourceClass(S),B.injectMethods(S.prototype);const F=B.generateStandaloneFunctions(),w="textmode.synth.js";class q{_usesFeedback=!1;_usesCharFeedback=!1;_usesCellColorFeedback=!1;trackUsage(e){switch(e){case"char":this._usesCharFeedback=!0;break;case"cellColor":this._usesCellColorFeedback=!0;break;default:this._usesFeedback=!0}}reset(){this._usesFeedback=!1,this._usesCharFeedback=!1,this._usesCellColorFeedback=!1}getUsage(){return{usesCharColorFeedback:this._usesFeedback,usesCharFeedback:this._usesCharFeedback,usesCellColorFeedback:this._usesCellColorFeedback}}get usesAnyFeedback(){return this._usesFeedback||this._usesCharFeedback||this._usesCellColorFeedback}get usesCharColorFeedback(){return this._usesFeedback}get usesCharFeedback(){return this._usesCharFeedback}get usesCellColorFeedback(){return this._usesCellColorFeedback}}class G{_externalLayers=new Map;_counter=0;_layerIdToPrefix=new Map;getPrefix(e){let r=this._layerIdToPrefix.get(e);return r||(r="extLayer"+this._counter++,this._layerIdToPrefix.set(e,r)),r}trackUsage(e,r){const a=this.getPrefix(e.layerId);let n=this._externalLayers.get(e.layerId);switch(n||(n={layerId:e.layerId,uniformPrefix:a,usesChar:!1,usesCharColor:!1,usesCellColor:!1},this._externalLayers.set(e.layerId,n)),r){case"char":n.usesChar=!0;break;case"cellColor":n.usesCellColor=!0;break;default:n.usesCharColor=!0}}hasLayer(e){return this._externalLayers.has(e)}getLayerInfo(e){return this._externalLayers.get(e)}getExternalLayers(){return new Map(this._externalLayers)}get hasExternalLayers(){return this._externalLayers.size>0}get count(){return this._externalLayers.size}reset(){this._externalLayers.clear(),this._counter=0,this._layerIdToPrefix.clear()}}const K={char:"prevCharBuffer",charColor:"prevCharColorBuffer",cellColor:"prevCellColorBuffer",main:"prevCharColorBuffer"};class Q{getContextAwareGlslFunction(e,r,a,n,o){return r!=="src"?e.glslFunction:n&&o?this._generateExternalSrcFunction(n,a,o):this._generateSelfFeedbackSrcFunction(a)}getFunctionName(e,r,a,n){return e.name!=="src"?e.name:a&&n?`src_ext_${n(a.layerId)}_${r}`:`src_${r}`}generateTransformCode(e,r,a,n,o,c,s,l,f,m,h,v,x){const d=this.getFunctionName(r,m,v,x),y=(...u)=>[...u,...f].join(", ");let i=o,p=c,_=s,M=l;switch(r.type){case"src":{const u=`c${a}`;e.push(` vec4 ${u} = ${d}(${y(n)});`),i=u;break}case"coord":{const u=`st${a}`;e.push(` vec2 ${u} = ${d}(${y(n)});`),e.push(` ${n} = ${u};`);break}case"color":{const u=`c${a}`;e.push(` vec4 ${u} = ${d}(${y(o)});`),i=u;break}case"combine":{const u=`c${a}`;e.push(` vec4 ${u} = ${d}(${y(o,h??"vec4(0.0)")});`),i=u;break}case"combineCoord":{const u=`st${a}`;e.push(` vec2 ${u} = ${d}(${y(n,h??"vec4(0.0)")});`),e.push(` ${n} = ${u};`);break}}return{colorVar:i,charVar:p,flagsVar:_,rotationVar:M}}_generateExternalSrcFunction(e,r,a){const n=a(e.layerId);return`
|
|
219
|
+
vec4 ${`src_ext_${n}_${r}`}(vec2 _st) {
|
|
220
|
+
return texture(${{char:`${n}_char`,charColor:`${n}_primary`,cellColor:`${n}_cell`,main:`${n}_primary`}[r]}, fract(_st));
|
|
221
|
+
}
|
|
222
|
+
`}_generateSelfFeedbackSrcFunction(e){return`
|
|
223
|
+
vec4 ${`src_${e}`}(vec2 _st) {
|
|
224
|
+
return texture(${K[e]}, fract(_st));
|
|
225
|
+
}
|
|
226
|
+
`}}class N{_uniforms=new Map;_dynamicUpdaters=new Map;processArgument(e,r,a){if((function(n){return Array.isArray(n)&&n.length>0&&typeof n[0]=="number"})(e)){const n=`${a}_${r.name}`,o={name:n,type:r.type,value:r.default??0,isDynamic:!0},c=s=>(function(l,f){const m=l._speed??1,h=l._smooth??0;let v=f.time*m*(f.bpm/60)+(l._offset??0);if(h!==0){const x=l._ease??R.linear,d=v-h/2,y=l[Math.floor(U(d,l.length))],i=l[Math.floor(U(d+1,l.length))];return x(Math.min(U(d,1)/h,1))*(i-y)+y}return l[Math.floor(U(v,l.length))]})(e,s);return this._uniforms.set(n,o),this._dynamicUpdaters.set(n,c),{glslValue:n,uniform:o,updater:c}}if(typeof e=="function"){const n=`${a}_${r.name}`,o={name:n,type:r.type,value:r.default??0,isDynamic:!0};return this._uniforms.set(n,o),this._dynamicUpdaters.set(n,e),{glslValue:n,uniform:o,updater:e}}if(typeof e=="number")return{glslValue:C(e)};if(Array.isArray(e)&&typeof e[0]=="number"){const n=e;if(n.length===2)return{glslValue:`vec2(${C(n[0])}, ${C(n[1])})`};if(n.length===3)return{glslValue:`vec3(${C(n[0])}, ${C(n[1])}, ${C(n[2])})`};if(n.length===4)return{glslValue:`vec4(${C(n[0])}, ${C(n[1])}, ${C(n[2])}, ${C(n[3])})`}}return this.processDefault(r)}processDefault(e){const r=e.default;return typeof r=="number"?{glslValue:C(r)}:Array.isArray(r)?{glslValue:`vec${r.length}(${r.map(C).join(", ")})`}:{glslValue:"0.0"}}getUniforms(){return new Map(this._uniforms)}getDynamicUpdaters(){return new Map(this._dynamicUpdaters)}clear(){this._uniforms.clear(),this._dynamicUpdaters.clear()}}function C(t){const e=t.toString();return e.includes(".")?e:e+".0"}function j(t){return new H().compile(t)}class H{_uniformManager=new N;_feedbackTracker=new q;_externalLayerManager=new G;_codeGenerator=new Q;_glslFunctions=new Set;_mainCode=[];_varCounter=0;_currentTarget="main";compile(e){this._reset();const r=this._compileChain(e,"main","vec4(1.0, 1.0, 1.0, 1.0)","v_uv","main");let a=r.charVar;e.charSource&&(a=this._compileCharSource(e));let n=r.colorVar;e.colorSource&&(n=this._compileChain(e.colorSource,"charColor","vec4(1.0, 1.0, 1.0, 1.0)","v_uv","charColor").colorVar);let o="vec4(0.0, 0.0, 0.0, 0.0)";e.cellColorSource&&(o=this._compileChain(e.cellColorSource,"cellColor","vec4(0.0, 0.0, 0.0, 0.0)","v_uv","cellColor").colorVar);const c=(function(f,m,h){return f?`
|
|
240
227
|
// Character output from generator
|
|
241
|
-
vec4 charOutput = ${
|
|
228
|
+
vec4 charOutput = ${m};`:`
|
|
242
229
|
// Derive character from color luminance
|
|
243
|
-
float lum = _luminance(${
|
|
230
|
+
float lum = _luminance(${h}.rgb);
|
|
244
231
|
int charIdx = int(lum * 255.0);
|
|
245
|
-
vec4 charOutput = vec4(float(charIdx % 256) / 255.0, float(charIdx / 256) / 255.0, 0.0, 0.0);`})(!!
|
|
246
|
-
`);let
|
|
232
|
+
vec4 charOutput = vec4(float(charIdx % 256) / 255.0, float(charIdx / 256) / 255.0, 0.0, 0.0);`})(!!a,a??"vec4(0.0)",r.colorVar),s=this._feedbackTracker.getUsage();return{fragmentSource:(function(f){const{uniforms:m,glslFunctions:h,mainCode:v,charOutputCode:x,primaryColorVar:d,cellColorVar:y,charMapping:i,usesFeedback:p,usesCharFeedback:_,usesCellColorFeedback:M,externalLayers:u}=f,X=Array.from(m.values()).map($=>`uniform ${$.type} ${$.name};`).join(`
|
|
233
|
+
`);let I="",z="";i&&(I=`uniform int u_charMap[${i.indices.length}];
|
|
247
234
|
uniform int u_charMapSize;`,z=`
|
|
248
235
|
// Apply character mapping
|
|
249
236
|
int rawCharIdx = int(charOutput.r * 255.0 + charOutput.g * 255.0 * 256.0);
|
|
250
237
|
int mappedCharIdx = u_charMap[int(mod(float(rawCharIdx), float(u_charMapSize)))];
|
|
251
238
|
charOutput.r = float(mappedCharIdx % 256) / 255.0;
|
|
252
|
-
charOutput.g = float(mappedCharIdx / 256) / 255.0;`);const
|
|
253
|
-
`),
|
|
239
|
+
charOutput.g = float(mappedCharIdx / 256) / 255.0;`);const b=[];p&&b.push("uniform sampler2D prevCharColorBuffer;"),_&&b.push("uniform sampler2D prevCharBuffer;"),M&&b.push("uniform sampler2D prevCellColorBuffer;");const A=b.join(`
|
|
240
|
+
`),V=[];if(u)for(const[,$]of u)$.usesChar&&V.push(`uniform sampler2D ${$.uniformPrefix}_char;`),$.usesCharColor&&V.push(`uniform sampler2D ${$.uniformPrefix}_primary;`),$.usesCellColor&&V.push(`uniform sampler2D ${$.uniformPrefix}_cell;`);return`#version 300 es
|
|
254
241
|
precision highp float;
|
|
255
242
|
|
|
256
243
|
// Varyings
|
|
@@ -264,14 +251,14 @@ layout(location = 2) out vec4 o_secondaryColor;
|
|
|
264
251
|
// Standard uniforms
|
|
265
252
|
uniform float time;
|
|
266
253
|
uniform vec2 resolution;
|
|
267
|
-
${
|
|
268
|
-
${
|
|
269
|
-
${
|
|
254
|
+
${A}
|
|
255
|
+
${V.length>0?`// External layer samplers
|
|
256
|
+
${V.join(`
|
|
270
257
|
`)}`:""}
|
|
271
|
-
${
|
|
258
|
+
${I}
|
|
272
259
|
|
|
273
260
|
// Dynamic uniforms
|
|
274
|
-
${
|
|
261
|
+
${X}
|
|
275
262
|
|
|
276
263
|
|
|
277
264
|
// Utility functions
|
|
@@ -372,28 +359,20 @@ float _noise(vec3 v) {
|
|
|
372
359
|
|
|
373
360
|
|
|
374
361
|
// Transform functions
|
|
375
|
-
${Array.from(
|
|
362
|
+
${Array.from(h).join(`
|
|
376
363
|
`)}
|
|
377
364
|
|
|
378
365
|
void main() {
|
|
379
366
|
// Transform chain
|
|
380
|
-
${
|
|
367
|
+
${v.join(`
|
|
381
368
|
`)}
|
|
382
369
|
|
|
383
|
-
${
|
|
370
|
+
${x}
|
|
384
371
|
${z}
|
|
385
372
|
|
|
386
373
|
// Output to MRT
|
|
387
374
|
o_character = charOutput;
|
|
388
|
-
o_primaryColor = ${
|
|
375
|
+
o_primaryColor = ${d};
|
|
389
376
|
o_secondaryColor = ${y};
|
|
390
377
|
}
|
|
391
|
-
`})({uniforms:this._uniformManager.getUniforms(),glslFunctions:this._glslFunctions,mainCode:this._mainCode,charOutputCode:
|
|
392
|
-
vec4 ${`src_ext_${o}_${this._currentTarget}`}(vec2 _st) {
|
|
393
|
-
return texture(${u}, fract(_st));
|
|
394
|
-
}
|
|
395
|
-
`}const r={char:"prevCharBuffer",charColor:"prevBuffer",cellColor:"prevCellColorBuffer",main:"prevBuffer"}[this._currentTarget];return`
|
|
396
|
-
vec4 ${`src_${this._currentTarget}`}(vec2 _st) {
|
|
397
|
-
return texture(${r}, fract(_st));
|
|
398
|
-
}
|
|
399
|
-
`}_getExternalLayerPrefix(e){let a=this._layerIdToPrefix.get(e);return a||(a="extLayer"+this._externalLayerCounter++,this._layerIdToPrefix.set(e,a)),a}_trackExternalLayerUsage(e,a){const n=this._getExternalLayerPrefix(e.layerId);let r=this._externalLayers.get(e.layerId);switch(r||(r={layerId:e.layerId,uniformPrefix:n,usesChar:!1,usesPrimary:!1,usesCellColor:!1},this._externalLayers.set(e.layerId,r)),a){case"char":r.usesChar=!0;break;case"cellColor":r.usesCellColor=!0;break;default:r.usesPrimary=!0}}_processArguments(e,a,n){const r=[];for(let o=0;o<a.length;o++){const u=a[o],i=e[o]??u.default,s=this._uniformManager.processArgument(i,u,n);r.push(s.glslValue)}return r}_generateTransformCode(e,a,n,r,o,u,i,s,f,h){const p=(...l)=>[...l,...s].join(", ");let d=e.name;e.name==="src"&&(h?d=`src_ext_${this._getExternalLayerPrefix(h.layerId)}_${this._currentTarget}`:d=`src_${this._currentTarget}`);let _=r,m=o,y=u,c=i;switch(e.type){case"src":{const l=`c${a}`;this._mainCode.push(` vec4 ${l} = ${d}(${p(n)});`),_=l;break}case"coord":{const l=`st${a}`;this._mainCode.push(` vec2 ${l} = ${d}(${p(n)});`),this._mainCode.push(` ${n} = ${l};`);break}case"color":{const l=`c${a}`;this._mainCode.push(` vec4 ${l} = ${d}(${p(r)});`),_=l;break}case"combine":{const l=`c${a}`;this._mainCode.push(` vec4 ${l} = ${d}(${p(r,f??"vec4(0.0)")});`),_=l;break}case"combineCoord":{const l=`st${a}`;this._mainCode.push(` vec2 ${l} = ${d}(${p(n,f??"vec4(0.0)")});`),this._mainCode.push(` ${n} = ${l};`);break}case"charModify":m||(m=`char${a}`,y=`flags${a}`,c=`rot${a}`,this._mainCode.push(` vec4 ${m} = vec4(0.0);`),this._mainCode.push(` float ${y} = 0.0;`),this._mainCode.push(` float ${c} = 0.0;`)),this._mainCode.push(` ${m} = ${d}(${p(m)});`)}return{colorVar:_,charVar:m,flagsVar:y,rotationVar:c}}}class E{_resolvedIndices;_lastFontCharacterCount=0;_lastChars="";resolve(e,a){const n=a.characters.length;if(this._resolvedIndices&&this._lastFontCharacterCount===n&&this._lastChars===e)return this._resolvedIndices;const r=Array.from(e),o=new Int32Array(r.length),u=a.characterMap,i=a.characters;for(let s=0;s<r.length;s++){const f=r[s],h=u.get(f);if(h!==void 0)o[s]=i.indexOf(h);else{const p=u.get(" ");o[s]=p!==void 0?i.indexOf(p):0}}return this._resolvedIndices=o,this._lastFontCharacterCount=n,this._lastChars=e,o}invalidate(){this._resolvedIndices=void 0,this._lastFontCharacterCount=0,this._lastChars=""}}const $="textmode.synth.js";function F(t){const e=new Map;for(const[,a]of t.externalLayerRefs)e.set(a.layerId,a.layer);for(const[,a]of t.nestedSources){const n=F(a);for(const[r,o]of n)e.set(r,o)}if(t.charSource){const a=F(t.charSource);for(const[n,r]of a)e.set(n,r)}if(t.colorSource){const a=F(t.colorSource);for(const[n,r]of a)e.set(n,r)}if(t.cellColorSource){const a=F(t.cellColorSource);for(const[n,r]of a)e.set(n,r)}return e}const G={name:$,version:"1.0.0",install(t,e){e.extendLayer("synth",function(a){const n=performance.now()/1e3,r=this.grid!==void 0&&this.drawFramebuffer!==void 0;let o=this.getPluginState($);o?(o.source=a,o.startTime=n,o.needsCompile=!0,o.characterResolver.invalidate(),r&&(o.compiled=B(a))):o={source:a,compiled:r?B(a):void 0,shader:void 0,characterResolver:new E,startTime:n,needsCompile:!0,pingPongBuffers:void 0,pingPongIndex:0},this.setPluginState($,o)}),e.registerLayerPreRenderHook(async a=>{const n=a.getPluginState($);if(!n)return;const r=a.grid,o=a.drawFramebuffer;if(!r||!o||(n.compiled||(n.compiled=B(n.source),n.externalLayerMap=F(n.source),n.needsCompile=!0),n.needsCompile&&n.compiled&&(n.shader?.dispose&&n.shader.dispose(),n.externalLayerMap=F(n.source),n.shader=await t.createFilterShader(n.compiled.fragmentSource),n.needsCompile=!1),!n.shader||!n.compiled))return;const u=n.compiled.usesFeedback,i=n.compiled.usesCharFeedback,s=n.compiled.usesCellColorFeedback,f=u||i||s;f&&!n.pingPongBuffers&&(n.pingPongBuffers=[t.createFramebuffer({width:r.cols,height:r.rows,attachments:3}),t.createFramebuffer({width:r.cols,height:r.rows,attachments:3})],n.pingPongIndex=0);const h={time:t.millis()/1e3,frameCount:t.frameCount,width:r.width,height:r.height,cols:r.cols,rows:r.rows},p=d=>{t.setUniform("time",h.time),t.setUniform("resolution",[h.cols,h.rows]);for(const[m,y]of n.compiled.dynamicUpdaters)t.setUniform(m,y(h));for(const[m,y]of n.compiled.uniforms)y.isDynamic||typeof y.value=="function"||t.setUniform(m,y.value);if(n.compiled.charMapping){const m=n.characterResolver.resolve(n.compiled.charMapping.chars,a.font);t.setUniform("u_charMap",m),t.setUniform("u_charMapSize",m.length)}d&&(u&&t.setUniform("prevBuffer",d.textures[1]),i&&t.setUniform("prevCharBuffer",d.textures[0]),s&&t.setUniform("prevCellColorBuffer",d.textures[2]));const _=n.compiled.externalLayers;if(_&&_.size>0&&n.externalLayerMap)for(const[m,y]of _){const c=n.externalLayerMap.get(m);if(!c){console.warn(`[SynthPlugin] External layer not found: ${m}`);continue}const l=c.getPluginState($);let v;l?.pingPongBuffers?v=l.pingPongBuffers[l.pingPongIndex].textures:c.drawFramebuffer&&(v=c.drawFramebuffer.textures),v&&(y.usesChar&&t.setUniform(`${y.uniformPrefix}_char`,v[0]),y.usesPrimary&&t.setUniform(`${y.uniformPrefix}_primary`,v[1]),y.usesCellColor&&t.setUniform(`${y.uniformPrefix}_cell`,v[2]))}};if(f&&n.pingPongBuffers){const d=n.pingPongBuffers[n.pingPongIndex],_=n.pingPongBuffers[1-n.pingPongIndex];_.begin(),t.clear(),t.shader(n.shader),p(d),t.rect(r.cols,r.rows),_.end(),o.begin(),t.clear(),t.shader(n.shader),p(d),t.rect(r.cols,r.rows),o.end(),n.pingPongIndex=1-n.pingPongIndex}else o.begin(),t.clear(),t.shader(n.shader),p(null),t.rect(r.cols,r.rows),o.end()}),e.registerLayerDisposedHook(a=>{const n=a.getPluginState($);n&&(n.shader?.dispose&&n.shader.dispose(),n.pingPongBuffers&&(n.pingPongBuffers[0].dispose?.(),n.pingPongBuffers[1].dispose?.()))})},uninstall(t,e){const a=[e.layerManager.base,...e.layerManager.all];for(const n of a){const r=n.getPluginState($);r&&(r.shader?.dispose&&r.shader.dispose(),r.pingPongBuffers&&(r.pingPongBuffers[0].dispose?.(),r.pingPongBuffers[1].dispose?.()))}e.removeLayerExtension("synth")}};"fast"in Array.prototype||(Array.prototype.fast=function(t=1){return this._speed=t,this},Array.prototype.smooth=function(t=1){return this._smooth=t,this},Array.prototype.ease=function(t="linear"){return typeof t=="function"?(this._smooth=1,this._ease=t):Y[t]&&(this._smooth=1,this._ease=Y[t]),this},Array.prototype.offset=function(t=.5){return this._offset=t%1,this},Array.prototype.fit=function(t=0,e=1){const a=Math.min(...this),n=Math.max(...this),r=this.map(o=>(function(u,i,s,f,h){return(u-i)*(h-f)/(s-i)+f})(o,a,n,t,e));return r._speed=this._speed,r._smooth=this._smooth,r._ease=this._ease,r._offset=this._offset,r}),k.registerMany(O),X.setSynthSourceClass(C),X.injectMethods(C.prototype);const w=X.generateStandaloneFunctions(),K=(t,e=256)=>{const a=new C;return a._charSource=t,a._charCount=e,a},Q=w.osc,H=w.noise,N=w.voronoi,W=w.gradient,J=w.shape,Z=w.solid,tt=(function(){const t=w.src;return e=>{if(!e)return t();const a=new C,n=e.id??`layer_${Date.now()}_${Math.random().toString(36).slice(2,9)}`;return a.addExternalLayerRef({layerId:n,layer:e}),a}})();g.SynthPlugin=G,g.SynthSource=C,g.cellColor=t=>{const e=new C;return e._cellColorSource=t,e},g.char=K,g.charColor=t=>{const e=new C;return e._colorSource=t,e},g.gradient=W,g.noise=H,g.osc=Q,g.paint=t=>{const e=new C;return e._colorSource=t,e._cellColorSource=t,e},g.shape=J,g.solid=Z,g.src=tt,g.voronoi=N,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
378
|
+
`})({uniforms:this._uniformManager.getUniforms(),glslFunctions:this._glslFunctions,mainCode:this._mainCode,charOutputCode:c,primaryColorVar:n,cellColorVar:o,charMapping:e.charMapping,usesFeedback:s.usesCharColorFeedback,usesCharFeedback:s.usesCharFeedback,usesCellColorFeedback:s.usesCellColorFeedback,externalLayers:this._externalLayerManager.getExternalLayers()}),uniforms:this._uniformManager.getUniforms(),dynamicUpdaters:this._uniformManager.getDynamicUpdaters(),charMapping:e.charMapping,usesCharColorFeedback:s.usesCharColorFeedback,usesCharFeedback:s.usesCharFeedback,usesCellColorFeedback:s.usesCellColorFeedback,externalLayers:this._externalLayerManager.getExternalLayers()}}_reset(){this._varCounter=0,this._uniformManager.clear(),this._feedbackTracker.reset(),this._externalLayerManager.reset(),this._glslFunctions.clear(),this._mainCode.length=0,this._currentTarget="main"}_compileCharSource(e){const r=this._compileChain(e.charSource,"charSrc","vec4(1.0, 1.0, 1.0, 1.0)","v_uv","char"),a="charFromSource_"+this._varCounter++,n=e.charCount??256;return this._mainCode.push(" // Convert charSource color to character index"),this._mainCode.push(` float charLum_${a} = _luminance(${r.colorVar}.rgb);`),this._mainCode.push(` int charIdx_${a} = int(charLum_${a} * ${n.toFixed(1)});`),this._mainCode.push(` vec4 ${a} = vec4(float(charIdx_${a} % 256) / 255.0, float(charIdx_${a} / 256) / 255.0, 0.0, 0.0);`),a}_compileChain(e,r,a,n="v_uv",o="main"){const c=this._currentTarget;this._currentTarget=o;const s=`${r}_st`;let l,f,m,h=`${r}_c`;this._mainCode.push(` vec2 ${s} = ${n};`),this._mainCode.push(` vec4 ${h} = ${a};`);const v=e.transforms,x=v.map(i=>this._getProcessedTransform(i.name)),d=this._identifyCoordTransforms(x),y=i=>{const p=v[i],_=x[i];if(!_)return void console.warn(`[SynthCompiler] Unknown transform: ${p.name}`);const M=e.externalLayerRefs.get(i);p.name==="src"&&this._trackSrcUsage(M);const u=this._codeGenerator.getContextAwareGlslFunction(_,p.name,this._currentTarget,M,A=>this._externalLayerManager.getPrefix(A));this._glslFunctions.add(u);const X=this._processArguments(p.userArgs,_.inputs,`${r}_${i}_${p.name}`),I=e.nestedSources.get(i);let z;I&&(_.type==="combine"||_.type==="combineCoord")&&(z=this._compileChain(I,`${r}_nested_${i}`,a,s,o).colorVar);const b=this._codeGenerator.generateTransformCode(this._mainCode,_,this._varCounter++,s,h,l,f,m,X,this._currentTarget,z,M,A=>this._externalLayerManager.getPrefix(A));h=b.colorVar,b.charVar&&(l=b.charVar),b.flagsVar&&(f=b.flagsVar),b.rotationVar&&(m=b.rotationVar)};for(let i=d.length-1;i>=0;i--)y(d[i]);for(let i=0;i<v.length;i++){const p=x[i];(!p||p.type!=="coord"&&p.type!=="combineCoord")&&y(i)}return this._currentTarget=c,{coordVar:s,colorVar:h,charVar:l,flagsVar:f,rotationVar:m}}_identifyCoordTransforms(e){const r=[];for(let a=0;a<e.length;a++){const n=e[a];n&&(n.type!=="coord"&&n.type!=="combineCoord"||r.push(a))}return r}_trackSrcUsage(e){e?this._externalLayerManager.trackUsage(e,this._currentTarget):this._feedbackTracker.trackUsage(this._currentTarget)}_getProcessedTransform(e){return L.getProcessed(e)}_processArguments(e,r,a){const n=[];for(let o=0;o<r.length;o++){const c=r[o],s=e[o]??c.default,l=this._uniformManager.processArgument(s,c,a);n.push(l.glslValue)}return n}}class W{_resolvedIndices;_lastFontCharacterCount=0;_lastChars="";resolve(e,r){const a=r.characters.length;if(this._resolvedIndices&&this._lastFontCharacterCount===a&&this._lastChars===e)return this._resolvedIndices;const n=Array.from(e),o=new Int32Array(n.length),c=r.characterMap,s=r.characters;for(let l=0;l<n.length;l++){const f=n[l],m=c.get(f);if(m!==void 0)o[l]=s.indexOf(m);else{const h=c.get(" ");o[l]=h!==void 0?s.indexOf(h):0}}return this._resolvedIndices=o,this._lastFontCharacterCount=a,this._lastChars=e,o}invalidate(){this._resolvedIndices=void 0,this._lastFontCharacterCount=0,this._lastChars=""}}function O(t={}){return{source:t.source??new S,compiled:t.compiled,shader:t.shader,characterResolver:t.characterResolver??new W,needsCompile:t.needsCompile??!1,pingPongBuffers:t.pingPongBuffers,pingPongIndex:t.pingPongIndex??0,externalLayerMap:t.externalLayerMap,bpm:t.bpm}}let D=60;function J(t){t.bpm=function(e){return(function(r){D=r})(e),e}}function P(t){const e=new Map;for(const[,r]of t.externalLayerRefs)e.set(r.layerId,r.layer);for(const[,r]of t.nestedSources){const a=P(r);for(const[n,o]of a)e.set(n,o)}if(t.charSource){const r=P(t.charSource);for(const[a,n]of r)e.set(a,n)}if(t.colorSource){const r=P(t.colorSource);for(const[a,n]of r)e.set(a,n)}if(t.cellColorSource){const r=P(t.cellColorSource);for(const[a,n]of r)e.set(a,n)}return e}function Z(t){const e=t.getPluginState(w);e&&(e.shader?.dispose&&e.shader.dispose(),e.pingPongBuffers&&(e.pingPongBuffers[0].dispose?.(),e.pingPongBuffers[1].dispose?.()))}const ee={name:w,version:"1.0.0",install(t,e){J(t),(function(r){r.extendLayer("synth",function(a){const n=this.grid!==void 0&&this.drawFramebuffer!==void 0;let o=this.getPluginState(w);o?(o.source=a,o.needsCompile=!0,o.characterResolver.invalidate(),n&&(o.compiled=j(a))):o=O({source:a,compiled:n?j(a):void 0,needsCompile:!0}),this.setPluginState(w,o)})})(e),(function(r){r.extendLayer("bpm",function(a){let n=this.getPluginState(w);n?n.bpm=a:n=O({bpm:a}),this.setPluginState(w,n)})})(e),(function(r){r.extendLayer("clearSynth",function(){const a=this.getPluginState(w);a&&(a.shader?.dispose&&a.shader.dispose(),a.pingPongBuffers&&(a.pingPongBuffers[0].dispose?.(),a.pingPongBuffers[1].dispose?.()),this.setPluginState(w,void 0))})})(e),e.registerLayerPreRenderHook(r=>(async function(a,n){const o=a.getPluginState(w);if(!o)return;const c=a.grid,s=a.drawFramebuffer;if(!c||!s||(o.compiled||(o.compiled=j(o.source),o.externalLayerMap=P(o.source),o.needsCompile=!0),o.needsCompile&&o.compiled&&(o.shader?.dispose&&o.shader.dispose(),o.externalLayerMap=P(o.source),o.shader=await n.createFilterShader(o.compiled.fragmentSource),o.needsCompile=!1),!o.shader||!o.compiled))return;const l=o.compiled.usesCharColorFeedback,f=o.compiled.usesCharFeedback,m=o.compiled.usesCellColorFeedback,h=l||f||m;h&&!o.pingPongBuffers&&(o.pingPongBuffers=[n.createFramebuffer({width:c.cols,height:c.rows,attachments:3}),n.createFramebuffer({width:c.cols,height:c.rows,attachments:3})],o.pingPongIndex=0);const v={time:n.secs,frameCount:n.frameCount,width:c.width,height:c.height,cols:c.cols,rows:c.rows,bpm:o.bpm??D},x=d=>{n.setUniform("time",n.secs),n.setUniform("resolution",[v.cols,v.rows]);for(const[i,p]of o.compiled.dynamicUpdaters)n.setUniform(i,p(v));for(const[i,p]of o.compiled.uniforms)p.isDynamic||typeof p.value=="function"||n.setUniform(i,p.value);if(o.compiled.charMapping){const i=o.characterResolver.resolve(o.compiled.charMapping.chars,a.font);n.setUniform("u_charMap",i),n.setUniform("u_charMapSize",i.length)}d&&(l&&n.setUniform("prevCharColorBuffer",d.textures[1]),f&&n.setUniform("prevCharBuffer",d.textures[0]),m&&n.setUniform("prevCellColorBuffer",d.textures[2]));const y=o.compiled.externalLayers;if(y&&y.size>0&&o.externalLayerMap)for(const[i,p]of y){const _=o.externalLayerMap.get(i);if(!_){console.warn(`[textmode.synth.js] External layer not found: ${i}`);continue}const M=_.getPluginState(w);let u;M?.pingPongBuffers?u=M.pingPongBuffers[M.pingPongIndex].textures:_.drawFramebuffer&&(u=_.drawFramebuffer.textures),u&&(p.usesChar&&n.setUniform(`${p.uniformPrefix}_char`,u[0]),p.usesCharColor&&n.setUniform(`${p.uniformPrefix}_primary`,u[1]),p.usesCellColor&&n.setUniform(`${p.uniformPrefix}_cell`,u[2]))}};if(h&&o.pingPongBuffers){const d=o.pingPongBuffers[o.pingPongIndex],y=o.pingPongBuffers[1-o.pingPongIndex];y.begin(),n.clear(),n.shader(o.shader),x(d),n.rect(c.cols,c.rows),y.end(),s.begin(),n.clear(),n.shader(o.shader),x(d),n.rect(c.cols,c.rows),s.end(),o.pingPongIndex=1-o.pingPongIndex}else s.begin(),n.clear(),n.shader(o.shader),x(null),n.rect(c.cols,c.rows),s.end()})(r,t)),e.registerLayerDisposedHook(Z)},uninstall(t,e){const r=[e.layerManager.base,...e.layerManager.all];for(const a of r){const n=a.getPluginState(w);n&&(n.shader?.dispose&&n.shader.dispose(),n.pingPongBuffers&&(n.pingPongBuffers[0].dispose?.(),n.pingPongBuffers[1].dispose?.()))}delete t.bpm,e.removeLayerExtension("synth"),e.removeLayerExtension("bpm"),e.removeLayerExtension("clearSynth")}};g.SynthPlugin=ee,g.SynthSource=S,g.cellColor=t=>{const e=new S;return e._colorSource=t,e},g.char=(t,e)=>{const r=new S;return r._charSource=t,r._charCount=e,r},g.charColor=t=>{const e=new S;return e._colorSource=t,e},g.gradient=function(t){return F.gradient(t)},g.noise=function(t,e){return F.noise(t,e)},g.osc=function(t,e,r){return F.osc(t,e,r)},g.paint=t=>{const e=new S;return e._colorSource=t,e._cellColorSource=t,e},g.shape=function(t,e,r){return F.shape(t,e,r)},g.solid=function(t,e,r,a){return F.solid(t,e,r,a)},g.src=t=>{const e=F.src;if(!t)return e();const r=new S,a=t.id??`layer_${Date.now()}_${Math.random().toString(36).slice(2,9)}`;return r.addExternalLayerRef({layerId:a,layer:t}),r},g.voronoi=function(t,e,r){return F.voronoi(t,e,r)},Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACH,SAAS,EACT,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,KAAK,EACL,GAAG,EACH,KAAK,EACL,KAAK,EACL,KAAK,EACL,GAAG,EACH,OAAO,GACV,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed source function exports for the public API.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { SynthContext } from '../core/types';
|
|
7
|
+
import { SynthSource } from '../core/SynthSource';
|
|
8
|
+
import { TextmodeLayer } from 'textmode.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create a synth source with cell background color defined.
|
|
11
|
+
*
|
|
12
|
+
* This function creates a SynthSource where the cell background color
|
|
13
|
+
* is driven by the provided source pattern. This is compositional and can be
|
|
14
|
+
* combined with `char()` and `charColor()`.
|
|
15
|
+
*
|
|
16
|
+
* @param source - A SynthSource producing color values for cell background
|
|
17
|
+
* @returns A new SynthSource configured with cell color
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const t = textmode.create({
|
|
22
|
+
* width: 800,
|
|
23
|
+
* height: 600,
|
|
24
|
+
* plugins: [SynthPlugin]
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Start with cell color
|
|
28
|
+
* t.layers.base.synth(
|
|
29
|
+
* cellColor(solid(0, 0, 0, 0.5))
|
|
30
|
+
* .char(noise(10))
|
|
31
|
+
* .charColor(osc(5))
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* // Complete composition - all three defined
|
|
35
|
+
* const colorPattern = voronoi(5, 0.3);
|
|
36
|
+
* t.layers.base.synth(
|
|
37
|
+
* cellColor(colorPattern.clone().invert())
|
|
38
|
+
* .char(noise(10), 16)
|
|
39
|
+
* .charMap('@#%*+=-:. ')
|
|
40
|
+
* .charColor(colorPattern)
|
|
41
|
+
* );
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const cellColor: (source: SynthSource) => SynthSource;
|
|
45
|
+
/**
|
|
46
|
+
* Create a character source from any color/pattern source.
|
|
47
|
+
*
|
|
48
|
+
* This function converts any pattern (like `osc()`, `noise()`, `voronoi()`) into
|
|
49
|
+
* character indices. The pattern's luminance or color values are mapped to character indices.
|
|
50
|
+
*
|
|
51
|
+
* @param source - A SynthSource producing color values that will be mapped to characters
|
|
52
|
+
* @param charCount - Number of different characters to use (default: 256)
|
|
53
|
+
* @returns A new SynthSource configured for character generation
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Simple usage - same pattern for chars and colors
|
|
58
|
+
* const pattern = osc(1, 0.1);
|
|
59
|
+
* t.layers.base.synth(
|
|
60
|
+
* char(pattern)
|
|
61
|
+
* .charColor(pattern.clone())
|
|
62
|
+
* );
|
|
63
|
+
*
|
|
64
|
+
* // With limited character count
|
|
65
|
+
* t.layers.base.synth(
|
|
66
|
+
* char(noise(10), 16)
|
|
67
|
+
* .charMap('@#%*+=-:. ')
|
|
68
|
+
* );
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare const char: (source: SynthSource, charCount?: number) => SynthSource;
|
|
72
|
+
/**
|
|
73
|
+
* Create a synth source with character foreground color defined.
|
|
74
|
+
*
|
|
75
|
+
* This function creates a SynthSource where the character foreground color
|
|
76
|
+
* is driven by the provided source pattern. This is compositional and can be
|
|
77
|
+
* combined with `char()` and `cellColor()`.
|
|
78
|
+
*
|
|
79
|
+
* @param source - A SynthSource producing color values for character foreground
|
|
80
|
+
* @returns A new SynthSource configured with character color
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const t = textmode.create({
|
|
85
|
+
* width: 800,
|
|
86
|
+
* height: 600,
|
|
87
|
+
* plugins: [SynthPlugin]
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // Start with character color
|
|
91
|
+
* const pattern = osc(10, 0.1);
|
|
92
|
+
* t.layers.base.synth(
|
|
93
|
+
* charColor(pattern)
|
|
94
|
+
* .char(noise(10))
|
|
95
|
+
* .cellColor(solid(0, 0, 0, 0.5))
|
|
96
|
+
* );
|
|
97
|
+
*
|
|
98
|
+
* // Using different patterns for each aspect
|
|
99
|
+
* t.layers.base.synth(
|
|
100
|
+
* charColor(voronoi(5).mult(osc(20)))
|
|
101
|
+
* .char(noise(10), 16)
|
|
102
|
+
* .charMap('@#%*+=-:. ')
|
|
103
|
+
* );
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare const charColor: (source: SynthSource) => SynthSource;
|
|
107
|
+
/**
|
|
108
|
+
* Generate a rotating radial gradient.
|
|
109
|
+
* @param speed - Rotation speed (default: 0.0)
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const t = textmode.create({
|
|
114
|
+
* width: 800,
|
|
115
|
+
* height: 600,
|
|
116
|
+
* plugins: [SynthPlugin]
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* // Animated gradient with array modulation
|
|
120
|
+
* t.layers.base.synth(
|
|
121
|
+
* gradient([1, 2, 4])
|
|
122
|
+
* );
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function gradient(speed?: number | number[] | ((ctx: SynthContext) => number)): SynthSource;
|
|
126
|
+
/**
|
|
127
|
+
* Generate Perlin noise patterns.
|
|
128
|
+
* @param scale - Scale of the noise pattern (default: 10.0)
|
|
129
|
+
* @param offset - Offset in noise space (default: 0.1)
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const t = textmode.create({
|
|
134
|
+
* width: 800,
|
|
135
|
+
* height: 600,
|
|
136
|
+
* plugins: [SynthPlugin]
|
|
137
|
+
* });
|
|
138
|
+
*
|
|
139
|
+
* // Basic noise pattern
|
|
140
|
+
* t.layers.base.synth(
|
|
141
|
+
* noise(10, 0.1)
|
|
142
|
+
* );
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function noise(scale?: number | number[] | ((ctx: SynthContext) => number), offset?: number | number[] | ((ctx: SynthContext) => number)): SynthSource;
|
|
146
|
+
/**
|
|
147
|
+
* Generate oscillating patterns using sine waves.
|
|
148
|
+
* @param frequency - Frequency of the oscillation (default: 60.0)
|
|
149
|
+
* @param sync - Synchronization offset (default: 0.1)
|
|
150
|
+
* @param offset - Phase offset (default: 0.0)
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const t = textmode.create({
|
|
155
|
+
* width: 800,
|
|
156
|
+
* height: 600,
|
|
157
|
+
* plugins: [SynthPlugin]
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* // Basic oscillating color pattern
|
|
161
|
+
* t.layers.base.synth(
|
|
162
|
+
* osc(1, 0.1)
|
|
163
|
+
* .cellColor(osc(10, 0.1))
|
|
164
|
+
* );
|
|
165
|
+
*
|
|
166
|
+
* // Animated frequency using array modulation
|
|
167
|
+
* t.layers.base.synth(
|
|
168
|
+
* osc([1, 10, 50, 100].fast(2), 0.001)
|
|
169
|
+
* );
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function osc(frequency?: number | number[] | ((ctx: SynthContext) => number), sync?: number | number[] | ((ctx: SynthContext) => number), offset?: number | number[] | ((ctx: SynthContext) => number)): SynthSource;
|
|
173
|
+
/**
|
|
174
|
+
* Create a synth source with both character and cell colors defined.
|
|
175
|
+
*
|
|
176
|
+
* This function creates a SynthSource where both the character foreground color
|
|
177
|
+
* and the cell background color are driven by the same source pattern.
|
|
178
|
+
* This is a convenience function equivalent to calling both `charColor()` and
|
|
179
|
+
* `cellColor()` with the same source, allowing for easy pixel art without visible characters.
|
|
180
|
+
*
|
|
181
|
+
* @param source - A SynthSource producing color values for both character and cell colors
|
|
182
|
+
* @returns A new SynthSource configured with both color sources
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const t = textmode.create({
|
|
187
|
+
* width: 800,
|
|
188
|
+
* height: 600,
|
|
189
|
+
* plugins: [SynthPlugin]
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* // Use same pattern for both foreground and background colors
|
|
193
|
+
* t.layers.base.synth(
|
|
194
|
+
* paint(osc(10, 0.1).mult(voronoi(5)))
|
|
195
|
+
* );
|
|
196
|
+
*
|
|
197
|
+
* // Paint with gradient
|
|
198
|
+
* t.layers.base.synth(
|
|
199
|
+
* paint(gradient(0.5))
|
|
200
|
+
* );
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export declare const paint: (source: SynthSource) => SynthSource;
|
|
204
|
+
/**
|
|
205
|
+
* Generate geometric shapes (polygons).
|
|
206
|
+
* @param sides - Number of sides (default: 3)
|
|
207
|
+
* @param radius - Radius of the shape (default: 0.3)
|
|
208
|
+
* @param smoothing - Edge smoothing amount (default: 0.01)
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const t = textmode.create({
|
|
213
|
+
* width: 800,
|
|
214
|
+
* height: 600,
|
|
215
|
+
* plugins: [SynthPlugin]
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* // Triangle
|
|
219
|
+
* t.layers.base.synth(
|
|
220
|
+
* shape(3)
|
|
221
|
+
* );
|
|
222
|
+
*
|
|
223
|
+
* // High-sided polygon (ellipse-like)
|
|
224
|
+
* t.layers.base.synth(
|
|
225
|
+
* shape(100)
|
|
226
|
+
* );
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
export declare function shape(sides?: number | number[] | ((ctx: SynthContext) => number), radius?: number | number[] | ((ctx: SynthContext) => number), smoothing?: number | number[] | ((ctx: SynthContext) => number)): SynthSource;
|
|
230
|
+
/**
|
|
231
|
+
* Generate a solid color.
|
|
232
|
+
* @param r - Red channel (0-1, default: 0.0)
|
|
233
|
+
* @param g - Green channel (0-1, default: 0.0)
|
|
234
|
+
* @param b - Blue channel (0-1, default: 0.0)
|
|
235
|
+
* @param a - Alpha channel (0-1, default: 1.0)
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* const t = textmode.create({
|
|
240
|
+
* width: 800,
|
|
241
|
+
* height: 600,
|
|
242
|
+
* plugins: [SynthPlugin]
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* // Solid colors with array modulation
|
|
246
|
+
* t.layers.base.synth(
|
|
247
|
+
* solid(0.6, 0, 0, 1)
|
|
248
|
+
* .charColor(solid([1, 0, 0], [0, 1, 0], [0, 0, 1], 1))
|
|
249
|
+
* .cellColor(solid([1, 0, 0], [0, 1, 0], [0, 0, 1], 1).invert())
|
|
250
|
+
* );
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
export declare function solid(r?: number | number[] | ((ctx: SynthContext) => number), g?: number | number[] | ((ctx: SynthContext) => number), b?: number | number[] | ((ctx: SynthContext) => number), a?: number | number[] | ((ctx: SynthContext) => number)): SynthSource;
|
|
254
|
+
/**
|
|
255
|
+
* Sample the previous frame's output for feedback effects.
|
|
256
|
+
*
|
|
257
|
+
* This is the core of feedback loops - it reads from the previous frame,
|
|
258
|
+
* enabling effects like trails, motion blur, and recursive patterns.
|
|
259
|
+
*
|
|
260
|
+
* **Context-aware behavior:** When called without arguments, `src()` automatically
|
|
261
|
+
* samples the appropriate texture based on where it's used in the synth chain:
|
|
262
|
+
* - Inside `char(...)` → samples previous frame's character data
|
|
263
|
+
* - Inside `charColor(...)` → samples previous frame's primary color
|
|
264
|
+
* - Inside `cellColor(...)` → samples previous frame's cell color
|
|
265
|
+
*
|
|
266
|
+
* **Cross-layer sampling:** When called with a layer argument, `src(layer)` samples
|
|
267
|
+
* from another layer's output, enabling hydra-style multi-output compositions:
|
|
268
|
+
* - The sampled texture is still context-aware based on the current compilation target
|
|
269
|
+
*
|
|
270
|
+
* Equivalent to hydra's `src(o0)`.
|
|
271
|
+
*
|
|
272
|
+
* @param layer - Optional TextmodeLayer to sample from. If omitted, samples from self (feedback).
|
|
273
|
+
* @returns A new SynthSource that samples the specified layer or self
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const t = textmode.create({
|
|
278
|
+
* width: 800,
|
|
279
|
+
* height: 600,
|
|
280
|
+
* plugins: [SynthPlugin]
|
|
281
|
+
* });
|
|
282
|
+
*
|
|
283
|
+
* // Classic hydra-style feedback loop with noise modulation
|
|
284
|
+
* t.layers.base.synth(
|
|
285
|
+
* src().modulate(noise(3), 0.005).blend(shape(4), 0.01)
|
|
286
|
+
* );
|
|
287
|
+
*
|
|
288
|
+
* // Cross-layer sampling (hydra-style o0, o1, etc.)
|
|
289
|
+
* const layer1 = t.layers.add();
|
|
290
|
+
* const layer2 = t.layers.add();
|
|
291
|
+
*
|
|
292
|
+
* layer1.synth(noise(10).mult(osc(20)));
|
|
293
|
+
*
|
|
294
|
+
* layer2.synth(
|
|
295
|
+
* char(voronoi(5).diff(src(layer1))) // Sample layer1's char texture
|
|
296
|
+
* .charColor(osc(10).blend(src(layer1), 0.5)) // Sample layer1's primary color
|
|
297
|
+
* );
|
|
298
|
+
*
|
|
299
|
+
* // Complex multi-layer composition
|
|
300
|
+
* t.layers.base.synth(
|
|
301
|
+
* noise(3, 0.3).thresh(0.3).diff(src(layer2), 0.3)
|
|
302
|
+
* );
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
export declare const src: (layer?: TextmodeLayer) => SynthSource;
|
|
306
|
+
/**
|
|
307
|
+
* Generate voronoi patterns.
|
|
308
|
+
* @param scale - Scale of voronoi cells (default: 5.0)
|
|
309
|
+
* @param speed - Animation speed (default: 0.3)
|
|
310
|
+
* @param blending - Blending between cell regions (default: 0.3)
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* const t = textmode.create({
|
|
315
|
+
* width: 800,
|
|
316
|
+
* height: 600,
|
|
317
|
+
* plugins: [SynthPlugin]
|
|
318
|
+
* });
|
|
319
|
+
*
|
|
320
|
+
* // Animated Voronoi pattern
|
|
321
|
+
* t.layers.base.synth(
|
|
322
|
+
* voronoi(5, 0.3, 0.3)
|
|
323
|
+
* );
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
export declare function voronoi(scale?: number | number[] | ((ctx: SynthContext) => number), speed?: number | number[] | ((ctx: SynthContext) => number), blending?: number | number[] | ((ctx: SynthContext) => number)): SynthSource;
|
|
327
|
+
//# sourceMappingURL=sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../../src/api/sources.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,KAAG,WAI/C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,GAAI,QAAQ,WAAW,EAAE,YAAY,MAAM,KAAG,WAQ9D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,KAAG,WAI/C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,GAC5D,WAAW,CAEb;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CACjB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EAC3D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,GAC7D,WAAW,CAEb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,GAAG,CACf,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EAC/D,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EAC1D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,GAC7D,WAAW,CAEb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,KAAK,GAAI,QAAQ,WAAW,KAAG,WAK3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,KAAK,CACjB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EAC3D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EAC5D,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,GAChE,WAAW,CAEb;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,KAAK,CACjB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EACvD,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EACvD,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EACvD,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,GACxD,WAAW,CAEb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,GAAG,GAAI,QAAQ,aAAa,KAAG,WAmB3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EAC3D,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,EAC3D,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,GAC/D,WAAW,CAEb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/augmentations/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,YAAY,CAAC"}
|