@paper-design/shaders 0.0.0-canary.b448849 → 0.0.0-canary.b4f628d

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.
@@ -15,24 +15,6 @@
15
15
  *
16
16
  * The HTML texture always matches the canvas size, so shaders sample it like any canvas-sized texture: a resize
17
17
  * captures the HTML again right away instead of waiting for the next paint.
18
- *
19
- * Shaders nested in that HTML don't get a canvas of their own. Each one renders into a framebuffer of the root
20
- * shader's context, and is pasted into its parent's HTML texture where it's laid out:
21
- *
22
- * <div data-paper-shader> ← root, owns the only canvas and context
23
- * <canvas content="drawable" layoutsubtree>
24
- * <div drawable>
25
- * <div data-paper-shader> ← nested, renders into a framebuffer
26
- * <div drawable>…</div> ← captured on its own, left out of the root capture
27
- * </div>
28
- * <img />
29
- * <div data-paper-shader></div> ← nested, without HTML
30
- * </div>
31
- * </canvas>
32
- * </div>
33
- *
34
- * A nested shader is pasted over everything else in its parent's HTML, and the browser doesn't apply the transforms,
35
- * opacity and clipping of the elements between them to it.
36
18
  */
37
19
  export interface DrawableCanvasElement extends HTMLCanvasElement {
38
20
  requestPaint(): void;
@@ -44,51 +26,10 @@ export declare function isHtmlInCanvasSupported(): boolean;
44
26
  /** `<img>` stays a static image uniform. nodeType instead of `instanceof` works across iframes */
45
27
  export declare function isHtmlUniform(value: unknown): value is HTMLElement;
46
28
  export declare function findReactCanvas(values: unknown[], parentElement: Element): DrawableCanvasElement | null;
47
- /**
48
- * The canvas of the root shader whose HTML holds this shader element, if it can render it. Its own children have to
49
- * be drawable HTML or HTML uniforms, anything else stays on top of a canvas of its own
50
- */
51
- export declare function findHostCanvas(parentElement: HTMLElement, values: unknown[]): DrawableCanvasElement | null;
52
- /** The layout position of the element's border box within the padding box of a positioned ancestor, in CSS px */
53
- export declare function getOffsetWithin(element: HTMLElement, ancestor: Element): {
54
- x: number;
55
- y: number;
56
- };
57
- /** Drawing buffer size of what HTML is captured into, and the CSS size of the element it covers */
58
- export interface HtmlCaptureBox {
59
- width: number;
60
- height: number;
61
- clientWidth: number;
62
- clientHeight: number;
63
- }
64
29
  /** Moves the element into the canvas, returns a function that puts it back */
65
30
  export declare function attachHtml(canvas: DrawableCanvasElement, element: HTMLElement): () => void;
66
31
  /**
67
- * Captures the element into the bound texture, sized to the drawing buffer of the box. The texture is only reallocated
32
+ * Captures the element into the bound texture, sized to the canvas drawing buffer. The texture is only reallocated
68
33
  * (and so cleared) when its size or the drawn area changes; returns that layout to pass back in next time
69
34
  */
70
- export declare function drawHtml(gl: WebGL2RenderingContext, box: HtmlCaptureBox, element: HTMLElement, lastLayout?: string): string;
71
- /** A texture to render into, the output of a nested shader or the HTML with nested shaders pasted in */
72
- export interface RenderTarget {
73
- texture: WebGLTexture;
74
- framebuffer: WebGLFramebuffer;
75
- width: number;
76
- height: number;
77
- }
78
- /** Creates the render target, or reallocates its texture when the size changes */
79
- export declare function resizeRenderTarget(gl: WebGL2RenderingContext, target: RenderTarget | undefined, width: number, height: number): RenderTarget;
80
- export declare function deleteRenderTarget(gl: WebGL2RenderingContext, target: RenderTarget | undefined): void;
81
- /** Corner radius of the element's border box in CSS px, the top left one for all corners */
82
- export declare function getBorderRadius(element: HTMLElement): number;
83
- /** A texture pasted into a render target */
84
- export interface PastedTexture {
85
- texture: WebGLTexture;
86
- /** Position and size in the target's pixels, from its top left */
87
- rect: [number, number, number, number];
88
- /** Corner radius in the target's pixels */
89
- radius?: number;
90
- /** Textures rendered by a shader have their first row at the bottom, HTML captures at the top */
91
- isRendered?: boolean;
92
- }
93
- /** Draws the HTML capture into the target as is, then the textures over it with their rounded corners */
94
- export declare function pasteTextures(gl: WebGL2RenderingContext, target: RenderTarget, base: WebGLTexture, textures: PastedTexture[]): void;
35
+ export declare function drawHtml(gl: WebGL2RenderingContext, canvas: DrawableCanvasElement, element: HTMLElement, lastLayout?: string): string;
@@ -3,7 +3,6 @@
3
3
  * https://github.com/paper-design/shaders *
4
4
  * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
5
 
6
- import { createProgram } from "./webgl-program.js";
7
6
  function isHtmlInCanvasSupported() {
8
7
  return typeof HTMLCanvasElement !== "undefined" && "requestPaint" in HTMLCanvasElement.prototype && typeof WebGL2RenderingContext !== "undefined" && "texElementSubImage2D" in WebGL2RenderingContext.prototype;
9
8
  }
@@ -19,33 +18,6 @@ function findReactCanvas(values, parentElement) {
19
18
  }
20
19
  return null;
21
20
  }
