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,351 @@
1
+ import { SilkGraphics } from "../SilkGraphics.js";
2
+ import { Spring } from "../motion.js";
3
+ import { Driver } from "./driver.js";
4
+ import { hex } from "./paint.js";
5
+ import { Container, Text } from "pixi.js";
6
+ //#region src/ui/measure.ts
7
+ const defaultFormat = (v) => String(Math.round(v * 10) / 10);
8
+ const isContainer = (t) => "children" in t;
9
+ /**
10
+ * The redlines between two boxes given as edges (`x0 < x1`, `y0 < y1`). Separate boxes get the
11
+ * horizontal and vertical gaps, with a dashed guide when they do not overlap on the other axis.
12
+ * Overlapping or nested boxes get the distances between matching edges, zero-length ones left out.
13
+ * Pure: it allocates a new array and draws nothing.
14
+ */
15
+ function redlines(a, b) {
16
+ const out = [];
17
+ const contains = (o, i) => i.x0 >= o.x0 && i.x1 <= o.x1 && i.y0 >= o.y0 && i.y1 <= o.y1;
18
+ const overlapX = a.x0 < b.x1 && b.x0 < a.x1;
19
+ const overlapY = a.y0 < b.y1 && b.y0 < a.y1;
20
+ const cy = (a.y0 + a.y1) / 2;
21
+ const cx = (a.x0 + a.x1) / 2;
22
+ if (overlapX && overlapY) {
23
+ const inner = contains(b, a) ? a : contains(a, b) ? b : a;
24
+ const outer = inner === a ? b : a;
25
+ const my = (Math.max(a.y0, b.y0) + Math.min(a.y1, b.y1)) / 2;
26
+ const mx = (Math.max(a.x0, b.x0) + Math.min(a.x1, b.x1)) / 2;
27
+ const push = (x0, y0, x1, y1) => {
28
+ const v = Math.hypot(x1 - x0, y1 - y0);
29
+ if (v > 1e-6) out.push({
30
+ x0,
31
+ y0,
32
+ x1,
33
+ y1,
34
+ value: v,
35
+ guides: []
36
+ });
37
+ };
38
+ push(Math.min(inner.x0, outer.x0), my, Math.max(inner.x0, outer.x0), my);
39
+ push(Math.min(inner.x1, outer.x1), my, Math.max(inner.x1, outer.x1), my);
40
+ push(mx, Math.min(inner.y0, outer.y0), mx, Math.max(inner.y0, outer.y0));
41
+ push(mx, Math.min(inner.y1, outer.y1), mx, Math.max(inner.y1, outer.y1));
42
+ return out;
43
+ }
44
+ if (a.x1 <= b.x0 || b.x1 <= a.x0) {
45
+ const [x0, x1] = a.x1 <= b.x0 ? [a.x1, b.x0] : [b.x1, a.x0];
46
+ const y = overlapY ? (Math.max(a.y0, b.y0) + Math.min(a.y1, b.y1)) / 2 : cy;
47
+ const guides = [];
48
+ if (!overlapY) {
49
+ const ex = a.x1 <= b.x0 ? b.x0 : b.x1;
50
+ guides.push([
51
+ ex,
52
+ y,
53
+ ex,
54
+ y < b.y0 ? b.y0 : b.y1
55
+ ]);
56
+ }
57
+ out.push({
58
+ x0,
59
+ y0: y,
60
+ x1,
61
+ y1: y,
62
+ value: x1 - x0,
63
+ guides
64
+ });
65
+ }
66
+ if (a.y1 <= b.y0 || b.y1 <= a.y0) {
67
+ const [y0, y1] = a.y1 <= b.y0 ? [a.y1, b.y0] : [b.y1, a.y0];
68
+ const x = overlapX ? (Math.max(a.x0, b.x0) + Math.min(a.x1, b.x1)) / 2 : cx;
69
+ const guides = [];
70
+ if (!overlapX) {
71
+ const ey = a.y1 <= b.y0 ? b.y0 : b.y1;
72
+ guides.push([
73
+ x,
74
+ ey,
75
+ x < b.x0 ? b.x0 : b.x1,
76
+ ey
77
+ ]);
78
+ }
79
+ out.push({
80
+ x0: x,
81
+ y0,
82
+ x1: x,
83
+ y1,
84
+ value: y1 - y0,
85
+ guides
86
+ });
87
+ }
88
+ return out;
89
+ }
90
+ /** A label: a rounded pill with text, pooled. */
91
+ var Tag = class extends Container {
92
+ bg = new SilkGraphics();
93
+ text;
94
+ _value = "";
95
+ _color = -1;
96
+ constructor(fontSize, textColor, label) {
97
+ super();
98
+ const style = {
99
+ fontFamily: "Inter, system-ui, sans-serif",
100
+ fontSize,
101
+ fontWeight: "600",
102
+ fill: textColor
103
+ };
104
+ this.text = label ? label(style) : new Text({
105
+ text: "",
106
+ style,
107
+ resolution: 3
108
+ });
109
+ this.text.anchor.set(.5);
110
+ this.addChild(this.bg, this.text);
111
+ }
112
+ set(value, color) {
113
+ if (value === this._value && color === this._color) return;
114
+ this._value = value;
115
+ this._color = color;
116
+ this.text.text = value;
117
+ const h = this.text.height + 6;
118
+ const w = Math.max(h, this.text.width + 10);
119
+ this.bg.clear().roundRect(-w / 2, -h / 2, w, h, 4, .6).fill(color);
120
+ }
121
+ };
122
+ /**
123
+ * Distances and sizes for editors, drawn on an overlay.
124
+ *
125
+ * {@link Measure.between} shows the redlines from one object to another (see {@link redlines}).
126
+ * {@link Measure.size} puts a `W x H` badge under an object.
127
+ *
128
+ * Values are in the measured space (the world under a camera), so zooming never changes them.
129
+ * Put the overlay beside the world, not inside it, so lines and labels keep their size on screen.
130
+ * Both follow their objects every frame while shown, and grow in when the pair changes. Rotated
131
+ * objects are measured by their axis-aligned box. The overlay ignores pointer events.
132
+ *
133
+ * Experimental: the API may change in a minor release.
134
+ * @experimental
135
+ */
136
+ var Measure = class extends Container {
137
+ _opts;
138
+ _g = new SilkGraphics();
139
+ _tags = new Container();
140
+ _pool = [];
141
+ _driver;
142
+ _color;
143
+ _sizeColor;
144
+ _textColor;
145
+ _grow = new Spring(0, 260, 22);
146
+ _badge = new Spring(0, 320, 20);
147
+ _a = null;
148
+ _b = null;
149
+ _sized = null;
150
+ _lastLines = [];
151
+ constructor(options = {}) {
152
+ super({ label: "Measure" });
153
+ this._opts = options;
154
+ this._color = hex(options.color ?? 15878178);
155
+ this._sizeColor = hex(options.sizeColor ?? 689407);
156
+ this._textColor = hex(options.textColor ?? 16777215);
157
+ this.eventMode = "none";
158
+ this.addChild(this._g, this._tags);
159
+ this._driver = new Driver((dt) => this._step(dt), options.ticker);
160
+ }
161
+ /** The redlines of the last frame, in the measured space. Empty while nothing is measured. */
162
+ get lines() {
163
+ return this._lastLines;
164
+ }
165
+ /** Shows the distances from `a` to `b`, animated. `null` for either fades them out. The same pair again is a no-op. */
166
+ between(a, b) {
167
+ if (a === this._a && b === this._b) return this;
168
+ const was = this._a !== null && this._b !== null;
169
+ this._a = a;
170
+ this._b = b;
171
+ if (a && b) {
172
+ if (!was) this._grow.value = 0;
173
+ else this._grow.value = Math.min(this._grow.value, .35);
174
+ this._grow.target = 1;
175
+ } else this._grow.target = 0;
176
+ this._driver.wake();
177
+ return this;
178
+ }
179
+ /** Shows a `W x H` badge under `target`, in the measured space. `null` fades it out. */
180
+ size(target) {
181
+ if (target === this._sized) return this;
182
+ if (target && !this._sized) this._badge.value = 0;
183
+ this._sized = target ?? this._sized;
184
+ this._badge.target = target ? 1 : 0;
185
+ if (!target) this._fadingSize = true;
186
+ else this._fadingSize = false;
187
+ this._driver.wake();
188
+ return this;
189
+ }
190
+ _fadingSize = false;
191
+ /** Fades out the redlines and the size badge. */
192
+ clear() {
193
+ return this.between(null, null).size(null);
194
+ }
195
+ /**
196
+ * Advances by `dt` seconds, clamped to 0..0.1. Only needed with `ticker: null`. Returns true
197
+ * while something animates or shows.
198
+ */
199
+ tick(dt) {
200
+ return this._driver.tick(dt);
201
+ }
202
+ destroy(options) {
203
+ this._driver.sleep();
204
+ super.destroy(options);
205
+ }
206
+ get _space() {
207
+ return this._opts.space ?? this.parent ?? this;
208
+ }
209
+ /** A target's axis-aligned box in the measured space. */
210
+ _box(t) {
211
+ if (!isContainer(t)) return {
212
+ x0: t.x,
213
+ y0: t.y,
214
+ x1: t.x + t.width,
215
+ y1: t.y + t.height
216
+ };
217
+ if (t.destroyed || !t.parent) return null;
218
+ const b = t.getLocalBounds();
219
+ const space = this._space;
220
+ let x0 = Infinity;
221
+ let y0 = Infinity;
222
+ let x1 = -Infinity;
223
+ let y1 = -Infinity;
224
+ for (const [x, y] of [
225
+ [b.minX, b.minY],
226
+ [b.maxX, b.minY],
227
+ [b.maxX, b.maxY],
228
+ [b.minX, b.maxY]
229
+ ]) {
230
+ const p = space.toLocal(t.toGlobal({
231
+ x,
232
+ y
233
+ }));
234
+ x0 = Math.min(x0, p.x);
235
+ y0 = Math.min(y0, p.y);
236
+ x1 = Math.max(x1, p.x);
237
+ y1 = Math.max(y1, p.y);
238
+ }
239
+ return {
240
+ x0,
241
+ y0,
242
+ x1,
243
+ y1
244
+ };
245
+ }
246
+ /** A point of the measured space in this overlay's coordinates. */
247
+ _map(x, y) {
248
+ const space = this._space;
249
+ return space === this ? {
250
+ x,
251
+ y
252
+ } : this.toLocal(space.toGlobal({
253
+ x,
254
+ y
255
+ }));
256
+ }
257
+ _tag(i) {
258
+ let tag = this._pool[i];
259
+ if (!tag) {
260
+ tag = new Tag(this._opts.fontSize ?? 11, this._textColor, this._opts.label);
261
+ this._pool.push(tag);
262
+ this._tags.addChild(tag);
263
+ }
264
+ tag.visible = true;
265
+ return tag;
266
+ }
267
+ _step(dt) {
268
+ this._grow.step(dt);
269
+ this._badge.step(dt);
270
+ const g = this._g.clear();
271
+ const fmt = this._opts.format ?? defaultFormat;
272
+ const red = this._color;
273
+ let used = 0;
274
+ const a = this._a ? this._box(this._a) : null;
275
+ const b = this._b ? this._box(this._b) : null;
276
+ const t = Math.max(0, Math.min(1, this._grow.value));
277
+ const lines = a && b ? redlines(a, b) : [];
278
+ this._lastLines = lines;
279
+ if (t > .002 && b && (this._opts.outline ?? true)) {
280
+ const p0 = this._map(b.x0, b.y0);
281
+ const p1 = this._map(b.x1, b.y1);
282
+ g.rect(p0.x, p0.y, p1.x - p0.x, p1.y - p0.y).stroke({
283
+ width: 1,
284
+ color: red,
285
+ alpha: t
286
+ });
287
+ }
288
+ for (const line of lines) {
289
+ if (t <= .002) break;
290
+ const p = this._map(line.x0, line.y0);
291
+ const q = this._map(line.x1, line.y1);
292
+ const mx = (p.x + q.x) / 2;
293
+ const my = (p.y + q.y) / 2;
294
+ const hx = (q.x - p.x) / 2 * t;
295
+ const hy = (q.y - p.y) / 2 * t;
296
+ const len = Math.hypot(q.x - p.x, q.y - p.y) || 1;
297
+ const nx = -(q.y - p.y) / len * 4;
298
+ const ny = (q.x - p.x) / len * 4;
299
+ for (const [gx0, gy0, gx1, gy1] of line.guides) {
300
+ const u = this._map(gx0, gy0);
301
+ const v = this._map(gx1, gy1);
302
+ g.moveTo(u.x, u.y).lineTo(v.x, v.y).stroke({
303
+ width: 1,
304
+ color: red,
305
+ alpha: .8 * t,
306
+ dash: [3, 3]
307
+ });
308
+ }
309
+ g.moveTo(mx - hx, my - hy).lineTo(mx + hx, my + hy).stroke({
310
+ width: 1,
311
+ color: red,
312
+ alpha: t
313
+ });
314
+ if (t > .6) {
315
+ const k = (t - .6) / .4;
316
+ g.moveTo(p.x - nx * k, p.y - ny * k).lineTo(p.x + nx * k, p.y + ny * k).moveTo(q.x - nx * k, q.y - ny * k).lineTo(q.x + nx * k, q.y + ny * k).stroke({
317
+ width: 1,
318
+ color: red,
319
+ alpha: t
320
+ });
321
+ }
322
+ const tag = this._tag(used++);
323
+ tag.set(fmt(line.value), red);
324
+ const room = len > tag.width + 8;
325
+ const vertical = Math.abs(q.y - p.y) > Math.abs(q.x - p.x);
326
+ tag.position.set(mx + (room || !vertical ? 0 : tag.width / 2 + 6), my + (room || vertical ? 0 : tag.height / 2 + 6));
327
+ tag.alpha = t;
328
+ tag.scale.set(.7 + .3 * t);
329
+ }
330
+ const s = this._sized ? this._box(this._sized) : null;
331
+ const k = Math.max(0, this._badge.value);
332
+ if (s && k > .002) {
333
+ const p = this._map((s.x0 + s.x1) / 2, s.y1);
334
+ const tag = this._tag(used++);
335
+ tag.set(`${fmt(s.x1 - s.x0)} × ${fmt(s.y1 - s.y0)}`, this._sizeColor);
336
+ tag.position.set(p.x, p.y + 8 + tag.height / 2 + (1 - Math.min(1, k)) * -6);
337
+ tag.alpha = Math.min(1, k);
338
+ tag.scale.set(.8 + .2 * Math.min(1, k));
339
+ } else if (this._fadingSize && k <= .002) this._sized = null;
340
+ for (let i = used; i < this._pool.length; i++) this._pool[i].visible = false;
341
+ const settling = Math.abs(this._grow.value - this._grow.target) > .002 || Math.abs(this._grow.velocity) > .01 || Math.abs(this._badge.value - this._badge.target) > .002 || Math.abs(this._badge.velocity) > .01;
342
+ const following = this._a !== null && this._b !== null || this._sized !== null && this._badge.target > 0;
343
+ if (!settling && !following) {
344
+ g.clear();
345
+ for (const tag of this._pool) tag.visible = false;
346
+ }
347
+ return settling || following;
348
+ }
349
+ };
350
+ //#endregion
351
+ export { Measure, redlines };
@@ -0,0 +1,2 @@
1
+ import { Minimap, MinimapOptions, MinimapState, MinimapTransform, minimapFit, minimapToWorld, unionRect, worldRectToMinimap, worldToMinimap } from "./panels/Minimap.js";
2
+ export { Minimap, type MinimapOptions, type MinimapState, type MinimapTransform, minimapFit, minimapToWorld, unionRect, worldRectToMinimap, worldToMinimap };
@@ -0,0 +1,2 @@
1
+ import { Minimap, minimapFit, minimapToWorld, unionRect, worldRectToMinimap, worldToMinimap } from "./panels/Minimap.js";
2
+ export { Minimap, minimapFit, minimapToWorld, unionRect, worldRectToMinimap, worldToMinimap };
@@ -0,0 +1,186 @@
1
+ import { Signal } from "../signal.js";
2
+ import { IconSource } from "./icon.js";
3
+ import { InputProfiles } from "./input.js";
4
+ import { RadialItem, RadialMenu, RadialMenuOptions } from "./RadialMenu.js";
5
+ import { Container, TextStyleOptions, Ticker } from "pixi.js";
6
+ //#region src/ui/modes.d.ts
7
+ /** Options of {@link ModeSwitcher}. */
8
+ export interface ModeSwitcherOptions {
9
+ /** The modes. Items with `children` are not supported here. */
10
+ modes: RadialItem[];
11
+ /** Starting mode id. Default the first mode. */
12
+ initial?: string;
13
+ /** Hold this key (a `KeyboardEvent.code`) to show the ring. A quick tap swaps to the previous mode. Default `Space`. `null` turns keys off. */
14
+ key?: string | null;
15
+ /** How long the key must be held before the ring shows. Default 160 ms. */
16
+ holdMs?: number;
17
+ /** A long-press on this container shows the ring under the finger. */
18
+ longPressTarget?: Container;
19
+ /** Long-press time. Default 380 ms. */
20
+ longPressMs?: number;
21
+ /** Look and feel of the ring (any {@link RadialMenuOptions} except items and callbacks). */
22
+ menu?: Omit<RadialMenuOptions, "items" | "onSelect" | "onClose" | "ticker">;
23
+ /** Ticker driving the animation. Default `Ticker.shared`. `null` for manual {@link ModeSwitcher.tick}. */
24
+ ticker?: Ticker | null;
25
+ /** Called after the mode changes, with the new id and the one before it. */
26
+ onChange?: (mode: string, previous: string | null) => void;
27
+ }
28
+ /** The reactive state of a {@link ModeSwitcher}. */
29
+ export interface ModeSwitcherState {
30
+ /** Current mode id. */
31
+ mode: Signal<string>;
32
+ /** Mode before the current one, the target of a quick tap. */
33
+ previous: Signal<string | null>;
34
+ /** Mode ids, most recently used first. */
35
+ recent: Signal<readonly string[]>;
36
+ }
37
+ /**
38
+ * Quick mode switching for editors, the hold-a-key ring of paint and 3D tools.
39
+ *
40
+ * - Hold the key: a ring of modes opens under the pointer, the most recently used first (the
41
+ * previous mode sits on top). Release over a mode to switch, or click it.
42
+ * - Tap the key: swap back to the previous mode, no ring.
43
+ * - Long-press `longPressTarget` on touch screens: the same ring, picked by sliding the finger.
44
+ *
45
+ * The keyboard only acts while the pointer is over the canvas (it moved there in the last few
46
+ * seconds) and never while a text field has focus. Keep the switcher on top of the stage. Key
47
+ * handling listens on `window`. The switcher picks modes only: your app decides what each mode does.
48
+ *
49
+ * Experimental: the API may change in a minor release.
50
+ *
51
+ * @experimental
52
+ */
53
+ export declare class ModeSwitcher extends Container {
54
+ /** Current, previous and recent modes. Read them, and switch with {@link ModeSwitcher.set}. */
55
+ readonly state: ModeSwitcherState;
56
+ /** The ring. Style it through the `menu` option. */
57
+ readonly menu: RadialMenu;
58
+ private readonly _opts;
59
+ private _modes;
60
+ private _pointer;
61
+ private _timer;
62
+ private _keyDown;
63
+ private _waitClosed;
64
+ private _stops;
65
+ constructor(options: ModeSwitcherOptions);
66
+ /** Current mode id. */
67
+ get mode(): string;
68
+ /** Switches to `id` (no-op for the current mode or an unknown id). */
69
+ set(id: string): void;
70
+ /** Swaps back to the previous mode. No-op before the first switch. */
71
+ toggle(): void;
72
+ /** Opens the ring at (x, y) in the switcher's coordinates. Pass the pointer that is down, if any. */
73
+ open(x: number, y: number, pointer?: Parameters<RadialMenu["openAt"]>[2]): void;
74
+ /** Advances the ring's animation by `dt` seconds (only needed with `ticker: null`). Returns true while moving. */
75
+ tick(dt: number): boolean;
76
+ /** Stops the hold timer, the key listener and the long-press gesture. */
77
+ override destroy(options?: Parameters<Container["destroy"]>[0]): void;
78
+ /** Ring items: every mode but the current one, most recent first. */
79
+ private _ring;
80
+ private _clearTimer;
81
+ private _onKey;
82
+ }
83
+ /** One choice of a {@link SegmentedSwitch}. */
84
+ export interface SegmentOption {
85
+ /** Value the switch reports when this segment is selected. Unique within the switch. */
86
+ id: string;
87
+ /** Text shown when there is no `icon`. */
88
+ label?: string;
89
+ /** Icon shown instead of `label`, sized by `iconSize`. */
90
+ icon?: IconSource;
91
+ }
92
+ /** Colours of a {@link SegmentedSwitch} (any Pixi colour). */
93
+ export interface SegmentedTheme {
94
+ /** Pill background. */
95
+ track: number | string;
96
+ /** The sliding thumb behind the selected segment. */
97
+ thumb: number | string;
98
+ /** Labels and icons of unselected segments. */
99
+ content: number | string;
100
+ /** Label or icon of the selected segment. */
101
+ contentActive: number | string;
102
+ /** Soft shadow under the thumb. */
103
+ shadow: number | string;
104
+ }
105
+ /** Dark default theme of {@link SegmentedSwitch}. Override single colours with the `theme` option. */
106
+ export declare const SEGMENTED_THEME: Readonly<SegmentedTheme>;
107
+ /** Options of {@link SegmentedSwitch}. */
108
+ export interface SegmentedSwitchOptions {
109
+ /** Segments from left to right. Fixed after construction. */
110
+ options: SegmentOption[];
111
+ /** Selected id. Default the first. */
112
+ value?: string;
113
+ /** Minimum width of a segment. Segments grow to fit their content. Default 64. */
114
+ segmentWidth?: number;
115
+ /** Pill height. Default 36. */
116
+ height?: number;
117
+ /** Gap between track and thumb. Default 3. */
118
+ padding?: number;
119
+ /** Icon size of segments with an `icon`. Default 18. */
120
+ iconSize?: number;
121
+ /** Style of segment labels. Default font size 13. */
122
+ textStyle?: TextStyleOptions;
123
+ /** Colours that replace parts of {@link SEGMENTED_THEME}. */
124
+ theme?: Partial<SegmentedTheme>;
125
+ /** Per pointer kind overrides of `slop`, which sets how far off the pill a slide still counts. */
126
+ profiles?: InputProfiles;
127
+ /** Ticker driving the animation. Default `Ticker.shared`. `null` for manual {@link SegmentedSwitch.tick}. */
128
+ ticker?: Ticker | null;
129
+ /** Called when `state.value` changes, by the user or by code. */
130
+ onChange?: (id: string, previous: string) => void;
131
+ }
132
+ /** The reactive state of a {@link SegmentedSwitch}. Write `value` or `enabled` to change it. */
133
+ export interface SegmentedState {
134
+ /** Selected segment id. Setting it slides the thumb and calls `onChange`. */
135
+ value: Signal<string>;
136
+ /** False ignores input. Default true. */
137
+ enabled: Signal<boolean>;
138
+ }
139
+ /**
140
+ * A pill of choices with a thumb that slides to the selected one, stretching on the way.
141
+ *
142
+ * Tap a segment, or press and slide along the pill (the thumb follows the finger and the choice
143
+ * lands on release). Centred on its position. Works for toolbars (select, move, rotate) and for
144
+ * speed or quality settings. Segments cannot be added or removed after construction.
145
+ *
146
+ * Experimental: the API may change in a minor release.
147
+ *
148
+ * @experimental
149
+ */
150
+ export declare class SegmentedSwitch extends Container {
151
+ /** Selected id and enabled flag. Write to them to change the switch. */
152
+ readonly state: SegmentedState;
153
+ private readonly _opts;
154
+ private readonly _theme;
155
+ private readonly _g;
156
+ private readonly _contents;
157
+ private readonly _driver;
158
+ private readonly _segments;
159
+ private readonly _w;
160
+ private readonly _h;
161
+ private readonly _left;
162
+ private readonly _right;
163
+ private _press;
164
+ private _dim;
165
+ private _pressId;
166
+ private _preview;
167
+ constructor(options: SegmentedSwitchOptions);
168
+ /** Width of the pill: the sum of the segment widths. */
169
+ get switchWidth(): number;
170
+ /** Height of the pill. */
171
+ get switchHeight(): number;
172
+ /** Advances the animation by `dt` seconds (only needed with `ticker: null`). Returns true while moving. */
173
+ tick(dt: number): boolean;
174
+ /** Stops the animation. Destroys children unless `options` says otherwise. */
175
+ override destroy(options?: Parameters<Container["destroy"]>[0]): void;
176
+ private _index;
177
+ private _edge;
178
+ /** Sends the thumb to segment `i`. The leading edge moves first, so the thumb stretches. */
179
+ private _aim;
180
+ private _at;
181
+ private _onDown;
182
+ private _onMove;
183
+ private _onUp;
184
+ private _step;
185
+ }
186
+ //#endregion