@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
|
@@ -1,54 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workspace brand-kit fonts registered for the canvas font picker (item B15).
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
-
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);
|
|
15
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
-
function step(op) {
|
|
18
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
-
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;
|
|
21
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
-
switch (op[0]) {
|
|
23
|
-
case 0: case 1: t = op; break;
|
|
24
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
-
default:
|
|
28
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
-
if (t[2]) _.ops.pop();
|
|
33
|
-
_.trys.pop(); continue;
|
|
34
|
-
}
|
|
35
|
-
op = body.call(thisArg, _);
|
|
36
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var registered = new Set();
|
|
4
|
+
const registered = new Set();
|
|
41
5
|
/** The registration that is under way (or the last one that was): the next list waits for it, so fonts are never loaded twice. */
|
|
42
|
-
|
|
6
|
+
let registerQueue = Promise.resolve();
|
|
43
7
|
function familyKey(font) {
|
|
44
|
-
|
|
45
|
-
return "".concat(font.family, "|").concat((_a = font.weight) !== null && _a !== void 0 ? _a : '400', "|").concat((_b = font.style) !== null && _b !== void 0 ? _b : 'normal');
|
|
8
|
+
return `${font.family}|${font.weight ?? '400'}|${font.style ?? 'normal'}`;
|
|
46
9
|
}
|
|
47
10
|
export function listWorkspaceFontFamilies(fonts) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (
|
|
51
|
-
var font = fonts_1[_i];
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const font of fonts) {
|
|
52
14
|
if (!font.family || seen.has(font.family))
|
|
53
15
|
continue;
|
|
54
16
|
seen.add(font.family);
|
|
@@ -57,58 +19,37 @@ export function listWorkspaceFontFamilies(fonts) {
|
|
|
57
19
|
return out;
|
|
58
20
|
}
|
|
59
21
|
/** How long a font file gets to arrive before it is given up on (until a later list tries it again). */
|
|
60
|
-
|
|
22
|
+
const FONT_LOAD_TIMEOUT_MS = 12_000;
|
|
61
23
|
/** Loads a font face, giving up after `FONT_LOAD_TIMEOUT_MS`; the timer never outlives the load. */
|
|
62
24
|
function loadFaceWithTimeout(face) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
timer = setTimeout(
|
|
25
|
+
let timer;
|
|
26
|
+
const timeUp = new Promise((_, reject) => {
|
|
27
|
+
timer = setTimeout(() => reject(new Error('font load timeout')), FONT_LOAD_TIMEOUT_MS);
|
|
66
28
|
});
|
|
67
|
-
return Promise.race([face.load(), timeUp]).finally(
|
|
29
|
+
return Promise.race([face.load(), timeUp]).finally(() => clearTimeout(timer));
|
|
68
30
|
}
|
|
69
31
|
/** Registers the fonts of one list that are not registered yet, one after the other. A font that fails is left out and tried again by a later list. */
|
|
70
|
-
function registerFontsOnce(fonts) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
weight: String((_a = font.weight) !== null && _a !== void 0 ? _a : '400'),
|
|
92
|
-
style: (_b = font.style) !== null && _b !== void 0 ? _b : 'normal',
|
|
93
|
-
display: 'swap'
|
|
94
|
-
});
|
|
95
|
-
return [4 /*yield*/, loadFaceWithTimeout(face)];
|
|
96
|
-
case 3:
|
|
97
|
-
loaded = _c.sent();
|
|
98
|
-
document.fonts.add(loaded);
|
|
99
|
-
registered.add(key);
|
|
100
|
-
return [3 /*break*/, 5];
|
|
101
|
-
case 4:
|
|
102
|
-
error_1 = _c.sent();
|
|
103
|
-
console.warn("Canvas: workspace font \"".concat(font.family, "\" could not load"), error_1);
|
|
104
|
-
return [3 /*break*/, 5];
|
|
105
|
-
case 5:
|
|
106
|
-
_i++;
|
|
107
|
-
return [3 /*break*/, 1];
|
|
108
|
-
case 6: return [2 /*return*/];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
32
|
+
async function registerFontsOnce(fonts) {
|
|
33
|
+
for (const font of fonts) {
|
|
34
|
+
const key = familyKey(font);
|
|
35
|
+
if (registered.has(key) || !font.url)
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
const format = font.format ? ` format('${font.format}')` : '';
|
|
39
|
+
const source = `url(${JSON.stringify(font.url)})${format}`;
|
|
40
|
+
const face = new FontFace(font.family, source, {
|
|
41
|
+
weight: String(font.weight ?? '400'),
|
|
42
|
+
style: font.style ?? 'normal',
|
|
43
|
+
display: 'swap'
|
|
44
|
+
});
|
|
45
|
+
const loaded = await loadFaceWithTimeout(face);
|
|
46
|
+
document.fonts.add(loaded);
|
|
47
|
+
registered.add(key);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.warn(`Canvas: workspace font "${font.family}" could not load`, error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
112
53
|
}
|
|
113
54
|
/**
|
|
114
55
|
* Registers the brand-kit fonts with the browser, so a text set in one is drawn in it. The page loads its brand kit after the
|
|
@@ -120,6 +61,6 @@ export function registerWorkspaceFonts(fonts) {
|
|
|
120
61
|
if (typeof document === 'undefined' || typeof FontFace === 'undefined')
|
|
121
62
|
return Promise.resolve();
|
|
122
63
|
// `registerFontsOnce` never rejects (each font is tried inside its own try/catch), so the queue never stays broken.
|
|
123
|
-
registerQueue = registerQueue.then(
|
|
64
|
+
registerQueue = registerQueue.then(() => registerFontsOnce(fonts));
|
|
124
65
|
return registerQueue;
|
|
125
66
|
}
|
package/dist/i18n/labels.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getShapeByKey } from '../canvas/shapes/ShapeLibrary.js';
|
|
2
2
|
// The groups of the shape library are kept under their English names (a shape of a saved canvas knows its group by that
|
|
3
3
|
// name); this says each in the page's language.
|
|
4
|
-
|
|
4
|
+
const CATEGORY_KEYS = {
|
|
5
5
|
'Geometric Shapes': 'canvas.category.geometric',
|
|
6
6
|
'Arrow Shapes': 'canvas.category.arrows',
|
|
7
7
|
'Media Icons': 'canvas.category.media',
|
|
@@ -11,14 +11,14 @@ var CATEGORY_KEYS = {
|
|
|
11
11
|
/** The name of a group of the shape library, by the English name the library keeps it under. */
|
|
12
12
|
export function categoryLabel(category, t) {
|
|
13
13
|
// Only the table's own entries: a group called "constructor" is not a method of the table.
|
|
14
|
-
|
|
14
|
+
const key = Object.prototype.hasOwnProperty.call(CATEGORY_KEYS, category) ? CATEGORY_KEYS[category] : undefined;
|
|
15
15
|
return key ? t(key) : category;
|
|
16
16
|
}
|
|
17
17
|
/** The name of a library shape the library no longer knows (an old save): its key as words ("arrow-right" → "Arrow Right"). */
|
|
18
18
|
function wordsOfKey(shapeKey) {
|
|
19
19
|
return shapeKey
|
|
20
20
|
.split('-')
|
|
21
|
-
.map(
|
|
21
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
22
22
|
.join(' ');
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -49,7 +49,7 @@ export function objectName(object, t) {
|
|
|
49
49
|
return t('canvas.tool.triangle');
|
|
50
50
|
if (object.shape === 'arrow')
|
|
51
51
|
return t('canvas.tool.arrow');
|
|
52
|
-
|
|
52
|
+
const known = getShapeByKey(object.shape);
|
|
53
53
|
return t('canvas.type.drawingOf', { name: known ? t(known.labelKey) : wordsOfKey(object.shape) });
|
|
54
54
|
}
|
|
55
55
|
}
|
package/dist/i18n/language.js
CHANGED
|
@@ -6,23 +6,23 @@ import { CANVAS_MESSAGES } from './messages.js';
|
|
|
6
6
|
* canvas) reads its words from it (`useCanvasLanguage`). The context belongs to one root, so two canvases on a page can
|
|
7
7
|
* speak two languages.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const canvasWords = createI18n({ catalog: CANVAS_MESSAGES, label: 'Canvas' });
|
|
10
10
|
/**
|
|
11
11
|
* Called by the root component of a canvas while it is created, so everything inside it speaks the page's language.
|
|
12
12
|
* It gives back the words as stores and `update(settings)` for when the page sets the language again.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export const provideCanvasLanguage = canvasWords.provideI18n;
|
|
15
15
|
/**
|
|
16
16
|
* Called by a part of the canvas while it is created. Gives its words as stores, so a part that is already on the screen
|
|
17
17
|
* changes when the page sets the language again. Outside a canvas (a part used on its own, such as the colour control)
|
|
18
18
|
* it speaks English.
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
20
|
+
export const useCanvasLanguage = canvasWords.useI18n;
|
|
21
21
|
/**
|
|
22
22
|
* The English `t` of the canvas, for code that has no component around it. The screens of the canvas get their words, in
|
|
23
23
|
* the page's language, from `useCanvasLanguage`.
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export const translateEnglish = canvasWords.translateEnglish;
|
|
26
26
|
/**
|
|
27
27
|
* Checks a page's `messages` against the canvas's catalog without showing anything: a key that does not exist (with the
|
|
28
28
|
* nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
|
package/dist/i18n/messages.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* - the English names the canvas keeps for the things it saves ("libraryShape", "Symbol Shapes", a shape's key): they
|
|
15
15
|
* are data, and a screen says them with the messages below.
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export const CANVAS_MESSAGES = {
|
|
18
18
|
// ===== The canvas itself =====
|
|
19
19
|
'canvas.state.loading': 'Loading canvas…',
|
|
20
20
|
'canvas.state.initFailed': 'Canvas failed to initialize.',
|
package/dist/i18n/shortcuts.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the two cannot disagree. A letter is the same on every keyboard, so it is not a message. `G` is not one of them on purpose: it
|
|
4
4
|
* hides the alignment guides while it is held (the triangle has `Y`).
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export const TOOL_KEYS = {
|
|
7
7
|
select: 'V',
|
|
8
8
|
hand: 'H',
|
|
9
9
|
erase: 'E',
|
|
@@ -21,21 +21,21 @@ export var TOOL_KEYS = {
|
|
|
21
21
|
* toolbar buttons name it in `aria-keyshortcuts`. A digit is the same on every keyboard, so it is not a message either. The
|
|
22
22
|
* engine's table (`TOOL_DIGITS`) is the one that answers the key; a test holds the two together.
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
24
|
+
export const TOOL_DIGIT_KEYS = {
|
|
25
25
|
select: '1',
|
|
26
26
|
draw: '2',
|
|
27
27
|
erase: '3',
|
|
28
28
|
arrow: '4',
|
|
29
29
|
text: '5'
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const named = (name) => ({ name });
|
|
32
|
+
const cap = (text) => ({ cap: text });
|
|
33
|
+
const PLUS = null;
|
|
34
|
+
const CTRL = named('canvas.key.ctrlCmd');
|
|
35
|
+
const ALT = named('canvas.key.alt');
|
|
36
|
+
const SHIFT = named('canvas.key.shift');
|
|
37
37
|
/** The keyboard shortcuts of the canvas, in the order of the list that opens with "?". */
|
|
38
|
-
export
|
|
38
|
+
export const SHORTCUT_GROUPS = [
|
|
39
39
|
{
|
|
40
40
|
title: 'canvas.shortcuts.groupTools',
|
|
41
41
|
shortcuts: [
|
|
@@ -103,11 +103,11 @@ export var SHORTCUT_GROUPS = [
|
|
|
103
103
|
];
|
|
104
104
|
/** The list of keyboard shortcuts in the page's language. */
|
|
105
105
|
export function shortcutGroups(t) {
|
|
106
|
-
return SHORTCUT_GROUPS.map(
|
|
106
|
+
return SHORTCUT_GROUPS.map((group) => ({
|
|
107
107
|
title: t(group.title),
|
|
108
|
-
shortcuts: group.shortcuts.map(
|
|
108
|
+
shortcuts: group.shortcuts.map((shortcut) => ({
|
|
109
109
|
label: t(shortcut.label),
|
|
110
|
-
keys: shortcut.keys.map(
|
|
111
|
-
})
|
|
112
|
-
})
|
|
110
|
+
keys: shortcut.keys.map((key) => (key === null ? null : 'name' in key ? t(key.name) : key.cap))
|
|
111
|
+
}))
|
|
112
|
+
}));
|
|
113
113
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Dynamic: const { Canvas } = await import('@widgetic/canvas')
|
|
8
8
|
*/
|
|
9
9
|
export { Canvas } from './canvas';
|
|
10
|
-
export type { WidgetConversionPayload, StrokeRecognizer, StrokeRecognitionRequest, StrokeRecognitionResult, CanvasFlyOptions, CanvasMoveOptions } from './canvas';
|
|
10
|
+
export type { WidgetConversionPayload, StrokeRecognizer, StrokeRecognitionRequest, StrokeRecognitionResult, CanvasClearCause, CanvasFlyOptions, CanvasMoveOptions } from './canvas';
|
|
11
11
|
export type { BoardFileKind, BoardFilePickRequest, BoardFilePicker, BoardLibraryFile, BoardPicture, BoardPictureLibraryFile } from './canvas';
|
|
12
12
|
export { TOOLBAR_POSITIONS, DEFAULT_TOOLBAR_POSITION } from './canvas';
|
|
13
13
|
export type { ToolbarPosition } from './canvas';
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* placement is only used in the layout it was measured in. One that is missing, damaged or from another layout is nothing: the
|
|
16
16
|
* page draws its empty board as before and the creator draws the rest when it arrives.
|
|
17
17
|
*
|
|
18
|
-
* It holds nothing private: pixel distances
|
|
18
|
+
* It holds nothing private: pixel distances, the toolbar's place, and the workspace key the canvas already keeps its own choices under.
|
|
19
19
|
*/
|
|
20
20
|
/** Where the placement is kept. The page and the creator are separate programs on one origin, so they meet here. */
|
|
21
21
|
export declare const BOARD_PLACEMENT_STORAGE_KEY = "widgetic.canvas.boardPlacement";
|
|
@@ -42,6 +42,8 @@ export interface BoardPlacement {
|
|
|
42
42
|
toolbarPosition: string | null;
|
|
43
43
|
/** Whether the board shows the drawing tools (the toolbar placeholder draws nothing without them). */
|
|
44
44
|
showDrawingTools: boolean;
|
|
45
|
+
/** The workspace the canvas keeps its choices under (the tool that is on when the board opens), or null. */
|
|
46
|
+
workspaceId: string | null;
|
|
45
47
|
}
|
|
46
48
|
/** The part of a DOM rectangle this file reads. */
|
|
47
49
|
export interface PlacementRect {
|
|
@@ -56,6 +58,7 @@ export interface BoardPlacementDetails {
|
|
|
56
58
|
viewportWidth: number;
|
|
57
59
|
toolbarPosition?: string | null;
|
|
58
60
|
showDrawingTools?: boolean;
|
|
61
|
+
workspaceId?: string | null;
|
|
59
62
|
}
|
|
60
63
|
/** The part of `Storage` this file uses (a test hands in a map). */
|
|
61
64
|
export interface PlacementStorage {
|
|
@@ -15,19 +15,19 @@
|
|
|
15
15
|
* placement is only used in the layout it was measured in. One that is missing, damaged or from another layout is nothing: the
|
|
16
16
|
* page draws its empty board as before and the creator draws the rest when it arrives.
|
|
17
17
|
*
|
|
18
|
-
* It holds nothing private: pixel distances
|
|
18
|
+
* It holds nothing private: pixel distances, the toolbar's place, and the workspace key the canvas already keeps its own choices under.
|
|
19
19
|
*/
|
|
20
20
|
/** Where the placement is kept. The page and the creator are separate programs on one origin, so they meet here. */
|
|
21
|
-
export
|
|
22
|
-
export
|
|
21
|
+
export const BOARD_PLACEMENT_STORAGE_KEY = 'widgetic.canvas.boardPlacement';
|
|
22
|
+
export const BOARD_PLACEMENT_VERSION = 1;
|
|
23
23
|
/** The window width from which the chat stands beside the board. */
|
|
24
|
-
export
|
|
24
|
+
export const WIDE_LAYOUT_MIN_WIDTH = 1024;
|
|
25
25
|
/** The window width from which the chat stands below the board. */
|
|
26
|
-
export
|
|
26
|
+
export const MEDIUM_LAYOUT_MIN_WIDTH = 768;
|
|
27
27
|
/** The most a distance may be (a placement with more is not a board card, it is a measurement gone wrong). */
|
|
28
|
-
|
|
28
|
+
const MAX_DISTANCE = 2_000;
|
|
29
29
|
/** The smallest board a placement may describe, in CSS pixels on each side. */
|
|
30
|
-
|
|
30
|
+
const MIN_BOARD_SIDE = 120;
|
|
31
31
|
/** The layout the creator is in at this window width. */
|
|
32
32
|
export function boardLayoutOf(viewportWidth) {
|
|
33
33
|
if (viewportWidth >= WIDE_LAYOUT_MIN_WIDTH)
|
|
@@ -44,52 +44,52 @@ function distanceIsUsable(value) {
|
|
|
44
44
|
* size, the board lies outside the host, or it is too small to be a board.
|
|
45
45
|
*/
|
|
46
46
|
export function measureBoardPlacement(host, board, details) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
const top = Math.round(board.top - host.top);
|
|
48
|
+
const left = Math.round(board.left - host.left);
|
|
49
|
+
const right = Math.round(host.right - board.right);
|
|
50
|
+
const bottom = Math.round(host.bottom - board.bottom);
|
|
51
51
|
if (![top, right, bottom, left].every(distanceIsUsable))
|
|
52
52
|
return null;
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const boardWidth = host.right - host.left - left - right;
|
|
54
|
+
const boardHeight = host.bottom - host.top - top - bottom;
|
|
55
55
|
if (!(boardWidth >= MIN_BOARD_SIDE) || !(boardHeight >= MIN_BOARD_SIDE))
|
|
56
56
|
return null;
|
|
57
57
|
return {
|
|
58
58
|
version: BOARD_PLACEMENT_VERSION,
|
|
59
59
|
layout: boardLayoutOf(details.viewportWidth),
|
|
60
|
-
top
|
|
61
|
-
right
|
|
62
|
-
bottom
|
|
63
|
-
left
|
|
60
|
+
top,
|
|
61
|
+
right,
|
|
62
|
+
bottom,
|
|
63
|
+
left,
|
|
64
64
|
toolbarPosition: typeof details.toolbarPosition === 'string' && details.toolbarPosition.length <= 8 ? details.toolbarPosition : null,
|
|
65
|
-
showDrawingTools: details.showDrawingTools !== false
|
|
65
|
+
showDrawingTools: details.showDrawingTools !== false,
|
|
66
|
+
workspaceId: typeof details.workspaceId === 'string' && details.workspaceId.length <= 200 ? details.workspaceId : null
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
function defaultStorage() {
|
|
69
70
|
try {
|
|
70
71
|
return typeof localStorage === 'undefined' ? null : localStorage;
|
|
71
72
|
}
|
|
72
|
-
catch
|
|
73
|
+
catch {
|
|
73
74
|
// A sandboxed frame refuses even the lookup.
|
|
74
75
|
return null;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
/** What was written last by this page, so a placement that has not changed is not written again (a measurement is taken at every save). */
|
|
78
|
-
|
|
79
|
+
let lastWritten = null;
|
|
79
80
|
/** Keeps the placement for the next visit. Writes only what changed. Returns whether it wrote. Never throws. */
|
|
80
|
-
export function rememberBoardPlacement(placement, storage) {
|
|
81
|
-
if (storage === void 0) { storage = defaultStorage(); }
|
|
81
|
+
export function rememberBoardPlacement(placement, storage = defaultStorage()) {
|
|
82
82
|
if (!storage)
|
|
83
83
|
return false;
|
|
84
84
|
try {
|
|
85
|
-
|
|
85
|
+
const text = JSON.stringify(placement);
|
|
86
86
|
if (text === lastWritten)
|
|
87
87
|
return false;
|
|
88
88
|
storage.setItem(BOARD_PLACEMENT_STORAGE_KEY, text);
|
|
89
89
|
lastWritten = text;
|
|
90
90
|
return true;
|
|
91
91
|
}
|
|
92
|
-
catch
|
|
92
|
+
catch {
|
|
93
93
|
// Storage is full or refused: the next visit draws the empty board, as it did before the placement existed.
|
|
94
94
|
return false;
|
|
95
95
|
}
|
|
@@ -98,18 +98,17 @@ export function rememberBoardPlacement(placement, storage) {
|
|
|
98
98
|
* The placement kept by the last visit, for the layout the window is in now. Null when none was kept, it is damaged, or it was
|
|
99
99
|
* measured in another layout (its distances would put the board in the wrong place).
|
|
100
100
|
*/
|
|
101
|
-
export function recallBoardPlacement(viewportWidth, storage) {
|
|
102
|
-
if (storage === void 0) { storage = defaultStorage(); }
|
|
101
|
+
export function recallBoardPlacement(viewportWidth, storage = defaultStorage()) {
|
|
103
102
|
if (!storage)
|
|
104
103
|
return null;
|
|
105
104
|
try {
|
|
106
|
-
|
|
105
|
+
const text = storage.getItem(BOARD_PLACEMENT_STORAGE_KEY);
|
|
107
106
|
if (!text)
|
|
108
107
|
return null;
|
|
109
|
-
|
|
108
|
+
const value = JSON.parse(text);
|
|
110
109
|
if (typeof value !== 'object' || value === null)
|
|
111
110
|
return null;
|
|
112
|
-
|
|
111
|
+
const record = value;
|
|
113
112
|
if (record.version !== BOARD_PLACEMENT_VERSION)
|
|
114
113
|
return null;
|
|
115
114
|
if (record.layout !== boardLayoutOf(viewportWidth))
|
|
@@ -118,7 +117,8 @@ export function recallBoardPlacement(viewportWidth, storage) {
|
|
|
118
117
|
return null;
|
|
119
118
|
if (typeof record.showDrawingTools !== 'boolean')
|
|
120
119
|
return null;
|
|
121
|
-
|
|
120
|
+
const toolbarPosition = typeof record.toolbarPosition === 'string' && record.toolbarPosition.length <= 8 ? record.toolbarPosition : null;
|
|
121
|
+
const workspaceId = typeof record.workspaceId === 'string' && record.workspaceId.length <= 200 ? record.workspaceId : null;
|
|
122
122
|
return {
|
|
123
123
|
version: BOARD_PLACEMENT_VERSION,
|
|
124
124
|
layout: record.layout,
|
|
@@ -126,11 +126,12 @@ export function recallBoardPlacement(viewportWidth, storage) {
|
|
|
126
126
|
right: record.right,
|
|
127
127
|
bottom: record.bottom,
|
|
128
128
|
left: record.left,
|
|
129
|
-
toolbarPosition
|
|
130
|
-
showDrawingTools: record.showDrawingTools
|
|
129
|
+
toolbarPosition,
|
|
130
|
+
showDrawingTools: record.showDrawingTools,
|
|
131
|
+
workspaceId
|
|
131
132
|
};
|
|
132
133
|
}
|
|
133
|
-
catch
|
|
134
|
+
catch {
|
|
134
135
|
return null;
|
|
135
136
|
}
|
|
136
137
|
}
|