22
- function findHostCanvas(parentElement, values) {
23
- const canvas = parentElement.parentElement?.closest("canvas");
24
- if (!canvas || !isHtmlInCanvasSupported() || canvas.getAttribute("content") !== "drawable") {
25
- return null;
26
- }
27
- const drawable = parentElement.parentElement.closest("[drawable]");
28
- if (!drawable || !canvas.contains(drawable)) {
29
- return null;
30
- }
31
- for (const child of Array.from(parentElement.children)) {
32
- if (!child.hasAttribute("drawable") && !values.includes(child)) {
33
- return null;
34
- }
35
- }
36
- return canvas;
37
- }
38
- function getOffsetWithin(element, ancestor) {
39
- let x = element.offsetLeft;
40
- let y = element.offsetTop;
41
- let current = element.offsetParent;
42
- while (current && current !== ancestor) {
43
- x += current.offsetLeft + current.clientLeft;
44
- y += current.offsetTop + current.clientTop;
45
- current = current.offsetParent;
46
- }
47
- return { x, y };
48
- }
49
21
  function attachHtml(canvas, element) {
50
22
  if (element.parentElement === canvas) {
51
23
  return () => {
@@ -66,17 +38,17 @@ function attachHtml(canvas, element) {
66
38
  }
67
39
  };
68
40
  }
69
- function drawHtml(gl, box, element, lastLayout) {
70
- const width = Math.max(1, box.width);
71
- const height = Math.max(1, box.height);
72
- const scaleX = width / Math.max(1, box.clientWidth);
73
- const scaleY = height / Math.max(1, box.clientHeight);
41
+ function drawHtml(gl, canvas, element, lastLayout) {
42
+ const width = Math.max(1, canvas.width);
43
+ const height = Math.max(1, canvas.height);
44
+ const scaleX = width / Math.max(1, canvas.clientWidth);
45
+ const scaleY = height / Math.max(1, canvas.clientHeight);
74
46
  const left = element.offsetLeft;
75
47
  const top = element.offsetTop;
76
48
  const visibleLeft = Math.max(0, left);
77
49
  const visibleTop = Math.max(0, top);
78
- const visibleRight = Math.min(box.clientWidth, left + element.offsetWidth);
79
- const visibleBottom = Math.min(box.clientHeight, top + element.offsetHeight);
50
+ const visibleRight = Math.min(canvas.clientWidth, left + element.offsetWidth);
51
+ const visibleBottom = Math.min(canvas.clientHeight, top + element.offsetHeight);
80
52
  const x0 = Math.round(visibleLeft * scaleX);
81
53
  const y0 = Math.round(visibleTop * scaleY);
82
54
  const x1 = Math.min(width, Math.round(visibleRight * scaleX));
@@ -97,140 +69,11 @@ function drawHtml(gl, box, element, lastLayout) {
97
69
  }
98
70
  return layout;
99
71
  }
100
- function resizeRenderTarget(gl, target, width, height) {
101
- if (target && target.width === width && target.height === height) {
102
- return target;
103
- }
104
- const texture = target?.texture ?? gl.createTexture();
105
- gl.bindTexture(gl.TEXTURE_2D, texture);
106
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
107
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
108
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
109
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
110
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
111
- gl.bindTexture(gl.TEXTURE_2D, null);
112
- const framebuffer = target?.framebuffer ?? gl.createFramebuffer();
113
- gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
114
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
115
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
116
- return { texture, framebuffer, width, height };
117
- }
118
- function deleteRenderTarget(gl, target) {
119
- if (!target) return;
120
- gl.deleteTexture(target.texture);
121
- gl.deleteFramebuffer(target.framebuffer);
122
- }
123
- function getBorderRadius(element) {
124
- const radius = parseFloat(getComputedStyle(element).borderTopLeftRadius) || 0;
125
- return Math.min(radius, element.offsetWidth / 2, element.offsetHeight / 2);
126
- }
127
- const pasteVertexShader = `#version 300 es
128
- layout(location = 0) in vec4 a_position;
129
-
130
- uniform vec4 u_rect;
131
- uniform vec2 u_targetSize;
132
- uniform float u_flipY;
133
-
134
- out vec2 v_uv;
135
- out vec2 v_px;
136
-
137
- void main() {
138
- vec2 corner = a_position.xy * .5 + .5;
139
- v_uv = vec2(corner.x, mix(corner.y, 1. - corner.y, u_flipY));
140
- v_px = corner * u_rect.zw;
141
- vec2 position = (u_rect.xy + corner * u_rect.zw) / u_targetSize;
142
- gl_Position = vec4(position * 2. - 1., 0., 1.);
143
- }
144
- `;
145
- const pasteFragmentShader = `#version 300 es
146
- precision highp float;
147
-
148
- uniform sampler2D u_texture;
149
- uniform vec4 u_rect;
150
- uniform float u_radius;
151
-
152
- in vec2 v_uv;
153
- in vec2 v_px;
154
-
155
- out vec4 fragColor;
156
-
157
- void main() {
158
- vec2 size = u_rect.zw;
159
- vec2 halfSize = .5 * size;
160
- vec2 q = abs(v_px - halfSize) - halfSize + u_radius;
161
- float distance = length(max(q, 0.)) + min(max(q.x, q.y), 0.) - u_radius;
162
- float mask = clamp(.5 - distance, 0., 1.);
163
- fragColor = texture(u_texture, v_uv) * mask;
164
- }
165
- `;
166
- const pastePrograms = /* @__PURE__ */ new WeakMap();
167
- function getPasteProgram(gl) {
168
- if (pastePrograms.has(gl)) {
169
- return pastePrograms.get(gl);
170
- }
171
- const program = createProgram(gl, pasteVertexShader, pasteFragmentShader);
172
- if (!program) {
173
- pastePrograms.set(gl, null);
174
- return null;
175
- }
176
- const vertexArray = gl.createVertexArray();
177
- gl.bindVertexArray(vertexArray);
178
- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
179
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]), gl.STATIC_DRAW);
180
- gl.enableVertexAttribArray(0);
181
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
182
- gl.bindVertexArray(null);
183
- const location = (name) => gl.getUniformLocation(program, name);
184
- const paste = {
185
- program,
186
- vertexArray,
187
- locations: {
188
- u_texture: location("u_texture"),
189
- u_rect: location("u_rect"),
190
- u_targetSize: location("u_targetSize"),
191
- u_flipY: location("u_flipY"),
192
- u_radius: location("u_radius")
193
- }
194
- };
195
- pastePrograms.set(gl, paste);
196
- return paste;
197
- }
198
- function pasteTextures(gl, target, base, textures) {
199
- const paste = getPasteProgram(gl);
200
- if (!paste) return;
201
- gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
202
- gl.viewport(0, 0, target.width, target.height);
203
- gl.useProgram(paste.program);
204
- gl.bindVertexArray(paste.vertexArray);
205
- gl.activeTexture(gl.TEXTURE0);
206
- gl.uniform1i(paste.locations.u_texture, 0);
207
- gl.uniform2f(paste.locations.u_targetSize, target.width, target.height);
208
- const draw = ({ texture, rect, radius = 0, isRendered = false }) => {
209
- gl.bindTexture(gl.TEXTURE_2D, texture);
210
- gl.uniform4fv(paste.locations.u_rect, rect);
211
- gl.uniform1f(paste.locations.u_radius, radius);
212
- gl.uniform1f(paste.locations.u_flipY, isRendered ? 1 : 0);
213
- gl.drawArrays(gl.TRIANGLES, 0, 6);
214
- };
215
- draw({ texture: base, rect: [0, 0, target.width, target.height] });
216
- gl.enable(gl.BLEND);
217
- gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
218
- textures.forEach(draw);
219
- gl.disable(gl.BLEND);
220
- gl.bindTexture(gl.TEXTURE_2D, null);
221
- gl.bindVertexArray(null);
222
- }
223
72
  export {
224
73
  attachHtml,
225
- deleteRenderTarget,
226
74
  drawHtml,
227
- findHostCanvas,
228
75
  findReactCanvas,
229
- getBorderRadius,
230
- getOffsetWithin,
231
76
  isHtmlInCanvasSupported,
232
- isHtmlUniform,
233
- pasteTextures,
234
- resizeRenderTarget
77
+ isHtmlUniform
235
78
  };
236
79
  //# sourceMappingURL=html-in-canvas.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/html-in-canvas.ts"],
