@paper-design/shaders 0.0.0-canary.0d8316e

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 (127) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +7 -0
  4. package/dist/empty-pixel.d.ts +1 -0
  5. package/dist/empty-pixel.js +10 -0
  6. package/dist/empty-pixel.js.map +7 -0
  7. package/dist/get-shader-color-from-string.d.ts +3 -0
  8. package/dist/get-shader-color-from-string.js +101 -0
  9. package/dist/get-shader-color-from-string.js.map +7 -0
  10. package/dist/get-shader-noise-texture.d.ts +1 -0
  11. package/dist/get-shader-noise-texture.js +18 -0
  12. package/dist/get-shader-noise-texture.js.map +7 -0
  13. package/dist/html-in-canvas.d.ts +35 -0
  14. package/dist/html-in-canvas.js +79 -0
  15. package/dist/html-in-canvas.js.map +7 -0
  16. package/dist/index.d.ts +69 -0
  17. package/dist/index.js +196 -0
  18. package/dist/index.js.map +7 -0
  19. package/dist/shader-color-spaces.d.ts +6 -0
  20. package/dist/shader-color-spaces.js +96 -0
  21. package/dist/shader-color-spaces.js.map +7 -0
  22. package/dist/shader-mount.d.ts +151 -0
  23. package/dist/shader-mount.js +605 -0
  24. package/dist/shader-mount.js.map +7 -0
  25. package/dist/shader-sizing.d.ts +30 -0
  26. package/dist/shader-sizing.js +38 -0
  27. package/dist/shader-sizing.js.map +7 -0
  28. package/dist/shader-utils.d.ts +10 -0
  29. package/dist/shader-utils.js +131 -0
  30. package/dist/shader-utils.js.map +7 -0
  31. package/dist/shaders/color-panels.d.ts +70 -0
  32. package/dist/shaders/color-panels.js +224 -0
  33. package/dist/shaders/color-panels.js.map +7 -0
  34. package/dist/shaders/dithering.d.ts +62 -0
  35. package/dist/shaders/dithering.js +271 -0
  36. package/dist/shaders/dithering.js.map +7 -0
  37. package/dist/shaders/dot-grid.d.ts +65 -0
  38. package/dist/shaders/dot-grid.js +110 -0
  39. package/dist/shaders/dot-grid.js.map +7 -0
  40. package/dist/shaders/dot-orbit.d.ts +57 -0
  41. package/dist/shaders/dot-orbit.js +123 -0
  42. package/dist/shaders/dot-orbit.js.map +7 -0
  43. package/dist/shaders/fluted-glass.d.ts +115 -0
  44. package/dist/shaders/fluted-glass.js +361 -0
  45. package/dist/shaders/fluted-glass.js.map +7 -0
  46. package/dist/shaders/gem-smoke.d.ts +96 -0
  47. package/dist/shaders/gem-smoke.js +573 -0
  48. package/dist/shaders/gem-smoke.js.map +7 -0
  49. package/dist/shaders/god-rays.d.ts +67 -0
  50. package/dist/shaders/god-rays.js +133 -0
  51. package/dist/shaders/god-rays.js.map +7 -0
  52. package/dist/shaders/grain-gradient.d.ts +80 -0
  53. package/dist/shaders/grain-gradient.js +301 -0
  54. package/dist/shaders/grain-gradient.js.map +7 -0
  55. package/dist/shaders/halftone-cmyk.d.ts +107 -0
  56. package/dist/shaders/halftone-cmyk.js +319 -0
  57. package/dist/shaders/halftone-cmyk.js.map +7 -0
  58. package/dist/shaders/halftone-dots.d.ts +83 -0
  59. package/dist/shaders/halftone-dots.js +345 -0
  60. package/dist/shaders/halftone-dots.js.map +7 -0
  61. package/dist/shaders/heatmap.d.ts +66 -0
  62. package/dist/shaders/heatmap.js +384 -0
  63. package/dist/shaders/heatmap.js.map +7 -0
  64. package/dist/shaders/image-dithering.d.ts +66 -0
  65. package/dist/shaders/image-dithering.js +209 -0
  66. package/dist/shaders/image-dithering.js.map +7 -0
  67. package/dist/shaders/lens-distortion.d.ts +100 -0
  68. package/dist/shaders/lens-distortion.js +290 -0
  69. package/dist/shaders/lens-distortion.js.map +7 -0
  70. package/dist/shaders/liquid-metal.d.ts +89 -0
  71. package/dist/shaders/liquid-metal.js +633 -0
  72. package/dist/shaders/liquid-metal.js.map +7 -0
  73. package/dist/shaders/mesh-gradient.d.ts +52 -0
  74. package/dist/shaders/mesh-gradient.js +131 -0
  75. package/dist/shaders/mesh-gradient.js.map +7 -0
  76. package/dist/shaders/metaballs.d.ts +51 -0
  77. package/dist/shaders/metaballs.js +111 -0
  78. package/dist/shaders/metaballs.js.map +7 -0
  79. package/dist/shaders/neuro-noise.d.ts +47 -0
  80. package/dist/shaders/neuro-noise.js +77 -0
  81. package/dist/shaders/neuro-noise.js.map +7 -0
  82. package/dist/shaders/paper-texture.d.ts +113 -0
  83. package/dist/shaders/paper-texture.js +541 -0
  84. package/dist/shaders/paper-texture.js.map +7 -0
  85. package/dist/shaders/perlin-noise.d.ts +52 -0
  86. package/dist/shaders/perlin-noise.js +167 -0
  87. package/dist/shaders/perlin-noise.js.map +7 -0
  88. package/dist/shaders/pulsing-border.d.ts +98 -0
  89. package/dist/shaders/pulsing-border.js +239 -0
  90. package/dist/shaders/pulsing-border.js.map +7 -0
  91. package/dist/shaders/simplex-noise.d.ts +45 -0
  92. package/dist/shaders/simplex-noise.js +92 -0
  93. package/dist/shaders/simplex-noise.js.map +7 -0
  94. package/dist/shaders/smoke-ring.d.ts +61 -0
  95. package/dist/shaders/smoke-ring.js +133 -0
  96. package/dist/shaders/smoke-ring.js.map +7 -0
  97. package/dist/shaders/spiral.d.ts +61 -0
  98. package/dist/shaders/spiral.js +83 -0
  99. package/dist/shaders/spiral.js.map +7 -0
  100. package/dist/shaders/static-mesh-gradient.d.ts +63 -0
  101. package/dist/shaders/static-mesh-gradient.js +131 -0
  102. package/dist/shaders/static-mesh-gradient.js.map +7 -0
  103. package/dist/shaders/static-radial-gradient.d.ts +72 -0
  104. package/dist/shaders/static-radial-gradient.js +188 -0
  105. package/dist/shaders/static-radial-gradient.js.map +7 -0
  106. package/dist/shaders/swirl.d.ts +63 -0
  107. package/dist/shaders/swirl.js +104 -0
  108. package/dist/shaders/swirl.js.map +7 -0
  109. package/dist/shaders/voronoi.d.ts +65 -0
  110. package/dist/shaders/voronoi.js +139 -0
  111. package/dist/shaders/voronoi.js.map +7 -0
  112. package/dist/shaders/warp.d.ts +70 -0
  113. package/dist/shaders/warp.js +130 -0
  114. package/dist/shaders/warp.js.map +7 -0
  115. package/dist/shaders/water.d.ts +63 -0
  116. package/dist/shaders/water.js +135 -0
  117. package/dist/shaders/water.js.map +7 -0
  118. package/dist/shaders/waves.d.ts +53 -0
  119. package/dist/shaders/waves.js +66 -0
  120. package/dist/shaders/waves.js.map +7 -0
  121. package/dist/types.d.ts +3 -0
  122. package/dist/types.js +6 -0
  123. package/dist/types.js.map +7 -0
  124. package/dist/vertex-shader.d.ts +2 -0
  125. package/dist/vertex-shader.js +163 -0
  126. package/dist/vertex-shader.js.map +7 -0
  127. package/package.json +29 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,69 @@
