@wonderyard/tela 0.0.0-stage → 0.1.0

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/dist/brush.d.ts +21 -0
  3. package/dist/brush.js +84 -0
  4. package/dist/document.d.ts +50 -0
  5. package/dist/document.js +105 -0
  6. package/dist/history.d.ts +16 -0
  7. package/dist/history.js +38 -0
  8. package/dist/image.d.ts +41 -0
  9. package/dist/image.js +94 -0
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.js +399 -0
  12. package/dist/input.d.ts +67 -0
  13. package/dist/input.js +536 -0
  14. package/dist/internals.d.ts +18 -0
  15. package/dist/internals.js +3 -0
  16. package/dist/keymap.d.ts +20 -0
  17. package/dist/keymap.js +266 -0
  18. package/dist/mask.d.ts +27 -0
  19. package/dist/mask.js +96 -0
  20. package/dist/moving.d.ts +102 -0
  21. package/dist/moving.js +215 -0
  22. package/dist/palette.d.ts +21 -0
  23. package/dist/palette.js +47 -0
  24. package/dist/react.d.ts +6 -0
  25. package/dist/react.js +16 -0
  26. package/dist/selection.d.ts +15 -0
  27. package/dist/selection.js +76 -0
  28. package/dist/sprite.d.ts +20 -0
  29. package/dist/sprite.js +49 -0
  30. package/dist/store.d.ts +4 -0
  31. package/dist/store.js +20 -0
  32. package/dist/tools.d.ts +43 -0
  33. package/dist/tools.js +113 -0
  34. package/dist/transactions.d.ts +45 -0
  35. package/dist/transactions.js +135 -0
  36. package/dist/types/document.d.ts +2 -0
  37. package/dist/types/history.d.ts +11 -0
  38. package/dist/types/image.d.ts +7 -0
  39. package/dist/types/index.d.ts +371 -0
  40. package/dist/types/input.d.ts +105 -0
  41. package/dist/types/keymap.d.ts +26 -0
  42. package/dist/types/mask.d.ts +11 -0
  43. package/dist/types/moving.d.ts +26 -0
  44. package/dist/types/selection.d.ts +1 -0
  45. package/dist/types/store.d.ts +4 -0
  46. package/dist/types/tools.d.ts +8 -0
  47. package/dist/types/view.d.ts +14 -0
  48. package/dist/view.d.ts +56 -0
  49. package/dist/view.js +139 -0
  50. package/package.json +72 -3
  51. package/README.md +0 -3
