@widgetic/canvas 0.5.40 → 0.5.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/canvas/DomCanvas.svelte +4 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +8 -0
- package/dist/canvas/autosaveScheduler.js +89 -37
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +19 -7
- package/dist/canvas/chromeLayout.js +18 -17
- package/dist/canvas/eventScope.js +14 -10
- package/dist/canvas/host/CanvasHost.d.ts +6 -0
- package/dist/canvas/host/CanvasHost.js +1556 -1267
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +25 -4
- package/dist/canvas/host/browserServices.js +116 -65
- package/dist/canvas/host/conversion.js +170 -82
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/pageEvents.js +4 -4
- package/dist/canvas/host/screenRects.js +31 -28
- package/dist/canvas/host/strokeSnap.js +143 -88
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +7 -6
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +25 -13
- package/dist/canvas/shapes/ShapeLibrary.js +148 -138
- package/dist/canvas/shapes/shapeImageStore.js +3 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/CanvasHint.svelte +16 -3
- package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
- package/dist/canvas/ui/CanvasToolbar.svelte +7 -7
- package/dist/canvas/ui/ToolButton.svelte +11 -3
- package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
- package/dist/canvas/ui/colorModel.js +32 -21
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +18 -18
- package/dist/canvas/ui/floatingLayer.js +6 -5
- package/dist/canvas/ui/keyHints.js +11 -9
- package/dist/canvas/ui/popoverSide.js +3 -2
- package/dist/canvas/ui/selectionTraits.js +40 -34
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +1 -1
- package/dist/canvas/ui/sizeLabelVisibility.js +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +33 -14
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +14 -4
- package/dist/canvas/view/geometry.js +103 -77
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +4 -1
- package/dist/engine/EngineCore.js +801 -695
- package/dist/engine/codec/canvasDocument.js +173 -173
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +38 -26
- package/dist/engine/core/arrow.d.ts +10 -3
- package/dist/engine/core/arrow.js +96 -75
- package/dist/engine/core/arrowBinding.d.ts +69 -0
- package/dist/engine/core/arrowBinding.js +344 -0
- package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
- package/dist/engine/core/arrowBindingRecords.js +141 -0
- package/dist/engine/core/brush.js +94 -67
- package/dist/engine/core/defaults.js +51 -90
- package/dist/engine/core/freehand.js +163 -147
- package/dist/engine/core/geometry.js +54 -47
- package/dist/engine/core/history.js +50 -33
- package/dist/engine/core/hitTest.d.ts +3 -0
- package/dist/engine/core/hitTest.js +83 -69
- package/dist/engine/core/matrix.js +20 -18
- package/dist/engine/core/pathData.js +210 -183
- package/dist/engine/core/rotationReset.js +6 -5
- package/dist/engine/core/scene.d.ts +3 -0
- package/dist/engine/core/scene.js +192 -129
- package/dist/engine/core/scribble.js +84 -59
- package/dist/engine/core/shapePaths.js +15 -12
- package/dist/engine/core/shapeTools.js +63 -72
- package/dist/engine/core/snapping.js +117 -65
- package/dist/engine/core/style.js +64 -31
- package/dist/engine/core/transform.js +94 -83
- package/dist/engine/core/types.d.ts +29 -0
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +36 -23
- package/dist/engine/input/PointerController.js +476 -447
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +12 -1
- package/dist/engine/input/gestures.js +342 -251
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.d.ts +9 -1
- package/dist/engine/input/keyboard.js +46 -27
- package/dist/engine/input/selectionHandles.js +50 -45
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +158 -86
- package/dist/engine/state.d.ts +6 -1
- package/dist/engine/state.js +17 -5
- package/dist/engine/text/layoutText.js +62 -43
- package/dist/engine/text/textMetrics.js +10 -8
- package/dist/engine/widgets.js +137 -101
- package/dist/fonts/interFont.js +68 -17
- package/dist/fonts/workspaceFonts.js +90 -32
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.d.ts +12 -0
- package/dist/i18n/shortcuts.js +32 -18
- package/dist/settings/workspaceToolSettings.js +48 -32
- package/dist/tools/components/catalog.d.ts +11 -0
- package/dist/tools/components/catalog.js +270 -0
- package/dist/tools/components/grouping.d.ts +9 -0
- package/dist/tools/components/grouping.js +33 -0
- package/dist/tools/definitions.d.ts +19 -0
- package/dist/tools/definitions.js +147 -0
- package/dist/tools/executors.d.ts +7 -0
- package/dist/tools/executors.js +324 -0
- package/dist/tools/hostAdapter.d.ts +14 -0
- package/dist/tools/hostAdapter.js +40 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/sceneSummary.d.ts +24 -0
- package/dist/tools/sceneSummary.js +170 -0
- package/dist/tools/sketchIntent.d.ts +17 -0
- package/dist/tools/sketchIntent.js +166 -0
- package/dist/tools/types.d.ts +54 -0
- package/dist/tools/types.js +11 -0
- package/package.json +7 -2
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pattern for words that must stand alone: not the end of a longer word, not the start of one. `\b` knows only the
|
|
3
|
+
* letters of ASCII, so it would never see the end of "desenează" or "Skizze" in another script; this looks at letters of
|
|
4
|
+
* every script. It is written without a lookbehind (which older Safari does not have), so it can never stop the module
|
|
5
|
+
* from loading.
|
|
6
|
+
*/
|
|
7
|
+
function standalone() {
|
|
8
|
+
var alternatives = [];
|
|
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');
|
|
13
|
+
}
|
|
14
|
+
/** A pattern for a phrase of a writing system that puts no spaces between words (Chinese, Japanese): found anywhere. */
|
|
15
|
+
function anywhere() {
|
|
16
|
+
var alternatives = [];
|
|
17
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18
|
+
alternatives[_i] = arguments[_i];
|
|
19
|
+
}
|
|
20
|
+
return new RegExp("(?:".concat(alternatives.join('|'), ")"), 'iu');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Words that say the author wants something drawn on the canvas. Only words that mean drawing: a request to create
|
|
24
|
+
* something ("make a quiz", "I need a video player") is a widget, and goes to the code generator.
|
|
25
|
+
*/
|
|
26
|
+
var SKETCH_PATTERNS = [
|
|
27
|
+
/\bdraw\b/i,
|
|
28
|
+
/\bsketch\b/i,
|
|
29
|
+
/\bwireframe\b/i,
|
|
30
|
+
/\bmove the\b/i,
|
|
31
|
+
/\bdelete all sketches\b/i,
|
|
32
|
+
/\bname every component\b/i,
|
|
33
|
+
/\barrow to it\b/i,
|
|
34
|
+
/\biterate on the drawing\b/i,
|
|
35
|
+
/\boutside the\b/i,
|
|
36
|
+
// English words for the same: forms of the verb and noun that `\b` words above do not reach.
|
|
37
|
+
standalone('sketch(?:es|ed|ing)', 'wireframes', 'wireframing', 'doodle[sd]?', 'doodling', 'whiteboard'),
|
|
38
|
+
// French
|
|
39
|
+
standalone('dessine(?:-moi)?', 'dessiner', 'croquis', 'esquisse[rz]?'),
|
|
40
|
+
// German
|
|
41
|
+
standalone('zeichne', 'zeichnen', 'skizze[n]?', 'skizziere[n]?'),
|
|
42
|
+
// Spanish
|
|
43
|
+
standalone('dibuja(?:me)?', 'dibújame', 'dibujar', 'bocetos?', 'esbozo', 'esbozar', 'bosquejo'),
|
|
44
|
+
// Italian
|
|
45
|
+
standalone('disegna(?:mi)?', 'disegnare', 'schizzo', 'schizza(?:re)?'),
|
|
46
|
+
// Portuguese
|
|
47
|
+
standalone('desenha(?:r)?', 'desenhe', 'desenho', 'rascunho', 'rascunhe', 'esbo[çc]o', 'esboce'),
|
|
48
|
+
// Romanian (with or without diacritics, and with the cedilla forms older keyboards write)
|
|
49
|
+
standalone('desene[aă]z[ăa](?:-mi)?', 'desena', 'desen', 'schi[țţt](?:[ăa]|e)', 'schi[țţt]e[aă]z[ăa]'),
|
|
50
|
+
// Polish
|
|
51
|
+
standalone('narysuj', 'rysuj', 'szkic(?:u|e)?', 'naszkicuj'),
|
|
52
|
+
// Dutch
|
|
53
|
+
standalone('teken', 'tekenen', 'schets(?:en)?'),
|
|
54
|
+
// Japanese, Chinese, Korean
|
|
55
|
+
anywhere('描いて', '描く', 'スケッチ', 'ワイヤーフレーム', '画一个', '画个', '画出', '绘制', '草图', '线框图', '그려', '스케치')
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* Words that say the author wants code, a build or a publish. They win over a drawing word: "draw it, then publish it"
|
|
59
|
+
* is a request for the widget.
|
|
60
|
+
*/
|
|
61
|
+
var CODEGEN_PATTERNS = [
|
|
62
|
+
/\bbuild\b/i,
|
|
63
|
+
/\bgenerate\b/i,
|
|
64
|
+
/\bcode\b/i,
|
|
65
|
+
/\bimplement\b/i,
|
|
66
|
+
/\bpublish\b/i,
|
|
67
|
+
/\bmake the button blue\b/i,
|
|
68
|
+
/\bfix the bug\b/i,
|
|
69
|
+
/\bdeploy\b/i,
|
|
70
|
+
/\bbuild me a\b/i,
|
|
71
|
+
/\bcountdown widget\b/i,
|
|
72
|
+
/\bwrite the react\b/i,
|
|
73
|
+
/\bship to production\b/i,
|
|
74
|
+
/\bship this\b/i,
|
|
75
|
+
/\brun codegen\b/i,
|
|
76
|
+
/\bpublish this widget\b/i,
|
|
77
|
+
// The same words in the languages the sketch words above cover.
|
|
78
|
+
standalone('construis', 'construire', 'génère', 'genere', 'générer', 'publie', 'publier', 'implémente', 'déploie'),
|
|
79
|
+
standalone('baue', 'bauen', 'generiere', 'generieren', 'veröffentliche', 'veröffentlichen', 'implementiere'),
|
|
80
|
+
standalone('construye', 'construir', 'genera', 'generar', 'código', 'codigo', 'publica', 'publicar', 'implementa', 'despliega'),
|
|
81
|
+
standalone('costruisci', 'costruire', 'generare', 'codice', 'pubblica', 'pubblicare'),
|
|
82
|
+
standalone('construa', 'gere', 'gerar', 'publique', 'implemente'),
|
|
83
|
+
standalone('construie[sș]te', 'genereaz[ăa]', 'cod', 'public[ăa]', 'implementeaz[ăa]'),
|
|
84
|
+
standalone('zbuduj', 'wygeneruj', 'kod', 'opublikuj', 'zaimplementuj'),
|
|
85
|
+
standalone('bouw', 'genereer', 'publiceer', 'implementeer')
|
|
86
|
+
];
|
|
87
|
+
export var SKETCH_INTENT_COUNTER_EXAMPLES = [
|
|
88
|
+
'build me a countdown widget',
|
|
89
|
+
'make the button blue in the widget',
|
|
90
|
+
'generate the react code for this',
|
|
91
|
+
'implement the checkout form',
|
|
92
|
+
'ship this widget to production',
|
|
93
|
+
'publish the widget now'
|
|
94
|
+
];
|
|
95
|
+
/**
|
|
96
|
+
* Free-text requests that draw, in the languages the router knows. Every one must route to the sketch assistant
|
|
97
|
+
* (the creator's tests and the gateway's mirror hold the same list).
|
|
98
|
+
*/
|
|
99
|
+
export var SKETCH_FREE_TEXT_EXAMPLES = [
|
|
100
|
+
'Sketch a pricing page with three plans and a call to action under each',
|
|
101
|
+
'wireframe a dashboard with a sidebar and four stat cards',
|
|
102
|
+
'can you draw three circles in a row and connect them with arrows',
|
|
103
|
+
'doodle a house with a red roof',
|
|
104
|
+
'put the navigation outside the thumbnail',
|
|
105
|
+
'dibuja una página de precios con tres planes',
|
|
106
|
+
'dibújame un formulario de inicio de sesión',
|
|
107
|
+
'haz un boceto de una tienda en línea',
|
|
108
|
+
'dessine une page de tarification avec trois offres',
|
|
109
|
+
'fais un croquis de la page d’accueil',
|
|
110
|
+
'zeichne eine Preisseite mit drei Tarifen',
|
|
111
|
+
'skizziere ein Dashboard mit vier Kacheln',
|
|
112
|
+
'disegna una pagina di login',
|
|
113
|
+
'fai uno schizzo della home page',
|
|
114
|
+
'desenha uma página de preços com três planos',
|
|
115
|
+
'faz um rascunho do painel',
|
|
116
|
+
'desenează o pagină de prețuri cu trei planuri',
|
|
117
|
+
'desenează-mi un formular de autentificare',
|
|
118
|
+
'fă o schiță a paginii de start',
|
|
119
|
+
'narysuj stronę z cennikiem',
|
|
120
|
+
'zrób szkic panelu',
|
|
121
|
+
'teken een prijzenpagina met drie abonnementen',
|
|
122
|
+
'maak een schets van het dashboard',
|
|
123
|
+
'ログイン画面のスケッチを描いて',
|
|
124
|
+
'画一个登录表单',
|
|
125
|
+
'로그인 폼을 그려줘'
|
|
126
|
+
];
|
|
127
|
+
/**
|
|
128
|
+
* Requests that are not for a drawing, with the verdict each gets. Creating something ("make", "create", "I need") is a
|
|
129
|
+
* widget, so most of them are `unknown` and go to the code generator by default; the ones that name code are `generate`.
|
|
130
|
+
*/
|
|
131
|
+
export var SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
|
|
132
|
+
['a video player with a playlist', 'unknown'],
|
|
133
|
+
['create a countdown timer with a start button', 'unknown'],
|
|
134
|
+
['I want a quiz about world capitals', 'unknown'],
|
|
135
|
+
['make a picture slider with arrows', 'unknown'],
|
|
136
|
+
['dibuja y publica el widget', 'generate'],
|
|
137
|
+
['publie le widget maintenant', 'generate'],
|
|
138
|
+
['erstelle einen Countdown-Timer', 'unknown'],
|
|
139
|
+
['costruisci un widget con il conto alla rovescia', 'generate'],
|
|
140
|
+
['crea un widget di sondaggio', 'unknown'],
|
|
141
|
+
['faz um widget de contagem decrescente', 'unknown'],
|
|
142
|
+
['construiește un widget cu numărătoare inversă', 'generate'],
|
|
143
|
+
['opublikuj widget teraz', 'generate'],
|
|
144
|
+
['画面を作って', 'unknown'],
|
|
145
|
+
// A word that only contains a drawing word is not a drawing request.
|
|
146
|
+
['kennzeichnen Sie die Felder', 'unknown']
|
|
147
|
+
];
|
|
148
|
+
/**
|
|
149
|
+
* Lightweight sketch-vs-codegen classifier for the creator chat (gateway mirrors this in tests).
|
|
150
|
+
*/
|
|
151
|
+
export function classifySketchIntent(message) {
|
|
152
|
+
var text = message.trim();
|
|
153
|
+
if (!text)
|
|
154
|
+
return 'unknown';
|
|
155
|
+
if (CODEGEN_PATTERNS.some(function (pattern) { return pattern.test(text); }))
|
|
156
|
+
return 'generate';
|
|
157
|
+
if (SKETCH_PATTERNS.some(function (pattern) { return pattern.test(text); }))
|
|
158
|
+
return 'sketch';
|
|
159
|
+
return 'unknown';
|
|
160
|
+
}
|
|
161
|
+
export var SKETCH_ACCEPTANCE_PROMPTS = [
|
|
162
|
+
'draw a video player for me',
|
|
163
|
+
'move the navigation outside the video thumbnail',
|
|
164
|
+
'delete all sketches',
|
|
165
|
+
'name every component and draw an arrow to it'
|
|
166
|
+
];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ObjectId, Rect } from '../engine/core/types.js';
|
|
2
|
+
import type { Scene } from '../engine/core/scene.js';
|
|
3
|
+
export declare const CANVAS_TOOL_NAMES: readonly ["get_canvas", "draw_ui_component", "add_shape", "add_text", "add_arrow", "move_elements", "delete_elements", "clear_canvas", "name_components_with_arrows"];
|
|
4
|
+
export type CanvasToolName = (typeof CANVAS_TOOL_NAMES)[number];
|
|
5
|
+
export interface CanvasBounds {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SceneElementSummary {
|
|
10
|
+
id: ObjectId;
|
|
11
|
+
kind: string;
|
|
12
|
+
label: string;
|
|
13
|
+
bbox: Rect;
|
|
14
|
+
zIndex: number;
|
|
15
|
+
parentId: ObjectId | null;
|
|
16
|
+
}
|
|
17
|
+
export interface SceneSummary {
|
|
18
|
+
bounds: CanvasBounds;
|
|
19
|
+
elements: SceneElementSummary[];
|
|
20
|
+
totalCount?: number;
|
|
21
|
+
truncated?: boolean;
|
|
22
|
+
truncationNote?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ToolSuccess {
|
|
25
|
+
ok: true;
|
|
26
|
+
message: string;
|
|
27
|
+
createdIds?: ObjectId[];
|
|
28
|
+
affectedIds?: ObjectId[];
|
|
29
|
+
summary?: SceneSummary;
|
|
30
|
+
}
|
|
31
|
+
export interface ToolFailure {
|
|
32
|
+
ok: false;
|
|
33
|
+
error: string;
|
|
34
|
+
code: 'invalid_args' | 'not_found' | 'bounds' | 'internal';
|
|
35
|
+
}
|
|
36
|
+
export type ToolResult = ToolSuccess | ToolFailure;
|
|
37
|
+
export interface CanvasToolHost {
|
|
38
|
+
readonly bounds: CanvasBounds;
|
|
39
|
+
getScene(): Scene;
|
|
40
|
+
/** Apply a new scene as one undo step. */
|
|
41
|
+
commitScene(next: Scene): void;
|
|
42
|
+
createId(prefix?: string): ObjectId;
|
|
43
|
+
}
|
|
44
|
+
export type ToolExecutor = (host: CanvasToolHost, args: Record<string, unknown>) => ToolResult;
|
|
45
|
+
export interface CanvasToolDefinition {
|
|
46
|
+
name: CanvasToolName;
|
|
47
|
+
description: string;
|
|
48
|
+
parameters: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export type UiComponentKind = 'video_player' | 'navigation_bar' | 'card' | 'button' | 'form' | 'table' | 'carousel' | 'modal';
|
|
51
|
+
export interface ToolMutation {
|
|
52
|
+
scene: Scene;
|
|
53
|
+
result: ToolResult;
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/canvas",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.41",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
"svelte": "./dist/i18n/index.js",
|
|
33
33
|
"default": "./dist/i18n/index.js"
|
|
34
34
|
},
|
|
35
|
+
"./tools": {
|
|
36
|
+
"types": "./dist/tools/index.d.ts",
|
|
37
|
+
"import": "./dist/tools/index.js",
|
|
38
|
+
"default": "./dist/tools/index.js"
|
|
39
|
+
},
|
|
35
40
|
"./icons/*": {
|
|
36
41
|
"types": "./dist/icons/*.d.ts",
|
|
37
42
|
"svelte": "./dist/icons/*.js",
|
|
@@ -54,7 +59,7 @@
|
|
|
54
59
|
"package": "NODE_ENV=production svelte-package",
|
|
55
60
|
"publish-to-npm": "node ../dev-tools/bin/publish-package.mjs",
|
|
56
61
|
"package:watch": "NODE_ENV=development svelte-package --watch",
|
|
57
|
-
"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\"",
|
|
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\"",
|
|
58
63
|
"preview": "vite preview",
|
|
59
64
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
60
65
|
"check:peers": "check-design-system-peers ..",
|