@agent-native/core 0.92.7 → 0.92.8
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/corpus/README.md +1 -1
- package/corpus/core/CHANGELOG.md +12 -0
- package/corpus/core/docs/content/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/ar-SA/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/ar-SA/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/ar-SA/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/de-DE/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/de-DE/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/de-DE/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/es-ES/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/es-ES/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/es-ES/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/fr-FR/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/fr-FR/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/fr-FR/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/hi-IN/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/hi-IN/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/hi-IN/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/ja-JP/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/ja-JP/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/ja-JP/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/ko-KR/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/ko-KR/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/ko-KR/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/pt-BR/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/pt-BR/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/pt-BR/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/zh-CN/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/zh-CN/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/zh-CN/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/locales/zh-TW/a2a-protocol.mdx +12 -0
- package/corpus/core/docs/content/locales/zh-TW/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/locales/zh-TW/pure-agent-apps.mdx +4 -0
- package/corpus/core/docs/content/pr-visual-recap.mdx +3 -3
- package/corpus/core/docs/content/pure-agent-apps.mdx +22 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/engine/builtin.ts +1 -1
- package/corpus/core/src/agent/model-config.ts +30 -30
- package/corpus/core/src/agent/production-agent.ts +129 -7
- package/corpus/core/src/cli/design-connect.ts +438 -83
- package/corpus/core/src/cli/recap.ts +2 -2
- package/corpus/core/src/client/AgentPanel.tsx +8 -1
- package/corpus/core/src/client/agent-chat-adapter.ts +12 -7
- package/corpus/core/src/client/composer/TiptapComposer.tsx +1 -1
- package/corpus/core/src/client/index.ts +4 -0
- package/corpus/core/src/client/org/TeamPage.tsx +41 -26
- package/corpus/core/src/client/use-action.ts +113 -1
- package/corpus/core/src/db/client.ts +12 -2
- package/corpus/core/src/db/create-get-db.ts +4 -1
- package/corpus/core/src/scripts/agent-engines/manage-agent-engine.ts +1 -1
- package/corpus/core/src/scripts/agent-engines/set-agent-engine.ts +1 -1
- package/corpus/core/src/server/transcribe-voice.ts +1 -1
- package/corpus/core/src/usage/store.ts +13 -4
- package/corpus/core/src/vite/client.ts +38 -1
- package/corpus/templates/analytics/AGENTS.md +3 -0
- package/corpus/templates/analytics/actions/get-data-program.ts +78 -0
- package/corpus/templates/analytics/actions/list-data-programs.ts +49 -0
- package/corpus/templates/analytics/app/global.css +11 -0
- package/corpus/templates/analytics/app/hooks/use-dashboard-chat-context.ts +163 -17
- package/corpus/templates/analytics/app/i18n/zh-TW.ts +2 -0
- package/corpus/templates/analytics/app/i18n-data.ts +20 -0
- package/corpus/templates/analytics/app/pages/adhoc/explorer-dashboard/ChartCard.tsx +96 -3
- package/corpus/templates/analytics/app/pages/adhoc/explorer-dashboard/index.tsx +3 -1
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/SqlChartCard.tsx +61 -4
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/index.tsx +40 -2
- package/corpus/templates/analytics/changelog/2026-07-09-analytics-no-longer-forgets-successful-data-queries-when-a-l.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-09-dashboard-charts-keep-consistent-spacing-when-they-stack-ver.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-09-dashboard-charts-tables-and-extensions-can-be-selected-and-d.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-09-long-running-analytics-requests-now-recover-automatically-wh.md +6 -0
- package/corpus/templates/analytics/server/db/index.ts +6 -0
- package/corpus/templates/clips/desktop/src/hooks/useMeetingTranscription.ts +1 -7
- package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +102 -15
- package/corpus/templates/content/app/hooks/use-content-database.ts +52 -0
- package/corpus/templates/content/app/hooks/use-document-properties.ts +50 -6
- package/corpus/templates/content/app/i18n/zh-TW.ts +2 -0
- package/corpus/templates/content/app/i18n-data.ts +28 -0
- package/corpus/templates/content/changelog/2026-07-09-notion-conflict-warnings-no-longer-flash-during-normal-synce.md +6 -0
- package/corpus/templates/content/changelog/2026-07-09-property-menus-and-delete-confirmations-now-open-visibly-and.md +6 -0
- package/corpus/templates/content/server/lib/notion-sync.ts +130 -28
- package/corpus/templates/design/actions/add-breakpoint.ts +48 -68
- package/corpus/templates/design/actions/add-localhost-screens.ts +496 -61
- package/corpus/templates/design/actions/apply-component-prop-edit.ts +2 -18
- package/corpus/templates/design/actions/apply-design-token-edit.ts +51 -82
- package/corpus/templates/design/actions/apply-tweaks.ts +63 -41
- package/corpus/templates/design/actions/capture-design-state.ts +2 -2
- package/corpus/templates/design/actions/connect-localhost.ts +58 -12
- package/corpus/templates/design/actions/create-component.ts +2 -18
- package/corpus/templates/design/actions/create-design-branch.ts +38 -18
- package/corpus/templates/design/actions/create-fusion-app.ts +15 -11
- package/corpus/templates/design/actions/delete-file.ts +19 -34
- package/corpus/templates/design/actions/deploy-design-preview.ts +59 -27
- package/corpus/templates/design/actions/deploy-fusion-app.ts +22 -15
- package/corpus/templates/design/actions/export-pdf.ts +2 -1
- package/corpus/templates/design/actions/export-zip.ts +9 -3
- package/corpus/templates/design/actions/generate-design.ts +107 -70
- package/corpus/templates/design/actions/get-component-details.ts +2 -18
- package/corpus/templates/design/actions/get-design-branch-diff.ts +2 -3
- package/corpus/templates/design/actions/get-design-surface-index.ts +2 -18
- package/corpus/templates/design/actions/get-design.ts +2 -1
- package/corpus/templates/design/actions/grant-localhost-write-consent.ts +7 -1
- package/corpus/templates/design/actions/import-design-tokens.ts +114 -76
- package/corpus/templates/design/actions/index-components.ts +2 -18
- package/corpus/templates/design/actions/list-design-source-capabilities.ts +23 -28
- package/corpus/templates/design/actions/list-local-files.ts +9 -2
- package/corpus/templates/design/actions/migrate-board-objects-to-file.ts +82 -98
- package/corpus/templates/design/actions/open-component-source.ts +2 -18
- package/corpus/templates/design/actions/open-visual-edit.ts +19 -1
- package/corpus/templates/design/actions/present-design-variants.ts +70 -70
- package/corpus/templates/design/actions/preview-component-prop-edit.ts +4 -14
- package/corpus/templates/design/actions/read-local-file.ts +9 -2
- package/corpus/templates/design/actions/remove-breakpoint.ts +40 -61
- package/corpus/templates/design/actions/rename-screen.ts +425 -0
- package/corpus/templates/design/actions/request-localhost-write-consent.ts +12 -2
- package/corpus/templates/design/actions/revoke-localhost-write-consent.ts +9 -2
- package/corpus/templates/design/actions/sync-fusion-app.ts +56 -39
- package/corpus/templates/design/actions/update-design.ts +376 -61
- package/corpus/templates/design/actions/update-file.ts +455 -188
- package/corpus/templates/design/actions/write-local-file.ts +10 -2
- package/corpus/templates/design/app/components/design/DesignCanvas.tsx +685 -608
- package/corpus/templates/design/app/components/design/LayersPanel.tsx +43 -15
- package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +576 -2015
- package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +62 -14
- package/corpus/templates/design/app/components/design/bridge/embedded-wheel.bridge.ts +263 -25
- package/corpus/templates/design/app/components/design/design-canvas/annotation-submit.ts +34 -0
- package/corpus/templates/design/app/components/design/design-canvas/coordinate-transforms.ts +40 -0
- package/corpus/templates/design/app/components/design/design-canvas/creation.ts +47 -0
- package/corpus/templates/design/app/components/design/design-canvas/element-payload.ts +27 -0
- package/corpus/templates/design/app/components/design/design-canvas/embedded-frame.ts +62 -0
- package/corpus/templates/design/app/components/design/design-canvas/external-preview.ts +137 -0
- package/corpus/templates/design/app/components/design/design-canvas/file-drop.ts +10 -0
- package/corpus/templates/design/app/components/design/design-canvas/hit-test.ts +23 -0
- package/corpus/templates/design/app/components/design/design-canvas/iframe-events.ts +23 -0
- package/corpus/templates/design/app/components/design/design-canvas/iframe-pan.ts +177 -0
- package/corpus/templates/design/app/components/design/design-canvas/motion-types.ts +7 -0
- package/corpus/templates/design/app/components/design/design-canvas/pending-text-edit.ts +62 -0
- package/corpus/templates/design/app/components/design/index.ts +2 -2
- package/corpus/templates/design/app/components/design/multi-screen/canvas-tools.ts +100 -0
- package/corpus/templates/design/app/components/design/multi-screen/coordinate-transforms.ts +81 -0
- package/corpus/templates/design/app/components/design/multi-screen/cross-screen-drop.ts +23 -13
- package/corpus/templates/design/app/components/design/multi-screen/culling.ts +238 -19
- package/corpus/templates/design/app/components/design/multi-screen/draft-primitives.ts +424 -0
- package/corpus/templates/design/app/components/design/multi-screen/frame-geometry.ts +341 -0
- package/corpus/templates/design/app/components/design/multi-screen/iframe-targeting.ts +52 -0
- package/corpus/templates/design/app/components/design/multi-screen/overview-layout.ts +62 -0
- package/corpus/templates/design/app/components/design/multi-screen/primitive-drop-target.ts +283 -0
- package/corpus/templates/design/app/components/design/multi-screen/screen-content-cache.ts +272 -0
- package/corpus/templates/design/app/components/design/multi-screen/types.ts +5 -1
- package/corpus/templates/design/app/components/design/multi-screen/wheel-gesture-state.ts +12 -0
- package/corpus/templates/design/app/components/visual-editor/DrawOverlay.tsx +325 -84
- package/corpus/templates/design/app/hooks/use-navigation-state.ts +15 -1
- package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +119 -47
- package/corpus/templates/design/app/i18n/zh-TW.ts +9 -0
- package/corpus/templates/design/app/i18n-data.ts +223 -0
- package/corpus/templates/design/app/lib/design-save-outbox.ts +379 -0
- package/corpus/templates/design/app/lib/png-clipboard.ts +113 -0
- package/corpus/templates/design/app/pages/design-editor/canvas-primitives.ts +229 -0
- package/corpus/templates/design/app/pages/design-editor/code-layer-state.ts +918 -0
- package/corpus/templates/design/app/pages/design-editor/collab-sync.ts +43 -0
- package/corpus/templates/design/app/pages/design-editor/cross-screen-text-color.ts +336 -0
- package/corpus/templates/design/app/pages/design-editor/data-operations.ts +270 -0
- package/corpus/templates/design/app/pages/design-editor/dom-guards.ts +24 -0
- package/corpus/templates/design/app/pages/design-editor/dom-utils.ts +11 -0
- package/corpus/templates/design/app/pages/design-editor/editor-session.ts +20 -0
- package/corpus/templates/design/app/pages/design-editor/editor-state.ts +408 -0
- package/corpus/templates/design/app/pages/design-editor/export-capture.ts +115 -0
- package/corpus/templates/design/app/pages/design-editor/geometry-persistence.ts +93 -0
- package/corpus/templates/design/app/pages/design-editor/history.ts +169 -0
- package/corpus/templates/design/app/pages/design-editor/layout-operations.ts +185 -0
- package/corpus/templates/design/app/pages/design-editor/motion-state.ts +309 -0
- package/corpus/templates/design/app/pages/design-editor/overview-camera.ts +438 -0
- package/corpus/templates/design/app/pages/design-editor/pending-edits.ts +510 -0
- package/corpus/templates/design/app/pages/design-editor/portable-style.ts +115 -0
- package/corpus/templates/design/app/pages/design-editor/selection-state.ts +337 -0
- package/corpus/templates/design/app/pages/design-editor/style-utils.ts +5 -0
- package/corpus/templates/design/app/pages/design-editor/tool-state.ts +92 -0
- package/corpus/templates/design/app/pages/design-editor/tweak-save.ts +87 -0
- package/corpus/templates/design/app/pages/design-editor/types.ts +36 -0
- package/corpus/templates/design/app/routes/design.$id.tsx +11 -1
- package/corpus/templates/design/changelog/2026-07-09-design-edits-canvas-positions-tools-and-tab-context-now-pers.md +6 -0
- package/corpus/templates/design/changelog/2026-07-09-figma-style-shortcuts-drawing-annotations-and-cross-screen-d.md +6 -0
- package/corpus/templates/design/changelog/2026-07-09-hand-and-scale-tools-now-keep-their-active-toolbar-identity-.md +6 -0
- package/corpus/templates/design/changelog/2026-07-09-large-multi-screen-designs-now-stay-responsive-during-long-c.md +6 -0
- package/corpus/templates/design/changelog/2026-07-09-layer-drags-now-land-exactly-where-the-insertion-indicator-s.md +6 -0
- package/corpus/templates/design/server/db/index.ts +2 -52
- package/corpus/templates/design/server/db/schema.ts +16 -0
- package/corpus/templates/design/server/lib/design-data-access.ts +70 -0
- package/corpus/templates/design/server/lib/design-data-mutation.ts +249 -0
- package/corpus/templates/design/server/lib/fusion-screens.ts +89 -76
- package/corpus/templates/design/server/lib/import-design-files.ts +76 -35
- package/corpus/templates/design/server/lib/verify-write-grant.ts +7 -2
- package/corpus/templates/design/server/plugins/db.ts +19 -0
- package/corpus/templates/design/server/source-workspace.ts +12 -13
- package/corpus/templates/design/shared/resolve-tweaks.ts +15 -0
- package/corpus/templates/design/shared/screen-rename.ts +42 -0
- package/corpus/templates/design/shared/source-mode.ts +84 -4
- package/dist/agent/engine/builder-engine.d.ts +1 -1
- package/dist/agent/engine/builder-engine.d.ts.map +1 -1
- package/dist/agent/engine/builtin.js +1 -1
- package/dist/agent/engine/builtin.js.map +1 -1
- package/dist/agent/model-config.d.ts +9 -9
- package/dist/agent/model-config.d.ts.map +1 -1
- package/dist/agent/model-config.js +30 -30
- package/dist/agent/model-config.js.map +1 -1
- package/dist/agent/production-agent.d.ts +60 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +106 -7
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/cli/design-connect.d.ts +30 -1
- package/dist/cli/design-connect.d.ts.map +1 -1
- package/dist/cli/design-connect.js +359 -75
- package/dist/cli/design-connect.js.map +1 -1
- package/dist/cli/recap.js +2 -2
- package/dist/cli/recap.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +6 -1
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +10 -5
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/composer/TiptapComposer.js +1 -1
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/org/TeamPage.d.ts.map +1 -1
- package/dist/client/org/TeamPage.js +6 -5
- package/dist/client/org/TeamPage.js.map +1 -1
- package/dist/client/use-action.d.ts +32 -0
- package/dist/client/use-action.d.ts.map +1 -1
- package/dist/client/use-action.js +68 -1
- package/dist/client/use-action.js.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/db/client.d.ts +3 -0
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +7 -2
- package/dist/db/client.js.map +1 -1
- package/dist/db/create-get-db.d.ts.map +1 -1
- package/dist/db/create-get-db.js +2 -2
- package/dist/db/create-get-db.js.map +1 -1
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/resources/handlers.d.ts +2 -2
- package/dist/scripts/agent-engines/manage-agent-engine.js +1 -1
- package/dist/scripts/agent-engines/manage-agent-engine.js.map +1 -1
- package/dist/scripts/agent-engines/set-agent-engine.js +1 -1
- package/dist/scripts/agent-engines/set-agent-engine.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/transcribe-voice.js +1 -1
- package/dist/server/transcribe-voice.js.map +1 -1
- package/dist/usage/store.d.ts.map +1 -1
- package/dist/usage/store.js +13 -4
- package/dist/usage/store.js.map +1 -1
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +36 -1
- package/dist/vite/client.js.map +1 -1
- package/docs/content/a2a-protocol.mdx +12 -0
- package/docs/content/locales/ar-SA/a2a-protocol.mdx +12 -0
- package/docs/content/locales/ar-SA/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/ar-SA/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/de-DE/a2a-protocol.mdx +12 -0
- package/docs/content/locales/de-DE/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/de-DE/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/es-ES/a2a-protocol.mdx +12 -0
- package/docs/content/locales/es-ES/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/es-ES/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/fr-FR/a2a-protocol.mdx +12 -0
- package/docs/content/locales/fr-FR/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/fr-FR/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/hi-IN/a2a-protocol.mdx +12 -0
- package/docs/content/locales/hi-IN/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/hi-IN/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/ja-JP/a2a-protocol.mdx +12 -0
- package/docs/content/locales/ja-JP/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/ja-JP/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/ko-KR/a2a-protocol.mdx +12 -0
- package/docs/content/locales/ko-KR/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/ko-KR/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/pt-BR/a2a-protocol.mdx +12 -0
- package/docs/content/locales/pt-BR/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/pt-BR/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/zh-CN/a2a-protocol.mdx +12 -0
- package/docs/content/locales/zh-CN/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/zh-CN/pure-agent-apps.mdx +4 -0
- package/docs/content/locales/zh-TW/a2a-protocol.mdx +12 -0
- package/docs/content/locales/zh-TW/pr-visual-recap.mdx +3 -3
- package/docs/content/locales/zh-TW/pure-agent-apps.mdx +4 -0
- package/docs/content/pr-visual-recap.mdx +3 -3
- package/docs/content/pure-agent-apps.mdx +22 -0
- package/package.json +2 -2
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { getDraftGeometryFromPoints } from "@shared/canvas-math";
|
|
2
|
+
import {
|
|
3
|
+
clonePenPath,
|
|
4
|
+
closePenPath,
|
|
5
|
+
constrainPointTo45Degrees,
|
|
6
|
+
getPenPathGeometry,
|
|
7
|
+
scalePenPathToGeometry,
|
|
8
|
+
serializePenPath,
|
|
9
|
+
translatePenPath,
|
|
10
|
+
type PenPath,
|
|
11
|
+
} from "@shared/pen-path";
|
|
12
|
+
|
|
13
|
+
import { DEFAULT_LINE_STROKE_WIDTH_PX } from "../canvas-primitive-style";
|
|
14
|
+
import { boardPointToScreenLocalPoint } from "./coordinate-transforms";
|
|
15
|
+
import { getFrameCenter } from "./frame-geometry";
|
|
16
|
+
import type {
|
|
17
|
+
CanvasPrimitiveInsert,
|
|
18
|
+
DraftCreationPreview,
|
|
19
|
+
DraftCreationTool,
|
|
20
|
+
DraftGeometryModifiers,
|
|
21
|
+
DraftPrimitive,
|
|
22
|
+
DraftPrimitiveInput,
|
|
23
|
+
FrameGeometry,
|
|
24
|
+
Point,
|
|
25
|
+
ResolvedScreenMetadata,
|
|
26
|
+
} from "./types";
|
|
27
|
+
|
|
28
|
+
const DRAFT_FRAME_WIDTH = 320;
|
|
29
|
+
const DRAFT_FRAME_HEIGHT = 640;
|
|
30
|
+
const DRAFT_RECT_WIDTH = 100;
|
|
31
|
+
const DRAFT_RECT_HEIGHT = 100;
|
|
32
|
+
const DRAFT_TEXT_WIDTH = 180;
|
|
33
|
+
const DRAFT_TEXT_HEIGHT = 48;
|
|
34
|
+
export const DRAFT_LINE_WIDTH = 160;
|
|
35
|
+
const DRAFT_PATH_MIN_SIZE = 12;
|
|
36
|
+
|
|
37
|
+
export function isDraftPrimitive(
|
|
38
|
+
value: DraftPrimitive | undefined,
|
|
39
|
+
): value is DraftPrimitive {
|
|
40
|
+
return Boolean(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getDraftPreviewGeometryForTool(
|
|
44
|
+
tool: DraftCreationTool,
|
|
45
|
+
start: Point,
|
|
46
|
+
end: Point,
|
|
47
|
+
hasMoved: boolean,
|
|
48
|
+
modifiers?: DraftGeometryModifiers,
|
|
49
|
+
): FrameGeometry {
|
|
50
|
+
if (tool === "line" || tool === "arrow") {
|
|
51
|
+
return getDraftGeometryForTool(tool, start, end, modifiers);
|
|
52
|
+
}
|
|
53
|
+
if (!hasMoved) {
|
|
54
|
+
return { x: start.x, y: start.y, width: 0, height: 0 };
|
|
55
|
+
}
|
|
56
|
+
return getDraftGeometryForTool(tool, start, end, modifiers);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function getDraftGeometryForTool(
|
|
60
|
+
tool: DraftCreationTool,
|
|
61
|
+
start: Point,
|
|
62
|
+
end: Point,
|
|
63
|
+
modifiers?: DraftGeometryModifiers,
|
|
64
|
+
): FrameGeometry {
|
|
65
|
+
if (tool === "line" || tool === "arrow") {
|
|
66
|
+
const effectiveEnd = modifiers?.shiftKey
|
|
67
|
+
? constrainPointTo45Degrees(start, end)
|
|
68
|
+
: end;
|
|
69
|
+
return getPathGeometry([start, effectiveEnd]);
|
|
70
|
+
}
|
|
71
|
+
const options =
|
|
72
|
+
tool === "frame"
|
|
73
|
+
? {
|
|
74
|
+
minWidth: 24,
|
|
75
|
+
minHeight: 24,
|
|
76
|
+
defaultWidth: DRAFT_FRAME_WIDTH,
|
|
77
|
+
defaultHeight: DRAFT_FRAME_HEIGHT,
|
|
78
|
+
}
|
|
79
|
+
: tool === "text"
|
|
80
|
+
? {
|
|
81
|
+
minWidth: 24,
|
|
82
|
+
minHeight: 18,
|
|
83
|
+
defaultWidth: DRAFT_TEXT_WIDTH,
|
|
84
|
+
defaultHeight: DRAFT_TEXT_HEIGHT,
|
|
85
|
+
}
|
|
86
|
+
: {
|
|
87
|
+
minWidth: 8,
|
|
88
|
+
minHeight: 8,
|
|
89
|
+
defaultWidth: DRAFT_RECT_WIDTH,
|
|
90
|
+
defaultHeight: DRAFT_RECT_HEIGHT,
|
|
91
|
+
};
|
|
92
|
+
return getDraftGeometryFromPoints(start, end, {
|
|
93
|
+
...options,
|
|
94
|
+
square: modifiers?.shiftKey,
|
|
95
|
+
fromCenter: modifiers?.altKey,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function getPathGeometry(points: readonly Point[]): FrameGeometry {
|
|
100
|
+
if (points.length === 0) {
|
|
101
|
+
return {
|
|
102
|
+
x: 0,
|
|
103
|
+
y: 0,
|
|
104
|
+
width: DRAFT_PATH_MIN_SIZE,
|
|
105
|
+
height: DRAFT_PATH_MIN_SIZE,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const xs = points.map((point) => point.x);
|
|
109
|
+
const ys = points.map((point) => point.y);
|
|
110
|
+
const left = Math.min(...xs);
|
|
111
|
+
const top = Math.min(...ys);
|
|
112
|
+
const right = Math.max(...xs);
|
|
113
|
+
const bottom = Math.max(...ys);
|
|
114
|
+
return {
|
|
115
|
+
x: left,
|
|
116
|
+
y: top,
|
|
117
|
+
width: Math.max(DRAFT_PATH_MIN_SIZE, right - left),
|
|
118
|
+
height: Math.max(DRAFT_PATH_MIN_SIZE, bottom - top),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function createDraftPrimitive({
|
|
123
|
+
tool,
|
|
124
|
+
start,
|
|
125
|
+
end,
|
|
126
|
+
moved,
|
|
127
|
+
toolProps,
|
|
128
|
+
modifiers,
|
|
129
|
+
}: DraftPrimitiveInput): DraftPrimitive {
|
|
130
|
+
const id = createDraftId(tool);
|
|
131
|
+
const geometry = moved
|
|
132
|
+
? getDraftGeometryForTool(tool, start, end, modifiers)
|
|
133
|
+
: getDraftGeometryForTool(tool, start, start, modifiers);
|
|
134
|
+
if (tool === "text") {
|
|
135
|
+
return {
|
|
136
|
+
id,
|
|
137
|
+
kind: "text",
|
|
138
|
+
geometry,
|
|
139
|
+
text: toolProps?.text ?? "",
|
|
140
|
+
fill: toolProps?.fill,
|
|
141
|
+
stroke: toolProps?.stroke,
|
|
142
|
+
autoSize: !moved,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (tool === "line" || tool === "arrow") {
|
|
146
|
+
const effectiveEnd = modifiers?.shiftKey
|
|
147
|
+
? constrainPointTo45Degrees(start, end)
|
|
148
|
+
: end;
|
|
149
|
+
const pathPoints = moved
|
|
150
|
+
? [start, effectiveEnd]
|
|
151
|
+
: [start, { x: start.x + DRAFT_LINE_WIDTH, y: start.y }];
|
|
152
|
+
return {
|
|
153
|
+
id,
|
|
154
|
+
kind: tool,
|
|
155
|
+
geometry: getPathGeometry(pathPoints),
|
|
156
|
+
points: pathPoints,
|
|
157
|
+
stroke: toolProps?.stroke,
|
|
158
|
+
strokeWidth: toolProps?.strokeWidth ?? DEFAULT_LINE_STROKE_WIDTH_PX,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
id,
|
|
163
|
+
kind:
|
|
164
|
+
tool === "frame"
|
|
165
|
+
? "frame"
|
|
166
|
+
: tool === "ellipse" || tool === "polygon" || tool === "star"
|
|
167
|
+
? tool
|
|
168
|
+
: "rectangle",
|
|
169
|
+
geometry,
|
|
170
|
+
fill: toolProps?.fill,
|
|
171
|
+
stroke: toolProps?.stroke,
|
|
172
|
+
strokeWidth: toolProps?.strokeWidth,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function shapeClosingHandles(
|
|
177
|
+
pathBefore: PenPath,
|
|
178
|
+
dragPoint: Point | null,
|
|
179
|
+
): PenPath {
|
|
180
|
+
const closed = closePenPath(pathBefore);
|
|
181
|
+
if (!dragPoint || closed.nodes.length === 0) return closed;
|
|
182
|
+
const first = closed.nodes[0];
|
|
183
|
+
const handleIn = {
|
|
184
|
+
x: first.point.x - (dragPoint.x - first.point.x),
|
|
185
|
+
y: first.point.y - (dragPoint.y - first.point.y),
|
|
186
|
+
};
|
|
187
|
+
const nodes = closed.nodes.slice();
|
|
188
|
+
nodes[0] = { ...first, handleIn };
|
|
189
|
+
return { nodes, closed: true };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function createPenDraftPrimitive(
|
|
193
|
+
path: PenPath,
|
|
194
|
+
{
|
|
195
|
+
id = createDraftId("pen"),
|
|
196
|
+
stroke,
|
|
197
|
+
strokeWidth,
|
|
198
|
+
}: { id?: string; stroke?: string; strokeWidth?: number } = {},
|
|
199
|
+
): DraftPrimitive {
|
|
200
|
+
const penPath = clonePenPath(path);
|
|
201
|
+
return {
|
|
202
|
+
id,
|
|
203
|
+
kind: "path",
|
|
204
|
+
geometry: getPenPathGeometry(penPath),
|
|
205
|
+
penPath,
|
|
206
|
+
pathData: serializePenPath(penPath),
|
|
207
|
+
stroke,
|
|
208
|
+
strokeWidth: strokeWidth ?? DEFAULT_LINE_STROKE_WIDTH_PX,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function createDraftId(tool: DraftCreationTool) {
|
|
213
|
+
return `draft-${tool}-${Date.now()}-${Math.random()
|
|
214
|
+
.toString(36)
|
|
215
|
+
.slice(2, 8)}`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function cloneDraftPrimitive(draft: DraftPrimitive): DraftPrimitive {
|
|
219
|
+
return {
|
|
220
|
+
...draft,
|
|
221
|
+
geometry: { ...draft.geometry },
|
|
222
|
+
points: draft.points?.map((point) => ({ ...point })),
|
|
223
|
+
penPath: draft.penPath ? clonePenPath(draft.penPath) : undefined,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function draftPrimitiveToInsert(
|
|
228
|
+
draft: DraftPrimitive,
|
|
229
|
+
frameGeometry: FrameGeometry,
|
|
230
|
+
metadata?: ResolvedScreenMetadata,
|
|
231
|
+
): CanvasPrimitiveInsert {
|
|
232
|
+
const viewport = {
|
|
233
|
+
width: metadata?.width ?? frameGeometry.width,
|
|
234
|
+
height: metadata?.height ?? frameGeometry.height,
|
|
235
|
+
};
|
|
236
|
+
const scaleX = viewport.width / Math.max(1, frameGeometry.width);
|
|
237
|
+
const scaleY = viewport.height / Math.max(1, frameGeometry.height);
|
|
238
|
+
const roundLocal = (value: number) => Math.round(value) || 0;
|
|
239
|
+
const toLocalPointRaw = (point: Point) =>
|
|
240
|
+
boardPointToScreenLocalPoint(point, frameGeometry, viewport);
|
|
241
|
+
const toLocalPoint = (point: Point) => {
|
|
242
|
+
const local = toLocalPointRaw(point);
|
|
243
|
+
return { x: roundLocal(local.x), y: roundLocal(local.y) };
|
|
244
|
+
};
|
|
245
|
+
const scaledPenPath = draft.penPath
|
|
246
|
+
? {
|
|
247
|
+
...draft.penPath,
|
|
248
|
+
nodes: draft.penPath.nodes.map((node) => ({
|
|
249
|
+
point: toLocalPoint(node.point),
|
|
250
|
+
handleIn: node.handleIn ? toLocalPoint(node.handleIn) : undefined,
|
|
251
|
+
handleOut: node.handleOut ? toLocalPoint(node.handleOut) : undefined,
|
|
252
|
+
})),
|
|
253
|
+
}
|
|
254
|
+
: undefined;
|
|
255
|
+
const draftCenterLocal = toLocalPointRaw(getFrameCenter(draft.geometry));
|
|
256
|
+
const localWidth = Math.max(1, Math.round(draft.geometry.width * scaleX));
|
|
257
|
+
const localHeight = Math.max(1, Math.round(draft.geometry.height * scaleY));
|
|
258
|
+
const localRotation =
|
|
259
|
+
(draft.geometry.rotation ?? 0) - (frameGeometry.rotation ?? 0);
|
|
260
|
+
const localGeometry = scaledPenPath
|
|
261
|
+
? getPenPathGeometry(scaledPenPath)
|
|
262
|
+
: {
|
|
263
|
+
...draft.geometry,
|
|
264
|
+
x: roundLocal(draftCenterLocal.x - localWidth / 2),
|
|
265
|
+
y: roundLocal(draftCenterLocal.y - localHeight / 2),
|
|
266
|
+
width: localWidth,
|
|
267
|
+
height: localHeight,
|
|
268
|
+
rotation: localRotation || undefined,
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
kind: draft.kind,
|
|
272
|
+
nodeId: draft.id,
|
|
273
|
+
geometry: localGeometry,
|
|
274
|
+
points: draft.points?.map(toLocalPoint),
|
|
275
|
+
pathData: scaledPenPath ? serializePenPath(scaledPenPath) : undefined,
|
|
276
|
+
text: draft.text,
|
|
277
|
+
fill: draft.fill,
|
|
278
|
+
stroke: draft.stroke,
|
|
279
|
+
strokeWidth: draft.strokeWidth,
|
|
280
|
+
autoSize: draft.autoSize,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function moveDraftPrimitive(
|
|
285
|
+
draft: DraftPrimitive,
|
|
286
|
+
dx: number,
|
|
287
|
+
dy: number,
|
|
288
|
+
): DraftPrimitive {
|
|
289
|
+
const movedPenPath = draft.penPath
|
|
290
|
+
? translatePenPath(draft.penPath, dx, dy)
|
|
291
|
+
: undefined;
|
|
292
|
+
return {
|
|
293
|
+
...draft,
|
|
294
|
+
geometry: {
|
|
295
|
+
...draft.geometry,
|
|
296
|
+
x: draft.geometry.x + dx,
|
|
297
|
+
y: draft.geometry.y + dy,
|
|
298
|
+
},
|
|
299
|
+
points: draft.points?.map((point) => ({
|
|
300
|
+
x: point.x + dx,
|
|
301
|
+
y: point.y + dy,
|
|
302
|
+
})),
|
|
303
|
+
penPath: movedPenPath,
|
|
304
|
+
pathData: movedPenPath ? serializePenPath(movedPenPath) : draft.pathData,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function applyDraftGeometry(
|
|
309
|
+
draft: DraftPrimitive,
|
|
310
|
+
geometry: FrameGeometry,
|
|
311
|
+
scaleK?: boolean,
|
|
312
|
+
): DraftPrimitive {
|
|
313
|
+
const origin = draft.geometry;
|
|
314
|
+
const scaleX = geometry.width / Math.max(1, origin.width);
|
|
315
|
+
const scaleY = geometry.height / Math.max(1, origin.height);
|
|
316
|
+
const scaledPenPath = draft.penPath
|
|
317
|
+
? scalePenPathToGeometry(draft.penPath, origin, geometry)
|
|
318
|
+
: undefined;
|
|
319
|
+
const scaledStrokeWidth =
|
|
320
|
+
scaleK && draft.strokeWidth !== undefined
|
|
321
|
+
? Math.max(
|
|
322
|
+
0,
|
|
323
|
+
Math.round(draft.strokeWidth * Math.max(scaleX, scaleY) * 100) / 100,
|
|
324
|
+
)
|
|
325
|
+
: draft.strokeWidth;
|
|
326
|
+
return {
|
|
327
|
+
...draft,
|
|
328
|
+
geometry,
|
|
329
|
+
points: draft.points?.map((point) => ({
|
|
330
|
+
x: geometry.x + (point.x - origin.x) * scaleX,
|
|
331
|
+
y: geometry.y + (point.y - origin.y) * scaleY,
|
|
332
|
+
})),
|
|
333
|
+
penPath: scaledPenPath,
|
|
334
|
+
pathData: scaledPenPath ? serializePenPath(scaledPenPath) : draft.pathData,
|
|
335
|
+
strokeWidth: scaledStrokeWidth,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function polygonPointsForBox(
|
|
340
|
+
kind: "polygon" | "star",
|
|
341
|
+
width: number,
|
|
342
|
+
height: number,
|
|
343
|
+
) {
|
|
344
|
+
const safeWidth = Math.max(1, width);
|
|
345
|
+
const safeHeight = Math.max(1, height);
|
|
346
|
+
const cx = safeWidth / 2;
|
|
347
|
+
const cy = safeHeight / 2;
|
|
348
|
+
const radius = Math.max(1, Math.min(safeWidth, safeHeight) / 2);
|
|
349
|
+
const points: Point[] = [];
|
|
350
|
+
|
|
351
|
+
if (kind === "polygon") {
|
|
352
|
+
for (let index = 0; index < 3; index += 1) {
|
|
353
|
+
const angle = -Math.PI / 2 + (index * Math.PI * 2) / 3;
|
|
354
|
+
points.push({
|
|
355
|
+
x: cx + Math.cos(angle) * radius,
|
|
356
|
+
y: cy + Math.sin(angle) * radius,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
for (let index = 0; index < 10; index += 1) {
|
|
361
|
+
const angle = -Math.PI / 2 + (index * Math.PI) / 5;
|
|
362
|
+
const pointRadius = index % 2 === 0 ? radius : radius * 0.45;
|
|
363
|
+
points.push({
|
|
364
|
+
x: cx + Math.cos(angle) * pointRadius,
|
|
365
|
+
y: cy + Math.sin(angle) * pointRadius,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return points
|
|
371
|
+
.map((point) => `${roundCoord(point.x)},${roundCoord(point.y)}`)
|
|
372
|
+
.join(" ");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function pointsToPath(points: readonly Point[]) {
|
|
376
|
+
if (points.length === 0) return "";
|
|
377
|
+
const [first, ...rest] = points;
|
|
378
|
+
return [
|
|
379
|
+
`M ${roundCoord(first.x)} ${roundCoord(first.y)}`,
|
|
380
|
+
...rest.map((point) => `L ${roundCoord(point.x)} ${roundCoord(point.y)}`),
|
|
381
|
+
].join(" ");
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function roundCoord(value: number) {
|
|
385
|
+
return Math.round(value * 10) / 10;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export function previewDraftPrimitive(
|
|
389
|
+
preview: DraftCreationPreview,
|
|
390
|
+
): DraftPrimitive {
|
|
391
|
+
return {
|
|
392
|
+
id: "draft-preview",
|
|
393
|
+
kind:
|
|
394
|
+
preview.tool === "pen"
|
|
395
|
+
? "path"
|
|
396
|
+
: preview.tool === "frame"
|
|
397
|
+
? "frame"
|
|
398
|
+
: preview.tool === "text"
|
|
399
|
+
? "text"
|
|
400
|
+
: preview.tool === "line" ||
|
|
401
|
+
preview.tool === "arrow" ||
|
|
402
|
+
preview.tool === "ellipse" ||
|
|
403
|
+
preview.tool === "polygon" ||
|
|
404
|
+
preview.tool === "star"
|
|
405
|
+
? preview.tool
|
|
406
|
+
: "rectangle",
|
|
407
|
+
geometry: preview.geometry,
|
|
408
|
+
points:
|
|
409
|
+
preview.points ??
|
|
410
|
+
(preview.tool === "line" || preview.tool === "arrow"
|
|
411
|
+
? [
|
|
412
|
+
{
|
|
413
|
+
x: preview.geometry.x,
|
|
414
|
+
y: preview.geometry.y + preview.geometry.height / 2,
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
x: preview.geometry.x + preview.geometry.width,
|
|
418
|
+
y: preview.geometry.y + preview.geometry.height / 2,
|
|
419
|
+
},
|
|
420
|
+
]
|
|
421
|
+
: undefined),
|
|
422
|
+
text: "Text", // i18n-ignore preview-only canvas placeholder
|
|
423
|
+
};
|
|
424
|
+
}
|