4
- "sourcesContent": ["import { createProgram } from './webgl-program.js';\n\n/**\n * Experimental HTML-in-canvas support (https://github.com/WICG/html-in-canvas),\n * available in Chromium behind `chrome://flags/#canvas-draw-element`. Older Chromium versions opt the canvas in with\n * `layoutsubtree` instead of `content=\"drawable\"`, so the canvas gets both.\n *\n * An HTML element passed as a texture uniform is moved into the shader canvas and drawn 1:1 where it's laid out:\n *\n * <div data-paper-shader>\n * <canvas content=\"drawable\" layoutsubtree>\n * <div drawable>\u2026</div>\n * </canvas>\n * </div>\n *\n * React renders this markup itself, since it can't let its nodes be moved, and the shader adopts that canvas.\n *\n * The HTML texture always matches the canvas size, so shaders sample it like any canvas-sized texture: a resize\n * captures the HTML again right away instead of waiting for the next paint.\n *\n * Shaders nested in that HTML don't get a canvas of their own. Each one renders into a framebuffer of the root\n * shader's context, and is pasted into its parent's HTML texture where it's laid out:\n *\n * <div data-paper-shader> \u2190 root, owns the only canvas and context\n * <canvas content=\"drawable\" layoutsubtree>\n * <div drawable>\n * <div data-paper-shader> \u2190 nested, renders into a framebuffer\n * <div drawable>\u2026</div> \u2190 captured on its own, left out of the root capture\n * </div>\n * <img />\n * <div data-paper-shader></div> \u2190 nested, without HTML\n * </div>\n * </canvas>\n * </div>\n *\n * A nested shader is pasted over everything else in its parent's HTML, and the browser doesn't apply the transforms,\n * opacity and clipping of the elements between them to it.\n */\n\nexport interface DrawableCanvasElement extends HTMLCanvasElement {\n requestPaint(): void;\n updateElementGeometry(element: Element, options?: { canvasTransform?: DOMMatrixInit }): void;\n}\n\ninterface DrawableCanvasWebGL2Context extends WebGL2RenderingContext {\n texElementSubImage2D(\n target: GLenum,\n level: GLint,\n xoffset: GLint,\n yoffset: GLint,\n element: Element,\n config?: { width?: number; height?: number; sx?: number; sy?: number; swidth?: number; sheight?: number }\n ): void;\n}\n\nexport function isHtmlInCanvasSupported(): boolean {\n return (\n typeof HTMLCanvasElement !== 'undefined' &&\n 'requestPaint' in HTMLCanvasElement.prototype &&\n typeof WebGL2RenderingContext !== 'undefined' &&\n 'texElementSubImage2D' in WebGL2RenderingContext.prototype\n );\n}\n\n/** `<img>` stays a static image uniform. nodeType instead of `instanceof` works across iframes */\nexport function isHtmlUniform(value: unknown): value is HTMLElement {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Node).nodeType === 1 &&\n (value as Element).tagName !== 'IMG'\n );\n}\n\nexport function findReactCanvas(values: unknown[], parentElement: Element): DrawableCanvasElement | null {\n for (const value of values) {\n const canvas = isHtmlUniform(value) ? value.parentElement : null;\n if (canvas?.tagName === 'CANVAS' && canvas.parentElement === parentElement) {\n return canvas as DrawableCanvasElement;\n }\n }\n return null;\n}\n\n/**\n * The canvas of the root shader whose HTML holds this shader element, if it can render it. Its own children have to\n * be drawable HTML or HTML uniforms, anything else stays on top of a canvas of its own\n */\nexport function findHostCanvas(parentElement: HTMLElement, values: unknown[]): DrawableCanvasElement | null {\n const canvas = parentElement.parentElement?.closest('canvas');\n if (!canvas || !isHtmlInCanvasSupported() || canvas.getAttribute('content') !== 'drawable') {\n return null;\n }\n\n const drawable = parentElement.parentElement!.closest('[drawable]');\n if (!drawable || !canvas.contains(drawable)) {\n return null;\n }\n\n for (const child of Array.from(parentElement.children)) {\n if (!child.hasAttribute('drawable') && !values.includes(child)) {\n return null;\n }\n }\n\n return canvas as DrawableCanvasElement;\n}\n\n/** The layout position of the element's border box within the padding box of a positioned ancestor, in CSS px */\nexport function getOffsetWithin(element: HTMLElement, ancestor: Element): { x: number; y: number } {\n let x = element.offsetLeft;\n let y = element.offsetTop;\n let current = element.offsetParent as HTMLElement | null;\n\n while (current && current !== ancestor) {\n x += current.offsetLeft + current.clientLeft;\n y += current.offsetTop + current.clientTop;\n current = current.offsetParent as HTMLElement | null;\n }\n\n return { x, y };\n}\n\n/** Drawing buffer size of what HTML is captured into, and the CSS size of the element it covers */\nexport interface HtmlCaptureBox {\n width: number;\n height: number;\n clientWidth: number;\n clientHeight: number;\n}\n\n/** Moves the element into the canvas, returns a function that puts it back */\nexport function attachHtml(canvas: DrawableCanvasElement, element: HTMLElement): () => void {\n if (element.parentElement === canvas) {\n return () => {};\n }\n\n const parent = element.parentNode;\n const nextSibling = element.nextSibling;\n canvas.setAttribute('content', 'drawable');\n canvas.setAttribute('layoutsubtree', '');\n element.setAttribute('drawable', '');\n canvas.append(element);\n\n return () => {\n element.removeAttribute('drawable');\n if (parent) {\n parent.insertBefore(element, nextSibling?.parentNode === parent ? nextSibling : null);\n } else {\n element.remove();\n }\n };\n}\n\n/**\n * Captures the element into the bound texture, sized to the drawing buffer of the box. The texture is only reallocated\n * (and so cleared) when its size or the drawn area changes; returns that layout to pass back in next time\n */\nexport function drawHtml(gl: WebGL2RenderingContext, box: HtmlCaptureBox, element: HTMLElement, lastLayout?: string): string {\n const width = Math.max(1, box.width);\n const height = Math.max(1, box.height);\n const scaleX = width / Math.max(1, box.clientWidth);\n const scaleY = height / Math.max(1, box.clientHeight);\n\n const left = element.offsetLeft;\n const top = element.offsetTop;\n const visibleLeft = Math.max(0, left);\n const visibleTop = Math.max(0, top);\n const visibleRight = Math.min(box.clientWidth, left + element.offsetWidth);\n const visibleBottom = Math.min(box.clientHeight, top + element.offsetHeight);\n const x0 = Math.round(visibleLeft * scaleX);\n const y0 = Math.round(visibleTop * scaleY);\n const x1 = Math.min(width, Math.round(visibleRight * scaleX));\n const y1 = Math.min(height, Math.round(visibleBottom * scaleY));\n\n const layout = `${width}x${height} ${x0},${y0},${x1},${y1}`;\n if (layout !== lastLayout) {\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n }\n\n if (x1 > x0 && y1 > y0) {\n (gl as DrawableCanvasWebGL2Context).texElementSubImage2D(gl.TEXTURE_2D, 0, x0, y0, element, {\n sx: visibleLeft - left,\n sy: visibleTop - top,\n swidth: visibleRight - visibleLeft,\n sheight: visibleBottom - visibleTop,\n width: x1 - x0,\n height: y1 - y0,\n });\n }\n\n return layout;\n}\n\n/** A texture to render into, the output of a nested shader or the HTML with nested shaders pasted in */\nexport interface RenderTarget {\n texture: WebGLTexture;\n framebuffer: WebGLFramebuffer;\n width: number;\n height: number;\n}\n\n/** Creates the render target, or reallocates its texture when the size changes */\nexport function resizeRenderTarget(\n gl: WebGL2RenderingContext,\n target: RenderTarget | undefined,\n width: number,\n height: number\n): RenderTarget {\n if (target && target.width === width && target.height === height) {\n return target;\n }\n\n const texture = target?.texture ?? gl.createTexture()!;\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.bindTexture(gl.TEXTURE_2D, null);\n\n const framebuffer = target?.framebuffer ?? gl.createFramebuffer()!;\n gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n\n return { texture, framebuffer, width, height };\n}\n\nexport function deleteRenderTarget(gl: WebGL2RenderingContext, target: RenderTarget | undefined): void {\n if (!target) return;\n gl.deleteTexture(target.texture);\n gl.deleteFramebuffer(target.framebuffer);\n}\n\n/** Corner radius of the element's border box in CSS px, the top left one for all corners */\nexport function getBorderRadius(element: HTMLElement): number {\n const radius = parseFloat(getComputedStyle(element).borderTopLeftRadius) || 0;\n return Math.min(radius, element.offsetWidth / 2, element.offsetHeight / 2);\n}\n\n// language=GLSL\nconst pasteVertexShader = `#version 300 es\nlayout(location = 0) in vec4 a_position;\n\nuniform vec4 u_rect;\nuniform vec2 u_targetSize;\nuniform float u_flipY;\n\nout vec2 v_uv;\nout vec2 v_px;\n\nvoid main() {\n vec2 corner = a_position.xy * .5 + .5;\n v_uv = vec2(corner.x, mix(corner.y, 1. - corner.y, u_flipY));\n v_px = corner * u_rect.zw;\n vec2 position = (u_rect.xy + corner * u_rect.zw) / u_targetSize;\n gl_Position = vec4(position * 2. - 1., 0., 1.);\n}\n`;\n\n// language=GLSL\nconst pasteFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform sampler2D u_texture;\nuniform vec4 u_rect;\nuniform float u_radius;\n\nin vec2 v_uv;\nin vec2 v_px;\n\nout vec4 fragColor;\n\nvoid main() {\n vec2 size = u_rect.zw;\n vec2 halfSize = .5 * size;\n vec2 q = abs(v_px - halfSize) - halfSize + u_radius;\n float distance = length(max(q, 0.)) + min(max(q.x, q.y), 0.) - u_radius;\n float mask = clamp(.5 - distance, 0., 1.);\n fragColor = texture(u_texture, v_uv) * mask;\n}\n`;\n\ninterface PasteProgram {\n program: WebGLProgram;\n vertexArray: WebGLVertexArrayObject;\n locations: Record<'u_texture' | 'u_rect' | 'u_targetSize' | 'u_flipY' | 'u_radius', WebGLUniformLocation | null>;\n}\n\nconst pastePrograms = new WeakMap<WebGL2RenderingContext, PasteProgram | null>();\n\nfunction getPasteProgram(gl: WebGL2RenderingContext): PasteProgram | null {\n if (pastePrograms.has(gl)) {\n return pastePrograms.get(gl)!;\n }\n\n const program = createProgram(gl, pasteVertexShader, pasteFragmentShader);\n if (!program) {\n pastePrograms.set(gl, null);\n return null;\n }\n\n const vertexArray = gl.createVertexArray()!;\n gl.bindVertexArray(vertexArray);\n gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]), gl.STATIC_DRAW);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n gl.bindVertexArray(null);\n\n const location = (name: keyof PasteProgram['locations']) => gl.getUniformLocation(program, name);\n const paste: PasteProgram = {\n program,\n vertexArray,\n locations: {\n u_texture: location('u_texture'),\n u_rect: location('u_rect'),\n u_targetSize: location('u_targetSize'),\n u_flipY: location('u_flipY'),\n u_radius: location('u_radius'),\n },\n };\n pastePrograms.set(gl, paste);\n return paste;\n}\n\n/** A texture pasted into a render target */\nexport interface PastedTexture {\n texture: WebGLTexture;\n /** Position and size in the target's pixels, from its top left */\n rect: [number, number, number, number];\n /** Corner radius in the target's pixels */\n radius?: number;\n /** Textures rendered by a shader have their first row at the bottom, HTML captures at the top */\n isRendered?: boolean;\n}\n\n/** Draws the HTML capture into the target as is, then the textures over it with their rounded corners */\nexport function pasteTextures(\n gl: WebGL2RenderingContext,\n target: RenderTarget,\n base: WebGLTexture,\n textures: PastedTexture[]\n): void {\n const paste = getPasteProgram(gl);\n if (!paste) return;\n\n gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);\n gl.viewport(0, 0, target.width, target.height);\n gl.useProgram(paste.program);\n gl.bindVertexArray(paste.vertexArray);\n gl.activeTexture(gl.TEXTURE0);\n gl.uniform1i(paste.locations.u_texture, 0);\n gl.uniform2f(paste.locations.u_targetSize, target.width, target.height);\n\n const draw = ({ texture, rect, radius = 0, isRendered = false }: PastedTexture) => {\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.uniform4fv(paste.locations.u_rect, rect);\n gl.uniform1f(paste.locations.u_radius, radius);\n gl.uniform1f(paste.locations.u_flipY, isRendered ? 1 : 0);\n gl.drawArrays(gl.TRIANGLES, 0, 6);\n };\n\n draw({ texture: base, rect: [0, 0, target.width, target.height] });\n\n // Premultiplied alpha over\n gl.enable(gl.BLEND);\n gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);\n textures.forEach(draw);\n gl.disable(gl.BLEND);\n\n // So that a later pass can't sample a texture it's rendering into\n gl.bindTexture(gl.TEXTURE_2D, null);\n gl.bindVertexArray(null);\n}\n"],
5
- "mappings": ";;;;;AAAA,SAAS,qBAAqB;AAuDvB,SAAS,0BAAmC;AACjD,SACE,OAAO,sBAAsB,eAC7B,kBAAkB,kBAAkB,aACpC,OAAO,2BAA2B,eAClC,0BAA0B,uBAAuB;AAErD;AAGO,SAAS,cAAc,OAAsC;AAClE,SACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAe,aAAa,KAC5B,MAAkB,YAAY;AAEnC;AAEO,SAAS,gBAAgB,QAAmB,eAAsD;AACvG,aAAW,SAAS,QAAQ;AAC1B,UAAM,SAAS,cAAc,KAAK,IAAI,MAAM,gBAAgB;AAC5D,QAAI,QAAQ,YAAY,YAAY,OAAO,kBAAkB,eAAe;AAC1E,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,eAAe,eAA4B,QAAiD;AAC1G,QAAM,SAAS,cAAc,eAAe,QAAQ,QAAQ;AAC5D,MAAI,CAAC,UAAU,CAAC,wBAAwB,KAAK,OAAO,aAAa,SAAS,MAAM,YAAY;AAC1F,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,cAAc,cAAe,QAAQ,YAAY;AAClE,MAAI,CAAC,YAAY,CAAC,OAAO,SAAS,QAAQ,GAAG;AAC3C,WAAO;AAAA,EACT;AAEA,aAAW,SAAS,MAAM,KAAK,cAAc,QAAQ,GAAG;AACtD,QAAI,CAAC,MAAM,aAAa,UAAU,KAAK,CAAC,OAAO,SAAS,KAAK,GAAG;AAC9D,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT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U,MAAM;AAC7C,OAAG,UAAU,MAAM,UAAU,SAAS,aAAa,IAAI,CAAC;AACxD,OAAG,WAAW,GAAG,WAAW,GAAG,CAAC;AAAA,EAClC;AAEA,OAAK,EAAE,SAAS,MAAM,MAAM,CAAC,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM,EAAE,CAAC;AAGjE,KAAG,OAAO,GAAG,KAAK;AAClB,KAAG,UAAU,GAAG,KAAK,GAAG,mBAAmB;AAC3C,WAAS,QAAQ,IAAI;AACrB,KAAG,QAAQ,GAAG,KAAK;AAGnB,KAAG,YAAY,GAAG,YAAY,IAAI;AAClC,KAAG,gBAAgB,IAAI;AACzB;",
4
+ "sourcesContent": ["/**\n * Experimental HTML-in-canvas support (https://github.com/WICG/html-in-canvas),\n * available in Chromium behind `chrome://flags/#canvas-draw-element`. Older Chromium versions opt the canvas in with\n * `layoutsubtree` instead of `content=\"drawable\"`, so the canvas gets both.\n *\n * An HTML element passed as a texture uniform is moved into the shader canvas and drawn 1:1 where it's laid out:\n *\n * <div data-paper-shader>\n * <canvas content=\"drawable\" layoutsubtree>\n * <div drawable>\u2026</div>\n * </canvas>\n * </div>\n *\n * React renders this markup itself, since it can't let its nodes be moved, and the shader adopts that canvas.\n *\n * The HTML texture always matches the canvas size, so shaders sample it like any canvas-sized texture: a resize\n * captures the HTML again right away instead of waiting for the next paint.\n */\n\nexport interface DrawableCanvasElement extends HTMLCanvasElement {\n requestPaint(): void;\n updateElementGeometry(element: Element, options?: { canvasTransform?: DOMMatrixInit }): void;\n}\n\ninterface DrawableCanvasWebGL2Context extends WebGL2RenderingContext {\n texElementSubImage2D(\n target: GLenum,\n level: GLint,\n xoffset: GLint,\n yoffset: GLint,\n element: Element,\n config?: { width?: number; height?: number; sx?: number; sy?: number; swidth?: number; sheight?: number }\n ): void;\n}\n\nexport function isHtmlInCanvasSupported(): boolean {\n return (\n typeof HTMLCanvasElement !== 'undefined' &&\n 'requestPaint' in HTMLCanvasElement.prototype &&\n typeof WebGL2RenderingContext !== 'undefined' &&\n 'texElementSubImage2D' in WebGL2RenderingContext.prototype\n );\n}\n\n/** `<img>` stays a static image uniform. nodeType instead of `instanceof` works across iframes */\nexport function isHtmlUniform(value: unknown): value is HTMLElement {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Node).nodeType === 1 &&\n (value as Element).tagName !== 'IMG'\n );\n}\n\nexport function findReactCanvas(values: unknown[], parentElement: Element): DrawableCanvasElement | null {\n for (const value of values) {\n const canvas = isHtmlUniform(value) ? value.parentElement : null;\n if (canvas?.tagName === 'CANVAS' && canvas.parentElement === parentElement) {\n return canvas as DrawableCanvasElement;\n }\n }\n return null;\n}\n\n/** Moves the element into the canvas, returns a function that puts it back */\nexport function attachHtml(canvas: DrawableCanvasElement, element: HTMLElement): () => void {\n if (element.parentElement === canvas) {\n return () => {};\n }\n\n const parent = element.parentNode;\n const nextSibling = element.nextSibling;\n canvas.setAttribute('content', 'drawable');\n canvas.setAttribute('layoutsubtree', '');\n element.setAttribute('drawable', '');\n canvas.append(element);\n\n return () => {\n element.removeAttribute('drawable');\n if (parent) {\n parent.insertBefore(element, nextSibling?.parentNode === parent ? nextSibling : null);\n } else {\n element.remove();\n }\n };\n}\n\n/**\n * Captures the element into the bound texture, sized to the canvas drawing buffer. The texture is only reallocated\n * (and so cleared) when its size or the drawn area changes; returns that layout to pass back in next time\n */\nexport function drawHtml(\n gl: WebGL2RenderingContext,\n canvas: DrawableCanvasElement,\n element: HTMLElement,\n lastLayout?: string\n): string {\n const width = Math.max(1, canvas.width);\n const height = Math.max(1, canvas.height);\n const scaleX = width / Math.max(1, canvas.clientWidth);\n const scaleY = height / Math.max(1, canvas.clientHeight);\n\n const left = element.offsetLeft;\n const top = element.offsetTop;\n const visibleLeft = Math.max(0, left);\n const visibleTop = Math.max(0, top);\n const visibleRight = Math.min(canvas.clientWidth, left + element.offsetWidth);\n const visibleBottom = Math.min(canvas.clientHeight, top + element.offsetHeight);\n const x0 = Math.round(visibleLeft * scaleX);\n const y0 = Math.round(visibleTop * scaleY);\n const x1 = Math.min(width, Math.round(visibleRight * scaleX));\n const y1 = Math.min(height, Math.round(visibleBottom * scaleY));\n\n const layout = `${width}x${height} ${x0},${y0},${x1},${y1}`;\n if (layout !== lastLayout) {\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n }\n\n if (x1 > x0 && y1 > y0) {\n (gl as DrawableCanvasWebGL2Context).texElementSubImage2D(gl.TEXTURE_2D, 0, x0, y0, element, {\n sx: visibleLeft - left,\n sy: visibleTop - top,\n swidth: visibleRight - visibleLeft,\n sheight: visibleBottom - visibleTop,\n width: x1 - x0,\n height: y1 - y0,\n });\n }\n\n return layout;\n}\n"],
5
+ "mappings": ";;;;;AAmCO,SAAS,0BAAmC;AACjD,SACE,OAAO,sBAAsB,eAC7B,kBAAkB,kBAAkB,aACpC,OAAO,2BAA2B,eAClC,0BAA0B,uBAAuB;AAErD;AAGO,SAAS,cAAc,OAAsC;AAClE,SACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAe,aAAa,KAC5B,MAAkB,YAAY;AAEnC;AAEO,SAAS,gBAAgB,QAAmB,eAAsD;AACvG,aAAW,SAAS,QAAQ;AAC1B,UAAM,SAAS,cAAc,KAAK,IAAI,MAAM,gBAAgB;AAC5D,QAAI,QAAQ,YAAY,YAAY,OAAO,kBAAkB,eAAe;AAC1E,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,WAAW,QAA+B,SAAkC;AAC1F,MAAI,QAAQ,kBAAkB,QAAQ;AACpC,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAEA,QAAM,SAAS,QAAQ;AACvB,QAAM,cAAc,QAAQ;AAC5B,SAAO,aAAa,WAAW,UAAU;AACzC,SAAO,aAAa,iBAAiB,EAAE;AACvC,UAAQ,aAAa,YAAY,EAAE;AACnC,SAAO,OAAO,OAAO;AAErB,SAAO,MAAM;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AAI,cAAc;AAAA,MAClB,IAAI,aAAa;AAAA,MACjB,QAAQ,eAAe;AAAA,MACvB,SAAS,gBAAgB;AAAA,MACzB,OAAO,KAAK;AAAA,MACZ,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /** The core Shader Mount class. Pass it a parent element and a fragment shader to get started. */
2
2
  export { ShaderMount, isPaperShaderElement } from './shader-mount.js';
