@eclipse-docks/extension-canvas 0.8.1 → 0.8.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"canvas-extension.js","names":[],"sources":["../src/canvas-extension.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n subscribe,\n TOOLBAR_MAIN_RIGHT,\n TOPIC_CONTRIBUTEIONS_CHANGED,\n type EditorInput,\n type HTMLContribution,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { CANVAS_SKILL } from './help';\nimport { isCanvasContribution, SYSTEM_CANVASES } from './contribution';\nimport { listRegisteredCanvases } from './canvases';\nimport { registerCanvasTools } from './canvas-tools';\nimport { registerCanvasCommands } from './commands';\nimport './canvas-switcher';\n\neditorRegistry.registerEditorInputHandler({\n editorId: 'system.canvas-editor',\n label: 'Canvas',\n icon: 'table-columns',\n ranking: 1100,\n canHandle: (input: unknown) => input instanceof File && input.getName().toLowerCase().endsWith('.canvas.js'),\n handle: async (input: File) => {\n const editorInput = {\n title: input.getName(),\n data: input,\n key: input.getWorkspacePath(),\n icon: 'table-columns',\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n editorInput.component = (id: string) => html`<docks-canvas-editor id=\"${id}\" .input=${editorInput}></docks-canvas-editor>`;\n return editorInput;\n },\n});\n\ncontributionRegistry.registerContribution(TOOLBAR_MAIN_RIGHT, {\n name: 'canvas.switcher',\n label: 'Canvases',\n component: () => html`<docks-canvas-switcher></docks-canvas-switcher>`,\n} as HTMLContribution);\n\nfunction registerListedCanvasTools(): void {\n for (const canvas of listRegisteredCanvases()) registerCanvasTools(canvas);\n}\n\nregisterCanvasCommands();\nregisterListedCanvasTools();\nsubscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event: { target?: string }) => {\n if (event?.target !== SYSTEM_CANVASES) return;\n for (const contribution of contributionRegistry.getContributions(SYSTEM_CANVASES)) {\n if (isCanvasContribution(contribution)) registerCanvasTools(contribution);\n }\n});\n\nvoid import('@eclipse-docks/extension-ai-system/api').then(ai => {\n ai.cognitiveRuntime.addSystemPromptEnhancer(prompt => `${prompt}\\n\\n${CANVAS_SKILL}`);\n}).catch(() => undefined);\n"],"mappings":";;;;;;;;;AAkBA,eAAe,2BAA2B;CACtC,UAAU;CACV,OAAO;CACP,MAAM;CACN,SAAS;CACT,YAAY,UAAmB,iBAAiB,QAAQ,MAAM,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,YAAY;CAC3G,QAAQ,OAAO,UAAgB;EAC3B,MAAM,cAAc;GAChB,OAAO,MAAM,QAAQ;GACrB,MAAM;GACN,KAAK,MAAM,iBAAiB;GAC5B,MAAM;GACN,OAAO,EAAE,MAAM,UAAU;GACzB,iBAAiB,IAAI;EACzB;EACA,YAAY,aAAa,OAAe,IAAI,4BAA4B,GAAG,WAAW,YAAY;EAClG,OAAO;CACX;AACJ,CAAC;AAED,qBAAqB,qBAAqB,oBAAoB;CAC1D,MAAM;CACN,OAAO;CACP,iBAAiB,IAAI;AACzB,CAAqB;AAErB,SAAS,4BAAkC;CACvC,KAAK,MAAM,UAAU,uBAAuB,GAAG,oBAAoB,MAAM;AAC7E;AAEA,uBAAuB;AACvB,0BAA0B;AAC1B,UAAU,+BAA+B,UAA+B;CACpE,IAAI,OAAO,WAAA,mBAA4B;CACvC,KAAK,MAAM,gBAAgB,qBAAqB,iBAAiB,eAAe,GAC5E,IAAI,qBAAqB,YAAY,GAAG,oBAAoB,YAAY;AAEhF,CAAC;AAEI,OAAO,yCAAyC,CAAC,MAAK,OAAM;CAC7D,GAAG,iBAAiB,yBAAwB,WAAU,GAAG,OAAO,MAAM,cAAc;AACxF,CAAC,CAAC,CAAC,YAAY,KAAA,CAAS"}
1
+ {"version":3,"file":"canvas-extension.js","names":[],"sources":["../src/canvas-extension.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n subscribe,\n TOOLBAR_MAIN_RIGHT,\n TOPIC_CONTRIBUTEIONS_CHANGED,\n type EditorInput,\n type HTMLContribution,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { SYSTEM_SKILLS, type SkillContribution } from '@eclipse-docks/extension-ai-system/api';\nimport { isCanvasContribution, SYSTEM_CANVASES } from './contribution';\nimport { listRegisteredCanvases } from './canvases';\nimport { registerCanvasTools } from './canvas-tools';\nimport { registerCanvasCommands } from './commands';\nimport './canvas-switcher';\n\neditorRegistry.registerEditorInputHandler({\n editorId: 'system.canvas-editor',\n label: 'Canvas',\n icon: 'table-columns',\n ranking: 1100,\n canHandle: (input: unknown) => input instanceof File && input.getName().toLowerCase().endsWith('.canvas.js'),\n handle: async (input: File) => {\n const editorInput = {\n title: input.getName(),\n data: input,\n key: input.getWorkspacePath(),\n icon: 'table-columns',\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n editorInput.component = (id: string) => html`<docks-canvas-editor id=\"${id}\" .input=${editorInput}></docks-canvas-editor>`;\n return editorInput;\n },\n});\n\ncontributionRegistry.registerContribution(TOOLBAR_MAIN_RIGHT, {\n name: 'canvas.switcher',\n label: 'Canvases',\n component: () => html`<docks-canvas-switcher></docks-canvas-switcher>`,\n} as HTMLContribution);\n\nconst canvasSkills = [\n {\n name: 'eclipse-docks-canvas',\n label: 'Eclipse Docks canvas',\n load: () => import('../skills/eclipse-docks-canvas/SKILL.md?raw'),\n ranking: 100,\n },\n {\n name: 'eclipse-docks-lit',\n label: 'Eclipse Docks Lit',\n load: () => import('../skills/eclipse-docks-lit/SKILL.md?raw'),\n ranking: 90,\n },\n {\n name: 'eclipse-docks-webawesome',\n label: 'Eclipse Docks Web Awesome',\n load: () => import('../skills/eclipse-docks-webawesome/SKILL.md?raw'),\n ranking: 90,\n },\n {\n name: 'eclipse-docks-core',\n label: 'Eclipse Docks core',\n load: () => import('../skills/eclipse-docks-core/SKILL.md?raw'),\n ranking: 90,\n },\n] as const satisfies ReadonlyArray<SkillContribution>;\n\nfor (const skill of canvasSkills) {\n contributionRegistry.registerContribution(SYSTEM_SKILLS, skill);\n}\n\nfunction registerListedCanvasTools(): void {\n for (const canvas of listRegisteredCanvases()) registerCanvasTools(canvas);\n}\n\nregisterCanvasCommands();\nregisterListedCanvasTools();\nsubscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event: { target?: string }) => {\n if (event?.target !== SYSTEM_CANVASES) return;\n for (const contribution of contributionRegistry.getContributions(SYSTEM_CANVASES)) {\n if (isCanvasContribution(contribution)) registerCanvasTools(contribution);\n }\n});\n"],"mappings":";;;;;;;;;AAkBA,eAAe,2BAA2B;CACtC,UAAU;CACV,OAAO;CACP,MAAM;CACN,SAAS;CACT,YAAY,UAAmB,iBAAiB,QAAQ,MAAM,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,YAAY;CAC3G,QAAQ,OAAO,UAAgB;EAC3B,MAAM,cAAc;GAChB,OAAO,MAAM,QAAQ;GACrB,MAAM;GACN,KAAK,MAAM,iBAAiB;GAC5B,MAAM;GACN,OAAO,EAAE,MAAM,UAAU;GACzB,iBAAiB,IAAI;EACzB;EACA,YAAY,aAAa,OAAe,IAAI,4BAA4B,GAAG,WAAW,YAAY;EAClG,OAAO;CACX;AACJ,CAAC;AAED,qBAAqB,qBAAqB,oBAAoB;CAC1D,MAAM;CACN,OAAO;CACP,iBAAiB,IAAI;AACzB,CAAqB;AAErB,IAAM,eAAe;CACjB;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;CACA;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;CACA;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;CACA;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;AACJ;AAEA,KAAK,MAAM,SAAS,cAChB,qBAAqB,qBAAqB,eAAe,KAAK;AAGlE,SAAS,4BAAkC;CACvC,KAAK,MAAM,UAAU,uBAAuB,GAAG,oBAAoB,MAAM;AAC7E;AAEA,uBAAuB;AACvB,0BAA0B;AAC1B,UAAU,+BAA+B,UAA+B;CACpE,IAAI,OAAO,WAAA,mBAA4B;CACvC,KAAK,MAAM,gBAAgB,qBAAqB,iBAAiB,eAAe,GAC5E,IAAI,qBAAqB,YAAY,GAAG,oBAAoB,YAAY;AAEhF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,KAAK,WAAW,EACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,iBAAiB,CAAC;AAIzB,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,EAAE,UAAU,SAAK,GAAG,WAAW,CAehG;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMpE;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOpE;AAMD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAYjF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjE;AAiBD,wBAAgB,sBAAsB,IAAI,IAAI,CAiK7C"}
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,KAAK,WAAW,EACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,OAAO,iBAAiB,CAAC;AAIzB,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,EAAE,UAAU,SAAK,GAAG,WAAW,CAehG;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMpE;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOpE;AAMD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAYjF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjE;AAiBD,wBAAgB,sBAAsB,IAAI,IAAI,CAyK7C"}
package/dist/commands.js CHANGED
@@ -1,6 +1,7 @@
1
- import { CANVAS_HELP } from "./help.js";
2
1
  import { listRegisteredCanvases } from "./canvases.js";
