@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,16 +9,18 @@ export function estimateFontVerticalMetrics(fontSize) {
|
|
|
9
9
|
/**
|
|
10
10
|
* The height of one line in world units: glyph ascent+descent plus balanced leading inside the CSS line-height box.
|
|
11
11
|
*/
|
|
12
|
-
export function textLineExtent(style, metrics
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export function textLineExtent(style, metrics) {
|
|
13
|
+
if (metrics === void 0) { metrics = estimateFontVerticalMetrics(style.fontSize); }
|
|
14
|
+
var glyphHeight = metrics.ascent + metrics.descent;
|
|
15
|
+
var lineHeight = lineBoxHeight(style);
|
|
16
|
+
var leading = Math.max(0, lineHeight - glyphHeight);
|
|
16
17
|
return glyphHeight + leading;
|
|
17
18
|
}
|
|
18
19
|
/** Splits leading evenly above and below the glyph box inside one line. */
|
|
19
|
-
export function lineVerticalInsets(style, metrics
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
export function lineVerticalInsets(style, metrics) {
|
|
21
|
+
if (metrics === void 0) { metrics = estimateFontVerticalMetrics(style.fontSize); }
|
|
22
|
+
var extent = textLineExtent(style, metrics);
|
|
23
|
+
var glyphHeight = metrics.ascent + metrics.descent;
|
|
24
|
+
var slack = Math.max(0, extent - glyphHeight);
|
|
23
25
|
return { top: slack / 2, bottom: slack / 2 };
|
|
24
26
|
}
|
package/dist/engine/widgets.js
CHANGED
|
@@ -6,29 +6,55 @@
|
|
|
6
6
|
* card for a widget, turn a sketch into one, find the card of a widget, say which cards are orphans), written
|
|
7
7
|
* against the engine alone so each rule is tested in Node. The component forwards them one to one.
|
|
8
8
|
*/
|
|
9
|
+
var __assign = (this && this.__assign) || function () {
|
|
10
|
+
__assign = Object.assign || function(t) {
|
|
11
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
12
|
+
s = arguments[i];
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
};
|
|
18
|
+
return __assign.apply(this, arguments);
|
|
19
|
+
};
|
|
20
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
21
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
23
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
+
};
|
|
25
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
26
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
27
|
+
if (ar || !(i in from)) {
|
|
28
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
29
|
+
ar[i] = from[i];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
|
+
};
|
|
34
|
+
var _ConversionRegistry_snapshots;
|
|
9
35
|
import { createWidgetObject } from './core/defaults.js';
|
|
10
36
|
import { unionRects } from './core/geometry.js';
|
|
11
37
|
import { boundsOfObjects, leafShapesOf, normalizeScene, removeObjects as removeFromScene, shapeVisualBounds, topLevelAncestorId, withDescendantIds } from './core/scene.js';
|
|
12
38
|
/** The size of the card a new widget gets. */
|
|
13
|
-
export
|
|
39
|
+
export var WIDGET_CARD_SIZE = Object.freeze({ width: 400, height: 300 });
|
|
14
40
|
/** The space between cards placed side by side. */
|
|
15
|
-
export
|
|
41
|
+
export var WIDGET_CARD_GAP = 48;
|
|
16
42
|
/** How many cards stand in a row before the next row starts. */
|
|
17
|
-
export
|
|
43
|
+
export var WIDGET_CARD_MAX_COLUMNS = 4;
|
|
18
44
|
/** A sketch turned into a card is never smaller than this, however little was drawn. */
|
|
19
|
-
export
|
|
45
|
+
export var ABSORBED_CARD_MIN_SIZE = Object.freeze({ width: 120, height: 80 });
|
|
20
46
|
/** Where the card goes when nothing on the board has a size to take. */
|
|
21
|
-
export
|
|
47
|
+
export var ABSORBED_CARD_FALLBACK_ORIGIN = Object.freeze({ x: 80, y: 80 });
|
|
22
48
|
/** The prefix of the id of a card made here. */
|
|
23
|
-
|
|
49
|
+
var CARD_ID_PREFIX = 'widget_img';
|
|
24
50
|
function cardsOf(scene) {
|
|
25
|
-
return scene.filter((object)
|
|
51
|
+
return scene.filter(function (object) { return object.type === 'widget'; });
|
|
26
52
|
}
|
|
27
53
|
/** The first card that stands for the widget, or undefined. */
|
|
28
54
|
export function findWidgetCard(engine, widgetId) {
|
|
29
55
|
if (!widgetId)
|
|
30
56
|
return undefined;
|
|
31
|
-
return cardsOf(engine.state.scene).find((card)
|
|
57
|
+
return cardsOf(engine.state.scene).find(function (card) { return card.widgetId === widgetId; });
|
|
32
58
|
}
|
|
33
59
|
/** The rectangle around the shapes of some units, strokes included: what a screenshot of them would show. */
|
|
34
60
|
function visualBoundsOfUnits(scene, ids) {
|
|
@@ -39,21 +65,23 @@ function visualBoundsOfUnits(scene, ids) {
|
|
|
39
65
|
* cards in rows of up to four around that middle, so a batch of widgets does not land on top of each other.
|
|
40
66
|
* The card becomes the selection. Returns its id.
|
|
41
67
|
*/
|
|
42
|
-
export function addWidgetCard(engine, widgetId, options
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
68
|
+
export function addWidgetCard(engine, widgetId, options) {
|
|
69
|
+
var _a;
|
|
70
|
+
if (options === void 0) { options = {}; }
|
|
71
|
+
var totalCount = Math.max(1, Math.floor(Number.isFinite(options.totalCount) ? options.totalCount : 1));
|
|
72
|
+
var gridIndex = Math.max(0, Math.floor(Number.isFinite(options.gridIndex) ? options.gridIndex : 0));
|
|
73
|
+
var center = engine.visibleCenter();
|
|
74
|
+
var columns = Math.min(totalCount, WIDGET_CARD_MAX_COLUMNS);
|
|
75
|
+
var rows = Math.max(1, Math.ceil(totalCount / columns));
|
|
76
|
+
var column = gridIndex % columns;
|
|
77
|
+
var row = Math.floor(gridIndex / columns);
|
|
50
78
|
// The whole grid is centred on the middle of the view: each card is shifted by half of the extent of the grid.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
79
|
+
var offsetX = (column - (columns - 1) / 2) * (WIDGET_CARD_SIZE.width + WIDGET_CARD_GAP);
|
|
80
|
+
var offsetY = (row - (rows - 1) / 2) * (WIDGET_CARD_SIZE.height + WIDGET_CARD_GAP);
|
|
81
|
+
var card = createWidgetObject({
|
|
54
82
|
id: engine.services.createId(CARD_ID_PREFIX),
|
|
55
|
-
widgetId,
|
|
56
|
-
widgetName: options.name
|
|
83
|
+
widgetId: widgetId,
|
|
84
|
+
widgetName: (_a = options.name) !== null && _a !== void 0 ? _a : null,
|
|
57
85
|
x: center.x - WIDGET_CARD_SIZE.width / 2 + offsetX,
|
|
58
86
|
y: center.y - WIDGET_CARD_SIZE.height / 2 + offsetY,
|
|
59
87
|
width: WIDGET_CARD_SIZE.width,
|
|
@@ -74,27 +102,22 @@ export function absorbSketchIntoWidget(engine, widgetId, screenshot) {
|
|
|
74
102
|
return null;
|
|
75
103
|
engine.endTextEdit();
|
|
76
104
|
engine.clearSelection();
|
|
77
|
-
|
|
78
|
-
|
|
105
|
+
var scene = engine.state.scene;
|
|
106
|
+
var shapes = scene.filter(function (object) { return object.type !== 'group'; });
|
|
79
107
|
if (shapes.length === 0) {
|
|
80
108
|
return addWidgetCard(engine, widgetId, { previewImage: screenshot || null });
|
|
81
109
|
}
|
|
82
|
-
if (shapes.every((shape)
|
|
110
|
+
if (shapes.every(function (shape) { return shape.type === 'widget' && shape.widgetId === widgetId; })) {
|
|
83
111
|
return shapes[0].id;
|
|
84
112
|
}
|
|
85
|
-
|
|
86
|
-
|
|
113
|
+
var bounds = visualBoundsOfUnits(scene, scene.map(function (object) { return object.id; }));
|
|
114
|
+
var box = {
|
|
87
115
|
x: bounds ? bounds.x : ABSORBED_CARD_FALLBACK_ORIGIN.x,
|
|
88
116
|
y: bounds ? bounds.y : ABSORBED_CARD_FALLBACK_ORIGIN.y,
|
|
89
117
|
width: Math.max(ABSORBED_CARD_MIN_SIZE.width, bounds ? bounds.width : 0),
|
|
90
118
|
height: Math.max(ABSORBED_CARD_MIN_SIZE.height, bounds ? bounds.height : 0)
|
|
91
119
|
};
|
|
92
|
-
|
|
93
|
-
id: engine.services.createId(CARD_ID_PREFIX),
|
|
94
|
-
widgetId,
|
|
95
|
-
...box,
|
|
96
|
-
thumbnail: screenshot || null
|
|
97
|
-
});
|
|
120
|
+
var card = createWidgetObject(__assign(__assign({ id: engine.services.createId(CARD_ID_PREFIX), widgetId: widgetId }, box), { thumbnail: screenshot || null }));
|
|
98
121
|
engine.applyScene([card], 'push');
|
|
99
122
|
engine.select([card.id]);
|
|
100
123
|
return card.id;
|
|
@@ -104,25 +127,30 @@ export function absorbSketchIntoWidget(engine, widgetId, screenshot) {
|
|
|
104
127
|
* selection can be gone by the time the host answers (clicking elsewhere clears it), and the answer still has to
|
|
105
128
|
* replace exactly those objects, so the choice is kept here, not looked up again.
|
|
106
129
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.#snapshots.set(id, snapshot);
|
|
130
|
+
var ConversionRegistry = /** @class */ (function () {
|
|
131
|
+
function ConversionRegistry() {
|
|
132
|
+
_ConversionRegistry_snapshots.set(this, new Map());
|
|
111
133
|
}
|
|
134
|
+
ConversionRegistry.prototype.remember = function (id, snapshot) {
|
|
135
|
+
__classPrivateFieldGet(this, _ConversionRegistry_snapshots, "f").set(id, snapshot);
|
|
136
|
+
};
|
|
112
137
|
/** The snapshot for an id, left in place (the host asks where a draft is on the screen while it makes the widget). */
|
|
113
|
-
peek(id) {
|
|
114
|
-
return this
|
|
115
|
-
}
|
|
138
|
+
ConversionRegistry.prototype.peek = function (id) {
|
|
139
|
+
return __classPrivateFieldGet(this, _ConversionRegistry_snapshots, "f").get(id);
|
|
140
|
+
};
|
|
116
141
|
/** The snapshot for an id, forgotten at the same time (a conversion is answered once). */
|
|
117
|
-
take(id) {
|
|
118
|
-
|
|
119
|
-
this
|
|
142
|
+
ConversionRegistry.prototype.take = function (id) {
|
|
143
|
+
var snapshot = __classPrivateFieldGet(this, _ConversionRegistry_snapshots, "f").get(id);
|
|
144
|
+
__classPrivateFieldGet(this, _ConversionRegistry_snapshots, "f").delete(id);
|
|
120
145
|
return snapshot;
|
|
121
|
-
}
|
|
122
|
-
clear() {
|
|
123
|
-
this
|
|
124
|
-
}
|
|
125
|
-
|
|
146
|
+
};
|
|
147
|
+
ConversionRegistry.prototype.clear = function () {
|
|
148
|
+
__classPrivateFieldGet(this, _ConversionRegistry_snapshots, "f").clear();
|
|
149
|
+
};
|
|
150
|
+
return ConversionRegistry;
|
|
151
|
+
}());
|
|
152
|
+
export { ConversionRegistry };
|
|
153
|
+
_ConversionRegistry_snapshots = new WeakMap();
|
|
126
154
|
/**
|
|
127
155
|
* Replaces an object (or what a conversion remembered under that id) with a card for the widget, at the same
|
|
128
156
|
* place and size, showing the screenshot. What was drawn there is removed with it, groups included. One undo
|
|
@@ -131,22 +159,22 @@ export class ConversionRegistry {
|
|
|
131
159
|
export function replaceObjectWithWidgetCard(engine, conversions, objectId, widgetId, screenshot) {
|
|
132
160
|
if (!objectId || !widgetId)
|
|
133
161
|
return null;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
162
|
+
var scene = engine.state.scene;
|
|
163
|
+
var index = engine.sceneIndex(scene);
|
|
164
|
+
var remembered = conversions.take(objectId);
|
|
165
|
+
var unitIds;
|
|
166
|
+
var bounds;
|
|
167
|
+
var opacity = 1;
|
|
140
168
|
if (remembered) {
|
|
141
|
-
unitIds = remembered.unitIds.filter((id)
|
|
169
|
+
unitIds = remembered.unitIds.filter(function (id) { return index.has(id); });
|
|
142
170
|
bounds = remembered.bounds;
|
|
143
171
|
}
|
|
144
172
|
else if (index.has(objectId)) {
|
|
145
173
|
// A member of a group is replaced together with its group: the group is the thing that was converted.
|
|
146
|
-
|
|
174
|
+
var unitId = topLevelAncestorId(index, objectId);
|
|
147
175
|
unitIds = [unitId];
|
|
148
176
|
bounds = visualBoundsOfUnits(scene, unitIds);
|
|
149
|
-
|
|
177
|
+
var first = leafShapesOf(scene, unitIds)[0];
|
|
150
178
|
if (first)
|
|
151
179
|
opacity = first.opacity;
|
|
152
180
|
}
|
|
@@ -156,34 +184,36 @@ export function replaceObjectWithWidgetCard(engine, conversions, objectId, widge
|
|
|
156
184
|
if (unitIds.length === 0 || !bounds)
|
|
157
185
|
return null;
|
|
158
186
|
engine.endTextEdit();
|
|
159
|
-
|
|
160
|
-
|
|
187
|
+
var doomed = withDescendantIds(scene, unitIds);
|
|
188
|
+
var card = createWidgetObject({
|
|
161
189
|
id: engine.services.createId(CARD_ID_PREFIX),
|
|
162
|
-
widgetId,
|
|
190
|
+
widgetId: widgetId,
|
|
163
191
|
x: bounds.x,
|
|
164
192
|
y: bounds.y,
|
|
165
193
|
width: Math.max(1, bounds.width),
|
|
166
194
|
height: Math.max(1, bounds.height),
|
|
167
|
-
opacity,
|
|
195
|
+
opacity: opacity,
|
|
168
196
|
thumbnail: screenshot || null
|
|
169
197
|
});
|
|
170
|
-
|
|
198
|
+
var next = normalizeScene(__spreadArray(__spreadArray([], scene.filter(function (object) { return !doomed.has(object.id); }), true), [card], false));
|
|
171
199
|
engine.applyScene(next, 'push');
|
|
172
200
|
engine.select([card.id]);
|
|
173
201
|
return card.id;
|
|
174
202
|
}
|
|
175
203
|
/** Gives a card a new screenshot (a refresh of its preview). It is not an undo step, but the board is marked as changed. */
|
|
176
204
|
export function updateWidgetThumbnail(engine, widgetId, dataUrl) {
|
|
177
|
-
|
|
205
|
+
var card = findWidgetCard(engine, widgetId);
|
|
178
206
|
if (!card)
|
|
179
207
|
return false;
|
|
180
|
-
|
|
208
|
+
var next = engine.state.scene.map(function (object) {
|
|
209
|
+
return object.id === card.id ? __assign(__assign({}, card), { thumbnail: dataUrl || null, thumbnailRef: null }) : object;
|
|
210
|
+
});
|
|
181
211
|
engine.applyScene(next, 'replace');
|
|
182
212
|
return true;
|
|
183
213
|
}
|
|
184
214
|
/** Picks the card of a widget. False when the board has none. */
|
|
185
215
|
export function selectWidgetCard(engine, widgetId) {
|
|
186
|
-
|
|
216
|
+
var card = findWidgetCard(engine, widgetId);
|
|
187
217
|
if (!card)
|
|
188
218
|
return false;
|
|
189
219
|
engine.select([card.id]);
|
|
@@ -191,10 +221,10 @@ export function selectWidgetCard(engine, widgetId) {
|
|
|
191
221
|
}
|
|
192
222
|
/** The widget of the card that is the whole selection, or null. */
|
|
193
223
|
export function selectedWidgetId(engine) {
|
|
194
|
-
|
|
224
|
+
var selectedIds = engine.state.selectedIds;
|
|
195
225
|
if (selectedIds.length !== 1)
|
|
196
226
|
return null;
|
|
197
|
-
|
|
227
|
+
var object = engine.getObject(selectedIds[0]);
|
|
198
228
|
return object && object.type === 'widget' ? object.widgetId : null;
|
|
199
229
|
}
|
|
200
230
|
/**
|
|
@@ -204,13 +234,14 @@ export function selectedWidgetId(engine) {
|
|
|
204
234
|
export function onlyCardIsSelected(state) {
|
|
205
235
|
if (state.selectedIds.length !== 1)
|
|
206
236
|
return false;
|
|
207
|
-
|
|
208
|
-
return state.scene.some((object)
|
|
237
|
+
var selectedId = state.selectedIds[0];
|
|
238
|
+
return state.scene.some(function (object) { return object.id === selectedId && object.type === 'widget'; });
|
|
209
239
|
}
|
|
210
240
|
/** The ids of the widgets that have a card on the board. */
|
|
211
241
|
export function linkedWidgetIds(engine) {
|
|
212
|
-
|
|
213
|
-
for (
|
|
242
|
+
var ids = new Set();
|
|
243
|
+
for (var _i = 0, _a = cardsOf(engine.state.scene); _i < _a.length; _i++) {
|
|
244
|
+
var card = _a[_i];
|
|
214
245
|
if (card.widgetId)
|
|
215
246
|
ids.add(card.widgetId);
|
|
216
247
|
}
|
|
@@ -220,10 +251,10 @@ export function linkedWidgetIds(engine) {
|
|
|
220
251
|
export function keepOnlyWidgetCard(engine, widgetId) {
|
|
221
252
|
if (!widgetId)
|
|
222
253
|
return 0;
|
|
223
|
-
|
|
254
|
+
var extras = cardsOf(engine.state.scene).filter(function (card) { return card.widgetId && card.widgetId !== widgetId; });
|
|
224
255
|
if (extras.length === 0)
|
|
225
256
|
return 0;
|
|
226
|
-
engine.removeObjects(extras.map((card)
|
|
257
|
+
engine.removeObjects(extras.map(function (card) { return card.id; }));
|
|
227
258
|
engine.clearSelection();
|
|
228
259
|
return extras.length;
|
|
229
260
|
}
|
|
@@ -234,23 +265,24 @@ export function keepOnlyWidgetCard(engine, widgetId) {
|
|
|
234
265
|
export function removeSketchObjectsKeeping(engine, widgetId) {
|
|
235
266
|
if (!widgetId)
|
|
236
267
|
return 0;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
for (
|
|
268
|
+
var scene = engine.state.scene;
|
|
269
|
+
var index = engine.sceneIndex(scene);
|
|
270
|
+
var keep = new Set();
|
|
271
|
+
for (var _i = 0, _a = cardsOf(scene); _i < _a.length; _i++) {
|
|
272
|
+
var card = _a[_i];
|
|
241
273
|
if (card.widgetId !== widgetId)
|
|
242
274
|
continue;
|
|
243
|
-
|
|
275
|
+
var current = card;
|
|
244
276
|
while (current && !keep.has(current.id)) {
|
|
245
277
|
keep.add(current.id);
|
|
246
278
|
current = current.parentId ? index.get(current.parentId) : undefined;
|
|
247
279
|
}
|
|
248
280
|
}
|
|
249
|
-
|
|
281
|
+
var doomed = scene.filter(function (object) { return !keep.has(object.id) && object.type !== 'group'; }).map(function (object) { return object.id; });
|
|
250
282
|
if (doomed.length === 0)
|
|
251
283
|
return 0;
|
|
252
284
|
engine.endTextEdit();
|
|
253
|
-
|
|
285
|
+
var next = removeFromScene(scene, doomed);
|
|
254
286
|
engine.applyScene(next, 'push');
|
|
255
287
|
engine.clearSelection();
|
|
256
288
|
return doomed.length;
|
|
@@ -260,19 +292,20 @@ export function removeSketchObjectsKeeping(engine, widgetId) {
|
|
|
260
292
|
* keeps it. Not an undo step and not a change of the board. Returns how many cards changed.
|
|
261
293
|
*/
|
|
262
294
|
export function hydrateWidgetMetadata(engine, widgetsById) {
|
|
263
|
-
|
|
264
|
-
|
|
295
|
+
var updated = 0;
|
|
296
|
+
var next = engine.state.scene.map(function (object) {
|
|
297
|
+
var _a, _b;
|
|
265
298
|
if (object.type !== 'widget' || !object.widgetId)
|
|
266
299
|
return object;
|
|
267
|
-
|
|
300
|
+
var metadata = widgetsById.get(object.widgetId);
|
|
268
301
|
if (!metadata)
|
|
269
302
|
return object;
|
|
270
|
-
|
|
271
|
-
|
|
303
|
+
var preview = (_b = (_a = metadata.thumbnailUrl) !== null && _a !== void 0 ? _a : metadata.thumbnail_url) !== null && _b !== void 0 ? _b : null;
|
|
304
|
+
var card = object;
|
|
272
305
|
if (metadata.name && card.widgetName !== metadata.name)
|
|
273
|
-
card = {
|
|
306
|
+
card = __assign(__assign({}, card), { widgetName: metadata.name });
|
|
274
307
|
if (preview && !card.thumbnail && !card.thumbnailRef)
|
|
275
|
-
card = {
|
|
308
|
+
card = __assign(__assign({}, card), { thumbnail: preview });
|
|
276
309
|
if (card === object)
|
|
277
310
|
return object;
|
|
278
311
|
updated += 1;
|
|
@@ -287,12 +320,13 @@ export function hydrateWidgetMetadata(engine, widgetsById) {
|
|
|
287
320
|
* Returns how many cards changed their mark.
|
|
288
321
|
*/
|
|
289
322
|
export function markOrphanedWidgetCards(engine, validWidgetIds) {
|
|
290
|
-
|
|
291
|
-
for (
|
|
323
|
+
var changed = 0;
|
|
324
|
+
for (var _i = 0, _a = cardsOf(engine.state.scene); _i < _a.length; _i++) {
|
|
325
|
+
var card = _a[_i];
|
|
292
326
|
if (!card.widgetId)
|
|
293
327
|
continue;
|
|
294
|
-
|
|
295
|
-
if (engine.setWidgetRuntime(card.widgetId, { orphaned }))
|
|
328
|
+
var orphaned = !validWidgetIds.has(card.widgetId);
|
|
329
|
+
if (engine.setWidgetRuntime(card.widgetId, { orphaned: orphaned }))
|
|
296
330
|
changed += 1;
|
|
297
331
|
}
|
|
298
332
|
return changed;
|
|
@@ -301,15 +335,15 @@ export function markOrphanedWidgetCards(engine, validWidgetIds) {
|
|
|
301
335
|
export function setPrimaryWidgetCard(engine, widgetId) {
|
|
302
336
|
if (!widgetId)
|
|
303
337
|
return false;
|
|
304
|
-
|
|
305
|
-
|
|
338
|
+
var changed = false;
|
|
339
|
+
var next = engine.state.scene.map(function (object) {
|
|
306
340
|
if (object.type !== 'widget')
|
|
307
341
|
return object;
|
|
308
|
-
|
|
342
|
+
var primary = object.widgetId === widgetId;
|
|
309
343
|
if (object.isPrimary === primary)
|
|
310
344
|
return object;
|
|
311
345
|
changed = true;
|
|
312
|
-
return {
|
|
346
|
+
return __assign(__assign({}, object), { isPrimary: primary });
|
|
313
347
|
});
|
|
314
348
|
if (changed)
|
|
315
349
|
engine.applyScene(next, 'replace');
|
|
@@ -317,22 +351,23 @@ export function setPrimaryWidgetCard(engine, widgetId) {
|
|
|
317
351
|
}
|
|
318
352
|
/** The widget the board is about, or null. */
|
|
319
353
|
export function primaryWidgetId(engine) {
|
|
320
|
-
|
|
354
|
+
var _a, _b;
|
|
355
|
+
return (_b = (_a = cardsOf(engine.state.scene).find(function (card) { return card.isPrimary; })) === null || _a === void 0 ? void 0 : _a.widgetId) !== null && _b !== void 0 ? _b : null;
|
|
321
356
|
}
|
|
322
357
|
/**
|
|
323
358
|
* Moves the card of a widget by a distance in screen pixels (the host's own bar drags it). Nothing is recorded
|
|
324
359
|
* until `commitWidgetCardMove`.
|
|
325
360
|
*/
|
|
326
361
|
export function moveWidgetCardByScreen(engine, widgetId, deltaScreenX, deltaScreenY) {
|
|
327
|
-
|
|
362
|
+
var card = findWidgetCard(engine, widgetId);
|
|
328
363
|
if (!card)
|
|
329
364
|
return false;
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
365
|
+
var zoom = engine.state.viewport.zoom || 1;
|
|
366
|
+
var deltaX = deltaScreenX / zoom;
|
|
367
|
+
var deltaY = deltaScreenY / zoom;
|
|
333
368
|
if (!Number.isFinite(deltaX) || !Number.isFinite(deltaY))
|
|
334
369
|
return false;
|
|
335
|
-
engine.applyScene(engine.state.scene.map((object)
|
|
370
|
+
engine.applyScene(engine.state.scene.map(function (object) { return (object.id === card.id ? __assign(__assign({}, card), { x: card.x + deltaX, y: card.y + deltaY }) : object); }), 'transient');
|
|
336
371
|
return true;
|
|
337
372
|
}
|
|
338
373
|
/** The host's bar let go of a card: the move is one undo step. */
|
|
@@ -341,5 +376,6 @@ export function commitWidgetCardMove(engine) {
|
|
|
341
376
|
}
|
|
342
377
|
/** The bounds of what a conversion of the selection covers, or null when nothing is selected. */
|
|
343
378
|
export function selectionConversionBounds(engine) {
|
|
344
|
-
|
|
379
|
+
var _a;
|
|
380
|
+
return (_a = visualBoundsOfUnits(engine.state.scene, engine.state.selectedIds)) !== null && _a !== void 0 ? _a : boundsOfObjects(engine.state.scene, engine.state.selectedIds);
|
|
345
381
|
}
|
package/dist/fonts/interFont.js
CHANGED
|
@@ -6,49 +6,102 @@
|
|
|
6
6
|
* canvas registers them as the family `Inter`. On its own the canvas asks nobody for a font file: on a page that is not
|
|
7
7
|
* ours (a partner's) a request for a path of its origin is a 404 in its logs, or a violation of its `font-src`.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
19
|
+
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);
|
|
20
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
21
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
22
|
+
function step(op) {
|
|
23
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
24
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
25
|
+
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;
|
|
26
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
27
|
+
switch (op[0]) {
|
|
28
|
+
case 0: case 1: t = op; break;
|
|
29
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
30
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
31
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
32
|
+
default:
|
|
33
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
34
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
35
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
36
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
37
|
+
if (t[2]) _.ops.pop();
|
|
38
|
+
_.trys.pop(); continue;
|
|
39
|
+
}
|
|
40
|
+
op = body.call(thisArg, _);
|
|
41
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
42
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export var INTER_FONT_FAMILY = 'Inter';
|
|
10
46
|
/** One load per list of addresses: the page's fonts are global, so asking twice for the same list changes nothing. */
|
|
11
|
-
|
|
47
|
+
var interLoads = new Map();
|
|
12
48
|
/** The `src` of a font face for one address the host gave. Quotes and backslashes are escaped, so an address cannot end the string. */
|
|
13
49
|
function toFontFaceSource(address) {
|
|
14
|
-
return
|
|
50
|
+
return "url(\"".concat(address.replace(/["\\]/g, '\\$&'), "\") format('woff2')");
|
|
15
51
|
}
|
|
16
52
|
/**
|
|
17
53
|
* Registers the Inter files the host gave (none by default) and waits for Inter to be usable, the host's or the page's own.
|
|
18
54
|
* It never rejects: when a file cannot be loaded the page's fonts are used and one warning says so.
|
|
19
55
|
*/
|
|
20
|
-
export function ensureInterFontLoaded(sources
|
|
56
|
+
export function ensureInterFontLoaded(sources) {
|
|
57
|
+
var _this = this;
|
|
58
|
+
if (sources === void 0) { sources = []; }
|
|
21
59
|
if (typeof document === 'undefined')
|
|
22
60
|
return Promise.resolve();
|
|
23
|
-
|
|
24
|
-
|
|
61
|
+
var loadKey = sources.join('\n');
|
|
62
|
+
var existingLoad = interLoads.get(loadKey);
|
|
25
63
|
if (existingLoad)
|
|
26
64
|
return existingLoad;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
65
|
+
var load = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
66
|
+
var face, loaded, error_1, error_2;
|
|
67
|
+
var _a, _b;
|
|
68
|
+
return __generator(this, function (_c) {
|
|
69
|
+
switch (_c.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (!(sources.length > 0 && typeof FontFace !== 'undefined' && ((_a = document.fonts) === null || _a === void 0 ? void 0 : _a.add))) return [3 /*break*/, 4];
|
|
72
|
+
_c.label = 1;
|
|
73
|
+
case 1:
|
|
74
|
+
_c.trys.push([1, 3, , 4]);
|
|
75
|
+
face = new FontFace(INTER_FONT_FAMILY, sources.map(toFontFaceSource).join(', '), {
|
|
76
|
+
weight: '100 900',
|
|
77
|
+
style: 'normal',
|
|
78
|
+
display: 'swap'
|
|
79
|
+
});
|
|
80
|
+
return [4 /*yield*/, face.load()];
|
|
81
|
+
case 2:
|
|
82
|
+
loaded = _c.sent();
|
|
83
|
+
document.fonts.add(loaded);
|
|
84
|
+
return [3 /*break*/, 4];
|
|
85
|
+
case 3:
|
|
86
|
+
error_1 = _c.sent();
|
|
87
|
+
console.warn('Canvas: the Inter files the page gave could not be loaded, the fonts of the page are used', error_1);
|
|
88
|
+
return [3 /*break*/, 4];
|
|
89
|
+
case 4:
|
|
90
|
+
_c.trys.push([4, 7, , 8]);
|
|
91
|
+
if (!((_b = document.fonts) === null || _b === void 0 ? void 0 : _b.load)) return [3 /*break*/, 6];
|
|
92
|
+
return [4 /*yield*/, document.fonts.load('16px Inter')];
|
|
93
|
+
case 5:
|
|
94
|
+
_c.sent();
|
|
95
|
+
_c.label = 6;
|
|
96
|
+
case 6: return [3 /*break*/, 8];
|
|
97
|
+
case 7:
|
|
98
|
+
error_2 = _c.sent();
|
|
99
|
+
console.warn('Canvas: Inter could not be preloaded, fallback fonts will be used', error_2);
|
|
100
|
+
return [3 /*break*/, 8];
|
|
101
|
+
case 8: return [2 /*return*/];
|
|
46
102
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
console.warn('Canvas: Inter could not be preloaded, fallback fonts will be used', error);
|
|
50
|
-
}
|
|
51
|
-
})();
|
|
103
|
+
});
|
|
104
|
+
}); })();
|
|
52
105
|
interLoads.set(loadKey, load);
|
|
53
106
|
return load;
|
|
54
107
|
}
|
|
@@ -9,4 +9,10 @@ export interface WorkspaceCanvasFont {
|
|
|
9
9
|
format?: string;
|
|
10
10
|
}
|
|
11
11
|
export declare function listWorkspaceFontFamilies(fonts: readonly WorkspaceCanvasFont[]): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Registers the brand-kit fonts with the browser, so a text set in one is drawn in it. The page loads its brand kit after the
|
|
14
|
+
* canvas has opened, so the canvas is given a list again and again (empty at first, with fonts later): every list is registered,
|
|
15
|
+
* each after the one before it, and a font that is registered already is not loaded a second time. (This used to register only the
|
|
16
|
+
* first list it was given, so the fonts that arrived later were in the font picker but never in the browser.)
|
|
17
|
+
*/
|
|
12
18
|
export declare function registerWorkspaceFonts(fonts: readonly WorkspaceCanvasFont[]): Promise<void>;
|