@paper-design/shaders 0.0.0-canary.2d03406 → 0.0.0-canary.3ce21729

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.
Files changed (50) hide show
  1. package/dist/html-content.d.ts +17 -0
  2. package/dist/html-content.js +93 -0
  3. package/dist/html-content.js.map +7 -0
  4. package/dist/html-in-canvas.d.ts +7 -19
  5. package/dist/html-in-canvas.js +24 -55
  6. package/dist/html-in-canvas.js.map +2 -2
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +2 -2
  10. package/dist/shader-mount.d.ts +60 -10
  11. package/dist/shader-mount.js +261 -98
  12. package/dist/shader-mount.js.map +2 -2
  13. package/dist/shaders/color-panels.js +0 -3
  14. package/dist/shaders/color-panels.js.map +2 -2
  15. package/dist/shaders/dot-orbit.js +1 -2
  16. package/dist/shaders/dot-orbit.js.map +2 -2
  17. package/dist/shaders/fluted-glass.d.ts +6 -6
  18. package/dist/shaders/fluted-glass.js +11 -11
  19. package/dist/shaders/fluted-glass.js.map +2 -2
  20. package/dist/shaders/god-rays.js +3 -5
  21. package/dist/shaders/god-rays.js.map +2 -2
  22. package/dist/shaders/halftone-cmyk.d.ts +6 -7
  23. package/dist/shaders/halftone-cmyk.js +11 -9
  24. package/dist/shaders/halftone-cmyk.js.map +2 -2
  25. package/dist/shaders/halftone-dots.d.ts +6 -7
  26. package/dist/shaders/halftone-dots.js +12 -11
  27. package/dist/shaders/halftone-dots.js.map +2 -2
  28. package/dist/shaders/image-dithering.d.ts +5 -5
  29. package/dist/shaders/image-dithering.js +34 -28
  30. package/dist/shaders/image-dithering.js.map +2 -2
  31. package/dist/shaders/lens-distortion.d.ts +3 -4
  32. package/dist/shaders/lens-distortion.js +16 -23
  33. package/dist/shaders/lens-distortion.js.map +2 -2
  34. package/dist/shaders/liquid-metal.js +1 -2
  35. package/dist/shaders/liquid-metal.js.map +2 -2
  36. package/dist/shaders/paper-texture.d.ts +8 -8
  37. package/dist/shaders/paper-texture.js +12 -12
  38. package/dist/shaders/paper-texture.js.map +2 -2
  39. package/dist/shaders/voronoi.js +1 -2
  40. package/dist/shaders/voronoi.js.map +2 -2
  41. package/dist/shaders/water.d.ts +6 -8
  42. package/dist/shaders/water.js +13 -11
  43. package/dist/shaders/water.js.map +2 -2
  44. package/dist/shared-context.d.ts +73 -0
  45. package/dist/shared-context.js +339 -0
  46. package/dist/shared-context.js.map +7 -0
  47. package/dist/vertex-shader.d.ts +1 -1
  48. package/dist/vertex-shader.js +21 -21
  49. package/dist/vertex-shader.js.map +1 -1
  50. package/package.json +1 -1