3
3
  export { isHtmlInCanvasSupported } from './html-in-canvas.js';
4
+ export { observeContentSize, type ShaderSizeToContent } from './size-to-content.js';
4
5
  export type { PaperShaderElement, ShaderMotionParams, ShaderMountUniforms, ShaderPreset, ImageShaderPreset, } from './shader-mount.js';
5
6
  /** Shader sizing options and uniforms */
6
7
  export { defaultObjectSizing, defaultPatternSizing, ShaderFitOptions, type ShaderFit, type ShaderSizingParams, type ShaderSizingUniforms, } from './shader-sizing.js';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { ShaderMount, isPaperShaderElement } from "./shader-mount.js";
7
7
  import { isHtmlInCanvasSupported } from "./html-in-canvas.js";
8
+ import { observeContentSize } from "./size-to-content.js";
8
9
  import {
9
10
  defaultObjectSizing,
10
11
  defaultPatternSizing,
@@ -167,6 +168,7 @@ export {
167
168
  metaballsFragmentShader,
168
169
  metaballsMeta,
169
170
  neuroNoiseFragmentShader,
171
+ observeContentSize,
170
172
  paperTextureFragmentShader,
171
173
  paperTextureMeta,
172
174
  perlinNoiseFragmentShader,
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["/** The core Shader Mount class. Pass it a parent element and a fragment shader to get started. */\nexport { ShaderMount, isPaperShaderElement } from './shader-mount.js';\nexport { isHtmlInCanvasSupported } from './html-in-canvas.js';\nexport type {\n PaperShaderElement,\n ShaderMotionParams,\n ShaderMountUniforms,\n ShaderPreset,\n ImageShaderPreset,\n} from './shader-mount.js';\n\n/** Shader sizing options and uniforms */\nexport {\n defaultObjectSizing,\n defaultPatternSizing,\n ShaderFitOptions,\n type ShaderFit,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from './shader-sizing.js';\n\n/** A flowing interplay of color spots, moving along distinct trajectories and transformed by organic distortion */\nexport {\n meshGradientFragmentShader,\n meshGradientMeta,\n type MeshGradientParams,\n type MeshGradientUniforms,\n} from './shaders/mesh-gradient.js';\n\n/** Radial multi-colored gradient shaped with layered noise for a natural, smoky aesthetic */\nexport {\n smokeRingMeta,\n smokeRingFragmentShader,\n type SmokeRingParams,\n type SmokeRingUniforms,\n} from './shaders/smoke-ring.js';\n\n/** A glowing, web-like structure of fluid lines and soft intersections. Great for creating atmospheric, organic-yet-futuristic visuals */\nexport { neuroNoiseFragmentShader, type NeuroNoiseParams, type NeuroNoiseUniforms } from './shaders/neuro-noise.js';\n\n/** Animated multi-color dots pattern with each dot orbiting around its cell center. Supports up to 40 colors and various shape and motion controls. Great for playful, dynamic backgrounds and UI textures */\nexport {\n dotOrbitMeta,\n dotOrbitFragmentShader,\n type DotOrbitParams,\n type DotOrbitUniforms,\n} from './shaders/dot-orbit.js';\n\n/** Static grid pattern made of circles, diamonds, squares or triangles */\nexport {\n dotGridFragmentShader,\n DotGridShapes,\n type DotGridShape,\n type DotGridParams,\n type DotGridUniforms,\n} from './shaders/dot-grid.js';\n\n/** A multi-color gradient mapped into smooth, animated curves, delivering a sleek, futuristic visual */\nexport {\n simplexNoiseMeta,\n simplexNoiseFragmentShader,\n type SimplexNoiseParams,\n type SimplexNoiseUniforms,\n} from './shaders/simplex-noise.js';\n\n/** Up to 20 gooey blobs moving around the center and merging into smooth organic shapes */\nexport {\n metaballsMeta,\n metaballsFragmentShader,\n type MetaballsParams,\n type MetaballsUniforms,\n} from './shaders/metaballs.js';\n\n/** Animated 3D Perlin noise with exposed controls */\nexport { perlinNoiseFragmentShader, type PerlinNoiseParams, type PerlinNoiseUniforms } from './shaders/perlin-noise.js';\n\n/** Anti-aliased animated Voronoi pattern with smooth and customizable edges */\nexport { voronoiMeta, voronoiFragmentShader, type VoronoiParams, type VoronoiUniforms } from './shaders/voronoi.js';\n\n/** Static line pattern configurable into textures ranging from sharp zigzags to smooth flowing waves */\nexport { wavesFragmentShader, type WavesParams, type WavesUniforms } from './shaders/waves.js';\n\n/** Animated color fields warped by noise and swirls, applied over base patterns (checks, stripes, or split edge). Blends up to 10 colors with adjustable distribution, softness, distortion, and swirl. Great for fluid, smoky, or marbled effects */\nexport {\n warpMeta,\n warpFragmentShader,\n WarpPatterns,\n type WarpParams,\n type WarpUniforms,\n type WarpPattern,\n} from './shaders/warp.js';\n\n/** Animated rays of light radiating from the center, blended with up to 5 colors. The rays are adjustable by size, density, brightness and center glow. Great for dramatic backgrounds, logo reveals, and VFX like energy bursts or sun shafts */\nexport { godRaysMeta, godRaysFragmentShader, type GodRaysParams, type GodRaysUniforms } from './shaders/god-rays.js';\n\n/** A single-colored animated spiral that morphs across a wide range of shapes - from crisp, thin-lined geometry to flowing whirlpool forms and wavy, abstract rings */\nexport { spiralFragmentShader, type SpiralParams, type SpiralUniforms } from './shaders/spiral.js';\n\n/** Animated bands of color twisting and bending, producing spirals, arcs, and flowing circular patterns */\nexport { swirlMeta, swirlFragmentShader, type SwirlParams, type SwirlUniforms } from './shaders/swirl.js';\n\n/** Animated 2-color dithering over with multiple pattern sources (noise, warp, dots, waves, ripple, swirl, sphere) */\nexport {\n ditheringFragmentShader,\n DitheringShapes,\n DitheringTypes,\n type DitheringParams,\n type DitheringUniforms,\n type DitheringShape,\n type DitheringType,\n} from './shaders/dithering.js';\n\n/** Multi-color gradients with grainy, noise-textured distortion available in 7 animated abstract forms */\nexport {\n grainGradientFragmentShader,\n grainGradientMeta,\n GrainGradientShapes,\n type GrainGradientParams,\n type GrainGradientUniforms,\n type GrainGradientShape,\n} from './shaders/grain-gradient.js';\n\n/** Luminous trails of color merging into a glowing gradient frame */\nexport {\n pulsingBorderMeta,\n pulsingBorderFragmentShader,\n PulsingBorderAspectRatios,\n type PulsingBorderParams,\n type PulsingBorderUniforms,\n type PulsingBorderAspectRatio,\n} from './shaders/pulsing-border.js';\n\n/** Glowing translucent 3D panels rotating around a central axis */\nexport {\n colorPanelsFragmentShader,\n colorPanelsMeta,\n type ColorPanelsParams,\n type ColorPanelsUniforms,\n} from './shaders/color-panels.js';\n\n/** Multi-point mesh gradients with up to 10 color spots, enhanced by two-direction warping, adjustable blend sharpness, and grain controls. Perfect for elegant wallpapers and atmospheric backdrops */\nexport {\n staticMeshGradientFragmentShader,\n staticMeshGradientMeta,\n type StaticMeshGradientParams,\n type StaticMeshGradientUniforms,\n} from './shaders/static-mesh-gradient.js';\n\n/** Radial gradient with up to 10 blended colors, featuring advanced focal point control, shape distortion, and grain effects */\nexport {\n staticRadialGradientFragmentShader,\n staticRadialGradientMeta,\n type StaticRadialGradientParams,\n type StaticRadialGradientUniforms,\n} from './shaders/static-radial-gradient.js';\n\n/** A static texture built from multiple noise layers, usable for a realistic paper and cardboard surfaces or generating abstract patterns. Can be used as a image filter or as a texture */\nexport {\n paperTextureFragmentShader,\n paperTextureMeta,\n type PaperTextureParams,\n type PaperTextureUniforms,\n} from './shaders/paper-texture.js';\n\n/** Water-like surface distortion with natural caustic realism. Works as an image filter or animated texture without image */\nexport { waterFragmentShader, type WaterParams, type WaterUniforms } from './shaders/water.js';\n\n/** Fluted glass image filter transforms an image into streaked, ribbed distortions, giving a mix of clarity and obscurity */\nexport {\n flutedGlassFragmentShader,\n GlassDistortionShapes,\n GlassGridShapes,\n type GlassDistortionShape,\n type GlassGridShape,\n type FlutedGlassParams,\n type FlutedGlassUniforms,\n} from './shaders/fluted-glass.js';\n\n/** A dithering image filter with support for 4 dithering modes and multiple color palettes (2-color, 3-color, and multicolor options, using either predefined colors or ones sampled directly from the original image) */\nexport {\n imageDitheringFragmentShader,\n type ImageDitheringParams,\n type ImageDitheringUniforms,\n} from './shaders/image-dithering.js';\n\n/** Lens Distortion image filter that separates an image into shifting color layers, recreating the chromatic aberration of a lens, and warps the image geometry with barrel or pincushion curvature */\nexport {\n lensDistortionFragmentShader,\n lensDistortionMeta,\n type LensDistortionParams,\n type LensDistortionUniforms,\n} from './shaders/lens-distortion.js';\n\n/** A glowing gradient of colors flowing through an input image. The effect creates a smoothly animated wave of intensity across the image */\nexport {\n heatmapMeta,\n heatmapFragmentShader,\n toProcessedHeatmap,\n type HeatmapParams,\n type HeatmapUniforms,\n} from './shaders/heatmap.js';\n\n/** Futuristic liquid metal material applied to uploaded logo or one of pre-defined abstract shape */\nexport {\n liquidMetalFragmentShader,\n LiquidMetalShapes,\n toProcessedLiquidMetal,\n type LiquidMetalShape,\n type LiquidMetalParams,\n type LiquidMetalUniforms,\n} from './shaders/liquid-metal.js';\n\n/** A halftone-dot image filter featuring customizable grids, color palettes, and dot styles */\nexport {\n HalftoneDotsTypes,\n HalftoneDotsGrids,\n halftoneDotsFragmentShader,\n type HalftoneDotsParams,\n type HalftoneDotsUniforms,\n type HalftoneDotsType,\n type HalftoneDotsGrid,\n} from './shaders/halftone-dots.js';\n\n/** A halftone CMYK classic algo */\nexport {\n HalftoneCmykTypes,\n halftoneCmykFragmentShader,\n type HalftoneCmykParams,\n type HalftoneCmykUniforms,\n type HalftoneCmykType,\n} from './shaders/halftone-cmyk.js';\n\n/** Animated color fields running around a glassy logo shape */\nexport {\n gemSmokeMeta,\n gemSmokeFragmentShader,\n toProcessedGemSmoke,\n GemSmokeShapes,\n type GemSmokeShape,\n type GemSmokeParams,\n type GemSmokeUniforms,\n} from './shaders/gem-smoke.js';\n\n// ----- Utils ----- //\nexport { getShaderColorFromString } from './get-shader-color-from-string.js';\nexport { getShaderNoiseTexture } from './get-shader-noise-texture.js';\nexport { emptyPixel } from './empty-pixel.js';\n"],
5
- "mappings": ";;;;;AACA,SAAS,aAAa,4BAA4B;AAClD,SAAS,+BAA+B;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C;AACzC,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;",
4
+ "sourcesContent": ["/** The core Shader Mount class. Pass it a parent element and a fragment shader to get started. */\nexport { ShaderMount, isPaperShaderElement } from './shader-mount.js';\nexport { isHtmlInCanvasSupported } from './html-in-canvas.js';\nexport { observeContentSize, type ShaderSizeToContent } from './size-to-content.js';\nexport type {\n PaperShaderElement,\n ShaderMotionParams,\n ShaderMountUniforms,\n ShaderPreset,\n ImageShaderPreset,\n} from './shader-mount.js';\n\n/** Shader sizing options and uniforms */\nexport {\n defaultObjectSizing,\n defaultPatternSizing,\n ShaderFitOptions,\n type ShaderFit,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from './shader-sizing.js';\n\n/** A flowing interplay of color spots, moving along distinct trajectories and transformed by organic distortion */\nexport {\n meshGradientFragmentShader,\n meshGradientMeta,\n type MeshGradientParams,\n type MeshGradientUniforms,\n} from './shaders/mesh-gradient.js';\n\n/** Radial multi-colored gradient shaped with layered noise for a natural, smoky aesthetic */\nexport {\n smokeRingMeta,\n smokeRingFragmentShader,\n type SmokeRingParams,\n type SmokeRingUniforms,\n} from './shaders/smoke-ring.js';\n\n/** A glowing, web-like structure of fluid lines and soft intersections. Great for creating atmospheric, organic-yet-futuristic visuals */\nexport { neuroNoiseFragmentShader, type NeuroNoiseParams, type NeuroNoiseUniforms } from './shaders/neuro-noise.js';\n\n/** Animated multi-color dots pattern with each dot orbiting around its cell center. Supports up to 40 colors and various shape and motion controls. Great for playful, dynamic backgrounds and UI textures */\nexport {\n dotOrbitMeta,\n dotOrbitFragmentShader,\n type DotOrbitParams,\n type DotOrbitUniforms,\n} from './shaders/dot-orbit.js';\n\n/** Static grid pattern made of circles, diamonds, squares or triangles */\nexport {\n dotGridFragmentShader,\n DotGridShapes,\n type DotGridShape,\n type DotGridParams,\n type DotGridUniforms,\n} from './shaders/dot-grid.js';\n\n/** A multi-color gradient mapped into smooth, animated curves, delivering a sleek, futuristic visual */\nexport {\n simplexNoiseMeta,\n simplexNoiseFragmentShader,\n type SimplexNoiseParams,\n type SimplexNoiseUniforms,\n} from './shaders/simplex-noise.js';\n\n/** Up to 20 gooey blobs moving around the center and merging into smooth organic shapes */\nexport {\n metaballsMeta,\n metaballsFragmentShader,\n type MetaballsParams,\n type MetaballsUniforms,\n} from './shaders/metaballs.js';\n\n/** Animated 3D Perlin noise with exposed controls */\nexport { perlinNoiseFragmentShader, type PerlinNoiseParams, type PerlinNoiseUniforms } from './shaders/perlin-noise.js';\n\n/** Anti-aliased animated Voronoi pattern with smooth and customizable edges */\nexport { voronoiMeta, voronoiFragmentShader, type VoronoiParams, type VoronoiUniforms } from './shaders/voronoi.js';\n\n/** Static line pattern configurable into textures ranging from sharp zigzags to smooth flowing waves */\nexport { wavesFragmentShader, type WavesParams, type WavesUniforms } from './shaders/waves.js';\n\n/** Animated color fields warped by noise and swirls, applied over base patterns (checks, stripes, or split edge). Blends up to 10 colors with adjustable distribution, softness, distortion, and swirl. Great for fluid, smoky, or marbled effects */\nexport {\n warpMeta,\n warpFragmentShader,\n WarpPatterns,\n type WarpParams,\n type WarpUniforms,\n type WarpPattern,\n} from './shaders/warp.js';\n\n/** Animated rays of light radiating from the center, blended with up to 5 colors. The rays are adjustable by size, density, brightness and center glow. Great for dramatic backgrounds, logo reveals, and VFX like energy bursts or sun shafts */\nexport { godRaysMeta, godRaysFragmentShader, type GodRaysParams, type GodRaysUniforms } from './shaders/god-rays.js';\n\n/** A single-colored animated spiral that morphs across a wide range of shapes - from crisp, thin-lined geometry to flowing whirlpool forms and wavy, abstract rings */\nexport { spiralFragmentShader, type SpiralParams, type SpiralUniforms } from './shaders/spiral.js';\n\n/** Animated bands of color twisting and bending, producing spirals, arcs, and flowing circular patterns */\nexport { swirlMeta, swirlFragmentShader, type SwirlParams, type SwirlUniforms } from './shaders/swirl.js';\n\n/** Animated 2-color dithering over with multiple pattern sources (noise, warp, dots, waves, ripple, swirl, sphere) */\nexport {\n ditheringFragmentShader,\n DitheringShapes,\n DitheringTypes,\n type DitheringParams,\n type DitheringUniforms,\n type DitheringShape,\n type DitheringType,\n} from './shaders/dithering.js';\n\n/** Multi-color gradients with grainy, noise-textured distortion available in 7 animated abstract forms */\nexport {\n grainGradientFragmentShader,\n grainGradientMeta,\n GrainGradientShapes,\n type GrainGradientParams,\n type GrainGradientUniforms,\n type GrainGradientShape,\n} from './shaders/grain-gradient.js';\n\n/** Luminous trails of color merging into a glowing gradient frame */\nexport {\n pulsingBorderMeta,\n pulsingBorderFragmentShader,\n PulsingBorderAspectRatios,\n type PulsingBorderParams,\n type PulsingBorderUniforms,\n type PulsingBorderAspectRatio,\n} from './shaders/pulsing-border.js';\n\n/** Glowing translucent 3D panels rotating around a central axis */\nexport {\n colorPanelsFragmentShader,\n colorPanelsMeta,\n type ColorPanelsParams,\n type ColorPanelsUniforms,\n} from './shaders/color-panels.js';\n\n/** Multi-point mesh gradients with up to 10 color spots, enhanced by two-direction warping, adjustable blend sharpness, and grain controls. Perfect for elegant wallpapers and atmospheric backdrops */\nexport {\n staticMeshGradientFragmentShader,\n staticMeshGradientMeta,\n type StaticMeshGradientParams,\n type StaticMeshGradientUniforms,\n} from './shaders/static-mesh-gradient.js';\n\n/** Radial gradient with up to 10 blended colors, featuring advanced focal point control, shape distortion, and grain effects */\nexport {\n staticRadialGradientFragmentShader,\n staticRadialGradientMeta,\n type StaticRadialGradientParams,\n type StaticRadialGradientUniforms,\n} from './shaders/static-radial-gradient.js';\n\n/** A static texture built from multiple noise layers, usable for a realistic paper and cardboard surfaces or generating abstract patterns. Can be used as a image filter or as a texture */\nexport {\n paperTextureFragmentShader,\n paperTextureMeta,\n type PaperTextureParams,\n type PaperTextureUniforms,\n} from './shaders/paper-texture.js';\n\n/** Water-like surface distortion with natural caustic realism. Works as an image filter or animated texture without image */\nexport { waterFragmentShader, type WaterParams, type WaterUniforms } from './shaders/water.js';\n\n/** Fluted glass image filter transforms an image into streaked, ribbed distortions, giving a mix of clarity and obscurity */\nexport {\n flutedGlassFragmentShader,\n GlassDistortionShapes,\n GlassGridShapes,\n type GlassDistortionShape,\n type GlassGridShape,\n type FlutedGlassParams,\n type FlutedGlassUniforms,\n} from './shaders/fluted-glass.js';\n\n/** A dithering image filter with support for 4 dithering modes and multiple color palettes (2-color, 3-color, and multicolor options, using either predefined colors or ones sampled directly from the original image) */\nexport {\n imageDitheringFragmentShader,\n type ImageDitheringParams,\n type ImageDitheringUniforms,\n} from './shaders/image-dithering.js';\n\n/** Lens Distortion image filter that separates an image into shifting color layers, recreating the chromatic aberration of a lens, and warps the image geometry with barrel or pincushion curvature */\nexport {\n lensDistortionFragmentShader,\n lensDistortionMeta,\n type LensDistortionParams,\n type LensDistortionUniforms,\n} from './shaders/lens-distortion.js';\n\n/** A glowing gradient of colors flowing through an input image. The effect creates a smoothly animated wave of intensity across the image */\nexport {\n heatmapMeta,\n heatmapFragmentShader,\n toProcessedHeatmap,\n type HeatmapParams,\n type HeatmapUniforms,\n} from './shaders/heatmap.js';\n\n/** Futuristic liquid metal material applied to uploaded logo or one of pre-defined abstract shape */\nexport {\n liquidMetalFragmentShader,\n LiquidMetalShapes,\n toProcessedLiquidMetal,\n type LiquidMetalShape,\n type LiquidMetalParams,\n type LiquidMetalUniforms,\n} from './shaders/liquid-metal.js';\n\n/** A halftone-dot image filter featuring customizable grids, color palettes, and dot styles */\nexport {\n HalftoneDotsTypes,\n HalftoneDotsGrids,\n halftoneDotsFragmentShader,\n type HalftoneDotsParams,\n type HalftoneDotsUniforms,\n type HalftoneDotsType,\n type HalftoneDotsGrid,\n} from './shaders/halftone-dots.js';\n\n/** A halftone CMYK classic algo */\nexport {\n HalftoneCmykTypes,\n halftoneCmykFragmentShader,\n type HalftoneCmykParams,\n type HalftoneCmykUniforms,\n type HalftoneCmykType,\n} from './shaders/halftone-cmyk.js';\n\n/** Animated color fields running around a glassy logo shape */\nexport {\n gemSmokeMeta,\n gemSmokeFragmentShader,\n toProcessedGemSmoke,\n GemSmokeShapes,\n type GemSmokeShape,\n type GemSmokeParams,\n type GemSmokeUniforms,\n} from './shaders/gem-smoke.js';\n\n// ----- Utils ----- //\nexport { getShaderColorFromString } from './get-shader-color-from-string.js';\nexport { getShaderNoiseTexture } from './get-shader-noise-texture.js';\nexport { emptyPixel } from './empty-pixel.js';\n"],
5
+ "mappings": ";;;;;AACA,SAAS,aAAa,4BAA4B;AAClD,SAAS,+BAA+B;AACxC,SAAS,0BAAoD;AAU7D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,gCAAgF;AAGzF;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,iCAAmF;AAG5F,SAAS,aAAa,6BAAuE;AAG7F,SAAS,2BAAiE;AAG1E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,aAAa,6BAAuE;AAG7F,SAAS,4BAAoE;AAG7E,SAAS,WAAW,2BAAiE;AAGrF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,2BAAiE;AAG1E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;",
6
6
  "names": []
7
7
  }
@@ -1,17 +1,8 @@
1
1
  export declare class ShaderMount {
2
2
  parentElement: PaperShaderElement;
3
- /** The canvas the shader is drawn on, which is the root shader's canvas when nested in its HTML */
4
3
  canvasElement: HTMLCanvasElement;
5
4
  private gl;
6
5
  private program;
7
- private vertexArray;
8
- /** Canvas of the root shader, when this one is nested in its HTML and renders into a framebuffer of its context */
9
- private hostCanvas;
10
- /** Where a nested shader renders to, so its parent can paste it into its HTML */
11
- private output;
12
- /** Size of what the shader draws into: its canvas, or its output when nested */
13
- private drawingWidth;
14
- private drawingHeight;
15
6
  private uniformLocations;
16
7
  /** The fragment shader that we are using */
17
8
  private fragmentShader;
@@ -86,22 +77,11 @@ export declare class ShaderMount {
86
77
  private setupResizeObserver;
87
78
  private setupIntersectionObserver;
88
79
  private handleVisualViewportChange;
80
+ /** Resizes to the canvas right away, for size changes the resize observer would only see next frame */
81
+ syncSize: () => void;
89
82
  /** Resize handler for when the container div changes size or the max pixel count changes and we want to resize our canvas to match */
90
83
  private handleResize;
91
84
  private render;
92
- private advanceFrame;
93
- /** Draws the shader, after the shaders nested in its HTML so they can be pasted into it */
94
- private draw;
95
- /** Pastes the output of the nested shaders into the HTML that holds them, where they're laid out */
96
- private pasteNestedShaders;
97
- /** All the shaders nested in the HTML of this root shader, at any depth */
98
- private getNestedShaders;
99
- /** The nested shaders whose closest shader ancestor is this one */
100
- private getNestedChildren;
101
- private getParentShader;
102
- /** The shader that owns the canvas and runs the render loop */
103
- private getRoot;
104
- private isAnimating;
105
85
  private requestRender;
106
86
  /** Creates a texture from an image and sets it into a uniform value */
107
87
  private setTextureUniform;
@@ -111,8 +91,6 @@ export declare class ShaderMount {
111
91
  /** Captures each HTML uniform into its texture. On resize only HTML that has a snapshot already, so it can't throw */
112
92
  private captureHtml;
113
93
  private unsetHtmlUniform;
114
- /** WebGL doesn't tell hit testing and accessibility where the HTML is drawn, which is where it's laid out */
115
- private updateHtmlGeometry;
116
94
  private handleCanvasPaint;
117
95
  /** Utility: recursive equality test for all the uniforms */
118
96
  private areUniformValuesEqual;
@@ -127,8 +105,6 @@ export declare class ShaderMount {
127
105
  /** Apply the target speed, pausing (0) while the tab is hidden or the element is out of the viewport */
128
106
  private updateCurrentSpeed;
129
107
  private setCurrentSpeed;
130
- /** The root shader loops while it or any of the shaders nested in it animates */
131
- private updateAnimationLoop;
132
108
  /** Set the maximum pixel count for the shader, this will limit the number of pixels that will be rendered */
133
109
  setMaxPixelCount: (newMaxPixelCount?: number) => void;
134
110
  /** Set the minimum pixel ratio for the shader */