@widgetic/canvas 0.5.43 → 0.5.45
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/dist/canvas/DomCanvas.svelte +56 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -28
- 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 +21 -19
- package/dist/canvas/eventScope.js +14 -10
- package/dist/canvas/host/CanvasHost.d.ts +87 -2
- package/dist/canvas/host/CanvasHost.js +1948 -1394
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +32 -5
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +155 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +211 -65
- package/dist/canvas/host/conversion.js +170 -82
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +21 -18
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +11 -9
- package/dist/canvas/host/screenRects.js +31 -28
- package/dist/canvas/host/storedPictures.js +243 -149
- package/dist/canvas/host/strokeSnap.js +143 -88
- package/dist/canvas/index.d.ts +2 -0
- 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 +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +17 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/ColorField.svelte +7 -2
- package/dist/canvas/ui/SelectionPanel.svelte +105 -42
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +35 -54
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/colorModel.js +32 -21
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +43 -21
- package/dist/canvas/ui/floatingLayer.js +6 -5
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/keyHints.js +11 -9
- package/dist/canvas/ui/popoverSide.js +3 -2
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +66 -35
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +90 -71
- package/dist/canvas/view/liftedScene.js +36 -24
- package/dist/canvas/view/mountedScene.js +79 -76
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +111 -2
- package/dist/engine/EngineCore.js +1013 -707
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +172 -186
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +38 -26
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +109 -84
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +126 -101
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +48 -29
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +98 -78
- package/dist/engine/core/cameraMove.d.ts +73 -0
- package/dist/engine/core/cameraMove.js +172 -0
- 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 +55 -38
- package/dist/engine/core/hitTest.js +81 -68
- 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 +22 -0
- package/dist/engine/core/scene.js +288 -139
- 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.d.ts +10 -0
- package/dist/engine/core/style.js +82 -33
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +103 -83
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +36 -23
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +549 -466
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +340 -266
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +131 -32
- package/dist/engine/input/selectionHandles.js +50 -45
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +158 -86
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +25 -4
- 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 +83 -30
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +108 -34
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +7 -1
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +30 -26
- package/dist/index.d.ts +2 -1
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +140 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +251 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +112 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +138 -0
- package/dist/settings/workspaceToolSettings.d.ts +6 -0
- package/dist/settings/workspaceToolSettings.js +58 -34
- package/dist/tools/components/catalog.js +74 -64
- package/dist/tools/components/grouping.js +28 -6
- package/dist/tools/definitions.js +31 -9
- package/dist/tools/executors.js +214 -106
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +15 -11
- package/dist/tools/sceneSummary.js +57 -43
- package/dist/tools/sketchIntent.js +21 -13
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +93 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +2 -1
- package/package.json +1 -1
|
@@ -9,117 +9,205 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Plain TypeScript over the engine's records and the rasterizer: runs in Node.
|
|
11
11
|
*/
|
|
12
|
+
var __assign = (this && this.__assign) || function () {
|
|
13
|
+
__assign = Object.assign || function(t) {
|
|
14
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
15
|
+
s = arguments[i];
|
|
16
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
17
|
+
t[p] = s[p];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
return __assign.apply(this, arguments);
|
|
22
|
+
};
|
|
23
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
24
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
33
|
+
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);
|
|
34
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
35
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
36
|
+
function step(op) {
|
|
37
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
38
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
39
|
+
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;
|
|
40
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
41
|
+
switch (op[0]) {
|
|
42
|
+
case 0: case 1: t = op; break;
|
|
43
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
44
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
45
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
46
|
+
default:
|
|
47
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
48
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
49
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
50
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
51
|
+
if (t[2]) _.ops.pop();
|
|
52
|
+
_.trys.pop(); continue;
|
|
53
|
+
}
|
|
54
|
+
op = body.call(thisArg, _);
|
|
55
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
56
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
60
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
61
|
+
if (ar || !(i in from)) {
|
|
62
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
63
|
+
ar[i] = from[i];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
67
|
+
};
|
|
12
68
|
import { leafShapesOf } from '../../engine/core/scene.js';
|
|
13
69
|
import { rasterBoundsOf, renderShapesToDataUrl } from '../../engine/render/rasterize.js';
|
|
14
|
-
import {
|
|
70
|
+
import { selectionConversionBounds } from '../../engine/widgets.js';
|
|
15
71
|
import { hostCustomTypeOf, hostObjectById, hostTypeOf, selectedHostObject } from './hostObject.js';
|
|
16
72
|
/** Message key integrators pass through `translate` as `untitledShapeName` in {@link buildConversionPayload}. */
|
|
17
|
-
export
|
|
73
|
+
export var UNTITLED_SHAPE_MESSAGE_KEY = 'canvas.defaults.untitledShape';
|
|
18
74
|
/** The background of a screenshot: opaque, so a model that reads a transparent PNG as black still sees the drawing. */
|
|
19
|
-
export
|
|
75
|
+
export var SCREENSHOT_BACKGROUND = '#ffffff';
|
|
20
76
|
/** A screenshot is twice the size of the board (as the canvas it replaces made them), so small text stays legible. */
|
|
21
|
-
export
|
|
77
|
+
export var SCREENSHOT_SCALE = 2;
|
|
22
78
|
/** What is selected, as the conversion and the capture see it. Null when nothing is. */
|
|
23
79
|
export function describeSelection(engine) {
|
|
24
|
-
|
|
80
|
+
var _a;
|
|
81
|
+
var selectedIds = engine.state.selectedIds;
|
|
25
82
|
if (selectedIds.length === 0)
|
|
26
83
|
return null;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
84
|
+
var units = engine.selectedObjects();
|
|
85
|
+
var shapes = leafShapesOf(engine.state.scene, selectedIds);
|
|
86
|
+
var bounds = selectionConversionBounds(engine);
|
|
30
87
|
if (units.length === 0 || shapes.length === 0 || !bounds)
|
|
31
88
|
return null;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
89
|
+
var host = selectedHostObject(engine);
|
|
90
|
+
var name = host ? (host.id === '' ? host.type : ((_a = host._customType) !== null && _a !== void 0 ? _a : host.type)) : 'object';
|
|
91
|
+
var kinds = new Set(shapes.map(function (shape) { var _a; return (_a = hostCustomTypeOf(shape)) !== null && _a !== void 0 ? _a : hostTypeOf(shape); }));
|
|
35
92
|
return {
|
|
36
|
-
units,
|
|
37
|
-
shapes,
|
|
38
|
-
bounds,
|
|
39
|
-
name,
|
|
40
|
-
shapeTypes: [
|
|
41
|
-
hasImages: shapes.some((shape)
|
|
42
|
-
hasText: shapes.some((shape)
|
|
93
|
+
units: units,
|
|
94
|
+
shapes: shapes,
|
|
95
|
+
bounds: bounds,
|
|
96
|
+
name: name,
|
|
97
|
+
shapeTypes: __spreadArray([], kinds, true),
|
|
98
|
+
hasImages: shapes.some(function (shape) { return shape.type === 'image' && Boolean(shape.src || shape.imageRef); }),
|
|
99
|
+
hasText: shapes.some(function (shape) { return shape.type === 'text'; })
|
|
43
100
|
};
|
|
44
101
|
}
|
|
45
102
|
/** A PNG of some shapes on a plain background, cropped to what they cover. Empty when there is nothing to draw. */
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
103
|
+
export function screenshotOfShapes(shapes, deps) {
|
|
104
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
105
|
+
var error_1;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
if (shapes.length === 0 || !rasterBoundsOf(shapes))
|
|
110
|
+
return [2 /*return*/, ''];
|
|
111
|
+
_a.label = 1;
|
|
112
|
+
case 1:
|
|
113
|
+
_a.trys.push([1, 3, , 4]);
|
|
114
|
+
return [4 /*yield*/, renderShapesToDataUrl(shapes, deps.raster, {
|
|
115
|
+
scale: SCREENSHOT_SCALE,
|
|
116
|
+
background: SCREENSHOT_BACKGROUND,
|
|
117
|
+
widgetFallbackName: deps.widgetFallbackName
|
|
118
|
+
})];
|
|
119
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
120
|
+
case 3:
|
|
121
|
+
error_1 = _a.sent();
|
|
122
|
+
console.warn('Canvas: could not draw the screenshot', error_1);
|
|
123
|
+
return [2 /*return*/, ''];
|
|
124
|
+
case 4: return [2 /*return*/];
|
|
125
|
+
}
|
|
54
126
|
});
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
console.warn('Canvas: could not draw the screenshot', error);
|
|
58
|
-
return '';
|
|
59
|
-
}
|
|
127
|
+
});
|
|
60
128
|
}
|
|
61
129
|
/** What the host needs to turn a selection into a widget, or null when nothing is selected. */
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
130
|
+
export function buildConversionPayload(deps) {
|
|
131
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
132
|
+
var engine, conversions, selection, single, frameId, screenshot, frame;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
engine = deps.engine, conversions = deps.conversions;
|
|
137
|
+
selection = describeSelection(engine);
|
|
138
|
+
if (!selection)
|
|
139
|
+
return [2 /*return*/, null];
|
|
140
|
+
single = selection.units.length === 1 ? selection.units[0] : null;
|
|
141
|
+
frameId = single ? single.id : engine.services.createId('selection');
|
|
142
|
+
if (!single) {
|
|
143
|
+
conversions.remember(frameId, { unitIds: selection.units.map(function (unit) { return unit.id; }), bounds: selection.bounds });
|
|
144
|
+
}
|
|
145
|
+
return [4 /*yield*/, screenshotOfShapes(selection.shapes, deps)];
|
|
146
|
+
case 1:
|
|
147
|
+
screenshot = _a.sent();
|
|
148
|
+
frame = single ? hostObjectById(engine, single.id) : selectedHostObject(engine);
|
|
149
|
+
return [2 /*return*/, {
|
|
150
|
+
frameName: selection.name || deps.untitledShapeName,
|
|
151
|
+
frameId: frameId,
|
|
152
|
+
screenshot: screenshot,
|
|
153
|
+
canvasData: {
|
|
154
|
+
frame: frame ? __assign({}, frame) : {},
|
|
155
|
+
children: [],
|
|
156
|
+
bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height }
|
|
157
|
+
},
|
|
158
|
+
metadata: {
|
|
159
|
+
childCount: selection.shapes.length,
|
|
160
|
+
shapeTypes: selection.shapeTypes,
|
|
161
|
+
hasImages: selection.hasImages,
|
|
162
|
+
hasText: selection.hasText
|
|
163
|
+
}
|
|
164
|
+
}];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
92
168
|
}
|
|
93
169
|
/** The extra facts the host is given about what was captured. */
|
|
94
170
|
function metadataOf(selection) {
|
|
95
|
-
|
|
96
|
-
|
|
171
|
+
var _a, _b, _c;
|
|
172
|
+
var metadata = {};
|
|
173
|
+
var only = selection.shapes.length === 1 && selection.units.length === 1 ? selection.shapes[0] : null;
|
|
97
174
|
if (only && only.type === 'image') {
|
|
98
175
|
metadata.hasImage = Boolean(only.src || only.imageRef);
|
|
99
|
-
metadata.imageUrl = only.src
|
|
100
|
-
metadata.originalFilename = only.fileName
|
|
176
|
+
metadata.imageUrl = (_a = only.src) !== null && _a !== void 0 ? _a : null;
|
|
177
|
+
metadata.originalFilename = (_b = only.fileName) !== null && _b !== void 0 ? _b : null;
|
|
101
178
|
}
|
|
102
179
|
if (only && only.type === 'text')
|
|
103
180
|
metadata.text = only.text;
|
|
104
|
-
if (selection.units.length > 1 || selection.units[0]
|
|
181
|
+
if (selection.units.length > 1 || ((_c = selection.units[0]) === null || _c === void 0 ? void 0 : _c.type) === 'group')
|
|
105
182
|
metadata.objectCount = selection.shapes.length;
|
|
106
183
|
return metadata;
|
|
107
184
|
}
|
|
108
185
|
/** What the host is given when a selection is captured (the "capture" button of the selection panel). */
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
186
|
+
export function buildCapturePayload(deps) {
|
|
187
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
188
|
+
var engine, selection, single, screenshot, host;
|
|
189
|
+
var _a, _b;
|
|
190
|
+
return __generator(this, function (_c) {
|
|
191
|
+
switch (_c.label) {
|
|
192
|
+
case 0:
|
|
193
|
+
engine = deps.engine;
|
|
194
|
+
selection = describeSelection(engine);
|
|
195
|
+
if (!selection)
|
|
196
|
+
return [2 /*return*/, null];
|
|
197
|
+
single = selection.units.length === 1 ? selection.units[0] : null;
|
|
198
|
+
return [4 /*yield*/, screenshotOfShapes(selection.shapes, deps)];
|
|
199
|
+
case 1:
|
|
200
|
+
screenshot = _c.sent();
|
|
201
|
+
host = selectedHostObject(engine);
|
|
202
|
+
return [2 /*return*/, {
|
|
203
|
+
screenshot: screenshot,
|
|
204
|
+
objectType: (_a = host === null || host === void 0 ? void 0 : host.type) !== null && _a !== void 0 ? _a : 'unknown',
|
|
205
|
+
customType: (_b = host === null || host === void 0 ? void 0 : host._customType) !== null && _b !== void 0 ? _b : undefined,
|
|
206
|
+
bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height },
|
|
207
|
+
objectId: single ? single.id : engine.services.createId('selection'),
|
|
208
|
+
metadata: metadataOf(selection)
|
|
209
|
+
}];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
125
213
|
}
|
|
@@ -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. */
|
|
@@ -25,44 +25,47 @@
|
|
|
25
25
|
import { rectsIntersect } from '../../engine/core/geometry.js';
|
|
26
26
|
import { visibleWorldRect } from '../../engine/core/viewport.js';
|
|
27
27
|
/** A board with fewer cards than this lists every one of them. */
|
|
28
|
-
export
|
|
28
|
+
export var NEAR_CARDS_MINIMUM = 8;
|
|
29
29
|
/** How far past the view a card is listed, as a share of the view's width and height, on every side. */
|
|
30
|
-
export
|
|
30
|
+
export var NEAR_CARD_MARGIN_RATIO = 1;
|
|
31
31
|
/** How far past the view a card that is listed already stays listed, in the same measure. More than `NEAR_CARD_MARGIN_RATIO`. */
|
|
32
|
-
export
|
|
32
|
+
export var KEEP_CARD_MARGIN_RATIO = 2;
|
|
33
33
|
/** A view with `ratio` of its width and height added on every side. */
|
|
34
34
|
function viewWithMargin(view, ratio) {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
var marginX = view.width * ratio;
|
|
36
|
+
var marginY = view.height * ratio;
|
|
37
37
|
return { x: view.x - marginX, y: view.y - marginY, width: view.width + marginX * 2, height: view.height + marginY * 2 };
|
|
38
38
|
}
|
|
39
39
|
/** A rectangle made of finite numbers, with some size: anything else says the board has no size (or no view) yet. */
|
|
40
40
|
function isUsableView(view) {
|
|
41
41
|
return Number.isFinite(view.x) && Number.isFinite(view.y) && Number.isFinite(view.width) && Number.isFinite(view.height) && view.width > 0 && view.height > 0;
|
|
42
42
|
}
|
|
43
|
-
export function createNearCards(options
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
export function createNearCards(options) {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
if (options === void 0) { options = {}; }
|
|
46
|
+
var minimumCards = (_a = options.minimumCards) !== null && _a !== void 0 ? _a : NEAR_CARDS_MINIMUM;
|
|
47
|
+
var nearMarginRatio = (_b = options.nearMarginRatio) !== null && _b !== void 0 ? _b : NEAR_CARD_MARGIN_RATIO;
|
|
48
|
+
var keepMarginRatio = Math.max(nearMarginRatio, (_c = options.keepMarginRatio) !== null && _c !== void 0 ? _c : KEEP_CARD_MARGIN_RATIO);
|
|
47
49
|
/** The ids that were listed the last time: the cards that keep their place while they are inside the keep area. */
|
|
48
|
-
|
|
50
|
+
var listed = new Set();
|
|
49
51
|
function listEveryCard(cards) {
|
|
50
|
-
listed = new Set(cards.map((card)
|
|
52
|
+
listed = new Set(cards.map(function (card) { return card.widgetId; }));
|
|
51
53
|
return new Set(listed);
|
|
52
54
|
}
|
|
53
55
|
return {
|
|
54
|
-
choose(cards, viewport, viewSize) {
|
|
56
|
+
choose: function (cards, viewport, viewSize) {
|
|
55
57
|
if (cards.length < minimumCards)
|
|
56
58
|
return listEveryCard(cards);
|
|
57
59
|
if (!Number.isFinite(viewport.zoom) || viewport.zoom <= 0)
|
|
58
60
|
return listEveryCard(cards);
|
|
59
|
-
|
|
61
|
+
var view = visibleWorldRect(viewport, viewSize);
|
|
60
62
|
if (!isUsableView(view))
|
|
61
63
|
return listEveryCard(cards);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (
|
|
64
|
+
var nearArea = viewWithMargin(view, nearMarginRatio);
|
|
65
|
+
var keepArea = viewWithMargin(view, keepMarginRatio);
|
|
66
|
+
var next = new Set();
|
|
67
|
+
for (var _i = 0, cards_1 = cards; _i < cards_1.length; _i++) {
|
|
68
|
+
var card = cards_1[_i];
|
|
66
69
|
if (card.always || rectsIntersect(nearArea, card.bounds) || (listed.has(card.widgetId) && rectsIntersect(keepArea, card.bounds))) {
|
|
67
70
|
next.add(card.widgetId);
|
|
68
71
|
}
|
|
@@ -70,7 +73,7 @@ export function createNearCards(options = {}) {
|
|
|
70
73
|
listed = next;
|
|
71
74
|
return new Set(next);
|
|
72
75
|
},
|
|
73
|
-
reset() {
|
|
76
|
+
reset: function () {
|
|
74
77
|
if (listed.size > 0)
|
|
75
78
|
listed = new Set();
|
|
76
79
|
}
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
* Kept free of Svelte so that Node can test it. A page rendered on the server has no `window` and gets nothing.
|
|
17
17
|
*/
|
|
18
18
|
import { canvasWarn } from '../canvasLogger.js';
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
19
|
+
export var CANVAS_SELECT_TOOL_EVENT = 'widgetic:canvas-select-tool';
|
|
20
|
+
export var CANVAS_TOOL_EVENT = 'widgetic:canvas-tool';
|
|
21
|
+
export var WIDGET_POINTER_BLOCK_EVENT = 'widgetic:widget-shape-pointer-block';
|
|
22
22
|
function dispatchOnWindow(name, detail) {
|
|
23
23
|
if (typeof window === 'undefined' || typeof CustomEvent === 'undefined')
|
|
24
24
|
return;
|
|
25
25
|
try {
|
|
26
|
-
window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail }));
|
|
26
|
+
window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail: detail }));
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
29
|
// A page that cannot take the event keeps its canvas.
|
|
30
|
-
canvasWarn(
|
|
30
|
+
canvasWarn("Canvas: could not send ".concat(name), error);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
/** The Select tool was chosen. */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export function createPictureSaveMemory() {
|
|
2
2
|
/** The store the memory is about. */
|
|
3
|
-
|
|
3
|
+
var rememberedFor = null;
|
|
4
4
|
/** Reference → the bytes the store accepted for it. */
|
|
5
|
-
|
|
5
|
+
var remembered = new Map();
|
|
6
6
|
/** What the save that is on its way has handed over or found already handed over, by reference; null between saves. */
|
|
7
|
-
|
|
7
|
+
var thisSave = null;
|
|
8
8
|
return {
|
|
9
|
-
startSave(store) {
|
|
9
|
+
startSave: function (store) {
|
|
10
10
|
if (!store) {
|
|
11
11
|
thisSave = null;
|
|
12
12
|
return null;
|
|
@@ -15,10 +15,10 @@ export function createPictureSaveMemory() {
|
|
|
15
15
|
rememberedFor = store;
|
|
16
16
|
remembered = new Map();
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
var seenInThisSave = new Map();
|
|
19
19
|
thisSave = seenInThisSave;
|
|
20
20
|
return {
|
|
21
|
-
save(reference, dataUrl) {
|
|
21
|
+
save: function (reference, dataUrl) {
|
|
22
22
|
// A throw from the store is the writer's to deal with, and nothing is noted for it.
|
|
23
23
|
if (remembered.get(reference) !== dataUrl)
|
|
24
24
|
store.save(reference, dataUrl);
|
|
@@ -26,8 +26,8 @@ export function createPictureSaveMemory() {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
},
|
|
29
|
-
finishSave(completed) {
|
|
30
|
-
|
|
29
|
+
finishSave: function (completed) {
|
|
30
|
+
var seenInThisSave = thisSave;
|
|
31
31
|
thisSave = null;
|
|
32
32
|
if (!seenInThisSave)
|
|
33
33
|
return;
|
|
@@ -35,8 +35,10 @@ export function createPictureSaveMemory() {
|
|
|
35
35
|
remembered = seenInThisSave;
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
for (
|
|
38
|
+
for (var _i = 0, seenInThisSave_1 = seenInThisSave; _i < seenInThisSave_1.length; _i++) {
|
|
39
|
+
var _a = seenInThisSave_1[_i], reference = _a[0], dataUrl = _a[1];
|
|
39
40
|
remembered.set(reference, dataUrl);
|
|
41
|
+
}
|
|
40
42
|
}
|
|
41
43
|
};
|
|
42
44
|
}
|
|
@@ -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),
|