@@ -0,0 +1,17 @@
1
+ /** Axes on which the shader takes the size of its content instead of its own size styles */
2
+ export type ShaderSizeToContent = 'width' | 'height' | 'both';
3
+ export interface HtmlContentObserver {
4
+ /** Syncs right away, for style changes that don't resize anything */
5
+ update(): void;
6
+ disconnect(): void;
7
+ }
8
+ /**
9
+ * Keeps the content element of an HTML shader in step with the shader element.
10
+ *
11
+ * The content element covers the shader's padding, like the canvas, so the shader's padding is copied onto it.
12
+ *
13
+ * With `sizeToContent`, the content element is measured, since the canvas can't be sized by what's inside it.
14
+ * The caller applies the measured size: `--paper-shader-content-width` and `--paper-shader-content-height` on the
15
+ * shader. `data-size-to-content` on the shader puts the content element at `max-content` width or `auto` height
16
+ */
17
+ export declare function observeHtmlContent(shader: HTMLElement, content: HTMLElement, sizeToContent?: ShaderSizeToContent): HtmlContentObserver;
@@ -0,0 +1,93 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ const WIDTH_VARIABLE = "--paper-shader-content-width";
7
+ const HEIGHT_VARIABLE = "--paper-shader-content-height";
8
+ const MIN_WIDTH_VARIABLE = "--paper-shader-content-min-width";
9
+ const MAX_WIDTH_VARIABLE = "--paper-shader-content-max-width";
10
+ const MIN_HEIGHT_VARIABLE = "--paper-shader-content-min-height";
11
+ const MAX_HEIGHT_VARIABLE = "--paper-shader-content-max-height";
12
+ const SIZE_VARIABLES = [
13
+ WIDTH_VARIABLE,
14
+ HEIGHT_VARIABLE,
15
+ MIN_WIDTH_VARIABLE,
16
+ MAX_WIDTH_VARIABLE,
17
+ MIN_HEIGHT_VARIABLE,
18
+ MAX_HEIGHT_VARIABLE
19
+ ];
20
+ function observeHtmlContent(shader, content, sizeToContent) {
21
+ let contentWidth = 0;
22
+ let contentHeight = 0;
23
+ let isMeasured = false;
24
+ const update = () => {
25
+ const style = getComputedStyle(shader);
26
+ const padding = `${style.paddingTop} ${style.paddingRight} ${style.paddingBottom} ${style.paddingLeft}`;
27
+ if (content.style.padding !== padding) {
28
+ content.style.padding = padding;
29
+ }
30
+ if (!sizeToContent || !isMeasured) return;
31
+ let extraX = 0;
32
+ let extraY = 0;
33
+ if (style.boxSizing === "border-box") {
34
+ extraX = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
35
+ extraY = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
36
+ } else {
37
+ extraX = -(parseFloat(style.paddingLeft) + parseFloat(style.paddingRight));
38
+ extraY = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom));
39
+ }
40
+ let hasChanged = setVariable(shader, WIDTH_VARIABLE, `${Math.max(0, contentWidth + extraX)}px`);
41
+ hasChanged = setVariable(shader, HEIGHT_VARIABLE, `${Math.max(0, contentHeight + extraY)}px`) || hasChanged;
42
+ for (const [variable, value, extra] of [
43
+ [MIN_WIDTH_VARIABLE, style.minWidth, extraX],
44
+ [MAX_WIDTH_VARIABLE, style.maxWidth, extraX],
45
+ [MIN_HEIGHT_VARIABLE, style.minHeight, extraY],
46
+ [MAX_HEIGHT_VARIABLE, style.maxHeight, extraY]
47
+ ]) {
48
+ const limit = value.endsWith("px") ? `${Math.max(0, parseFloat(value) - extra)}px` : null;
49
+ hasChanged = setVariable(shader, variable, limit) || hasChanged;
50
+ }
51
+ if (hasChanged) {
52
+ shader.paperShaderMount?.syncSize();
53
+ }
54
+ };
55
+ const observer = new ResizeObserver((entries) => {
56
+ for (const entry of entries) {
57
+ const size = entry.borderBoxSize[0];
58
+ if (entry.target === content && size) {
59
+ contentWidth = size.inlineSize;
60
+ contentHeight = size.blockSize;
61
+ isMeasured = true;
62
+ }
63
+ }
64
+ update();
65
+ });
66
+ observer.observe(content, { box: "border-box" });
67
+ observer.observe(shader);
68
+ update();
69
+ return {
70
+ update,
71
+ disconnect: () => {
72
+ observer.disconnect();
73
+ for (const variable of SIZE_VARIABLES) {
74
+ shader.style.removeProperty(variable);
75
+ }
76
+ }
77
+ };
78
+ }
79
+ function setVariable(element, variable, value) {
80
+ const current = element.style.getPropertyValue(variable);
81
+ if (value === null) {
82
+ if (current === "") return false;
83
+ element.style.removeProperty(variable);
84
+ return true;
85
+ }
86
+ if (current === value) return false;
87
+ element.style.setProperty(variable, value);
88
+ return true;
89
+ }
90
+ export {
91
+ observeHtmlContent
92
+ };
93
+ //# sourceMappingURL=html-content.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/html-content.ts"],
4
+ "sourcesContent": ["import type { PaperShaderElement } from './shader-mount.js';\n\nconst WIDTH_VARIABLE = '--paper-shader-content-width';\nconst HEIGHT_VARIABLE = '--paper-shader-content-height';\nconst MIN_WIDTH_VARIABLE = '--paper-shader-content-min-width';\nconst MAX_WIDTH_VARIABLE = '--paper-shader-content-max-width';\nconst MIN_HEIGHT_VARIABLE = '--paper-shader-content-min-height';\nconst MAX_HEIGHT_VARIABLE = '--paper-shader-content-max-height';\nconst SIZE_VARIABLES = [\n WIDTH_VARIABLE,\n HEIGHT_VARIABLE,\n MIN_WIDTH_VARIABLE,\n MAX_WIDTH_VARIABLE,\n MIN_HEIGHT_VARIABLE,\n MAX_HEIGHT_VARIABLE,\n];\n\n/** Axes on which the shader takes the size of its content instead of its own size styles */\nexport type ShaderSizeToContent = 'width' | 'height' | 'both';\n\nexport interface HtmlContentObserver {\n /** Syncs right away, for style changes that don't resize anything */\n update(): void;\n disconnect(): void;\n}\n\n/**\n * Keeps the content element of an HTML shader in step with the shader element.\n *\n * The content element covers the shader's padding, like the canvas, so the shader's padding is copied onto it.\n *\n * With `sizeToContent`, the content element is measured, since the canvas can't be sized by what's inside it.\n * The caller applies the measured size: `--paper-shader-content-width` and `--paper-shader-content-height` on the\n * shader. `data-size-to-content` on the shader puts the content element at `max-content` width or `auto` height\n */\nexport function observeHtmlContent(\n shader: HTMLElement,\n content: HTMLElement,\n sizeToContent?: ShaderSizeToContent\n): HtmlContentObserver {\n let contentWidth = 0;\n let contentHeight = 0;\n let isMeasured = false;\n\n const update = () => {\n const style = getComputedStyle(shader);\n\n const padding = `${style.paddingTop} ${style.paddingRight} ${style.paddingBottom} ${style.paddingLeft}`;\n if (content.style.padding !== padding) {\n content.style.padding = padding;\n }\n\n if (!sizeToContent || !isMeasured) return;\n\n // The canvas and the content fill the shader's padding box, so the size set on the shader is the content size plus\n // the border for border-box, or minus the padding for content-box\n let extraX = 0;\n let extraY = 0;\n if (style.boxSizing === 'border-box') {\n extraX = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);\n extraY = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);\n } else {\n extraX = -(parseFloat(style.paddingLeft) + parseFloat(style.paddingRight));\n extraY = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom));\n }\n\n let hasChanged = setVariable(shader, WIDTH_VARIABLE, `${Math.max(0, contentWidth + extraX)}px`);\n hasChanged = setVariable(shader, HEIGHT_VARIABLE, `${Math.max(0, contentHeight + extraY)}px`) || hasChanged;\n\n // The content wraps at the shader's size limits. Only px ones: a percentage would be of the shader,\n // which takes the content size, so the content would keep shrinking\n for (const [variable, value, extra] of [\n [MIN_WIDTH_VARIABLE, style.minWidth, extraX],\n [MAX_WIDTH_VARIABLE, style.maxWidth, extraX],\n [MIN_HEIGHT_VARIABLE, style.minHeight, extraY],\n [MAX_HEIGHT_VARIABLE, style.maxHeight, extraY],\n ] as const) {\n const limit = value.endsWith('px') ? `${Math.max(0, parseFloat(value) - extra)}px` : null;\n hasChanged = setVariable(shader, variable, limit) || hasChanged;\n }\n\n // Otherwise the canvas only sees its new size next frame\n if (hasChanged) {\n (shader as PaperShaderElement).paperShaderMount?.syncSize();\n }\n };\n\n // The shader is observed too, so that its border and padding changes are picked up\n const observer = new ResizeObserver((entries) => {\n for (const entry of entries) {\n const size = entry.borderBoxSize[0];\n if (entry.target === content && size) {\n contentWidth = size.inlineSize;\n contentHeight = size.blockSize;\n isMeasured = true;\n }\n }\n update();\n });\n // Border box, so that the content's padding changes are picked up\n observer.observe(content, { box: 'border-box' });\n observer.observe(shader);\n\n update();\n\n return {\n update,\n disconnect: () => {\n observer.disconnect();\n for (const variable of SIZE_VARIABLES) {\n shader.style.removeProperty(variable);\n }\n },\n };\n}\n\n/** Returns whether the value changed, null removes the variable */\nfunction setVariable(element: HTMLElement, variable: string, value: string | null): boolean {\n const current = element.style.getPropertyValue(variable);\n if (value === null) {\n if (current === '') return false;\n element.style.removeProperty(variable);\n return true;\n }\n if (current === value) return false;\n element.style.setProperty(variable, value);\n return true;\n}\n"],
5
+ "mappings": ";;;;;AAEA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAoBO,SAAS,mBACd,QACA,SACA,eACqB;AACrB,MAAI,eAAe;AACnB,MAAI,gBAAgB;AACpB,MAAI,aAAa;AAEjB,QAAM,SAAS,MAAM;AACnB,UAAM,QAAQ,iBAAiB,MAAM;AAErC,UAAM,UAAU,GAAG,MAAM,UAAU,IAAI,MAAM,YAAY,IAAI,MAAM,aAAa,IAAI,MAAM,WAAW;AACrG,QAAI,QAAQ,MAAM,YAAY,SAAS;AACrC,cAAQ,MAAM,UAAU;AAAA,IAC1B;AAEA,QAAI,CAAC,iBAAiB,CAAC,WAAY;AAInC,QAAI,SAAS;AACb,QAAI,SAAS;AACb,QAAI,MAAM,cAAc,cAAc;AACpC,eAAS,WAAW,MAAM,eAAe,IAAI,WAAW,MAAM,gBAAgB;AAC9E,eAAS,WAAW,MAAM,cAAc,IAAI,WAAW,MAAM,iBAAiB;AAAA,IAChF,OAAO;AACL,eAAS,EAAE,WAAW,MAAM,WAAW,IAAI,WAAW,MAAM,YAAY;AACxE,eAAS,EAAE,WAAW,MAAM,UAAU,IAAI,WAAW,MAAM,aAAa;AAAA,IAC1E;AAEA,QAAI,aAAa,YAAY,QAAQ,gBAAgB,GAAG,KAAK,IAAI,GAAG,eAAe,MAAM,CAAC,IAAI;AAC9F,iBAAa,YAAY,QAAQ,iBAAiB,GAAG,KAAK,IAAI,GAAG,gBAAgB,MAAM,CAAC,IAAI,KAAK;AAIjG,eAAW,CAAC,UAAU,OAAO,KAAK,KAAK;AAAA,MACrC,CAAC,oBAAoB,MAAM,UAAU,MAAM;AAAA,MAC3C,CAAC,oBAAoB,MAAM,UAAU,MAAM;AAAA,MAC3C,CAAC,qBAAqB,MAAM,WAAW,MAAM;AAAA,MAC7C,CAAC,qBAAqB,MAAM,WAAW,MAAM;AAAA,IAC/C,GAAY;AACV,YAAM,QAAQ,MAAM,SAAS,IAAI,IAAI,GAAG,KAAK,IAAI,GAAG,WAAW,KAAK,IAAI,KAAK,CAAC,OAAO;AACrF,mBAAa,YAAY,QAAQ,UAAU,KAAK,KAAK;AAAA,IACvD;AAGA,QAAI,YAAY;AACd,MAAC,OAA8B,kBAAkB,SAAS;AAAA,IAC5D;AAAA,EACF;AAGA,QAAM,WAAW,IAAI,eAAe,CAAC,YAAY;AAC/C,eAAW,SAAS,SAAS;AAC3B,YAAM,OAAO,MAAM,cAAc,CAAC;AAClC,UAAI,MAAM,WAAW,WAAW,MAAM;AACpC,uBAAe,KAAK;AACpB,wBAAgB,KAAK;AACrB,qBAAa;AAAA,MACf;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AAED,WAAS,QAAQ,SAAS,EAAE,KAAK,aAAa,CAAC;AAC/C,WAAS,QAAQ,MAAM;AAEvB,SAAO;AAEP,SAAO;AAAA,IACL;AAAA,IACA,YAAY,MAAM;AAChB,eAAS,WAAW;AACpB,iBAAW,YAAY,gBAAgB;AACrC,eAAO,MAAM,eAAe,QAAQ;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;AAGA,SAAS,YAAY,SAAsB,UAAkB,OAA+B;AAC1F,QAAM,UAAU,QAAQ,MAAM,iBAAiB,QAAQ;AACvD,MAAI,UAAU,MAAM;AAClB,QAAI,YAAY,GAAI,QAAO;AAC3B,YAAQ,MAAM,eAAe,QAAQ;AACrC,WAAO;AAAA,EACT;AACA,MAAI,YAAY,MAAO,QAAO;AAC9B,UAAQ,MAAM,YAAY,UAAU,KAAK;AACzC,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,35 +1,23 @@
1
1
  /**
2
- * Experimental HTML-in-canvas support (https://github.com/WICG/html-in-canvas),
3
- * available in Chromium behind `chrome://flags/#canvas-draw-element`. Older Chromium versions opt the canvas in with
4
- * `layoutsubtree` instead of `content="drawable"`, so the canvas gets both.
2
+ * https://github.com/WICG/html-in-canvas
5
3
  *
6
- * An HTML element passed as a texture uniform is moved into the shader canvas and drawn 1:1 where it's laid out:
4
+ * An HTML uniform has to be in this markup already, `layoutsubtree` is for older Chromium:
7
5
  *
8
6
  * <div data-paper-shader>
9
7
  * <canvas content="drawable" layoutsubtree>
10
8
  * <div drawable>…</div>
11
9
  * </canvas>
12
10
  * </div>
13
- *
14
- * React renders this markup itself, since it can't let its nodes be moved, and the shader adopts that canvas.
15
- *
16
- * The HTML texture always matches the canvas size, so shaders sample it like any canvas-sized texture: a resize
17
- * captures the HTML again right away instead of waiting for the next paint.
18
11
  */
