@widgetic/canvas 0.5.45 → 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/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 -2
- package/dist/canvas/host/CanvasHost.js +1615 -1847
- 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/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/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +21 -21
- 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.js +35 -41
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- 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/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +9 -2
- package/dist/engine/EngineCore.js +798 -907
- 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.js +84 -96
- 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.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +32 -65
- 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.js +267 -310
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +35 -39
- 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.js +28 -30
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +8 -0
- package/dist/settings/workspaceToolSettings.js +35 -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 +11 -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 +2 -2
|
@@ -10,53 +10,6 @@
|
|
|
10
10
|
*
|
|
11
11
|
* The functions are plain TypeScript over the engine's records, so they run (and are tested) in Node.
|
|
12
12
|
*/
|
|
13
|
-
var __assign = (this && this.__assign) || function () {
|
|
14
|
-
__assign = Object.assign || function(t) {
|
|
15
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
16
|
-
s = arguments[i];
|
|
17
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
18
|
-
t[p] = s[p];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
return __assign.apply(this, arguments);
|
|
23
|
-
};
|
|
24
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
25
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
34
|
-
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);
|
|
35
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
36
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
37
|
-
function step(op) {
|
|
38
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
39
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
40
|
-
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;
|
|
41
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
42
|
-
switch (op[0]) {
|
|
43
|
-
case 0: case 1: t = op; break;
|
|
44
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
45
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
46
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
47
|
-
default:
|
|
48
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
49
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
50
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
51
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
52
|
-
if (t[2]) _.ops.pop();
|
|
53
|
-
_.trys.pop(); continue;
|
|
54
|
-
}
|
|
55
|
-
op = body.call(thisArg, _);
|
|
56
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
57
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
13
|
import { brushCentreline, isBrushStroke } from '../../engine/core/brush.js';
|
|
61
14
|
import { outlineBounds } from '../../engine/core/hitTest.js';
|
|
62
15
|
import { parsePathData } from '../../engine/core/pathData.js';
|
|
@@ -70,8 +23,7 @@ import { CANVAS_SHAPE_SNAP_ENABLED, CANVAS_SNAP_SHAPE_LABELS, confidentSnapShape
|
|
|
70
23
|
* (`CANVAS_SHAPE_SNAP_ENABLED`, false as shipped) turns it on for every page when it is flipped, which is the one
|
|
71
24
|
* line to roll the behaviour out or back. The flag is a parameter so a test can hold both of its values.
|
|
72
25
|
*/
|
|
73
|
-
export function isShapeSnapOn(pageAsked, packageFlag) {
|
|
74
|
-
if (packageFlag === void 0) { packageFlag = CANVAS_SHAPE_SNAP_ENABLED; }
|
|
26
|
+
export function isShapeSnapOn(pageAsked, packageFlag = CANVAS_SHAPE_SNAP_ENABLED) {
|
|
75
27
|
return packageFlag === true || pageAsked === true;
|
|
76
28
|
}
|
|
77
29
|
/**
|
|
@@ -82,71 +34,67 @@ export function isShapeSnapOn(pageAsked, packageFlag) {
|
|
|
82
34
|
*/
|
|
83
35
|
export function strokeMeasurementPoints(stroke, handLine) {
|
|
84
36
|
if (handLine && handLine.length >= 2)
|
|
85
|
-
return handLine.map(
|
|
37
|
+
return handLine.map((point) => ({ x: point.x - stroke.x, y: point.y - stroke.y }));
|
|
86
38
|
if (isBrushStroke(stroke))
|
|
87
39
|
return brushCentreline(stroke);
|
|
88
40
|
return flattenPathCommands(parsePathData(stroke.d));
|
|
89
41
|
}
|
|
90
42
|
/** What the geometry says about a stroke: its measurements, or null when it is too small or too plain to measure. */
|
|
91
43
|
export function measureDrawnStroke(stroke, handLine) {
|
|
92
|
-
|
|
44
|
+
const points = strokeMeasurementPoints(stroke, handLine);
|
|
93
45
|
if (points.length < 2)
|
|
94
46
|
return null;
|
|
95
|
-
|
|
47
|
+
const measurements = measureStroke(points);
|
|
96
48
|
if (!measurements)
|
|
97
49
|
return null;
|
|
98
|
-
return { points
|
|
50
|
+
return { points, measurements };
|
|
99
51
|
}
|
|
100
52
|
/**
|
|
101
53
|
* Decides whether a stroke is a clean shape. Resolves to null for "leave it as drawn".
|
|
102
54
|
* Deliberately never rejects.
|
|
103
55
|
*/
|
|
104
|
-
export function decideStrokeSnap(stroke, context, handLine) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
case 1:
|
|
132
|
-
answer = _g.sent();
|
|
133
|
-
named_1 = (_c = answer === null || answer === void 0 ? void 0 : answer.shape) !== null && _c !== void 0 ? _c : null;
|
|
134
|
-
if (!named_1 || !candidates.some(function (candidate) { return candidate.shape === named_1; })) {
|
|
135
|
-
(_d = context.log) === null || _d === void 0 ? void 0 : _d.call(context, 'Shape snap: the recognizer declined or named a shape the geometry ruled out', {
|
|
136
|
-
shape: named_1,
|
|
137
|
-
reason: (_e = answer === null || answer === void 0 ? void 0 : answer.reason) !== null && _e !== void 0 ? _e : 'no_answer'
|
|
138
|
-
});
|
|
139
|
-
return [2 /*return*/, null];
|
|
140
|
-
}
|
|
141
|
-
return [2 /*return*/, { shape: named_1, source: 'recognizer', axisTilt: measurements.axisTilt }];
|
|
142
|
-
case 2:
|
|
143
|
-
error_1 = _g.sent();
|
|
144
|
-
(_f = context.log) === null || _f === void 0 ? void 0 : _f.call(context, 'Shape snap: failed, leaving the stroke as drawn', error_1);
|
|
145
|
-
return [2 /*return*/, null];
|
|
146
|
-
case 3: return [2 /*return*/];
|
|
147
|
-
}
|
|
56
|
+
export async function decideStrokeSnap(stroke, context, handLine) {
|
|
57
|
+
try {
|
|
58
|
+
const measured = measureDrawnStroke(stroke, handLine);
|
|
59
|
+
if (!measured)
|
|
60
|
+
return null;
|
|
61
|
+
const { points, measurements } = measured;
|
|
62
|
+
// Only shapes the measurements cannot rule out are ever considered, and the same list is the only roster
|
|
63
|
+
// the host may choose from.
|
|
64
|
+
const rankings = rankSnapShapes(measurements);
|
|
65
|
+
if (rankings.length === 0)
|
|
66
|
+
return null;
|
|
67
|
+
const candidates = rankings.map((ranking) => ({ ...ranking, label: CANVAS_SNAP_SHAPE_LABELS[ranking.shape] }));
|
|
68
|
+
const decisive = confidentSnapShape(rankings);
|
|
69
|
+
if (decisive)
|
|
70
|
+
return { shape: decisive.shape, source: 'geometry', axisTilt: measurements.axisTilt };
|
|
71
|
+
if (!context.recognize) {
|
|
72
|
+
context.log?.('Shape snap: ambiguous and no recognizer configured, leaving the stroke as drawn', {
|
|
73
|
+
candidates: candidates.map((candidate) => candidate.shape)
|
|
74
|
+
});
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const strokeImage = renderStrokeSnapImage(points);
|
|
78
|
+
const answer = await context.recognize({
|
|
79
|
+
measurements,
|
|
80
|
+
candidates,
|
|
81
|
+
best: candidates[0] ?? null,
|
|
82
|
+
...(strokeImage ? { image: strokeImage } : {})
|
|
148
83
|
});
|
|
149
|
-
|
|
84
|
+
const named = answer?.shape ?? null;
|
|
85
|
+
if (!named || !candidates.some((candidate) => candidate.shape === named)) {
|
|
86
|
+
context.log?.('Shape snap: the recognizer declined or named a shape the geometry ruled out', {
|
|
87
|
+
shape: named,
|
|
88
|
+
reason: answer?.reason ?? 'no_answer'
|
|
89
|
+
});
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return { shape: named, source: 'recognizer', axisTilt: measurements.axisTilt };
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
context.log?.('Shape snap: failed, leaving the stroke as drawn', error);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
150
98
|
}
|
|
151
99
|
/**
|
|
152
100
|
* The clean shape for a stroke: the same place and size (where the hand went, when it is known, else the box of the
|
|
@@ -154,67 +102,64 @@ export function decideStrokeSnap(stroke, context, handLine) {
|
|
|
154
102
|
* The circle and the two library shapes stay square. Null when the shape cannot be built.
|
|
155
103
|
*/
|
|
156
104
|
export function buildSnappedShape(stroke, shape, services, handLine) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
var replacement = null;
|
|
105
|
+
const box = (handLine && handLine.length >= 2 ? outlineBounds(handLine) : null) ?? shapeBounds(stroke);
|
|
106
|
+
const placement = planSnapPlacement(shape, { left: box.x, top: box.y, width: box.width, height: box.height });
|
|
107
|
+
const area = placement.bounds;
|
|
108
|
+
const start = { x: area.left, y: area.top };
|
|
109
|
+
const end = { x: area.left + area.width, y: area.top + area.height };
|
|
110
|
+
const id = services.createId('obj');
|
|
111
|
+
let replacement = null;
|
|
165
112
|
if (shape === 'diamond' || shape === 'hexagon') {
|
|
166
|
-
replacement = buildLibraryShape({ id
|
|
113
|
+
replacement = buildLibraryShape({ id, x: area.left, y: area.top, width: area.width, height: area.height, key: shape });
|
|
167
114
|
}
|
|
168
115
|
else {
|
|
169
|
-
|
|
116
|
+
const kind = shape === 'oval' ? 'ellipse' : shape;
|
|
170
117
|
replacement = buildDraggedShape({
|
|
171
|
-
kind
|
|
172
|
-
start
|
|
173
|
-
end
|
|
118
|
+
kind,
|
|
119
|
+
start,
|
|
120
|
+
end,
|
|
174
121
|
constrain: false,
|
|
175
122
|
dragged: true,
|
|
176
123
|
wireframe: true,
|
|
177
|
-
createId:
|
|
124
|
+
createId: () => id,
|
|
178
125
|
random: services.random
|
|
179
126
|
});
|
|
180
127
|
}
|
|
181
128
|
if (!replacement)
|
|
182
129
|
return null;
|
|
183
|
-
return
|
|
130
|
+
return {
|
|
131
|
+
...replacement,
|
|
132
|
+
parentId: stroke.parentId,
|
|
133
|
+
opacity: stroke.opacity,
|
|
134
|
+
fill: 'transparent',
|
|
135
|
+
fillOpacity: 0,
|
|
184
136
|
// A brush stroke keeps its colour in the fill of its outline: the clean shape draws it as a line.
|
|
185
|
-
stroke: lineColorOf(stroke),
|
|
137
|
+
stroke: lineColorOf(stroke),
|
|
138
|
+
strokeWidth: stroke.strokeWidth,
|
|
139
|
+
strokeStyle: stroke.strokeStyle
|
|
140
|
+
};
|
|
186
141
|
}
|
|
187
142
|
/**
|
|
188
143
|
* Decides and, when the answer is a shape, replaces the stroke on the board in one undo step. Resolves to the
|
|
189
144
|
* decision that was applied, or null when the stroke stays.
|
|
190
145
|
*/
|
|
191
|
-
export function snapDrawnStroke(engine, stroke, context, handLine) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
(_a = context.log) === null || _a === void 0 ? void 0 : _a.call(context, 'Shape snap: could not put the clean shape on the board', error);
|
|
213
|
-
return [2 /*return*/, null];
|
|
214
|
-
}
|
|
215
|
-
(_b = context.log) === null || _b === void 0 ? void 0 : _b.call(context, 'Shape snap: stroke replaced with the clean shape', __assign(__assign({}, decision), { id: replacement.id }));
|
|
216
|
-
return [2 /*return*/, decision];
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
});
|
|
146
|
+
export async function snapDrawnStroke(engine, stroke, context, handLine) {
|
|
147
|
+
const decision = await decideStrokeSnap(stroke, context, handLine);
|
|
148
|
+
if (!decision)
|
|
149
|
+
return null;
|
|
150
|
+
// While the host was thinking the person may have moved, restyled or erased the stroke: then it is theirs.
|
|
151
|
+
if (engine.getObject(stroke.id) !== stroke)
|
|
152
|
+
return null;
|
|
153
|
+
const replacement = buildSnappedShape(stroke, decision.shape, engine.services, handLine);
|
|
154
|
+
if (!replacement)
|
|
155
|
+
return null;
|
|
156
|
+
try {
|
|
157
|
+
engine.applyScene(replaceObject(engine.state.scene, stroke.id, replacement), 'push');
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
context.log?.('Shape snap: could not put the clean shape on the board', error);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
context.log?.('Shape snap: stroke replaced with the clean shape', { ...decision, id: replacement.id });
|
|
164
|
+
return decision;
|
|
220
165
|
}
|
package/dist/canvas/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ 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
17
|
export type { BoardFileKind, BoardFilePickRequest, BoardFilePicker, BoardLibraryFile, BoardPicture, BoardPictureLibraryFile } from './host/boardFiles';
|
|
18
18
|
export { CANVAS_SHAPE_SNAP_ENABLED, STROKE_SNAP_IMAGE_SIDE, projectStrokeToImagePoints, renderStrokeSnapImage } from './shapes/strokeShapeSnap';
|
|
19
19
|
export { canvasLog, canvasWarn, canvasDebug, setCanvasLogsEnabled, isCanvasLogsEnabled } from './canvasLogger';
|
package/dist/canvas/openMarks.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Nothing reads them but a person with the panel open, so a page that has no User Timing API (or a browser that refuses a
|
|
6
6
|
* mark) loses nothing.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export const CANVAS_OPEN_MARKS = {
|
|
9
9
|
/** The board is in place with the data the page gave it, a moment before `onReady` is called. */
|
|
10
10
|
READY: 'canvas:ready',
|
|
11
11
|
/** `loadCanvas` began reading a saved canvas. */
|
|
@@ -20,7 +20,7 @@ export function markCanvasOpenStep(stepName) {
|
|
|
20
20
|
return;
|
|
21
21
|
performance.mark(stepName);
|
|
22
22
|
}
|
|
23
|
-
catch
|
|
23
|
+
catch {
|
|
24
24
|
// Marks are diagnostics only.
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Document-level outside press: deselect when the press is outside the canvas root and its portaled UI (item B18).
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export const CANVAS_UI_ATTRIBUTE = 'data-canvas-ui';
|
|
5
5
|
export function isCanvasOwnedTarget(event, canvasRoot) {
|
|
6
6
|
if (!canvasRoot)
|
|
7
7
|
return false;
|
|
8
|
-
|
|
8
|
+
const path = typeof event.composedPath === 'function' ? event.composedPath() : [];
|
|
9
9
|
if (path.length > 0) {
|
|
10
|
-
for (
|
|
11
|
-
var node = path_1[_i];
|
|
10
|
+
for (const node of path) {
|
|
12
11
|
if (!(node instanceof Node))
|
|
13
12
|
continue;
|
|
14
13
|
if (node === canvasRoot || canvasRoot.contains(node))
|
|
15
14
|
return true;
|
|
16
|
-
if (node instanceof Element && node.closest(
|
|
15
|
+
if (node instanceof Element && node.closest(`[${CANVAS_UI_ATTRIBUTE}]`))
|
|
17
16
|
return true;
|
|
18
17
|
}
|
|
19
18
|
return false;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
if (target instanceof Node && (canvasRoot.contains(target) || (target instanceof Element && target.closest(
|
|
20
|
+
const target = event.target;
|
|
21
|
+
if (target instanceof Node && (canvasRoot.contains(target) || (target instanceof Element && target.closest(`[${CANVAS_UI_ATTRIBUTE}]`)))) {
|
|
23
22
|
return true;
|
|
24
23
|
}
|
|
25
24
|
return false;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { CHROME_ANCHORS, normalizeAnchor } from './chromeLayout.js';
|
|
10
10
|
/** The places the zoom control can stand: `TL TC TR` (top), `CL CR` (the sides) and `BL BC BR` (bottom). */
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export const PAN_ZOOM_POSITIONS = CHROME_ANCHORS;
|
|
12
|
+
export const DEFAULT_PAN_ZOOM_POSITION = 'BL';
|
|
13
13
|
/** The position to use for what a page passed: anything that is not one of the eight is the default. */
|
|
14
14
|
export function normalizePanZoomPosition(value) {
|
|
15
15
|
return normalizeAnchor(value, DEFAULT_PAN_ZOOM_POSITION);
|
|
@@ -2,18 +2,9 @@
|
|
|
2
2
|
* The font family a person chose for a text, kept in the canvas's preference store (the browser's `localStorage`, or the
|
|
3
3
|
* store a partner page installed with `setCanvasPreferenceStorage`), so that the next text they place starts with it.
|
|
4
4
|
*/
|
|
5
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
6
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
7
|
-
if (ar || !(i in from)) {
|
|
8
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
9
|
-
ar[i] = from[i];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
13
|
-
};
|
|
14
5
|
import { getCanvasPreferenceStorage } from '../components/preferenceStorage.js';
|
|
15
6
|
/** The font families the selection panel offers for a text, in the order of its list. */
|
|
16
|
-
export
|
|
7
|
+
export const TEXT_FONT_FAMILIES = [
|
|
17
8
|
'Inter',
|
|
18
9
|
'Comic Sans MS',
|
|
19
10
|
'Arial',
|
|
@@ -25,50 +16,47 @@ export var TEXT_FONT_FAMILIES = [
|
|
|
25
16
|
'Impact'
|
|
26
17
|
];
|
|
27
18
|
/** Families added from the workspace brand kit (not persisted in this list; merged in the panel). */
|
|
28
|
-
|
|
19
|
+
let workspaceFontFamilies = [];
|
|
29
20
|
export function setWorkspaceFontFamilies(families) {
|
|
30
|
-
workspaceFontFamilies =
|
|
21
|
+
workspaceFontFamilies = [...new Set(families.filter(Boolean))];
|
|
31
22
|
}
|
|
32
23
|
export function fontFamiliesForPicker() {
|
|
33
|
-
|
|
34
|
-
for (
|
|
35
|
-
var family = workspaceFontFamilies_1[_i];
|
|
24
|
+
const merged = [...TEXT_FONT_FAMILIES];
|
|
25
|
+
for (const family of workspaceFontFamilies) {
|
|
36
26
|
if (!merged.includes(family))
|
|
37
27
|
merged.push(family);
|
|
38
28
|
}
|
|
39
29
|
return merged;
|
|
40
30
|
}
|
|
41
31
|
/** Inter + Comic Sans for the picker’s “Default fonts” group. */
|
|
42
|
-
export
|
|
32
|
+
export const PRIMARY_CANVAS_FONT_FAMILIES = ['Inter', 'Comic Sans MS'];
|
|
43
33
|
export function builtInFontFamiliesForPicker() {
|
|
44
|
-
return TEXT_FONT_FAMILIES.filter(
|
|
34
|
+
return TEXT_FONT_FAMILIES.filter((family) => !PRIMARY_CANVAS_FONT_FAMILIES.includes(family));
|
|
45
35
|
}
|
|
46
36
|
export function workspaceFontFamiliesForPicker() {
|
|
47
|
-
return
|
|
37
|
+
return [...workspaceFontFamilies];
|
|
48
38
|
}
|
|
49
39
|
/** The key the choice is kept under. */
|
|
50
|
-
export
|
|
40
|
+
export const PREFERRED_TEXT_FONT_STORAGE_KEY = 'widgetic-canvas:preferred-text-font';
|
|
51
41
|
/** The font family kept from an earlier choice, or null when none was made (or the store refuses, or the name is no longer offered). */
|
|
52
42
|
export function readPreferredTextFontFamily() {
|
|
53
|
-
var _a;
|
|
54
43
|
try {
|
|
55
|
-
|
|
44
|
+
const stored = getCanvasPreferenceStorage()?.getItem(PREFERRED_TEXT_FONT_STORAGE_KEY);
|
|
56
45
|
return stored && fontFamiliesForPicker().includes(stored) ? stored : null;
|
|
57
46
|
}
|
|
58
|
-
catch
|
|
47
|
+
catch {
|
|
59
48
|
// A store that blocks reading is the same as a store with nothing in it.
|
|
60
49
|
return null;
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
52
|
/** Keeps the choice for the next text. A store that refuses the write is not an error: the choice then lasts until the page closes. */
|
|
64
53
|
export function writePreferredTextFontFamily(fontFamily) {
|
|
65
|
-
var _a;
|
|
66
54
|
if (!fontFamiliesForPicker().includes(fontFamily))
|
|
67
55
|
return;
|
|
68
56
|
try {
|
|
69
|
-
|
|
57
|
+
getCanvasPreferenceStorage()?.setItem(PREFERRED_TEXT_FONT_STORAGE_KEY, fontFamily);
|
|
70
58
|
}
|
|
71
|
-
catch
|
|
59
|
+
catch {
|
|
72
60
|
// Nothing to do: the engine still holds the choice for this session.
|
|
73
61
|
}
|
|
74
62
|
}
|