@widgetic/canvas 0.5.45 → 0.5.47
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 +3 -2
- package/dist/canvas/DomCanvas.svelte +1 -2
- package/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +19 -21
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +6 -5
- package/dist/canvas/host/CanvasHost.js +1664 -1861
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/boardFiles.js +35 -51
- package/dist/canvas/host/browserServices.js +108 -196
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +18 -21
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pauseCollector.d.ts +18 -0
- package/dist/canvas/host/pauseCollector.js +45 -0
- package/dist/canvas/host/pictureSaves.js +9 -11
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.js +149 -243
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
- package/dist/canvas/ui/CanvasHint.svelte +10 -9
- package/dist/canvas/ui/SelectionPanel.svelte +14 -12
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
- package/dist/canvas/ui/ShapesMenu.svelte +6 -4
- package/dist/canvas/ui/ToolButton.svelte +7 -6
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +28 -8
- package/dist/canvas/ui/floatingCard.js +48 -28
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.d.ts +8 -4
- package/dist/canvas/ui/selectionTraits.js +44 -58
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +2 -2
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +72 -91
- package/dist/canvas/view/liftedScene.js +24 -36
- package/dist/canvas/view/mountedScene.js +76 -79
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/input-controls/ColorIC.svelte +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +42 -10
- package/dist/engine/EngineCore.js +843 -916
- package/dist/engine/codec/canvasDocument.js +192 -155
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +79 -92
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.d.ts +24 -0
- package/dist/engine/core/brush.js +223 -103
- package/dist/engine/core/cameraMove.js +39 -51
- package/dist/engine/core/defaults.js +92 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +38 -55
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.js +160 -224
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.d.ts +23 -18
- package/dist/engine/core/shapeTools.js +104 -67
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.d.ts +18 -2
- package/dist/engine/core/style.js +79 -80
- package/dist/engine/core/styleMemory.d.ts +88 -0
- package/dist/engine/core/styleMemory.js +189 -0
- package/dist/engine/core/transform.js +84 -95
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +513 -526
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +8 -3
- package/dist/engine/input/gestures.js +378 -346
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +42 -41
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.js +6 -17
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.js +30 -83
- package/dist/fonts/workspaceFonts.js +33 -92
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/poster/boardPlacement.d.ts +4 -1
- package/dist/poster/boardPlacement.js +34 -33
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedStyles.d.ts +22 -0
- package/dist/settings/rememberedStyles.js +47 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +25 -0
- package/dist/settings/workspaceToolSettings.js +38 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +137 -169
- package/dist/tools/hostAdapter.js +10 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/styleArguments.js +19 -21
- package/dist/tools/types.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ the canvas itself.
|
|
|
77
77
|
|
|
78
78
|
| Keys start with | The words of |
|
|
79
79
|
| --- | --- |
|
|
80
|
-
| `canvas.state.` | "Loading canvas…", the line when the canvas could not start, the name of the board for a screen reader, and the notice when a saved canvas cannot be opened |
|
|
80
|
+
| `canvas.state.` | "Loading canvas…" (the name of the loader for a screen reader: the loader draws no words), the line when the canvas could not start, the name of the board for a screen reader, and the notice when a saved canvas cannot be opened |
|
|
81
81
|
| `canvas.hint.` | the hint on an empty board |
|
|
82
82
|
| `canvas.defaults.`, `canvas.draw.` | what new things start with ("Type here", "Untitled Shape"), and the words a widget card draws (its name when it has none, "Widget preview") |
|
|
83
83
|
| `canvas.toolbar.`, `canvas.tool.`, `canvas.menu.`, `canvas.category.`, `canvas.shape.` | the toolbar: the tools and their hints, the menu of shapes, its groups, and the name of every shape in it |
|
|
@@ -173,7 +173,8 @@ The saved canvas is a versioned document (`CANVAS_DOCUMENT_VERSION = 2`): a flat
|
|
|
173
173
|
empty with a notice and is left as it is until something new is added.
|
|
174
174
|
|
|
175
175
|
**The pencil is a brush.** A stroke is thicker where the hand slows down (a pen's own pressure draws it when the device reports
|
|
176
|
-
one), a click is a round dot, **Shift**
|
|
176
|
+
one), a click is a round dot, **Shift** held while drawing makes a straight line from where the pointer was when it went down (let
|
|
177
|
+
go, the line is kept and the stroke goes on by hand), and a resize makes a stroke longer, never fatter. A board saves
|
|
177
178
|
each stroke as its line and its pressures (`ink`) and draws the outline again when it is read.
|
|
178
179
|
|
|
179
180
|
**An arrow is two points and a bend.** Its open head keeps its size when the arrow is stretched, a selected arrow has a handle
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
// selector's indicator is a card of its own at the top.)
|
|
79
79
|
export let toolbarPosition: ToolbarPosition = DEFAULT_TOOLBAR_POSITION;
|
|
80
80
|
|
|
81
|
-
// Wireframe mode:
|
|
81
|
+
// Wireframe mode: new objects start white with a dark stroke (the colour fields of the selection panel are there in either look)
|
|
82
82
|
export let wireframeMode: CanvasHostProps['wireframeMode'] = DEFAULT_HOST_PROPS.wireframeMode;
|
|
83
83
|
|
|
84
84
|
// The advanced chrome of a widget card: with it on a card can be turned, and the primary widget has its ring. With it off
|
|
@@ -529,7 +529,6 @@
|
|
|
529
529
|
{host}
|
|
530
530
|
state={engineState}
|
|
531
531
|
ui={uiState}
|
|
532
|
-
{wireframeMode}
|
|
533
532
|
canCapture={!!onObjectClick}
|
|
534
533
|
canConvert={!!(onWidgetRename || onRefreshScreenshot || onWidgetImageClick || onSetPrimaryWidget)}
|
|
535
534
|
canRename={!!onWidgetRename}
|
|
@@ -19,48 +19,12 @@
|
|
|
19
19
|
*
|
|
20
20
|
* Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
|
|
21
21
|
*/
|
|
22
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
23
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
32
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
33
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
34
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
|
-
function step(op) {
|
|
36
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
38
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
39
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
|
-
switch (op[0]) {
|
|
41
|
-
case 0: case 1: t = op; break;
|
|
42
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
43
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
44
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
45
|
-
default:
|
|
46
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
47
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
48
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
49
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
50
|
-
if (t[2]) _.ops.pop();
|
|
51
|
-
_.trys.pop(); continue;
|
|
52
|
-
}
|
|
53
|
-
op = body.call(thisArg, _);
|
|
54
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
55
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
22
|
/** The shortest time a save that is held back waits before the host is asked again, so that a delay of 0 does not spin. */
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
now:
|
|
62
|
-
setTimer:
|
|
63
|
-
clearTimer:
|
|
23
|
+
const SHORTEST_RECHECK_DELAY_MS = 250;
|
|
24
|
+
const realClock = {
|
|
25
|
+
now: () => Date.now(),
|
|
26
|
+
setTimer: (callback, delayMs) => setTimeout(callback, delayMs),
|
|
27
|
+
clearTimer: (handle) => clearTimeout(handle)
|
|
64
28
|
};
|
|
65
29
|
/** A number a host passed as a duration: anything that is not a finite number of at least 0 is 0. */
|
|
66
30
|
function toDurationMs(value) {
|
|
@@ -70,20 +34,19 @@ function isPromiseLike(value) {
|
|
|
70
34
|
return !!value && typeof value.then === 'function';
|
|
71
35
|
}
|
|
72
36
|
export function createAutosaveScheduler(options) {
|
|
73
|
-
|
|
74
|
-
var clock = (_a = options.clock) !== null && _a !== void 0 ? _a : realClock;
|
|
37
|
+
const clock = options.clock ?? realClock;
|
|
75
38
|
/** Something changed that no save has taken yet. */
|
|
76
|
-
|
|
39
|
+
let dirty = false;
|
|
77
40
|
/** When the first change that no save has taken yet was made: where the longest wait is counted from. */
|
|
78
|
-
|
|
79
|
-
|
|
41
|
+
let firstChangeAt = null;
|
|
42
|
+
let timerHandle = null;
|
|
80
43
|
/** The save that is on its way, if there is one. It never rejects. */
|
|
81
|
-
|
|
44
|
+
let saveOnItsWay = null;
|
|
82
45
|
/** The next save fell due while another was on its way: it starts as soon as that one is done. */
|
|
83
|
-
|
|
46
|
+
let dueWhileSaving = false;
|
|
84
47
|
/** How many saves in a row have failed. A save that goes through, or a board that was just loaded, makes it 0. */
|
|
85
|
-
|
|
86
|
-
|
|
48
|
+
let failuresInARow = 0;
|
|
49
|
+
let disposed = false;
|
|
87
50
|
function stopTimer() {
|
|
88
51
|
if (timerHandle === null)
|
|
89
52
|
return;
|
|
@@ -107,8 +70,7 @@ export function createAutosaveScheduler(options) {
|
|
|
107
70
|
}
|
|
108
71
|
/** Starts the save, or, when the host holds saves back, looks again a delay later. */
|
|
109
72
|
function saveUnlessHeldBack() {
|
|
110
|
-
|
|
111
|
-
if ((_a = options.isSuspended) === null || _a === void 0 ? void 0 : _a.call(options)) {
|
|
73
|
+
if (options.isSuspended?.()) {
|
|
112
74
|
startTimer(Math.max(toDurationMs(options.getDelayMs()), SHORTEST_RECHECK_DELAY_MS));
|
|
113
75
|
return;
|
|
114
76
|
}
|
|
@@ -118,7 +80,7 @@ export function createAutosaveScheduler(options) {
|
|
|
118
80
|
function scheduleRetry() {
|
|
119
81
|
if (disposed || timerHandle !== null || !options.getRetryDelayMs)
|
|
120
82
|
return;
|
|
121
|
-
|
|
83
|
+
let waitMs = 0;
|
|
122
84
|
try {
|
|
123
85
|
waitMs = toDurationMs(options.getRetryDelayMs(failuresInARow));
|
|
124
86
|
}
|
|
@@ -129,13 +91,12 @@ export function createAutosaveScheduler(options) {
|
|
|
129
91
|
startTimer(waitMs);
|
|
130
92
|
}
|
|
131
93
|
function noteFailure(error) {
|
|
132
|
-
var _a;
|
|
133
94
|
// What the failed save was meant to keep is not kept: it is unsaved again, and the retry (or the next change or
|
|
134
95
|
// flush) tries again.
|
|
135
96
|
dirty = true;
|
|
136
97
|
failuresInARow += 1;
|
|
137
98
|
try {
|
|
138
|
-
|
|
99
|
+
options.onSaveFailed?.(error);
|
|
139
100
|
}
|
|
140
101
|
catch (reportError) {
|
|
141
102
|
console.warn('[autosave] onSaveFailed threw', reportError);
|
|
@@ -149,7 +110,7 @@ export function createAutosaveScheduler(options) {
|
|
|
149
110
|
// made while the save is on its way) is unsaved again, and is the next save's.
|
|
150
111
|
dirty = false;
|
|
151
112
|
firstChangeAt = null;
|
|
152
|
-
|
|
113
|
+
let outcome;
|
|
153
114
|
try {
|
|
154
115
|
outcome = options.save();
|
|
155
116
|
}
|
|
@@ -161,11 +122,11 @@ export function createAutosaveScheduler(options) {
|
|
|
161
122
|
failuresInARow = 0;
|
|
162
123
|
return Promise.resolve();
|
|
163
124
|
}
|
|
164
|
-
|
|
165
|
-
.then(
|
|
125
|
+
const running = Promise.resolve(outcome)
|
|
126
|
+
.then(() => {
|
|
166
127
|
failuresInARow = 0;
|
|
167
|
-
},
|
|
168
|
-
.then(
|
|
128
|
+
}, (error) => noteFailure(error))
|
|
129
|
+
.then(() => {
|
|
169
130
|
if (saveOnItsWay === running)
|
|
170
131
|
saveOnItsWay = null;
|
|
171
132
|
if (disposed)
|
|
@@ -181,36 +142,23 @@ export function createAutosaveScheduler(options) {
|
|
|
181
142
|
function markChanged() {
|
|
182
143
|
if (disposed)
|
|
183
144
|
return;
|
|
184
|
-
|
|
145
|
+
const now = clock.now();
|
|
185
146
|
dirty = true;
|
|
186
147
|
if (firstChangeAt === null)
|
|
187
148
|
firstChangeAt = now;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
149
|
+
const quietUntil = now + toDurationMs(options.getDelayMs());
|
|
150
|
+
const longestWait = toDurationMs(options.getMaxWaitMs());
|
|
151
|
+
const dueAt = longestWait > 0 ? Math.min(quietUntil, firstChangeAt + longestWait) : quietUntil;
|
|
191
152
|
startTimer(dueAt - now);
|
|
192
153
|
}
|
|
193
|
-
function flush() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
_a.sent();
|
|
202
|
-
return [3 /*break*/, 0];
|
|
203
|
-
case 2:
|
|
204
|
-
// Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
|
|
205
|
-
if (disposed || !dirty)
|
|
206
|
-
return [2 /*return*/];
|
|
207
|
-
return [4 /*yield*/, startSave()];
|
|
208
|
-
case 3:
|
|
209
|
-
_a.sent();
|
|
210
|
-
return [2 /*return*/];
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
154
|
+
async function flush() {
|
|
155
|
+
// A save on its way finishes first, so that two never overlap.
|
|
156
|
+
while (saveOnItsWay)
|
|
157
|
+
await saveOnItsWay;
|
|
158
|
+
// Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
|
|
159
|
+
if (disposed || !dirty)
|
|
160
|
+
return;
|
|
161
|
+
await startSave();
|
|
214
162
|
}
|
|
215
163
|
function cancel() {
|
|
216
164
|
stopTimer();
|
|
@@ -224,10 +172,10 @@ export function createAutosaveScheduler(options) {
|
|
|
224
172
|
disposed = true;
|
|
225
173
|
}
|
|
226
174
|
return {
|
|
227
|
-
markChanged
|
|
228
|
-
flush
|
|
229
|
-
cancel
|
|
230
|
-
dispose
|
|
175
|
+
markChanged,
|
|
176
|
+
flush,
|
|
177
|
+
cancel,
|
|
178
|
+
dispose,
|
|
231
179
|
get isDirty() {
|
|
232
180
|
return dirty;
|
|
233
181
|
}
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* Written out in full, so that the stylesheet of a page that installs the canvas picks every class up when it reads this
|
|
11
11
|
* file. Kept free of Svelte and of the DOM so that Node can test it.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export const BOARD_FRAME_CLASSES = 'rounded-card after:pointer-events-none after:absolute after:inset-0 after:z-50 after:rounded-[inherit] after:border after:border-border';
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* white in the design, while the full canvas stays `muted`). Nothing else changes: the variable is not set anywhere else, so
|
|
11
11
|
* the board, the creator and the embeds keep the token.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export const BOARD_SURFACE_COLOR = 'var(--canvas-surface, var(--muted, #f5f5f5))';
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
let _enabled = true;
|
|
2
2
|
export function setCanvasLogsEnabled(enabled) {
|
|
3
3
|
_enabled = enabled;
|
|
4
4
|
}
|
|
5
5
|
export function isCanvasLogsEnabled() {
|
|
6
6
|
return _enabled;
|
|
7
7
|
}
|
|
8
|
-
export function canvasLog() {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i] = arguments[_i];
|
|
12
|
-
}
|
|
8
|
+
export function canvasLog(...args) {
|
|
13
9
|
if (_enabled)
|
|
14
|
-
console.log
|
|
10
|
+
console.log(...args);
|
|
15
11
|
}
|
|
16
|
-
export function canvasWarn() {
|
|
17
|
-
var args = [];
|
|
18
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
|
-
args[_i] = arguments[_i];
|
|
20
|
-
}
|
|
12
|
+
export function canvasWarn(...args) {
|
|
21
13
|
if (_enabled)
|
|
22
|
-
console.warn
|
|
14
|
+
console.warn(...args);
|
|
23
15
|
}
|
|
24
|
-
export function canvasDebug() {
|
|
25
|
-
var args = [];
|
|
26
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
27
|
-
args[_i] = arguments[_i];
|
|
28
|
-
}
|
|
16
|
+
export function canvasDebug(...args) {
|
|
29
17
|
if (_enabled)
|
|
30
|
-
console.debug
|
|
18
|
+
console.debug(...args);
|
|
31
19
|
}
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { ZOOM_CONTROL_MIN_WIDTHS, ZOOM_CONTROL_VISIBLE_FROM } from './ui/floatingCard.js';
|
|
21
21
|
/** The eight places a card can stand. */
|
|
22
|
-
export
|
|
22
|
+
export const CHROME_ANCHORS = ['TL', 'TC', 'TR', 'CL', 'CR', 'BL', 'BC', 'BR'];
|
|
23
23
|
/**
|
|
24
24
|
* The classes that put an anchor in place, 16 px from the edges as the Figma design has it. Written out in full, so that
|
|
25
25
|
* the stylesheet of a page that installs the canvas picks every one of them up when it reads this file.
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
const ANCHOR_CLASSES = {
|
|
28
28
|
// rtl-ok: the page names a corner of the screen, as it is drawn
|
|
29
29
|
TL: 'absolute top-4 left-4',
|
|
30
30
|
TC: 'absolute top-4 left-1/2 -translate-x-1/2',
|
|
@@ -45,9 +45,9 @@ var ANCHOR_CLASSES = {
|
|
|
45
45
|
* are against), a column on a side edge (centred on each other, so the layout does not depend on the direction of the
|
|
46
46
|
* page). A slot never grows larger than the board minus its 16 px edges.
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const SLOT_TOP_ROW_CLASSES = 'flex flex-row items-start gap-2 max-w-[calc(100%-2rem)]';
|
|
49
|
+
const SLOT_BOTTOM_ROW_CLASSES = 'flex flex-row items-end gap-2 max-w-[calc(100%-2rem)]';
|
|
50
|
+
const SLOT_COLUMN_CLASSES = 'flex flex-col items-center gap-2 max-h-[calc(100%-2rem)]';
|
|
51
51
|
/** The anchor to use for what a page passed: anything that is not one of the eight is the fallback, so a mistyped option never takes a card off the board. */
|
|
52
52
|
export function normalizeAnchor(value, fallback) {
|
|
53
53
|
return CHROME_ANCHORS.includes(value) ? value : fallback;
|
|
@@ -77,19 +77,18 @@ export function anchorClasses(anchor) {
|
|
|
77
77
|
* from one anchor to another does not make the other one start again.
|
|
78
78
|
*/
|
|
79
79
|
export function chromeSlots(toolbarAnchor, zoomAnchor, shown) {
|
|
80
|
-
|
|
81
|
-
for (
|
|
82
|
-
|
|
83
|
-
var cards = [];
|
|
80
|
+
const slots = [];
|
|
81
|
+
for (const anchor of CHROME_ANCHORS) {
|
|
82
|
+
const cards = [];
|
|
84
83
|
if (shown.toolbar && toolbarAnchor === anchor)
|
|
85
84
|
cards.push('toolbar');
|
|
86
85
|
if (shown.zoom && zoomAnchor === anchor)
|
|
87
86
|
cards.push('zoom');
|
|
88
87
|
if (cards.length === 0)
|
|
89
88
|
continue;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
slots.push({ anchor
|
|
89
|
+
const vertical = isSideAnchor(anchor);
|
|
90
|
+
const layout = vertical ? SLOT_COLUMN_CLASSES : isTopAnchor(anchor) ? SLOT_TOP_ROW_CLASSES : SLOT_BOTTOM_ROW_CLASSES;
|
|
91
|
+
slots.push({ anchor, cards, vertical, classes: `${ANCHOR_CLASSES[anchor]} ${layout}` });
|
|
93
92
|
}
|
|
94
93
|
return slots;
|
|
95
94
|
}
|
|
@@ -102,8 +101,8 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
|
|
|
102
101
|
// A card on a side edge shares no line with a card on the top or the bottom edge, and neither do two cards on different edges.
|
|
103
102
|
if (isSideAnchor(toolbarAnchor) || isSideAnchor(zoomAnchor) || toolbarAnchor[0] !== zoomAnchor[0])
|
|
104
103
|
return ZOOM_CONTROL_VISIBLE_FROM.alone;
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const toolbarColumn = toolbarAnchor[1];
|
|
105
|
+
const zoomColumn = zoomAnchor[1];
|
|
107
106
|
if (toolbarColumn === zoomColumn)
|
|
108
107
|
return ZOOM_CONTROL_VISIBLE_FROM.sameSlot;
|
|
109
108
|
if (toolbarColumn === 'C')
|
|
@@ -114,7 +113,7 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
|
|
|
114
113
|
}
|
|
115
114
|
/** Minimum board width (px) before the zoom card is drawn; pairs with scoped `@container` CSS in `ZoomControl.svelte`. */
|
|
116
115
|
export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
|
|
117
|
-
|
|
116
|
+
const className = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
|
|
118
117
|
if (className === ZOOM_CONTROL_VISIBLE_FROM.alone)
|
|
119
118
|
return ZOOM_CONTROL_MIN_WIDTHS.alone;
|
|
120
119
|
if (className === ZOOM_CONTROL_VISIBLE_FROM.sameSlot)
|
|
@@ -131,19 +130,18 @@ export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
|
|
|
131
130
|
* out in full, so that the stylesheet of a page that installs the canvas picks both up.
|
|
132
131
|
*/
|
|
133
132
|
export function selectorIndicatorTopClassFor(slots) {
|
|
134
|
-
return slots.some(
|
|
133
|
+
return slots.some((slot) => slot.anchor === 'TC') ? 'top-16' : 'top-4';
|
|
135
134
|
}
|
|
136
|
-
|
|
135
|
+
const TOP_PANEL_CONFLICT_ANCHORS = new Set(['TC', 'TR']);
|
|
137
136
|
/**
|
|
138
137
|
* What the panel keeps clear of, for the slots that are drawn. The selector's indicator, when it is shown, stands across the
|
|
139
138
|
* top centre (it can be as wide as the board), so the panel starts below it as it does below a card of the top edge.
|
|
140
139
|
*/
|
|
141
|
-
export function panelClearanceFor(slots, options) {
|
|
142
|
-
|
|
143
|
-
var rightEdgeSlot = slots.find(function (slot) { return slot.anchor === 'CR'; });
|
|
140
|
+
export function panelClearanceFor(slots, options = {}) {
|
|
141
|
+
const rightEdgeSlot = slots.find((slot) => slot.anchor === 'CR');
|
|
144
142
|
return {
|
|
145
143
|
// Top-left chrome (e.g. zoom on the creator big page) does not overlap the top-right selection panel.
|
|
146
|
-
belowTopCards: options.selectorIndicator === true || slots.some(
|
|
144
|
+
belowTopCards: options.selectorIndicator === true || slots.some((slot) => TOP_PANEL_CONFLICT_ANCHORS.has(slot.anchor)),
|
|
147
145
|
besideSideCard: rightEdgeSlot ? (rightEdgeSlot.cards.includes('toolbar') ? 'toolbar' : 'zoom') : null
|
|
148
146
|
};
|
|
149
147
|
}
|
|
@@ -16,10 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
/** The shadow root a node lives in, or null when it lives in the page itself (or is not in a tree at all). */
|
|
18
18
|
export function getShadowRootOf(node) {
|
|
19
|
-
|
|
20
|
-
var root = (_a = node === null || node === void 0 ? void 0 : node.getRootNode) === null || _a === void 0 ? void 0 : _a.call(node);
|
|
19
|
+
const root = node?.getRootNode?.();
|
|
21
20
|
// (`instanceof ShadowRoot` would not hold for a root made by another window, an iframe's, say.)
|
|
22
|
-
|
|
21
|
+
const isShadowRoot = !!root && root.nodeType === 11 && 'host' in root;
|
|
23
22
|
return isShadowRoot ? root : null;
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
@@ -32,14 +31,14 @@ export function getShadowRootOf(node) {
|
|
|
32
31
|
* Has to be called while the event is being dispatched (`composedPath()` is empty afterwards).
|
|
33
32
|
*/
|
|
34
33
|
export function eventIsForScope(event, scopeNode) {
|
|
35
|
-
|
|
34
|
+
const shadowRoot = getShadowRootOf(scopeNode);
|
|
36
35
|
if (!shadowRoot)
|
|
37
36
|
return true;
|
|
38
37
|
return event.composedPath().includes(shadowRoot);
|
|
39
38
|
}
|
|
40
39
|
/** The element that has the focus in the tree `scopeNode` lives in: the page's, or the shadow root's own. */
|
|
41
40
|
export function getFocusedElementIn(scopeNode) {
|
|
42
|
-
|
|
41
|
+
const shadowRoot = getShadowRootOf(scopeNode);
|
|
43
42
|
return shadowRoot ? shadowRoot.activeElement : document.activeElement;
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
@@ -47,8 +46,7 @@ export function getFocusedElementIn(scopeNode) {
|
|
|
47
46
|
* event from inside a shadow root; the first element of the path is the one that was pressed.
|
|
48
47
|
*/
|
|
49
48
|
export function getEventOrigin(event) {
|
|
50
|
-
|
|
51
|
-
var first = (_a = event.composedPath()[0]) !== null && _a !== void 0 ? _a : event.target;
|
|
49
|
+
const first = event.composedPath()[0] ?? event.target;
|
|
52
50
|
return first && first.nodeType === 1 ? first : null;
|
|
53
51
|
}
|
|
54
52
|
/**
|
|
@@ -66,8 +64,7 @@ export function eventWentThrough(event, element) {
|
|
|
66
64
|
* page never sees it, and otherwise `document.body`.
|
|
67
65
|
*/
|
|
68
66
|
export function getTransientHostFor(scopeNode) {
|
|
69
|
-
|
|
70
|
-
return (_a = getShadowRootOf(scopeNode)) !== null && _a !== void 0 ? _a : document.body;
|
|
67
|
+
return getShadowRootOf(scopeNode) ?? document.body;
|
|
71
68
|
}
|
|
72
69
|
/**
|
|
73
70
|
* Whether the canvas whose element is `scopeNode` should take the keyboard back after the element that held it went away
|
|
@@ -79,15 +76,14 @@ export function getTransientHostFor(scopeNode) {
|
|
|
79
76
|
* the shortcuts do not mind where the focus is, so there is nothing to do.
|
|
80
77
|
*/
|
|
81
78
|
export function shouldTakeFocusBack(scopeNode) {
|
|
82
|
-
|
|
83
|
-
var shadowRoot = getShadowRootOf(scopeNode);
|
|
79
|
+
const shadowRoot = getShadowRootOf(scopeNode);
|
|
84
80
|
if (!shadowRoot)
|
|
85
81
|
return false;
|
|
86
82
|
if (shadowRoot.activeElement)
|
|
87
83
|
return false;
|
|
88
84
|
// The focus in the tree the shadow root's host is in (the page's, or another shadow root's).
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
const outerTree = shadowRoot.host.getRootNode();
|
|
86
|
+
const focusOutside = outerTree.activeElement;
|
|
87
|
+
const outerBody = outerTree.body ?? null;
|
|
92
88
|
return !focusOutside || focusOutside === shadowRoot.host || focusOutside === outerBody;
|
|
93
89
|
}
|
|
@@ -20,12 +20,11 @@ import type { EngineState, PenStyle, ToolId } from '../../engine/state.js';
|
|
|
20
20
|
import { ConversionRegistry } from '../../engine/widgets.js';
|
|
21
21
|
import type { WidgetMetadata } from '../../engine/widgets.js';
|
|
22
22
|
import { type WorkspaceCanvasFont } from '../../fonts/workspaceFonts.js';
|
|
23
|
-
import type { StylePatch } from '../../engine/core/style.js';
|
|
24
23
|
import type { PanZoomPosition } from '../panZoomPosition.js';
|
|
25
24
|
import type { ToolbarPosition } from '../toolbarPosition.js';
|
|
26
25
|
import type { Translate as CatalogTranslate } from '@widgetic/design-system/i18n';
|
|
27
26
|
import type { CanvasMessageKey } from '../../i18n/messages.js';
|
|
28
|
-
import type { CanvasFlyOptions, CanvasMoveOptions, ObjectClickPayload, StrokeRecognizer } from '../types.js';
|
|
27
|
+
import type { CanvasClearCause, CanvasFlyOptions, CanvasMoveOptions, ObjectClickPayload, StrokeRecognizer } from '../types.js';
|
|
29
28
|
import type { BoardFilePicker, BoardLibraryFile, BoardPicture, BoardPictureLibraryFile } from './boardFiles.js';
|
|
30
29
|
import type { LoadedImageFile } from './browserServices.js';
|
|
31
30
|
import type { HostObject } from './hostObject.js';
|
|
@@ -101,7 +100,11 @@ export interface CanvasHostProps {
|
|
|
101
100
|
suspendAutosave: boolean;
|
|
102
101
|
showSaveButton: boolean;
|
|
103
102
|
onCanvasDirty: (() => void) | null;
|
|
104
|
-
|
|
103
|
+
/**
|
|
104
|
+
* The board was emptied. `cause` says by whom: the page (`onClearAllObjects()`: `'clear-all'`) or the person (their delete or cut took
|
|
105
|
+
* the last object: `'deleted'`). A handler that takes no argument hears both. Called after `onCanvasDirty` of the same change.
|
|
106
|
+
*/
|
|
107
|
+
onCanvasCleared: ((cause: CanvasClearCause) => void) | null;
|
|
105
108
|
onWidgetImageClick: ((widgetId: string) => void) | null;
|
|
106
109
|
onRecognizeStroke: StrokeRecognizer | null;
|
|
107
110
|
onNonWidgetSelected: (() => void) | null;
|
|
@@ -230,8 +233,6 @@ export declare class CanvasHost {
|
|
|
230
233
|
constructor(initialProps?: Partial<CanvasHostProps>);
|
|
231
234
|
/** The page changed some props. */
|
|
232
235
|
setProps(patch: Partial<CanvasHostProps>): void;
|
|
233
|
-
/** Persists tool style changes for this workspace (called from the selection panel). */
|
|
234
|
-
persistWorkspaceStyle(patch: StylePatch): void;
|
|
235
236
|
/**
|
|
236
237
|
* Sets the pen, the line the Draw tool draws next (its colour, its width, how much of the board shows through it), and keeps it
|
|
237
238
|
* for this workspace, so the pen is the same when the page is opened again. The settings panel calls it while the Draw tool is
|