19
12
  export interface DrawableCanvasElement extends HTMLCanvasElement {
20
13
  requestPaint(): void;
21
- updateElementGeometry(element: Element, options?: {
22
- canvasTransform?: DOMMatrixInit;
23
- }): void;
24
14
  }
25
15
  export declare function isHtmlInCanvasSupported(): boolean;
26
- /** `<img>` stays a static image uniform. nodeType instead of `instanceof` works across iframes */
16
+ /** nodeType, since `instanceof` fails across iframes */
27
17
  export declare function isHtmlUniform(value: unknown): value is HTMLElement;
28
- export declare function findReactCanvas(values: unknown[], parentElement: Element): DrawableCanvasElement | null;
29
- /** Moves the element into the canvas, returns a function that puts it back */
30
- export declare function attachHtml(canvas: DrawableCanvasElement, element: HTMLElement): () => void;
18
+ export declare function findDrawableCanvas(values: unknown[], parentElement: Element): DrawableCanvasElement | null;
31
19
  /**
32
- * Captures the element into the bound texture, sized to the canvas drawing buffer. The texture is only reallocated
33
- * (and so cleared) when its size or the drawn area changes; returns that layout to pass back in next time
20
+ * Draws the element into its canvas where it's laid out, scaled to the canvas resolution.
21
+ * Only in the canvas `paint` event, as that's when the browser has the element's paint record
34
22
  */
