@paper-design/shaders 0.0.0-canary.8e2c2d8 → 0.0.0-canary.a0c0e896

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 (40) 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 +23 -0
  5. package/dist/html-in-canvas.js +48 -0
  6. package/dist/html-in-canvas.js.map +7 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +4 -0
  9. package/dist/index.js.map +2 -2
  10. package/dist/shader-mount.d.ts +54 -14
  11. package/dist/shader-mount.js +271 -62
  12. package/dist/shader-mount.js.map +2 -2
  13. package/dist/shaders/fluted-glass.d.ts +3 -0
  14. package/dist/shaders/fluted-glass.js +14 -3
  15. package/dist/shaders/fluted-glass.js.map +2 -2
  16. package/dist/shaders/halftone-cmyk.d.ts +3 -1
  17. package/dist/shaders/halftone-cmyk.js +23 -3
  18. package/dist/shaders/halftone-cmyk.js.map +2 -2
  19. package/dist/shaders/halftone-dots.d.ts +3 -1
  20. package/dist/shaders/halftone-dots.js +23 -3
  21. package/dist/shaders/halftone-dots.js.map +2 -2
  22. package/dist/shaders/image-dithering.d.ts +4 -2
  23. package/dist/shaders/image-dithering.js +14 -4
  24. package/dist/shaders/image-dithering.js.map +2 -2
  25. package/dist/shaders/lens-distortion.d.ts +2 -0
  26. package/dist/shaders/lens-distortion.js +11 -4
  27. package/dist/shaders/lens-distortion.js.map +2 -2
  28. package/dist/shaders/paper-texture.d.ts +4 -0
  29. package/dist/shaders/paper-texture.js +22 -9
  30. package/dist/shaders/paper-texture.js.map +2 -2
  31. package/dist/shaders/water.d.ts +3 -1
  32. package/dist/shaders/water.js +22 -5
  33. package/dist/shaders/water.js.map +2 -2
  34. package/dist/shared-context.d.ts +72 -0
  35. package/dist/shared-context.js +300 -0
  36. package/dist/shared-context.js.map +7 -0
  37. package/dist/vertex-shader.d.ts +1 -1
  38. package/dist/vertex-shader.js +3 -0
  39. package/dist/vertex-shader.js.map +2 -2
  40. 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
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * https://github.com/WICG/html-in-canvas
3
+ *
4
+ * An HTML uniform has to be in this markup already, `layoutsubtree` is for older Chromium:
5
+ *
6
+ * <div data-paper-shader>
7
+ * <canvas content="drawable" layoutsubtree>
8
+ * <div drawable>…</div>
9
+ * </canvas>
10
+ * </div>
11
+ */
12
+ export interface DrawableCanvasElement extends HTMLCanvasElement {
13
+ requestPaint(): void;
14
+ }
15
+ export declare function isHtmlInCanvasSupported(): boolean;
16
+ /** nodeType, since `instanceof` fails across iframes */
17
+ export declare function isHtmlUniform(value: unknown): value is HTMLElement;
18
+ export declare function findDrawableCanvas(values: unknown[], parentElement: Element): DrawableCanvasElement | null;
19
+ /**
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
22
+ */
23
+ export declare function drawHtml(context: CanvasRenderingContext2D, element: HTMLElement): void;
@@ -0,0 +1,48 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ function isHtmlInCanvasSupported() {
7
+ return typeof HTMLCanvasElement !== "undefined" && "requestPaint" in HTMLCanvasElement.prototype && typeof CanvasRenderingContext2D !== "undefined" && "drawElementImage" in CanvasRenderingContext2D.prototype;
8
+ }
9
+ function isHtmlUniform(value) {
10
+ return value?.nodeType === 1 && value.tagName !== "IMG";
11
+ }
12
+ function findDrawableCanvas(values, parentElement) {
13
+ for (const value of values) {
14
+ const canvas = isHtmlUniform(value) ? value.parentElement : null;
15
+ if (canvas?.tagName === "CANVAS" && canvas.parentElement === parentElement) {
16
+ return canvas;
17
+ }
18
+ }
19
+ return null;
20
+ }
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
+ );
41
+ }
42
+ export {
43
+ drawHtml,
44
+ findDrawableCanvas,
45
+ isHtmlInCanvasSupported,
46
+ isHtmlUniform
47
+ };
48
+ //# sourceMappingURL=html-in-canvas.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/html-in-canvas.ts"],
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
+ "names": []
7
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +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
+ export { isHtmlInCanvasSupported } from './html-in-canvas.js';
4
+ export { observeHtmlContent, type HtmlContentObserver, type ShaderSizeToContent } from './html-content.js';
3
5
  export type { PaperShaderElement, ShaderMotionParams, ShaderMountUniforms, ShaderPreset, ImageShaderPreset, } from './shader-mount.js';
