@widgetic/canvas 0.5.44 → 0.5.46
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 +1 -1
- package/dist/canvas/DomCanvas.svelte +52 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
- package/dist/canvas/host/CanvasHost.d.ts +74 -3
- package/dist/canvas/host/CanvasHost.js +278 -16
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +9 -1
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +139 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +58 -0
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/SelectionPanel.svelte +78 -17
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +34 -55
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +26 -4
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +26 -1
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +1 -1
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +129 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +15 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/engine/EngineCore.d.ts +46 -4
- package/dist/engine/EngineCore.js +85 -16
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +25 -2
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +24 -12
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +10 -3
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +10 -6
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +10 -2
- package/dist/engine/core/cameraMove.d.ts +6 -0
- package/dist/engine/core/cameraMove.js +6 -0
- package/dist/engine/core/defaults.js +2 -0
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +86 -1
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +19 -3
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +9 -0
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +70 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +41 -10
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +100 -5
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +10 -0
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +44 -29
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +6 -0
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +16 -12
- package/dist/index.d.ts +2 -1
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +138 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +226 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +89 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +122 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +14 -0
- package/dist/settings/workspaceToolSettings.js +21 -10
- package/dist/tools/definitions.js +26 -4
- package/dist/tools/executors.js +81 -5
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +2 -0
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +91 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files of the person's library (the File Browser of their workspace) as the board sees them.
|
|
3
|
+
*
|
|
4
|
+
* The board never shows a File Browser itself: the page that embeds it owns the browser, the workspace and the partner's media
|
|
5
|
+
* library, and gives the board a picker (`pickFiles`). This module is what is said at that door in both directions:
|
|
6
|
+
*
|
|
7
|
+
* - what the board asks for (`BoardFilePickRequest`: pictures and vector files, one or several), and what comes back (`BoardLibraryFile`s,
|
|
8
|
+
* which are checked here because they come from the page, and a partner's page is not ours);
|
|
9
|
+
* - what the board says about the pictures it holds (`BoardPicture`), so the page can put the ones the library does not have yet into it.
|
|
10
|
+
*
|
|
11
|
+
* Deleting something from the board never reaches the library: no function here deletes anything, and the board has no callback
|
|
12
|
+
* that does.
|
|
13
|
+
*
|
|
14
|
+
* Plain TypeScript: runs in Node.
|
|
15
|
+
*/
|
|
16
|
+
import { readLibraryFileAddress } from '../../engine/codec/canvasDocument.js';
|
|
17
|
+
/** The kinds the board asks the picker for, in the order the File Browser lists them. */
|
|
18
|
+
export const BOARD_FILE_KINDS = ['image', 'svg'];
|
|
19
|
+
const PICTURE_EXTENSIONS = {
|
|
20
|
+
svg: 'svg',
|
|
21
|
+
png: 'image',
|
|
22
|
+
jpg: 'image',
|
|
23
|
+
jpeg: 'image',
|
|
24
|
+
gif: 'image',
|
|
25
|
+
webp: 'image',
|
|
26
|
+
avif: 'image',
|
|
27
|
+
bmp: 'image'
|
|
28
|
+
};
|
|
29
|
+
/** What a library address is allowed to be: an http(s) address, or a path of the page (never `data:`, `javascript:`, `//host`). */
|
|
30
|
+
const LIBRARY_URL_PATTERN = /^(?:https?:\/\/|\/(?!\/))/i;
|
|
31
|
+
const MAX_URL_LENGTH = 2000;
|
|
32
|
+
const MAX_NAME_LENGTH = 300;
|
|
33
|
+
const MAX_ID_LENGTH = 200;
|
|
34
|
+
/** A picked list longer than this is cut: one dialog is not for a hundred files, and each is fetched. */
|
|
35
|
+
export const MAX_PICKED_FILES = 40;
|
|
36
|
+
/** The extension of a file name or an address, lower-cased, without the query or the hash. Empty when there is none. */
|
|
37
|
+
export function fileExtensionOf(nameOrUrl) {
|
|
38
|
+
const withoutQuery = nameOrUrl.split(/[?#]/, 1)[0] ?? '';
|
|
39
|
+
const lastSegment = withoutQuery.slice(withoutQuery.lastIndexOf('/') + 1);
|
|
40
|
+
const dot = lastSegment.lastIndexOf('.');
|
|
41
|
+
return dot > 0 ? lastSegment.slice(dot + 1).toLowerCase() : '';
|
|
42
|
+
}
|
|
43
|
+
/** The kind of a file by what the library says it is, else by its name; null when it is not a picture the board can draw. */
|
|
44
|
+
export function boardFileKindOf(file) {
|
|
45
|
+
const mimeType = (file.mimeType ?? '').toLowerCase();
|
|
46
|
+
if (mimeType === 'image/svg+xml')
|
|
47
|
+
return 'svg';
|
|
48
|
+
if (mimeType.startsWith('image/'))
|
|
49
|
+
return 'image';
|
|
50
|
+
return PICTURE_EXTENSIONS[fileExtensionOf(file.name)] ?? PICTURE_EXTENSIONS[fileExtensionOf(file.url ?? '')] ?? null;
|
|
51
|
+
}
|
|
52
|
+
/** The media type the browser needs to draw the file: the library's own when it is a picture's, else the one its extension says. */
|
|
53
|
+
export function pictureMimeTypeOf(file) {
|
|
54
|
+
const mimeType = (file.mimeType ?? '').toLowerCase();
|
|
55
|
+
if (mimeType.startsWith('image/'))
|
|
56
|
+
return mimeType;
|
|
57
|
+
const kind = boardFileKindOf(file);
|
|
58
|
+
if (kind === 'svg')
|
|
59
|
+
return 'image/svg+xml';
|
|
60
|
+
const extension = fileExtensionOf(file.name) || fileExtensionOf(file.url ?? '');
|
|
61
|
+
if (extension === 'jpg' || extension === 'jpeg')
|
|
62
|
+
return 'image/jpeg';
|
|
63
|
+
return extension ? `image/${extension}` : 'image/png';
|
|
64
|
+
}
|
|
65
|
+
/** A readable name for a file whose picker did not give one: the last part of its address. */
|
|
66
|
+
function nameFromUrl(url) {
|
|
67
|
+
const withoutQuery = url.split(/[?#]/, 1)[0] ?? '';
|
|
68
|
+
const last = withoutQuery.slice(withoutQuery.lastIndexOf('/') + 1);
|
|
69
|
+
try {
|
|
70
|
+
return decodeURIComponent(last).slice(0, MAX_NAME_LENGTH) || 'picture';
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return last.slice(0, MAX_NAME_LENGTH) || 'picture';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function readId(value) {
|
|
77
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
78
|
+
return String(value);
|
|
79
|
+
if (typeof value === 'string' && value !== '' && value.length <= MAX_ID_LENGTH)
|
|
80
|
+
return value;
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Keeps what can be drawn of what a picker answered. The answer comes from the page, so it is checked like any input: not a list is
|
|
85
|
+
* nothing; an entry that is not an object, has no loadable address, or is not a picture is dropped; the list is cut at
|
|
86
|
+
* `MAX_PICKED_FILES`; the same file twice (same id, or the same address) is kept once.
|
|
87
|
+
*/
|
|
88
|
+
export function normalizeLibraryFiles(answer) {
|
|
89
|
+
if (!Array.isArray(answer))
|
|
90
|
+
return [];
|
|
91
|
+
const files = [];
|
|
92
|
+
const seen = new Set();
|
|
93
|
+
for (const entry of answer) {
|
|
94
|
+
if (files.length >= MAX_PICKED_FILES)
|
|
95
|
+
break;
|
|
96
|
+
if (typeof entry !== 'object' || entry === null)
|
|
97
|
+
continue;
|
|
98
|
+
const raw = entry;
|
|
99
|
+
const url = typeof raw.url === 'string' ? raw.url.trim() : '';
|
|
100
|
+
if (url === '' || url.length > MAX_URL_LENGTH || !LIBRARY_URL_PATTERN.test(url))
|
|
101
|
+
continue;
|
|
102
|
+
const name = (typeof raw.name === 'string' && raw.name.trim() !== '' ? raw.name.trim() : nameFromUrl(url)).slice(0, MAX_NAME_LENGTH);
|
|
103
|
+
const mimeType = typeof raw.mimeType === 'string' && raw.mimeType !== '' ? raw.mimeType.slice(0, 100) : null;
|
|
104
|
+
if (!boardFileKindOf({ name, url, mimeType }))
|
|
105
|
+
continue;
|
|
106
|
+
const id = readId(raw.id);
|
|
107
|
+
const identity = id ? `id:${id}` : `url:${url}`;
|
|
108
|
+
if (seen.has(identity))
|
|
109
|
+
continue;
|
|
110
|
+
seen.add(identity);
|
|
111
|
+
files.push({ id, name, url, mimeType });
|
|
112
|
+
}
|
|
113
|
+
return files;
|
|
114
|
+
}
|
|
115
|
+
/** Whether a picture of the board is in the library already (the page put it there, or the person picked it from there). */
|
|
116
|
+
export function isInLibrary(picture) {
|
|
117
|
+
return Boolean(picture.libraryFileId || picture.libraryFileUrl);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The scene with the library's answer written into one picture: the very same list when no picture has that object id, or when it
|
|
121
|
+
* already says the same. An answer the page gave badly (no id, an address that is not http(s) or a path of the page) changes nothing,
|
|
122
|
+
* so a partner's bug cannot put an address of its choosing on the board.
|
|
123
|
+
*/
|
|
124
|
+
export function applyLibraryFile(scene, objectId, file) {
|
|
125
|
+
const id = readId(file?.id);
|
|
126
|
+
const url = readLibraryFileAddress(file?.url);
|
|
127
|
+
if (!id || !url)
|
|
128
|
+
return scene;
|
|
129
|
+
let changed = false;
|
|
130
|
+
const next = scene.map((object) => {
|
|
131
|
+
if (object.id !== objectId || object.type !== 'image')
|
|
132
|
+
return object;
|
|
133
|
+
if (object.libraryFileId === id && object.libraryFileUrl === url)
|
|
134
|
+
return object;
|
|
135
|
+
changed = true;
|
|
136
|
+
return { ...object, libraryFileId: id, libraryFileUrl: url };
|
|
137
|
+
});
|
|
138
|
+
return changed ? next : scene;
|
|
139
|
+
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { MeasureText } from '../../engine/text/layoutText.js';
|
|
10
10
|
import type { RasterServices } from '../../engine/render/rasterize.js';
|
|
11
|
+
import type { BoardLibraryFile } from './boardFiles.js';
|
|
11
12
|
/** A text measurer that uses the browser's canvas, or a fixed advance where there is none (the server, a test). */
|
|
12
13
|
export declare function createBrowserMeasureText(): MeasureText;
|
|
13
14
|
/** The picture behind an address, decoded. Null when it cannot be loaded. */
|
|
@@ -22,6 +23,9 @@ export interface LoadedImageFile {
|
|
|
22
23
|
width: number;
|
|
23
24
|
height: number;
|
|
24
25
|
fileName: string;
|
|
26
|
+
/** Set when the picture came from the person's file library: the library's id for it, and where it keeps the file. */
|
|
27
|
+
libraryFileId?: string | null;
|
|
28
|
+
libraryFileUrl?: string | null;
|
|
25
29
|
}
|
|
26
30
|
/** The longest side a picture keeps when it is large; a bigger one is scaled down before it is stored in the board. */
|
|
27
31
|
export declare const IMAGE_MAX_SIDE = 2048;
|
|
@@ -35,6 +39,19 @@ export declare const IMAGE_FALLBACK_SIDE = 300;
|
|
|
35
39
|
* Rejects when the file is not a picture the browser can show.
|
|
36
40
|
*/
|
|
37
41
|
export declare function readImageFile(file: File | Blob, fileName?: string): Promise<LoadedImageFile>;
|
|
42
|
+
/** How long the library gets to hand over a picture's bytes before the board settles for its address. */
|
|
43
|
+
export declare const LIBRARY_PICTURE_TIMEOUT_MS = 10000;
|
|
44
|
+
/** A library picture bigger than this is not read into the board: the board holds its address (a photo of 40 MB is not board material). */
|
|
45
|
+
export declare const LIBRARY_PICTURE_MAX_BYTES: number;
|
|
46
|
+
/**
|
|
47
|
+
* Reads a file of the person's library into a picture for the board, remembering where the library keeps it.
|
|
48
|
+
*
|
|
49
|
+
* The bytes are fetched when the library lets the page (CORS), so the board and the screenshots of it do not depend on the library
|
|
50
|
+
* being reachable, and a large photo is scaled down like any picture the person drops. When the bytes cannot be had (no CORS, an
|
|
51
|
+
* error, too slow, too big) the board holds the file's address instead: it still shows the picture, and the library stays the owner.
|
|
52
|
+
* Null when the browser cannot show the file at all.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readLibraryPicture(file: BoardLibraryFile): Promise<LoadedImageFile | null>;
|
|
38
55
|
/**
|
|
39
56
|
* Opens the browser's file chooser for pictures and answers with what was chosen (an empty list when the person
|
|
40
57
|
* cancels). Must be called while a click or a key press is being handled, or the browser refuses to open the chooser.
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createFixedAdvanceMeasure } from '../../engine/text/layoutText.js';
|
|
10
10
|
import { getTransientHostFor } from '../eventScope.js';
|
|
11
|
+
import { pictureMimeTypeOf } from './boardFiles.js';
|
|
11
12
|
const hasDocument = () => typeof document !== 'undefined' && typeof document.createElement === 'function';
|
|
12
13
|
/** A text measurer that uses the browser's canvas, or a fixed advance where there is none (the server, a test). */
|
|
13
14
|
export function createBrowserMeasureText() {
|
|
@@ -134,6 +135,63 @@ export async function readImageFile(file, fileName = '') {
|
|
|
134
135
|
}
|
|
135
136
|
return { src, width, height, fileName: name };
|
|
136
137
|
}
|
|
138
|
+
/** How long the library gets to hand over a picture's bytes before the board settles for its address. */
|
|
139
|
+
export const LIBRARY_PICTURE_TIMEOUT_MS = 10_000;
|
|
140
|
+
/** A library picture bigger than this is not read into the board: the board holds its address (a photo of 40 MB is not board material). */
|
|
141
|
+
export const LIBRARY_PICTURE_MAX_BYTES = 30 * 1024 * 1024;
|
|
142
|
+
/** The size of the picture behind an address: read with the CORS mode first, then as a plain picture (to be shown, not to be drawn on a canvas). */
|
|
143
|
+
async function measureImageAddress(source) {
|
|
144
|
+
const image = await loadImageElement(source);
|
|
145
|
+
if (image)
|
|
146
|
+
return { width: image.naturalWidth || IMAGE_FALLBACK_SIDE, height: image.naturalHeight || IMAGE_FALLBACK_SIDE };
|
|
147
|
+
if (typeof Image === 'undefined')
|
|
148
|
+
return null;
|
|
149
|
+
return new Promise((resolve) => {
|
|
150
|
+
const plain = new Image();
|
|
151
|
+
plain.onload = () => resolve({ width: plain.naturalWidth || IMAGE_FALLBACK_SIDE, height: plain.naturalHeight || IMAGE_FALLBACK_SIDE });
|
|
152
|
+
plain.onerror = () => resolve(null);
|
|
153
|
+
plain.src = source;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Reads a file of the person's library into a picture for the board, remembering where the library keeps it.
|
|
158
|
+
*
|
|
159
|
+
* The bytes are fetched when the library lets the page (CORS), so the board and the screenshots of it do not depend on the library
|
|
160
|
+
* being reachable, and a large photo is scaled down like any picture the person drops. When the bytes cannot be had (no CORS, an
|
|
161
|
+
* error, too slow, too big) the board holds the file's address instead: it still shows the picture, and the library stays the owner.
|
|
162
|
+
* Null when the browser cannot show the file at all.
|
|
163
|
+
*/
|
|
164
|
+
export async function readLibraryPicture(file) {
|
|
165
|
+
const library = { libraryFileId: file.id, libraryFileUrl: file.url };
|
|
166
|
+
if (typeof fetch === 'function') {
|
|
167
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
|
168
|
+
const timer = controller ? setTimeout(() => controller.abort(), LIBRARY_PICTURE_TIMEOUT_MS) : null;
|
|
169
|
+
try {
|
|
170
|
+
const response = await fetch(file.url, controller ? { signal: controller.signal } : undefined);
|
|
171
|
+
if (!response.ok)
|
|
172
|
+
throw new Error(`The library answered ${response.status}`);
|
|
173
|
+
const blob = await response.blob();
|
|
174
|
+
if (blob.size > LIBRARY_PICTURE_MAX_BYTES)
|
|
175
|
+
throw new Error('The file is too big to be kept in the board');
|
|
176
|
+
// A CDN may call a vector file `application/octet-stream`; the browser only draws a picture that is called one.
|
|
177
|
+
const typed = new Blob([blob], { type: pictureMimeTypeOf({ name: file.name, url: file.url, mimeType: file.mimeType ?? (blob.type || null) }) });
|
|
178
|
+
return { ...(await readImageFile(typed, file.name)), ...library };
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
console.warn('Canvas: the library file could not be read into the board, it is shown from its address', file.name, error);
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
if (timer)
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const size = await measureImageAddress(file.url);
|
|
189
|
+
if (!size) {
|
|
190
|
+
console.warn('Canvas: the library file is not a picture the browser can show', file.name);
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
return { src: file.url, width: size.width, height: size.height, fileName: file.name, ...library };
|
|
194
|
+
}
|
|
137
195
|
/**
|
|
138
196
|
* Opens the browser's file chooser for pictures and answers with what was chosen (an empty list when the person
|
|
139
197
|
* cancels). Must be called while a click or a key press is being handled, or the browser refuses to open the chooser.
|
package/dist/canvas/index.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export type { ToolbarPosition } from './toolbarPosition';
|
|
|
13
13
|
export { PAN_ZOOM_POSITIONS, DEFAULT_PAN_ZOOM_POSITION } from './panZoomPosition';
|
|
14
14
|
export type { PanZoomPosition } from './panZoomPosition';
|
|
15
15
|
export type { StrokeRecognizer, StrokeRecognitionRequest, StrokeRecognitionResult } from './types';
|
|
16
|
-
export type { CanvasFlyOptions, CanvasMoveOptions } from './types';
|
|
16
|
+
export type { CanvasClearCause, CanvasFlyOptions, CanvasMoveOptions } from './types';
|
|
17
|
+
export type { BoardFileKind, BoardFilePickRequest, BoardFilePicker, BoardLibraryFile, BoardPicture, BoardPictureLibraryFile } from './host/boardFiles';
|
|
17
18
|
export { CANVAS_SHAPE_SNAP_ENABLED, STROKE_SNAP_IMAGE_SIDE, projectStrokeToImagePoints, renderStrokeSnapImage } from './shapes/strokeShapeSnap';
|
|
18
19
|
export { canvasLog, canvasWarn, canvasDebug, setCanvasLogsEnabled, isCanvasLogsEnabled } from './canvasLogger';
|
|
19
20
|
export { setShapeImageStore, getShapeImageStore, SHAPE_IMAGE_STORE_OBJECT_URLS } from './shapes/shapeImageStore';
|
package/dist/canvas/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Importable by both the canvas project and consuming apps (e.g. widget-creator).
|
|
4
4
|
*/
|
|
5
5
|
import type { CanvasSnapShape, SnapRanking, StrokeMeasurements } from './shapes/strokeShapeSnap';
|
|
6
|
-
import type { ViewMoveOptions } from '../engine/EngineCore.js';
|
|
6
|
+
import type { BoardClearCause, ViewMoveOptions } from '../engine/EngineCore.js';
|
|
7
7
|
/** Payload emitted when a frame is converted to a widget via onConvertToWidget callback. */
|
|
8
8
|
export interface WidgetConversionPayload {
|
|
9
9
|
frameName: string;
|
|
@@ -84,6 +84,12 @@ export type StrokeRecognizer = (request: StrokeRecognitionRequest) => Promise<St
|
|
|
84
84
|
* and be told when it is over (and whether the view arrived or the person took it first).
|
|
85
85
|
*/
|
|
86
86
|
export type CanvasMoveOptions = ViewMoveOptions;
|
|
87
|
+
/**
|
|
88
|
+
* Why `onCanvasCleared` was called: the page emptied the board (`onClearAllObjects()`, `'clear-all'`) or the person's delete or cut took
|
|
89
|
+
* the last object off it (`'deleted'`). A page that puts the view back (`flyToContent`) for a board the person emptied reacts to
|
|
90
|
+
* `'deleted'` and to a "Clear canvas" link of its own, and leaves the clears it makes itself (opening another board) alone.
|
|
91
|
+
*/
|
|
92
|
+
export type CanvasClearCause = BoardClearCause;
|
|
87
93
|
/** What `flyToPoint` and `flyToObjects` take besides how the move goes: the zoom to arrive at. */
|
|
88
94
|
export interface CanvasFlyOptions extends CanvasMoveOptions {
|
|
89
95
|
/**
|
|
@@ -141,6 +141,12 @@
|
|
|
141
141
|
</DropdownMenu.Item>
|
|
142
142
|
{/snippet}
|
|
143
143
|
|
|
144
|
+
<!--
|
|
145
|
+
`data-canvas-ui` marks the menu as the canvas's own (its layer submenu sits inside it): on a page without a shadow root the
|
|
146
|
+
menu is portaled to `document.body`, outside the canvas root, and a press on one of its entries would otherwise count as a
|
|
147
|
+
press outside the canvas (`outsideClickDeselect.ts`) and clear the selection before the click lands. The entries that act
|
|
148
|
+
on the selection (Duplicate, Bring to front, Delete...) are disabled by then, and nothing happens.
|
|
149
|
+
-->
|
|
144
150
|
<DropdownMenu.Root open={point !== null} onOpenChange={setOpen}>
|
|
145
151
|
{#if anchor}
|
|
146
152
|
<DropdownMenu.Content
|
|
@@ -151,6 +157,7 @@
|
|
|
151
157
|
portalProps={canvasOverlayPortalProps($floatingLayer)}
|
|
152
158
|
onCloseAutoFocus={returnFocusToBoard}
|
|
153
159
|
aria-label={$t('canvas.panel.actions')}
|
|
160
|
+
data-canvas-ui
|
|
154
161
|
data-canvas-context-menu
|
|
155
162
|
class="{CANVAS_OVERLAY_Z_CLASS} w-[240px] py-1 {MENU_PADDING_CLASS} shadow-floating focus-visible:outline-hidden {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
156
163
|
>
|
|
@@ -33,11 +33,13 @@
|
|
|
33
33
|
state: EngineState;
|
|
34
34
|
ui: HostUiState;
|
|
35
35
|
showDrawingTools: boolean;
|
|
36
|
+
/** Whether the Shapes menu offers the person's file library (the page turned it on and gave the browser that opens it). */
|
|
37
|
+
showFiles?: boolean;
|
|
36
38
|
/** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
37
39
|
anchor: ChromeAnchor;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
let { host, state, ui, showDrawingTools, anchor }: Props = $props();
|
|
42
|
+
let { host, state, ui, showDrawingTools, showFiles = false, anchor }: Props = $props();
|
|
41
43
|
|
|
42
44
|
const { t } = useCanvasLanguage();
|
|
43
45
|
|
|
@@ -81,6 +83,7 @@
|
|
|
81
83
|
libraryShapeKey={state.libraryShapeKey}
|
|
82
84
|
open={ui.shapesMenuOpen}
|
|
83
85
|
imageShortcut={TOOL_KEYS.image}
|
|
86
|
+
{showFiles}
|
|
84
87
|
/>
|
|
85
88
|
|
|
86
89
|
<!-- The history group is the first thing a board too narrow for the whole bar gives up (Figma's phone): undo and redo stay on the keys. An upright bar is as long as the board is tall, so it keeps them. -->
|
|
@@ -6,6 +6,8 @@ interface Props {
|
|
|
6
6
|
state: EngineState;
|
|
7
7
|
ui: HostUiState;
|
|
8
8
|
showDrawingTools: boolean;
|
|
9
|
+
/** Whether the Shapes menu offers the person's file library (the page turned it on and gave the browser that opens it). */
|
|
10
|
+
showFiles?: boolean;
|
|
9
11
|
/** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
10
12
|
anchor: ChromeAnchor;
|
|
11
13
|
}
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
Every change goes through the engine's one `setStyle`, so what the panel does is what an undo takes back, and a slider that
|
|
11
11
|
is still being dragged is one step of the history, taken when it ends.
|
|
12
12
|
|
|
13
|
+
With the Draw tool chosen and nothing selected the panel is about the pen: the line the next stroke is drawn with. It has
|
|
14
|
+
the rows a line drawn by hand has (Stroke, Stroke width and Opacity), and what is set there is what the next line looks like,
|
|
15
|
+
before anything is drawn (see `describePenStyle`). Nothing that is drawn already changes, and the pen is kept for the
|
|
16
|
+
workspace (see `CanvasHost.changePenStyle`). It opens and closes like the panel of a selection.
|
|
17
|
+
|
|
13
18
|
A selection shows a settings control at the corner; it opens the panel, and the close button collapses it again without
|
|
14
19
|
changing when the selection changes. Nothing opens the panel by itself, not a selection and not a text: it is closed by
|
|
15
20
|
default, it stays as the person left it while the selection moves from one object to another, and it goes back to the
|
|
@@ -21,8 +26,10 @@
|
|
|
21
26
|
import { onDestroy } from 'svelte';
|
|
22
27
|
import type { Attachment } from 'svelte/attachments';
|
|
23
28
|
import { IconButton, NumberControls, Select, Slider } from '@widgetic/design-system/components';
|
|
29
|
+
import { MIN_BRUSH_WIDTH } from '../../engine/core/brush.js';
|
|
24
30
|
import type { StylePatch } from '../../engine/core/style.js';
|
|
25
|
-
import
|
|
31
|
+
import { MIN_PEN_OPACITY } from '../../engine/state.js';
|
|
32
|
+
import type { EngineState, PenStyle } from '../../engine/state.js';
|
|
26
33
|
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
27
34
|
import { objectName } from '../../i18n/labels.js';
|
|
28
35
|
import type { PanelClearance } from '../chromeLayout.js';
|
|
@@ -37,7 +44,15 @@
|
|
|
37
44
|
workspaceFontFamiliesForPicker,
|
|
38
45
|
writePreferredTextFontFamily
|
|
39
46
|
} from '../preferredTextFont.js';
|
|
40
|
-
import {
|
|
47
|
+
import {
|
|
48
|
+
describePenStyle,
|
|
49
|
+
describeSelection,
|
|
50
|
+
formatFontSizeDisplay,
|
|
51
|
+
minimumStrokeWidth,
|
|
52
|
+
showFillColorRow,
|
|
53
|
+
showStrokeColorRow,
|
|
54
|
+
traitNumber
|
|
55
|
+
} from './selectionTraits.js';
|
|
41
56
|
import ToolButton from './ToolButton.svelte';
|
|
42
57
|
import WidgetActions from './WidgetActions.svelte';
|
|
43
58
|
import { shouldOfferSelectionPanelForTraits } from './widgetSelectionPanel.js';
|
|
@@ -76,12 +91,27 @@
|
|
|
76
91
|
const PANEL_END_BESIDE_SIDE_CARD = { toolbar: '5.25rem', zoom: '4rem' } as const;
|
|
77
92
|
const PANEL_MAX_WIDTH_CLASSES = { none: 'max-w-[calc(100%-2rem)]', toolbar: 'max-w-[calc(100%-6.25rem)]', zoom: 'max-w-[calc(100%-5rem)]' } as const;
|
|
78
93
|
|
|
79
|
-
|
|
94
|
+
// ── the pen
|
|
95
|
+
// With the Draw tool chosen and nothing selected, the panel is about the pen: the line the next stroke is drawn with (see
|
|
96
|
+
// `EngineState.penStyle`). It offers what a line drawn by hand has (its colour, its width and how much of the board shows
|
|
97
|
+
// through it), so that these can be set before anything is drawn. A selection is about the selection, whatever the tool is.
|
|
98
|
+
const editsPen = $derived(state.tool === 'draw' && state.selectedIds.length === 0);
|
|
99
|
+
|
|
100
|
+
const traits = $derived(editsPen ? describePenStyle(state.penStyle) : describeSelection(state.scene, state.selectedIds));
|
|
80
101
|
const hasSelection = $derived(traits.units.length > 0);
|
|
81
102
|
|
|
82
103
|
const title = $derived(
|
|
83
|
-
|
|
104
|
+
editsPen
|
|
105
|
+
? $t('canvas.tool.draw')
|
|
106
|
+
: traits.units.length === 1
|
|
107
|
+
? objectName(traits.units[0], $t)
|
|
108
|
+
: hasSelection
|
|
109
|
+
? $t('canvas.type.selection')
|
|
110
|
+
: $t('canvas.panel.actions')
|
|
84
111
|
);
|
|
112
|
+
// The name of the panel and of the control that opens it, for a screen reader: the pen is not a selection.
|
|
113
|
+
const panelLabel = $derived(editsPen ? $t('canvas.panel.penLabel') : $t('canvas.panel.label'));
|
|
114
|
+
const openLabel = $derived(editsPen ? $t('canvas.panel.penOpen') : $t('canvas.panel.open'));
|
|
85
115
|
|
|
86
116
|
// The font of a text, offered as the old panel offered it: eight families that every screen has.
|
|
87
117
|
const WORKSPACE_FONT_FAMILIES = $derived(workspaceFontFamiliesForPicker());
|
|
@@ -98,8 +128,24 @@
|
|
|
98
128
|
commitTimer = undefined;
|
|
99
129
|
}
|
|
100
130
|
|
|
101
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Sets the pen (see `editsPen`): of the keys of a change of style a line takes its colour (`stroke`), its width and its opacity.
|
|
133
|
+
* The pen is not on the board, so there is no step of the history to take and nothing to commit; `final` is false while a drag is going.
|
|
134
|
+
*/
|
|
135
|
+
function changePen(patch: StylePatch, final: boolean): void {
|
|
136
|
+
const penPatch: Partial<PenStyle> = {};
|
|
137
|
+
if (patch.stroke !== undefined) penPatch.color = patch.stroke;
|
|
138
|
+
if (patch.strokeWidth !== undefined) penPatch.width = patch.strokeWidth;
|
|
139
|
+
if (patch.opacity !== undefined) penPatch.opacity = patch.opacity;
|
|
140
|
+
host.changePenStyle(penPatch, { final });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Changes how the selection looks (or the pen, while the panel is about the pen). `commit` is false while a drag is going. */
|
|
102
144
|
function changeStyle(patch: StylePatch, commit = true): void {
|
|
145
|
+
if (editsPen) {
|
|
146
|
+
changePen(patch, commit);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
103
149
|
try {
|
|
104
150
|
host.engine.setStyle(patch, { commit });
|
|
105
151
|
stopCommitTimer();
|
|
@@ -115,7 +161,9 @@
|
|
|
115
161
|
|
|
116
162
|
function endChange(): void {
|
|
117
163
|
stopCommitTimer();
|
|
118
|
-
host.
|
|
164
|
+
// The pen has nothing to commit: the end of a drag only lets the host say, once, what the pen is now.
|
|
165
|
+
if (editsPen) host.changePenStyle({}, { final: true });
|
|
166
|
+
else host.engine.commit();
|
|
119
167
|
}
|
|
120
168
|
|
|
121
169
|
onDestroy(() => {
|
|
@@ -165,7 +213,13 @@
|
|
|
165
213
|
}
|
|
166
214
|
|
|
167
215
|
const percent = (fraction: number): number => Math.round(fraction * 100);
|
|
168
|
-
|
|
216
|
+
// An arrow (or any shape that is only a line) cannot be given no line: the stepper stops at the thinnest one, and the mixed
|
|
217
|
+
// selection starts its buttons from there instead of from a 0 that is out of range.
|
|
218
|
+
// The pen is a line drawn by hand, whose thinnest is the brush's.
|
|
219
|
+
const strokeWidthMin = $derived(editsPen ? MIN_BRUSH_WIDTH : minimumStrokeWidth(traits));
|
|
220
|
+
const strokeWidthValue = $derived(traitNumber(traits.strokeWidth, strokeWidthMin));
|
|
221
|
+
// The pen is never made so faint that it cannot be seen (the slider goes in whole percents, see `MIN_PEN_OPACITY`).
|
|
222
|
+
const opacityMin = $derived(editsPen ? Math.round(MIN_PEN_OPACITY * 100) : 0);
|
|
169
223
|
const fontSizeValue = $derived(traits.text ? traitNumber(traits.text.fontSize, 16) : 16);
|
|
170
224
|
|
|
171
225
|
// The widget on the board is not edited here: a selected card whose widget is there has no settings control and no panel.
|
|
@@ -174,12 +228,15 @@
|
|
|
174
228
|
);
|
|
175
229
|
// A lone widget card does not open the sketch settings panel on any board (`shouldOfferSelectionPanelForTraits`); on the
|
|
176
230
|
// simple board it does not even when the page can capture (`selectionIsAWidgetWithoutSettings`).
|
|
231
|
+
// The pen has its panel on every board that has the Draw tool: it is the way to set the line before it is drawn.
|
|
177
232
|
const showPanel = $derived(
|
|
178
|
-
|
|
179
|
-
(
|
|
233
|
+
editsPen ||
|
|
234
|
+
(!selectionIsAWidgetWithoutSettings &&
|
|
235
|
+
((shouldOfferSelectionPanelForTraits(traits) && hasSelection) || (canCapture && !canConvert)))
|
|
180
236
|
);
|
|
181
237
|
const showFillColor = $derived(showFillColorRow(traits, wireframeMode));
|
|
182
|
-
|
|
238
|
+
// The pen's colour is shown in the wireframe look too: a line drawn by hand keeps its colour there.
|
|
239
|
+
const showStrokeColor = $derived(editsPen || showStrokeColorRow(traits, wireframeMode));
|
|
183
240
|
const fontSizeDisplay = $derived(traits.text ? formatFontSizeDisplay(traits.text.fontSize) : '–');
|
|
184
241
|
const panelAnchorClass = $derived(
|
|
185
242
|
`${clearance.belowTopCards ? 'top-16' : 'top-4'} ${PANEL_MAX_WIDTH_CLASSES[clearance.besideSideCard ?? 'none']}`
|
|
@@ -192,7 +249,7 @@
|
|
|
192
249
|
style:inset-inline-end={clearance.besideSideCard ? PANEL_END_BESIDE_SIDE_CARD[clearance.besideSideCard] : undefined}
|
|
193
250
|
>
|
|
194
251
|
<div class={FLOATING_CARD_CLASSES} data-canvas-selection-settings>
|
|
195
|
-
<ToolButton label={
|
|
252
|
+
<ToolButton label={openLabel} onclick={() => host.updateUi({ selectionPanelDismissed: false })}>
|
|
196
253
|
<IconSettings />
|
|
197
254
|
</ToolButton>
|
|
198
255
|
</div>
|
|
@@ -201,7 +258,7 @@
|
|
|
201
258
|
|
|
202
259
|
{#if showPanel && !ui.selectionPanelDismissed}
|
|
203
260
|
<aside
|
|
204
|
-
aria-label={
|
|
261
|
+
aria-label={panelLabel}
|
|
205
262
|
data-canvas-ui
|
|
206
263
|
data-canvas-selection-panel
|
|
207
264
|
class="pointer-events-auto absolute end-4 z-20 flex min-h-[304px] w-[336px] flex-col gap-4 overflow-y-auto rounded-card border border-border bg-popover p-4 text-foreground shadow-floating {clearance.belowTopCards ? 'top-16 max-h-[calc(100%-5rem)]' : 'top-4 max-h-[calc(100%-2rem)]'} {PANEL_MAX_WIDTH_CLASSES[clearance.besideSideCard ?? 'none']}"
|
|
@@ -210,7 +267,7 @@
|
|
|
210
267
|
<header class="flex h-8 w-full shrink-0 items-center gap-2">
|
|
211
268
|
<h2 class="truncate text-body font-semibold leading-5">{title}</h2>
|
|
212
269
|
<div class="min-h-px min-w-0 flex-1" aria-hidden="true"></div>
|
|
213
|
-
{#if hasSelection}
|
|
270
|
+
{#if hasSelection || editsPen}
|
|
214
271
|
<IconButton label={$t('canvas.panel.close')} onclick={dismiss}>
|
|
215
272
|
<IconX />
|
|
216
273
|
</IconButton>
|
|
@@ -227,7 +284,8 @@
|
|
|
227
284
|
{#if showStrokeColor}
|
|
228
285
|
<div class="flex h-9 w-full items-start" data-canvas-panel-row="stroke">
|
|
229
286
|
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.stroke')}</span>
|
|
230
|
-
|
|
287
|
+
<!-- A pen always has a colour: "no colour" is a choice for the outline of a shape, not for the line the next stroke is drawn with. -->
|
|
288
|
+
<ColorField label={$t('canvas.panel.stroke')} value={traits.stroke} allowNone={!editsPen} onchange={(color, commit) => changeStyle({ stroke: color }, commit)} />
|
|
231
289
|
</div>
|
|
232
290
|
{/if}
|
|
233
291
|
|
|
@@ -242,7 +300,7 @@
|
|
|
242
300
|
increaseLabel={$t('canvas.panel.increase')}
|
|
243
301
|
value={traits.strokeWidth.kind === 'same' ? Number(strokeWidthValue.toFixed(1)) : null}
|
|
244
302
|
fallbackValue={strokeWidthValue}
|
|
245
|
-
min={
|
|
303
|
+
min={strokeWidthMin}
|
|
246
304
|
max={200}
|
|
247
305
|
step={1}
|
|
248
306
|
onChange={(next) => changeStyle({ strokeWidth: next })}
|
|
@@ -265,7 +323,7 @@
|
|
|
265
323
|
<div class="flex h-9 w-full items-start" data-canvas-panel-row="opacity" role="group" aria-label={$t('canvas.panel.opacity')} {@attach nameSliderThumb($t('canvas.panel.opacity'))}>
|
|
266
324
|
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.opacity')}</span>
|
|
267
325
|
<div class="flex w-[185px] shrink-0 items-center gap-3">
|
|
268
|
-
<Slider type="single" min={
|
|
326
|
+
<Slider type="single" min={opacityMin} max={100} step={1} value={percent(traitNumber(traits.opacity, 1))} onValueChange={(next: number) => changeStyle({ opacity: next / 100 }, false)} onValueCommit={endChange} />
|
|
269
327
|
<span class="w-7 shrink-0 text-end text-body tabular-nums">{traits.opacity.kind === 'same' ? percent(traits.opacity.value) : '–'}</span>
|
|
270
328
|
</div>
|
|
271
329
|
</div>
|
|
@@ -359,6 +417,9 @@
|
|
|
359
417
|
</div>
|
|
360
418
|
{/if}
|
|
361
419
|
|
|
362
|
-
|
|
420
|
+
<!-- What can be done with the sketch for the page (capture, convert, rename) is about the board, not about the pen: the pen's panel is only the pen. -->
|
|
421
|
+
{#if !editsPen}
|
|
422
|
+
<WidgetActions {host} {state} {ui} {traits} {canCapture} {canConvert} {canRename} {canRefresh} {canOpenDetails} />
|
|
423
|
+
{/if}
|
|
363
424
|
</aside>
|
|
364
425
|
{/if}
|