35
- export declare function drawHtml(gl: WebGL2RenderingContext, canvas: DrawableCanvasElement, element: HTMLElement, lastLayout?: string): string;
23
+ export declare function drawHtml(context: CanvasRenderingContext2D, element: HTMLElement): void;
@@ -4,12 +4,12 @@
4
4
  * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
5
 
6
6
  function isHtmlInCanvasSupported() {
7
- return typeof HTMLCanvasElement !== "undefined" && "requestPaint" in HTMLCanvasElement.prototype && typeof WebGL2RenderingContext !== "undefined" && "texElementSubImage2D" in WebGL2RenderingContext.prototype;
7
+ return typeof HTMLCanvasElement !== "undefined" && "requestPaint" in HTMLCanvasElement.prototype && typeof CanvasRenderingContext2D !== "undefined" && "drawElementImage" in CanvasRenderingContext2D.prototype;
8
8
  }
9
9
  function isHtmlUniform(value) {
10
- return typeof value === "object" && value !== null && value.nodeType === 1 && value.tagName !== "IMG";
10
+ return value?.nodeType === 1 && value.tagName !== "IMG";
11
11
  }
12
- function findReactCanvas(values, parentElement) {
12
+ function findDrawableCanvas(values, parentElement) {
13
13
  for (const value of values) {
14
14
  const canvas = isHtmlUniform(value) ? value.parentElement : null;
15
15
  if (canvas?.tagName === "CANVAS" && canvas.parentElement === parentElement) {
@@ -18,61 +18,30 @@ function findReactCanvas(values, parentElement) {
18
18
  }
19
19
  return null;
20
20
  }
21
- function attachHtml(canvas, element) {
22
- if (element.parentElement === canvas) {
23
- return () => {
24
- };
25
- }
26
- const parent = element.parentNode;
27
- const nextSibling = element.nextSibling;
28
- canvas.setAttribute("content", "drawable");
29
- canvas.setAttribute("layoutsubtree", "");
30
- element.setAttribute("drawable", "");
31
- canvas.append(element);
32
- return () => {
33
- element.removeAttribute("drawable");
34
- if (parent) {
35
- parent.insertBefore(element, nextSibling?.parentNode === parent ? nextSibling : null);
36
- } else {
37
- element.remove();
38
- }
39
- };
40
- }
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);
46
- const left = element.offsetLeft;
47
- const top = element.offsetTop;
48
- const visibleLeft = Math.max(0, left);
49
- const visibleTop = Math.max(0, top);
50
- const visibleRight = Math.min(canvas.clientWidth, left + element.offsetWidth);
51
- const visibleBottom = Math.min(canvas.clientHeight, top + element.offsetHeight);
52
- const x0 = Math.round(visibleLeft * scaleX);
53
- const y0 = Math.round(visibleTop * scaleY);
54
- const x1 = Math.min(width, Math.round(visibleRight * scaleX));
55
- const y1 = Math.min(height, Math.round(visibleBottom * scaleY));
56
- const layout = `${width}x${height} ${x0},${y0},${x1},${y1}`;
57
- if (layout !== lastLayout) {
58
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
59
- }
60
- if (x1 > x0 && y1 > y0) {
61
- gl.texElementSubImage2D(gl.TEXTURE_2D, 0, x0, y0, element, {
62
- sx: visibleLeft - left,
63
- sy: visibleTop - top,
64
- swidth: visibleRight - visibleLeft,
65
- sheight: visibleBottom - visibleTop,
66
- width: x1 - x0,
67
- height: y1 - y0
68
- });
69
- }
70
- return layout;
21
+ function drawHtml(context, element) {
22
+ const canvas = context.canvas;
23
+ const canvasStyle = getComputedStyle(canvas);
24
+ const elementStyle = getComputedStyle(element);
25
+ const canvasCssWidth = parseFloat(canvasStyle.width) || canvas.clientWidth;
26
+ const canvasCssHeight = parseFloat(canvasStyle.height) || canvas.clientHeight;
27
+ const elementCssWidth = parseFloat(elementStyle.width) || element.offsetWidth;
28
+ const elementCssHeight = parseFloat(elementStyle.height) || element.offsetHeight;
29
+ const scaleX = canvas.width / Math.max(1, canvasCssWidth);
30
+ const scaleY = canvas.height / Math.max(1, canvasCssHeight);
31
+ context.setTransform(1, 0, 0, 1, 0, 0);
32
+ context.globalCompositeOperation = "source-over";
33
+ context.clearRect(0, 0, canvas.width, canvas.height);
34
+ context.drawElementImage(
35
+ element,
36
+ element.offsetLeft * scaleX,
37
+ element.offsetTop * scaleY,
38
+ elementCssWidth * scaleX,
39
+ elementCssHeight * scaleY
40
+ );
71
41
  }
72
42
  export {
73
- attachHtml,
74
43
  drawHtml,
75
- findReactCanvas,
44
+ findDrawableCanvas,
76
45
  isHtmlInCanvasSupported,
77
46
  isHtmlUniform
78
47
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/html-in-canvas.ts"],
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;AACX,YAAQ,gBAAgB,UAAU;AAClC,QAAI,QAAQ;AACV,aAAO,aAAa,SAAS,aAAa,eAAe,SAAS,cAAc,IAAI;AAAA,IACtF,OAAO;AACL,cAAQ,OAAO;AAAA,IACjB;AAAA,EACF;AACF;AAMO,SAAS,SACd,IACA,QACA,SACA,YACQ;AACR,QAAM,QAAQ,KAAK,IAAI,GAAG,OAAO,KAAK;AACtC,QAAM,SAAS,KAAK,IAAI,GAAG,OAAO,MAAM;AACxC,QAAM,SAAS,QAAQ,KAAK,IAAI,GAAG,OAAO,WAAW;AACrD,QAAM,SAAS,SAAS,KAAK,IAAI,GAAG,OAAO,YAAY;AAEvD,QAAM,OAAO,QAAQ;AACrB,QAAM,MAAM,QAAQ;AACpB,QAAM,cAAc,KAAK,IAAI,GAAG,IAAI;AACpC,QAAM,aAAa,KAAK,IAAI,GAAG,GAAG;AAClC,QAAM,eAAe,KAAK,IAAI,OAAO,aAAa,OAAO,QAAQ,WAAW;AAC5E,QAAM,gBAAgB,KAAK,IAAI,OAAO,cAAc,MAAM,QAAQ,YAAY;AAC9E,QAAM,KAAK,KAAK,MAAM,cAAc,MAAM;AAC1C,QAAM,KAAK,KAAK,MAAM,aAAa,MAAM;AACzC,QAAM,KAAK,KAAK,IAAI,OAAO,KAAK,MAAM,eAAe,MAAM,CAAC;AAC5D,QAAM,KAAK,KAAK,IAAI,QAAQ,KAAK,MAAM,gBAAgB,MAAM,CAAC;AAE9D,QAAM,SAAS,GAAG,KAAK,IAAI,MAAM,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;AACzD,MAAI,WAAW,YAAY;AACzB,OAAG,WAAW,GAAG,YAAY,GAAG,GAAG,OAAO,OAAO,QAAQ,GAAG,GAAG,MAAM,GAAG,eAAe,IAAI;AAAA,EAC7F;AAEA,MAAI,KAAK,MAAM,KAAK,IAAI;AACtB,IAAC,GAAmC,qBAAqB,GAAG,YAAY,GAAG,IAAI,IAAI,SAAS;AAAA,MAC1F,IAAI,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;",
4
+ "sourcesContent": ["/**\n * https://github.com/WICG/html-in-canvas\n *\n * An HTML uniform has to be in this markup already, `layoutsubtree` is for older Chromium:\n *\n * <div data-paper-shader>\n * <canvas content=\"drawable\" layoutsubtree>\n * <div drawable>\u2026</div>\n * </canvas>\n * </div>\n */\n\nexport interface DrawableCanvasElement extends HTMLCanvasElement {\n requestPaint(): void;\n}\n\ninterface DrawableCanvasRenderingContext2D extends CanvasRenderingContext2D {\n drawElementImage(element: Element, dx: number, dy: number, dwidth: number, dheight: number): DOMMatrix;\n}\n\nexport function isHtmlInCanvasSupported(): boolean {\n return (\n typeof HTMLCanvasElement !== 'undefined' &&\n 'requestPaint' in HTMLCanvasElement.prototype &&\n typeof CanvasRenderingContext2D !== 'undefined' &&\n 'drawElementImage' in CanvasRenderingContext2D.prototype\n );\n}\n\n/** nodeType, since `instanceof` fails across iframes */\nexport function isHtmlUniform(value: unknown): value is HTMLElement {\n return (value as Node | null | undefined)?.nodeType === 1 && (value as Element).tagName !== 'IMG';\n}\n\nexport function findDrawableCanvas(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 * Draws the element into its canvas where it's laid out, scaled to the canvas resolution.\n * Only in the canvas `paint` event, as that's when the browser has the element's paint record\n */\nexport function drawHtml(context: CanvasRenderingContext2D, element: HTMLElement): void {\n const canvas = context.canvas as HTMLCanvasElement;\n\n // Offset and client sizes are rounded, bounding rects include ancestor transforms\n const canvasStyle = getComputedStyle(canvas);\n const elementStyle = getComputedStyle(element);\n const canvasCssWidth = parseFloat(canvasStyle.width) || canvas.clientWidth;\n const canvasCssHeight = parseFloat(canvasStyle.height) || canvas.clientHeight;\n const elementCssWidth = parseFloat(elementStyle.width) || element.offsetWidth;\n const elementCssHeight = parseFloat(elementStyle.height) || element.offsetHeight;\n const scaleX = canvas.width / Math.max(1, canvasCssWidth);\n const scaleY = canvas.height / Math.max(1, canvasCssHeight);\n\n context.setTransform(1, 0, 0, 1, 0, 0);\n context.globalCompositeOperation = 'source-over';\n context.clearRect(0, 0, canvas.width, canvas.height);\n\n // Also places the element for hit testing and accessibility where it's drawn, which is where it's laid out\n (context as DrawableCanvasRenderingContext2D).drawElementImage(\n element,\n element.offsetLeft * scaleX,\n element.offsetTop * scaleY,\n elementCssWidth * scaleX,\n elementCssHeight * scaleY\n );\n}\n"],
5
+ "mappings": ";;;;;AAoBO,SAAS,0BAAmC;AACjD,SACE,OAAO,sBAAsB,eAC7B,kBAAkB,kBAAkB,aACpC,OAAO,6BAA6B,eACpC,sBAAsB,yBAAyB;AAEnD;AAGO,SAAS,cAAc,OAAsC;AAClE,SAAQ,OAAmC,aAAa,KAAM,MAAkB,YAAY;AAC9F;AAEO,SAAS,mBAAmB,QAAmB,eAAsD;AAC1G,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,SAAS,SAAmC,SAA4B;AACtF,QAAM,SAAS,QAAQ;AAGvB,QAAM,cAAc,iBAAiB,MAAM;AAC3C,QAAM,eAAe,iBAAiB,OAAO;AAC7C,QAAM,iBAAiB,WAAW,YAAY,KAAK,KAAK,OAAO;AAC/D,QAAM,kBAAkB,WAAW,YAAY,MAAM,KAAK,OAAO;AACjE,QAAM,kBAAkB,WAAW,aAAa,KAAK,KAAK,QAAQ;AAClE,QAAM,mBAAmB,WAAW,aAAa,MAAM,KAAK,QAAQ;AACpE,QAAM,SAAS,OAAO,QAAQ,KAAK,IAAI,GAAG,cAAc;AACxD,QAAM,SAAS,OAAO,SAAS,KAAK,IAAI,GAAG,eAAe;AAE1D,UAAQ,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACrC,UAAQ,2BAA2B;AACnC,UAAQ,UAAU,GAAG,GAAG,OAAO,OAAO,OAAO,MAAM;AAGnD,EAAC,QAA6C;AAAA,IAC5C;AAAA,IACA,QAAQ,aAAa;AAAA,IACrB,QAAQ,YAAY;AAAA,IACpB,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EACrB;AACF;",
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 { observeHtmlContent, type HtmlContentObserver, type ShaderSizeToContent } from './html-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 { observeHtmlContent } from "./html-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
+ observeHtmlContent,
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;AAUxC;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;",
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 { observeHtmlContent, type HtmlContentObserver, type ShaderSizeToContent } from './html-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,0BAA8E;AAUvF;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,13 +1,22 @@
1
- export declare class ShaderMount {
1
+ import { type SharedContextUser } from './shared-context.js';
2
+ export declare class ShaderMount implements SharedContextUser {
2
3
  parentElement: PaperShaderElement;
4
+ /** A 2D canvas, the shader draws with a WebGL context shared by every shader and copies the frame here */
3
5
  canvasElement: HTMLCanvasElement;
6
+ readonly context2d: CanvasRenderingContext2D;
7
+ /** The size to draw at, the canvas takes it when the frame is copied into it */
8
+ frameWidth: number;
9
+ frameHeight: number;
10
+ private sharedContext;
4
11
  private gl;
5
12
  private program;
13
+ private vertexArray;
14
+ private positionBuffer;
6
15
  private uniformLocations;
7
16
  /** The fragment shader that we are using */
8
17
  private fragmentShader;
9
- /** Stores the RAF for the render loop */
10
- private rafId;
18
+ /** If a frame is scheduled in the shared context's render loop */
19
+ private isFrameScheduled;
11
20
  /** Time of the last rendered frame */
12
21
  private lastRenderTime;
13
22
  /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */
@@ -28,12 +37,16 @@ export declare class ShaderMount {
28
37
  private textures;
29
38
  private minPixelRatio;
30
39
  private maxPixelCount;
40
+ private resolutionScale;
31
41
  private isSafari;
32
42
  private uniformCache;
33
43
  private textureUnitMap;
34
44
  private ownerDocument;
35
45
  private htmlUniforms;
36
- private isReactCanvas;
46
+ private isProvidedCanvas;
47
+ /** Resolves after the first render at the element's size */
48
+ readonly ready: Promise<void>;
49
+ private resolveReadyPromise;
37
50
  constructor(
38
51
  /** The div you'd like to mount the shader to. The shader will match its size. */
39
52
  parentElement: HTMLElement, fragmentShader: string, uniforms: ShaderMountUniforms, webGlContextAttributes?: WebGLContextAttributes,
@@ -55,7 +68,14 @@ export declare class ShaderMount {
55
68
  */
56
69
  maxPixelCount?: number,
57
70
  /** Names of the uniforms that should have mipmaps generated for them */
58
- mipmaps?: string[]);
71
+ mipmaps?: string[],
72
+ /**
73
+ * Multiplier on the rendered resolution, defaults to 1.
74
+ * Useful when an ancestor is scaled with a CSS transform, which layout sizes ignore.
75
+ */
76
+ resolutionScale?: number);
77
+ /** Creates the program and its resources in the shared context */
78
+ private initGl;
59
79
  private initProgram;
60
80
  private setupPositionAttribute;
61
81
  private setupUniforms;
@@ -73,22 +93,42 @@ export declare class ShaderMount {
73
93
  private devicePixelsSupported;
74
94
  private intersectionObserver;
75
95
  private isInViewport;
96
+ /** Paused by the app, whatever the speed */
97
+ private isPaused;
76
98
  private resizeObserver;
77
99
  private setupResizeObserver;
78
100
  private setupIntersectionObserver;
79
101
  private handleVisualViewportChange;
102
+ /** Resizes to the canvas right away, for size changes the resize observer would only see next frame */
103
+ syncSize: () => void;
80
104
  /** Resize handler for when the container div changes size or the max pixel count changes and we want to resize our canvas to match */
81
105
  private handleResize;
106
+ /** Draws right away instead of in the next shared animation frame */
82
107
  private render;
108
+ /** Draws into the viewport the shared context set up for this shader */
109
+ drawFrame: (currentTime: number) => void;
110
+ /** Nothing can draw until the context is restored, so `ready` doesn't wait for it */
111
+ handleContextLost: () => void;
112
+ /** The restored context has none of the old resources, so they're all created again from the provided uniforms */
113
+ handleContextRestored: () => void;
114
+ private bindTextures;
115
+ /** HTML is captured and drawn in the canvas paint event, so a shader with HTML draws only there */
83
116
  private requestRender;
84
117
  /** Creates a texture from an image and sets it into a uniform value */
85
118
  private setTextureUniform;
86
119
  private createTexture;
87
- /** Moves the element into the shader canvas and redraws it into the texture on every canvas paint */
120
+ /** Captures the element, which has to be a child of the shader canvas, into the texture on every canvas paint */
88
121
  private setHtmlUniform;
89
- /** Captures each HTML uniform into its texture. On resize only HTML that has a snapshot already, so it can't throw */
122
+ /** Without HTML left, a frame that waits for a paint is drawn in the shared render loop instead */
123
+ private removeHtmlUniform;
124
+ /** HTML is drawn 1:1, so its aspect ratio is the canvas aspect ratio. Needs this program in use */
125
+ private setHtmlAspectRatio;
126
+ /** Draws each HTML uniform into the canvas and uploads it into its texture, which replaces the frame in the canvas */
90
127
  private captureHtml;
91
- private unsetHtmlUniform;
128
+ /**
129
+ * Captured and drawn within the paint event, so the captured HTML never shows in place of the frame.
130
+ * Also the animation loop of a shader with HTML, `drawFrame` requests the next paint while animating
131
+ */
92
132
  private handleCanvasPaint;
93
133
  /** Utility: recursive equality test for all the uniforms */
94
134
  private areUniformValuesEqual;
@@ -100,16 +140,20 @@ export declare class ShaderMount {
100
140
  setFrame: (newFrame: number) => void;
101
141
  /** Set an animation speed (or 0 to stop animation) */
102
142
  setSpeed: (newSpeed?: number) => void;
103
- /** Apply the target speed, pausing (0) while the tab is hidden or the element is out of the viewport */
143
+ /** Pause or resume the animation, keeping the speed to resume at, e.g. while the shader is too small to notice it */
144
+ setPaused: (isPaused: boolean) => void;
145
+ /** Apply the target speed, pausing (0) while paused, the tab is hidden or the element is out of the viewport */
104
146
  private updateCurrentSpeed;
105
147
  private setCurrentSpeed;
106
148
  /** Set the maximum pixel count for the shader, this will limit the number of pixels that will be rendered */
107
149
  setMaxPixelCount: (newMaxPixelCount?: number) => void;
108
150
  /** Set the minimum pixel ratio for the shader */
109
151
  setMinPixelRatio: (newMinPixelRatio?: number) => void;
152
+ /** Set the multiplier on the rendered resolution */
153
+ setResolutionScale: (newResolutionScale?: number) => void;
110
154
  /** Update the uniforms that are provided by the outside shader, can be a partial set with only the uniforms that have changed */
111
155
  setUniforms: (newUniforms: ShaderMountUniforms) => void;
112
- /** Render right away only when the rAF loop isn't running */
156
+ /** Render right away only when no frame is scheduled, e.g. for frame by frame exports that capture right after */
113
157
  private renderUnlessAnimating;
114
158
  private handleDocumentVisibilityChange;
115
159
  /** Dispose of the shader mount, cleaning up all of the WebGL resources */
@@ -118,6 +162,8 @@ export declare class ShaderMount {
118
162
  /** The parent `<div>` element that has a ShaderMount available on it */
119
163
  export interface PaperShaderElement extends HTMLElement {
120
164
  paperShaderMount: ShaderMount | undefined;
165
+ /** Set by the React ShaderMount, resolves with the mount once it's `ready` */
166
+ paperShaderMountReady?: Promise<ShaderMount | null>;
121
167
  }
122
168
  /** Check if an element is a Paper shader element */
123
169
  export declare function isPaperShaderElement(element: HTMLElement): element is PaperShaderElement;
@@ -126,6 +172,10 @@ export declare function isPaperShaderElement(element: HTMLElement): element is P
126
172
  *
127
173
  * We accept undefined as a convenience for server rendering, when some things may be undefined
128
174
  * We just skip setting the uniform if it's undefined. This allows the shader mount to still take up space during server rendering
175
+ *
176
+ * An image or HTML uniform `u_name` also sets these uniforms when the shader declares them:
177
+ * - `u_nameAspectRatio` (float): width / height of the image, or of the canvas for HTML, since HTML is drawn 1:1
178
+ * - `u_nameIsHtml` (bool): true when the uniform is HTML
129
179
  */
130
180
  export interface ShaderMountUniforms {
131
181
  [key: string]: boolean | number | number[] | number[][] | HTMLImageElement | HTMLElement | undefined;