pixi-silk 0.1.0 → 1.0.2

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 (214) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +48 -68
  3. package/dist/SilkGraphics.d.ts +270 -55
  4. package/dist/SilkGraphics.js +909 -147
  5. package/dist/app.d.ts +32 -16
  6. package/dist/app.js +44 -10
  7. package/dist/atlas.d.ts +13 -6
  8. package/dist/atlas.js +13 -6
  9. package/dist/batch.d.ts +63 -0
  10. package/dist/batch.js +327 -0
  11. package/dist/color.d.ts +4 -1
  12. package/dist/color.js +9 -4
  13. package/dist/constants.js +31 -5
  14. package/dist/curves.d.ts +9 -3
  15. package/dist/curves.js +11 -5
  16. package/dist/glass/Glass.d.ts +62 -0
  17. package/dist/glass/Glass.js +135 -0
  18. package/dist/glass/GlassFilter.d.ts +33 -0
  19. package/dist/glass/GlassFilter.js +264 -0
  20. package/dist/glass/glass-wgsl.js +129 -0
  21. package/dist/glass/options.d.ts +63 -0
  22. package/dist/glass/options.js +55 -0
  23. package/dist/glass.d.ts +4 -0
  24. package/dist/glass.js +4 -0
  25. package/dist/glow/Glow.d.ts +60 -0
  26. package/dist/glow/Glow.js +65 -0
  27. package/dist/glow/aurora.d.ts +66 -0
  28. package/dist/glow/aurora.js +133 -0
  29. package/dist/glow/light.d.ts +38 -0
  30. package/dist/glow/light.js +83 -0
  31. package/dist/glow/recipes.d.ts +37 -0
  32. package/dist/glow/recipes.js +154 -0
  33. package/dist/glow/shapes.d.ts +13 -0
  34. package/dist/glow/shapes.js +34 -0
  35. package/dist/glow.d.ts +6 -0
  36. package/dist/glow.js +6 -0
  37. package/dist/gradient.d.ts +57 -4
  38. package/dist/gradient.js +142 -4
  39. package/dist/history.d.ts +194 -0
  40. package/dist/history.js +350 -0
  41. package/dist/hit.js +160 -26
  42. package/dist/index.d.ts +6 -5
  43. package/dist/index.js +4 -3
  44. package/dist/layout/flex.js +409 -0
  45. package/dist/layout/node.d.ts +53 -0
  46. package/dist/layout/node.js +117 -0
  47. package/dist/layout/style.d.ts +115 -0
  48. package/dist/layout.d.ts +3 -0
  49. package/dist/layout.js +2 -0
  50. package/dist/motion.d.ts +14 -10
  51. package/dist/motion.js +14 -10
  52. package/dist/path.d.ts +150 -0
  53. package/dist/path.js +761 -0
  54. package/dist/selection.d.ts +133 -0
  55. package/dist/selection.js +194 -0
  56. package/dist/shader-slot.js +9 -0
  57. package/dist/shader-wgsl.js +946 -0
  58. package/dist/shader.js +480 -55
  59. package/dist/signal.d.ts +49 -0
  60. package/dist/signal.js +79 -0
  61. package/dist/stroke.js +271 -0
  62. package/dist/text/SilkText.d.ts +249 -0
  63. package/dist/text/SilkText.js +568 -0
  64. package/dist/text/atlas.d.ts +153 -0
  65. package/dist/text/atlas.js +316 -0
  66. package/dist/text/edt.d.ts +14 -0
  67. package/dist/text/edt.js +97 -0
  68. package/dist/text/label.d.ts +19 -0
  69. package/dist/text/label.js +38 -0
  70. package/dist/text/layout.d.ts +150 -0
  71. package/dist/text/layout.js +270 -0
  72. package/dist/text/segment.d.ts +34 -0
  73. package/dist/text/segment.js +98 -0
  74. package/dist/text/shader.js +355 -0
  75. package/dist/text.d.ts +7 -0
  76. package/dist/text.js +7 -0
  77. package/dist/ui/ButtonDock.d.ts +47 -0
  78. package/dist/ui/ButtonDock.js +110 -0
  79. package/dist/ui/RadialMenu.d.ts +222 -0
  80. package/dist/ui/RadialMenu.js +680 -0
  81. package/dist/ui/SilkButton.d.ts +149 -0
  82. package/dist/ui/SilkButton.js +323 -0
  83. package/dist/ui/ValuePill.d.ts +48 -0
  84. package/dist/ui/ValuePill.js +77 -0
  85. package/dist/ui/arc.d.ts +32 -0
  86. package/dist/ui/arc.js +58 -0
  87. package/dist/ui/brush.d.ts +117 -0
  88. package/dist/ui/brush.js +280 -0
  89. package/dist/ui/camera.d.ts +250 -0
  90. package/dist/ui/camera.js +634 -0
  91. package/dist/ui/color/ColorPicker.d.ts +72 -0
  92. package/dist/ui/color/ColorPicker.js +125 -0
  93. package/dist/ui/color/ColorSlider.d.ts +81 -0
  94. package/dist/ui/color/ColorSlider.js +227 -0
  95. package/dist/ui/color/ColorWheel.d.ts +34 -0
  96. package/dist/ui/color/ColorWheel.js +117 -0
  97. package/dist/ui/color/Eyedropper.d.ts +57 -0
  98. package/dist/ui/color/Eyedropper.js +159 -0
  99. package/dist/ui/color/OklchPicker.d.ts +45 -0
  100. package/dist/ui/color/OklchPicker.js +137 -0
  101. package/dist/ui/color/SwatchPalette.d.ts +60 -0
  102. package/dist/ui/color/SwatchPalette.js +160 -0
  103. package/dist/ui/color/SwatchPopup.d.ts +68 -0
  104. package/dist/ui/color/SwatchPopup.js +237 -0
  105. package/dist/ui/color/draw.d.ts +22 -0
  106. package/dist/ui/color/draw.js +128 -0
  107. package/dist/ui/color/model.d.ts +94 -0
  108. package/dist/ui/color/model.js +193 -0
  109. package/dist/ui/color/rings.d.ts +75 -0
  110. package/dist/ui/color/rings.js +247 -0
  111. package/dist/ui/color.d.ts +11 -0
  112. package/dist/ui/color.js +11 -0
  113. package/dist/ui/dial.d.ts +229 -0
  114. package/dist/ui/dial.js +553 -0
  115. package/dist/ui/driver.d.ts +24 -0
  116. package/dist/ui/driver.js +46 -0
  117. package/dist/ui/gesture.d.ts +66 -0
  118. package/dist/ui/gesture.js +116 -0
  119. package/dist/ui/gizmo.d.ts +199 -0
  120. package/dist/ui/gizmo.js +957 -0
  121. package/dist/ui/grid.d.ts +106 -0
  122. package/dist/ui/grid.js +228 -0
  123. package/dist/ui/group.d.ts +81 -0
  124. package/dist/ui/group.js +144 -0
  125. package/dist/ui/guides.d.ts +142 -0
  126. package/dist/ui/guides.js +379 -0
  127. package/dist/ui/halo.d.ts +164 -0
  128. package/dist/ui/halo.js +438 -0
  129. package/dist/ui/icon.d.ts +14 -0
  130. package/dist/ui/icon.js +40 -0
  131. package/dist/ui/index.d.ts +62 -0
  132. package/dist/ui/index.js +56 -0
  133. package/dist/ui/input.d.ts +28 -0
  134. package/dist/ui/input.js +49 -0
  135. package/dist/ui/inspector.d.ts +4 -0
  136. package/dist/ui/inspector.js +4 -0
  137. package/dist/ui/keys.d.ts +20 -0
  138. package/dist/ui/keys.js +65 -0
  139. package/dist/ui/label.d.ts +18 -0
  140. package/dist/ui/layers.d.ts +5 -0
  141. package/dist/ui/layers.js +5 -0
  142. package/dist/ui/layout/debug.d.ts +38 -0
  143. package/dist/ui/layout/debug.js +299 -0
  144. package/dist/ui/layout/flex-container.d.ts +150 -0
  145. package/dist/ui/layout/flex-container.js +441 -0
  146. package/dist/ui/layout/simulate.d.ts +49 -0
  147. package/dist/ui/layout/simulate.js +92 -0
  148. package/dist/ui/layout/smart-container.d.ts +180 -0
  149. package/dist/ui/layout/smart-container.js +302 -0
  150. package/dist/ui/layout.d.ts +5 -0
  151. package/dist/ui/layout.js +5 -0
  152. package/dist/ui/marquee.d.ts +124 -0
  153. package/dist/ui/marquee.js +321 -0
  154. package/dist/ui/measure.d.ts +138 -0
  155. package/dist/ui/measure.js +351 -0
  156. package/dist/ui/minimap.d.ts +2 -0
  157. package/dist/ui/minimap.js +2 -0
  158. package/dist/ui/modes.d.ts +186 -0
  159. package/dist/ui/modes.js +380 -0
  160. package/dist/ui/odometer.d.ts +104 -0
  161. package/dist/ui/odometer.js +244 -0
  162. package/dist/ui/outline.d.ts +104 -0
  163. package/dist/ui/outline.js +310 -0
  164. package/dist/ui/paint.js +22 -0
  165. package/dist/ui/panel.d.ts +4 -0
  166. package/dist/ui/panel.js +4 -0
  167. package/dist/ui/panels/Inspector.d.ts +228 -0
  168. package/dist/ui/panels/Inspector.js +516 -0
  169. package/dist/ui/panels/LayerTree.d.ts +193 -0
  170. package/dist/ui/panels/LayerTree.js +878 -0
  171. package/dist/ui/panels/Minimap.d.ts +140 -0
  172. package/dist/ui/panels/Minimap.js +412 -0
  173. package/dist/ui/panels/Panel.d.ts +273 -0
  174. package/dist/ui/panels/Panel.js +767 -0
  175. package/dist/ui/panels/ScrollView.d.ts +126 -0
  176. package/dist/ui/panels/ScrollView.js +358 -0
  177. package/dist/ui/panels/binding.d.ts +59 -0
  178. package/dist/ui/panels/binding.js +84 -0
  179. package/dist/ui/panels/fields.d.ts +265 -0
  180. package/dist/ui/panels/fields.js +760 -0
  181. package/dist/ui/panels/icons.d.ts +7 -0
  182. package/dist/ui/panels/icons.js +136 -0
  183. package/dist/ui/panels/pixi-tree.d.ts +35 -0
  184. package/dist/ui/panels/pixi-tree.js +82 -0
  185. package/dist/ui/panels/theme.d.ts +79 -0
  186. package/dist/ui/panels/theme.js +91 -0
  187. package/dist/ui/panels/tree.d.ts +130 -0
  188. package/dist/ui/panels/tree.js +199 -0
  189. package/dist/ui/pathgizmo.d.ts +253 -0
  190. package/dist/ui/pathgizmo.js +932 -0
  191. package/dist/ui/pill.d.ts +3 -0
  192. package/dist/ui/pill.js +2 -0
  193. package/dist/ui/ruler.d.ts +113 -0
  194. package/dist/ui/ruler.js +371 -0
  195. package/dist/ui/snap.d.ts +151 -0
  196. package/dist/ui/snap.js +380 -0
  197. package/dist/ui/spacing.d.ts +122 -0
  198. package/dist/ui/spacing.js +346 -0
  199. package/dist/ui/textedit.d.ts +304 -0
  200. package/dist/ui/textedit.js +1085 -0
  201. package/dist/ui/timeline.d.ts +175 -0
  202. package/dist/ui/timeline.js +488 -0
  203. package/dist/webgpu.d.ts +25 -0
  204. package/dist/webgpu.js +32 -0
  205. package/package.json +172 -1
  206. package/skills/pixi-silk/SKILL.md +138 -0
  207. package/skills/pixi-silk-app-rendering/SKILL.md +114 -0
  208. package/skills/pixi-silk-drawing/SKILL.md +154 -0
  209. package/skills/pixi-silk-editor/SKILL.md +200 -0
  210. package/skills/pixi-silk-layout/SKILL.md +150 -0
  211. package/skills/pixi-silk-migrate-from-graphics/SKILL.md +115 -0
  212. package/skills/pixi-silk-paint/SKILL.md +132 -0
  213. package/skills/pixi-silk-text/SKILL.md +127 -0
  214. package/skills/pixi-silk-widgets/SKILL.md +139 -0
