@rb-games/core 0.1.1 → 0.1.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.
- package/dist/chunk-5BLUF2HG.js +25 -0
- package/dist/chunk-5BLUF2HG.js.map +1 -0
- package/dist/chunk-DOHQE2YZ.js +392 -0
- package/dist/chunk-DOHQE2YZ.js.map +1 -0
- package/dist/chunk-FOZO6TLY.js +673 -0
- package/dist/chunk-FOZO6TLY.js.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-KOHCRCV3.js +490 -0
- package/dist/chunk-KOHCRCV3.js.map +1 -0
- package/dist/chunk-MI6BP7A6.js +11 -0
- package/dist/chunk-MI6BP7A6.js.map +1 -0
- package/dist/chunk-NQMORMNP.js +15 -0
- package/dist/chunk-NQMORMNP.js.map +1 -0
- package/dist/chunk-RAEOBW6E.js +133 -0
- package/dist/chunk-RAEOBW6E.js.map +1 -0
- package/dist/chunk-UE7T7Z45.js +884 -0
- package/dist/chunk-UE7T7Z45.js.map +1 -0
- package/dist/devtools/index.js +2 -882
- package/dist/devtools/index.js.map +1 -1
- package/dist/engine/index.js +6 -1267
- package/dist/engine/index.js.map +1 -1
- package/dist/filters/index.js +1 -1
- package/dist/helpers/index.js +6 -35
- package/dist/helpers/index.js.map +1 -1
- package/dist/i18n/index.js +4 -525
- package/dist/i18n/index.js.map +1 -1
- package/dist/layout/index.js +2 -671
- package/dist/layout/index.js.map +1 -1
- package/dist/particle/index.js +1 -6
- package/dist/particle/index.js.map +1 -1
- package/dist/plugins/Plugin.types.d.ts +4 -2
- package/dist/plugins/Plugin.types.d.ts.map +1 -1
- package/dist/plugins/index.js +6 -521
- package/dist/plugins/index.js.map +1 -1
- package/dist/state-machine/index.js +1 -1
- package/dist/store/index.js +1 -1
- package/dist/ui/index.js +5 -531
- package/dist/ui/index.js.map +1 -1
- package/dist/utils/index.js +4 -897
- package/dist/utils/index.js.map +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
package/dist/layout/index.js
CHANGED
|
@@ -1,673 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// layout/Bounds.ts
|
|
4
|
-
function rectToBoundsLike(r) {
|
|
5
|
-
const left = r.x;
|
|
6
|
-
const top = r.y;
|
|
7
|
-
const width = r.width;
|
|
8
|
-
const height = r.height;
|
|
9
|
-
const right = left + width;
|
|
10
|
-
const bottom = top + height;
|
|
11
|
-
return {
|
|
12
|
-
left,
|
|
13
|
-
right,
|
|
14
|
-
top,
|
|
15
|
-
bottom,
|
|
16
|
-
width,
|
|
17
|
-
height,
|
|
18
|
-
centerX: left + width / 2,
|
|
19
|
-
centerY: top + height / 2
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function getCommonParent(items) {
|
|
23
|
-
var _a;
|
|
24
|
-
const parent = (_a = items[0]) == null ? void 0 : _a.parent;
|
|
25
|
-
if (!parent) throw new Error("Items must have a parent");
|
|
26
|
-
for (const it of items) {
|
|
27
|
-
if (it.parent !== parent) throw new Error("All items must share the same parent");
|
|
28
|
-
}
|
|
29
|
-
return parent;
|
|
30
|
-
}
|
|
31
|
-
function getLocalBoundsInParent(child, parent) {
|
|
32
|
-
const world = child.getBounds();
|
|
33
|
-
const topLeft = parent.toLocal(new Point(world.x, world.y));
|
|
34
|
-
const bottomRight = parent.toLocal(new Point(world.x + world.width, world.y + world.height));
|
|
35
|
-
const left = Math.min(topLeft.x, bottomRight.x);
|
|
36
|
-
const right = Math.max(topLeft.x, bottomRight.x);
|
|
37
|
-
const top = Math.min(topLeft.y, bottomRight.y);
|
|
38
|
-
const bottom = Math.max(topLeft.y, bottomRight.y);
|
|
39
|
-
const width = right - left;
|
|
40
|
-
const height = bottom - top;
|
|
41
|
-
return {
|
|
42
|
-
left,
|
|
43
|
-
right,
|
|
44
|
-
top,
|
|
45
|
-
bottom,
|
|
46
|
-
width,
|
|
47
|
-
height,
|
|
48
|
-
centerX: left + width / 2,
|
|
49
|
-
centerY: top + height / 2
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function getSelectionBounds(items, parent) {
|
|
53
|
-
const p = parent ?? getCommonParent(items);
|
|
54
|
-
let left = Infinity, right = -Infinity, top = Infinity, bottom = -Infinity;
|
|
55
|
-
for (const it of items) {
|
|
56
|
-
const b = getLocalBoundsInParent(it, p);
|
|
57
|
-
left = Math.min(left, b.left);
|
|
58
|
-
right = Math.max(right, b.right);
|
|
59
|
-
top = Math.min(top, b.top);
|
|
60
|
-
bottom = Math.max(bottom, b.bottom);
|
|
61
|
-
}
|
|
62
|
-
const width = right - left;
|
|
63
|
-
const height = bottom - top;
|
|
64
|
-
return {
|
|
65
|
-
left,
|
|
66
|
-
right,
|
|
67
|
-
top,
|
|
68
|
-
bottom,
|
|
69
|
-
width,
|
|
70
|
-
height,
|
|
71
|
-
centerX: left + width / 2,
|
|
72
|
-
centerY: top + height / 2
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function getReferenceBounds(items, options) {
|
|
76
|
-
if (options == null ? void 0 : options.container) {
|
|
77
|
-
const box = options.container;
|
|
78
|
-
if (box instanceof Container) {
|
|
79
|
-
const parent2 = box;
|
|
80
|
-
const world = parent2.getBounds();
|
|
81
|
-
const topLeft = parent2.toLocal(new Point(world.x, world.y));
|
|
82
|
-
const bottomRight = parent2.toLocal(new Point(world.x + world.width, world.y + world.height));
|
|
83
|
-
const left = Math.min(topLeft.x, bottomRight.x);
|
|
84
|
-
const right = Math.max(topLeft.x, bottomRight.x);
|
|
85
|
-
const top = Math.min(topLeft.y, bottomRight.y);
|
|
86
|
-
const bottom = Math.max(topLeft.y, bottomRight.y);
|
|
87
|
-
const width = right - left;
|
|
88
|
-
const height = bottom - top;
|
|
89
|
-
return {
|
|
90
|
-
ref: {
|
|
91
|
-
left,
|
|
92
|
-
right,
|
|
93
|
-
top,
|
|
94
|
-
bottom,
|
|
95
|
-
width,
|
|
96
|
-
height,
|
|
97
|
-
centerX: left + width / 2,
|
|
98
|
-
centerY: top + height / 2
|
|
99
|
-
},
|
|
100
|
-
parent: parent2
|
|
101
|
-
};
|
|
102
|
-
} else {
|
|
103
|
-
const parent2 = getCommonParent(items);
|
|
104
|
-
return { ref: rectToBoundsLike(box), parent: parent2 };
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const parent = getCommonParent(items);
|
|
108
|
-
if (options == null ? void 0 : options.key) {
|
|
109
|
-
if (options.key.parent !== parent) throw new Error("key and items must share the same parent");
|
|
110
|
-
return { ref: getLocalBoundsInParent(options.key, parent), parent };
|
|
111
|
-
}
|
|
112
|
-
return { ref: getSelectionBounds(items, parent), parent };
|
|
113
|
-
}
|
|
114
|
-
function nudgeX(child, dx) {
|
|
115
|
-
child.x += dx;
|
|
116
|
-
}
|
|
117
|
-
function nudgeY(child, dy) {
|
|
118
|
-
child.y += dy;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// layout/Align.ts
|
|
122
|
-
var Align = class {
|
|
123
|
-
/**
|
|
124
|
-
* Aligns containers to the left edge of the reference bounds.
|
|
125
|
-
*
|
|
126
|
-
* @param items - Array of containers to align
|
|
127
|
-
* @param options - Alignment options to control the reference point
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* // Align to selection bounds (default)
|
|
132
|
-
* Align.left([sprite1, sprite2, sprite3]);
|
|
133
|
-
*
|
|
134
|
-
* // Align to container
|
|
135
|
-
* Align.left([sprite1, sprite2], { container: bounds });
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
static left(items, options) {
|
|
139
|
-
const { ref, parent } = getReferenceBounds(items, options);
|
|
140
|
-
for (const it of items) {
|
|
141
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
142
|
-
nudgeX(it, ref.left - b.left);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Aligns containers to the horizontal center of the reference bounds.
|
|
147
|
-
*
|
|
148
|
-
* @param items - Array of containers to align
|
|
149
|
-
* @param options - Alignment options to control the reference point
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```typescript
|
|
153
|
-
* // Center horizontally within selection
|
|
154
|
-
* Align.hCenter([sprite1, sprite2, sprite3]);
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
static hCenter(items, options) {
|
|
158
|
-
const { ref, parent } = getReferenceBounds(items, options);
|
|
159
|
-
for (const it of items) {
|
|
160
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
161
|
-
nudgeX(it, ref.centerX - b.centerX);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Aligns containers to the right edge of the reference bounds.
|
|
166
|
-
*
|
|
167
|
-
* @param items - Array of containers to align
|
|
168
|
-
* @param options - Alignment options to control the reference point
|
|
169
|
-
*/
|
|
170
|
-
static right(items, options) {
|
|
171
|
-
const { ref, parent } = getReferenceBounds(items, options);
|
|
172
|
-
for (const it of items) {
|
|
173
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
174
|
-
nudgeX(it, ref.right - b.right);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Aligns containers to the top edge of the reference bounds.
|
|
179
|
-
*
|
|
180
|
-
* @param items - Array of containers to align
|
|
181
|
-
* @param options - Alignment options to control the reference point
|
|
182
|
-
*/
|
|
183
|
-
static top(items, options) {
|
|
184
|
-
const { ref, parent } = getReferenceBounds(items, options);
|
|
185
|
-
for (const it of items) {
|
|
186
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
187
|
-
nudgeY(it, ref.top - b.top);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Aligns containers to the vertical center of the reference bounds.
|
|
192
|
-
*
|
|
193
|
-
* @param items - Array of containers to align
|
|
194
|
-
* @param options - Alignment options to control the reference point
|
|
195
|
-
*/
|
|
196
|
-
static vCenter(items, options) {
|
|
197
|
-
const { ref, parent } = getReferenceBounds(items, options);
|
|
198
|
-
for (const it of items) {
|
|
199
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
200
|
-
nudgeY(it, ref.centerY - b.centerY);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Aligns containers to the bottom edge of the reference bounds.
|
|
205
|
-
*
|
|
206
|
-
* @param items - Array of containers to align
|
|
207
|
-
* @param options - Alignment options to control the reference point
|
|
208
|
-
*/
|
|
209
|
-
static bottom(items, options) {
|
|
210
|
-
const { ref, parent } = getReferenceBounds(items, options);
|
|
211
|
-
for (const it of items) {
|
|
212
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
213
|
-
nudgeY(it, ref.bottom - b.bottom);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
var Distribute = class {
|
|
218
|
-
static hLeft(items, options) {
|
|
219
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
220
|
-
const sorted = [...items].sort(
|
|
221
|
-
(a, b) => getLocalBoundsInParent(a, parent).left - getLocalBoundsInParent(b, parent).left
|
|
222
|
-
);
|
|
223
|
-
if (sorted.length <= 2) return;
|
|
224
|
-
const first = getLocalBoundsInParent(sorted[0], parent).left;
|
|
225
|
-
const last = getLocalBoundsInParent(sorted[sorted.length - 1], parent).left;
|
|
226
|
-
const step = (last - first) / (sorted.length - 1);
|
|
227
|
-
sorted.forEach((it, i) => {
|
|
228
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
229
|
-
nudgeX(it, first + step * i - b.left);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
static hCenters(items, options) {
|
|
233
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
234
|
-
const sorted = [...items].sort(
|
|
235
|
-
(a, b) => getLocalBoundsInParent(a, parent).centerX - getLocalBoundsInParent(b, parent).centerX
|
|
236
|
-
);
|
|
237
|
-
if (sorted.length <= 2) return;
|
|
238
|
-
const first = getLocalBoundsInParent(sorted[0], parent).centerX;
|
|
239
|
-
const last = getLocalBoundsInParent(sorted[sorted.length - 1], parent).centerX;
|
|
240
|
-
const step = (last - first) / (sorted.length - 1);
|
|
241
|
-
sorted.forEach((it, i) => {
|
|
242
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
243
|
-
nudgeX(it, first + step * i - b.centerX);
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
static hRight(items, options) {
|
|
247
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
248
|
-
const sorted = [...items].sort(
|
|
249
|
-
(a, b) => getLocalBoundsInParent(a, parent).right - getLocalBoundsInParent(b, parent).right
|
|
250
|
-
);
|
|
251
|
-
if (sorted.length <= 2) return;
|
|
252
|
-
const first = getLocalBoundsInParent(sorted[0], parent).right;
|
|
253
|
-
const last = getLocalBoundsInParent(sorted[sorted.length - 1], parent).right;
|
|
254
|
-
const step = (last - first) / (sorted.length - 1);
|
|
255
|
-
sorted.forEach((it, i) => {
|
|
256
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
257
|
-
nudgeX(it, first + step * i - b.right);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
static vTop(items, options) {
|
|
261
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
262
|
-
const sorted = [...items].sort(
|
|
263
|
-
(a, b) => getLocalBoundsInParent(a, parent).top - getLocalBoundsInParent(b, parent).top
|
|
264
|
-
);
|
|
265
|
-
if (sorted.length <= 2) return;
|
|
266
|
-
const first = getLocalBoundsInParent(sorted[0], parent).top;
|
|
267
|
-
const last = getLocalBoundsInParent(sorted[sorted.length - 1], parent).top;
|
|
268
|
-
const step = (last - first) / (sorted.length - 1);
|
|
269
|
-
sorted.forEach((it, i) => {
|
|
270
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
271
|
-
nudgeY(it, first + step * i - b.top);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
static vCenters(items, options) {
|
|
275
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
276
|
-
const sorted = [...items].sort(
|
|
277
|
-
(a, b) => getLocalBoundsInParent(a, parent).centerY - getLocalBoundsInParent(b, parent).centerY
|
|
278
|
-
);
|
|
279
|
-
if (sorted.length <= 2) return;
|
|
280
|
-
const first = getLocalBoundsInParent(sorted[0], parent).centerY;
|
|
281
|
-
const last = getLocalBoundsInParent(sorted[sorted.length - 1], parent).centerY;
|
|
282
|
-
const step = (last - first) / (sorted.length - 1);
|
|
283
|
-
sorted.forEach((it, i) => {
|
|
284
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
285
|
-
nudgeY(it, first + step * i - b.centerY);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
static vBottom(items, options) {
|
|
289
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
290
|
-
const sorted = [...items].sort(
|
|
291
|
-
(a, b) => getLocalBoundsInParent(a, parent).bottom - getLocalBoundsInParent(b, parent).bottom
|
|
292
|
-
);
|
|
293
|
-
if (sorted.length <= 2) return;
|
|
294
|
-
const first = getLocalBoundsInParent(sorted[0], parent).bottom;
|
|
295
|
-
const last = getLocalBoundsInParent(sorted[sorted.length - 1], parent).bottom;
|
|
296
|
-
const step = (last - first) / (sorted.length - 1);
|
|
297
|
-
sorted.forEach((it, i) => {
|
|
298
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
299
|
-
nudgeY(it, first + step * i - b.bottom);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
static hSpacing(items, options) {
|
|
303
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
304
|
-
if (items.length <= 2) return;
|
|
305
|
-
const sorted = [...items].sort(
|
|
306
|
-
(a, b) => getLocalBoundsInParent(a, parent).left - getLocalBoundsInParent(b, parent).left
|
|
307
|
-
);
|
|
308
|
-
const ref = (options == null ? void 0 : options.container) ?? getSelectionBounds(sorted, parent);
|
|
309
|
-
const totalWidth = sorted.reduce(
|
|
310
|
-
(sum, it) => sum + getLocalBoundsInParent(it, parent).width,
|
|
311
|
-
0
|
|
312
|
-
);
|
|
313
|
-
const width = ref instanceof Rectangle ? ref.width : ref.width;
|
|
314
|
-
const left = ref instanceof Rectangle ? ref.x : ref.left;
|
|
315
|
-
const gap = (width - totalWidth) / (sorted.length - 1);
|
|
316
|
-
let cursor = left;
|
|
317
|
-
sorted.forEach((it) => {
|
|
318
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
319
|
-
nudgeX(it, cursor - b.left);
|
|
320
|
-
const newB = getLocalBoundsInParent(it, parent);
|
|
321
|
-
cursor = newB.right + gap;
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
static vSpacing(items, options) {
|
|
325
|
-
const parent = (options == null ? void 0 : options.parent) ?? getCommonParent(items);
|
|
326
|
-
if (items.length <= 2) return;
|
|
327
|
-
const sorted = [...items].sort(
|
|
328
|
-
(a, b) => getLocalBoundsInParent(a, parent).top - getLocalBoundsInParent(b, parent).top
|
|
329
|
-
);
|
|
330
|
-
const ref = (options == null ? void 0 : options.container) ?? getSelectionBounds(sorted, parent);
|
|
331
|
-
const totalHeight = sorted.reduce(
|
|
332
|
-
(sum, it) => sum + getLocalBoundsInParent(it, parent).height,
|
|
333
|
-
0
|
|
334
|
-
);
|
|
335
|
-
const height = ref instanceof Rectangle ? ref.height : ref.height;
|
|
336
|
-
const top = ref instanceof Rectangle ? ref.y : ref.top;
|
|
337
|
-
const gap = (height - totalHeight) / (sorted.length - 1);
|
|
338
|
-
let cursor = top;
|
|
339
|
-
sorted.forEach((it) => {
|
|
340
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
341
|
-
nudgeY(it, cursor - b.top);
|
|
342
|
-
const newB = getLocalBoundsInParent(it, parent);
|
|
343
|
-
cursor = newB.bottom + gap;
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
function normalizeGap(opts) {
|
|
348
|
-
if (typeof opts.gap === "number") return { h: opts.gap, v: opts.gap };
|
|
349
|
-
if (typeof opts.gap === "object" && opts.gap) return { h: opts.gap.h ?? 0, v: opts.gap.v ?? 0 };
|
|
350
|
-
const h = opts.columnGap ?? 0;
|
|
351
|
-
const v = opts.rowGap ?? 0;
|
|
352
|
-
return { h, v };
|
|
353
|
-
}
|
|
354
|
-
function normalizePadding(p) {
|
|
355
|
-
if (typeof p === "number") return { top: p, right: p, bottom: p, left: p };
|
|
356
|
-
return { top: (p == null ? void 0 : p.top) ?? 0, right: (p == null ? void 0 : p.right) ?? 0, bottom: (p == null ? void 0 : p.bottom) ?? 0, left: (p == null ? void 0 : p.left) ?? 0 };
|
|
357
|
-
}
|
|
358
|
-
function normalizeMargin(value) {
|
|
359
|
-
if (value === void 0) {
|
|
360
|
-
return { top: 0, right: 0, bottom: 0, left: 0 };
|
|
361
|
-
}
|
|
362
|
-
if (typeof value === "number") {
|
|
363
|
-
return { top: value, right: value, bottom: value, left: value };
|
|
364
|
-
}
|
|
365
|
-
const top = value.top ?? value.y ?? 0;
|
|
366
|
-
const bottom = value.bottom ?? value.y ?? 0;
|
|
367
|
-
const left = value.left ?? value.x ?? 0;
|
|
368
|
-
const right = value.right ?? value.x ?? 0;
|
|
369
|
-
return { top, right, bottom, left };
|
|
370
|
-
}
|
|
371
|
-
function getFlowBounds(items, opts, parent) {
|
|
372
|
-
const pad = normalizePadding(opts.padding);
|
|
373
|
-
if (opts.wrap === "bounds" && opts.bounds) {
|
|
374
|
-
let r;
|
|
375
|
-
if (opts.bounds instanceof Rectangle) {
|
|
376
|
-
r = opts.bounds;
|
|
377
|
-
} else {
|
|
378
|
-
const b = getLocalBoundsInParent(opts.bounds, parent);
|
|
379
|
-
r = new Rectangle(b.left, b.top, b.width, b.height);
|
|
380
|
-
}
|
|
381
|
-
return new Rectangle(
|
|
382
|
-
r.x + pad.left,
|
|
383
|
-
r.y + pad.top,
|
|
384
|
-
Math.max(0, r.width - pad.left - pad.right),
|
|
385
|
-
Math.max(0, r.height - pad.top - pad.bottom)
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
const sel = getSelectionBounds(items, parent);
|
|
389
|
-
return new Rectangle(
|
|
390
|
-
// TODO Not sure side effects check this out latter
|
|
391
|
-
/*sel.left +*/
|
|
392
|
-
pad.left,
|
|
393
|
-
/*sel.top + */
|
|
394
|
-
pad.top,
|
|
395
|
-
Math.max(0, sel.width - pad.left - pad.right),
|
|
396
|
-
Math.max(0, sel.height - pad.top - pad.bottom)
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
var Flow = class {
|
|
400
|
-
/**
|
|
401
|
-
* Arranges containers in a flexbox-like layout.
|
|
402
|
-
*
|
|
403
|
-
* This method modifies container positions in-place to create the desired layout.
|
|
404
|
-
* Items are sorted (if order function provided) and then arranged according to
|
|
405
|
-
* direction, wrapping, alignment, and justification settings.
|
|
406
|
-
*
|
|
407
|
-
* @param items - Array of containers to layout
|
|
408
|
-
* @param options - Layout configuration options
|
|
409
|
-
*
|
|
410
|
-
* @example
|
|
411
|
-
* ```typescript
|
|
412
|
-
* // Simple horizontal row
|
|
413
|
-
* Flow.layout(items, { direction: 'row', gap: 10 });
|
|
414
|
-
*
|
|
415
|
-
* // Grid with 4 columns
|
|
416
|
-
* Flow.layout(items, {
|
|
417
|
-
* direction: 'row',
|
|
418
|
-
* wrap: 'count',
|
|
419
|
-
* columnCount: 4,
|
|
420
|
-
* gap: { h: 10, v: 15 }
|
|
421
|
-
* });
|
|
422
|
-
*
|
|
423
|
-
* // Centered vertical list
|
|
424
|
-
* Flow.layout(items, {
|
|
425
|
-
* direction: 'column',
|
|
426
|
-
* align: 'center',
|
|
427
|
-
* gap: 20
|
|
428
|
-
* });
|
|
429
|
-
* ```
|
|
430
|
-
*/
|
|
431
|
-
static layout(items, options) {
|
|
432
|
-
if (!items || items.length === 0) return;
|
|
433
|
-
const opts = {
|
|
434
|
-
direction: "row",
|
|
435
|
-
wrap: "none",
|
|
436
|
-
gap: 0,
|
|
437
|
-
justify: "start",
|
|
438
|
-
align: "start",
|
|
439
|
-
...options
|
|
440
|
-
};
|
|
441
|
-
const parent = getCommonParent(items);
|
|
442
|
-
const gap = normalizeGap(opts);
|
|
443
|
-
const dir = opts.direction ?? "row";
|
|
444
|
-
const wrap = opts.wrap ?? "none";
|
|
445
|
-
const ordered = opts.order ? [...items].sort(opts.order) : [...items];
|
|
446
|
-
const area = getFlowBounds(ordered, opts, parent);
|
|
447
|
-
if (wrap === "count") {
|
|
448
|
-
if (dir === "row") {
|
|
449
|
-
const cols = opts.columnCount ?? (opts.rowCount ? Math.ceil(ordered.length / opts.rowCount) : ordered.length);
|
|
450
|
-
const lines = [];
|
|
451
|
-
for (let i = 0; i < ordered.length; i += cols) lines.push(ordered.slice(i, i + cols));
|
|
452
|
-
layoutLinesRow(lines, parent, area, gap, opts.justify, opts.align, opts.margins);
|
|
453
|
-
} else {
|
|
454
|
-
const rows = opts.rowCount ?? (opts.columnCount ? Math.ceil(ordered.length / opts.columnCount) : ordered.length);
|
|
455
|
-
const columns = [];
|
|
456
|
-
for (let i = 0; i < ordered.length; i += rows) columns.push(ordered.slice(i, i + rows));
|
|
457
|
-
layoutLinesColumn(columns, parent, area, gap, opts.justify, opts.align, opts.margins);
|
|
458
|
-
}
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
if (wrap === "bounds") {
|
|
462
|
-
if (dir === "row") {
|
|
463
|
-
const lines = [];
|
|
464
|
-
let line = [];
|
|
465
|
-
let lineW = 0;
|
|
466
|
-
for (const it of ordered) {
|
|
467
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
468
|
-
const needed = line.length === 0 ? b.width : gap.h + b.width;
|
|
469
|
-
if (line.length > 0 && lineW + needed > area.width) {
|
|
470
|
-
lines.push(line);
|
|
471
|
-
line = [it];
|
|
472
|
-
lineW = b.width;
|
|
473
|
-
} else {
|
|
474
|
-
line.push(it);
|
|
475
|
-
lineW += needed;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
if (line.length) lines.push(line);
|
|
479
|
-
layoutLinesRow(lines, parent, area, gap, opts.justify, opts.align, opts.margins);
|
|
480
|
-
} else {
|
|
481
|
-
const columns = [];
|
|
482
|
-
let col = [];
|
|
483
|
-
let colH = 0;
|
|
484
|
-
for (const it of ordered) {
|
|
485
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
486
|
-
const needed = col.length === 0 ? b.height : gap.v + b.height;
|
|
487
|
-
if (col.length > 0 && colH + needed > area.height) {
|
|
488
|
-
columns.push(col);
|
|
489
|
-
col = [it];
|
|
490
|
-
colH = b.height;
|
|
491
|
-
} else {
|
|
492
|
-
col.push(it);
|
|
493
|
-
colH += needed;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
if (col.length) columns.push(col);
|
|
497
|
-
layoutLinesColumn(columns, parent, area, gap, opts.justify, opts.align, opts.margins);
|
|
498
|
-
}
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
if (wrap === "none") {
|
|
502
|
-
if (dir === "row") {
|
|
503
|
-
const lines = [ordered];
|
|
504
|
-
layoutLinesRow(lines, parent, area, gap, opts.justify, opts.align, opts.margins);
|
|
505
|
-
} else {
|
|
506
|
-
const columns = [ordered];
|
|
507
|
-
layoutLinesColumn(columns, parent, area, gap, opts.justify, opts.align, opts.margins);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
function layoutLinesRow(lines, parent, area, gap, justify, align, margins) {
|
|
513
|
-
let y = area.y;
|
|
514
|
-
for (const line of lines) {
|
|
515
|
-
let contentW = 0;
|
|
516
|
-
let lineH = 0;
|
|
517
|
-
const sizes = line.map((it) => {
|
|
518
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
519
|
-
lineH = Math.max(lineH, b.height);
|
|
520
|
-
return b;
|
|
521
|
-
});
|
|
522
|
-
if (line.length > 0) contentW = sizes.reduce((s, b, i) => s + b.width + (i > 0 ? gap.h : 0), 0);
|
|
523
|
-
let x = area.x;
|
|
524
|
-
if (justify === "center") {
|
|
525
|
-
x += Math.max(0, (area.width - contentW) / 2);
|
|
526
|
-
} else if (justify === "end") {
|
|
527
|
-
x += Math.max(0, area.width - contentW);
|
|
528
|
-
} else if (justify === "space-between" && line.length > 1) {
|
|
529
|
-
const free = Math.max(0, area.width - sizes.reduce((s, b) => s + b.width, 0));
|
|
530
|
-
const g = free / (line.length - 1);
|
|
531
|
-
positionRow(line, sizes, parent, x, y, lineH, { h: g, v: gap.v }, align, margins);
|
|
532
|
-
y += lineH + gap.v;
|
|
533
|
-
continue;
|
|
534
|
-
} else if (justify === "space-around" && line.length > 0) {
|
|
535
|
-
const free = Math.max(0, area.width - sizes.reduce((s, b) => s + b.width, 0));
|
|
536
|
-
const g = free / line.length;
|
|
537
|
-
x += g / 2;
|
|
538
|
-
positionRow(line, sizes, parent, x, y, lineH, { h: g, v: gap.v }, align, margins);
|
|
539
|
-
y += lineH + gap.v;
|
|
540
|
-
continue;
|
|
541
|
-
} else if (justify === "space-evenly" && line.length > 0) {
|
|
542
|
-
const free = Math.max(0, area.width - sizes.reduce((s, b) => s + b.width, 0));
|
|
543
|
-
const g = free / (line.length + 1);
|
|
544
|
-
x += g;
|
|
545
|
-
positionRow(line, sizes, parent, x, y, lineH, { h: g, v: gap.v }, align, margins);
|
|
546
|
-
y += lineH + gap.v;
|
|
547
|
-
continue;
|
|
548
|
-
}
|
|
549
|
-
positionRow(line, sizes, parent, x, y, lineH, gap, align, margins);
|
|
550
|
-
y += lineH + gap.v;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
function positionRow(line, sizes, parent, x, y, lineH, gap, align, margins) {
|
|
554
|
-
let cursor = x;
|
|
555
|
-
for (let i = 0; i < line.length; i++) {
|
|
556
|
-
const it = line[i];
|
|
557
|
-
const b = sizes[i];
|
|
558
|
-
const margin = normalizeMargin(margins == null ? void 0 : margins[i]);
|
|
559
|
-
const dx = cursor + margin.left - b.left;
|
|
560
|
-
let dy = 0;
|
|
561
|
-
if (align === "start") dy = y + margin.top - b.top;
|
|
562
|
-
else if (align === "center") dy = y + margin.top + (lineH - b.height) / 2 - b.top;
|
|
563
|
-
else dy = y + margin.top + (lineH - b.height) - b.top;
|
|
564
|
-
nudgeX(it, dx);
|
|
565
|
-
nudgeY(it, dy);
|
|
566
|
-
cursor += margin.left + b.width + margin.right + gap.h;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
function layoutLinesColumn(columns, parent, area, gap, justify, align, margins) {
|
|
570
|
-
let x = area.x;
|
|
571
|
-
for (const col of columns) {
|
|
572
|
-
let contentH = 0;
|
|
573
|
-
let colW = 0;
|
|
574
|
-
const sizes = col.map((it) => {
|
|
575
|
-
const b = getLocalBoundsInParent(it, parent);
|
|
576
|
-
colW = Math.max(colW, b.width);
|
|
577
|
-
return b;
|
|
578
|
-
});
|
|
579
|
-
if (col.length > 0) contentH = sizes.reduce((s, b, i) => s + b.height + (i > 0 ? gap.v : 0), 0);
|
|
580
|
-
let y = area.y;
|
|
581
|
-
if (justify === "center") {
|
|
582
|
-
y += Math.max(0, (area.height - contentH) / 2);
|
|
583
|
-
} else if (justify === "end") {
|
|
584
|
-
y += Math.max(0, area.height - contentH);
|
|
585
|
-
} else if (justify === "space-between" && col.length > 1) {
|
|
586
|
-
const free = Math.max(0, area.height - sizes.reduce((s, b) => s + b.height, 0));
|
|
587
|
-
const g = free / (col.length - 1);
|
|
588
|
-
positionColumn(col, sizes, parent, x, y, colW, { h: gap.h, v: g }, align, margins);
|
|
589
|
-
x += colW + gap.h;
|
|
590
|
-
continue;
|
|
591
|
-
} else if (justify === "space-around" && col.length > 0) {
|
|
592
|
-
const free = Math.max(0, area.height - sizes.reduce((s, b) => s + b.height, 0));
|
|
593
|
-
const g = free / col.length;
|
|
594
|
-
y += g / 2;
|
|
595
|
-
positionColumn(col, sizes, parent, x, y, colW, { h: gap.h, v: g }, align, margins);
|
|
596
|
-
x += colW + gap.h;
|
|
597
|
-
continue;
|
|
598
|
-
} else if (justify === "space-evenly" && col.length > 0) {
|
|
599
|
-
const free = Math.max(0, area.height - sizes.reduce((s, b) => s + b.height, 0));
|
|
600
|
-
const g = free / (col.length + 1);
|
|
601
|
-
y += g;
|
|
602
|
-
positionColumn(col, sizes, parent, x, y, colW, { h: gap.h, v: g }, align, margins);
|
|
603
|
-
x += colW + gap.h;
|
|
604
|
-
continue;
|
|
605
|
-
}
|
|
606
|
-
positionColumn(col, sizes, parent, x, y, colW, gap, align, margins);
|
|
607
|
-
x += colW + gap.h;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
function positionColumn(col, sizes, parent, x, y, colW, gap, align, margins) {
|
|
611
|
-
let cursor = y;
|
|
612
|
-
for (let i = 0; i < col.length; i++) {
|
|
613
|
-
const it = col[i];
|
|
614
|
-
const b = sizes[i];
|
|
615
|
-
const margin = normalizeMargin(margins == null ? void 0 : margins[i]);
|
|
616
|
-
let dx = 0;
|
|
617
|
-
if (align === "start") dx = x + margin.left - b.left;
|
|
618
|
-
else if (align === "center") dx = x + margin.left + (colW - b.width) / 2 - b.left;
|
|
619
|
-
else dx = x + margin.left + (colW - b.width) - b.left;
|
|
620
|
-
const dy = cursor + margin.top - b.top;
|
|
621
|
-
nudgeX(it, dx);
|
|
622
|
-
nudgeY(it, dy);
|
|
623
|
-
cursor += margin.top + b.height + margin.bottom + gap.v;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// layout/PositionUtils.ts
|
|
628
|
-
function resolvePositionValue(value, axis, viewportSize, sourceScaledSize) {
|
|
629
|
-
if (typeof value === "number") {
|
|
630
|
-
return value;
|
|
631
|
-
}
|
|
632
|
-
const trimmed = value.trim();
|
|
633
|
-
if (trimmed.endsWith("%")) {
|
|
634
|
-
const percent = parseFloat(trimmed) / 100;
|
|
635
|
-
return viewportSize * percent - sourceScaledSize * percent;
|
|
636
|
-
}
|
|
637
|
-
switch (trimmed) {
|
|
638
|
-
case "center":
|
|
639
|
-
return (viewportSize - sourceScaledSize) / 2;
|
|
640
|
-
case "top":
|
|
641
|
-
return axis === "y" ? 0 : (viewportSize - sourceScaledSize) / 2;
|
|
642
|
-
case "bottom":
|
|
643
|
-
return axis === "y" ? viewportSize - sourceScaledSize : (viewportSize - sourceScaledSize) / 2;
|
|
644
|
-
case "left":
|
|
645
|
-
return axis === "x" ? 0 : (viewportSize - sourceScaledSize) / 2;
|
|
646
|
-
case "right":
|
|
647
|
-
return axis === "x" ? viewportSize - sourceScaledSize : (viewportSize - sourceScaledSize) / 2;
|
|
648
|
-
default:
|
|
649
|
-
const num = parseFloat(trimmed);
|
|
650
|
-
return isNaN(num) ? 0 : num;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
function resolvePosition(position, viewportWidth, viewportHeight, sourceScaledWidth, sourceScaledHeight) {
|
|
654
|
-
if (typeof position === "number") {
|
|
655
|
-
return { x: position, y: position };
|
|
656
|
-
}
|
|
657
|
-
const parts = position.trim().split(/\s+/);
|
|
658
|
-
if (parts.length === 1) {
|
|
659
|
-
const val = parts[0];
|
|
660
|
-
return {
|
|
661
|
-
x: resolvePositionValue(val, "x", viewportWidth, sourceScaledWidth),
|
|
662
|
-
y: resolvePositionValue(val, "y", viewportHeight, sourceScaledHeight)
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
return {
|
|
666
|
-
x: resolvePositionValue(parts[0], "x", viewportWidth, sourceScaledWidth),
|
|
667
|
-
y: resolvePositionValue(parts[1], "y", viewportHeight, sourceScaledHeight)
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
export { Align, Distribute, Flow, getCommonParent, getLocalBoundsInParent, getReferenceBounds, getSelectionBounds, nudgeX, nudgeY, resolvePosition, resolvePositionValue };
|
|
1
|
+
export { Align, Distribute, Flow, getCommonParent, getLocalBoundsInParent, getReferenceBounds, getSelectionBounds, nudgeX, nudgeY, resolvePosition, resolvePositionValue } from '../chunk-FOZO6TLY.js';
|
|
2
|
+
import '../chunk-G3PMV62Z.js';
|
|
672
3
|
//# sourceMappingURL=index.js.map
|
|
673
4
|
//# sourceMappingURL=index.js.map
|