@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
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
-
if (ar || !(i in from)) {
|
|
4
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
-
ar[i] = from[i];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
-
};
|
|
10
1
|
import { boundsOfObjects, findObject, indexScene, shapeBounds } from '../engine/core/scene.js';
|
|
11
2
|
import { isBoxedObject } from '../engine/core/types.js';
|
|
12
|
-
|
|
13
|
-
export
|
|
3
|
+
const DEFAULT_BOUNDS = { width: 1200, height: 800 };
|
|
4
|
+
export const SCENE_SUMMARY_MAX_ELEMENTS = 48;
|
|
14
5
|
/** The longest label a summary carries (the assistant request schema accepts 256, and the model needs far fewer). */
|
|
15
|
-
|
|
6
|
+
const SCENE_LABEL_MAX_CHARS = 80;
|
|
16
7
|
/** A label cut to the length a summary carries, so a long text never makes a request the gateway refuses. */
|
|
17
8
|
function shortenLabel(text) {
|
|
18
|
-
return text.length > SCENE_LABEL_MAX_CHARS ?
|
|
9
|
+
return text.length > SCENE_LABEL_MAX_CHARS ? `${text.slice(0, SCENE_LABEL_MAX_CHARS - 3)}...` : text;
|
|
19
10
|
}
|
|
20
11
|
export function labelOfObject(object) {
|
|
21
|
-
var _a, _b;
|
|
22
12
|
if (object.type === 'text') {
|
|
23
13
|
return shortenLabel(object.text.trim());
|
|
24
14
|
}
|
|
25
15
|
if (object.type === 'widget')
|
|
26
|
-
return
|
|
16
|
+
return object.widgetName ?? 'widget';
|
|
27
17
|
if (object.type === 'group')
|
|
28
18
|
return 'group';
|
|
29
19
|
if (object.type === 'path' && object.arrow)
|
|
@@ -35,12 +25,11 @@ export function labelOfObject(object) {
|
|
|
35
25
|
if (object.type === 'ellipse')
|
|
36
26
|
return 'ellipse';
|
|
37
27
|
if (object.type === 'image')
|
|
38
|
-
return
|
|
28
|
+
return object.fileName ?? 'image';
|
|
39
29
|
return object.type;
|
|
40
30
|
}
|
|
41
31
|
function groupLabelFromMembers(groupId, scene) {
|
|
42
|
-
for (
|
|
43
|
-
var object = scene_1[_i];
|
|
32
|
+
for (const object of scene) {
|
|
44
33
|
if (object.parentId === groupId && object.type === 'text') {
|
|
45
34
|
// Cut like the label of a loose text: a component's first text can be a whole paragraph.
|
|
46
35
|
return shortenLabel(object.text.trim()) || 'group';
|
|
@@ -67,31 +56,30 @@ function elementPriority(element) {
|
|
|
67
56
|
return 3;
|
|
68
57
|
}
|
|
69
58
|
function compareElements(a, b) {
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
const pa = elementPriority(a);
|
|
60
|
+
const pb = elementPriority(b);
|
|
72
61
|
if (pa !== pb)
|
|
73
62
|
return pa - pb;
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const areaA = a.bbox.width * a.bbox.height;
|
|
64
|
+
const areaB = b.bbox.width * b.bbox.height;
|
|
76
65
|
if (areaA !== areaB)
|
|
77
66
|
return areaB - areaA;
|
|
78
67
|
return a.zIndex - b.zIndex;
|
|
79
68
|
}
|
|
80
|
-
export function summarizeScene(scene, bounds) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
scene.forEach(function (object, zIndex) {
|
|
69
|
+
export function summarizeScene(scene, bounds = DEFAULT_BOUNDS) {
|
|
70
|
+
const elements = [];
|
|
71
|
+
scene.forEach((object, zIndex) => {
|
|
84
72
|
if (object.type === 'group') {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!
|
|
73
|
+
const memberIds = scene.filter((member) => member.parentId === object.id).map((member) => member.id);
|
|
74
|
+
const bbox = boundsOfObjects(scene, memberIds);
|
|
75
|
+
if (!bbox)
|
|
88
76
|
return;
|
|
89
77
|
elements.push({
|
|
90
78
|
id: object.id,
|
|
91
79
|
kind: 'group',
|
|
92
80
|
label: groupLabelFromMembers(object.id, scene),
|
|
93
|
-
bbox
|
|
94
|
-
zIndex
|
|
81
|
+
bbox,
|
|
82
|
+
zIndex,
|
|
95
83
|
parentId: object.parentId
|
|
96
84
|
});
|
|
97
85
|
return;
|
|
@@ -100,69 +88,67 @@ export function summarizeScene(scene, bounds) {
|
|
|
100
88
|
return;
|
|
101
89
|
if (!isBoxedObject(object))
|
|
102
90
|
return;
|
|
103
|
-
|
|
91
|
+
const bbox = shapeBounds(object);
|
|
104
92
|
elements.push({
|
|
105
93
|
id: object.id,
|
|
106
94
|
kind: kindOfObject(object),
|
|
107
95
|
label: labelOfObject(object),
|
|
108
|
-
bbox
|
|
109
|
-
zIndex
|
|
96
|
+
bbox,
|
|
97
|
+
zIndex,
|
|
110
98
|
parentId: object.parentId
|
|
111
99
|
});
|
|
112
100
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
const sorted = [...elements].sort(compareElements);
|
|
102
|
+
const totalCount = sorted.length;
|
|
103
|
+
const truncated = totalCount > SCENE_SUMMARY_MAX_ELEMENTS;
|
|
104
|
+
const limited = truncated ? sorted.slice(0, SCENE_SUMMARY_MAX_ELEMENTS) : sorted;
|
|
117
105
|
return {
|
|
118
|
-
bounds
|
|
106
|
+
bounds,
|
|
119
107
|
elements: limited,
|
|
120
|
-
totalCount
|
|
121
|
-
truncated
|
|
122
|
-
truncationNote: truncated ?
|
|
108
|
+
totalCount,
|
|
109
|
+
truncated,
|
|
110
|
+
truncationNote: truncated ? `Showing ${SCENE_SUMMARY_MAX_ELEMENTS} of ${totalCount} top-level elements.` : undefined
|
|
123
111
|
};
|
|
124
112
|
}
|
|
125
113
|
export function findByLabel(scene, needle) {
|
|
126
|
-
|
|
127
|
-
for (
|
|
128
|
-
var object = scene_2[_i];
|
|
114
|
+
const lower = needle.toLowerCase();
|
|
115
|
+
for (const object of scene) {
|
|
129
116
|
if (object.type === 'group') {
|
|
130
|
-
|
|
117
|
+
const label = groupLabelFromMembers(object.id, scene).toLowerCase();
|
|
131
118
|
if (label.includes(lower))
|
|
132
119
|
return object.id;
|
|
133
120
|
}
|
|
134
121
|
if (object.type === 'text') {
|
|
135
|
-
|
|
122
|
+
const label = object.text.toLowerCase();
|
|
136
123
|
if (label.includes(lower))
|
|
137
124
|
return object.id;
|
|
138
125
|
}
|
|
139
126
|
}
|
|
140
|
-
for (
|
|
141
|
-
|
|
142
|
-
var label = labelOfObject(object).toLowerCase();
|
|
127
|
+
for (const object of scene) {
|
|
128
|
+
const label = labelOfObject(object).toLowerCase();
|
|
143
129
|
if (label.includes(lower))
|
|
144
130
|
return object.id;
|
|
145
131
|
}
|
|
146
132
|
return null;
|
|
147
133
|
}
|
|
148
134
|
export function centerOf(id, scene) {
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
if (!
|
|
135
|
+
const object = findObject(scene, id);
|
|
136
|
+
if (object?.type === 'group') {
|
|
137
|
+
const bbox = boundsOfObjects(scene, [id]);
|
|
138
|
+
if (!bbox)
|
|
153
139
|
return null;
|
|
154
|
-
return { x:
|
|
140
|
+
return { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 };
|
|
155
141
|
}
|
|
156
142
|
if (!object || !isBoxedObject(object))
|
|
157
143
|
return null;
|
|
158
|
-
|
|
144
|
+
const bbox = shapeBounds(object);
|
|
159
145
|
return { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 };
|
|
160
146
|
}
|
|
161
147
|
export function sceneIndexMap(scene) {
|
|
162
148
|
return indexScene(scene);
|
|
163
149
|
}
|
|
164
150
|
export function bboxIntersects(a, b) {
|
|
165
|
-
|
|
151
|
+
const pad = 2;
|
|
166
152
|
return (a.x + a.width > b.x + pad &&
|
|
167
153
|
b.x + b.width > a.x + pad &&
|
|
168
154
|
a.y + a.height > b.y + pad &&
|
|
@@ -4,26 +4,18 @@
|
|
|
4
4
|
* every script. It is written without a lookbehind (which older Safari does not have), so it can never stop the module
|
|
5
5
|
* from loading.
|
|
6
6
|
*/
|
|
7
|
-
function standalone() {
|
|
8
|
-
|
|
9
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
10
|
-
alternatives[_i] = arguments[_i];
|
|
11
|
-
}
|
|
12
|
-
return new RegExp("(?:^|[^\\p{L}\\p{N}_])(?:".concat(alternatives.join('|'), ")(?![\\p{L}\\p{N}_])"), 'iu');
|
|
7
|
+
function standalone(...alternatives) {
|
|
8
|
+
return new RegExp(`(?:^|[^\\p{L}\\p{N}_])(?:${alternatives.join('|')})(?![\\p{L}\\p{N}_])`, 'iu');
|
|
13
9
|
}
|
|
14
10
|
/** A pattern for a phrase of a writing system that puts no spaces between words (Chinese, Japanese): found anywhere. */
|
|
15
|
-
function anywhere() {
|
|
16
|
-
|
|
17
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18
|
-
alternatives[_i] = arguments[_i];
|
|
19
|
-
}
|
|
20
|
-
return new RegExp("(?:".concat(alternatives.join('|'), ")"), 'iu');
|
|
11
|
+
function anywhere(...alternatives) {
|
|
12
|
+
return new RegExp(`(?:${alternatives.join('|')})`, 'iu');
|
|
21
13
|
}
|
|
22
14
|
/**
|
|
23
15
|
* Words that say the author wants something drawn on the canvas. Only words that mean drawing: a request to create
|
|
24
16
|
* something ("make a quiz", "I need a video player") is a widget, and goes to the code generator.
|
|
25
17
|
*/
|
|
26
|
-
|
|
18
|
+
const SKETCH_PATTERNS = [
|
|
27
19
|
/\bdraw\b/i,
|
|
28
20
|
/\bsketch\b/i,
|
|
29
21
|
/\bwireframe\b/i,
|
|
@@ -58,7 +50,7 @@ var SKETCH_PATTERNS = [
|
|
|
58
50
|
* Words that say the author wants code, a build or a publish. They win over a drawing word: "draw it, then publish it"
|
|
59
51
|
* is a request for the widget.
|
|
60
52
|
*/
|
|
61
|
-
|
|
53
|
+
const CODEGEN_PATTERNS = [
|
|
62
54
|
/\bbuild\b/i,
|
|
63
55
|
/\bgenerate\b/i,
|
|
64
56
|
/\bcode\b/i,
|
|
@@ -84,7 +76,7 @@ var CODEGEN_PATTERNS = [
|
|
|
84
76
|
standalone('zbuduj', 'wygeneruj', 'kod', 'opublikuj', 'zaimplementuj'),
|
|
85
77
|
standalone('bouw', 'genereer', 'publiceer', 'implementeer')
|
|
86
78
|
];
|
|
87
|
-
export
|
|
79
|
+
export const SKETCH_INTENT_COUNTER_EXAMPLES = [
|
|
88
80
|
'build me a countdown widget',
|
|
89
81
|
'make the button blue in the widget',
|
|
90
82
|
'generate the react code for this',
|
|
@@ -96,7 +88,7 @@ export var SKETCH_INTENT_COUNTER_EXAMPLES = [
|
|
|
96
88
|
* Free-text requests that draw, in the languages the router knows. Every one must route to the sketch assistant
|
|
97
89
|
* (the creator's tests and the gateway's mirror hold the same list).
|
|
98
90
|
*/
|
|
99
|
-
export
|
|
91
|
+
export const SKETCH_FREE_TEXT_EXAMPLES = [
|
|
100
92
|
'Sketch a pricing page with three plans and a call to action under each',
|
|
101
93
|
'wireframe a dashboard with a sidebar and four stat cards',
|
|
102
94
|
'can you draw three circles in a row and connect them with arrows',
|
|
@@ -128,7 +120,7 @@ export var SKETCH_FREE_TEXT_EXAMPLES = [
|
|
|
128
120
|
* Requests that are not for a drawing, with the verdict each gets. Creating something ("make", "create", "I need") is a
|
|
129
121
|
* widget, so most of them are `unknown` and go to the code generator by default; the ones that name code are `generate`.
|
|
130
122
|
*/
|
|
131
|
-
export
|
|
123
|
+
export const SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
|
|
132
124
|
['a video player with a playlist', 'unknown'],
|
|
133
125
|
['create a countdown timer with a start button', 'unknown'],
|
|
134
126
|
['I want a quiz about world capitals', 'unknown'],
|
|
@@ -149,16 +141,16 @@ export var SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
|
|
|
149
141
|
* Lightweight sketch-vs-codegen classifier for the creator chat (gateway mirrors this in tests).
|
|
150
142
|
*/
|
|
151
143
|
export function classifySketchIntent(message) {
|
|
152
|
-
|
|
144
|
+
const text = message.trim();
|
|
153
145
|
if (!text)
|
|
154
146
|
return 'unknown';
|
|
155
|
-
if (CODEGEN_PATTERNS.some(
|
|
147
|
+
if (CODEGEN_PATTERNS.some((pattern) => pattern.test(text)))
|
|
156
148
|
return 'generate';
|
|
157
|
-
if (SKETCH_PATTERNS.some(
|
|
149
|
+
if (SKETCH_PATTERNS.some((pattern) => pattern.test(text)))
|
|
158
150
|
return 'sketch';
|
|
159
151
|
return 'unknown';
|
|
160
152
|
}
|
|
161
|
-
export
|
|
153
|
+
export const SKETCH_ACCEPTANCE_PROMPTS = [
|
|
162
154
|
'draw a video player for me',
|
|
163
155
|
'move the navigation outside the video thumbnail',
|
|
164
156
|
'delete all sketches',
|
|
@@ -7,27 +7,25 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { isFontFamilyName } from '../engine/codec/canvasDocument.js';
|
|
9
9
|
/** A colour the assistant may pass: a hex colour (the brand kit's colours are hex), or `transparent` where a fill may be. */
|
|
10
|
-
|
|
10
|
+
const HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
11
11
|
/** The colour in an argument: a hex colour (and `transparent` when `allowTransparent`). Absent when the model passed nothing. */
|
|
12
|
-
export function readColorArgument(value, name, allowTransparent) {
|
|
13
|
-
if (allowTransparent === void 0) { allowTransparent = false; }
|
|
12
|
+
export function readColorArgument(value, name, allowTransparent = false) {
|
|
14
13
|
if (value === undefined || value === null || value === '')
|
|
15
14
|
return { ok: true, value: undefined };
|
|
16
|
-
|
|
15
|
+
const text = typeof value === 'string' ? value.trim() : '';
|
|
17
16
|
if (HEX_COLOR_PATTERN.test(text))
|
|
18
17
|
return { ok: true, value: text.toLowerCase() };
|
|
19
18
|
if (allowTransparent && text.toLowerCase() === 'transparent')
|
|
20
19
|
return { ok: true, value: 'transparent' };
|
|
21
|
-
return { ok: false, error:
|
|
20
|
+
return { ok: false, error: `${name} must be a hex colour such as #1a2b3c${allowTransparent ? ' or "transparent"' : ''}, not ${JSON.stringify(value)}.` };
|
|
22
21
|
}
|
|
23
22
|
/** The first family of a CSS font list, without quotes, lower-cased: how two spellings of one family are compared. */
|
|
24
23
|
function familyKey(family) {
|
|
25
|
-
|
|
26
|
-
var first = (_a = family.split(',')[0]) !== null && _a !== void 0 ? _a : '';
|
|
24
|
+
const first = family.split(',')[0] ?? '';
|
|
27
25
|
return first.trim().replace(/^["']|["']$/g, '').toLowerCase();
|
|
28
26
|
}
|
|
29
27
|
/** How many families a refusal lists (the model needs a few to choose from, not a hundred). */
|
|
30
|
-
|
|
28
|
+
const FONT_LIST_IN_REFUSAL = 24;
|
|
31
29
|
/**
|
|
32
30
|
* The font family in an argument, as the canvas knows it. With a list of families (the built-in ones and the brand kit's) the name
|
|
33
31
|
* must be one of them (any spelling of the case); the answer is the family as the list writes it. Without a list any well-formed
|
|
@@ -36,39 +34,39 @@ var FONT_LIST_IN_REFUSAL = 24;
|
|
|
36
34
|
export function readFontFamilyArgument(value, known) {
|
|
37
35
|
if (value === undefined || value === null || value === '')
|
|
38
36
|
return { ok: true, value: undefined };
|
|
39
|
-
|
|
37
|
+
const text = typeof value === 'string' ? value.trim() : '';
|
|
40
38
|
if (text === '' || !isFontFamilyName(text))
|
|
41
|
-
return { ok: false, error:
|
|
39
|
+
return { ok: false, error: `fontFamily must be a font family name, not ${JSON.stringify(value)}.` };
|
|
42
40
|
if (!known || known.length === 0)
|
|
43
41
|
return { ok: true, value: text };
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const wanted = familyKey(text);
|
|
43
|
+
const match = known.find((family) => familyKey(family) === wanted);
|
|
46
44
|
if (match)
|
|
47
45
|
return { ok: true, value: match };
|
|
48
|
-
|
|
49
|
-
return { ok: false, error:
|
|
46
|
+
const listed = known.slice(0, FONT_LIST_IN_REFUSAL).join(', ');
|
|
47
|
+
return { ok: false, error: `The font "${text}" is not on this canvas. Use one of: ${listed}${known.length > FONT_LIST_IN_REFUSAL ? ', …' : ''}.` };
|
|
50
48
|
}
|
|
51
49
|
/** A number inside a range, or absent. Anything else is refused. */
|
|
52
50
|
export function readNumberArgument(value, name, minimum, maximum) {
|
|
53
51
|
if (value === undefined || value === null || value === '')
|
|
54
52
|
return { ok: true, value: undefined };
|
|
55
|
-
|
|
53
|
+
const number = typeof value === 'number' ? value : Number(value);
|
|
56
54
|
if (!Number.isFinite(number) || number < minimum || number > maximum) {
|
|
57
|
-
return { ok: false, error:
|
|
55
|
+
return { ok: false, error: `${name} must be a number from ${minimum} to ${maximum}, not ${JSON.stringify(value)}.` };
|
|
58
56
|
}
|
|
59
57
|
return { ok: true, value: number };
|
|
60
58
|
}
|
|
61
59
|
/** The side a picture is given when the assistant does not say how big (an icon is a small thing). */
|
|
62
|
-
export
|
|
60
|
+
export const ASSET_DEFAULT_SIDE = 96;
|
|
63
61
|
/**
|
|
64
62
|
* The size a placed picture gets: both sides as asked; one side as asked and the other from the picture's proportions; or, with no
|
|
65
63
|
* size asked, the longer side is `ASSET_DEFAULT_SIDE`. The proportions are the picture's own when it says its size, a square when not.
|
|
66
64
|
*/
|
|
67
65
|
export function assetSizeFor(asset, width, height) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const known = typeof asset.width === 'number' && typeof asset.height === 'number' && asset.width > 0 && asset.height > 0;
|
|
67
|
+
const aspect = known ? asset.width / asset.height : 1;
|
|
68
|
+
let finalWidth;
|
|
69
|
+
let finalHeight;
|
|
72
70
|
if (width !== undefined && height !== undefined) {
|
|
73
71
|
finalWidth = width;
|
|
74
72
|
finalHeight = height;
|
package/dist/tools/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/canvas",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.46",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"package": "NODE_ENV=production svelte-package",
|
|
60
60
|
"publish-to-npm": "node ../dev-tools/bin/publish-package.mjs",
|
|
61
61
|
"package:watch": "NODE_ENV=development svelte-package --watch",
|
|
62
|
-
"test": "node --test \"scripts/*.test.ts\" \"tests/*.test.mjs\" \"tests/engine/*.test.mjs\" \"tests/host/*.test.mjs\" \"tests/view/*.test.mjs\" \"tests/ui/*.test.mjs\" \"tests/tools/*.test.mjs\"",
|
|
62
|
+
"test": "node --test \"scripts/*.test.ts\" \"tests/*.test.mjs\" \"tests/engine/*.test.mjs\" \"tests/host/*.test.mjs\" \"tests/settings/*.test.mjs\" \"tests/view/*.test.mjs\" \"tests/ui/*.test.mjs\" \"tests/tools/*.test.mjs\"",
|
|
63
63
|
"preview": "vite preview",
|
|
64
64
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
65
65
|
"check:peers": "check-design-system-peers ..",
|