package/dist/input.js ADDED
@@ -0,0 +1,536 @@
1
+ import { outline as e } from "./mask.js";
2
+ import { dabs as t, footprint as n, line as r } from "./tools.js";
3
+ import { lookup as i } from "./keymap.js";
4
+ import { nextZoom as a, pixelGridOpacity as o } from "./view.js";
5
+ // lib/input.ts
6
+ var s = /* @__PURE__ */ new WeakMap(), c = [
7
+ "rectangular_marquee",
8
+ "lasso",
9
+ "magic_wand"
10
+ ];
11
+ function l(e, t, n, r) {
12
+ let [i, a] = [t.x - e.x, t.y - e.y];
13
+ if (n) {
14
+ let e = Math.min(Math.abs(i), Math.abs(a));
15
+ [i, a] = [(i < 0 ? -1 : 1) * e, (a < 0 ? -1 : 1) * e];
16
+ }
17
+ return r ? [{
18
+ x: e.x - Math.abs(i),
19
+ y: e.y - Math.abs(a)
20
+ }, {
21
+ x: e.x + Math.abs(i),
22
+ y: e.y + Math.abs(a)
23
+ }] : [e, {
24
+ x: e.x + i,
25
+ y: e.y + a
26
+ }];
27
+ }
28
+ var u = 10;
29
+ function d(e, t) {
30
+ let [n, r] = [t.x - e.x, t.y - e.y], [i, a] = [Math.abs(n), Math.abs(r)], o = Math.atan2(a, i) * 180 / Math.PI, s = [
31
+ 0,
32
+ 26.565,
33
+ 45,
34
+ 63.435,
35
+ 90
36
+ ].reduce((e, t) => Math.abs(t - o) < Math.abs(e - o) ? t : e), [c, l] = [Math.sign(n), Math.sign(r)], u = Math.min(i, a), [d, f] = s === 0 ? [n, 0] : s === 90 ? [0, r] : s === 45 ? [c * u, l * u] : s < 45 ? [n, l * Math.trunc(i / 2)] : [c * Math.trunc(a / 2), r];
37
+ return {
38
+ x: e.x + d,
39
+ y: e.y + f
40
+ };
41
+ }
42
+ var f = /^(INPUT|TEXTAREA|SELECT)$/;
43
+ function p(s) {
44
+ let { store: p } = s, h = null, g = null, _ = null, v = null, y = null, b = {
45
+ shift: !1,
46
+ ctrl: !1,
47
+ alt: !1,
48
+ space: !1
49
+ }, x = Promise.resolve(), S = Promise.resolve(), C = (e) => x = x.then(e, e), w = (e) => ({
50
+ x: Math.floor(e.x),
51
+ y: Math.floor(e.y)
52
+ }), T = (e, t) => s.keymap.some((n) => "action" in n && n.action === e && n.keys.some((e) => e.split("+").every((e) => e === "Shift" ? t.shift : e === "Ctrl" ? t.ctrl : e === "Alt" && t.alt))), E = (e) => e.button === "right" || T("SubtractSelection", e) ? "subtract" : T("IntersectSelection", e) ? "intersect" : T("AddSelection", e) ? "add" : null, D = (e) => {
53
+ let t = p.getState().selection, [n, r] = t ? [e.x - t.x, e.y - t.y] : [-1, -1];
54
+ return !!t && n >= 0 && r >= 0 && n < t.width && r < t.height && !!t.data[r * t.width + n];
55
+ }, O = (e, t, n) => T("AngleSnapFromLastPoint", n) ? d(e, t) : t, k = (e) => {
56
+ let { brush: t } = p.getState();
57
+ t.type !== "image" && s.set({ brush: {
58
+ ...t,
59
+ size: Math.min(Math.max(e, 1), s.maxBrushSize)
60
+ } });
61
+ }, A = (e, t) => {
62
+ let n = s.pixel(e.x, e.y);
63
+ n !== null && s.set(t === "left" ? { fgColor: n } : { bgColor: n });
64
+ }, j = {
65
+ down: (e) => C(async () => {
66
+ if (h) return;
67
+ let t = w(e);
68
+ if (e.button === "middle" || b.space || p.getState().tool === "hand") {
69
+ h = {
70
+ kind: "pan",
71
+ screenX: e.screenX,
72
+ screenY: e.screenY
73
+ };
74
+ return;
75
+ }
76
+ let { tool: n, selectionMode: r } = p.getState();
77
+ if (c.includes(n)) {
78
+ let i = E(e);
79
+ if (!i && T("Eyedropper", e)) {
80
+ let n = e.button === "right" ? "right" : "left";
81
+ return h = {
82
+ kind: "pick",
83
+ button: n
84
+ }, s.hold(() => A(t, n));
85
+ }
86
+ if (!i && (r === "replace" || r === "add") && D(t)) {
87
+ h = {
88
+ kind: "move",
89
+ start: t
90
+ }, s.moving.get() || await s.moving.lift(e.ctrl);
91
+ return;
92
+ }
93
+ s.moving.commit(), h = {
94
+ kind: "select",
95
+ tool: n,
96
+ mode: i ?? r,
97
+ points: [t],
98
+ path: [{
99
+ x: e.x,
100
+ y: e.y
101
+ }],
102
+ held: {
103
+ shift: e.shift,
104
+ ctrl: e.ctrl
105
+ },
106
+ square: !1,
107
+ centre: !1
108
+ };
109
+ return;
110
+ }
111
+ if (e.ctrl && e.alt) {
112
+ h = {
113
+ kind: "size",
114
+ screenX: e.screenX,
115
+ size: m(p.getState().brush)
116
+ };
117
+ return;
118
+ }
119
+ if (T("Eyedropper", e)) {
120
+ let { button: n } = e;
121
+ return h = {
122
+ kind: "pick",
123
+ button: n
124
+ }, s.hold(() => A(t, n));
125
+ }
126
+ let { fgColor: i, bgColor: a, brush: o } = p.getState(), l = {
127
+ right: e.button === "right",
128
+ fg: i,
129
+ bg: a,
130
+ brush: o
131
+ };
132
+ if (n === "paint_bucket") return h = { kind: "filled" }, s.hold(() => s.fill(t, l));
133
+ await s.ready();
134
+ let u = s.stroke(l);
135
+ if (_ && T("StraightLineFromLastPoint", e)) {
136
+ let n = O(_, t, e);
137
+ u.to(_, n), h = {
138
+ kind: "free",
139
+ stroke: u,
140
+ end: n
141
+ };
142
+ } else u.to(null, t), h = {
143
+ kind: "free",
144
+ stroke: u,
145
+ end: t
146
+ };
147
+ }),
148
+ move: (e) => C(() => {
149
+ let t = w(e);
150
+ if (!h) return !e.ctrl || !e.alt ? void (g = null) : (g ??= {
151
+ screenX: e.screenX,
152
+ size: m(p.getState().brush)
153
+ }, k(g.size + Math.trunc((e.screenX - g.screenX) / u)));
154
+ if (h.kind === "pan") {
155
+ let { view: t } = p.getState(), n = {
156
+ x: t.scroll.x - (e.screenX - h.screenX),
157
+ y: t.scroll.y - (e.screenY - h.screenY)
158
+ };
159
+ return [h.screenX, h.screenY] = [e.screenX, e.screenY], p.setState({ view: {
160
+ zoom: t.zoom,
161
+ scroll: n
162
+ } });
163
+ }
164
+ if (h.kind === "size") return k(h.size + Math.trunc((e.screenX - h.screenX) / u));
165
+ if (h.kind === "pick") {
166
+ let { button: e } = h;
167
+ return s.hold(() => A(t, e));
168
+ }
169
+ if (h.kind !== "filled") {
170
+ if (h.kind === "move") {
171
+ let [n, r] = [t.x - h.start.x, t.y - h.start.y];
172
+ e.shift ? s.moving.drag(Math.abs(n) >= Math.abs(r) ? {
173
+ x: n,
174
+ y: 0
175
+ } : {
176
+ x: 0,
177
+ y: r
178
+ }) : s.moving.drag({
179
+ x: n,
180
+ y: r
181
+ });
182
+ } else if (h.kind === "select") {
183
+ let n = h;
184
+ e.shift || (n.held.shift = !1), e.ctrl || (n.held.ctrl = !1), n.square = T("SquareAspect", e) && !n.held.shift, n.centre = T("DrawFromCenter", e) && !n.held.ctrl;
185
+ let r = n.points.at(-1);
186
+ n.tool === "lasso" && (n.path.push({
187
+ x: e.x,
188
+ y: e.y
189
+ }), (t.x !== r.x || t.y !== r.y) && n.points.push(t)), n.tool === "rectangular_marquee" && (n.points = [n.points[0], t]);
190
+ } else (t.x !== h.end.x || t.y !== h.end.y) && (h.stroke.to(h.end, t), h.end = t);
191
+ }
192
+ }),
193
+ up: (e) => C(() => {
194
+ if (h?.kind === "move" && s.moving.drop(), h?.kind === "free" && (h.stroke.end(), _ = h.end), h?.kind === "select") {
195
+ let { tool: e, points: t, mode: n, square: r, centre: i } = h, a = t.every((e) => e.x === t[0].x && e.y === t[0].y);
196
+ e === "magic_wand" ? s.selectWith(e, t.slice(0, 1), n) : a ? n === p.getState().selectionMode && n === "replace" && s.deselect() : e === "lasso" ? s.selectWith(e, t, n) : s.selectWith(e, l(t[0], t[1], r, i), n);
197
+ }
198
+ h = null;
199
+ }),
200
+ cancel() {
201
+ return h ? h.kind === "free" ? (j.end(), !1) : (h = null, !0) : !1;
202
+ },
203
+ end() {
204
+ h?.kind === "free" && (h.stroke.end(), _ = h.end, h = { kind: "filled" });
205
+ },
206
+ idle: () => S,
207
+ key(e) {
208
+ let t = i(s.keymap, e, b.space, s.platform);
209
+ if (!t) return !1;
210
+ let { editor: n } = s;
211
+ if ("command" in t && t.command === "Apply" && !s.moving.get() || "command" in t && t.command === "Cancel" && !p.getState().selection || "command" in t && t.command === "MoveMask" && !c.includes(p.getState().tool)) return !1;
212
+ if ("command" in t) {
213
+ let e = n.command[t.command];
214
+ S = e(t.params);
215
+ } else "tool" in t ? s.set({ tool: t.tool }) : "run" in t && t.run(n);
216
+ return !0;
217
+ },
218
+ wheel(e, t) {
219
+ let { zoomWithScrollWheel: n, view: r, screen: i, brush: o } = p.getState();
220
+ if (e.ctrl && !b.ctrl) return s.pinch(1 - e.dy / 100, t), !0;
221
+ if (e.ctrl && n) return e.dy && k(m(o) + (e.dy < 0 ? 1 : -1)), !0;
222
+ if (n ? !e.shift : e.ctrl) {
223
+ let n = e.mode ? Math.sign(e.dx + e.dy) * 1.5 : e.dx + e.dy, i = Math.abs(n) >= 1.5 && a(r.zoom, n < 0 ? 1 : -1);
224
+ return i && s.zoomTo(i, t), !0;
225
+ }
226
+ let [c, l] = e.shift && !e.dx ? [e.dy, 0] : [e.dx, e.dy];
227
+ return e.mode && (c = Math.sign(c) * Math.trunc(i.width / 10), l = Math.sign(l) * Math.trunc(i.height / 10)), p.setState({ view: {
228
+ zoom: r.zoom,
229
+ scroll: {
230
+ x: r.scroll.x + c,
231
+ y: r.scroll.y + l
232
+ }
233
+ } }), !0;
234
+ },
235
+ focus() {
236
+ let { screen: e } = p.getState();
237
+ return y ?? {
238
+ x: e.width / 2,
239
+ y: e.height / 2
240
+ };
241
+ },
242
+ attach: N,
243
+ toPixel: (e, t) => null
244
+ }, M = () => {
245
+ let e = /* @__PURE__ */ new Map();
246
+ if (!v) return e;
247
+ let { brush: n, fgColor: i, bgColor: a } = p.getState(), o = {
248
+ ...v,
249
+ ...b
250
+ }, s = !h && _ && T("StraightLineFromLastPoint", o), c = s ? _ : v.pixel, l = t({
251
+ right: !1,
252
+ fg: i,
253
+ bg: a,
254
+ brush: n
255
+ }, c), u = (t, n) => l(t, n, (t, n, r) => e.set(`${t},${n}`, r));
256
+ if (s) {
257
+ let e = O(_, v.pixel, o);
258
+ r(_, e, u);
259
+ } else u(v.pixel.x, v.pixel.y);
260
+ return e;
261
+ };
262
+ function N(t, r) {
263
+ let i = r.getContext("2d");
264
+ t.style.touchAction = "none";
265
+ let a = (e, n) => {
266
+ let r = t.getBoundingClientRect(), { x: i, y: a, scale: o } = p.getState().transform, [s, c] = [e - r.left, n - r.top];
267
+ return {
268
+ x: (s - i) / o,
269
+ y: (c - a) / o,
270
+ screenX: s,
271
+ screenY: c
272
+ };
273
+ };
274
+ j.toPixel = (e, t) => {
275
+ let n = w(a(e, t)), { width: r, height: i } = p.getState();
276
+ return n.x >= 0 && n.y >= 0 && n.x < r && n.y < i ? n : null;
277
+ };
278
+ let u = (e, t = e.button) => ({
279
+ ...a(e.clientX, e.clientY),
280
+ button: t === 2 ? "right" : t === 1 ? "middle" : "left",
281
+ shift: e.shiftKey,
282
+ ctrl: e.ctrlKey,
283
+ alt: e.altKey
284
+ }), d = () => {
285
+ if (v) {
286
+ let e = a(v.client.x, v.client.y);
287
+ v = {
288
+ ...v,
289
+ ...e,
290
+ pixel: w(e)
291
+ };
292
+ }
293
+ let r = p.getState(), { screen: u, transform: d, palette: f, brushPreview: m, crosshair: g, cursorColor: _, systemCursor: y } = r, { x, y: S, scale: C } = d;
294
+ i.setTransform(u.dpr, 0, 0, u.dpr, 0, 0), i.clearRect(0, 0, u.width, u.height);
295
+ let T = (e) => Math.round(e * u.dpr) / u.dpr, E = (e, t) => {
296
+ let [n, r] = [T(x + e * C), T(S + t * C)];
297
+ return [
298
+ n,
299
+ r,
300
+ T(x + (e + 1) * C) - n,
301
+ T(S + (t + 1) * C) - r
302
+ ];
303
+ }, A = h?.kind === "pan" || b.space || r.tool === "hand", j = c.includes(r.tool);
304
+ t.style.cursor = A ? h?.kind === "pan" ? "grabbing" : "grab" : j || y || m === "none" && !g ? "crosshair" : "none";
305
+ let N = v && !A && !j ? M() : null, P = N && {
306
+ set: N,
307
+ cells: [...N.keys()].map((e) => e.split(",").map(Number))
308
+ }, F = s.moving.get();
309
+ if (F) for (let e = 0; e < F.height; e++) for (let t = 0; t < F.width; t++) {
310
+ let [n, a, o] = [
311
+ e * F.width + t,
312
+ F.x + t,
313
+ F.y + e
314
+ ];
315
+ a < 0 || o < 0 || a >= r.width || o >= r.height || F.data[n] && (F.opaque || F.pixels[n]) && (i.fillStyle = f[F.pixels[n]] ?? "#000000", i.fillRect(...E(a, o)));
316
+ }
317
+ if (P && (m === "full" || m === "full-edges")) for (let [e, t] of P.cells) e >= 0 && t >= 0 && e < r.width && t < r.height && (i.fillStyle = f[N.get(`${e},${t}`)] ?? "#000000", i.fillRect(...E(e, t)));
318
+ let I = r.showPixelGrid ? o(C) : 0;
319
+ if (I) {
320
+ let e = Math.max(0, Math.floor(-x / C)), t = Math.min(r.width, Math.ceil((u.width - x) / C)), n = Math.max(0, Math.floor(-S / C)), a = Math.min(r.height, Math.ceil((u.height - S) / C));
321
+ i.fillStyle = "#c8c8c8", i.globalAlpha = I;
322
+ for (let r = e; r < t; r++) i.fillRect(T(x + r * C), S + n * C, 1, (a - n) * C);
323
+ for (let r = n; r < a; r++) i.fillRect(x + e * C, T(S + r * C), (t - e) * C, 1);
324
+ i.globalAlpha = 1;
325
+ }
326
+ i.beginPath();
327
+ let L = F ?? r.selection;
328
+ if (L) {
329
+ L.data !== O && ([O, k] = [L.data, e(L.data, L.width, L.height)]);
330
+ for (let [e, t, n, r] of k) i.moveTo(x + (L.x + e) * C, S + (L.y + t) * C), i.lineTo(x + (L.x + n) * C, S + (L.y + r) * C);
331
+ }
332
+ if (h?.kind === "select" && h.tool !== "magic_wand") {
333
+ let e = h.tool === "lasso" ? h.path : l(h.points[0], h.points.at(-1), h.square, h.centre);
334
+ if (h.tool === "rectangular_marquee") {
335
+ let [t, n] = e, [r, a] = [Math.min(t.x, n.x), Math.min(t.y, n.y)];
336
+ i.rect(x + r * C, S + a * C, (Math.abs(n.x - t.x) + 1) * C, (Math.abs(n.y - t.y) + 1) * C);
337
+ } else e.forEach((e, t) => i[t ? "lineTo" : "moveTo"](x + e.x * C, S + e.y * C));
338
+ }
339
+ if (i.lineWidth = 1, i.strokeStyle = "#ffffff", i.setLineDash([]), i.stroke(), i.strokeStyle = "#000000", i.setLineDash([4, 4]), i.lineDashOffset = D.matches ? 0 : -Math.floor(performance.now() / 100) % 8, i.stroke(), i.setLineDash([]), !P || !v) return;
340
+ let { cells: R } = P;
341
+ if (i.beginPath(), m === "edges" || m === "full-edges") for (let [e, t] of R) {
342
+ let [n, r, a, o] = E(e, t), s = (n, r) => N.has(`${e + n},${t + r}`);
343
+ _ ? (s(0, -1) || i.rect(n, r, a, 0), s(0, 1) || i.rect(n, r + o, a, 0), s(-1, 0) || i.rect(n, r, 0, o), s(1, 0) || i.rect(n + a, r, 0, o)) : (i.fillStyle = "#ffffff", s(0, -1) || i.fillRect(n, r - 1, a, 1), s(-1, 0) || i.fillRect(n - 1, r, 1, o), i.fillStyle = "#000000", s(0, 1) || i.fillRect(n, r + o, a, 1), s(1, 0) || i.fillRect(n + a, r, 1, o));
344
+ }
345
+ if (g) {
346
+ let e = n(p.getState().brush), t = x + (v.pixel.x + e.width / 2 - e.center.x) * C, r = S + (v.pixel.y + e.height / 2 - e.center.y) * C, a = Math.max(e.width, e.height) / 2 * C + 3;
347
+ for (let [e, n] of [
348
+ [1, 0],
349
+ [-1, 0],
350
+ [0, 1],
351
+ [0, -1]
352
+ ]) i.moveTo(t + e * a, r + n * a), i.lineTo(t + e * (a + 6), r + n * (a + 6));
353
+ }
354
+ _ || (i.strokeStyle = "#ffffff", i.lineWidth = 3, i.stroke()), i.strokeStyle = _ ?? "#000000", i.lineWidth = 1, i.stroke();
355
+ }, m = /* @__PURE__ */ new Map(), g = null, _ = !1, x = (e) => e.pointerType === "touch" && p.getState().touchGestures, S = () => {
356
+ let [e, n] = [...m.values()], r = t.getBoundingClientRect();
357
+ return {
358
+ x: (e.x + n.x) / 2 - r.left,
359
+ y: (e.y + n.y) / 2 - r.top,
360
+ span: Math.hypot(e.x - n.x, e.y - n.y)
361
+ };
362
+ }, C = (e) => {
363
+ if (!(e.button > 2)) {
364
+ if (t.setPointerCapture(e.pointerId), x(e)) {
365
+ if (m.set(e.pointerId, {
366
+ x: e.clientX,
367
+ y: e.clientY
368
+ }), m.size === 1) return void (g = e);
369
+ g ? g = null : j.cancel(), _ = !0;
370
+ } else j.down(u(e));
371
+ }
372
+ }, T = (e) => {
373
+ if (m.has(e.pointerId)) {
374
+ if (_) {
375
+ if (m.size < 2) return void m.set(e.pointerId, {
376
+ x: e.clientX,
377
+ y: e.clientY
378
+ });
379
+ let t = S();
380
+ m.set(e.pointerId, {
381
+ x: e.clientX,
382
+ y: e.clientY
383
+ });
384
+ let n = S(), { zoom: r, scroll: i } = p.getState().view;
385
+ p.setState({ view: {
386
+ zoom: r,
387
+ scroll: {
388
+ x: i.x - n.x + t.x,
389
+ y: i.y - n.y + t.y
390
+ }
391
+ } }), t.span && s.pinch(n.span / t.span, n);
392
+ return;
393
+ }
394
+ if (g) {
395
+ if (Math.hypot(e.clientX - g.clientX, e.clientY - g.clientY) < 4) return;
396
+ j.down(u(g)), g = null;
397
+ }
398
+ }
399
+ let t = u(e, h?.kind === "pick" && h.button === "right" ? 2 : 0);
400
+ v = {
401
+ ...t,
402
+ pixel: w(t),
403
+ client: {
404
+ x: e.clientX,
405
+ y: e.clientY
406
+ }
407
+ }, j.move(t), d();
408
+ }, E = (e) => {
409
+ if (m.delete(e.pointerId)) {
410
+ if (_) return void (_ = m.size > 0);
411
+ if (g) {
412
+ let t = g;
413
+ if (g = null, e.type === "pointercancel") return;
414
+ j.down(u(t));
415
+ }
416
+ }
417
+ j.up(u(e)).then(d);
418
+ }, D = matchMedia("(prefers-reduced-motion: reduce)"), O = null, k = [], A = setInterval(() => {
419
+ !D.matches && (p.getState().selection || h?.kind === "select") && d();
420
+ }, 100), N = (e) => {
421
+ let n = t.getBoundingClientRect();
422
+ y = {
423
+ x: e.clientX - n.left,
424
+ y: e.clientY - n.top
425
+ };
426
+ }, P = () => {
427
+ h || (v = null, d());
428
+ }, F = (e) => e.preventDefault(), I = (e) => {
429
+ let { screenX: t, screenY: n } = a(e.clientX, e.clientY), r = {
430
+ dx: e.deltaX,
431
+ dy: e.deltaY,
432
+ mode: e.deltaMode,
433
+ shift: e.shiftKey,
434
+ ctrl: e.ctrlKey
435
+ };
436
+ j.wheel(r, {
437
+ x: t,
438
+ y: n
439
+ }) && e.preventDefault();
440
+ }, L = (e, t) => {
441
+ e.key === "Control" && (b.ctrl = t), e.key === "Shift" && (b.shift = t), e.key === "Alt" && (b.alt = t), e.code === "Space" && (b.space = t);
442
+ }, R = (e) => {
443
+ let t = e.target;
444
+ return !!t && (f.test(t.tagName) || t.isContentEditable);
445
+ }, z = (e) => {
446
+ L(e, !0), !e.defaultPrevented && !R(e) && j.key(e) && e.preventDefault(), d();
447
+ }, B = (e) => {
448
+ L(e, !1), d();
449
+ }, V = () => Object.assign(b, {
450
+ shift: !1,
451
+ ctrl: !1,
452
+ alt: !1,
453
+ space: !1
454
+ }), H = () => {
455
+ let { width: e, height: n } = t.getBoundingClientRect(), i = window.devicePixelRatio || 1;
456
+ r.width = Math.round(e * i), r.height = Math.round(n * i), p.setState({ screen: {
457
+ width: e,
458
+ height: n,
459
+ dpr: i
460
+ } });
461
+ }, U = new ResizeObserver(H);
462
+ U.observe(t);
463
+ let W = null, G = () => {
464
+ W?.removeEventListener("change", K), W = matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`), W.addEventListener("change", K);
465
+ };
466
+ function K() {
467
+ H(), G();
468
+ }
469
+ G(), H();
470
+ let q = p.subscribe(d), J = [
471
+ [
472
+ t,
473
+ "pointerdown",
474
+ C
475
+ ],
476
+ [
477
+ t,
478
+ "pointermove",
479
+ T
480
+ ],
481
+ [
482
+ t,
483
+ "pointerup",
484
+ E
485
+ ],
486
+ [
487
+ t,
488
+ "pointercancel",
489
+ E
490
+ ],
491
+ [
492
+ t,
493
+ "pointerleave",
494
+ P
495
+ ],
496
+ [
497
+ t,
498
+ "contextmenu",
499
+ F
500
+ ],
501
+ [
502
+ t,
503
+ "wheel",
504
+ I
505
+ ],
506
+ [
507
+ window,
508
+ "pointermove",
509
+ N
510
+ ],
511
+ [
512
+ window,
513
+ "keydown",
514
+ z
515
+ ],
516
+ [
517
+ window,
518
+ "keyup",
519
+ B
520
+ ],
521
+ [
522
+ window,
523
+ "blur",
524
+ V
525
+ ]
526
+ ];
527
+ for (let [e, t, n] of J) e.addEventListener(t, n, { passive: !1 });
528
+ return d(), () => {
529
+ for (let [e, t, n] of J) e.removeEventListener(t, n);
530
+ U.disconnect(), clearInterval(A), W?.removeEventListener("change", K), q(), v = null, j.toPixel = () => null, t.style.cursor = "", i.clearRect(0, 0, r.width, r.height);
531
+ };
532
+ }
533
+ return j;
534
+ }
535
+ var m = (e) => e.type === "image" ? 1 : e.size;
536
+ export { p as createInput, s as inputs, l as marqueeRect, d as snap };
@@ -0,0 +1,18 @@
1
+ import { Editor, State } from './types/index';
2
+ import { Mask } from './types/mask';
3
+ /** Each editor's clipboard and screen, for tela's tests. */
4
+ export declare const internals: WeakMap<Editor, {
5
+ clipboard: {
6
+ get(): (Mask & {
7
+ pixels: Uint8Array;
8
+ }) | null;
9
+ set(c: Mask & {
10
+ pixels: Uint8Array;
11
+ }): void;
12
+ };
13
+ setScreen(screen: State["screen"]): void;
14
+ moving(): (Mask & {
15
+ pixels: Uint8Array;
16
+ opaque: boolean;
17
+ }) | null;
18
+ }>;
@@ -0,0 +1,3 @@
1
+ // lib/internals.ts
2
+ var e = /* @__PURE__ */ new WeakMap();
3
+ export { e as internals };
@@ -0,0 +1,20 @@
1
+ import { KeymapEntry } from './types/keymap';
2
+ /**
3
+ * The default keymap for what tela has built so far; each slice adds its entries.
4
+ */
5
+ export declare function defaultKeymap(platform: "mac" | "other"): KeymapEntry[];
6
+ /** How a key matched: 2 on its printed character, 1 on the US key position, 0 not at all. */
7
+ export declare function matchKey(e: KeyboardEvent, key: string, space: boolean, platform: "mac" | "other"): 0 | 1 | 2;
8
+ /** The entry a key event runs: a character match beats a fallback one. */
9
+ export declare function lookup(keymap: readonly KeymapEntry[], e: KeyboardEvent, space: boolean, platform: "mac" | "other"): {
10
+ command: import('./types').CommandId;
11
+ params?: object;
12
+ keys: import('./types/keymap').Keys;
13
+ } | {
14
+ tool: import('./types').ToolId;
15
+ keys: import('./types/keymap').Keys;
16
+ } | {
17
+ id: string;
18
+ run: (editor: import('./types').Editor) => void;
19
+ keys: import('./types/keymap').Keys;
20
+ } | null;