@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.
- package/LICENSE +21 -0
- package/dist/brush.d.ts +21 -0
- package/dist/brush.js +84 -0
- package/dist/document.d.ts +50 -0
- package/dist/document.js +105 -0
- package/dist/history.d.ts +16 -0
- package/dist/history.js +38 -0
- package/dist/image.d.ts +41 -0
- package/dist/image.js +94 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +399 -0
- package/dist/input.d.ts +67 -0
- package/dist/input.js +536 -0
- package/dist/internals.d.ts +18 -0
- package/dist/internals.js +3 -0
- package/dist/keymap.d.ts +20 -0
- package/dist/keymap.js +266 -0
- package/dist/mask.d.ts +27 -0
- package/dist/mask.js +96 -0
- package/dist/moving.d.ts +102 -0
- package/dist/moving.js +215 -0
- package/dist/palette.d.ts +21 -0
- package/dist/palette.js +47 -0
- package/dist/react.d.ts +6 -0
- package/dist/react.js +16 -0
- package/dist/selection.d.ts +15 -0
- package/dist/selection.js +76 -0
- package/dist/sprite.d.ts +20 -0
- package/dist/sprite.js +49 -0
- package/dist/store.d.ts +4 -0
- package/dist/store.js +20 -0
- package/dist/tools.d.ts +43 -0
- package/dist/tools.js +113 -0
- package/dist/transactions.d.ts +45 -0
- package/dist/transactions.js +135 -0
- package/dist/types/document.d.ts +2 -0
- package/dist/types/history.d.ts +11 -0
- package/dist/types/image.d.ts +7 -0
- package/dist/types/index.d.ts +371 -0
- package/dist/types/input.d.ts +105 -0
- package/dist/types/keymap.d.ts +26 -0
- package/dist/types/mask.d.ts +11 -0
- package/dist/types/moving.d.ts +26 -0
- package/dist/types/selection.d.ts +1 -0
- package/dist/types/store.d.ts +4 -0
- package/dist/types/tools.d.ts +8 -0
- package/dist/types/view.d.ts +14 -0
- package/dist/view.d.ts +56 -0
- package/dist/view.js +139 -0
- package/package.json +72 -3
- package/README.md +0 -3
package/dist/keymap.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { matchesKeyboardEvent as e, parseHotkey as t } from "@tanstack/hotkeys";
|
|
2
|
+
// lib/keymap.ts
|
|
3
|
+
function n(e) {
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
command: "Undo",
|
|
7
|
+
keys: ["Cmd+Z"]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
command: "Redo",
|
|
11
|
+
keys: e === "mac" ? [
|
|
12
|
+
"Cmd+Y",
|
|
13
|
+
"Cmd+R",
|
|
14
|
+
"Cmd+Shift+Z"
|
|
15
|
+
] : ["Cmd+Y", "Cmd+Shift+Z"]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
tool: "pencil",
|
|
19
|
+
keys: ["B"]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
tool: "paint_bucket",
|
|
23
|
+
keys: ["G"]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
tool: "hand",
|
|
27
|
+
keys: ["H"]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
tool: "rectangular_marquee",
|
|
31
|
+
keys: ["M"]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
tool: "lasso",
|
|
35
|
+
keys: ["Q"]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
tool: "magic_wand",
|
|
39
|
+
keys: ["W"]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
command: "MaskAll",
|
|
43
|
+
keys: ["Cmd+A"]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
command: "DeselectMask",
|
|
47
|
+
keys: ["Cmd+D"]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
command: "InvertMask",
|
|
51
|
+
keys: ["Cmd+Shift+I"]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
command: "Zoom",
|
|
55
|
+
params: { action: "in" },
|
|
56
|
+
keys: [
|
|
57
|
+
"Cmd++",
|
|
58
|
+
"Cmd+=",
|
|
59
|
+
"Cmd+Shift+="
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
command: "Zoom",
|
|
64
|
+
params: { action: "out" },
|
|
65
|
+
keys: ["Cmd+-"]
|
|
66
|
+
},
|
|
67
|
+
...[
|
|
68
|
+
1,
|
|
69
|
+
2,
|
|
70
|
+
3,
|
|
71
|
+
4,
|
|
72
|
+
5,
|
|
73
|
+
6
|
|
74
|
+
].map((e) => ({
|
|
75
|
+
command: "Zoom",
|
|
76
|
+
params: {
|
|
77
|
+
action: "set",
|
|
78
|
+
percentage: 100 * 2 ** (e - 1)
|
|
79
|
+
},
|
|
80
|
+
keys: [String(e)]
|
|
81
|
+
})),
|
|
82
|
+
{
|
|
83
|
+
command: "Zoom",
|
|
84
|
+
params: {
|
|
85
|
+
action: "set",
|
|
86
|
+
percentage: 50
|
|
87
|
+
},
|
|
88
|
+
keys: ["`", "~"]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
command: "FitScreen",
|
|
92
|
+
keys: ["Cmd+0"]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
command: "ScrollCenter",
|
|
96
|
+
keys: ["Shift+Z"]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
command: "ShowPixelGrid",
|
|
100
|
+
keys: ["Cmd+Shift+'"]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
command: "ChangeBrush",
|
|
104
|
+
params: { change: "increment-size" },
|
|
105
|
+
keys: [
|
|
106
|
+
"+",
|
|
107
|
+
"=",
|
|
108
|
+
"Pad+"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
command: "ChangeBrush",
|
|
113
|
+
params: { change: "decrement-size" },
|
|
114
|
+
keys: ["-", "Pad-"]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
command: "NewBrush",
|
|
118
|
+
keys: ["Cmd+B"]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
command: "ChangeBrush",
|
|
122
|
+
params: { change: "rotate-90cw" },
|
|
123
|
+
keys: ["Space+R"]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
command: "ChangeBrush",
|
|
127
|
+
params: { change: "flip-x" },
|
|
128
|
+
keys: ["Space+X", "Space+H"]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
command: "ChangeBrush",
|
|
132
|
+
params: { change: "flip-y" },
|
|
133
|
+
keys: ["Space+Y", "Space+V"]
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
command: "ChangeBrush",
|
|
137
|
+
params: { change: "flip-d" },
|
|
138
|
+
keys: ["Space+D"]
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
command: "SwitchColors",
|
|
142
|
+
keys: ["X"]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
command: "Copy",
|
|
146
|
+
keys: ["Cmd+C"]
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
command: "Cut",
|
|
150
|
+
keys: ["Cmd+X"]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
command: "Paste",
|
|
154
|
+
keys: ["Cmd+V"]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
command: "Clear",
|
|
158
|
+
keys: ["Backspace", "Delete"]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
command: "Flip",
|
|
162
|
+
params: {
|
|
163
|
+
target: "mask",
|
|
164
|
+
orientation: "horizontal"
|
|
165
|
+
},
|
|
166
|
+
keys: ["Shift+H"]
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
command: "Flip",
|
|
170
|
+
params: {
|
|
171
|
+
target: "mask",
|
|
172
|
+
orientation: "vertical"
|
|
173
|
+
},
|
|
174
|
+
keys: ["Shift+V"]
|
|
175
|
+
},
|
|
176
|
+
...[
|
|
177
|
+
"left",
|
|
178
|
+
"right",
|
|
179
|
+
"up",
|
|
180
|
+
"down"
|
|
181
|
+
].map((e) => ({
|
|
182
|
+
command: "MoveMask",
|
|
183
|
+
params: {
|
|
184
|
+
target: "content",
|
|
185
|
+
direction: e,
|
|
186
|
+
units: "pixel",
|
|
187
|
+
quantity: 1
|
|
188
|
+
},
|
|
189
|
+
keys: [`Arrow${e[0].toUpperCase()}${e.slice(1)}`]
|
|
190
|
+
})),
|
|
191
|
+
{
|
|
192
|
+
command: "Apply",
|
|
193
|
+
keys: ["Enter"]
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
command: "CanvasSize",
|
|
197
|
+
params: { ui: !0 },
|
|
198
|
+
keys: ["C"]
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
command: "Cancel",
|
|
202
|
+
keys: ["Escape"]
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
action: "StraightLineFromLastPoint",
|
|
206
|
+
keys: ["Shift"]
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
action: "AngleSnapFromLastPoint",
|
|
210
|
+
keys: ["Ctrl"]
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
action: "Eyedropper",
|
|
214
|
+
keys: ["Alt"]
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
action: "AddSelection",
|
|
218
|
+
keys: ["Shift"]
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
action: "SubtractSelection",
|
|
222
|
+
keys: ["Alt+Shift"]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
action: "IntersectSelection",
|
|
226
|
+
keys: ["Ctrl+Shift"]
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
action: "SquareAspect",
|
|
230
|
+
keys: ["Shift"]
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
action: "DrawFromCenter",
|
|
234
|
+
keys: ["Ctrl"]
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
}
|
|
238
|
+
var r = {
|
|
239
|
+
"Pad+": "NumpadAdd",
|
|
240
|
+
"Pad-": "NumpadSubtract"
|
|
241
|
+
}, i = {
|
|
242
|
+
Cmd: "Mod",
|
|
243
|
+
Ctrl: "Control",
|
|
244
|
+
Alt: "Alt",
|
|
245
|
+
Shift: "Shift"
|
|
246
|
+
};
|
|
247
|
+
function a(n, a, o, s) {
|
|
248
|
+
let c = a.split("+");
|
|
249
|
+
if ((a.endsWith("++") || a === "+") && c.splice(-2, 2, "+"), c[0] === "Space") {
|
|
250
|
+
if (!o) return 0;
|
|
251
|
+
c.shift();
|
|
252
|
+
} else if (o) return 0;
|
|
253
|
+
let l = c.at(-1);
|
|
254
|
+
if (r[a]) return n.code === r[a] ? 2 : 0;
|
|
255
|
+
let u = [...c.slice(0, -1).map((e) => i[e] ?? e), l].join("+"), d = s === "mac" ? "mac" : "windows";
|
|
256
|
+
return e(n, u, d) ? t(u, d).key?.toLowerCase() === n.key.toLowerCase() ? 2 : 1 : 0;
|
|
257
|
+
}
|
|
258
|
+
function o(e, t, n, r) {
|
|
259
|
+
let i = null, o = 0;
|
|
260
|
+
for (let s of e) if (!("action" in s)) for (let e of s.keys) {
|
|
261
|
+
let c = a(t, e, n, r);
|
|
262
|
+
c > o && ([i, o] = [s, c]);
|
|
263
|
+
}
|
|
264
|
+
return i;
|
|
265
|
+
}
|
|
266
|
+
export { n as defaultKeymap, o as lookup, a as matchKey };
|
package/dist/mask.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Point } from './types/index';
|
|
2
|
+
import { Mask, SelectionMode } from './types/mask';
|
|
3
|
+
/** The mask on an image-sized bitmap, clipped to the image. */
|
|
4
|
+
export declare function toBits(mask: Mask, width: number, height: number): Uint8Array<ArrayBuffer>;
|
|
5
|
+
/** The bitmap cropped to its selected pixels, or null when none is. */
|
|
6
|
+
export declare function toMask(bits: Uint8Array, width: number): Mask | null;
|
|
7
|
+
/**
|
|
8
|
+
* A tool's shape combined with the selection pixel by pixel. With no selection, Add acts as
|
|
9
|
+
* Replace, and Subtract and Intersect give nothing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function combine(selection: Uint8Array | null, shape: Uint8Array, mode: SelectionMode): Uint8Array<ArrayBufferLike>;
|
|
12
|
+
/**
|
|
13
|
+
* The region of the clicked index, 4- or 8-connected to it when contiguous. `within` bounds it:
|
|
14
|
+
* the Paint Bucket's selection, which the flood never crosses; the Magic Wand passes none. A click
|
|
15
|
+
* off the image gives nothing.
|
|
16
|
+
*/
|
|
17
|
+
export declare function flood(image: Uint8Array, width: number, height: number, at: Point, contiguous: boolean, connectivity: 4 | 8, within?: Uint8Array | null): Uint8Array<ArrayBuffer>;
|
|
18
|
+
/**
|
|
19
|
+
* The selection's edges as runs along pixel edges, [x1, y1, x2, y2] in sprite pixels: each run
|
|
20
|
+
* stops where the edge ends or the selected side changes.
|
|
21
|
+
*
|
|
22
|
+
* shortcut: runs straight from the bitmap; the ants' dash phase at corners may differ,
|
|
23
|
+
* revisit if a gesture spec observes it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function outline(bits: Uint8Array, width: number, height: number): [number, number, number, number][];
|
|
26
|
+
/** The mask cropped to its selected pixels, off the image or not; null when none is. */
|
|
27
|
+
export declare function tight(mask: Mask): Mask | null;
|
package/dist/mask.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// lib/mask.ts
|
|
2
|
+
function e(e, t, n) {
|
|
3
|
+
let r = new Uint8Array(t * n);
|
|
4
|
+
for (let i = 0; i < e.height; i++) for (let a = 0; a < e.width; a++) {
|
|
5
|
+
let [o, s] = [e.x + a, e.y + i];
|
|
6
|
+
o >= 0 && s >= 0 && o < t && s < n && e.data[i * e.width + a] && (r[s * t + o] = 1);
|
|
7
|
+
}
|
|
8
|
+
return r;
|
|
9
|
+
}
|
|
10
|
+
function t(e, t) {
|
|
11
|
+
let [n, r, i, a] = [
|
|
12
|
+
Infinity,
|
|
13
|
+
Infinity,
|
|
14
|
+
-1,
|
|
15
|
+
-1
|
|
16
|
+
];
|
|
17
|
+
if (e.forEach((e, o) => {
|
|
18
|
+
if (!e) return;
|
|
19
|
+
let [s, c] = [o % t, Math.floor(o / t)];
|
|
20
|
+
[n, r, i, a] = [
|
|
21
|
+
Math.min(n, s),
|
|
22
|
+
Math.min(r, c),
|
|
23
|
+
Math.max(i, s),
|
|
24
|
+
Math.max(a, c)
|
|
25
|
+
];
|
|
26
|
+
}), i < 0) return null;
|
|
27
|
+
let [o, s] = [i - n + 1, a - r + 1], c = new Uint8Array(o * s);
|
|
28
|
+
for (let i = 0; i < s; i++) c.set(e.subarray((r + i) * t + n, (r + i) * t + n + o), i * o);
|
|
29
|
+
return {
|
|
30
|
+
x: n,
|
|
31
|
+
y: r,
|
|
32
|
+
width: o,
|
|
33
|
+
height: s,
|
|
34
|
+
data: c
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function n(e, t, n) {
|
|
38
|
+
return n === "replace" || n === "add" && !e ? t : e ? e.map((e, r) => n === "add" ? e | t[r] : n === "subtract" ? e & 1 - t[r] : e & t[r]) : new Uint8Array(t.length);
|
|
39
|
+
}
|
|
40
|
+
function r(e, t, n, r, i, a, o = null) {
|
|
41
|
+
let s = new Uint8Array(t * n);
|
|
42
|
+
if (r.x < 0 || r.y < 0 || r.x >= t || r.y >= n) return s;
|
|
43
|
+
let c = e[r.y * t + r.x], l = (t) => e[t] === c && (!o || o[t] === 1);
|
|
44
|
+
if (!i) return s.map((e, t) => +!!l(t));
|
|
45
|
+
let u = [r.y * t + r.x];
|
|
46
|
+
if (!l(u[0])) return s;
|
|
47
|
+
s[u[0]] = 1;
|
|
48
|
+
for (let e = u.pop(); e !== void 0; e = u.pop()) {
|
|
49
|
+
let [r, i] = [e % t, Math.floor(e / t)];
|
|
50
|
+
for (let e = -1; e <= 1; e++) for (let o = -1; o <= 1; o++) {
|
|
51
|
+
if (!o && !e || a === 4 && o && e) continue;
|
|
52
|
+
let [c, d] = [r + o, i + e];
|
|
53
|
+
if (c < 0 || d < 0 || c >= t || d >= n) continue;
|
|
54
|
+
let f = d * t + c;
|
|
55
|
+
!s[f] && l(f) && (s[f] = 1, u.push(f));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return s;
|
|
59
|
+
}
|
|
60
|
+
function i(e, t, n) {
|
|
61
|
+
let r = (r, i) => r >= 0 && i >= 0 && r < t && i < n ? e[i * t + r] : 0, i = [];
|
|
62
|
+
for (let e = 0; e <= n; e++) {
|
|
63
|
+
let n = -1, a = 0;
|
|
64
|
+
for (let o = 0; o <= t; o++) {
|
|
65
|
+
let s = o < t ? r(o, e) - r(o, e - 1) : 0;
|
|
66
|
+
s !== a && (a && i.push([
|
|
67
|
+
n,
|
|
68
|
+
e,
|
|
69
|
+
o,
|
|
70
|
+
e
|
|
71
|
+
]), [n, a] = [o, s]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (let e = 0; e <= t; e++) {
|
|
75
|
+
let t = -1, a = 0;
|
|
76
|
+
for (let o = 0; o <= n; o++) {
|
|
77
|
+
let s = o < n ? r(e, o) - r(e - 1, o) : 0;
|
|
78
|
+
s !== a && (a && i.push([
|
|
79
|
+
e,
|
|
80
|
+
t,
|
|
81
|
+
e,
|
|
82
|
+
o
|
|
83
|
+
]), [t, a] = [o, s]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return i;
|
|
87
|
+
}
|
|
88
|
+
function a(e) {
|
|
89
|
+
let n = t(e.data, e.width);
|
|
90
|
+
return n && {
|
|
91
|
+
...n,
|
|
92
|
+
x: e.x + n.x,
|
|
93
|
+
y: e.y + n.y
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export { n as combine, r as flood, i as outline, a as tight, e as toBits, t as toMask };
|
package/dist/moving.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Doc } from './types/document';
|
|
2
|
+
import { BrushChange } from './types/image';
|
|
3
|
+
import { Point, State } from './types/index';
|
|
4
|
+
import { Mask } from './types/mask';
|
|
5
|
+
import { Clip, Moving } from './types/moving';
|
|
6
|
+
/** The image positions under a mask, with their places in it. */
|
|
7
|
+
export declare function under(doc: Doc, m: Mask, x?: number, y?: number): [p: number, i: number][];
|
|
8
|
+
/** `value` at `positions`, not yet written. */
|
|
9
|
+
export declare const fillWith: (doc: Doc, positions: number[], value: number) => import('./types/history').Change;
|
|
10
|
+
/** The selection's pixels, lifted; unless `keep`, their place takes `holeIndex`. */
|
|
11
|
+
export declare function lift(doc: Doc, sel: Mask, keep: boolean, holeIndex: number): Moving;
|
|
12
|
+
/** The clipboard as moving pixels, its top-left at `at`. */
|
|
13
|
+
export declare const paste: (c: Clip, at: Point, before: Mask | null) => Moving;
|
|
14
|
+
/** Where the moving pixels lie now, as a mask with their indices. */
|
|
15
|
+
export declare const lying: (m: Moving) => {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
21
|
+
pixels: Uint8Array<ArrayBufferLike>;
|
|
22
|
+
};
|
|
23
|
+
/** The drag in progress becomes part of where they lie. */
|
|
24
|
+
export declare function drop(m: Moving): void;
|
|
25
|
+
export declare function nudge(m: Moving, dx: number, dy: number): void;
|
|
26
|
+
/** A flip or turn of the moving pixels; a 90° turn keeps the box's exact centre. */
|
|
27
|
+
export declare function reshape(m: Moving, change: BrushChange[], quarter: boolean): void;
|
|
28
|
+
/** Edit > Shift on the moving pixels: their indices wrap inside their box; the shape stays. */
|
|
29
|
+
export declare function wrapMoving(m: Moving, dx: number, dy: number): void;
|
|
30
|
+
/** The moving pixels written where they lie, not yet done; index 0 left out unless `opaque`. */
|
|
31
|
+
export declare function laid(doc: Doc, m: Moving, opaque: boolean): import('./types/history').Change;
|
|
32
|
+
/** A copy of the moving pixels as they lie, or else of the selection; null with neither. */
|
|
33
|
+
export declare function copy(doc: Doc, m: Moving | null): Clip | null;
|
|
34
|
+
/**
|
|
35
|
+
* Where ⌘V puts the clipboard: per axis, its place while its centre is in view, else centred on
|
|
36
|
+
* the view; then clamped onto the image. Headless (no screen), its copied place.
|
|
37
|
+
*/
|
|
38
|
+
export declare function placement(doc: Doc, c: Clip, screen: {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
}, t: {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
scale: number;
|
|
45
|
+
}): Point;
|
|
46
|
+
/**
|
|
47
|
+
* The editor's moving pixels and clipboard. A commit, discard or clear returns one undo state's
|
|
48
|
+
* change for the editor to record; a cancel records nothing.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createMoving(deps: {
|
|
51
|
+
doc: Doc;
|
|
52
|
+
store: {
|
|
53
|
+
getState(): State;
|
|
54
|
+
setState(patch: Partial<State>): void;
|
|
55
|
+
};
|
|
56
|
+
/** The `movingpixels` event. */
|
|
57
|
+
emit: (phase: "start" | "end") => void;
|
|
58
|
+
/** What the lift, Cut and Delete leave. */
|
|
59
|
+
holeIndex(): number;
|
|
60
|
+
}): {
|
|
61
|
+
readonly active: boolean;
|
|
62
|
+
/** Where the moving pixels lie, with the Transparent Color option; null when none move. */
|
|
63
|
+
shown: () => {
|
|
64
|
+
opaque: boolean;
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
70
|
+
pixels: Uint8Array<ArrayBufferLike>;
|
|
71
|
+
} | null;
|
|
72
|
+
/** Lifts the selection; the editor sends the "start" event and reads first. */
|
|
73
|
+
lift(keep: boolean): void;
|
|
74
|
+
/** Writes the moving pixels where they lie: one undo state with the lift and the selection. */
|
|
75
|
+
commit(): {
|
|
76
|
+
label: string;
|
|
77
|
+
change: import('./types/history').Change;
|
|
78
|
+
} | null;
|
|
79
|
+
/** ⌘Z or ✗: the image and the selection as before the lift; nothing recorded. */
|
|
80
|
+
cancel(): boolean;
|
|
81
|
+
/** Delete or Cut while moving: the hole stays, the pixels go, deselected; one undo state. */
|
|
82
|
+
discard(): import('./types/history').Change;
|
|
83
|
+
/** File > Open: the moving pixels go, recording nothing. */
|
|
84
|
+
reset(): void;
|
|
85
|
+
/** Copies the moving pixels as they lie, or the selection; false with neither. */
|
|
86
|
+
copy(): boolean;
|
|
87
|
+
/** The selection's pixels, or the whole image, take the hole index; deselects; one undo state. */
|
|
88
|
+
clear(): import('./types/history').Change;
|
|
89
|
+
/** The clipboard as moving pixels at `at`, or where ⌘V puts it; the editor commits first. */
|
|
90
|
+
paste(at?: Point): boolean;
|
|
91
|
+
reshape(change: BrushChange[], quarter: boolean): void;
|
|
92
|
+
nudge(dx: number, dy: number): void;
|
|
93
|
+
wrap(dx: number, dy: number): void;
|
|
94
|
+
drag: (by: Point) => undefined;
|
|
95
|
+
drop: () => void;
|
|
96
|
+
clipboard: {
|
|
97
|
+
get: () => Clip | null;
|
|
98
|
+
set: (c: Clip) => undefined;
|
|
99
|
+
};
|
|
100
|
+
/** The clipboard's indices follow `f`, as a remap moves them. */
|
|
101
|
+
remap(f: (i: number) => number): void;
|
|
102
|
+
};
|
package/dist/moving.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { turn as e, wrap as t } from "./image.js";
|
|
2
|
+
import { group as n } from "./history.js";
|
|
3
|
+
// lib/moving.ts
|
|
4
|
+
function r(e, t, n = t.x, r = t.y) {
|
|
5
|
+
let i = [];
|
|
6
|
+
for (let a = 0; a < t.height; a++) for (let o = 0; o < t.width; o++) {
|
|
7
|
+
let [s, c, l] = [
|
|
8
|
+
n + o,
|
|
9
|
+
r + a,
|
|
10
|
+
a * t.width + o
|
|
11
|
+
];
|
|
12
|
+
t.data[l] && s >= 0 && c >= 0 && s < e.width && c < e.height && i.push([c * e.width + s, l]);
|
|
13
|
+
}
|
|
14
|
+
return i;
|
|
15
|
+
}
|
|
16
|
+
var i = (e, t, n) => e.pixels(Uint32Array.from(t), Uint8Array.from(t, (t) => e.image[t]), new Uint8Array(t.length).fill(n));
|
|
17
|
+
function a(e, t, n, a) {
|
|
18
|
+
let o = new Uint8Array(t.width * t.height), c = r(e, t);
|
|
19
|
+
for (let [t, n] of c) o[n] = e.image[t];
|
|
20
|
+
let l = n ? null : i(e, c.map(([e]) => e), a);
|
|
21
|
+
return {
|
|
22
|
+
...s(t, o, t.data, t),
|
|
23
|
+
hole: l,
|
|
24
|
+
label: "Move Selection"
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var o = (e, t, n) => ({
|
|
28
|
+
...s(e, e.pixels.slice(), e.data.slice(), t),
|
|
29
|
+
before: n,
|
|
30
|
+
hole: null,
|
|
31
|
+
label: "Paste"
|
|
32
|
+
}), s = (e, t, n, r) => ({
|
|
33
|
+
data: t,
|
|
34
|
+
mask: n.slice(),
|
|
35
|
+
width: e.width,
|
|
36
|
+
height: e.height,
|
|
37
|
+
x: r.x,
|
|
38
|
+
y: r.y,
|
|
39
|
+
drag: {
|
|
40
|
+
x: 0,
|
|
41
|
+
y: 0
|
|
42
|
+
},
|
|
43
|
+
before: e
|
|
44
|
+
}), c = (e) => ({
|
|
45
|
+
x: Math.floor(e.x) + e.drag.x,
|
|
46
|
+
y: Math.floor(e.y) + e.drag.y,
|
|
47
|
+
width: e.width,
|
|
48
|
+
height: e.height,
|
|
49
|
+
data: e.mask,
|
|
50
|
+
pixels: e.data
|
|
51
|
+
});
|
|
52
|
+
function l(e) {
|
|
53
|
+
[e.x, e.y, e.drag] = [
|
|
54
|
+
e.x + e.drag.x,
|
|
55
|
+
e.y + e.drag.y,
|
|
56
|
+
{
|
|
57
|
+
x: 0,
|
|
58
|
+
y: 0
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
function u(e, t, n) {
|
|
63
|
+
e.x += t, e.y += n;
|
|
64
|
+
}
|
|
65
|
+
function d(t, n, r) {
|
|
66
|
+
l(t);
|
|
67
|
+
let [i, a] = [t.width, t.height];
|
|
68
|
+
for (let r of n) {
|
|
69
|
+
let n = e(t.data, t.width, t.height, r);
|
|
70
|
+
t.mask = e(t.mask, t.width, t.height, r).data, [t.data, t.width, t.height] = [
|
|
71
|
+
n.data,
|
|
72
|
+
n.width,
|
|
73
|
+
n.height
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
r && u(t, (i - a) / 2, (a - i) / 2);
|
|
77
|
+
}
|
|
78
|
+
function f(e, n, r) {
|
|
79
|
+
e.data = t(e, {
|
|
80
|
+
...e,
|
|
81
|
+
x: 0,
|
|
82
|
+
y: 0
|
|
83
|
+
}, n, r).data;
|
|
84
|
+
}
|
|
85
|
+
function p(e, t, n) {
|
|
86
|
+
let i = r(e, c(t)).filter(([, e]) => n || t.data[e]);
|
|
87
|
+
return e.pixels(Uint32Array.from(i, ([e]) => e), Uint8Array.from(i, ([t]) => e.image[t]), Uint8Array.from(i, ([, e]) => t.data[e]));
|
|
88
|
+
}
|
|
89
|
+
function m(e, t) {
|
|
90
|
+
if (t) {
|
|
91
|
+
let e = c(t);
|
|
92
|
+
return {
|
|
93
|
+
...e,
|
|
94
|
+
data: e.data.slice(),
|
|
95
|
+
pixels: e.pixels.slice()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (!e.sel) return null;
|
|
99
|
+
let n = new Uint8Array(e.sel.width * e.sel.height);
|
|
100
|
+
for (let [t, i] of r(e, e.sel)) n[i] = e.image[t];
|
|
101
|
+
return {
|
|
102
|
+
...e.sel,
|
|
103
|
+
data: e.sel.data.slice(),
|
|
104
|
+
pixels: n
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function h(e, t, n, r) {
|
|
108
|
+
if (!n.width) return {
|
|
109
|
+
x: t.x,
|
|
110
|
+
y: t.y
|
|
111
|
+
};
|
|
112
|
+
let i = t.width >= e.width || t.height >= e.height, a = (e, t, n, a, o) => {
|
|
113
|
+
let [s, c] = [-a / r.scale, (o - a) / r.scale], l = Math.floor(e + t / 2), u = l >= s && l < c ? e : Math.round((s + c) / 2 - t / 2);
|
|
114
|
+
return i ? Math.min(Math.max(u, 0), Math.max(n - t, 0)) : Math.min(Math.max(u, 1 - t), n - 1);
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
x: a(t.x, t.width, e.width, r.x, n.width),
|
|
118
|
+
y: a(t.y, t.height, e.height, r.y, n.height)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function g(e) {
|
|
122
|
+
let { doc: t, store: s, emit: g } = e, _ = null, v = null, y = (e) => {
|
|
123
|
+
_ = e;
|
|
124
|
+
let { transparentColor: t } = s.getState();
|
|
125
|
+
t.autoOpaque && s.setState({ transparentColor: {
|
|
126
|
+
...t,
|
|
127
|
+
opaque: !0
|
|
128
|
+
} }), s.setState({ movingPixels: !0 });
|
|
129
|
+
}, b = () => {
|
|
130
|
+
_ = null, s.setState({ movingPixels: !1 }), g("end");
|
|
131
|
+
}, x = () => {
|
|
132
|
+
let { x: e, y: n, width: r, height: i, data: a } = c(_);
|
|
133
|
+
t.select({
|
|
134
|
+
x: e,
|
|
135
|
+
y: n,
|
|
136
|
+
width: r,
|
|
137
|
+
height: i,
|
|
138
|
+
data: a
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
get active() {
|
|
143
|
+
return _ !== null;
|
|
144
|
+
},
|
|
145
|
+
shown: () => _ && {
|
|
146
|
+
...c(_),
|
|
147
|
+
opaque: s.getState().transparentColor.opaque
|
|
148
|
+
},
|
|
149
|
+
lift(n) {
|
|
150
|
+
y(a(t, t.sel, n, e.holeIndex())), _.hole?.redo();
|
|
151
|
+
},
|
|
152
|
+
commit() {
|
|
153
|
+
if (!_) return null;
|
|
154
|
+
let e = _, r = p(t, e, s.getState().transparentColor.opaque);
|
|
155
|
+
return r.redo(), x(), b(), {
|
|
156
|
+
label: e.label,
|
|
157
|
+
change: n([
|
|
158
|
+
e.hole,
|
|
159
|
+
r,
|
|
160
|
+
t.selChange(e.before, t.sel)
|
|
161
|
+
])
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
cancel() {
|
|
165
|
+
return _ ? (_.hole?.undo(), t.select(_.before), b(), !0) : !1;
|
|
166
|
+
},
|
|
167
|
+
discard() {
|
|
168
|
+
let e = _;
|
|
169
|
+
return t.select(null), b(), n([e.hole, t.selChange(e.before, null)]);
|
|
170
|
+
},
|
|
171
|
+
reset() {
|
|
172
|
+
_ && b();
|
|
173
|
+
},
|
|
174
|
+
copy() {
|
|
175
|
+
let e = m(t, _);
|
|
176
|
+
return e && (v = e), !!e;
|
|
177
|
+
},
|
|
178
|
+
clear() {
|
|
179
|
+
let a = t.sel ? r(t, t.sel).map(([e]) => e) : Array.from(t.image.keys()), o = i(t, a, e.holeIndex());
|
|
180
|
+
o.redo();
|
|
181
|
+
let s = t.sel;
|
|
182
|
+
return t.select(null), n([o, t.selChange(s, null)]);
|
|
183
|
+
},
|
|
184
|
+
paste(e) {
|
|
185
|
+
if (!v) return !1;
|
|
186
|
+
g("start");
|
|
187
|
+
let n = v, { screen: r, transform: i } = s.getState();
|
|
188
|
+
return y(o(n, e ?? h(t, n, r, i), t.sel)), x(), !0;
|
|
189
|
+
},
|
|
190
|
+
reshape(e, t) {
|
|
191
|
+
d(_, e, t), x();
|
|
192
|
+
},
|
|
193
|
+
nudge(e, t) {
|
|
194
|
+
u(_, e, t), x();
|
|
195
|
+
},
|
|
196
|
+
wrap(e, t) {
|
|
197
|
+
f(_, e, t);
|
|
198
|
+
},
|
|
199
|
+
drag: (e) => void (_.drag = e),
|
|
200
|
+
drop: () => {
|
|
201
|
+
l(_), x();
|
|
202
|
+
},
|
|
203
|
+
clipboard: {
|
|
204
|
+
get: () => v,
|
|
205
|
+
set: (e) => void (v = e)
|
|
206
|
+
},
|
|
207
|
+
remap(e) {
|
|
208
|
+
v &&= {
|
|
209
|
+
...v,
|
|
210
|
+
pixels: v.pixels.map(e)
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
export { m as copy, g as createMoving, l as drop, i as fillWith, p as laid, a as lift, c as lying, u as nudge, o as paste, h as placement, d as reshape, r as under, f as wrapMoving };
|