@widgetic/canvas 0.5.40 → 0.5.41
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 +7 -3
- package/dist/canvas/DomCanvas.svelte +4 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +8 -0
- package/dist/canvas/autosaveScheduler.js +89 -37
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +19 -7
- package/dist/canvas/chromeLayout.js +18 -17
- package/dist/canvas/eventScope.js +14 -10
- package/dist/canvas/host/CanvasHost.d.ts +6 -0
- package/dist/canvas/host/CanvasHost.js +1556 -1267
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +25 -4
- package/dist/canvas/host/browserServices.js +116 -65
- package/dist/canvas/host/conversion.js +170 -82
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/pageEvents.js +4 -4
- package/dist/canvas/host/screenRects.js +31 -28
- package/dist/canvas/host/strokeSnap.js +143 -88
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +7 -6
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +25 -13
- package/dist/canvas/shapes/ShapeLibrary.js +148 -138
- package/dist/canvas/shapes/shapeImageStore.js +3 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/CanvasHint.svelte +16 -3
- package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
- package/dist/canvas/ui/CanvasToolbar.svelte +7 -7
- package/dist/canvas/ui/ToolButton.svelte +11 -3
- package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
- package/dist/canvas/ui/colorModel.js +32 -21
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +18 -18
- package/dist/canvas/ui/floatingLayer.js +6 -5
- package/dist/canvas/ui/keyHints.js +11 -9
- package/dist/canvas/ui/popoverSide.js +3 -2
- package/dist/canvas/ui/selectionTraits.js +40 -34
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +1 -1
- package/dist/canvas/ui/sizeLabelVisibility.js +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +33 -14
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +14 -4
- package/dist/canvas/view/geometry.js +103 -77
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +4 -1
- package/dist/engine/EngineCore.js +801 -695
- package/dist/engine/codec/canvasDocument.js +173 -173
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +38 -26
- package/dist/engine/core/arrow.d.ts +10 -3
- package/dist/engine/core/arrow.js +96 -75
- package/dist/engine/core/arrowBinding.d.ts +69 -0
- package/dist/engine/core/arrowBinding.js +344 -0
- package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
- package/dist/engine/core/arrowBindingRecords.js +141 -0
- package/dist/engine/core/brush.js +94 -67
- package/dist/engine/core/defaults.js +51 -90
- package/dist/engine/core/freehand.js +163 -147
- package/dist/engine/core/geometry.js +54 -47
- package/dist/engine/core/history.js +50 -33
- package/dist/engine/core/hitTest.d.ts +3 -0
- package/dist/engine/core/hitTest.js +83 -69
- package/dist/engine/core/matrix.js +20 -18
- package/dist/engine/core/pathData.js +210 -183
- package/dist/engine/core/rotationReset.js +6 -5
- package/dist/engine/core/scene.d.ts +3 -0
- package/dist/engine/core/scene.js +192 -129
- package/dist/engine/core/scribble.js +84 -59
- package/dist/engine/core/shapePaths.js +15 -12
- package/dist/engine/core/shapeTools.js +63 -72
- package/dist/engine/core/snapping.js +117 -65
- package/dist/engine/core/style.js +64 -31
- package/dist/engine/core/transform.js +94 -83
- package/dist/engine/core/types.d.ts +29 -0
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +36 -23
- package/dist/engine/input/PointerController.js +476 -447
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +12 -1
- package/dist/engine/input/gestures.js +342 -251
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.d.ts +9 -1
- package/dist/engine/input/keyboard.js +46 -27
- package/dist/engine/input/selectionHandles.js +50 -45
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +158 -86
- package/dist/engine/state.d.ts +6 -1
- package/dist/engine/state.js +17 -5
- package/dist/engine/text/layoutText.js +62 -43
- package/dist/engine/text/textMetrics.js +10 -8
- package/dist/engine/widgets.js +137 -101
- package/dist/fonts/interFont.js +68 -17
- package/dist/fonts/workspaceFonts.js +90 -32
- 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.d.ts +12 -0
- package/dist/i18n/shortcuts.js +32 -18
- package/dist/settings/workspaceToolSettings.js +48 -32
- package/dist/tools/components/catalog.d.ts +11 -0
- package/dist/tools/components/catalog.js +270 -0
- package/dist/tools/components/grouping.d.ts +9 -0
- package/dist/tools/components/grouping.js +33 -0
- package/dist/tools/definitions.d.ts +19 -0
- package/dist/tools/definitions.js +147 -0
- package/dist/tools/executors.d.ts +7 -0
- package/dist/tools/executors.js +324 -0
- package/dist/tools/hostAdapter.d.ts +14 -0
- package/dist/tools/hostAdapter.js +40 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/sceneSummary.d.ts +24 -0
- package/dist/tools/sceneSummary.js +170 -0
- package/dist/tools/sketchIntent.d.ts +17 -0
- package/dist/tools/sketchIntent.js +166 -0
- package/dist/tools/types.d.ts +54 -0
- package/dist/tools/types.js +11 -0
- package/package.json +7 -2
|
@@ -41,7 +41,7 @@ export function hostCustomTypeOf(object) {
|
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
function viewOf(object, index, scene) {
|
|
44
|
-
|
|
44
|
+
var view = {
|
|
45
45
|
id: object.id,
|
|
46
46
|
_objectId: object.id,
|
|
47
47
|
type: hostTypeOf(object),
|
|
@@ -54,7 +54,7 @@ function viewOf(object, index, scene) {
|
|
|
54
54
|
view._isPrimaryWidget = object.isPrimary;
|
|
55
55
|
}
|
|
56
56
|
if (object.type === 'group') {
|
|
57
|
-
view.objects = scene.filter((member)
|
|
57
|
+
view.objects = scene.filter(function (member) { return member.parentId === object.id; }).map(function (member) { return viewOf(member, index, scene); });
|
|
58
58
|
}
|
|
59
59
|
return view;
|
|
60
60
|
}
|
|
@@ -62,7 +62,7 @@ function viewOf(object, index, scene) {
|
|
|
62
62
|
export function hostObjectById(engine, id) {
|
|
63
63
|
if (!id)
|
|
64
64
|
return null;
|
|
65
|
-
|
|
65
|
+
var object = engine.getObject(id);
|
|
66
66
|
if (!object)
|
|
67
67
|
return null;
|
|
68
68
|
return viewOf(object, engine.sceneIndex(), engine.state.scene);
|
|
@@ -72,11 +72,11 @@ export function hostObjectById(engine, id) {
|
|
|
72
72
|
* Null when nothing is selected.
|
|
73
73
|
*/
|
|
74
74
|
export function selectedHostObject(engine) {
|
|
75
|
-
|
|
75
|
+
var selected = engine.selectedObjects();
|
|
76
76
|
if (selected.length === 0)
|
|
77
77
|
return null;
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
var index = engine.sceneIndex();
|
|
79
|
+
var scene = engine.state.scene;
|
|
80
80
|
if (selected.length === 1)
|
|
81
81
|
return viewOf(selected[0], index, scene);
|
|
82
82
|
return {
|
|
@@ -84,7 +84,7 @@ export function selectedHostObject(engine) {
|
|
|
84
84
|
_objectId: '',
|
|
85
85
|
type: 'activeSelection',
|
|
86
86
|
_customType: null,
|
|
87
|
-
objects: selected.map((object)
|
|
87
|
+
objects: selected.map(function (object) { return viewOf(object, index, scene); })
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
/** The shapes behind a list of units (a group counts through its members), for the conversion payload. */
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
* Kept free of Svelte so that Node can test it. A page rendered on the server has no `window` and gets nothing.
|
|
13
13
|
*/
|
|
14
14
|
import { canvasWarn } from '../canvasLogger.js';
|
|
15
|
-
export
|
|
16
|
-
export
|
|
15
|
+
export var CANVAS_SELECT_TOOL_EVENT = 'widgetic:canvas-select-tool';
|
|
16
|
+
export var WIDGET_POINTER_BLOCK_EVENT = 'widgetic:widget-shape-pointer-block';
|
|
17
17
|
function dispatchOnWindow(name, detail) {
|
|
18
18
|
if (typeof window === 'undefined' || typeof CustomEvent === 'undefined')
|
|
19
19
|
return;
|
|
20
20
|
try {
|
|
21
|
-
window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail }));
|
|
21
|
+
window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail: detail }));
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
24
|
// A page that cannot take the event keeps its canvas.
|
|
25
|
-
canvasWarn(
|
|
25
|
+
canvasWarn("Canvas: could not send ".concat(name), error);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
/** The Select tool was chosen. */
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
import { boxToWorldMatrix } from '../../engine/core/matrix.js';
|
|
12
12
|
import { shapeBounds } from '../../engine/core/scene.js';
|
|
13
13
|
function cssScaleOf(frame) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
var layoutWidth = frame.layoutWidth && frame.layoutWidth > 0 ? frame.layoutWidth : frame.width;
|
|
15
|
+
var layoutHeight = frame.layoutHeight && frame.layoutHeight > 0 ? frame.layoutHeight : frame.height;
|
|
16
16
|
return {
|
|
17
17
|
scaleX: layoutWidth > 0 && frame.width > 0 ? frame.width / layoutWidth : 1,
|
|
18
18
|
scaleY: layoutHeight > 0 && frame.height > 0 ? frame.height / layoutHeight : 1
|
|
@@ -20,7 +20,7 @@ function cssScaleOf(frame) {
|
|
|
20
20
|
}
|
|
21
21
|
/** A point of the world on the page. */
|
|
22
22
|
export function worldPointToPage(viewport, frame, x, y) {
|
|
23
|
-
|
|
23
|
+
var _a = cssScaleOf(frame), scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
24
24
|
return {
|
|
25
25
|
x: frame.left + (viewport.x + x * viewport.zoom) * scaleX,
|
|
26
26
|
y: frame.top + (viewport.y + y * viewport.zoom) * scaleY
|
|
@@ -28,12 +28,12 @@ export function worldPointToPage(viewport, frame, x, y) {
|
|
|
28
28
|
}
|
|
29
29
|
/** The matrix from a box's own pixels to the page, or null when something is not a finite number. */
|
|
30
30
|
export function boxToPageMatrix(box, viewport, frame) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
var _a = cssScaleOf(frame), scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
32
|
+
var world = boxToWorldMatrix(box);
|
|
33
33
|
// page = frame + scale * (viewport.translate + zoom * world)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
var zoomX = viewport.zoom * scaleX;
|
|
35
|
+
var zoomY = viewport.zoom * scaleY;
|
|
36
|
+
var matrix = [
|
|
37
37
|
world[0] * zoomX,
|
|
38
38
|
world[1] * zoomY,
|
|
39
39
|
world[2] * zoomX,
|
|
@@ -45,31 +45,34 @@ export function boxToPageMatrix(box, viewport, frame) {
|
|
|
45
45
|
}
|
|
46
46
|
/** The geometry of a card on the page. Null when the numbers are not usable. */
|
|
47
47
|
export function widgetPreviewGeometry(shape, viewport, frame) {
|
|
48
|
-
|
|
48
|
+
var matrix = boxToPageMatrix(shape, viewport, frame);
|
|
49
49
|
if (!matrix)
|
|
50
50
|
return null;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
var localWidth = shape.width || 1;
|
|
52
|
+
var localHeight = shape.height || 1;
|
|
53
|
+
var corners = [
|
|
54
54
|
[0, 0],
|
|
55
55
|
[localWidth, 0],
|
|
56
56
|
[0, localHeight],
|
|
57
57
|
[localWidth, localHeight]
|
|
58
|
-
].map((
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
].map(function (_a) {
|
|
59
|
+
var x = _a[0], y = _a[1];
|
|
60
|
+
return ({
|
|
61
|
+
x: matrix[0] * x + matrix[2] * y + matrix[4],
|
|
62
|
+
y: matrix[1] * x + matrix[3] * y + matrix[5]
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
var xs = corners.map(function (corner) { return corner.x; });
|
|
66
|
+
var ys = corners.map(function (corner) { return corner.y; });
|
|
67
|
+
var left = Math.min.apply(Math, xs);
|
|
68
|
+
var top = Math.min.apply(Math, ys);
|
|
66
69
|
return {
|
|
67
|
-
left,
|
|
68
|
-
top,
|
|
69
|
-
width: Math.max(
|
|
70
|
-
height: Math.max(
|
|
71
|
-
localWidth,
|
|
72
|
-
localHeight,
|
|
70
|
+
left: left,
|
|
71
|
+
top: top,
|
|
72
|
+
width: Math.max.apply(Math, xs) - left,
|
|
73
|
+
height: Math.max.apply(Math, ys) - top,
|
|
74
|
+
localWidth: localWidth,
|
|
75
|
+
localHeight: localHeight,
|
|
73
76
|
// The old canvas answered with the matrix of the card's pixels, one unit per local pixel.
|
|
74
77
|
matrix: [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]]
|
|
75
78
|
};
|
|
@@ -80,8 +83,8 @@ export function screenRectOfShape(shape, viewport, frame) {
|
|
|
80
83
|
}
|
|
81
84
|
/** The box of a rectangle of the world on the page, with the board it sits on. */
|
|
82
85
|
export function screenRectOfBounds(bounds, viewport, frame) {
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
var topLeft = worldPointToPage(viewport, frame, bounds.x, bounds.y);
|
|
87
|
+
var bottomRight = worldPointToPage(viewport, frame, bounds.x + bounds.width, bounds.y + bounds.height);
|
|
85
88
|
return {
|
|
86
89
|
left: Math.min(topLeft.x, bottomRight.x),
|
|
87
90
|
top: Math.min(topLeft.y, bottomRight.y),
|
|
@@ -10,6 +10,53 @@
|
|
|
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
|
+
};
|
|
13
60
|
import { brushCentreline, isBrushStroke } from '../../engine/core/brush.js';
|
|
14
61
|
import { outlineBounds } from '../../engine/core/hitTest.js';
|
|
15
62
|
import { parsePathData } from '../../engine/core/pathData.js';
|
|
@@ -23,7 +70,8 @@ import { CANVAS_SHAPE_SNAP_ENABLED, CANVAS_SNAP_SHAPE_LABELS, confidentSnapShape
|
|
|
23
70
|
* (`CANVAS_SHAPE_SNAP_ENABLED`, false as shipped) turns it on for every page when it is flipped, which is the one
|
|
24
71
|
* line to roll the behaviour out or back. The flag is a parameter so a test can hold both of its values.
|
|
25
72
|
*/
|
|
26
|
-
export function isShapeSnapOn(pageAsked, packageFlag
|
|
73
|
+
export function isShapeSnapOn(pageAsked, packageFlag) {
|
|
74
|
+
if (packageFlag === void 0) { packageFlag = CANVAS_SHAPE_SNAP_ENABLED; }
|
|
27
75
|
return packageFlag === true || pageAsked === true;
|
|
28
76
|
}
|
|
29
77
|
/**
|
|
@@ -34,67 +82,71 @@ export function isShapeSnapOn(pageAsked, packageFlag = CANVAS_SHAPE_SNAP_ENABLED
|
|
|
34
82
|
*/
|
|
35
83
|
export function strokeMeasurementPoints(stroke, handLine) {
|
|
36
84
|
if (handLine && handLine.length >= 2)
|
|
37
|
-
return handLine.map((point)
|
|
85
|
+
return handLine.map(function (point) { return ({ x: point.x - stroke.x, y: point.y - stroke.y }); });
|
|
38
86
|
if (isBrushStroke(stroke))
|
|
39
87
|
return brushCentreline(stroke);
|
|
40
88
|
return flattenPathCommands(parsePathData(stroke.d));
|
|
41
89
|
}
|
|
42
90
|
/** What the geometry says about a stroke: its measurements, or null when it is too small or too plain to measure. */
|
|
43
91
|
export function measureDrawnStroke(stroke, handLine) {
|
|
44
|
-
|
|
92
|
+
var points = strokeMeasurementPoints(stroke, handLine);
|
|
45
93
|
if (points.length < 2)
|
|
46
94
|
return null;
|
|
47
|
-
|
|
95
|
+
var measurements = measureStroke(points);
|
|
48
96
|
if (!measurements)
|
|
49
97
|
return null;
|
|
50
|
-
return { points, measurements };
|
|
98
|
+
return { points: points, measurements: measurements };
|
|
51
99
|
}
|
|
52
100
|
/**
|
|
53
101
|
* Decides whether a stroke is a clean shape. Resolves to null for "leave it as drawn".
|
|
54
102
|
* Deliberately never rejects.
|
|
55
103
|
*/
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
export function decideStrokeSnap(stroke, context, handLine) {
|
|
105
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
106
|
+
var measured, points, measurements, rankings, candidates, decisive, strokeImage, answer, named_1, error_1;
|
|
107
|
+
var _a, _b, _c, _d, _e, _f;
|
|
108
|
+
return __generator(this, function (_g) {
|
|
109
|
+
switch (_g.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
_g.trys.push([0, 2, , 3]);
|
|
112
|
+
measured = measureDrawnStroke(stroke, handLine);
|
|
113
|
+
if (!measured)
|
|
114
|
+
return [2 /*return*/, null];
|
|
115
|
+
points = measured.points, measurements = measured.measurements;
|
|
116
|
+
rankings = rankSnapShapes(measurements);
|
|
117
|
+
if (rankings.length === 0)
|
|
118
|
+
return [2 /*return*/, null];
|
|
119
|
+
candidates = rankings.map(function (ranking) { return (__assign(__assign({}, ranking), { label: CANVAS_SNAP_SHAPE_LABELS[ranking.shape] })); });
|
|
120
|
+
decisive = confidentSnapShape(rankings);
|
|
121
|
+
if (decisive)
|
|
122
|
+
return [2 /*return*/, { shape: decisive.shape, source: 'geometry', axisTilt: measurements.axisTilt }];
|
|
123
|
+
if (!context.recognize) {
|
|
124
|
+
(_a = context.log) === null || _a === void 0 ? void 0 : _a.call(context, 'Shape snap: ambiguous and no recognizer configured, leaving the stroke as drawn', {
|
|
125
|
+
candidates: candidates.map(function (candidate) { return candidate.shape; })
|
|
126
|
+
});
|
|
127
|
+
return [2 /*return*/, null];
|
|
128
|
+
}
|
|
129
|
+
strokeImage = renderStrokeSnapImage(points);
|
|
130
|
+
return [4 /*yield*/, context.recognize(__assign({ measurements: measurements, candidates: candidates, best: (_b = candidates[0]) !== null && _b !== void 0 ? _b : null }, (strokeImage ? { image: strokeImage } : {})))];
|
|
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
|
+
}
|
|
83
148
|
});
|
|
84
|
-
|
|
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
|
-
}
|
|
149
|
+
});
|
|
98
150
|
}
|
|
99
151
|
/**
|
|
100
152
|
* The clean shape for a stroke: the same place and size (where the hand went, when it is known, else the box of the
|
|
@@ -102,64 +154,67 @@ export async function decideStrokeSnap(stroke, context, handLine) {
|
|
|
102
154
|
* The circle and the two library shapes stay square. Null when the shape cannot be built.
|
|
103
155
|
*/
|
|
104
156
|
export function buildSnappedShape(stroke, shape, services, handLine) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
157
|
+
var _a;
|
|
158
|
+
var box = (_a = (handLine && handLine.length >= 2 ? outlineBounds(handLine) : null)) !== null && _a !== void 0 ? _a : shapeBounds(stroke);
|
|
159
|
+
var placement = planSnapPlacement(shape, { left: box.x, top: box.y, width: box.width, height: box.height });
|
|
160
|
+
var area = placement.bounds;
|
|
161
|
+
var start = { x: area.left, y: area.top };
|
|
162
|
+
var end = { x: area.left + area.width, y: area.top + area.height };
|
|
163
|
+
var id = services.createId('obj');
|
|
164
|
+
var replacement = null;
|
|
112
165
|
if (shape === 'diamond' || shape === 'hexagon') {
|
|
113
|
-
replacement = buildLibraryShape({ id, x: area.left, y: area.top, width: area.width, height: area.height, key: shape });
|
|
166
|
+
replacement = buildLibraryShape({ id: id, x: area.left, y: area.top, width: area.width, height: area.height, key: shape });
|
|
114
167
|
}
|
|
115
168
|
else {
|
|
116
|
-
|
|
169
|
+
var kind = shape === 'oval' ? 'ellipse' : shape;
|
|
117
170
|
replacement = buildDraggedShape({
|
|
118
|
-
kind,
|
|
119
|
-
start,
|
|
120
|
-
end,
|
|
171
|
+
kind: kind,
|
|
172
|
+
start: start,
|
|
173
|
+
end: end,
|
|
121
174
|
constrain: false,
|
|
122
175
|
dragged: true,
|
|
123
176
|
wireframe: true,
|
|
124
|
-
createId: ()
|
|
177
|
+
createId: function () { return id; },
|
|
125
178
|
random: services.random
|
|
126
179
|
});
|
|
127
180
|
}
|
|
128
181
|
if (!replacement)
|
|
129
182
|
return null;
|
|
130
|
-
return {
|
|
131
|
-
...replacement,
|
|
132
|
-
parentId: stroke.parentId,
|
|
133
|
-
opacity: stroke.opacity,
|
|
134
|
-
fill: 'transparent',
|
|
135
|
-
fillOpacity: 0,
|
|
183
|
+
return __assign(__assign({}, replacement), { parentId: stroke.parentId, opacity: stroke.opacity, fill: 'transparent', fillOpacity: 0,
|
|
136
184
|
// A brush stroke keeps its colour in the fill of its outline: the clean shape draws it as a line.
|
|
137
|
-
stroke: lineColorOf(stroke),
|
|
138
|
-
strokeWidth: stroke.strokeWidth,
|
|
139
|
-
strokeStyle: stroke.strokeStyle
|
|
140
|
-
};
|
|
185
|
+
stroke: lineColorOf(stroke), strokeWidth: stroke.strokeWidth, strokeStyle: stroke.strokeStyle });
|
|
141
186
|
}
|
|
142
187
|
/**
|
|
143
188
|
* Decides and, when the answer is a shape, replaces the stroke on the board in one undo step. Resolves to the
|
|
144
189
|
* decision that was applied, or null when the stroke stays.
|
|
145
190
|
*/
|
|
146
|
-
export
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
191
|
+
export function snapDrawnStroke(engine, stroke, context, handLine) {
|
|
192
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
193
|
+
var decision, replacement;
|
|
194
|
+
var _a, _b;
|
|
195
|
+
return __generator(this, function (_c) {
|
|
196
|
+
switch (_c.label) {
|
|
197
|
+
case 0: return [4 /*yield*/, decideStrokeSnap(stroke, context, handLine)];
|
|
198
|
+
case 1:
|
|
199
|
+
decision = _c.sent();
|
|
200
|
+
if (!decision)
|
|
201
|
+
return [2 /*return*/, null];
|
|
202
|
+
// While the host was thinking the person may have moved, restyled or erased the stroke: then it is theirs.
|
|
203
|
+
if (engine.getObject(stroke.id) !== stroke)
|
|
204
|
+
return [2 /*return*/, null];
|
|
205
|
+
replacement = buildSnappedShape(stroke, decision.shape, engine.services, handLine);
|
|
206
|
+
if (!replacement)
|
|
207
|
+
return [2 /*return*/, null];
|
|
208
|
+
try {
|
|
209
|
+
engine.applyScene(replaceObject(engine.state.scene, stroke.id, replacement), 'push');
|
|
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
|
+
});
|
|
165
220
|
}
|
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 var 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 (_a) {
|
|
24
24
|
// Marks are diagnostics only.
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,24 +1,25 @@
|
|
|
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 var CANVAS_UI_ATTRIBUTE = 'data-canvas-ui';
|
|
5
5
|
export function isCanvasOwnedTarget(event, canvasRoot) {
|
|
6
6
|
if (!canvasRoot)
|
|
7
7
|
return false;
|
|
8
|
-
|
|
8
|
+
var path = typeof event.composedPath === 'function' ? event.composedPath() : [];
|
|
9
9
|
if (path.length > 0) {
|
|
10
|
-
for (
|
|
10
|
+
for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
|
|
11
|
+
var node = path_1[_i];
|
|
11
12
|
if (!(node instanceof Node))
|
|
12
13
|
continue;
|
|
13
14
|
if (node === canvasRoot || canvasRoot.contains(node))
|
|
14
15
|
return true;
|
|
15
|
-
if (node instanceof Element && node.closest(
|
|
16
|
+
if (node instanceof Element && node.closest("[".concat(CANVAS_UI_ATTRIBUTE, "]")))
|
|
16
17
|
return true;
|
|
17
18
|
}
|
|
18
19
|
return false;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
if (target instanceof Node && (canvasRoot.contains(target) || (target instanceof Element && target.closest(
|
|
21
|
+
var target = event.target;
|
|
22
|
+
if (target instanceof Node && (canvasRoot.contains(target) || (target instanceof Element && target.closest("[".concat(CANVAS_UI_ATTRIBUTE, "]"))))) {
|
|
22
23
|
return true;
|
|
23
24
|
}
|
|
24
25
|
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 var PAN_ZOOM_POSITIONS = CHROME_ANCHORS;
|
|
12
|
+
export var 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,9 +2,18 @@
|
|
|
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
|
+
};
|
|
5
14
|
import { getCanvasPreferenceStorage } from '../components/preferenceStorage.js';
|
|
6
15
|
/** The font families the selection panel offers for a text, in the order of its list. */
|
|
7
|
-
export
|
|
16
|
+
export var TEXT_FONT_FAMILIES = [
|
|
8
17
|
'Inter',
|
|
9
18
|
'Comic Sans MS',
|
|
10
19
|
'Arial',
|
|
@@ -16,47 +25,50 @@ export const TEXT_FONT_FAMILIES = [
|
|
|
16
25
|
'Impact'
|
|
17
26
|
];
|
|
18
27
|
/** Families added from the workspace brand kit (not persisted in this list; merged in the panel). */
|
|
19
|
-
|
|
28
|
+
var workspaceFontFamilies = [];
|
|
20
29
|
export function setWorkspaceFontFamilies(families) {
|
|
21
|
-
workspaceFontFamilies = [
|
|
30
|
+
workspaceFontFamilies = __spreadArray([], new Set(families.filter(Boolean)), true);
|
|
22
31
|
}
|
|
23
32
|
export function fontFamiliesForPicker() {
|
|
24
|
-
|
|
25
|
-
for (
|
|
33
|
+
var merged = __spreadArray([], TEXT_FONT_FAMILIES, true);
|
|
34
|
+
for (var _i = 0, workspaceFontFamilies_1 = workspaceFontFamilies; _i < workspaceFontFamilies_1.length; _i++) {
|
|
35
|
+
var family = workspaceFontFamilies_1[_i];
|
|
26
36
|
if (!merged.includes(family))
|
|
27
37
|
merged.push(family);
|
|
28
38
|
}
|
|
29
39
|
return merged;
|
|
30
40
|
}
|
|
31
41
|
/** Inter + Comic Sans for the picker’s “Default fonts” group. */
|
|
32
|
-
export
|
|
42
|
+
export var PRIMARY_CANVAS_FONT_FAMILIES = ['Inter', 'Comic Sans MS'];
|
|
33
43
|
export function builtInFontFamiliesForPicker() {
|
|
34
|
-
return TEXT_FONT_FAMILIES.filter((family)
|
|
44
|
+
return TEXT_FONT_FAMILIES.filter(function (family) { return !PRIMARY_CANVAS_FONT_FAMILIES.includes(family); });
|
|
35
45
|
}
|
|
36
46
|
export function workspaceFontFamiliesForPicker() {
|
|
37
|
-
return [
|
|
47
|
+
return __spreadArray([], workspaceFontFamilies, true);
|
|
38
48
|
}
|
|
39
49
|
/** The key the choice is kept under. */
|
|
40
|
-
export
|
|
50
|
+
export var PREFERRED_TEXT_FONT_STORAGE_KEY = 'widgetic-canvas:preferred-text-font';
|
|
41
51
|
/** 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). */
|
|
42
52
|
export function readPreferredTextFontFamily() {
|
|
53
|
+
var _a;
|
|
43
54
|
try {
|
|
44
|
-
|
|
55
|
+
var stored = (_a = getCanvasPreferenceStorage()) === null || _a === void 0 ? void 0 : _a.getItem(PREFERRED_TEXT_FONT_STORAGE_KEY);
|
|
45
56
|
return stored && fontFamiliesForPicker().includes(stored) ? stored : null;
|
|
46
57
|
}
|
|
47
|
-
catch {
|
|
58
|
+
catch (_b) {
|
|
48
59
|
// A store that blocks reading is the same as a store with nothing in it.
|
|
49
60
|
return null;
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
/** 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. */
|
|
53
64
|
export function writePreferredTextFontFamily(fontFamily) {
|
|
65
|
+
var _a;
|
|
54
66
|
if (!fontFamiliesForPicker().includes(fontFamily))
|
|
55
67
|
return;
|
|
56
68
|
try {
|
|
57
|
-
getCanvasPreferenceStorage()
|
|
69
|
+
(_a = getCanvasPreferenceStorage()) === null || _a === void 0 ? void 0 : _a.setItem(PREFERRED_TEXT_FONT_STORAGE_KEY, fontFamily);
|
|
58
70
|
}
|
|
59
|
-
catch {
|
|
71
|
+
catch (_b) {
|
|
60
72
|
// Nothing to do: the engine still holds the choice for this session.
|
|
61
73
|
}
|
|
62
74
|
}
|