@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
|
@@ -9,205 +9,117 @@
|
|
|
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
|
-
};
|
|
68
12
|
import { leafShapesOf } from '../../engine/core/scene.js';
|
|
69
13
|
import { rasterBoundsOf, renderShapesToDataUrl } from '../../engine/render/rasterize.js';
|
|
70
|
-
import { selectionConversionBounds } from '../../engine/widgets.js';
|
|
14
|
+
import { ConversionRegistry, selectionConversionBounds } from '../../engine/widgets.js';
|
|
71
15
|
import { hostCustomTypeOf, hostObjectById, hostTypeOf, selectedHostObject } from './hostObject.js';
|
|
72
16
|
/** Message key integrators pass through `translate` as `untitledShapeName` in {@link buildConversionPayload}. */
|
|
73
|
-
export
|
|
17
|
+
export const UNTITLED_SHAPE_MESSAGE_KEY = 'canvas.defaults.untitledShape';
|
|
74
18
|
/** The background of a screenshot: opaque, so a model that reads a transparent PNG as black still sees the drawing. */
|
|
75
|
-
export
|
|
19
|
+
export const SCREENSHOT_BACKGROUND = '#ffffff';
|
|
76
20
|
/** A screenshot is twice the size of the board (as the canvas it replaces made them), so small text stays legible. */
|
|
77
|
-
export
|
|
21
|
+
export const SCREENSHOT_SCALE = 2;
|
|
78
22
|
/** What is selected, as the conversion and the capture see it. Null when nothing is. */
|
|
79
23
|
export function describeSelection(engine) {
|
|
80
|
-
|
|
81
|
-
var selectedIds = engine.state.selectedIds;
|
|
24
|
+
const { selectedIds } = engine.state;
|
|
82
25
|
if (selectedIds.length === 0)
|
|
83
26
|
return null;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
27
|
+
const units = engine.selectedObjects();
|
|
28
|
+
const shapes = leafShapesOf(engine.state.scene, selectedIds);
|
|
29
|
+
const bounds = selectionConversionBounds(engine);
|
|
87
30
|
if (units.length === 0 || shapes.length === 0 || !bounds)
|
|
88
31
|
return null;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
32
|
+
const host = selectedHostObject(engine);
|
|
33
|
+
const name = host ? (host.id === '' ? host.type : (host._customType ?? host.type)) : 'object';
|
|
34
|
+
const kinds = new Set(shapes.map((shape) => hostCustomTypeOf(shape) ?? hostTypeOf(shape)));
|
|
92
35
|
return {
|
|
93
|
-
units
|
|
94
|
-
shapes
|
|
95
|
-
bounds
|
|
96
|
-
name
|
|
97
|
-
shapeTypes:
|
|
98
|
-
hasImages: shapes.some(
|
|
99
|
-
hasText: shapes.some(
|
|
36
|
+
units,
|
|
37
|
+
shapes,
|
|
38
|
+
bounds,
|
|
39
|
+
name,
|
|
40
|
+
shapeTypes: [...kinds],
|
|
41
|
+
hasImages: shapes.some((shape) => shape.type === 'image' && Boolean(shape.src || shape.imageRef)),
|
|
42
|
+
hasText: shapes.some((shape) => shape.type === 'text')
|
|
100
43
|
};
|
|
101
44
|
}
|
|
102
45
|
/** A PNG of some shapes on a plain background, cropped to what they cover. Empty when there is nothing to draw. */
|
|
103
|
-
export function screenshotOfShapes(shapes, deps) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
}
|
|
46
|
+
export async function screenshotOfShapes(shapes, deps) {
|
|
47
|
+
if (shapes.length === 0 || !rasterBoundsOf(shapes))
|
|
48
|
+
return '';
|
|
49
|
+
try {
|
|
50
|
+
return await renderShapesToDataUrl(shapes, deps.raster, {
|
|
51
|
+
scale: SCREENSHOT_SCALE,
|
|
52
|
+
background: SCREENSHOT_BACKGROUND,
|
|
53
|
+
widgetFallbackName: deps.widgetFallbackName
|
|
126
54
|
});
|
|
127
|
-
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.warn('Canvas: could not draw the screenshot', error);
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
128
60
|
}
|
|
129
61
|
/** What the host needs to turn a selection into a widget, or null when nothing is selected. */
|
|
130
|
-
export function buildConversionPayload(deps) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
shapeTypes: selection.shapeTypes,
|
|
161
|
-
hasImages: selection.hasImages,
|
|
162
|
-
hasText: selection.hasText
|
|
163
|
-
}
|
|
164
|
-
}];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
62
|
+
export async function buildConversionPayload(deps) {
|
|
63
|
+
const { engine, conversions } = deps;
|
|
64
|
+
const selection = describeSelection(engine);
|
|
65
|
+
if (!selection)
|
|
66
|
+
return null;
|
|
67
|
+
// One object is converted by its own id. Several have none: the selection gets one and is remembered under it,
|
|
68
|
+
// before anything (the screenshot takes a moment) can clear the selection.
|
|
69
|
+
const single = selection.units.length === 1 ? selection.units[0] : null;
|
|
70
|
+
const frameId = single ? single.id : engine.services.createId('selection');
|
|
71
|
+
if (!single) {
|
|
72
|
+
conversions.remember(frameId, { unitIds: selection.units.map((unit) => unit.id), bounds: selection.bounds });
|
|
73
|
+
}
|
|
74
|
+
const screenshot = await screenshotOfShapes(selection.shapes, deps);
|
|
75
|
+
const frame = single ? hostObjectById(engine, single.id) : selectedHostObject(engine);
|
|
76
|
+
return {
|
|
77
|
+
frameName: selection.name || deps.untitledShapeName,
|
|
78
|
+
frameId,
|
|
79
|
+
screenshot,
|
|
80
|
+
canvasData: {
|
|
81
|
+
frame: frame ? { ...frame } : {},
|
|
82
|
+
children: [],
|
|
83
|
+
bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height }
|
|
84
|
+
},
|
|
85
|
+
metadata: {
|
|
86
|
+
childCount: selection.shapes.length,
|
|
87
|
+
shapeTypes: selection.shapeTypes,
|
|
88
|
+
hasImages: selection.hasImages,
|
|
89
|
+
hasText: selection.hasText
|
|
90
|
+
}
|
|
91
|
+
};
|
|
168
92
|
}
|
|
169
93
|
/** The extra facts the host is given about what was captured. */
|
|
170
94
|
function metadataOf(selection) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
var only = selection.shapes.length === 1 && selection.units.length === 1 ? selection.shapes[0] : null;
|
|
95
|
+
const metadata = {};
|
|
96
|
+
const only = selection.shapes.length === 1 && selection.units.length === 1 ? selection.shapes[0] : null;
|
|
174
97
|
if (only && only.type === 'image') {
|
|
175
98
|
metadata.hasImage = Boolean(only.src || only.imageRef);
|
|
176
|
-
metadata.imageUrl =
|
|
177
|
-
metadata.originalFilename =
|
|
99
|
+
metadata.imageUrl = only.src ?? null;
|
|
100
|
+
metadata.originalFilename = only.fileName ?? null;
|
|
178
101
|
}
|
|
179
102
|
if (only && only.type === 'text')
|
|
180
103
|
metadata.text = only.text;
|
|
181
|
-
if (selection.units.length > 1 ||
|
|
104
|
+
if (selection.units.length > 1 || selection.units[0]?.type === 'group')
|
|
182
105
|
metadata.objectCount = selection.shapes.length;
|
|
183
106
|
return metadata;
|
|
184
107
|
}
|
|
185
108
|
/** What the host is given when a selection is captured (the "capture" button of the selection panel). */
|
|
186
|
-
export function buildCapturePayload(deps) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
});
|
|
109
|
+
export async function buildCapturePayload(deps) {
|
|
110
|
+
const { engine } = deps;
|
|
111
|
+
const selection = describeSelection(engine);
|
|
112
|
+
if (!selection)
|
|
113
|
+
return null;
|
|
114
|
+
const single = selection.units.length === 1 ? selection.units[0] : null;
|
|
115
|
+
const screenshot = await screenshotOfShapes(selection.shapes, deps);
|
|
116
|
+
const host = selectedHostObject(engine);
|
|
117
|
+
return {
|
|
118
|
+
screenshot,
|
|
119
|
+
objectType: host?.type ?? 'unknown',
|
|
120
|
+
customType: host?._customType ?? undefined,
|
|
121
|
+
bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height },
|
|
122
|
+
objectId: single ? single.id : engine.services.createId('selection'),
|
|
123
|
+
metadata: metadataOf(selection)
|
|
124
|
+
};
|
|
213
125
|
}
|
|
@@ -41,7 +41,7 @@ export function hostCustomTypeOf(object) {
|
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
function viewOf(object, index, scene) {
|
|
44
|
-
|
|
44
|
+
const 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(
|
|
57
|
+
view.objects = scene.filter((member) => member.parentId === object.id).map((member) => 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
|
+
const 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
|
+
const selected = engine.selectedObjects();
|
|
76
76
|
if (selected.length === 0)
|
|
77
77
|
return null;
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const index = engine.sceneIndex();
|
|
79
|
+
const 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(
|
|
87
|
+
objects: selected.map((object) => 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,47 +25,44 @@
|
|
|
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 const 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 const 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 const 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
|
+
const marginX = view.width * ratio;
|
|
36
|
+
const 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
|
-
|
|
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);
|
|
43
|
+
export function createNearCards(options = {}) {
|
|
44
|
+
const minimumCards = options.minimumCards ?? NEAR_CARDS_MINIMUM;
|
|
45
|
+
const nearMarginRatio = options.nearMarginRatio ?? NEAR_CARD_MARGIN_RATIO;
|
|
46
|
+
const keepMarginRatio = Math.max(nearMarginRatio, options.keepMarginRatio ?? KEEP_CARD_MARGIN_RATIO);
|
|
49
47
|
/** The ids that were listed the last time: the cards that keep their place while they are inside the keep area. */
|
|
50
|
-
|
|
48
|
+
let listed = new Set();
|
|
51
49
|
function listEveryCard(cards) {
|
|
52
|
-
listed = new Set(cards.map(
|
|
50
|
+
listed = new Set(cards.map((card) => card.widgetId));
|
|
53
51
|
return new Set(listed);
|
|
54
52
|
}
|
|
55
53
|
return {
|
|
56
|
-
choose
|
|
54
|
+
choose(cards, viewport, viewSize) {
|
|
57
55
|
if (cards.length < minimumCards)
|
|
58
56
|
return listEveryCard(cards);
|
|
59
57
|
if (!Number.isFinite(viewport.zoom) || viewport.zoom <= 0)
|
|
60
58
|
return listEveryCard(cards);
|
|
61
|
-
|
|
59
|
+
const view = visibleWorldRect(viewport, viewSize);
|
|
62
60
|
if (!isUsableView(view))
|
|
63
61
|
return listEveryCard(cards);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (
|
|
68
|
-
var card = cards_1[_i];
|
|
62
|
+
const nearArea = viewWithMargin(view, nearMarginRatio);
|
|
63
|
+
const keepArea = viewWithMargin(view, keepMarginRatio);
|
|
64
|
+
const next = new Set();
|
|
65
|
+
for (const card of cards) {
|
|
69
66
|
if (card.always || rectsIntersect(nearArea, card.bounds) || (listed.has(card.widgetId) && rectsIntersect(keepArea, card.bounds))) {
|
|
70
67
|
next.add(card.widgetId);
|
|
71
68
|
}
|
|
@@ -73,7 +70,7 @@ export function createNearCards(options) {
|
|
|
73
70
|
listed = next;
|
|
74
71
|
return new Set(next);
|
|
75
72
|
},
|
|
76
|
-
reset
|
|
73
|
+
reset() {
|
|
77
74
|
if (listed.size > 0)
|
|
78
75
|
listed = new Set();
|
|
79
76
|
}
|
|
@@ -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 const CANVAS_SELECT_TOOL_EVENT = 'widgetic:canvas-select-tool';
|
|
20
|
+
export const CANVAS_TOOL_EVENT = 'widgetic:canvas-tool';
|
|
21
|
+
export const 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 }));
|
|
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 ${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
|
+
let rememberedFor = null;
|
|
4
4
|
/** Reference → the bytes the store accepted for it. */
|
|
5
|
-
|
|
5
|
+
let 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
|
+
let thisSave = null;
|
|
8
8
|
return {
|
|
9
|
-
startSave
|
|
9
|
+
startSave(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
|
+
const seenInThisSave = new Map();
|
|
19
19
|
thisSave = seenInThisSave;
|
|
20
20
|
return {
|
|
21
|
-
save
|
|
21
|
+
save(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
|
|
30
|
-
|
|
29
|
+
finishSave(completed) {
|
|
30
|
+
const seenInThisSave = thisSave;
|
|
31
31
|
thisSave = null;
|
|
32
32
|
if (!seenInThisSave)
|
|
33
33
|
return;
|
|
@@ -35,10 +35,8 @@ export function createPictureSaveMemory() {
|
|
|
35
35
|
remembered = seenInThisSave;
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
for (
|
|
39
|
-
var _a = seenInThisSave_1[_i], reference = _a[0], dataUrl = _a[1];
|
|
38
|
+
for (const [reference, dataUrl] of seenInThisSave)
|
|
40
39
|
remembered.set(reference, dataUrl);
|
|
41
|
-
}
|
|
42
40
|
}
|
|
43
41
|
};
|
|
44
42
|
}
|
|
@@ -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
|
+
const layoutWidth = frame.layoutWidth && frame.layoutWidth > 0 ? frame.layoutWidth : frame.width;
|
|
15
|
+
const 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
|
+
const { scaleX, scaleY } = cssScaleOf(frame);
|
|
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
|
+
const { scaleX, scaleY } = cssScaleOf(frame);
|
|
32
|
+
const world = boxToWorldMatrix(box);
|
|
33
33
|
// page = frame + scale * (viewport.translate + zoom * world)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const zoomX = viewport.zoom * scaleX;
|
|
35
|
+
const zoomY = viewport.zoom * scaleY;
|
|
36
|
+
const matrix = [
|
|
37
37
|
world[0] * zoomX,
|
|
38
38
|
world[1] * zoomY,
|
|
39
39
|
world[2] * zoomX,
|
|
@@ -45,34 +45,31 @@ 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
|
+
const matrix = boxToPageMatrix(shape, viewport, frame);
|
|
49
49
|
if (!matrix)
|
|
50
50
|
return null;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const localWidth = shape.width || 1;
|
|
52
|
+
const localHeight = shape.height || 1;
|
|
53
|
+
const 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
|
-
|
|
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);
|
|
58
|
+
].map(([x, y]) => ({
|
|
59
|
+
x: matrix[0] * x + matrix[2] * y + matrix[4],
|
|
60
|
+
y: matrix[1] * x + matrix[3] * y + matrix[5]
|
|
61
|
+
}));
|
|
62
|
+
const xs = corners.map((corner) => corner.x);
|
|
63
|
+
const ys = corners.map((corner) => corner.y);
|
|
64
|
+
const left = Math.min(...xs);
|
|
65
|
+
const top = Math.min(...ys);
|
|
69
66
|
return {
|
|
70
|
-
left
|
|
71
|
-
top
|
|
72
|
-
width: Math.max
|
|
73
|
-
height: Math.max
|
|
74
|
-
localWidth
|
|
75
|
-
localHeight
|
|
67
|
+
left,
|
|
68
|
+
top,
|
|
69
|
+
width: Math.max(...xs) - left,
|
|
70
|
+
height: Math.max(...ys) - top,
|
|
71
|
+
localWidth,
|
|
72
|
+
localHeight,
|
|
76
73
|
// The old canvas answered with the matrix of the card's pixels, one unit per local pixel.
|
|
77
74
|
matrix: [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]]
|
|
78
75
|
};
|
|
@@ -83,8 +80,8 @@ export function screenRectOfShape(shape, viewport, frame) {
|
|
|
83
80
|
}
|
|
84
81
|
/** The box of a rectangle of the world on the page, with the board it sits on. */
|
|
85
82
|
export function screenRectOfBounds(bounds, viewport, frame) {
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
const topLeft = worldPointToPage(viewport, frame, bounds.x, bounds.y);
|
|
84
|
+
const bottomRight = worldPointToPage(viewport, frame, bounds.x + bounds.width, bounds.y + bounds.height);
|
|
88
85
|
return {
|
|
89
86
|
left: Math.min(topLeft.x, bottomRight.x),
|
|
90
87
|
top: Math.min(topLeft.y, bottomRight.y),
|