4
6
  /** Shader sizing options and uniforms */
5
7
  export { defaultObjectSizing, defaultPatternSizing, ShaderFitOptions, type ShaderFit, type ShaderSizingParams, type ShaderSizingUniforms, } from './shader-sizing.js';
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@
4
4
  * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
5
 
6
6
  import { ShaderMount, isPaperShaderElement } from "./shader-mount.js";
7
+ import { isHtmlInCanvasSupported } from "./html-in-canvas.js";
8
+ import { observeHtmlContent } from "./html-content.js";
7
9
  import {
8
10
  defaultObjectSizing,
9
11
  defaultPatternSizing,
@@ -156,6 +158,7 @@ export {
156
158
  heatmapFragmentShader,
157
159
  heatmapMeta,
158
160
  imageDitheringFragmentShader,
161
+ isHtmlInCanvasSupported,
159
162
  isPaperShaderElement,
160
163
  lensDistortionFragmentShader,
161
164
  lensDistortionMeta,
@@ -165,6 +168,7 @@ export {
165
168
  metaballsFragmentShader,
166
169
  metaballsMeta,
167
170
  neuroNoiseFragmentShader,
171
+ observeHtmlContent,
168
172
  paperTextureFragmentShader,
169
173
  paperTextureMeta,
170
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 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;AAUlD;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,14 @@ export declare class ShaderMount {
28
37
  private textures;
29
38
  private minPixelRatio;
30
39
  private maxPixelCount;
31
- private displayScale;
40
+ private resolutionScale;
32
41
  private isSafari;
33
42
  private uniformCache;
34
43
  private textureUnitMap;
35
44
  private ownerDocument;
36
- /** Resolves once the canvas has been rendered at its element's size with all of its inputs, e.g. to read its pixels */
45
+ private htmlUniforms;
46
+ private isProvidedCanvas;
47
+ /** Resolves after the first render at the element's size */
37
48
  readonly ready: Promise<void>;
38
49
  private resolveReadyPromise;
39
50
  constructor(
@@ -59,11 +70,12 @@ export declare class ShaderMount {
59
70
  /** Names of the uniforms that should have mipmaps generated for them */
60
71
  mipmaps?: string[],
61
72
  /**
62
- * The scale the element is displayed or drawn at, defaults to 1.
63
- * Layout sizes ignore CSS transforms and canvas drawing, so pass e.g. 0.25 when an ancestor is scaled to 25%,
64
- * or 3 when the element is captured at 3x. Still limited by `maxPixelCount`.
73
+ * Multiplier on the rendered resolution, defaults to 1.
74
+ * Useful when an ancestor is scaled with a CSS transform, which layout sizes ignore.
65
75
  */
66
- displayScale?: number);
76
+ resolutionScale?: number);
77
+ /** Creates the program and its resources in the shared context */
78
+ private initGl;
67
79
  private initProgram;
68
80
  private setupPositionAttribute;
69
81
  private setupUniforms;
@@ -85,13 +97,37 @@ export declare class ShaderMount {
85
97
  private setupResizeObserver;
86
98
  private setupIntersectionObserver;
87
99
  private handleVisualViewportChange;
100
+ /** Resizes to the canvas right away, for size changes the resize observer would only see next frame */
101
+ syncSize: () => void;
88
102
  /** Resize handler for when the container div changes size or the max pixel count changes and we want to resize our canvas to match */
89
103
  private handleResize;
104
+ /** Draws right away instead of in the next shared animation frame */
90
105
  private render;
106
+ /** Draws into the viewport the shared context set up for this shader */
107
+ drawFrame: (currentTime: number) => void;
108
+ /** Nothing can draw until the context is restored, so `ready` doesn't wait for it */
109
+ handleContextLost: () => void;
110
+ /** The restored context has none of the old resources, so they're all created again from the provided uniforms */
111
+ handleContextRestored: () => void;
112
+ private bindTextures;
113
+ /** HTML is captured and drawn in the canvas paint event, so a shader with HTML draws only there */
91
114
  private requestRender;
92
115
  /** Creates a texture from an image and sets it into a uniform value */
93
116
  private setTextureUniform;
94
117
  private createTexture;
118
+ /** Captures the element, which has to be a child of the shader canvas, into the texture on every canvas paint */
119
+ private setHtmlUniform;
120
+ /** Without HTML left, a frame that waits for a paint is drawn in the shared render loop instead */
121
+ private removeHtmlUniform;
122
+ /** HTML is drawn 1:1, so its aspect ratio is the canvas aspect ratio. Needs this program in use */
123
+ private setHtmlAspectRatio;
124
+ /** Draws each HTML uniform into the canvas and uploads it into its texture, which replaces the frame in the canvas */
125
+ private captureHtml;
126
+ /**
127
+ * Captured and drawn within the paint event, so the captured HTML never shows in place of the frame.
128
+ * Also the animation loop of a shader with HTML, `drawFrame` requests the next paint while animating
129
+ */
130
+ private handleCanvasPaint;
95
131
  /** Utility: recursive equality test for all the uniforms */
96
132
  private areUniformValuesEqual;
97
133
  /** Sets the provided uniform values into the WebGL program, can be a partial list of uniforms that have changed */
@@ -109,11 +145,11 @@ export declare class ShaderMount {
109
145
  setMaxPixelCount: (newMaxPixelCount?: number) => void;
110
146
  /** Set the minimum pixel ratio for the shader */
111
147
  setMinPixelRatio: (newMinPixelRatio?: number) => void;
112
- /** Set the scale the element is displayed or drawn at, e.g. when an ancestor's CSS transform scales it */
113
- setDisplayScale: (newDisplayScale?: number) => void;
148
+ /** Set the multiplier on the rendered resolution */
149
+ setResolutionScale: (newResolutionScale?: number) => void;
114
150
  /** Update the uniforms that are provided by the outside shader, can be a partial set with only the uniforms that have changed */
115
151
  setUniforms: (newUniforms: ShaderMountUniforms) => void;
116
- /** Render right away only when the rAF loop isn't running */
152
+ /** Render right away only when no frame is scheduled, e.g. for frame by frame exports that capture right after */
117
153
  private renderUnlessAnimating;
118
154
  private handleDocumentVisibilityChange;
119
155
  /** Dispose of the shader mount, cleaning up all of the WebGL resources */
@@ -122,7 +158,7 @@ export declare class ShaderMount {
122
158
  /** The parent `<div>` element that has a ShaderMount available on it */
123
159
  export interface PaperShaderElement extends HTMLElement {
124
160
  paperShaderMount: ShaderMount | undefined;
125
- /** Set by the React ShaderMount when it starts mounting, resolves with the mount once it's `ready` */
161
+ /** Set by the React ShaderMount, resolves with the mount once it's `ready` */
126
162
  paperShaderMountReady?: Promise<ShaderMount | null>;
127
163
  }
128
164
  /** Check if an element is a Paper shader element */
@@ -132,9 +168,13 @@ export declare function isPaperShaderElement(element: HTMLElement): element is P
132
168
  *
133
169
  * We accept undefined as a convenience for server rendering, when some things may be undefined
134
170
  * We just skip setting the uniform if it's undefined. This allows the shader mount to still take up space during server rendering
171
+ *
172
+ * An image or HTML uniform `u_name` also sets these uniforms when the shader declares them:
173
+ * - `u_nameAspectRatio` (float): width / height of the image, or of the canvas for HTML, since HTML is drawn 1:1
174
+ * - `u_nameIsHtml` (bool): true when the uniform is HTML
135
175
  */
136
176
  export interface ShaderMountUniforms {
137
- [key: string]: boolean | number | number[] | number[][] | HTMLImageElement | undefined;
177
+ [key: string]: boolean | number | number[] | number[][] | HTMLImageElement | HTMLElement | undefined;
138
178
  }
139
179
  export interface ShaderMotionParams {
140
180
  speed?: number;