3
- import { readActiveCanvas } from "./active-canvas.js";
2
+ import { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas } from "./active-canvas.js";
3
+ import { attachPreviewShot } from "./preview-image.js";
4
+ import { writeWorkspaceFile } from "./workspace-file.js";
4
5
  import "./canvas-editor.js";
5
6
  import { File, PANEL_BOTTOM, SIDEBAR_AUXILIARY, SIDEBAR_MAIN, contributionRegistry, editorRegistry, registerAll, workspaceService } from "@eclipse-docks/core";
6
7
  import { html } from "@eclipse-docks/core/externals/lit";
@@ -74,18 +75,6 @@ async function waitForCanvas(match) {
74
75
  return null;
75
76
  }
76
77
  function registerCanvasCommands() {
77
- registerAll({
78
- command: {
79
- id: "canvas.help",
80
- name: "Canvas help",
81
- description: "Returns the canvas.js contract and the canvases registered on system.canvases",
82
- parameters: []
83
- },
84
- handler: { execute: async () => {
85
- const listed = listRegisteredCanvases().map((item) => `${item.name}: ${item.label}`).join("\n");
86
- return listed ? `${CANVAS_HELP}\n\nRegistered canvases:\n${listed}` : CANVAS_HELP;
87
- } }
88
- });
89
78
  registerAll({
90
79
  command: {
91
80
  id: "canvas.open",
@@ -113,8 +102,11 @@ function registerCanvasCommands() {
113
102
  if (path) {
114
103
  const opened = await openCanvasByPath(path);
115
104
  if (opened !== "ready") return opened;
116
- const active = await waitForCanvas((item) => item.kind === "workspace");
117
- return active?.reload ? active.reload() : opened;
105
+ const normalized = path.replace(/^\/+/, "");
106
+ const active = await waitForCanvas((item) => item.getFilePath?.()?.replace(/^\/+/, "") === normalized);
107
+ if (!active?.reload) return opened;
108
+ await active.syncFromFile?.();
109
+ return active.reload();
118
110
  }
119
111
  return "Provide a workspace path or a registered canvas name";
120
112
  } }
@@ -123,32 +115,33 @@ function registerCanvasCommands() {
123
115
  command: {
124
116
  id: "canvas.apply_source",
125
117
  name: "Apply canvas source",
126
- description: "Writes source into the active workspace canvas, compiles it, and returns ready or the compile error",
118
+ description: "Updates an open canvas editor and recompiles its preview without saving. When that canvas is not open in an editor, writes the file instead.",
127
119
  parameters: [{
128
120
  name: "source",
129
121
  description: "Full canvas module source",
130
122
  required: true
131
123
  }, {
132
124
  name: "path",
133
- description: "Workspace path of the canvas file",
125
+ description: "Workspace path of the canvas file. Required when that canvas is not open in an editor.",
134
126
  required: false
135
127
  }]
136
128
  },
137
- handler: {
138
- canExecute: () => !!workspaceCanvas(),
139
- execute: async ({ params }) => {
140
- const active = workspaceCanvas();
141
- if (!active?.setSource || !active.reload) return "No workspace canvas is active";
142
- const source = String(params?.source ?? "");
143
- const path = params?.path ?? active.getFilePath?.() ?? void 0;
144
- if (path) {
145
- const { writeWorkspaceFile } = await import("./workspace-file.js");
146
- if (!await writeWorkspaceFile(path, source)) return `Cannot write workspace file "${path}"`;
129
+ handler: { execute: async ({ params }) => {
130
+ const source = String(params?.source ?? "");
131
+ const path = (typeof params?.path === "string" ? params.path : void 0) ?? workspaceCanvas()?.getFilePath?.() ?? void 0;
132
+ const targets = path ? connectedWorkspaceEditors(path) : [];
133
+ if (targets.length) {
134
+ let compiled = "ready";
135
+ for (const editor of targets) {
136
+ if (!editor.setSource || !editor.reload) continue;
137
+ editor.setSource(source);
138
+ compiled = await editor.reload();
147
139
  }
148
- active.setSource(source);
149
- return active.reload();
140
+ return compiled;
150
141
  }
151
- }
142
+ if (!path) return "Provide a workspace path";
143
+ return writeWorkspaceFile(path, source);
144
+ } }
152
145
  });
153
146
  registerAll({
154
147
  command: {
@@ -203,6 +196,22 @@ function registerCanvasCommands() {
203
196
  }
204
197
  }
205
198
  });
199
+ registerAll({
200
+ command: {
201
+ id: "canvas.capture_preview",
202
+ name: "Capture canvas preview",
203
+ description: "Renders the open canvas preview to an image, attaches it to the session, and returns it for visual inspection. Content inside an iframe may be blank.",
204
+ parameters: []
205
+ },
206
+ handler: {
207
+ canExecute: () => !!findOpenCanvas()?.capturePreview,
208
+ execute: async () => {
209
+ const active = findOpenCanvas();
210
+ if (!active) return "No canvas is open";
211
+ return attachPreviewShot(active);
212
+ }
213
+ }
214
+ });
206
215
  registerAll({
207
216
  command: {
208
217
  id: "canvas.show_as_view",
@@ -1 +1 @@
1
- {"version":3,"file":"commands.js","names":[],"sources":["../src/commands.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n registerAll,\n SIDEBAR_AUXILIARY,\n SIDEBAR_MAIN,\n PANEL_BOTTOM,\n workspaceService,\n type EditorInput,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { readActiveCanvas } from './active-canvas';\nimport { listRegisteredCanvases } from './canvases';\nimport type { CanvasContribution } from './contribution';\nimport { CANVAS_HELP } from './help';\nimport './canvas-editor';\n\nconst VIEW_SLOTS = new Set([SIDEBAR_MAIN, SIDEBAR_AUXILIARY, PANEL_BOTTOM]);\n\nexport function canvasEditorInput(contribution: CanvasContribution, sourceText = ''): EditorInput {\n const hasSource = contribution.source !== undefined;\n const input = {\n key: `canvas:${contribution.name}`,\n title: contribution.label,\n icon: contribution.icon ?? 'table-columns',\n data: { contribution },\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n input.component = (id: string) => hasSource\n ? html`<docks-canvas-editor id=\"${id}\" .input=${input} .source=${sourceText}></docks-canvas-editor>`\n : html`<docks-canvas-surface id=\"${id}\" .input=${input}></docks-canvas-surface>`;\n (input as unknown as { editorId: string }).editorId = 'system.canvas-editor';\n return input;\n}\n\nexport async function openCanvasByName(name: string): Promise<string> {\n const contribution = listRegisteredCanvases().find(item => item.name === name);\n if (!contribution) return `No canvas named ${name}`;\n const sourceText = typeof contribution.source === 'function' ? await contribution.source() : (contribution.source ?? '');\n await editorRegistry.loadEditor(canvasEditorInput(contribution, sourceText));\n return 'ready';\n}\n\nexport async function openCanvasByPath(path: string): Promise<string> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return 'No workspace is open';\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return `Cannot find workspace file \"${path}\"`;\n await editorRegistry.loadEditor(resource, 'system.canvas-editor');\n return 'ready';\n}\n\nfunction viewName(path: string): string {\n return `canvas-view:${path}`;\n}\n\nexport function showCanvasView(slot: string, path: string, source: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n const name = viewName(path);\n contributionRegistry.unregisterContribution(slot, name);\n contributionRegistry.registerContribution(slot, {\n name,\n label: path.split('/').pop() || path,\n icon: 'table-columns',\n closable: true,\n component: (id: string) => html`<docks-canvas-surface id=\"${id}\" .entryPath=${path} .source=${source}></docks-canvas-surface>`,\n });\n return 'ready';\n}\n\nexport function hideCanvasView(slot: string, path: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n contributionRegistry.unregisterContribution(slot, viewName(path));\n return 'ready';\n}\n\nfunction workspaceCanvas() {\n const active = readActiveCanvas();\n if (!active?.editor || active.kind !== 'workspace') return null;\n return active;\n}\n\nasync function waitForCanvas(match: (active: NonNullable<ReturnType<typeof readActiveCanvas>>) => boolean) {\n for (let attempt = 0; attempt < 30; attempt++) {\n const active = readActiveCanvas();\n if (active?.reload && match(active)) return active;\n await new Promise(resolve => setTimeout(resolve, 50));\n }\n return null;\n}\n\nexport function registerCanvasCommands(): void {\n registerAll({\n command: {\n id: 'canvas.help',\n name: 'Canvas help',\n description: 'Returns the canvas.js contract and the canvases registered on system.canvases',\n parameters: [],\n },\n handler: {\n execute: async () => {\n const listed = listRegisteredCanvases().map(item => `${item.name}: ${item.label}`).join('\\n');\n return listed ? `${CANVAS_HELP}\\n\\nRegistered canvases:\\n${listed}` : CANVAS_HELP;\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.open',\n name: 'Open canvas',\n description: 'Opens a workspace .canvas.js path or a canvas registered on system.canvases and returns ready or a compile error',\n parameters: [\n { name: 'path', description: 'Workspace path of a .canvas.js file', required: false },\n { name: 'name', description: 'Name of a canvas registered on system.canvases', required: false },\n ],\n },\n handler: {\n execute: async ({ params }) => {\n const name = params?.name as string | undefined;\n const path = params?.path as string | undefined;\n if (name) {\n const opened = await openCanvasByName(name);\n if (opened !== 'ready') return opened;\n const active = await waitForCanvas(item => item.canvasName === name);\n return active?.reload ? active.reload() : opened;\n }\n if (path) {\n const opened = await openCanvasByPath(path);\n if (opened !== 'ready') return opened;\n const active = await waitForCanvas(item => item.kind === 'workspace');\n return active?.reload ? active.reload() : opened;\n }\n return 'Provide a workspace path or a registered canvas name';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.apply_source',\n name: 'Apply canvas source',\n description: 'Writes source into the active workspace canvas, compiles it, and returns ready or the compile error',\n parameters: [\n { name: 'source', description: 'Full canvas module source', required: true },\n { name: 'path', description: 'Workspace path of the canvas file', required: false },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n if (!active?.setSource || !active.reload) return 'No workspace canvas is active';\n const source = String(params?.source ?? '');\n const path = (params?.path as string | undefined) ?? active.getFilePath?.() ?? undefined;\n if (path) {\n const { writeWorkspaceFile } = await import('./workspace-file');\n const written = await writeWorkspaceFile(path, source);\n if (!written) return `Cannot write workspace file \"${path}\"`;\n }\n active.setSource(source);\n return active.reload();\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_source',\n name: 'Get canvas source',\n description: 'Returns the current source buffer of the active workspace canvas',\n parameters: [],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async () => workspaceCanvas()?.getContent?.() ?? '',\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_state',\n name: 'Get canvas state',\n description: 'Reads one persisted state value from the active workspace canvas',\n parameters: [{ name: 'key', description: 'State key', required: true }],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => workspaceCanvas()?.getState?.(String(params?.key ?? '')),\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.set_state',\n name: 'Set canvas state',\n description: 'Writes one persisted state value on the active workspace canvas',\n parameters: [\n { name: 'key', description: 'State key', required: true },\n { name: 'value', description: 'JSON value', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n if (!active?.setState) return 'No workspace canvas is active';\n active.setState(String(params?.key ?? ''), params?.value);\n return 'ready';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.show_as_view',\n name: 'Show canvas as view',\n description: 'Pins the active workspace canvas preview into a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n const path = active?.getFilePath?.();\n if (!active || !path) return 'No workspace canvas is active';\n return showCanvasView(String(params?.slot ?? ''), path, active.getContent?.() ?? '');\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.hide_view',\n name: 'Hide canvas view',\n description: 'Removes a pinned canvas preview from a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n { name: 'path', description: 'Workspace path of the canvas file', required: false },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const path = (params?.path as string | undefined) ?? workspaceCanvas()?.getFilePath?.() ?? '';\n if (!path) return 'No canvas path';\n return hideCanvasView(String(params?.slot ?? ''), path);\n },\n },\n });\n}\n"],"mappings":";;;;;;;AAkBA,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAc;CAAmB;AAAY,CAAC;AAE1E,SAAgB,kBAAkB,cAAkC,aAAa,IAAiB;CAC9F,MAAM,YAAY,aAAa,WAAW,KAAA;CAC1C,MAAM,QAAQ;EACV,KAAK,UAAU,aAAa;EAC5B,OAAO,aAAa;EACpB,MAAM,aAAa,QAAQ;EAC3B,MAAM,EAAE,aAAa;EACrB,OAAO,EAAE,MAAM,UAAU;EACzB,iBAAiB,IAAI;CACzB;CACA,MAAM,aAAa,OAAe,YAC5B,IAAI,4BAA4B,GAAG,WAAW,MAAM,WAAW,WAAW,2BAC1E,IAAI,6BAA6B,GAAG,WAAW,MAAM;CAC3D,MAA2C,WAAW;CACtD,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,eAAe,uBAAuB,CAAC,CAAC,MAAK,SAAQ,KAAK,SAAS,IAAI;CAC7E,IAAI,CAAC,cAAc,OAAO,mBAAmB;CAC7C,MAAM,aAAa,OAAO,aAAa,WAAW,aAAa,MAAM,aAAa,OAAO,IAAK,aAAa,UAAU;CACrH,MAAM,eAAe,WAAW,kBAAkB,cAAc,UAAU,CAAC;CAC3E,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,EAAE,CAAC;CACrE,IAAI,EAAE,oBAAoB,OAAO,OAAO,+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GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,SAAS,gBAAgB;IAC/B,MAAM,OAAO,QAAQ,cAAc;IACnC,IAAI,CAAC,UAAU,CAAC,MAAM,OAAO;IAC7B,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,aAAa,KAAK,EAAE;GACvF;EACJ;CACJ,CAAC;CAED,YAAY;EACR,SAAS;GACL,IAAI;GACJ,MAAM;GACN,aAAa;GACb,YAAY,CACR;IAAE,MAAM;IAAQ,aAAa;IAAoD,UAAU;GAAK,GAChG;IAAE,MAAM;IAAQ,aAAa;IAAqC,UAAU;GAAM,CACtF;EACJ;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,gBAAgB;GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,OAAQ,QAAQ,QAA+B,gBAAgB,CAAC,EAAE,cAAc,KAAK;IAC3F,IAAI,CAAC,MAAM,OAAO;IAClB,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,IAAI;GAC1D;EACJ;CACJ,CAAC;AACL"}
1
+ {"version":3,"file":"commands.js","names":[],"sources":["../src/commands.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n registerAll,\n SIDEBAR_AUXILIARY,\n SIDEBAR_MAIN,\n PANEL_BOTTOM,\n workspaceService,\n type EditorInput,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas } from './active-canvas';\nimport { listRegisteredCanvases } from './canvases';\nimport type { CanvasContribution } from './contribution';\nimport { attachPreviewShot } from './preview-image';\nimport { writeWorkspaceFile } from './workspace-file';\nimport './canvas-editor';\n\nconst VIEW_SLOTS = new Set([SIDEBAR_MAIN, SIDEBAR_AUXILIARY, PANEL_BOTTOM]);\n\nexport function canvasEditorInput(contribution: CanvasContribution, sourceText = ''): EditorInput {\n const hasSource = contribution.source !== undefined;\n const input = {\n key: `canvas:${contribution.name}`,\n title: contribution.label,\n icon: contribution.icon ?? 'table-columns',\n data: { contribution },\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n input.component = (id: string) => hasSource\n ? html`<docks-canvas-editor id=\"${id}\" .input=${input} .source=${sourceText}></docks-canvas-editor>`\n : html`<docks-canvas-surface id=\"${id}\" .input=${input}></docks-canvas-surface>`;\n (input as unknown as { editorId: string }).editorId = 'system.canvas-editor';\n return input;\n}\n\nexport async function openCanvasByName(name: string): Promise<string> {\n const contribution = listRegisteredCanvases().find(item => item.name === name);\n if (!contribution) return `No canvas named ${name}`;\n const sourceText = typeof contribution.source === 'function' ? await contribution.source() : (contribution.source ?? '');\n await editorRegistry.loadEditor(canvasEditorInput(contribution, sourceText));\n return 'ready';\n}\n\nexport async function openCanvasByPath(path: string): Promise<string> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return 'No workspace is open';\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return `Cannot find workspace file \"${path}\"`;\n await editorRegistry.loadEditor(resource, 'system.canvas-editor');\n return 'ready';\n}\n\nfunction viewName(path: string): string {\n return `canvas-view:${path}`;\n}\n\nexport function showCanvasView(slot: string, path: string, source: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n const name = viewName(path);\n contributionRegistry.unregisterContribution(slot, name);\n contributionRegistry.registerContribution(slot, {\n name,\n label: path.split('/').pop() || path,\n icon: 'table-columns',\n closable: true,\n component: (id: string) => html`<docks-canvas-surface id=\"${id}\" .entryPath=${path} .source=${source}></docks-canvas-surface>`,\n });\n return 'ready';\n}\n\nexport function hideCanvasView(slot: string, path: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n contributionRegistry.unregisterContribution(slot, viewName(path));\n return 'ready';\n}\n\nfunction workspaceCanvas() {\n const active = readActiveCanvas();\n if (!active?.editor || active.kind !== 'workspace') return null;\n return active;\n}\n\nasync function waitForCanvas(match: (active: NonNullable<ReturnType<typeof readActiveCanvas>>) => boolean) {\n for (let attempt = 0; attempt < 30; attempt++) {\n const active = readActiveCanvas();\n if (active?.reload && match(active)) return active;\n await new Promise(resolve => setTimeout(resolve, 50));\n }\n return null;\n}\n\nexport function registerCanvasCommands(): void {\n registerAll({\n command: {\n id: 'canvas.open',\n name: 'Open canvas',\n description: 'Opens a workspace .canvas.js path or a canvas registered on system.canvases and returns ready or a compile error',\n parameters: [\n { name: 'path', description: 'Workspace path of a .canvas.js file', required: false },\n { name: 'name', description: 'Name of a canvas registered on system.canvases', required: false },\n ],\n },\n handler: {\n execute: async ({ params }) => {\n const name = params?.name as string | undefined;\n const path = params?.path as string | undefined;\n if (name) {\n const opened = await openCanvasByName(name);\n if (opened !== 'ready') return opened;\n const active = await waitForCanvas(item => item.canvasName === name);\n return active?.reload ? active.reload() : opened;\n }\n if (path) {\n const opened = await openCanvasByPath(path);\n if (opened !== 'ready') return opened;\n const normalized = path.replace(/^\\/+/, '');\n const active = await waitForCanvas(item => item.getFilePath?.()?.replace(/^\\/+/, '') === normalized);\n if (!active?.reload) return opened;\n await active.syncFromFile?.();\n return active.reload();\n }\n return 'Provide a workspace path or a registered canvas name';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.apply_source',\n name: 'Apply canvas source',\n description: 'Updates an open canvas editor and recompiles its preview without saving. When that canvas is not open in an editor, writes the file instead.',\n parameters: [\n { name: 'source', description: 'Full canvas module source', required: true },\n { name: 'path', description: 'Workspace path of the canvas file. Required when that canvas is not open in an editor.', required: false },\n ],\n },\n handler: {\n execute: async ({ params }) => {\n const source = String(params?.source ?? '');\n const requested = typeof params?.path === 'string' ? params.path : undefined;\n const path = requested ?? workspaceCanvas()?.getFilePath?.() ?? undefined;\n const targets = path ? connectedWorkspaceEditors(path) : [];\n if (targets.length) {\n let compiled = 'ready';\n for (const editor of targets) {\n if (!editor.setSource || !editor.reload) continue;\n editor.setSource(source);\n compiled = await editor.reload();\n }\n return compiled;\n }\n if (!path) return 'Provide a workspace path';\n return writeWorkspaceFile(path, source);\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_source',\n name: 'Get canvas source',\n description: 'Returns the current source buffer of the active workspace canvas',\n parameters: [],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async () => workspaceCanvas()?.getContent?.() ?? '',\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_state',\n name: 'Get canvas state',\n description: 'Reads one persisted state value from the active workspace canvas',\n parameters: [{ name: 'key', description: 'State key', required: true }],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => workspaceCanvas()?.getState?.(String(params?.key ?? '')),\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.set_state',\n name: 'Set canvas state',\n description: 'Writes one persisted state value on the active workspace canvas',\n parameters: [\n { name: 'key', description: 'State key', required: true },\n { name: 'value', description: 'JSON value', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n if (!active?.setState) return 'No workspace canvas is active';\n active.setState(String(params?.key ?? ''), params?.value);\n return 'ready';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.capture_preview',\n name: 'Capture canvas preview',\n description: 'Renders the open canvas preview to an image, attaches it to the session, and returns it for visual inspection. Content inside an iframe may be blank.',\n parameters: [],\n },\n handler: {\n canExecute: () => !!findOpenCanvas()?.capturePreview,\n execute: async () => {\n const active = findOpenCanvas();\n if (!active) return 'No canvas is open';\n return attachPreviewShot(active);\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.show_as_view',\n name: 'Show canvas as view',\n description: 'Pins the active workspace canvas preview into a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n const path = active?.getFilePath?.();\n if (!active || !path) return 'No workspace canvas is active';\n return showCanvasView(String(params?.slot ?? ''), path, active.getContent?.() ?? '');\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.hide_view',\n name: 'Hide canvas view',\n description: 'Removes a pinned canvas preview from a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n { name: 'path', description: 'Workspace path of the canvas file', required: false },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const path = (params?.path as string | undefined) ?? workspaceCanvas()?.getFilePath?.() ?? '';\n if (!path) return 'No canvas path';\n return hideCanvasView(String(params?.slot ?? ''), path);\n },\n },\n });\n}\n"],"mappings":";;;;;;;;AAmBA,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAc;CAAmB;AAAY,CAAC;AAE1E,SAAgB,kBAAkB,cAAkC,aAAa,IAAiB;CAC9F,MAAM,YAAY,aAAa,WAAW,KAAA;CAC1C,MAAM,QAAQ;EACV,KAAK,UAAU,aAAa;EAC5B,OAAO,aAAa;EACpB,MAAM,aAAa,QAAQ;EAC3B,MAAM,EAAE,aAAa;EACrB,OAAO,EAAE,MAAM,UAAU;EACzB,iBAAiB,IAAI;CACzB;CACA,MAAM,aAAa,OAAe,YAC5B,IAAI,4BAA4B,GAAG,WAAW,MAAM,WAAW,WAAW,2BAC1E,IAAI,6BAA6B,GAAG,WAAW,MAAM;CAC3D,MAA2C,WAAW;CACtD,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,eAAe,uBAAuB,CAAC,CAAC,MAAK,SAAQ,KAAK,SAAS,IAAI;CAC7E,IAAI,CAAC,cAAc,OAAO,mBAAmB;CAC7C,MAAM,aAAa,OAAO,aAAa,WAAW,aAAa,MAAM,aAAa,OAAO,IAAK,aAAa,UAAU;CACrH,MAAM,eAAe,WAAW,kBAAkB,cAAc,UAAU,CAAC;CAC3E,OAAO;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,MAAM;GACN,aAAa;GACb,YAAY,CAAC;EACjB;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,eAAe,CAAC,EAAE;GACtC,SAAS,YAAY;IACjB,MAAM,SAAS,eAAe;IAC9B,IAAI,CAAC,QAAQ,OAAO;IACpB,OAAO,kBAAkB,MAAM;GACnC;EACJ;CACJ,CAAC;CAED,YAAY;EACR,SAAS;GACL,IAAI;GACJ,MAAM;GACN,aAAa;GACb,YAAY,CACR;IAAE,MAAM;IAAQ,aAAa;IAAoD,UAAU;GAAK,CACpG;EACJ;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,gBAAgB;GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,SAAS,gBAAgB;IAC/B,MAAM,OAAO,QAAQ,cAAc;IACnC,IAAI,CAAC,UAAU,CAAC,MAAM,OAAO;IAC7B,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,aAAa,KAAK,EAAE;GACvF;EACJ;CACJ,CAAC;CAED,YAAY;EACR,SAAS;GACL,IAAI;GACJ,MAAM;GACN,aAAa;GACb,YAAY,CACR;IAAE,MAAM;IAAQ,aAAa;IAAoD,UAAU;GAAK,GAChG;IAAE,MAAM;IAAQ,aAAa;IAAqC,UAAU;GAAM,CACtF;EACJ;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,gBAAgB;GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,OAAQ,QAAQ,QAA+B,gBAAgB,CAAC,EAAE,cAAc,KAAK;IAC3F,IAAI,CAAC,MAAM,OAAO;IAClB,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,IAAI;GAC1D;EACJ;CACJ,CAAC;AACL"}
@@ -0,0 +1,21 @@
1
+ /** Same field the specialist loop reads to schedule a follow-up vision message. */
2
+ export declare const PREVIEW_IMAGE_KEY = "_presentImage";
3
+ export interface PreviewShot {
4
+ dataUrl: string;
5
+ byteLength: number;
6
+ mime: string;
7
+ }
8
+ export interface StoredPreview {
9
+ id: string;
10
+ name: string;
11
+ path?: string;
12
+ }
13
+ export declare function rasterizeElement(element: HTMLElement): Promise<PreviewShot>;
14
+ export declare function previewFileName(sourceName: string | null | undefined, mime: string): string;
15
+ export declare function attachPreviewShot(active: {
16
+ capturePreview?: () => Promise<PreviewShot>;
17
+ getFilePath?: () => string | null;
18
+ canvasName?: string;
19
+ }): Promise<Record<string, unknown> | string>;
20
+ export declare function previewToolOutput(shot: PreviewShot, name: string, stored?: StoredPreview | null, presentKey?: string): Record<string, unknown>;
21
+ //# sourceMappingURL=preview-image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-image.d.ts","sourceRoot":"","sources":["../src/preview-image.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAKjD,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAsBjF;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI3F;AAED,wBAAsB,iBAAiB,CAAC,MAAM,EAAE;IAC5C,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5C,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,CAa5C;AAED,wBAAgB,iBAAiB,CAC7B,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,aAAa,GAAG,IAAI,EAC7B,UAAU,SAAoB,GAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAezB"}
@@ -0,0 +1,87 @@
1
+ import { domToBlob } from "modern-screenshot";
2
+ //#region src/preview-image.ts
3
+ /** Same field the specialist loop reads to schedule a follow-up vision message. */
4
+ var PREVIEW_IMAGE_KEY = "_presentImage";
5
+ var MAX_BYTES = 35e5;
6
+ var MAX_EDGE = 1600;
7
+ async function rasterizeElement(element) {
8
+ const rect = element.getBoundingClientRect();
9
+ if (rect.width < 2 || rect.height < 2) throw new Error("Canvas preview has no visible size");
10
+ const width = Math.round(rect.width);
11
+ const height = Math.round(rect.height);
12
+ const options = {
13
+ width,
14
+ height,
15
+ scale: Math.min(2, MAX_EDGE / Math.max(width, height)),
16
+ backgroundColor: opaqueBackground(element),
17
+ font: false,
18
+ features: { restoreScrollPosition: true }
19
+ };
20
+ let mime = "image/png";
21
+ let blob = await domToBlob(element, options);
22
+ if (blob.size > MAX_BYTES) {
23
+ mime = "image/jpeg";
24
+ blob = await domToBlob(element, {
25
+ ...options,
26
+ type: "image/jpeg",
27
+ quality: .8
28
+ });
29
+ }
30
+ if (blob.size > MAX_BYTES) throw new Error("Canvas preview image is too large to attach");
31
+ const bytes = new Uint8Array(await blob.arrayBuffer());
32
+ return {
33
+ mime,
34
+ byteLength: bytes.byteLength,
35
+ dataUrl: `data:${mime};base64,${bytesToBase64(bytes)}`
36
+ };
37
+ }
38
+ function previewFileName(sourceName, mime) {
39
+ return `${(sourceName?.split("/").pop() || "canvas").replace(/\.canvas\.js$/i, "").replace(/[^\w.-]+/g, "_") || "canvas"}.preview.${mime === "image/jpeg" ? "jpg" : "png"}`;
40
+ }
41
+ async function attachPreviewShot(active) {
42
+ if (!active.capturePreview) return "No canvas is open";
43
+ const shot = await active.capturePreview();
44
+ const name = previewFileName(active.getFilePath?.() ?? active.canvasName, shot.mime);
45
+ const { cognitiveRuntime } = await import("@eclipse-docks/extension-ai-system/api");
46
+ return previewToolOutput(shot, name, (await cognitiveRuntime.addAttachments(void 0, [{
47
+ name,
48
+ mime: shot.mime,
49
+ kind: "image",
50
+ dataUrl: shot.dataUrl,
51
+ byteLength: shot.byteLength
52
+ }]))[0]);
53
+ }
54
+ function previewToolOutput(shot, name, stored, presentKey = PREVIEW_IMAGE_KEY) {
55
+ return {
56
+ id: stored?.id ?? "",
57
+ name: stored?.name ?? name,
58
+ path: stored?.path,
59
+ mime: shot.mime,
60
+ kind: "image",
61
+ byteLength: shot.byteLength,
62
+ stored: Boolean(stored),
63
+ [presentKey]: true,
64
+ dataUrl: shot.dataUrl,
65
+ note: stored ? "Image bytes will be provided to the model in the next message for vision inspection." : "Image bytes follow for inspection. The preview was not stored because the session attachment limit is full."
66
+ };
67
+ }
68
+ function opaqueBackground(start) {
69
+ let current = start;
70
+ while (current) {
71
+ const color = getComputedStyle(current).backgroundColor;
72
+ if (color && color !== "transparent" && color !== "rgba(0, 0, 0, 0)") return color;
73
+ const root = current.getRootNode();
74
+ current = current.parentElement ?? (root instanceof ShadowRoot ? root.host : null);
75
+ }
76
+ return "#ffffff";
77
+ }
78
+ function bytesToBase64(bytes) {
79
+ const chunk = 32768;
80
+ let binary = "";
81
+ for (let i = 0; i < bytes.length; i += chunk) binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
82
+ return btoa(binary);
83
+ }
84
+ //#endregion
85
+ export { PREVIEW_IMAGE_KEY, attachPreviewShot, previewFileName, previewToolOutput, rasterizeElement };
86
+
87
+ //# sourceMappingURL=preview-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-image.js","names":[],"sources":["../src/preview-image.ts"],"sourcesContent":["import { domToBlob } from 'modern-screenshot';\n\n/** Same field the specialist loop reads to schedule a follow-up vision message. */\nexport const PREVIEW_IMAGE_KEY = '_presentImage';\n\nconst MAX_BYTES = 3_500_000;\nconst MAX_EDGE = 1600;\n\nexport interface PreviewShot {\n dataUrl: string;\n byteLength: number;\n mime: string;\n}\n\nexport interface StoredPreview {\n id: string;\n name: string;\n path?: string;\n}\n\nexport async function rasterizeElement(element: HTMLElement): Promise<PreviewShot> {\n const rect = element.getBoundingClientRect();\n if (rect.width < 2 || rect.height < 2) throw new Error('Canvas preview has no visible size');\n const width = Math.round(rect.width);\n const height = Math.round(rect.height);\n const options = {\n width,\n height,\n scale: Math.min(2, MAX_EDGE / Math.max(width, height)),\n backgroundColor: opaqueBackground(element),\n font: false as const,\n features: { restoreScrollPosition: true },\n };\n let mime = 'image/png';\n let blob = await domToBlob(element, options);\n if (blob.size > MAX_BYTES) {\n mime = 'image/jpeg';\n blob = await domToBlob(element, { ...options, type: 'image/jpeg', quality: 0.8 });\n }\n if (blob.size > MAX_BYTES) throw new Error('Canvas preview image is too large to attach');\n const bytes = new Uint8Array(await blob.arrayBuffer());\n return { mime, byteLength: bytes.byteLength, dataUrl: `data:${mime};base64,${bytesToBase64(bytes)}` };\n}\n\nexport function previewFileName(sourceName: string | null | undefined, mime: string): string {\n const base = (sourceName?.split('/').pop() || 'canvas').replace(/\\.canvas\\.js$/i, '').replace(/[^\\w.-]+/g, '_') || 'canvas';\n const ext = mime === 'image/jpeg' ? 'jpg' : 'png';\n return `${base}.preview.${ext}`;\n}\n\nexport async function attachPreviewShot(active: {\n capturePreview?: () => Promise<PreviewShot>;\n getFilePath?: () => string | null;\n canvasName?: string;\n}): Promise<Record<string, unknown> | string> {\n if (!active.capturePreview) return 'No canvas is open';\n const shot = await active.capturePreview();\n const name = previewFileName(active.getFilePath?.() ?? active.canvasName, shot.mime);\n const { cognitiveRuntime } = await import('@eclipse-docks/extension-ai-system/api');\n const stored = await cognitiveRuntime.addAttachments(undefined, [{\n name,\n mime: shot.mime,\n kind: 'image',\n dataUrl: shot.dataUrl,\n byteLength: shot.byteLength,\n }]);\n return previewToolOutput(shot, name, stored[0]);\n}\n\nexport function previewToolOutput(\n shot: PreviewShot,\n name: string,\n stored?: StoredPreview | null,\n presentKey = PREVIEW_IMAGE_KEY,\n): Record<string, unknown> {\n return {\n id: stored?.id ?? '',\n name: stored?.name ?? name,\n path: stored?.path,\n mime: shot.mime,\n kind: 'image',\n byteLength: shot.byteLength,\n stored: Boolean(stored),\n [presentKey]: true,\n dataUrl: shot.dataUrl,\n note: stored\n ? 'Image bytes will be provided to the model in the next message for vision inspection.'\n : 'Image bytes follow for inspection. The preview was not stored because the session attachment limit is full.',\n };\n}\n\nfunction opaqueBackground(start: Element): string {\n let current: Element | null = start;\n while (current) {\n const color = getComputedStyle(current).backgroundColor;\n if (color && color !== 'transparent' && color !== 'rgba(0, 0, 0, 0)') return color;\n const root = current.getRootNode();\n current = current.parentElement ?? (root instanceof ShadowRoot ? root.host : null);\n }\n return '#ffffff';\n}\n\nfunction bytesToBase64(bytes: Uint8Array): string {\n const chunk = 0x8000;\n let binary = '';\n for (let i = 0; i < bytes.length; i += chunk) {\n binary += String.fromCharCode(...bytes.subarray(i, i + chunk));\n }\n return btoa(binary);\n}\n"],"mappings":";;;AAGA,IAAa,oBAAoB;AAEjC,IAAM,YAAY;AAClB,IAAM,WAAW;AAcjB,eAAsB,iBAAiB,SAA4C;CAC/E,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,IAAI,KAAK,QAAQ,KAAK,KAAK,SAAS,GAAG,MAAM,IAAI,MAAM,oCAAoC;CAC3F,MAAM,QAAQ,KAAK,MAAM,KAAK,KAAK;CACnC,MAAM,SAAS,KAAK,MAAM,KAAK,MAAM;CACrC,MAAM,UAAU;EACZ;EACA;EACA,OAAO,KAAK,IAAI,GAAG,WAAW,KAAK,IAAI,OAAO,MAAM,CAAC;EACrD,iBAAiB,iBAAiB,OAAO;EACzC,MAAM;EACN,UAAU,EAAE,uBAAuB,KAAK;CAC5C;CACA,IAAI,OAAO;CACX,IAAI,OAAO,MAAM,UAAU,SAAS,OAAO;CAC3C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0B;CAC9B,OAAO,SAAS;EACZ,MAAM,QAAQ,iBAAiB,OAAO,CAAC,CAAC;EACxC,IAAI,SAAS,UAAU,iBAAiB,UAAU,oBAAoB,OAAO;EAC7E,MAAM,OAAO,QAAQ,YAAY;EACjC,UAAU,QAAQ,kBAAkB,gBAAgB,aAAa,KAAK,OAAO;CACjF;CACA,OAAO;AACX;AAEA,SAAS,cAAc,OAA2B;CAC9C,MAAM,QAAQ;CACd,IAAI,SAAS;CACb,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,OACnC,UAAU,OAAO,aAAa,GAAG,MAAM,SAAS,GAAG,IAAI,KAAK,CAAC;CAEjE,OAAO,KAAK,MAAM;AACtB"}
@@ -1,5 +1,5 @@
1
- import { File } from '@eclipse-docks/core';
2
1
  import { CanvasFileBytes } from './compile';
3
2
  export declare function readWorkspaceFile(path: string): Promise<CanvasFileBytes | null>;
4
- export declare function writeWorkspaceFile(path: string, contents: string): Promise<File | null>;
3
+ /** Writes a canvas module. Used when that file is not open in an editor. */
4
+ export declare function writeWorkspaceFile(path: string, contents: string): Promise<string>;
5
5
  //# sourceMappingURL=workspace-file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-file.d.ts","sourceRoot":"","sources":["../src/workspace-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAIjD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAerF;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAO7F"}
1
+ {"version":3,"file":"workspace-file.d.ts","sourceRoot":"","sources":["../src/workspace-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAIjD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAerF;AAED,4EAA4E;AAC5E,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASxF"}
@@ -27,13 +27,16 @@ async function readWorkspaceFile(path) {
27
27
  if (typeof blob === "string") return { text: blob };
28
28
  return null;
29
29
  }
30
+ /** Writes a canvas module. Used when that file is not open in an editor. */
30
31
  async function writeWorkspaceFile(path, contents) {
32
+ const normalized = path.replace(/^\/+/, "");
33
+ if (!normalized.endsWith(".canvas.js")) return `Not a canvas file "${path}"`;
31
34
  const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();
32
- if (!workspace) return null;
33
- const resource = await workspace.getResource(path.replace(/^\/+/, ""), { create: true });
34
- if (!(resource instanceof File)) return null;
35
+ if (!workspace) return "No workspace is open";
36
+ const resource = await workspace.getResource(normalized, { create: true });
37
+ if (!(resource instanceof File)) return `Cannot write workspace file "${path}"`;
35
38
  await resource.saveContents(contents);
36
- return resource;
39
+ return "ready";
37
40
  }
38
41
  //#endregion
39
42
  export { readWorkspaceFile, writeWorkspaceFile };
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-file.js","names":[],"sources":["../src/workspace-file.ts"],"sourcesContent":["import { File, workspaceService } from '@eclipse-docks/core';\nimport type { CanvasFileBytes } from './compile';\n\nconst TEXT_EXT = new Set(['js', 'mjs', 'css', 'json', 'svg', 'txt', 'md', 'html', 'csv']);\n\nexport async function readWorkspaceFile(path: string): Promise<CanvasFileBytes | null> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return null;\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return null;\n const ext = path.split('.').pop()?.toLowerCase() ?? '';\n if (TEXT_EXT.has(ext) || path.endsWith('.canvas.js')) {\n const text = await resource.getContents();\n return { text: typeof text === 'string' ? text : String(text ?? '') };\n }\n const blob = await resource.getContents({ blob: true });\n if (blob instanceof Blob) return { bytes: new Uint8Array(await blob.arrayBuffer()) };\n if (blob instanceof Uint8Array) return { bytes: blob };\n if (typeof blob === 'string') return { text: blob };\n return null;\n}\n\nexport async function writeWorkspaceFile(path: string, contents: string): Promise<File | null> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return null;\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''), { create: true });\n if (!(resource instanceof File)) return null;\n await resource.saveContents(contents);\n return resource;\n}\n"],"mappings":";;AAGA,IAAM,2BAAW,IAAI,IAAI;CAAC;CAAM;CAAO;CAAO;CAAQ;CAAO;CAAO;CAAM;CAAQ;AAAK,CAAC;AAExF,eAAsB,kBAAkB,MAA+C;CACnF,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,EAAE,CAAC;CACrE,IAAI,EAAE,oBAAoB,OAAO,OAAO;CACxC,MAAM,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,YAAY,KAAK;CACpD,IAAI,SAAS,IAAI,GAAG,KAAK,KAAK,SAAS,YAAY,GAAG;EAClD,MAAM,OAAO,MAAM,SAAS,YAAY;EACxC,OAAO,EAAE,MAAM,OAAO,SAAS,WAAW,OAAO,OAAO,QAAQ,EAAE,EAAE;CACxE;CACA,MAAM,OAAO,MAAM,SAAS,YAAY,EAAE,MAAM,KAAK,CAAC;CACtD,IAAI,gBAAgB,MAAM,OAAO,EAAE,OAAO,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC,EAAE;CACnF,IAAI,gBAAgB,YAAY,OAAO,EAAE,OAAO,KAAK;CACrD,IAAI,OAAO,SAAS,UAAU,OAAO,EAAE,MAAM,KAAK;CAClD,OAAO;AACX;AAEA,eAAsB,mBAAmB,MAAc,UAAwC;CAC3F,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,EAAE,GAAG,EAAE,QAAQ,KAAK,CAAC;CACvF,IAAI,EAAE,oBAAoB,OAAO,OAAO;CACxC,MAAM,SAAS,aAAa,QAAQ;CACpC,OAAO;AACX"}
1
+ {"version":3,"file":"workspace-file.js","names":[],"sources":["../src/workspace-file.ts"],"sourcesContent":["import { File, workspaceService } from '@eclipse-docks/core';\nimport type { CanvasFileBytes } from './compile';\n\nconst TEXT_EXT = new Set(['js', 'mjs', 'css', 'json', 'svg', 'txt', 'md', 'html', 'csv']);\n\nexport async function readWorkspaceFile(path: string): Promise<CanvasFileBytes | null> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return null;\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return null;\n const ext = path.split('.').pop()?.toLowerCase() ?? '';\n if (TEXT_EXT.has(ext) || path.endsWith('.canvas.js')) {\n const text = await resource.getContents();\n return { text: typeof text === 'string' ? text : String(text ?? '') };\n }\n const blob = await resource.getContents({ blob: true });\n if (blob instanceof Blob) return { bytes: new Uint8Array(await blob.arrayBuffer()) };\n if (blob instanceof Uint8Array) return { bytes: blob };\n if (typeof blob === 'string') return { text: blob };\n return null;\n}\n\n/** Writes a canvas module. Used when that file is not open in an editor. */\nexport async function writeWorkspaceFile(path: string, contents: string): Promise<string> {\n const normalized = path.replace(/^\\/+/, '');\n if (!normalized.endsWith('.canvas.js')) return `Not a canvas file \"${path}\"`;\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return 'No workspace is open';\n const resource = await workspace.getResource(normalized, { create: true });\n if (!(resource instanceof File)) return `Cannot write workspace file \"${path}\"`;\n await resource.saveContents(contents);\n return 'ready';\n}\n"],"mappings":";;AAGA,IAAM,2BAAW,IAAI,IAAI;CAAC;CAAM;CAAO;CAAO;CAAQ;CAAO;CAAO;CAAM;CAAQ;AAAK,CAAC;AAExF,eAAsB,kBAAkB,MAA+C;CACnF,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,EAAE,CAAC;CACrE,IAAI,EAAE,oBAAoB,OAAO,OAAO;CACxC,MAAM,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,YAAY,KAAK;CACpD,IAAI,SAAS,IAAI,GAAG,KAAK,KAAK,SAAS,YAAY,GAAG;EAClD,MAAM,OAAO,MAAM,SAAS,YAAY;EACxC,OAAO,EAAE,MAAM,OAAO,SAAS,WAAW,OAAO,OAAO,QAAQ,EAAE,EAAE;CACxE;CACA,MAAM,OAAO,MAAM,SAAS,YAAY,EAAE,MAAM,KAAK,CAAC;CACtD,IAAI,gBAAgB,MAAM,OAAO,EAAE,OAAO,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC,EAAE;CACnF,IAAI,gBAAgB,YAAY,OAAO,EAAE,OAAO,KAAK;CACrD,IAAI,OAAO,SAAS,UAAU,OAAO,EAAE,MAAM,KAAK;CAClD,OAAO;AACX;;AAGA,eAAsB,mBAAmB,MAAc,UAAmC;CACtF,MAAM,aAAa,KAAK,QAAQ,QAAQ,EAAE;CAC1C,IAAI,CAAC,WAAW,SAAS,YAAY,GAAG,OAAO,sBAAsB,KAAK;CAC1E,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,YAAY,EAAE,QAAQ,KAAK,CAAC;CACzE,IAAI,EAAE,oBAAoB,OAAO,OAAO,gCAAgC,KAAK;CAC7E,MAAM,SAAS,aAAa,QAAQ;CACpC,OAAO;AACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eclipse-docks/extension-canvas",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -16,7 +16,8 @@
16
16
  }
17
17
  },
18
18
  "files": [
19
- "dist"
19
+ "dist",
20
+ "skills"
20
21
  ],
21
22
  "scripts": {
22
23
  "build": "vite build",
@@ -25,7 +26,8 @@
25
26
  "dependencies": {
26
27
  "@eclipse-docks/core": "*",
27
28
  "@eclipse-docks/extension-ai-system": "*",
28
- "@eclipse-docks/extension-monaco-editor": "*"
29
+ "@eclipse-docks/extension-monaco-editor": "*",
30
+ "modern-screenshot": "^4.7.0"
29
31
  },
30
32
  "devDependencies": {
31
33
  "jsdom": "^25.0.0",
@@ -0,0 +1,127 @@
1
+ ---
2
+ name: eclipse-docks-canvas
3
+ description: >-
4
+ Create or edit interactive Eclipse Docks canvases (.canvas.js): LitElement UIs,
5
+ dashboards, todo apps, widgets, maps, and previewable tools. Use when the user
6
+ wants an interactive view, canvas, widget, or .canvas.js file — even if they do
7
+ not say "canvas".
8
+ ---
9
+
10
+ # Eclipse Docks canvas
11
+
12
+ Write a workspace file ending in `.canvas.js`. Default-export a `LitElement` subclass from `docks/lit`. Do **not** extend `HTMLElement`. Do **not** call `customElements.define` — the host registers the tag.
13
+
14
+ ## Hard rules
15
+
16
+ 1. **`canvasHost` is unavailable in `constructor`.** The host sets `this.canvasHost` after construction. Read/write persisted state in `connectedCallback` (after `super`) or later. Always guard: `this.canvasHost?.getState` / `setState`.
17
+ 2. Pure JavaScript only — no TypeScript, no decorators. Declare reactive fields with `static properties = { … }`. Initialize plain defaults in `constructor`; hydrate from `canvasHost` only after connect.
18
+ 3. Build controls and chrome with Web Awesome (`wa-button`, `wa-input`, `wa-checkbox`, `wa-card`, `wa-callout`, `wa-spinner`). `import "docks/webawesome"` only registers the elements; a raw `<button>` or `<input>` is not a substitute. Load `eclipse-docks-webawesome` before a non-trivial UI, and use `--wa-color-*` tokens instead of hardcoded colors.
19
+ 4. Emit complete, valid JavaScript — no truncated objects or unfinished strings.
20
+ 5. The page uses `Cross-Origin-Embedder-Policy: require-corp`. A cross-origin response loads only when the request is CORS and the server sends `Access-Control-Allow-Origin`, or when the server sends `Cross-Origin-Resource-Policy: cross-origin`. An `<iframe srcdoc>` inherits this policy; `sandbox="allow-same-origin"` does not exempt it. Keep `docks/lit`, `docks/webawesome`, and `canvasHost` on the LitElement.
21
+
22
+ ## Minimal pattern
23
+
24
+ ```js
25
+ import { LitElement, html, css } from "docks/lit";
26
+ import "docks/webawesome";
27
+
28
+ export default class extends LitElement {
29
+ static properties = {
30
+ items: { state: true },
31
+ draft: { state: true },
32
+ };
33
+
34
+ static styles = css`
35
+ :host { display: block; padding: 1rem; box-sizing: border-box; }
36
+ `;
37
+
38
+ constructor() {
39
+ super();
40
+ this.items = [];
41
+ this.draft = "";
42
+ }
43
+
44
+ connectedCallback() {
45
+ super.connectedCallback();
46
+ const saved = this.canvasHost?.getState("items", null);
47
+ if (Array.isArray(saved)) this.items = saved;
48
+ }
49
+
50
+ persist() {
51
+ this.canvasHost?.setState("items", this.items);
52
+ }
53
+
54
+ addItem() {
55
+ const text = this.draft.trim();
56
+ if (!text) return;
57
+ this.items = [...this.items, { id: crypto.randomUUID(), text, done: false }];
58
+ this.draft = "";
59
+ this.persist();
60
+ }
61
+
62
+ render() {
63
+ return html`
64
+ <wa-input
65
+ placeholder="New item"
66
+ .value=${this.draft}
67
+ @input=${(e) => { this.draft = e.target.value; }}
68
+ @keydown=${(e) => { if (e.key === "Enter") this.addItem(); }}
69
+ ></wa-input>
70
+ <wa-button @click=${() => this.addItem()}>Add</wa-button>
71
+ <ul>
72
+ ${this.items.map((item) => html`<li>${item.text}</li>`)}
73
+ </ul>
74
+ `;
75
+ }
76
+ }
77
+ ```
78
+
79
+ APIs: `this.canvasHost.getState(key, fallback)`, `this.canvasHost.setState(key, value)`, `this.canvasHost.openFile(path)`.
80
+
81
+ ## Cross-origin resources
82
+
83
+ `<img>`, `<link>`, and `<script>` tags without `crossorigin` are no-cors. A no-cors response that omits `Cross-Origin-Resource-Policy` fails with `not-set cross-origin-resource-policy`, even when it sends `Access-Control-Allow-Origin: *`. Moving that URL into an `<iframe srcdoc>` does not change the check. Subresources inside the frame follow the same rule.
84
+
85
+ When the server only sends `Access-Control-Allow-Origin`, request the resource as CORS. `fetch()` already does. For an element, set `crossorigin="anonymous"`. When a library creates the element, set its equivalent option (often `crossOrigin: "anonymous"`). A missing `Access-Control-Allow-Origin` header on that request is a CORS error, not the CORP error.
86
+
87
+ ```html
88
+ <img crossorigin="anonymous" src="https://cdn.example/asset.png" />
89
+ <script crossorigin="anonymous" src="https://cdn.example/lib.js"></script>
90
+ ```
91
+
92
+ A host that sends neither header cannot be embedded in this page. Pass the string `"anonymous"` to a library option (`crossOrigin: "anonymous"`). A boolean `true` is not that option.
93
+
94
+ ## Styles inside the shadow root
95
+
96
+ The canvas renders in a shadow root. A `<link>` or `<style>` added to `document.head` does not apply to nodes inside that root. A widget that positions its own DOM with classes will load its images and still draw them in the wrong place until its stylesheet is on the shadow root.
97
+
98
+ Fetch the stylesheet as CORS and adopt it before constructing the widget:
99
+
100
+ ```js
101
+ const cssText = await (await fetch(stylesheetUrl, { mode: "cors" })).text();
102
+ const sheet = new CSSStyleSheet();
103
+ sheet.replaceSync(cssText);
104
+ this.shadowRoot.adoptedStyleSheets = [...this.shadowRoot.adoptedStyleSheets, sheet];
105
+ ```
106
+
107
+ `static styles` is for the host. Do not rely on a document-level stylesheet for DOM the library creates inside the shadow root.
108
+
109
+ ## Imports
110
+
111
+ - `docks/lit`, `docks/webawesome`, `docks/core` → running app
112
+ - Relative imports → workspace files (compiler inlines them: JSON → value, text/CSS → string, binaries → data URL)
113
+
114
+ Before non-trivial UI or shell integration, load companion skills as needed:
115
+
116
+ - `skills.load` `eclipse-docks-lit` — reactive properties, templates, directives (pure JS)
117
+ - `skills.load` `eclipse-docks-webawesome` — `wa-*` components and layout utilities
118
+ - `skills.load` `eclipse-docks-core` — workspace, editors, commands, dialogs, events
119
+
120
+ ## Workflow
121
+
122
+ 1. `workspace_write` a durable `<root>/….canvas.js` (qualify with a root from `workspace_list`).
123
+ 2. `canvas.open` with that path — returns `ready` or the compile/runtime error.
124
+ 3. Change a canvas with `canvas.apply_source`. If that canvas is open in an editor, the editor marks itself dirty and recompiles the preview and does not save. If it is not open in an editor, the tool writes the file. Do not `workspace_write` a canvas that is already open.
125
+ 4. Optional: `canvas.capture_preview` to attach a screenshot (iframe contents may be blank).
126
+
127
+ Extension-registered canvases live on `system.canvases` and open by name via `canvas.open`.