1
+ /** The core Shader Mount class. Pass it a parent element and a fragment shader to get started. */
2
+ export { ShaderMount, isPaperShaderElement } from './shader-mount.js';
3
+ export { isHtmlInCanvasSupported } from './html-in-canvas.js';
4
+ export type { PaperShaderElement, ShaderMotionParams, ShaderMountUniforms, ShaderPreset, ImageShaderPreset, } from './shader-mount.js';
5
+ /** Shader sizing options and uniforms */
6
+ export { defaultObjectSizing, defaultPatternSizing, ShaderFitOptions, type ShaderFit, type ShaderSizingParams, type ShaderSizingUniforms, } from './shader-sizing.js';
7
+ /** A flowing interplay of color spots, moving along distinct trajectories and transformed by organic distortion */
8
+ export { meshGradientFragmentShader, meshGradientMeta, type MeshGradientParams, type MeshGradientUniforms, } from './shaders/mesh-gradient.js';
9
+ /** Radial multi-colored gradient shaped with layered noise for a natural, smoky aesthetic */
10
+ export { smokeRingMeta, smokeRingFragmentShader, type SmokeRingParams, type SmokeRingUniforms, } from './shaders/smoke-ring.js';
11
+ /** A glowing, web-like structure of fluid lines and soft intersections. Great for creating atmospheric, organic-yet-futuristic visuals */
12
+ export { neuroNoiseFragmentShader, type NeuroNoiseParams, type NeuroNoiseUniforms } from './shaders/neuro-noise.js';
13
+ /** 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 */
14
+ export { dotOrbitMeta, dotOrbitFragmentShader, type DotOrbitParams, type DotOrbitUniforms, } from './shaders/dot-orbit.js';
15
+ /** Static grid pattern made of circles, diamonds, squares or triangles */
16
+ export { dotGridFragmentShader, DotGridShapes, type DotGridShape, type DotGridParams, type DotGridUniforms, } from './shaders/dot-grid.js';
17
+ /** A multi-color gradient mapped into smooth, animated curves, delivering a sleek, futuristic visual */
18
+ export { simplexNoiseMeta, simplexNoiseFragmentShader, type SimplexNoiseParams, type SimplexNoiseUniforms, } from './shaders/simplex-noise.js';
19
+ /** Up to 20 gooey blobs moving around the center and merging into smooth organic shapes */
20
+ export { metaballsMeta, metaballsFragmentShader, type MetaballsParams, type MetaballsUniforms, } from './shaders/metaballs.js';
21
+ /** Animated 3D Perlin noise with exposed controls */
22
+ export { perlinNoiseFragmentShader, type PerlinNoiseParams, type PerlinNoiseUniforms } from './shaders/perlin-noise.js';
23
+ /** Anti-aliased animated Voronoi pattern with smooth and customizable edges */
24
+ export { voronoiMeta, voronoiFragmentShader, type VoronoiParams, type VoronoiUniforms } from './shaders/voronoi.js';
25
+ /** Static line pattern configurable into textures ranging from sharp zigzags to smooth flowing waves */
26
+ export { wavesFragmentShader, type WavesParams, type WavesUniforms } from './shaders/waves.js';
27
+ /** 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 */
28
+ export { warpMeta, warpFragmentShader, WarpPatterns, type WarpParams, type WarpUniforms, type WarpPattern, } from './shaders/warp.js';
29
+ /** 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 */
30
+ export { godRaysMeta, godRaysFragmentShader, type GodRaysParams, type GodRaysUniforms } from './shaders/god-rays.js';
31
+ /** 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 */
32
+ export { spiralFragmentShader, type SpiralParams, type SpiralUniforms } from './shaders/spiral.js';
33
+ /** Animated bands of color twisting and bending, producing spirals, arcs, and flowing circular patterns */
34
+ export { swirlMeta, swirlFragmentShader, type SwirlParams, type SwirlUniforms } from './shaders/swirl.js';
35
+ /** Animated 2-color dithering over with multiple pattern sources (noise, warp, dots, waves, ripple, swirl, sphere) */
36
+ export { ditheringFragmentShader, DitheringShapes, DitheringTypes, type DitheringParams, type DitheringUniforms, type DitheringShape, type DitheringType, } from './shaders/dithering.js';
37
+ /** Multi-color gradients with grainy, noise-textured distortion available in 7 animated abstract forms */
38
+ export { grainGradientFragmentShader, grainGradientMeta, GrainGradientShapes, type GrainGradientParams, type GrainGradientUniforms, type GrainGradientShape, } from './shaders/grain-gradient.js';
39
+ /** Luminous trails of color merging into a glowing gradient frame */
40
+ export { pulsingBorderMeta, pulsingBorderFragmentShader, PulsingBorderAspectRatios, type PulsingBorderParams, type PulsingBorderUniforms, type PulsingBorderAspectRatio, } from './shaders/pulsing-border.js';
41
+ /** Glowing translucent 3D panels rotating around a central axis */
42
+ export { colorPanelsFragmentShader, colorPanelsMeta, type ColorPanelsParams, type ColorPanelsUniforms, } from './shaders/color-panels.js';
43
+ /** 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 */
44
+ export { staticMeshGradientFragmentShader, staticMeshGradientMeta, type StaticMeshGradientParams, type StaticMeshGradientUniforms, } from './shaders/static-mesh-gradient.js';
45
+ /** Radial gradient with up to 10 blended colors, featuring advanced focal point control, shape distortion, and grain effects */
46
+ export { staticRadialGradientFragmentShader, staticRadialGradientMeta, type StaticRadialGradientParams, type StaticRadialGradientUniforms, } from './shaders/static-radial-gradient.js';
47
+ /** 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 */
48
+ export { paperTextureFragmentShader, paperTextureMeta, type PaperTextureParams, type PaperTextureUniforms, } from './shaders/paper-texture.js';
49
+ /** Water-like surface distortion with natural caustic realism. Works as an image filter or animated texture without image */
50
+ export { waterFragmentShader, type WaterParams, type WaterUniforms } from './shaders/water.js';
51
+ /** Fluted glass image filter transforms an image into streaked, ribbed distortions, giving a mix of clarity and obscurity */
52
+ export { flutedGlassFragmentShader, GlassDistortionShapes, GlassGridShapes, type GlassDistortionShape, type GlassGridShape, type FlutedGlassParams, type FlutedGlassUniforms, } from './shaders/fluted-glass.js';
53
+ /** 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) */
54
+ export { imageDitheringFragmentShader, type ImageDitheringParams, type ImageDitheringUniforms, } from './shaders/image-dithering.js';
55
+ /** 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 */
56
+ export { lensDistortionFragmentShader, lensDistortionMeta, type LensDistortionParams, type LensDistortionUniforms, } from './shaders/lens-distortion.js';
57
+ /** A glowing gradient of colors flowing through an input image. The effect creates a smoothly animated wave of intensity across the image */
58
+ export { heatmapMeta, heatmapFragmentShader, toProcessedHeatmap, type HeatmapParams, type HeatmapUniforms, } from './shaders/heatmap.js';
59
+ /** Futuristic liquid metal material applied to uploaded logo or one of pre-defined abstract shape */
60
+ export { liquidMetalFragmentShader, LiquidMetalShapes, toProcessedLiquidMetal, type LiquidMetalShape, type LiquidMetalParams, type LiquidMetalUniforms, } from './shaders/liquid-metal.js';
61
+ /** A halftone-dot image filter featuring customizable grids, color palettes, and dot styles */
62
+ export { HalftoneDotsTypes, HalftoneDotsGrids, halftoneDotsFragmentShader, type HalftoneDotsParams, type HalftoneDotsUniforms, type HalftoneDotsType, type HalftoneDotsGrid, } from './shaders/halftone-dots.js';
63
+ /** A halftone CMYK classic algo */
64
+ export { HalftoneCmykTypes, halftoneCmykFragmentShader, type HalftoneCmykParams, type HalftoneCmykUniforms, type HalftoneCmykType, } from './shaders/halftone-cmyk.js';
65
+ /** Animated color fields running around a glassy logo shape */
66
+ export { gemSmokeMeta, gemSmokeFragmentShader, toProcessedGemSmoke, GemSmokeShapes, type GemSmokeShape, type GemSmokeParams, type GemSmokeUniforms, } from './shaders/gem-smoke.js';
67
+ export { getShaderColorFromString } from './get-shader-color-from-string.js';
68
+ export { getShaderNoiseTexture } from './get-shader-noise-texture.js';
69
+ export { emptyPixel } from './empty-pixel.js';
package/dist/index.js ADDED
@@ -0,0 +1,196 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { ShaderMount, isPaperShaderElement } from "./shader-mount.js";
7
+ import { isHtmlInCanvasSupported } from "./html-in-canvas.js";
8
+ import {
9
+ defaultObjectSizing,
10
+ defaultPatternSizing,
11
+ ShaderFitOptions
12
+ } from "./shader-sizing.js";
13
+ import {
14
+ meshGradientFragmentShader,
15
+ meshGradientMeta
16
+ } from "./shaders/mesh-gradient.js";
17
+ import {
18
+ smokeRingMeta,
19
+ smokeRingFragmentShader
20
+ } from "./shaders/smoke-ring.js";
21
+ import { neuroNoiseFragmentShader } from "./shaders/neuro-noise.js";
22
+ import {
23
+ dotOrbitMeta,
24
+ dotOrbitFragmentShader
25
+ } from "./shaders/dot-orbit.js";
26
+ import {
27
+ dotGridFragmentShader,
28
+ DotGridShapes
29
+ } from "./shaders/dot-grid.js";
30
+ import {
31
+ simplexNoiseMeta,
32
+ simplexNoiseFragmentShader
33
+ } from "./shaders/simplex-noise.js";
34
+ import {
35
+ metaballsMeta,
36
+ metaballsFragmentShader
37
+ } from "./shaders/metaballs.js";
38
+ import { perlinNoiseFragmentShader } from "./shaders/perlin-noise.js";
39
+ import { voronoiMeta, voronoiFragmentShader } from "./shaders/voronoi.js";
40
+ import { wavesFragmentShader } from "./shaders/waves.js";
41
+ import {
42
+ warpMeta,
43
+ warpFragmentShader,
44
+ WarpPatterns
45
+ } from "./shaders/warp.js";
46
+ import { godRaysMeta, godRaysFragmentShader } from "./shaders/god-rays.js";
47
+ import { spiralFragmentShader } from "./shaders/spiral.js";
48
+ import { swirlMeta, swirlFragmentShader } from "./shaders/swirl.js";
49
+ import {
50
+ ditheringFragmentShader,
51
+ DitheringShapes,
52
+ DitheringTypes
53
+ } from "./shaders/dithering.js";
54
+ import {
55
+ grainGradientFragmentShader,
56
+ grainGradientMeta,
57
+ GrainGradientShapes
58
+ } from "./shaders/grain-gradient.js";
59
+ import {
60
+ pulsingBorderMeta,
61
+ pulsingBorderFragmentShader,
62
+ PulsingBorderAspectRatios
63
+ } from "./shaders/pulsing-border.js";
64
+ import {
65
+ colorPanelsFragmentShader,
66
+ colorPanelsMeta
67
+ } from "./shaders/color-panels.js";
68
+ import {
69
+ staticMeshGradientFragmentShader,
70
+ staticMeshGradientMeta
71
+ } from "./shaders/static-mesh-gradient.js";
72
+ import {
73
+ staticRadialGradientFragmentShader,
74
+ staticRadialGradientMeta
75
+ } from "./shaders/static-radial-gradient.js";
76
+ import {
77
+ paperTextureFragmentShader,
78
+ paperTextureMeta
79
+ } from "./shaders/paper-texture.js";
80
+ import { waterFragmentShader } from "./shaders/water.js";
81
+ import {
82
+ flutedGlassFragmentShader,
83
+ GlassDistortionShapes,
84
+ GlassGridShapes
85
+ } from "./shaders/fluted-glass.js";
86
+ import {
87
+ imageDitheringFragmentShader
88
+ } from "./shaders/image-dithering.js";
89
+ import {
90
+ lensDistortionFragmentShader,
91
+ lensDistortionMeta
92
+ } from "./shaders/lens-distortion.js";
93
+ import {
94
+ heatmapMeta,
95
+ heatmapFragmentShader,
96
+ toProcessedHeatmap
97
+ } from "./shaders/heatmap.js";
98
+ import {
99
+ liquidMetalFragmentShader,
100
+ LiquidMetalShapes,
101
+ toProcessedLiquidMetal
102
+ } from "./shaders/liquid-metal.js";
103
+ import {
104
+ HalftoneDotsTypes,
105
+ HalftoneDotsGrids,
106
+ halftoneDotsFragmentShader
107
+ } from "./shaders/halftone-dots.js";
108
+ import {
109
+ HalftoneCmykTypes,
110
+ halftoneCmykFragmentShader
111
+ } from "./shaders/halftone-cmyk.js";
112
+ import {
113
+ gemSmokeMeta,
114
+ gemSmokeFragmentShader,
115
+ toProcessedGemSmoke,
116
+ GemSmokeShapes
117
+ } from "./shaders/gem-smoke.js";
118
+ import { getShaderColorFromString } from "./get-shader-color-from-string.js";
119
+ import { getShaderNoiseTexture } from "./get-shader-noise-texture.js";
120
+ import { emptyPixel } from "./empty-pixel.js";
121
+ export {
122
+ DitheringShapes,
123
+ DitheringTypes,
124
+ DotGridShapes,
125
+ GemSmokeShapes,
126
+ GlassDistortionShapes,
127
+ GlassGridShapes,
128
+ GrainGradientShapes,
129
+ HalftoneCmykTypes,
130
+ HalftoneDotsGrids,
131
+ HalftoneDotsTypes,
132
+ LiquidMetalShapes,
133
+ PulsingBorderAspectRatios,
134
+ ShaderFitOptions,
135
+ ShaderMount,
136
+ WarpPatterns,
137
+ colorPanelsFragmentShader,
138
+ colorPanelsMeta,
139
+ defaultObjectSizing,
140
+ defaultPatternSizing,
141
+ ditheringFragmentShader,
142
+ dotGridFragmentShader,
143
+ dotOrbitFragmentShader,
144
+ dotOrbitMeta,
145
+ emptyPixel,
146
+ flutedGlassFragmentShader,
147
+ gemSmokeFragmentShader,
148
+ gemSmokeMeta,
149
+ getShaderColorFromString,
150
+ getShaderNoiseTexture,
151
+ godRaysFragmentShader,
152
+ godRaysMeta,
153
+ grainGradientFragmentShader,
154
+ grainGradientMeta,
155
+ halftoneCmykFragmentShader,
156
+ halftoneDotsFragmentShader,
157
+ heatmapFragmentShader,
158
+ heatmapMeta,
159
+ imageDitheringFragmentShader,
160
+ isHtmlInCanvasSupported,
161
+ isPaperShaderElement,
162
+ lensDistortionFragmentShader,
163
+ lensDistortionMeta,
164
+ liquidMetalFragmentShader,
165
+ meshGradientFragmentShader,
166
+ meshGradientMeta,
167
+ metaballsFragmentShader,
168
+ metaballsMeta,
169
+ neuroNoiseFragmentShader,
170
+ paperTextureFragmentShader,
171
+ paperTextureMeta,
172
+ perlinNoiseFragmentShader,
173
+ pulsingBorderFragmentShader,
174
+ pulsingBorderMeta,
175
+ simplexNoiseFragmentShader,
176
+ simplexNoiseMeta,
177
+ smokeRingFragmentShader,
178
+ smokeRingMeta,
179
+ spiralFragmentShader,
180
+ staticMeshGradientFragmentShader,
181
+ staticMeshGradientMeta,
182
+ staticRadialGradientFragmentShader,
183
+ staticRadialGradientMeta,
184
+ swirlFragmentShader,
185
+ swirlMeta,
186
+ toProcessedGemSmoke,
187
+ toProcessedHeatmap,
188
+ toProcessedLiquidMetal,
189
+ voronoiFragmentShader,
190
+ voronoiMeta,
191
+ warpFragmentShader,
192
+ warpMeta,
193
+ waterFragmentShader,
194
+ wavesFragmentShader
195
+ };
196
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ export declare const ShaderColorSpaces: {
2
+ readonly rgb: 0;
3
+ readonly oklch: 1;
4
+ };
5
+ export type ShaderColorSpace = keyof typeof ShaderColorSpaces;
6
+ export declare const declareOklchTransforms = "\n\n// magic numbers (and magic could be better tbh)\n#define OKLCH_CHROMA_THRESHOLD .001\n#define OKLCH_HUE_NEUTRALIZER - 2.\n\nvec3 srgbToLinear(vec3 srgb) {\n return pow(srgb, vec3(2.2));\n}\n\nvec3 linearToSrgb(vec3 linear) {\n return pow(linear, vec3(1.0 / 2.2));\n}\n\nvec3 LrgbToOklab(vec3 rgb) {\n float L = pow(0.4122214708 * rgb.r + 0.5363325363 * rgb.g + 0.0514459929 * rgb.b, 1.0 / 3.0);\n float M = pow(0.2119034982 * rgb.r + 0.6806995451 * rgb.g + 0.1073969566 * rgb.b, 1.0 / 3.0);\n float S = pow(0.0883024619 * rgb.r + 0.2817188376 * rgb.g + 0.6299787005 * rgb.b, 1.0 / 3.0);\n return vec3(\n 0.2104542553 * L + 0.793617785 * M - 0.0040720468 * S,\n 1.9779984951 * L - 2.428592205 * M + 0.4505937099 * S,\n 0.0259040371 * L + 0.7827717662 * M - 0.808675766 * S\n );\n}\n\nvec3 OklabToLrgb(vec3 oklab) {\n float L = oklab.x;\n float a = oklab.y;\n float b = oklab.z;\n\n float l_ = L + 0.3963377774 * a + 0.2158037573 * b;\n float m_ = L - 0.1055613458 * a - 0.0638541728 * b;\n float s_ = L - 0.0894841775 * a - 1.291485548 * b;\n\n float l = l_ * l_ * l_;\n float m = m_ * m_ * m_;\n float s = s_ * s_ * s_;\n\n return vec3(\n 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s\n );\n}\n\nvec3 oklabToOklch(vec3 oklab) {\n float C = length(oklab.yz);\n float H = atan(oklab.z, oklab.y);\n if (C < OKLCH_CHROMA_THRESHOLD) {\n H = OKLCH_HUE_NEUTRALIZER;\n }\n return vec3(oklab.x, C, H);\n}\n\nvec3 oklchToOklab(vec3 oklch) {\n float a = oklch.y * cos(oklch.z);\n float b = oklch.y * sin(oklch.z);\n return vec3(oklch.x, a, b);\n}\n\nfloat mixHue(float h1, float h2, float mixer) {\n float delta = mod(h2 - h1 + PI, TWO_PI) - PI;\n return h1 + mixer * delta;\n}\n\nvec3 srgbToOklab(vec3 rgb) {\n return oklabToOklch(LrgbToOklab(srgbToLinear(rgb)));\n}\n\nvec3 oklabToSrgb(vec3 oklab) {\n return linearToSrgb(OklabToLrgb(oklchToOklab(oklab)));\n}\n\nvec3 mixOklabVector(vec3 color1, vec3 color2, float mixer) {\n color1.x = mix(color1.x, color2.x, mixer);\n color1.y = mix(color1.y, color2.y, mixer);\n if (color1.y > OKLCH_CHROMA_THRESHOLD && color2.y > OKLCH_CHROMA_THRESHOLD) {\n color1.z = mixHue(color1.z, color2.z, mixer);\n }\n return color1;\n}\n";
@@ -0,0 +1,96 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ const ShaderColorSpaces = {
7
+ rgb: 0,
8
+ oklch: 1
9
+ };
10
+ const declareOklchTransforms = `
11
+
12
+ // magic numbers (and magic could be better tbh)
13
+ #define OKLCH_CHROMA_THRESHOLD .001
14
+ #define OKLCH_HUE_NEUTRALIZER - 2.
15
+
16
+ vec3 srgbToLinear(vec3 srgb) {
17
+ return pow(srgb, vec3(2.2));
18
+ }
19
+
20
+ vec3 linearToSrgb(vec3 linear) {
21
+ return pow(linear, vec3(1.0 / 2.2));
22
+ }
23
+
24
+ vec3 LrgbToOklab(vec3 rgb) {
25
+ float L = pow(0.4122214708 * rgb.r + 0.5363325363 * rgb.g + 0.0514459929 * rgb.b, 1.0 / 3.0);
26
+ float M = pow(0.2119034982 * rgb.r + 0.6806995451 * rgb.g + 0.1073969566 * rgb.b, 1.0 / 3.0);
27
+ float S = pow(0.0883024619 * rgb.r + 0.2817188376 * rgb.g + 0.6299787005 * rgb.b, 1.0 / 3.0);
28
+ return vec3(
29
+ 0.2104542553 * L + 0.793617785 * M - 0.0040720468 * S,
30
+ 1.9779984951 * L - 2.428592205 * M + 0.4505937099 * S,
31
+ 0.0259040371 * L + 0.7827717662 * M - 0.808675766 * S
32
+ );
33
+ }
34
+
35
+ vec3 OklabToLrgb(vec3 oklab) {
36
+ float L = oklab.x;
37
+ float a = oklab.y;
38
+ float b = oklab.z;
39
+
40
+ float l_ = L + 0.3963377774 * a + 0.2158037573 * b;
41
+ float m_ = L - 0.1055613458 * a - 0.0638541728 * b;
42
+ float s_ = L - 0.0894841775 * a - 1.291485548 * b;
43
+
44
+ float l = l_ * l_ * l_;
45
+ float m = m_ * m_ * m_;
46
+ float s = s_ * s_ * s_;
47
+
48
+ return vec3(
49
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
50
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
51
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
52
+ );
53
+ }
54
+
55
+ vec3 oklabToOklch(vec3 oklab) {
56
+ float C = length(oklab.yz);
57
+ float H = atan(oklab.z, oklab.y);
58
+ if (C < OKLCH_CHROMA_THRESHOLD) {
59
+ H = OKLCH_HUE_NEUTRALIZER;
60
+ }
61
+ return vec3(oklab.x, C, H);
62
+ }
63
+
64
+ vec3 oklchToOklab(vec3 oklch) {
65
+ float a = oklch.y * cos(oklch.z);
66
+ float b = oklch.y * sin(oklch.z);
67
+ return vec3(oklch.x, a, b);
68
+ }
69
+
70
+ float mixHue(float h1, float h2, float mixer) {
71
+ float delta = mod(h2 - h1 + PI, TWO_PI) - PI;
72
+ return h1 + mixer * delta;
73
+ }
74
+
75
+ vec3 srgbToOklab(vec3 rgb) {
76
+ return oklabToOklch(LrgbToOklab(srgbToLinear(rgb)));
77
+ }
78
+
79
+ vec3 oklabToSrgb(vec3 oklab) {
80
+ return linearToSrgb(OklabToLrgb(oklchToOklab(oklab)));
81
+ }
82
+
83
+ vec3 mixOklabVector(vec3 color1, vec3 color2, float mixer) {
84
+ color1.x = mix(color1.x, color2.x, mixer);
85
+ color1.y = mix(color1.y, color2.y, mixer);
86
+ if (color1.y > OKLCH_CHROMA_THRESHOLD && color2.y > OKLCH_CHROMA_THRESHOLD) {
87
+ color1.z = mixHue(color1.z, color2.z, mixer);
88
+ }
89
+ return color1;
90
+ }
91
+ `;
92
+ export {
93
+ ShaderColorSpaces,
94
+ declareOklchTransforms
95
+ };
96
+ //# sourceMappingURL=shader-color-spaces.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/shader-color-spaces.ts"],
4
+ "sourcesContent": ["export const ShaderColorSpaces = {\n rgb: 0,\n oklch: 1,\n} as const;\n\nexport type ShaderColorSpace = keyof typeof ShaderColorSpaces;\n\nexport const declareOklchTransforms = `\n\n// magic numbers (and magic could be better tbh)\n#define OKLCH_CHROMA_THRESHOLD .001\n#define OKLCH_HUE_NEUTRALIZER - 2.\n\nvec3 srgbToLinear(vec3 srgb) {\n return pow(srgb, vec3(2.2));\n}\n\nvec3 linearToSrgb(vec3 linear) {\n return pow(linear, vec3(1.0 / 2.2));\n}\n\nvec3 LrgbToOklab(vec3 rgb) {\n float L = pow(0.4122214708 * rgb.r + 0.5363325363 * rgb.g + 0.0514459929 * rgb.b, 1.0 / 3.0);\n float M = pow(0.2119034982 * rgb.r + 0.6806995451 * rgb.g + 0.1073969566 * rgb.b, 1.0 / 3.0);\n float S = pow(0.0883024619 * rgb.r + 0.2817188376 * rgb.g + 0.6299787005 * rgb.b, 1.0 / 3.0);\n return vec3(\n 0.2104542553 * L + 0.793617785 * M - 0.0040720468 * S,\n 1.9779984951 * L - 2.428592205 * M + 0.4505937099 * S,\n 0.0259040371 * L + 0.7827717662 * M - 0.808675766 * S\n );\n}\n\nvec3 OklabToLrgb(vec3 oklab) {\n float L = oklab.x;\n float a = oklab.y;\n float b = oklab.z;\n\n float l_ = L + 0.3963377774 * a + 0.2158037573 * b;\n float m_ = L - 0.1055613458 * a - 0.0638541728 * b;\n float s_ = L - 0.0894841775 * a - 1.291485548 * b;\n\n float l = l_ * l_ * l_;\n float m = m_ * m_ * m_;\n float s = s_ * s_ * s_;\n\n return vec3(\n 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s\n );\n}\n\nvec3 oklabToOklch(vec3 oklab) {\n float C = length(oklab.yz);\n float H = atan(oklab.z, oklab.y);\n if (C < OKLCH_CHROMA_THRESHOLD) {\n H = OKLCH_HUE_NEUTRALIZER;\n }\n return vec3(oklab.x, C, H);\n}\n\nvec3 oklchToOklab(vec3 oklch) {\n float a = oklch.y * cos(oklch.z);\n float b = oklch.y * sin(oklch.z);\n return vec3(oklch.x, a, b);\n}\n\nfloat mixHue(float h1, float h2, float mixer) {\n float delta = mod(h2 - h1 + PI, TWO_PI) - PI;\n return h1 + mixer * delta;\n}\n\nvec3 srgbToOklab(vec3 rgb) {\n return oklabToOklch(LrgbToOklab(srgbToLinear(rgb)));\n}\n\nvec3 oklabToSrgb(vec3 oklab) {\n return linearToSrgb(OklabToLrgb(oklchToOklab(oklab)));\n}\n\nvec3 mixOklabVector(vec3 color1, vec3 color2, float mixer) {\n color1.x = mix(color1.x, color2.x, mixer);\n color1.y = mix(color1.y, color2.y, mixer);\n if (color1.y > OKLCH_CHROMA_THRESHOLD && color2.y > OKLCH_CHROMA_THRESHOLD) {\n color1.z = mixHue(color1.z, color2.z, mixer);\n }\n return color1;\n}\n`;\n"],
5
+ "mappings": ";;;;;AAAO,MAAM,oBAAoB;AAAA,EAC/B,KAAK;AAAA,EACL,OAAO;AACT;AAIO,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,151 @@
1
+ export declare class ShaderMount {
2
+ parentElement: PaperShaderElement;
3
+ canvasElement: HTMLCanvasElement;
4
+ private gl;
5
+ private program;
6
+ private uniformLocations;
7
+ /** The fragment shader that we are using */
8
+ private fragmentShader;
9
+ /** Stores the RAF for the render loop */
10
+ private rafId;
11
+ /** Time of the last rendered frame */
12
+ private lastRenderTime;
13
+ /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */
14
+ private currentFrame;
15
+ /** The speed that we progress through animation time (multiplies by delta time every update). Allows negatives to play in reverse. If set to 0, rAF will stop entirely so static shaders have no recurring performance costs */
16
+ private speed;
17
+ /** Actual speed used that accounts for visibility: we pause the shader if the tab is hidden or the element out of the viewport */
18
+ private currentSpeed;
19
+ /** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */
20
+ private providedUniforms;
21
+ /** Names of the uniforms that should have mipmaps generated for them */
22
+ private mipmaps;
23
+ /** Just a sanity check to make sure frames don't run after we're disposed */
24
+ private hasBeenDisposed;
25
+ /** If the resolution of the canvas has changed since the last render */
26
+ private resolutionChanged;
27
+ /** Store textures that are provided by the user */
28
+ private textures;
29
+ private minPixelRatio;
30
+ private maxPixelCount;
31
+ private isSafari;
32
+ private uniformCache;
33
+ private textureUnitMap;
34
+ private ownerDocument;
35
+ private htmlUniforms;
36
+ private isReactCanvas;
37
+ constructor(
38
+ /** The div you'd like to mount the shader to. The shader will match its size. */
39
+ parentElement: HTMLElement, fragmentShader: string, uniforms: ShaderMountUniforms, webGlContextAttributes?: WebGLContextAttributes,
40
+ /** The speed of the animation, or 0 to stop it. Supports negative values to play in reverse. */
41
+ speed?: number,
42
+ /** Pass a frame to offset the starting u_time value and give deterministic results*/
43
+ frame?: number,
44
+ /**
45
+ * The minimum pixel ratio to render at, defaults to 2.
46
+ * May be reduced to improve performance or increased together with `maxPixelCount` to improve antialiasing.
47
+ */
48
+ minPixelRatio?: number,
49
+ /**
50
+ * The maximum amount of physical device pixels to render for the shader,
51
+ * by default it's 1920 * 1080 * 2x dpi (per each side) = 8,294,400 pixels of a 4K screen.
52
+ * Actual DOM size of the canvas can be larger, it will just lose quality after this.
53
+ *
54
+ * May be reduced to improve performance or increased to improve quality on high-resolution screens.
55
+ */
56
+ maxPixelCount?: number,
57
+ /** Names of the uniforms that should have mipmaps generated for them */
58
+ mipmaps?: string[]);
59
+ private initProgram;
60
+ private setupPositionAttribute;
61
+ private setupUniforms;
62
+ /**
63
+ * The scale that we should render at.
64
+ * - Used to target 2x rendering even on 1x screens for better antialiasing
65
+ * - Prevents the virtual resolution from going beyond the maximum resolution
66
+ * - Accounts for the page zoom level so we render in physical device pixels rather than CSS pixels
67
+ */
68
+ private renderScale;
69
+ private parentWidth;
70
+ private parentHeight;
71
+ private parentDevicePixelWidth;
72
+ private parentDevicePixelHeight;
73
+ private devicePixelsSupported;
74
+ private intersectionObserver;
75
+ private isInViewport;
76
+ private resizeObserver;
77
+ private setupResizeObserver;
78
+ private setupIntersectionObserver;
79
+ private handleVisualViewportChange;
80
+ /** 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
+ private handleResize;
82
+ private render;
83
+ private requestRender;
84
+ /** Creates a texture from an image and sets it into a uniform value */
85
+ private setTextureUniform;
86
+ private createTexture;
87
+ /** Moves the element into the shader canvas and redraws it into the texture on every canvas paint */
88
+ private setHtmlUniform;
89
+ /** Captures each HTML uniform into its texture. On resize only HTML that has a snapshot already, so it can't throw */
90
+ private captureHtml;
91
+ private unsetHtmlUniform;
92
+ private handleCanvasPaint;
93
+ /** Utility: recursive equality test for all the uniforms */
94
+ private areUniformValuesEqual;
95
+ /** Sets the provided uniform values into the WebGL program, can be a partial list of uniforms that have changed */
96
+ private setUniformValues;
97
+ /** Gets the current total animation time from 0ms */
98
+ getCurrentFrame: () => number;
99
+ /** Set a frame to get a deterministic result, frames are literally just milliseconds from zero since the animation started */
100
+ setFrame: (newFrame: number) => void;
101
+ /** Set an animation speed (or 0 to stop animation) */
102
+ setSpeed: (newSpeed?: number) => void;
103
+ /** Apply the target speed, pausing (0) while the tab is hidden or the element is out of the viewport */
104
+ private updateCurrentSpeed;
105
+ private setCurrentSpeed;
106
+ /** Set the maximum pixel count for the shader, this will limit the number of pixels that will be rendered */
107
+ setMaxPixelCount: (newMaxPixelCount?: number) => void;
108
+ /** Set the minimum pixel ratio for the shader */
109
+ setMinPixelRatio: (newMinPixelRatio?: number) => void;
110
+ /** Update the uniforms that are provided by the outside shader, can be a partial set with only the uniforms that have changed */
111
+ setUniforms: (newUniforms: ShaderMountUniforms) => void;
112
+ /** Render right away only when the rAF loop isn't running */
113
+ private renderUnlessAnimating;
114
+ private handleDocumentVisibilityChange;
115
+ /** Dispose of the shader mount, cleaning up all of the WebGL resources */
116
+ dispose: () => void;
117
+ }
118
+ /** The parent `<div>` element that has a ShaderMount available on it */
119
+ export interface PaperShaderElement extends HTMLElement {
120
+ paperShaderMount: ShaderMount | undefined;
121
+ }
122
+ /** Check if an element is a Paper shader element */
123
+ export declare function isPaperShaderElement(element: HTMLElement): element is PaperShaderElement;
124
+ /**
125
+ * Uniform types that we support to be auto-mapped into the fragment shader
126
+ *
127
+ * We accept undefined as a convenience for server rendering, when some things may be undefined
128
+ * We just skip setting the uniform if it's undefined. This allows the shader mount to still take up space during server rendering
129
+ */
130
+ export interface ShaderMountUniforms {
131
+ [key: string]: boolean | number | number[] | number[][] | HTMLImageElement | HTMLElement | undefined;
132
+ }
133
+ export interface ShaderMotionParams {
134
+ speed?: number;
135
+ frame?: number;
136
+ }
137
+ export type ShaderPreset<T> = {
138
+ name: string;
139
+ params: Required<T>;
140
+ };
141
+ export type ImageShaderPreset<T> = {
142
+ name: string;
143
+ /**
144
+ * Params for the shader excluding the image.
145
+ * Image is excluded as it isn't considered a preset,
146
+ * e.g. when switching between presets it shouldn't switch the image.
147
+ *
148
+ * While we exclude images from presets they should still be set with a default prop value so the code-first usage of shaders remains great.
149
+ */
150
+ params: Required<Omit<T, 'image'>>;
151
+ };