@drawback/ui 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/README.md +22 -2
- package/dist/i18n-BZnCrD-C.d.mts +265 -0
- package/dist/index.d.mts +588 -0
- package/dist/index.mjs +4821 -0
- package/dist/locales/de.d.mts +3 -0
- package/dist/locales/de.mjs +231 -0
- package/package.json +69 -4
- package/src/app/default-editor.tsx +371 -0
- package/src/components/color-picker/color-picker.tsx +341 -0
- package/src/components/color-picker/colors.ts +135 -0
- package/src/components/font-picker/font-picker.tsx +298 -0
- package/src/components/icons.tsx +222 -0
- package/src/components/primitives.tsx +565 -0
- package/src/components/style-icons.tsx +172 -0
- package/src/features/canvas-commands/canvas-commands.tsx +173 -0
- package/src/features/context-menu/context-menu.tsx +354 -0
- package/src/features/controls/controls.tsx +281 -0
- package/src/features/export/export-dialog.tsx +164 -0
- package/src/features/layers/layers-tree.ts +335 -0
- package/src/features/layers/layers.tsx +858 -0
- package/src/features/links/links.tsx +268 -0
- package/src/features/main-menu/canvas-properties.tsx +121 -0
- package/src/features/main-menu/main-menu.tsx +215 -0
- package/src/features/minimap/minimap.tsx +69 -0
- package/src/features/properties/linear-properties.tsx +169 -0
- package/src/features/properties/properties.tsx +573 -0
- package/src/features/shortcuts/shortcuts-dialog.tsx +120 -0
- package/src/features/toolbar/toolbar.tsx +216 -0
- package/src/hooks/use-latest.ts +16 -0
- package/src/index.ts +138 -0
- package/src/lib/commands.ts +14 -0
- package/src/lib/download.ts +8 -0
- package/src/lib/i18n.ts +350 -0
- package/src/lib/locales/de.ts +231 -0
- package/src/lib/plugins.tsx +92 -0
- package/src/lib/registry.ts +140 -0
- package/src/stores/ui-context.tsx +253 -0
- package/src/styles.css +1366 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyEditor,
|
|
3
|
+
ElementId,
|
|
4
|
+
ElementRecord,
|
|
5
|
+
GroupId,
|
|
6
|
+
GroupRecord,
|
|
7
|
+
LayerId,
|
|
8
|
+
LayerRecord,
|
|
9
|
+
} from '@drawback/core';
|
|
10
|
+
|
|
11
|
+
interface RowBase {
|
|
12
|
+
/** Stable key, also used for expansion state. */
|
|
13
|
+
readonly key: string;
|
|
14
|
+
readonly depth: number;
|
|
15
|
+
readonly expandable: boolean;
|
|
16
|
+
readonly expanded: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface LayerRow extends RowBase {
|
|
20
|
+
readonly kind: 'layer';
|
|
21
|
+
readonly record: LayerRecord;
|
|
22
|
+
readonly active: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface GroupRow extends RowBase {
|
|
26
|
+
readonly kind: 'group';
|
|
27
|
+
readonly record: GroupRecord;
|
|
28
|
+
readonly layerId: LayerId;
|
|
29
|
+
readonly members: readonly ElementId[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ElementRow extends RowBase {
|
|
33
|
+
readonly kind: 'element';
|
|
34
|
+
readonly record: ElementRecord;
|
|
35
|
+
readonly label: string;
|
|
36
|
+
readonly icon: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type TreeRow = LayerRow | GroupRow | ElementRow;
|
|
40
|
+
|
|
41
|
+
export interface LayerTreeSource {
|
|
42
|
+
readonly layers: readonly {
|
|
43
|
+
readonly layer: LayerRecord;
|
|
44
|
+
readonly children: readonly LayerTreeSourceNode[];
|
|
45
|
+
}[];
|
|
46
|
+
readonly activeLayer: LayerId | undefined;
|
|
47
|
+
/** Elements of a layer from top to bottom. */
|
|
48
|
+
elementsOf(layerId: LayerId): readonly ElementRecord[];
|
|
49
|
+
/** Group chain of an element, innermost first. */
|
|
50
|
+
groupsOf(elementId: ElementId): readonly GroupId[];
|
|
51
|
+
group(id: GroupId): GroupRecord | undefined;
|
|
52
|
+
describe(element: ElementRecord): { readonly label: string; readonly icon: string };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface LayerTreeSourceNode {
|
|
56
|
+
readonly layer: LayerRecord;
|
|
57
|
+
readonly children: readonly LayerTreeSourceNode[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface BuildOptions {
|
|
61
|
+
/** Keys of expanded rows; layers are expanded unless listed in `collapsed`. */
|
|
62
|
+
readonly expanded: ReadonlySet<string>;
|
|
63
|
+
readonly collapsed: ReadonlySet<string>;
|
|
64
|
+
/** Case-insensitive name filter; matching rows and their parents stay visible and expanded. */
|
|
65
|
+
readonly query?: string;
|
|
66
|
+
readonly type?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type RowData<Row> = Row extends TreeRow ? Omit<Row, 'depth' | 'expanded' | 'expandable'> : never;
|
|
70
|
+
|
|
71
|
+
interface Node {
|
|
72
|
+
readonly row: RowData<TreeRow>;
|
|
73
|
+
readonly children: Node[];
|
|
74
|
+
readonly matches: boolean;
|
|
75
|
+
/** Has element rows that were not built because the layer is collapsed. */
|
|
76
|
+
readonly hasMore?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const layerKey = (id: LayerId): string => `layer:${id}`;
|
|
80
|
+
export const groupKey = (layerId: LayerId, id: GroupId): string => `group:${layerId}:${id}`;
|
|
81
|
+
export const elementKey = (id: ElementId): string => `element:${id}`;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Flattens layers (top layer first), groups and elements (topmost first) into visible rows.
|
|
85
|
+
* A group appears in each layer that holds some of its members, at its topmost member.
|
|
86
|
+
*/
|
|
87
|
+
export function buildLayerRows(source: LayerTreeSource, options: BuildOptions): TreeRow[] {
|
|
88
|
+
const query = options.query?.trim().toLowerCase() ?? '';
|
|
89
|
+
const filtering = query !== '' || options.type !== undefined;
|
|
90
|
+
const matchesText = (text: string | undefined): boolean =>
|
|
91
|
+
query === '' || (text ?? '').toLowerCase().includes(query);
|
|
92
|
+
|
|
93
|
+
const buildLayer = (node: LayerTreeSourceNode): Node => {
|
|
94
|
+
const layer = node.layer;
|
|
95
|
+
const children: Node[] = [...node.children].reverse().map(buildLayer);
|
|
96
|
+
const groupNodes = new Map<GroupId, Node & { readonly members: ElementId[] }>();
|
|
97
|
+
// A collapsed layer shows no element rows: skip describing its elements unless searching.
|
|
98
|
+
const skipElements = !filtering && options.collapsed.has(layerKey(layer.id));
|
|
99
|
+
const elements = skipElements ? [] : source.elementsOf(layer.id);
|
|
100
|
+
|
|
101
|
+
for (const element of elements) {
|
|
102
|
+
const description = source.describe(element);
|
|
103
|
+
const matches =
|
|
104
|
+
matchesText(description.label) &&
|
|
105
|
+
(options.type === undefined || element.type === options.type);
|
|
106
|
+
let parent: Node[] = children;
|
|
107
|
+
const chain = [...source.groupsOf(element.id)].reverse();
|
|
108
|
+
|
|
109
|
+
for (const groupId of chain) {
|
|
110
|
+
let groupNode = groupNodes.get(groupId);
|
|
111
|
+
|
|
112
|
+
if (groupNode === undefined) {
|
|
113
|
+
const record = source.group(groupId);
|
|
114
|
+
|
|
115
|
+
if (record === undefined) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const members: ElementId[] = [];
|
|
120
|
+
const created = {
|
|
121
|
+
row: {
|
|
122
|
+
kind: 'group' as const,
|
|
123
|
+
key: groupKey(layer.id, groupId),
|
|
124
|
+
record,
|
|
125
|
+
layerId: layer.id,
|
|
126
|
+
members,
|
|
127
|
+
},
|
|
128
|
+
children: [],
|
|
129
|
+
matches: query !== '' && matchesText(record.name),
|
|
130
|
+
members,
|
|
131
|
+
};
|
|
132
|
+
groupNodes.set(groupId, created);
|
|
133
|
+
parent.push(created);
|
|
134
|
+
groupNode = created;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
groupNode.members.push(element.id);
|
|
138
|
+
parent = groupNode.children;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
parent.push({
|
|
142
|
+
row: {
|
|
143
|
+
kind: 'element',
|
|
144
|
+
key: elementKey(element.id),
|
|
145
|
+
record: element,
|
|
146
|
+
label: description.label,
|
|
147
|
+
icon: description.icon,
|
|
148
|
+
},
|
|
149
|
+
children: [],
|
|
150
|
+
matches,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
row: {
|
|
156
|
+
kind: 'layer',
|
|
157
|
+
key: layerKey(layer.id),
|
|
158
|
+
record: layer,
|
|
159
|
+
active: layer.id === source.activeLayer,
|
|
160
|
+
},
|
|
161
|
+
children,
|
|
162
|
+
matches: query !== '' && options.type === undefined && matchesText(layer.name),
|
|
163
|
+
...(skipElements && source.elementsOf(layer.id).length > 0 ? { hasMore: true } : {}),
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const visible = (node: Node): boolean =>
|
|
168
|
+
!filtering || node.matches || node.children.some(visible);
|
|
169
|
+
|
|
170
|
+
const rows: TreeRow[] = [];
|
|
171
|
+
const flatten = (node: Node, depth: number): void => {
|
|
172
|
+
if (!visible(node)) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const expandable = node.children.length > 0 || node.hasMore === true;
|
|
177
|
+
const key = node.row.key;
|
|
178
|
+
const expanded =
|
|
179
|
+
expandable &&
|
|
180
|
+
(filtering ||
|
|
181
|
+
(node.row.kind === 'layer' ? !options.collapsed.has(key) : options.expanded.has(key)));
|
|
182
|
+
rows.push({ ...node.row, depth, expandable, expanded } as TreeRow);
|
|
183
|
+
|
|
184
|
+
if (expanded) {
|
|
185
|
+
for (const child of node.children) {
|
|
186
|
+
flatten(child, depth + 1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
for (const node of [...source.layers].reverse().map(buildLayer)) {
|
|
192
|
+
flatten(node, 0);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return rows;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface ActiveGuide {
|
|
199
|
+
/** Depth of the row whose children the guide connects. */
|
|
200
|
+
readonly level: number;
|
|
201
|
+
readonly start: number;
|
|
202
|
+
readonly end: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The indent guide to emphasize for the row at `anchor`: its own children when it is expanded,
|
|
207
|
+
* otherwise its siblings under the parent row. `end` is exclusive.
|
|
208
|
+
*/
|
|
209
|
+
export function activeGuide(rows: readonly TreeRow[], anchor: number): ActiveGuide | undefined {
|
|
210
|
+
const row = rows[anchor];
|
|
211
|
+
|
|
212
|
+
if (row === undefined) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let parent = anchor;
|
|
217
|
+
|
|
218
|
+
if (!row.expandable || !row.expanded) {
|
|
219
|
+
do {
|
|
220
|
+
parent -= 1;
|
|
221
|
+
} while (parent >= 0 && (rows[parent]?.depth ?? 0) >= row.depth);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const level = rows[parent]?.depth;
|
|
225
|
+
|
|
226
|
+
if (level === undefined) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let end = parent + 1;
|
|
231
|
+
|
|
232
|
+
while (end < rows.length && (rows[end]?.depth ?? 0) > level) {
|
|
233
|
+
end += 1;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return end > parent + 1 ? { level, start: parent + 1, end } : undefined;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface StickyRow {
|
|
240
|
+
readonly index: number;
|
|
241
|
+
/** Offset from the top of the viewport; pushed up by the layer's last row so it never covers it. */
|
|
242
|
+
readonly top: number;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Expanded layer rows pinned to the top of the viewport while their contents scroll past,
|
|
247
|
+
* outermost first. `padding` is the space above the first row.
|
|
248
|
+
*/
|
|
249
|
+
export function stickyRows(
|
|
250
|
+
rows: readonly TreeRow[],
|
|
251
|
+
scrollTop: number,
|
|
252
|
+
rowStride: number,
|
|
253
|
+
padding = 0,
|
|
254
|
+
): StickyRow[] {
|
|
255
|
+
const content = scrollTop - padding;
|
|
256
|
+
const result: StickyRow[] = [];
|
|
257
|
+
|
|
258
|
+
while (content > 0) {
|
|
259
|
+
const depth = result.length;
|
|
260
|
+
const probe = Math.floor((content + depth * rowStride) / rowStride);
|
|
261
|
+
let index = Math.min(probe, rows.length - 1);
|
|
262
|
+
|
|
263
|
+
while (index >= 0 && (rows[index]?.depth ?? 0) > depth) {
|
|
264
|
+
index -= 1;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const row = rows[index];
|
|
268
|
+
|
|
269
|
+
if (
|
|
270
|
+
row === undefined ||
|
|
271
|
+
row.kind !== 'layer' ||
|
|
272
|
+
row.depth !== depth ||
|
|
273
|
+
!row.expanded ||
|
|
274
|
+
index * rowStride >= content + depth * rowStride
|
|
275
|
+
) {
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let end = index + 1;
|
|
280
|
+
|
|
281
|
+
while (end < rows.length && (rows[end]?.depth ?? 0) > depth) {
|
|
282
|
+
end += 1;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const top = Math.min(depth * rowStride, (end - 2) * rowStride - content);
|
|
286
|
+
|
|
287
|
+
if (end === index + 1 || probe >= end || top + rowStride <= depth * rowStride) {
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
result.push({ index, top });
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Index range of rows to render for a scroll position (inclusive start, exclusive end). */
|
|
298
|
+
export function visibleRange(
|
|
299
|
+
scrollTop: number,
|
|
300
|
+
viewportHeight: number,
|
|
301
|
+
rowHeight: number,
|
|
302
|
+
count: number,
|
|
303
|
+
overscan = 6,
|
|
304
|
+
): { readonly start: number; readonly end: number } {
|
|
305
|
+
const start = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan);
|
|
306
|
+
const end = Math.min(count, Math.ceil((scrollTop + viewportHeight) / rowHeight) + overscan);
|
|
307
|
+
return { start, end: Math.max(start, end) };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Tree source backed by the public editor API. */
|
|
311
|
+
export function editorTreeSource(editor: AnyEditor): LayerTreeSource {
|
|
312
|
+
// Built per layer on first use, so collapsed layers cost nothing.
|
|
313
|
+
const byLayer = new Map<string, readonly ElementRecord[]>();
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
layers: editor.layers.tree(),
|
|
317
|
+
activeLayer: editor.layers.active(),
|
|
318
|
+
elementsOf: (layerId) => {
|
|
319
|
+
let elements = byLayer.get(layerId);
|
|
320
|
+
|
|
321
|
+
if (elements === undefined) {
|
|
322
|
+
elements = [
|
|
323
|
+
...editor.elements.inRenderOrder({ layerId: layerId as never, includeHidden: true }),
|
|
324
|
+
].reverse();
|
|
325
|
+
byLayer.set(layerId, elements);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return elements;
|
|
329
|
+
},
|
|
330
|
+
groupsOf: (elementId) => editor.groups.ancestors(elementId),
|
|
331
|
+
group: (id) => editor.groups.get(id),
|
|
332
|
+
describe: (element) =>
|
|
333
|
+
editor.elements.describe(element.id) ?? { label: element.type, icon: 'element' },
|
|
334
|
+
};
|
|
335
|
+
}
|