@@ -0,0 +1,83 @@
1
+ import { Color } from "pixi.js";
2
+ //#region src/glow/light.ts
3
+ /** The visible spectrum, red to violet, as eight saturated `0xRRGGBB` stops. */
4
+ const SPECTRUM = [
5
+ 16717636,
6
+ 16739584,
7
+ 16766464,
8
+ 58998,
9
+ 58879,
10
+ 2718207,
11
+ 8146431,
12
+ 13959417
13
+ ];
14
+ /** `count` colours spread evenly along {@link SPECTRUM}, interpolated in sRGB. `count` is rounded, at least 1. */
15
+ function spectrum(count) {
16
+ const n = Math.max(1, Math.round(count));
17
+ const c = new Color();
18
+ return Array.from({ length: n }, (_, i) => {
19
+ const t = n === 1 ? 0 : i / (n - 1) * (SPECTRUM.length - 1);
20
+ const a = Math.floor(t);
21
+ const b = Math.min(SPECTRUM.length - 1, a + 1);
22
+ const f = t - a;
23
+ const ca = c.setValue(SPECTRUM[a]).toArray();
24
+ const cb = new Color(SPECTRUM[b]).toArray();
25
+ return c.setValue([
26
+ ca[0] + (cb[0] - ca[0]) * f,
27
+ ca[1] + (cb[1] - ca[1]) * f,
28
+ ca[2] + (cb[2] - ca[2]) * f
29
+ ]).toNumber();
30
+ });
31
+ }
32
+ /** Corners of a tapered ray as a flat `[x, y]` list of four points: start left, start right, end right, end left. */
33
+ function rayQuad(r) {
34
+ const dx = r.x1 - r.x0;
35
+ const dy = r.y1 - r.y0;
36
+ const len = Math.hypot(dx, dy) || 1;
37
+ const nx = -dy / len;
38
+ const ny = dx / len;
39
+ return [
40
+ r.x0 + nx * r.w0 / 2,
41
+ r.y0 + ny * r.w0 / 2,
42
+ r.x0 - nx * r.w0 / 2,
43
+ r.y0 - ny * r.w0 / 2,
44
+ r.x1 - nx * r.w1 / 2,
45
+ r.y1 - ny * r.w1 / 2,
46
+ r.x1 + nx * r.w1 / 2,
47
+ r.y1 + ny * r.w1 / 2
48
+ ];
49
+ }
50
+ /**
51
+ * Adds a tapered ray to `g` as one polygon and returns `g`. Fill it afterwards, blurred for light.
52
+ * One shape has no seam down its diagonal when it is blurred or translucent.
53
+ */
54
+ function ray(g, r) {
55
+ return g.poly(rayQuad(r));
56
+ }
57
+ /**
58
+ * `count` rays fanning out from (x, y) around `angle` (radians), `spread` radians wide in all, each
59
+ * `length` long. Neighbouring rays touch at their ends. `width` is the total width at the start,
60
+ * shared between the rays (default 0, a point). Pair with {@link spectrum} for the colours.
61
+ */
62
+ function fan(x, y, angle, spread, length, count, width = 0) {
63
+ const n = Math.max(1, Math.round(count));
64
+ const slice = spread / n;
65
+ return Array.from({ length: n }, (_, i) => {
66
+ const a = angle - spread / 2 + slice * (i + .5);
67
+ const end = 2 * length * Math.tan(slice / 2) + width / n;
68
+ return {
69
+ x0: x,
70
+ y0: y,
71
+ x1: x + Math.cos(a) * length,
72
+ y1: y + Math.sin(a) * length,
73
+ w0: width / n,
74
+ w1: end
75
+ };
76
+ });
77
+ }
78
+ /** Upper-case hex string of a colour without alpha, `#FF3636` style, for swatch labels. */
79
+ function hexLabel(color) {
80
+ return `#${new Color(color).toHex().slice(1).toUpperCase()}`;
81
+ }
82
+ //#endregion
83
+ export { SPECTRUM, fan, hexLabel, ray, rayQuad, spectrum };
@@ -0,0 +1,37 @@
1
+ import { Gradient } from "../gradient.js";
2
+ import { GlowLayer } from "./Glow.js";
3
+ import { ColorSource } from "pixi.js";
4
+ //#region src/glow/recipes.d.ts
5
+ /** Options of {@link neon}. */
6
+ export interface NeonOptions {
7
+ /** Rough size of the shape in local units. Every blur and spread scales with it. Tuned at 100. Default 100. */
8
+ size?: number;
9
+ /** Paint of the solid core, a colour or a gradient. Default a radial gradient from a pale tint to the glow colour. */
10
+ core?: ColorSource | Gradient;
11
+ /** Strength of the bloom, from 0 to about 2. Negative values count as 0. Default 1. */
12
+ intensity?: number;
13
+ /**
14
+ * What the glow sits on. Light adds up on `dark` surfaces. On `light` ones (white cards) added
15
+ * light would vanish, so the passes paint normally. Default `dark`.
16
+ */
17
+ surface?: "dark" | "light";
18
+ }
19
+ /**
20
+ * A neon glow as seven {@link GlowLayer}s, back to front, for a shape about `size` wide. Two blooms
21
+ * go behind. Then come two coloured drop glows and the core, a radial gradient with a pale inner
22
+ * shadow. A 60% white copy on top makes the middle burn towards white. A thin blurred white outline
23
+ * finishes it. On a `dark` surface the glows blend additively.
24
+ */
25
+ export declare function neon(color: ColorSource, options?: NeonOptions): GlowLayer[];
26
+ /**
27
+ * A soft halo only, no core: `rings` additive passes of the shape (default 3), each wider and fainter,
28
+ * returned back to front. `size` (default 100) scales the blur and spread.
29
+ */
30
+ export declare function halo(color: ColorSource, size?: number, rings?: number): GlowLayer[];
31
+ /**
32
+ * Stacked additive shadows behind a shape, as in CSS. Each `[blur, spread]` pair uses the CSS blur
33
+ * radius, which is twice the gaussian sigma. The default stack is `[8, 0]`, `[32, 8]` and
34
+ * `[128, 32]` in white at alpha 0.6.
35
+ */
36
+ export declare function shadowStack(color?: ColorSource, stack?: [blur: number, spread: number][], alpha?: number): GlowLayer[];
37
+ //#endregion
@@ -0,0 +1,154 @@
1
+ import { Gradient, radial } from "../gradient.js";
2
+ import { Color } from "pixi.js";
3
+ //#region src/glow/recipes.ts
4
+ /** Mixes `color` towards white by `t` (0 keeps it, 1 is white). */
5
+ function tint(color, t) {
6
+ const [r, g, b] = new Color(color).toArray();
7
+ return new Color([
8
+ r + (1 - r) * t,
9
+ g + (1 - g) * t,
10
+ b + (1 - b) * t
11
+ ]).toNumber();
12
+ }
13
+ /**
14
+ * A neon glow as seven {@link GlowLayer}s, back to front, for a shape about `size` wide. Two blooms
15
+ * go behind. Then come two coloured drop glows and the core, a radial gradient with a pale inner
16
+ * shadow. A 60% white copy on top makes the middle burn towards white. A thin blurred white outline
17
+ * finishes it. On a `dark` surface the glows blend additively.
18
+ */
19
+ function neon(color, options = {}) {
20
+ const { size = 100, intensity = 1, surface = "dark" } = options;
21
+ const s = size / 100;
22
+ const k = Math.max(0, intensity);
23
+ const dark = surface === "dark";
24
+ const blend = dark ? "add" : "normal";
25
+ const light = dark ? 1 : .55;
26
+ const pale = tint(color, .85);
27
+ const bloom = radial([[
28
+ 0,
29
+ tint(color, .35),
30
+ 1
31
+ ], [
32
+ 1,
33
+ color,
34
+ .6
35
+ ]], { radius: .75 });
36
+ const core = options.core ?? radial([
37
+ [
38
+ 0,
39
+ pale,
40
+ 1
41
+ ],
42
+ [
43
+ .55,
44
+ tint(color, .3),
45
+ 1
46
+ ],
47
+ [
48
+ 1,
49
+ color,
50
+ 1
51
+ ]
52
+ ], {
53
+ center: [.5, .45],
54
+ radius: .7
55
+ });
56
+ return [
57
+ {
58
+ fill: {
59
+ gradient: bloom,
60
+ alpha: .75 * k * light,
61
+ blur: 55 * s,
62
+ spread: 28 * s
63
+ },
64
+ blend
65
+ },
66
+ {
67
+ fill: {
68
+ gradient: bloom,
69
+ alpha: .7 * k * light,
70
+ blur: 25 * s,
71
+ spread: 6 * s
72
+ },
73
+ blend
74
+ },
75
+ {
76
+ fill: {
77
+ color,
78
+ alpha: .3 * light,
79
+ blur: 7.5 * s
80
+ },
81
+ blend
82
+ },
83
+ {
84
+ fill: {
85
+ color: tint(color, .1),
86
+ alpha: .2 * light,
87
+ blur: 30 * s
88
+ },
89
+ blend
90
+ },
91
+ { fill: {
92
+ ...core instanceof Gradient ? { gradient: core } : { color: core },
93
+ innerShadow: {
94
+ color: tint(color, .95),
95
+ blur: 5 * s,
96
+ spread: 2 * s
97
+ }
98
+ } },
99
+ {
100
+ fill: {
101
+ color: 16777215,
102
+ alpha: .6 * light * Math.min(1, k),
103
+ blur: 10 * s
104
+ },
105
+ blend
106
+ },
107
+ { stroke: {
108
+ width: 2 * s,
109
+ color: 16777215,
110
+ alpha: .9,
111
+ blur: 5 * s
112
+ } }
113
+ ];
114
+ }
115
+ /**
116
+ * A soft halo only, no core: `rings` additive passes of the shape (default 3), each wider and fainter,
117
+ * returned back to front. `size` (default 100) scales the blur and spread.
118
+ */
119
+ function halo(color, size = 100, rings = 3) {
120
+ return Array.from({ length: rings }, (_, i) => {
121
+ const t = (i + 1) / rings;
122
+ return {
123
+ fill: {
124
+ color,
125
+ alpha: .7 * (1 - t * .6),
126
+ blur: size * (.06 + .4 * t * t),
127
+ spread: size * .04 * t
128
+ },
129
+ blend: "add"
130
+ };
131
+ }).reverse();
132
+ }
133
+ /**
134
+ * Stacked additive shadows behind a shape, as in CSS. Each `[blur, spread]` pair uses the CSS blur
135
+ * radius, which is twice the gaussian sigma. The default stack is `[8, 0]`, `[32, 8]` and
136
+ * `[128, 32]` in white at alpha 0.6.
137
+ */
138
+ function shadowStack(color = 16777215, stack = [
139
+ [8, 0],
140
+ [32, 8],
141
+ [128, 32]
142
+ ], alpha = .6) {
143
+ return stack.map(([blur, spread]) => ({
144
+ fill: {
145
+ color,
146
+ alpha,
147
+ blur: blur / 2,
148
+ spread
149
+ },
150
+ blend: "add"
151
+ }));
152
+ }
153
+ //#endregion
154
+ export { halo, neon, shadowStack };
@@ -0,0 +1,13 @@
1
+ import { SilkGraphics } from "../SilkGraphics.js";
2
+ //#region src/glow/shapes.d.ts
3
+ /**
4
+ * Adds a lightning bolt filling the box (x, y, w, h) to `g` as one polygon and returns `g`. Fill it
5
+ * once and blur, spread and inner shadows treat it as a single shape.
6
+ */
7
+ export declare function bolt(g: SilkGraphics, x: number, y: number, w: number, h: number): SilkGraphics;
8
+ /**
9
+ * Adds a drop with its tip up as one closed path and returns `g`. It is a circle of radius `r` around
10
+ * (cx, cy), pulled into a point `tip` above the centre (default `1.6 * r`).
11
+ */
12
+ export declare function drop(g: SilkGraphics, cx: number, cy: number, r: number, tip?: number): SilkGraphics;
13
+ //#endregion
@@ -0,0 +1,34 @@
1
+ //#region src/glow/shapes.ts
2
+ /** Corners of a lightning bolt in a 1 x 1 box, clockwise from the top tip. */
3
+ const BOLT = [
4
+ .64,
5
+ 0,
6
+ .06,
7
+ .58,
8
+ .44,
9
+ .58,
10
+ .3,
11
+ 1,
12
+ .94,
13
+ .4,
14
+ .56,
15
+ .4
16
+ ];
17
+ /**
18
+ * Adds a lightning bolt filling the box (x, y, w, h) to `g` as one polygon and returns `g`. Fill it
19
+ * once and blur, spread and inner shadows treat it as a single shape.
20
+ */
21
+ function bolt(g, x, y, w, h) {
22
+ return g.poly(BOLT.map((v, i) => i % 2 === 0 ? x + v * w : y + v * h));
23
+ }
24
+ /**
25
+ * Adds a drop with its tip up as one closed path and returns `g`. It is a circle of radius `r` around
26
+ * (cx, cy), pulled into a point `tip` above the centre (default `1.6 * r`).
27
+ */
28
+ function drop(g, cx, cy, r, tip = r * 1.6) {
29
+ const k = .5523 * r;
30
+ const ty = cy - tip;
31
+ return g.beginPath().moveTo(cx, ty).bezierCurveTo(cx + r * .2, ty + tip * .35, cx + r, cy - k, cx + r, cy).bezierCurveTo(cx + r, cy + k, cx + k, cy + r, cx, cy + r).bezierCurveTo(cx - k, cy + r, cx - r, cy + k, cx - r, cy).bezierCurveTo(cx - r, cy - k, cx - r * .2, ty + tip * .35, cx, ty).closePath();
32
+ }
33
+ //#endregion
34
+ export { bolt, drop };
package/dist/glow.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Aurora, AuroraBlob, AuroraOptions, auroraBlobs } from "./glow/aurora.js";
2
+ import { Glow, GlowLayer, GlowOptions } from "./glow/Glow.js";
3
+ import { Ray, SPECTRUM, fan, hexLabel, ray, rayQuad, spectrum } from "./glow/light.js";
4
+ import { NeonOptions, halo, neon, shadowStack } from "./glow/recipes.js";
5
+ import { bolt, drop } from "./glow/shapes.js";
6
+ export { Aurora, type AuroraBlob, type AuroraOptions, Glow, type GlowLayer, type GlowOptions, type NeonOptions, type Ray, SPECTRUM, auroraBlobs, bolt, drop, fan, halo, hexLabel, neon, ray, rayQuad, shadowStack, spectrum };
package/dist/glow.js ADDED
@@ -0,0 +1,6 @@
1
+ import { Aurora, auroraBlobs } from "./glow/aurora.js";
2
+ import { Glow } from "./glow/Glow.js";
3
+ import { SPECTRUM, fan, hexLabel, ray, rayQuad, spectrum } from "./glow/light.js";
4
+ import { halo, neon, shadowStack } from "./glow/recipes.js";
5
+ import { bolt, drop } from "./glow/shapes.js";
6
+ export { Aurora, Glow, SPECTRUM, auroraBlobs, bolt, drop, fan, halo, hexLabel, neon, ray, rayQuad, shadowStack, spectrum };
@@ -19,7 +19,8 @@ export type StopInput = ColorSource | [number, ColorSource] | [number, ColorSour
19
19
  * - `linear`: piecewise linear between stops (CSS behaviour).
20
20
  * - `smooth`: monotone cubic spline through the stops with eased ends. Removes the
21
21
  * Mach bands you see at every stop of a linear ramp and never overshoots.
22
- * - a function remaps the gradient parameter before lookup (e.g. an easing curve for scrims).
22
+ * - a function remaps the gradient parameter 0..1 before lookup, for example an easing curve
23
+ * for scrims. Reuse one function instance: each new function bakes a new atlas row.
23
24
  */
24
25
  export type Easing = "linear" | "smooth" | ((t: number) => number);
25
26
  /** Gradient coordinates: `shape` = fractions of each painted shape's box, `local` = the graphics' local units (one ramp across many shapes). */
@@ -41,7 +42,11 @@ export interface GradientOptions {
41
42
  }
42
43
  /**
43
44
  * Base class of all gradients. Stops are interpolated premultiplied (OKLab by default), baked into a
44
- * shared half-float atlas and dithered when sampled, so gradients stay smooth without banding.
45
+ * shared half-float atlas and dithered when sampled, which hides banding.
46
+ *
47
+ * A gradient is read when a shape is filled or stroked. Changing its points later does not change
48
+ * shapes already painted: paint them again. The atlas holds 256 ramps in use at once, and
49
+ * gradients with the same stops, space and easing share one.
45
50
  */
46
51
  export declare abstract class Gradient {
47
52
  /** Interpolation space. */
@@ -123,9 +128,9 @@ export declare class PathGradient extends Gradient {}
123
128
  * ```
124
129
  */
125
130
  export declare const linear: (stops: StopInput[], options?: Omit<LinearGradientOptions, "stops">) => LinearGradient;
126
- /** Top-to-bottom linear gradient across the painted shape. */
131
+ /** Top-to-bottom linear gradient across each painted shape's box. */
127
132
  export declare const vertical: (stops: StopInput[], options?: Omit<LinearGradientOptions, "stops" | "from" | "to">) => LinearGradient;
128
- /** Left-to-right linear gradient across the painted shape. */
133
+ /** Left-to-right linear gradient across each painted shape's box. */
129
134
  export declare const horizontal: (stops: StopInput[], options?: Omit<LinearGradientOptions, "stops" | "from" | "to">) => LinearGradient;
130
135
  /** Radial gradient from `center` (default the box centre) out to `radius`, optionally starting at `innerRadius`. */
131
136
  export declare const radial: (stops: StopInput[], options?: Omit<RadialGradientOptions, "stops">) => RadialGradient;
@@ -136,4 +141,52 @@ export declare const radial: (stops: StopInput[], options?: Omit<RadialGradientO
136
141
  export declare const conic: (stops: StopInput[], options?: Omit<ConicGradientOptions, "stops">) => ConicGradient;
137
142
  /** Gradient that follows a stroke from its first point (t = 0) to its last (t = 1). */
138
143
  export declare const along: (stops: StopInput[], options?: Omit<GradientOptions, "stops" | "units">) => PathGradient;
144
+ /** A mesh control colour: any Pixi colour, or `[color, alpha]`. */
145
+ export type MeshColorInput = ColorSource | [ColorSource, number];
146
+ /** Options of {@link mesh}: where the grid sits, its units and its interpolation space. */
147
+ export interface MeshGradientOptions {
148
+ /** Top-left corner of the grid. Default `[0, 0]`. */
149
+ from?: Vec2;
150
+ /** Bottom-right corner of the grid. Default `[1, 1]`. */
151
+ to?: Vec2;
152
+ /** `shape` (default): fractions of each painted shape's box. `local`: the graphics' local units. */
153
+ units?: GradientUnits;
154
+ /** Interpolation space. Default `oklab`. */
155
+ space?: ColorSpace;
156
+ }
157
+ /**
158
+ * A smooth colour surface through a grid of control colours, like a gradient mesh in Illustrator.
159
+ * Colours blend with a bicubic spline in its `space` (OKLab by default), so falloffs stay soft in
160
+ * both directions. The surface is baked at 16x16 samples.
161
+ * Create it with {@link mesh}.
162
+ */
163
+ export declare class MeshGradient extends Gradient {
164
+ /** Columns of control colours. */
165
+ readonly cols: number;
166
+ /** Rows of control colours. */
167
+ readonly rows: number;
168
+ /** Top-left corner of the grid. */
169
+ from: Vec2;
170
+ /** Bottom-right corner of the grid. */
171
+ to: Vec2;
172
+ private readonly _colors;
173
+ constructor(cols: number, rows: number, colors: MeshColorInput[], options?: MeshGradientOptions);
174
+ }
175
+ /**
176
+ * Gradient mesh: `cols` by `rows` control colours (row by row, top-left first) spread over the
177
+ * painted shape's box, blended into one smooth surface. `cols` and `rows` are clamped to 1..16.
178
+ * Missing colours repeat the last one.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * // a light beam that fades at the sides and towards the top
183
+ * const beam = mesh(3, 3, [
184
+ * [0xffd6e8, 0], [0xffd6e8, 0], [0xffd6e8, 0],
185
+ * [0xffd6e8, 0.2], [0xffd6e8, 0.5], [0xffd6e8, 0.2],
186
+ * [0xffe6f0, 0.6], [0xffffff, 1], [0xffe6f0, 0.6],
187
+ * ]);
188
+ * g.rect(0, 0, 200, 240).fill(beam);
189
+ * ```
190
+ */
191
+ export declare const mesh: (cols: number, rows: number, colors: MeshColorInput[], options?: MeshGradientOptions) => MeshGradient;
139
192
  //#endregion
package/dist/gradient.js CHANGED
@@ -70,7 +70,11 @@ function monotoneTangents(xs, ys) {
70
70
  }
71
71
  /**
72
72
  * Base class of all gradients. Stops are interpolated premultiplied (OKLab by default), baked into a
73
- * shared half-float atlas and dithered when sampled, so gradients stay smooth without banding.
73
+ * shared half-float atlas and dithered when sampled, which hides banding.
74
+ *
75
+ * A gradient is read when a shape is filled or stroked. Changing its points later does not change
76
+ * shapes already painted: paint them again. The atlas holds 256 ramps in use at once, and
77
+ * gradients with the same stops, space and easing share one.
74
78
  */
75
79
  var Gradient = class {
76
80
  /** @internal Normalised stops (offsets clamped and sorted, colours parsed). */
@@ -266,14 +270,14 @@ const linear = (stops, options = {}) => new LinearGradient({
266
270
  ...options,
267
271
  stops
268
272
  });
269
- /** Top-to-bottom linear gradient across the painted shape. */
273
+ /** Top-to-bottom linear gradient across each painted shape's box. */
270
274
  const vertical = (stops, options = {}) => new LinearGradient({
271
275
  ...options,
272
276
  stops,
273
277
  from: [0, 0],
274
278
  to: [0, 1]
275
279
  });
276
- /** Left-to-right linear gradient across the painted shape. */
280
+ /** Left-to-right linear gradient across each painted shape's box. */
277
281
  const horizontal = (stops, options = {}) => new LinearGradient({
278
282
  ...options,
279
283
  stops,
@@ -298,5 +302,139 @@ const along = (stops, options = {}) => new PathGradient({
298
302
  ...options,
299
303
  stops
300
304
  });
305
+ const MESH_SIZE = 16;
306
+ /** @internal Catmull-Rom weights for the four samples around fraction `f`. */
307
+ function catmullRomWeights(f) {
308
+ const f2 = f * f;
309
+ const f3 = f2 * f;
310
+ return [
311
+ -.5 * f3 + f2 - .5 * f,
312
+ 1.5 * f3 - 2.5 * f2 + 1,
313
+ -1.5 * f3 + 2 * f2 + .5 * f,
314
+ .5 * f3 - .5 * f2
315
+ ];
316
+ }
317
+ /**
318
+ * @internal Samples a `cols` x `rows` grid of 4-channel values at (`x`, `y`) in grid units (0 to
319
+ * cols - 1, 0 to rows - 1) with a bicubic Catmull-Rom. The surface passes through every control value.
320
+ */
321
+ function sampleMesh(values, cols, rows, x, y) {
322
+ const ix = Math.min(Math.floor(x), Math.max(cols - 2, 0));
323
+ const iy = Math.min(Math.floor(y), Math.max(rows - 2, 0));
324
+ const wx = catmullRomWeights(cols > 1 ? x - ix : 0);
325
+ const wy = catmullRomWeights(rows > 1 ? y - iy : 0);
326
+ const out = [
327
+ 0,
328
+ 0,
329
+ 0,
330
+ 0
331
+ ];
332
+ for (let j = 0; j < 4; j++) {
333
+ const r = Math.min(Math.max(iy + j - 1, 0), rows - 1);
334
+ for (let i = 0; i < 4; i++) {
335
+ const c = Math.min(Math.max(ix + i - 1, 0), cols - 1);
336
+ const w = wx[i] * wy[j];
337
+ const v = values[r * cols + c];
338
+ for (let k = 0; k < 4; k++) out[k] += w * v[k];
339
+ }
340
+ }
341
+ return out;
342
+ }
343
+ /**
344
+ * A smooth colour surface through a grid of control colours, like a gradient mesh in Illustrator.
345
+ * Colours blend with a bicubic spline in its `space` (OKLab by default), so falloffs stay soft in
346
+ * both directions. The surface is baked at 16x16 samples.
347
+ * Create it with {@link mesh}.
348
+ */
349
+ var MeshGradient = class extends Gradient {
350
+ /** @internal */
351
+ kind = GradKind.Mesh;
352
+ /** Columns of control colours. */
353
+ cols;
354
+ /** Rows of control colours. */
355
+ rows;
356
+ /** Top-left corner of the grid. */
357
+ from;
358
+ /** Bottom-right corner of the grid. */
359
+ to;
360
+ _colors;
361
+ constructor(cols, rows, colors, options = {}) {
362
+ const c = Math.max(1, Math.min(MESH_SIZE, Math.round(cols)));
363
+ const r = Math.max(1, Math.min(MESH_SIZE, Math.round(rows)));
364
+ const parsed = [];
365
+ for (let i = 0; i < c * r; i++) {
366
+ const input = colors[Math.min(i, colors.length - 1)] ?? 16777215;
367
+ parsed.push(Array.isArray(input) ? parseColor(input[0], input[1]) : parseColor(input));
368
+ }
369
+ super({
370
+ stops: [16777215],
371
+ space: options.space,
372
+ units: options.units
373
+ });
374
+ this.cols = c;
375
+ this.rows = r;
376
+ this.from = options.from ?? [0, 0];
377
+ this.to = options.to ?? [1, 1];
378
+ this._colors = parsed;
379
+ this.key = `mesh|${this.space}|${c}x${r}|${parsed.map((p) => p.map((v) => v.toFixed(5)).join(",")).join(";")}`;
380
+ }
381
+ /** @internal */
382
+ resolve(frame, out, o) {
383
+ const a = point(frame, this.units, this.from);
384
+ const b = point(frame, this.units, this.to);
385
+ out[o] = a[0];
386
+ out[o + 1] = a[1];
387
+ out[o + 2] = b[0];
388
+ out[o + 3] = b[1];
389
+ }
390
+ /** @internal Bakes a 16 x 16 grid (one atlas row) of premultiplied sRGB samples. */
391
+ bake(out) {
392
+ const values = this._colors.map((rgba) => {
393
+ const w = toSpace(rgba, this.space);
394
+ const a = rgba[3];
395
+ return [
396
+ w[0] * a,
397
+ w[1] * a,
398
+ w[2] * a,
399
+ a
400
+ ];
401
+ });
402
+ for (let j = 0; j < MESH_SIZE; j++) for (let i = 0; i < MESH_SIZE; i++) {
403
+ const v = sampleMesh(values, this.cols, this.rows, i / 15 * (this.cols - 1), j / 15 * (this.rows - 1));
404
+ const a = Math.min(1, Math.max(0, v[3]));
405
+ const o = (j * MESH_SIZE + i) * 4;
406
+ if (a <= 1e-7) {
407
+ out[o] = out[o + 1] = out[o + 2] = out[o + 3] = 0;
408
+ continue;
409
+ }
410
+ const rgb = fromSpace([
411
+ v[0] / a,
412
+ v[1] / a,
413
+ v[2] / a
414
+ ], this.space);
415
+ out[o] = rgb[0] * a;
416
+ out[o + 1] = rgb[1] * a;
417
+ out[o + 2] = rgb[2] * a;
418
+ out[o + 3] = a;
419
+ }
420
+ }
421
+ };
422
+ /**
423
+ * Gradient mesh: `cols` by `rows` control colours (row by row, top-left first) spread over the
424
+ * painted shape's box, blended into one smooth surface. `cols` and `rows` are clamped to 1..16.
425
+ * Missing colours repeat the last one.
426
+ *
427
+ * @example
428
+ * ```ts
429
+ * // a light beam that fades at the sides and towards the top
430
+ * const beam = mesh(3, 3, [
431
+ * [0xffd6e8, 0], [0xffd6e8, 0], [0xffd6e8, 0],
432
+ * [0xffd6e8, 0.2], [0xffd6e8, 0.5], [0xffd6e8, 0.2],
433
+ * [0xffe6f0, 0.6], [0xffffff, 1], [0xffe6f0, 0.6],
434
+ * ]);
435
+ * g.rect(0, 0, 200, 240).fill(beam);
436
+ * ```
437
+ */
438
+ const mesh = (cols, rows, colors, options = {}) => new MeshGradient(cols, rows, colors, options);
301
439
  //#endregion
302
- export { ConicGradient, Gradient, LinearGradient, PathGradient, RadialGradient, along, conic, horizontal, linear, radial, vertical };
440
+ export { ConicGradient, Gradient, LinearGradient, MeshGradient, PathGradient, RadialGradient, along, catmullRomWeights, conic, horizontal, linear, mesh, radial, sampleMesh, vertical };