@drawmotive/editor-ui 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controls.d.ts +2 -1
- package/dist/groups.d.ts +26 -0
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/panels.d.ts +9 -1
- package/dist/ui-controller.js +1 -1
- package/dist/ui-model.d.ts +1 -1
- package/dist/ui-options.d.ts +1 -1
- package/dist/use-editor-hotkeys.d.ts +5 -0
- package/package.json +2 -2
package/dist/controls.d.ts
CHANGED
|
@@ -25,12 +25,13 @@ interface ToolButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
25
25
|
shortcut?: string;
|
|
26
26
|
}
|
|
27
27
|
export declare const ToolButton: import("react").ForwardRefExoticComponent<ToolButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
28
|
-
export declare function PanelButton({ id, button, children, label, nested }: {
|
|
28
|
+
export declare function PanelButton({ id, button, children, label, nested, position }: {
|
|
29
29
|
id: string;
|
|
30
30
|
button: ReactElement<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
31
31
|
children: ReactNode;
|
|
32
32
|
label?: string;
|
|
33
33
|
nested?: boolean;
|
|
34
|
+
position?: "top-start" | "bottom-start";
|
|
34
35
|
}): import("react").JSX.Element;
|
|
35
36
|
export declare const Separator: () => import("react").JSX.Element;
|
|
36
37
|
export declare const PanelHeading: ({ children }: {
|
package/dist/groups.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { EditorInstance, EditorSelectionSnapshot } from '@drawmotive/editor';
|
|
3
|
+
interface GroupControlOptions {
|
|
4
|
+
editor: EditorInstance;
|
|
5
|
+
container: HTMLElement;
|
|
6
|
+
overlay: RefObject<HTMLDivElement | null>;
|
|
7
|
+
selection: EditorSelectionSnapshot | null;
|
|
8
|
+
revision: string | null;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
busy: boolean;
|
|
11
|
+
setPanel(value: string | null): void;
|
|
12
|
+
run(action: () => Promise<unknown>, key?: string): Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
/** Group workflow state belongs to this editor session and retires before another session can acquire the canvas. */
|
|
15
|
+
export declare function useGroupControls({ editor, container, overlay, selection, revision, enabled, busy, setPanel, run }: GroupControlOptions): {
|
|
16
|
+
supported: boolean;
|
|
17
|
+
available: boolean;
|
|
18
|
+
primary: number;
|
|
19
|
+
menu: import("react").JSX.Element | null;
|
|
20
|
+
chrome: import("react").JSX.Element;
|
|
21
|
+
create: () => Promise<void>;
|
|
22
|
+
ungroup: () => Promise<void>;
|
|
23
|
+
rename: (id: string) => Promise<void>;
|
|
24
|
+
selectObjects: () => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
package/dist/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import"@mantine/core/styles/UnstyledButton.css";@import"@mantine/core/styles/Popover.css";@import"@mantine/core/styles/Tooltip.css";@import"@mantine/core/styles/Kbd.css";@import"@mantine/core/styles/Input.css";@import"@mantine/core/styles/InlineInput.css";@import"@mantine/core/styles/Checkbox.css";@import"@mantine/core/styles/Button.css";@import"@mantine/core/styles/Divider.css";@import"@mantine/core/styles/Group.css";@import"@mantine/core/styles/Stack.css";.dm-phosphor-loader{display:block;flex-shrink:0;animation:dm-phosphor-spin .8s linear infinite}@keyframes dm-phosphor-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.dm-phosphor-loader{animation:none}}.dm-editor-ui{--dm-surface:var(--mantine-color-body);--dm-header:var(--mantine-color-default-hover);--dm-text:var(--mantine-color-text);--dm-border:var(--mantine-color-default-border);--dm-hover:var(--mantine-color-default-hover);--dm-active:var(--mantine-primary-color-light);--dm-color-foreground:#1b1b1b;--dm-color-background:#fff;--dm-color-primary-stroke:#007aff;--dm-color-primary-fill:#b3d7ff;--dm-color-secondary-stroke:#5a6268;--dm-color-secondary-fill:#d6d8db;--dm-color-accent-stroke:#ff4081;--dm-color-accent-fill:#ffc1dc;--dm-color-success-stroke:#34c759;--dm-color-success-fill:#b8efb3;--dm-color-warning-stroke:#fc0;--dm-color-warning-fill:#fff3bf;position:absolute;inset:0;overflow:hidden;container-type:size;pointer-events:none;z-index:10;font:var(--mantine-font-size-sm)/var(--mantine-line-height) var(--mantine-font-family);color:var(--dm-text);text-align:left}.dm-editor-ui[data-mantine-color-scheme=dark]{--dm-color-foreground:#e6edf3;--dm-color-background:#202632;--dm-color-primary-stroke:#66b0ff;--dm-color-primary-fill:#243f61;--dm-color-secondary-stroke:#aab4c0;--dm-color-secondary-fill:#39424f;--dm-color-accent-stroke:#ff80ab;--dm-color-accent-fill:#583047;--dm-color-success-stroke:#6ddd8a;--dm-color-success-fill:#294c38;--dm-color-warning-stroke:#ffd95e;--dm-color-warning-fill:#51472c}.dm-editor-ui *,.dm-editor-ui *:before,.dm-editor-ui *:after{box-sizing:border-box}.dm-editor-ui .dm-toolbar{margin:0;min-width:0;padding:2px;display:flex;align-items:center;gap:5px;border:1px solid var(--dm-border);border-radius:4px;background:var(--dm-surface);box-shadow:0 2px 6px #0002;pointer-events:auto;color:var(--dm-text)}.dm-editor-ui .dm-corner{position:absolute;max-width:calc(100% - 20px);flex-wrap:wrap}.dm-topLeft{top:10px;left:10px}.dm-topRight{top:10px;right:10px}.dm-bottomLeft{bottom:10px;left:10px}.dm-bottomRight{bottom:10px;right:10px}.dm-editor-ui .dm-drawing{position:absolute;max-height:calc(100% - 90px);max-width:calc(100% - 100px)}.dm-drawing.dm-left{left:10px;top:70px;flex-direction:column}.dm-drawing.dm-right{right:10px;top:70px;flex-direction:column}.dm-drawing.dm-top{top:60px;left:50%;transform:translate(-50%)}.dm-drawing.dm-bottom{bottom:60px;left:50%;transform:translate(-50%)}.dm-editor-ui .dm-context{position:absolute;max-width:calc(100% - 8px);flex-wrap:wrap;z-index:20}.dm-context-entry{display:contents}.dm-separator{height:20px;align-self:center;border-left:1px solid var(--dm-border);margin:0 1px}.dm-editor-ui .dm-tool{border:0;border-radius:4px;background:transparent;color:inherit;min-width:30px;height:30px;padding:4px;display:inline-flex;align-items:center;justify-content:center;gap:6px;cursor:pointer;font:inherit;line-height:1;pointer-events:auto;vertical-align:middle}.dm-editor-ui .dm-tool:hover{background:var(--dm-hover)}.dm-editor-ui .dm-tool[data-selected]{background:var(--dm-active)}.dm-editor-ui .dm-tool:focus-visible{outline:2px solid var(--mantine-primary-color-filled);outline-offset:1px}.dm-editor-ui .dm-tool:disabled{opacity:.42;cursor:default}.dm-editor-ui .dm-zoom{min-width:46px;font-size:12px;font-weight:600}.dm-editor-ui .dm-host-action{padding:4px 9px}.dm-editor-ui .dm-panel{pointer-events:auto;z-index:30;padding:5px;border:1px solid var(--dm-border);border-radius:5px;background:var(--dm-surface);color:var(--dm-text);box-shadow:0 3px 12px #0003;max-width:calc(100cqw - 8px)}.dm-panel-heading{padding:2px 4px;margin:-1px -1px 2px;background:var(--dm-header);font-size:11px;text-transform:uppercase;letter-spacing:.04em}.dm-panel-stack.dm-drawing-properties{min-width:0;max-width:100%;padding:0;gap:8px}.dm-property-description{margin:0;color:var(--dm-text);font-size:12px;line-height:1.45;opacity:.8}.dm-drawing-property{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.4fr);column-gap:12px;align-items:center}.dm-drawing-property-label{margin:0}.dm-drawing-property-input{min-width:0}.dm-settings{width:310px;max-width:100%;max-height:calc(100cqh - 64px);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin}.dm-settings-header{padding:10px 12px}.dm-settings-header h2{margin:0;font-size:16px;font-weight:600;line-height:1.4}.dm-settings-section{display:flex;flex-direction:column;gap:14px;padding:14px 12px;border-top:1px solid var(--dm-border)}.dm-settings-section-heading{display:flex;align-items:center;justify-content:space-between;gap:8px}.dm-settings-section h3{margin:0;flex-shrink:0;font-size:13px;font-weight:600;line-height:1.4}.dm-settings-section-heading p{margin:0;padding:2px 6px;border:1px solid var(--dm-border);border-radius:4px;background:var(--dm-header);color:var(--dm-text);font-size:11px;font-weight:500;line-height:1.4;white-space:nowrap}.dm-panel-row{display:flex;align-items:center;flex-wrap:wrap;gap:5px;padding:2px}.dm-panel-stack{display:flex;flex-direction:column;gap:8px;min-width:165px;max-width:300px;padding:3px}.dm-panel-stack.dm-numbering-panel{width:230px;max-width:calc(100cqw - 26px);min-width:0}.dm-number-prefix{max-width:calc(100% - 6px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--mantine-font-size-xs)}.dm-group-controls,.dm-title-controls{display:flex;align-items:center;gap:5px;flex-wrap:wrap;max-width:100%}.dm-group-controls .mantine-NativeSelect-root{width:140px}.dm-group-controls .mantine-NativeSelect-root:last-child{width:180px}.dm-endpoint-grid{display:grid;grid-template-columns:repeat(3,34px);gap:5px}.dm-editor-ui .dm-menu-item{justify-content:flex-start;width:100%;padding-inline:7px}.dm-editor-ui .dm-button-group{display:inline-flex;border:1px solid var(--dm-border);border-radius:4px;overflow:hidden}.dm-button-group .dm-tool{border-radius:0}.dm-stroke-fill{display:inline-flex;position:relative;width:20px;height:20px}.dm-stroke-fill>svg:last-child{position:absolute;left:0;top:0}.dm-palette>path[opacity]{fill:var(--dm-palette-fill);opacity:1}.dm-slot{display:inline-flex;pointer-events:auto}.dm-help kbd{font:11px ui-monospace,monospace;white-space:nowrap}.dm-help{min-width:230px;padding:5px}.dm-help>div{display:flex;justify-content:space-between;gap:15px;margin-top:8px}.dm-error{position:absolute;bottom:55px;left:10px;right:10px;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 10px;border:1px solid #e76d6d;background:var(--dm-surface);border-radius:5px;pointer-events:auto;z-index:40}.dm-quick-insert-backdrop{position:absolute;inset:0;z-index:35;pointer-events:auto;background:#0002;display:flex;align-items:flex-start;justify-content:center;padding:clamp(8px,8cqw,48px) 8px 8px}.dm-quick-insert{width:430px;max-width:100%;max-height:100%;min-height:0;display:flex;flex-direction:column;padding:5px;border:1px solid var(--dm-border);border-radius:7px;background:var(--dm-surface);box-shadow:0 6px 24px #0003;color:var(--dm-text);font-size:13px}.dm-quick-insert-query{display:flex;align-items:center;gap:6px;min-height:33px;padding:0 4px;flex-shrink:0;border-bottom:1px solid var(--dm-border)}.dm-quick-insert-query>svg{width:15px;height:15px;flex-shrink:0;opacity:.7}.dm-quick-insert kbd{font:10px ui-monospace,monospace;opacity:.8}.dm-quick-insert-search{width:100%;min-width:0;height:29px;border:0;border-radius:2px;padding:2px;background:transparent;color:inherit;font:inherit;outline-offset:0}.dm-quick-insert-search:focus{outline:2px solid var(--mantine-primary-color-filled)}.dm-quick-insert-count{font-size:11px;opacity:.7}.dm-quick-insert-close{display:flex;align-items:center;justify-content:center;flex-shrink:0;width:24px;height:24px;border:0;border-radius:3px;padding:4px;background:transparent;color:inherit;cursor:pointer}.dm-quick-insert-close>svg{width:14px;height:14px}.dm-quick-insert-close:hover{background:var(--dm-hover)}.dm-quick-insert-close:focus-visible{outline:2px solid var(--mantine-primary-color-filled)}.dm-quick-insert-results{overflow:auto;min-height:0;max-height:320px;overscroll-behavior:contain}.dm-quick-insert-group{display:grid;grid-template-columns:64px minmax(0,1fr);gap:4px;padding:4px 2px;border-bottom:1px solid var(--dm-border)}.dm-quick-insert-group:last-child{border-bottom:0}.dm-quick-insert-group[data-ungrouped]{grid-template-columns:minmax(0,1fr)}.dm-quick-insert-group-label{font-size:11px;line-height:1.35;opacity:.75;padding:4px 2px;overflow-wrap:anywhere}.dm-quick-insert-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(70px,100%),1fr));gap:2px;min-width:0}.dm-quick-insert-group[data-ungrouped]>.dm-quick-insert-grid{grid-template-columns:repeat(5,minmax(0,1fr))}.dm-quick-insert-option{min-width:0;min-height:50px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:4px 2px;border:0;border-radius:4px;background:transparent;color:inherit;font:inherit;cursor:pointer}.dm-quick-insert-option>svg,.dm-quick-insert-option>img{width:24px;height:24px;flex-shrink:0;object-fit:contain}.dm-editor-ui[data-mantine-color-scheme=dark] .dm-quick-insert-option>img{background:#f5f6fa;border-radius:3px;padding:2px}.dm-quick-insert-option>span{display:block;width:100%;font-size:11px;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dm-quick-insert-option:hover{background:var(--dm-hover)}.dm-quick-insert-option[aria-selected=true]{background:var(--dm-active)}.dm-quick-insert-option:disabled{opacity:.5;cursor:default}.dm-quick-insert-empty{padding:18px 8px;text-align:center}.dm-quick-insert-hint{display:flex;align-items:center;gap:6px;min-height:24px;flex-shrink:0;padding:3px 4px 0;border-top:1px solid var(--dm-border);font-size:11px;opacity:.8}.dm-quick-insert-detail{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dm-quick-insert-keys{white-space:nowrap}.dm-quick-insert-keys kbd{border:1px solid var(--dm-border);border-radius:3px;padding:0 3px}@media(pointer:coarse){.dm-quick-insert-option{min-height:56px}.dm-quick-insert-query{min-height:42px}.dm-quick-insert-search{height:36px;font-size:16px}}@media(prefers-reduced-motion:reduce){.dm-editor-ui *{animation:none!important;transition:none!important}}
|
|
1
|
+
@import"@mantine/core/styles/UnstyledButton.css";@import"@mantine/core/styles/Popover.css";@import"@mantine/core/styles/Tooltip.css";@import"@mantine/core/styles/Kbd.css";@import"@mantine/core/styles/Input.css";@import"@mantine/core/styles/InlineInput.css";@import"@mantine/core/styles/Checkbox.css";@import"@mantine/core/styles/Button.css";@import"@mantine/core/styles/Divider.css";@import"@mantine/core/styles/Group.css";@import"@mantine/core/styles/Stack.css";.dm-phosphor-loader{display:block;flex-shrink:0;animation:dm-phosphor-spin .8s linear infinite}@keyframes dm-phosphor-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.dm-phosphor-loader{animation:none}}.dm-editor-ui{--dm-surface:var(--mantine-color-body);--dm-header:var(--mantine-color-default-hover);--dm-text:var(--mantine-color-text);--dm-border:var(--mantine-color-default-border);--dm-hover:var(--mantine-color-default-hover);--dm-active:var(--mantine-primary-color-light);--dm-color-foreground:#1b1b1b;--dm-color-background:#fff;--dm-color-primary-stroke:#007aff;--dm-color-primary-fill:#b3d7ff;--dm-color-secondary-stroke:#5a6268;--dm-color-secondary-fill:#d6d8db;--dm-color-accent-stroke:#ff4081;--dm-color-accent-fill:#ffc1dc;--dm-color-success-stroke:#34c759;--dm-color-success-fill:#b8efb3;--dm-color-warning-stroke:#fc0;--dm-color-warning-fill:#fff3bf;position:absolute;inset:0;overflow:hidden;container-type:size;pointer-events:none;z-index:10;font:var(--mantine-font-size-sm)/var(--mantine-line-height) var(--mantine-font-family);color:var(--dm-text);text-align:left}.dm-editor-ui[data-mantine-color-scheme=dark]{--dm-color-foreground:#e6edf3;--dm-color-background:#202632;--dm-color-primary-stroke:#66b0ff;--dm-color-primary-fill:#243f61;--dm-color-secondary-stroke:#aab4c0;--dm-color-secondary-fill:#39424f;--dm-color-accent-stroke:#ff80ab;--dm-color-accent-fill:#583047;--dm-color-success-stroke:#6ddd8a;--dm-color-success-fill:#294c38;--dm-color-warning-stroke:#ffd95e;--dm-color-warning-fill:#51472c}.dm-editor-ui *,.dm-editor-ui *:before,.dm-editor-ui *:after{box-sizing:border-box}.dm-object-drop-layout{position:absolute;top:10px;left:50%;transform:translate(-50%);display:flex;align-items:center;gap:6px;padding:6px 10px;border:1px solid var(--dm-border);border-radius:999px;background:var(--dm-surface);color:var(--dm-text);font-size:13px;white-space:nowrap;box-shadow:0 2px 6px #0002;pointer-events:none}.dm-editor-ui .dm-toolbar{margin:0;min-width:0;padding:2px;display:flex;align-items:center;gap:5px;border:1px solid var(--dm-border);border-radius:4px;background:var(--dm-surface);box-shadow:0 2px 6px #0002;pointer-events:auto;color:var(--dm-text)}.dm-editor-ui .dm-corner{position:absolute;max-width:calc(100% - 20px);flex-wrap:wrap}.dm-topLeft{top:10px;left:10px}.dm-topRight{top:10px;right:10px}.dm-bottomLeft{bottom:10px;left:10px}.dm-bottomRight{bottom:10px;right:10px}.dm-editor-ui .dm-drawing{position:absolute;max-height:calc(100% - 90px);max-width:calc(100% - 100px)}.dm-drawing.dm-left{left:10px;top:70px;flex-direction:column}.dm-drawing.dm-right{right:10px;top:70px;flex-direction:column}.dm-drawing.dm-top{top:60px;left:50%;transform:translate(-50%)}.dm-drawing.dm-bottom{bottom:60px;left:50%;transform:translate(-50%)}.dm-editor-ui .dm-context{position:absolute;max-width:calc(100% - 8px);flex-wrap:wrap;z-index:20}.dm-context-entry{display:contents}.dm-separator{height:20px;align-self:center;border-left:1px solid var(--dm-border);margin:0 1px}.dm-editor-ui .dm-tool{border:0;border-radius:4px;background:transparent;color:inherit;min-width:30px;height:30px;padding:4px;display:inline-flex;align-items:center;justify-content:center;gap:6px;cursor:pointer;font:inherit;line-height:1;pointer-events:auto;vertical-align:middle}.dm-editor-ui .dm-tool:hover{background:var(--dm-hover)}.dm-editor-ui .dm-tool[data-selected]{background:var(--dm-active)}.dm-editor-ui .dm-tool:focus-visible{outline:2px solid var(--mantine-primary-color-filled);outline-offset:1px}.dm-editor-ui .dm-tool:disabled{opacity:.42;cursor:default}.dm-editor-ui .dm-zoom{min-width:46px;font-size:12px;font-weight:600}.dm-editor-ui .dm-host-action{padding:4px 9px}.dm-editor-ui .dm-panel{pointer-events:auto;z-index:30;padding:5px;border:1px solid var(--dm-border);border-radius:5px;background:var(--dm-surface);color:var(--dm-text);box-shadow:0 3px 12px #0003;max-width:calc(100cqw - 8px)}.dm-panel-heading{padding:2px 4px;margin:-1px -1px 2px;background:var(--dm-header);font-size:11px;text-transform:uppercase;letter-spacing:.04em}.dm-panel-stack.dm-drawing-properties{min-width:0;max-width:100%;padding:0;gap:8px}.dm-property-description{margin:0;color:var(--dm-text);font-size:12px;line-height:1.45;opacity:.8}.dm-drawing-property{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.4fr);column-gap:12px;align-items:center}.dm-drawing-property-label{margin:0}.dm-drawing-property-input{min-width:0}.dm-settings{width:310px;max-width:100%;max-height:calc(100cqh - 64px);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin}.dm-settings-header{padding:10px 12px}.dm-settings-header h2{margin:0;font-size:16px;font-weight:600;line-height:1.4}.dm-settings-section{display:flex;flex-direction:column;gap:14px;padding:14px 12px;border-top:1px solid var(--dm-border)}.dm-settings-section-heading{display:flex;align-items:center;justify-content:space-between;gap:8px}.dm-settings-section h3{margin:0;flex-shrink:0;font-size:13px;font-weight:600;line-height:1.4}.dm-settings-section-heading p{margin:0;padding:2px 6px;border:1px solid var(--dm-border);border-radius:4px;background:var(--dm-header);color:var(--dm-text);font-size:11px;font-weight:500;line-height:1.4;white-space:nowrap}.dm-panel-row{display:flex;align-items:center;flex-wrap:wrap;gap:5px;padding:2px}.dm-panel-stack{display:flex;flex-direction:column;gap:8px;min-width:165px;max-width:300px;padding:3px}.dm-panel-stack.dm-numbering-panel{width:230px;max-width:calc(100cqw - 26px);min-width:0}.dm-number-prefix{max-width:calc(100% - 6px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--mantine-font-size-xs)}.dm-group-controls,.dm-title-controls{display:flex;align-items:center;gap:5px;flex-wrap:wrap;max-width:100%}.dm-group-controls .mantine-NativeSelect-root{width:140px}.dm-group-controls .mantine-NativeSelect-root:last-child{width:180px}.dm-endpoint-grid{display:grid;grid-template-columns:repeat(3,34px);gap:5px}.dm-editor-ui .dm-menu-item{justify-content:flex-start;width:100%;padding-inline:7px}.dm-editor-ui .dm-button-group{display:inline-flex;border:1px solid var(--dm-border);border-radius:4px;overflow:hidden}.dm-button-group .dm-tool{border-radius:0}.dm-stroke-fill{display:inline-flex;position:relative;width:20px;height:20px}.dm-stroke-fill>svg:last-child{position:absolute;left:0;top:0}.dm-palette>path[opacity]{fill:var(--dm-palette-fill);opacity:1}.dm-slot{display:inline-flex;pointer-events:auto}.dm-help kbd{font:11px ui-monospace,monospace;white-space:nowrap}.dm-help{min-width:230px;padding:5px}.dm-help>div{display:flex;justify-content:space-between;gap:15px;margin-top:8px}.dm-error{position:absolute;bottom:55px;left:10px;right:10px;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 10px;border:1px solid #e76d6d;background:var(--dm-surface);border-radius:5px;pointer-events:auto;z-index:40}.dm-quick-insert-backdrop{position:absolute;inset:0;z-index:35;pointer-events:auto;background:#0002;display:flex;align-items:flex-start;justify-content:center;padding:clamp(8px,8cqw,48px) 8px 8px}.dm-quick-insert{width:430px;max-width:100%;max-height:100%;min-height:0;display:flex;flex-direction:column;padding:5px;border:1px solid var(--dm-border);border-radius:7px;background:var(--dm-surface);box-shadow:0 6px 24px #0003;color:var(--dm-text);font-size:13px}.dm-quick-insert-query{display:flex;align-items:center;gap:6px;min-height:33px;padding:0 4px;flex-shrink:0;border-bottom:1px solid var(--dm-border)}.dm-quick-insert-query>svg{width:15px;height:15px;flex-shrink:0;opacity:.7}.dm-quick-insert kbd{font:10px ui-monospace,monospace;opacity:.8}.dm-quick-insert-search{width:100%;min-width:0;height:29px;border:0;border-radius:2px;padding:2px;background:transparent;color:inherit;font:inherit;outline-offset:0}.dm-quick-insert-search:focus{outline:2px solid var(--mantine-primary-color-filled)}.dm-quick-insert-count{font-size:11px;opacity:.7}.dm-quick-insert-close{display:flex;align-items:center;justify-content:center;flex-shrink:0;width:24px;height:24px;border:0;border-radius:3px;padding:4px;background:transparent;color:inherit;cursor:pointer}.dm-quick-insert-close>svg{width:14px;height:14px}.dm-quick-insert-close:hover{background:var(--dm-hover)}.dm-quick-insert-close:focus-visible{outline:2px solid var(--mantine-primary-color-filled)}.dm-quick-insert-results{overflow:auto;min-height:0;max-height:320px;overscroll-behavior:contain}.dm-quick-insert-group{display:grid;grid-template-columns:64px minmax(0,1fr);gap:4px;padding:4px 2px;border-bottom:1px solid var(--dm-border)}.dm-quick-insert-group:last-child{border-bottom:0}.dm-quick-insert-group[data-ungrouped]{grid-template-columns:minmax(0,1fr)}.dm-quick-insert-group-label{font-size:11px;line-height:1.35;opacity:.75;padding:4px 2px;overflow-wrap:anywhere}.dm-quick-insert-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(70px,100%),1fr));gap:2px;min-width:0}.dm-quick-insert-group[data-ungrouped]>.dm-quick-insert-grid{grid-template-columns:repeat(5,minmax(0,1fr))}.dm-quick-insert-option{min-width:0;min-height:50px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:4px 2px;border:0;border-radius:4px;background:transparent;color:inherit;font:inherit;cursor:pointer}.dm-quick-insert-option>svg,.dm-quick-insert-option>img{width:24px;height:24px;flex-shrink:0;object-fit:contain}.dm-editor-ui[data-mantine-color-scheme=dark] .dm-quick-insert-option>img{background:#f5f6fa;border-radius:3px;padding:2px}.dm-quick-insert-option>span{display:block;width:100%;font-size:11px;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dm-quick-insert-option:hover{background:var(--dm-hover)}.dm-quick-insert-option[aria-selected=true]{background:var(--dm-active)}.dm-quick-insert-option:disabled{opacity:.5;cursor:default}.dm-quick-insert-empty{padding:18px 8px;text-align:center}.dm-quick-insert-hint{display:flex;align-items:center;gap:6px;min-height:24px;flex-shrink:0;padding:3px 4px 0;border-top:1px solid var(--dm-border);font-size:11px;opacity:.8}.dm-quick-insert-detail{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dm-quick-insert-keys{white-space:nowrap}.dm-quick-insert-keys kbd{border:1px solid var(--dm-border);border-radius:3px;padding:0 3px}@media(pointer:coarse){.dm-quick-insert-option{min-height:56px}.dm-quick-insert-query{min-height:42px}.dm-quick-insert-search{height:36px;font-size:16px}}@media(prefers-reduced-motion:reduce){.dm-editor-ui *{animation:none!important;transition:none!important}}.dm-group-status{z-index:45;max-width:calc(100% - 24px);white-space:normal;text-align:center}.dm-group-status:empty{clip-path:inset(50%);padding:0;border:0}.dm-group-backdrop{position:absolute;inset:0;z-index:36;display:flex;align-items:flex-start;justify-content:center;padding:clamp(12px,8cqw,56px) 10px 10px;pointer-events:auto;background:#0002}.dm-group-dialog{display:flex;flex-direction:column;gap:12px;width:min(440px,100%);max-height:100%;padding:16px;border:1px solid var(--dm-border);border-radius:8px;background:var(--dm-surface);color:var(--dm-text);box-shadow:0 6px 24px #0003}.dm-group-dialog h2{margin:0;font:600 16px/1.3 var(--mantine-font-family)}.dm-group-dialog p{margin:0;overflow-wrap:anywhere}.dm-group-rows{display:grid;min-height:0;overflow:auto;overscroll-behavior:contain}.dm-group-rows label{display:grid;gap:2px;min-height:32px;align-content:center;cursor:pointer;overflow-wrap:anywhere}.dm-group-rows small{color:var(--mantine-color-dimmed)}.dm-group-rows .mantine-Checkbox-body{align-items:center;padding:3px 4px}.dm-group-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap}.dm-group-actions span:first-child{margin-inline-end:auto}.dm-group-destinations{display:grid;gap:2px;min-height:0;overflow:auto;overscroll-behavior:contain}.dm-group-destinations button{justify-self:stretch;text-align:left;overflow:hidden}.dm-group-placement{position:absolute;inset:0;z-index:37;pointer-events:auto;touch-action:none;cursor:crosshair}.dm-group-placement:focus-visible{outline:2px solid var(--mantine-primary-color-filled);outline-offset:-2px}.dm-group-preview{position:absolute;inset:0;z-index:34;pointer-events:none;color:var(--mantine-primary-color-filled)}.dm-group-preview[data-valid=false]{color:var(--mantine-color-orange-7)}.dm-group-preview-target,.dm-group-preview-ghost{position:absolute;border:2px solid currentColor;border-radius:4px}.dm-group-preview-ghost{border-style:dashed;background:color-mix(in srgb,currentColor 12%,transparent)}.dm-group-placement-info{position:absolute;z-index:35;inset:auto 10px 55px;display:flex;align-items:center;justify-content:center;gap:8px;flex-wrap:wrap;width:fit-content;max-width:calc(100% - 20px);margin-inline:auto;padding:8px 10px;border:1px solid var(--dm-border);border-radius:6px;background:var(--dm-surface);cursor:default}@media(pointer:coarse){.dm-group-rows label{min-height:44px}}.dm-editor-ui .dm-more-options{max-height:min(320px,max(80px,calc(50cqh - 48px)));overflow:auto;overscroll-behavior:contain}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{useEffect as xn,useRef as yt,useState as kn}from"react";import{createEditor as wn}from"@drawmotive/editor";import{useCallback as Ve,useEffect as bt,useLayoutEffect as cn,useRef as te,useState as j}from"react";import{MantineProvider as un,MantineThemeProvider as pn,mergeThemeOverrides as mn}from"@mantine/core";var Tn=Object.freeze(["strokeFillColor","strokeColor","strokeStyle","cornerRadius","editText","textSizeSmall","textSizeMedium","textSizeLarge","bold","italic","textAlign","lineStartStyle","lineEndStyle","swapLineEndpoints","lineRouting","groupTheme","groupTitleStyle","numbering","moreOptions"]),Ge=Object.freeze(["strokeFillColor","strokeColor","strokeStyle","textAlign","lineStartStyle","lineEndStyle","lineRouting","groupTitleStyle","numbering","moreOptions"]);function Z(e){let t=e.length===2&&e.find(o=>o.kind==="BoundText"&&e.some(r=>r.id===o.bindingItemId));return t?[t]:e}function _e(e){let t=e.resolved?.numbering;if(!t||typeof t!="object"||Array.isArray(t))return;let{number:o,prefix:r,maximum:n,drawingEnabled:i}=t;if((o===null||Number.isSafeInteger(o)&&o>0)&&typeof r=="string"&&Number.isSafeInteger(n)&&n>=0&&typeof i=="boolean")return t}function Et(e,t){if(e=Z(e),!t.visible||!e.length||e.some(n=>t.objectTypes&&!t.objectTypes.includes(n.kind)))return[];let o=n=>e.every(i=>i.capabilities[n]),r=[];return o("text")?r.push("strokeColor","textSizeSmall","textSizeMedium","textSizeLarge","bold","italic","textAlign"):(o("line")&&r.push("lineStartStyle","swapLineEndpoints","lineEndStyle","lineRouting"),o("group")&&(r.push("groupTheme"),e.length===1&&o("groupTitle")&&r.push("groupTitleStyle")),o("stroke")&&r.push(o("fill")?"strokeFillColor":"strokeColor"),o("stroke")&&r.push("strokeStyle"),o("cornerRadius")&&r.push("cornerRadius")),o("editText")&&e.length===1&&r.push("editText"),e.length===1&&_e(e[0])&&r.push("numbering"),r.push("moreOptions"),r.filter(n=>(!t.tools||t.tools.includes(n))&&(!Ge.includes(n)||!t.panels||t.panels.includes(n)))}function Tt(e,t,o){let r=(n,i,c)=>Math.max(4,Math.min(n,i-c-4));return{left:r(e.left,o.width,t.width),top:r(e.top-t.height-10>=4?e.top-t.height-10:e.bottom+10,o.height,t.height)}}function Ct(e,t,o,r,n){let i=d=>(t.left-r.left+d*t.width/(o.width||1))*(n.width||1)/(r.width||1),c=d=>(t.top-r.top+d*t.height/(o.height||1))*(n.height||1)/(r.height||1);return{left:i(e.left),top:c(e.top),right:i(e.right),bottom:c(e.bottom)}}var It=Object.freeze({state:"Unavailable"}),U=e=>({state:"Uniform",value:e}),zt=["strokeColor","fillColor","strokeWidth","strokeStyle","cornerRadius","textSize","resolvedTextSize","bold","italic","horizontalAlignment","verticalAlignment","lineStartStyle","lineEndStyle","lineRouting","groupColorRole","groupHeaderVisible"],Qe=(e,t,o)=>Object.entries(e.resolved?.themeValues?.[t]??{}).find(([,r])=>r===o)?.[0]??null,Pt=(e,t)=>{let o=Qe(e,"colors",t);return{role:o,argb:o===null?t??null:null}};function de(e,t,o){let r=e.resolved?.themeValues?.[t]?.[o];if(r===void 0)throw new Error("The selection does not provide the requested theme role: "+o);return r}function Rt(e){let t=e.model,o=e.capabilities,r=e.resolved??{},n=t.data?.paintStyle??{},i=t.fontStyle??{},c=r.fontStyle??{},d=Object.fromEntries(zt.map(u=>[u,It]));return d.strokeColor=U(Pt(e,o.text?i.color:n.color)),o.text?(Object.assign(d,{textSize:U(Qe(e,"fontSizes",i.size)??i.size),resolvedTextSize:U(c.size),bold:U(c.weight===700),italic:U(c.slant==="Italic"),horizontalAlignment:U(c.textAlign??"Center")}),o.verticalTextAlignment&&(d.verticalAlignment=U(c.verticalTextAlign??"Center"))):(d.strokeWidth=U(Qe(e,"lineWidths",n.strokeWidth)??n.strokeWidth),d.strokeStyle=U(n.strokeClass??"Solid"),o.fill&&(d.fillColor=U(Pt(e,n.fillColor))),o.cornerRadius&&(d.cornerRadius=U(r.cornerRadius??0))),o.line&&Object.assign(d,{lineStartStyle:U(t.startStyle??0),lineEndStyle:U(t.endStyle??1),lineRouting:U(o.connectorRouting?t.routing??"Straight":"Straight")}),o.group&&Object.assign(d,{groupColorRole:U(r.groupColorRole??null),groupHeaderVisible:U(r.groupHeaderVisible??!0)}),{...e,properties:d,...e.boundText?{boundText:Rt(e.boundText)}:{}}}function be(e){let t=e.items.map(Rt),o=Z(t),r=Object.fromEntries(zt.map(n=>{let i=o.map(d=>d.properties[n]);if(!i.length||i.some(d=>d.state==="Unavailable"))return[n,It];let c=i[0];return[n,i.every(d=>JSON.stringify(d.value)===JSON.stringify(c.value))?c:{state:"Mixed"}]}));return{...e,items:t,properties:r}}var R=(e,t,o)=>({itemId:e.id,path:t,value:o}),F=(e,t,...o)=>({itemId:e.id,op:"call",path:[t],arguments:o});function Oe(e,t,o,r){return{revision:e.revision,description:t,token:e.token,changes:(r?[r]:Z(e.items)).flatMap(o)}}import{EditorError as xe}from"@drawmotive/editor";var Me=Object.freeze(["undo","redo","arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode","drawingProperties","zoomIn","zoomOut","resetZoom","settings","help"]),Xe=Object.freeze(["topLeft","topRight","bottomLeft","bottomRight"]),ce=Object.freeze(["arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode"]),Ut=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Nt=e=>typeof e=="string"&&/^host[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e),Ro=e=>typeof e=="string"&&/^slot[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e);function ye(e,t,o){if(!Ut(e))throw new TypeError(o+" must be an object");for(let r of Object.keys(e))if(!t.includes(r))throw new TypeError("Unknown "+o+" option: "+r)}function ve(e,t){if(typeof e!="boolean")throw new TypeError(t+" must be a boolean");return e}function Ot(e,t){if(typeof e!="string"||!e.trim())throw new TypeError(t+" must be a nonempty string");return e}function $e(e,t,o=r=>typeof r=="string"&&!!r.trim()){if(!Array.isArray(e)||e.some(r=>!o(r))||new Set(e).size!==e.length)throw new TypeError(t+" must contain distinct valid IDs");return Object.freeze([...e])}function Ue(e,t,o){return e===void 0?{}:typeof e=="boolean"?{visible:e}:(ye(e,["visible",...t],o),e.visible!==void 0&&ve(e.visible,o+".visible"),e)}function Je(e={}){e===!1&&(e={enabled:!1}),ye(e,["enabled","buttons","actions","regions","drawingToolbar","contextToolbar","tooltip"],"ui");let t=e.enabled===void 0?!0:ve(e.enabled,"ui.enabled"),o=e.buttons??{};ye(o,Me,"ui.buttons");let r=Object.fromEntries(Me.map(a=>[a,a!=="help"]));for(let[a,T]of Object.entries(o))r[a]=ve(T,"ui.buttons."+a);let n=new Map;if(e.actions!==void 0&&!Array.isArray(e.actions))throw new TypeError("ui.actions must be an array");let i=(e.actions??[]).map(a=>{if(ye(a,["id","label","icon","visible","enabled","onInvoke"],"action"),!Nt(a.id))throw new TypeError("Action id must use the host. namespace");if(n.has(a.id))throw new TypeError("Duplicate action id: "+a.id);if(typeof a.onInvoke!="function")throw new TypeError("Action "+a.id+" requires an onInvoke handler");let T={id:a.id,label:Ot(a.label,"Action label"),enabled:a.enabled===void 0?!0:ve(a.enabled,"Action enabled"),visible:a.visible===void 0?!0:ve(a.visible,"Action visible")};return a.icon!==void 0&&(T.icon=Ot(a.icon,"Action icon")),n.set(a.id,a.onInvoke),Object.freeze(T)}),c=e.regions??{};ye(c,Xe,"ui.regions");let d=new Set(Object.values(c).flatMap(a=>Ut(a)&&Array.isArray(a.items)?a.items.filter(Nt):[])),u={topLeft:["undo","redo"],topRight:["help",...i.filter(a=>!d.has(a.id)).map(a=>a.id)],bottomLeft:[],bottomRight:["zoomOut","resetZoom","zoomIn","settings"]},f=Object.fromEntries(Xe.map(a=>{let T=Ue(c[a],["items"],"ui.regions."+a);return[a,Object.freeze({visible:t&&(T.visible??!0),items:$e(T.items??u[a],"ui.regions."+a+".items",A=>Me.includes(A)||n.has(A)||Ro(A))})]})),p=Ue(e.drawingToolbar,["position","tools"],"ui.drawingToolbar"),y=p.position??"left";if(!["left","right","top","bottom"].includes(y))throw new TypeError("ui.drawingToolbar.position must be left, right, top or bottom");let x=Object.freeze({visible:t&&(p.visible??!0),position:y,tools:$e(p.tools??ce.filter(a=>a!=="sketchyMode"),"ui.drawingToolbar.tools",a=>ce.includes(a))}),g=Ue(e.contextToolbar,["objectTypes","tools","panels"],"ui.contextToolbar"),s={visible:t&&(g.visible??!0)};for(let a of["objectTypes","tools","panels"])g[a]!==void 0&&(s[a]=$e(g[a],"ui.contextToolbar."+a));let m=Ue(e.tooltip,["position","delay"],"ui.tooltip"),v=m.position??"top",E=m.delay??250;if(!["top","bottom","left","right"].includes(v))throw new TypeError("ui.tooltip.position must be top, bottom, left or right");if(!Number.isFinite(E)||E<0)throw new TypeError("ui.tooltip.delay must be nonnegative");let h=Object.freeze({visible:m.visible??!0,position:v,delay:E});return Object.freeze({ui:Object.freeze({enabled:t,buttons:Object.freeze(r),actions:Object.freeze(i),regions:Object.freeze(f),drawingToolbar:x,contextToolbar:Object.freeze(s),tooltip:h}),handlers:n})}function Ye(e,t){let{ui:o,handlers:r}=Je(t),n=o,i=!1,c=new Set,d=new Set,u=()=>new xe("EditorDisposed","Editor UI has been disposed"),f=()=>{if(i||e.lifecycle!=="ready")throw u()},p,y,x=()=>{if(!i){i=!0,p?.(),y?.();for(let g of d)g.abort(u());d.clear(),r.clear(),c.clear()}};return e.lifecycle==="ready"?(y=e.onEvent("disposing",x),p=e.onDisposed(x)):x(),Object.freeze({get ui(){return n},editor:e,dispose:x,onChanged(g){if(f(),typeof g!="function")throw new TypeError("Listener must be a function");c.add(g);try{g(n)}catch(s){throw c.delete(g),s}return()=>c.delete(g)},async invokeAction(g){f();let s=r.get(g),m=n.actions.find(E=>E.id===g);if(!s)throw new xe("UnknownAction","Unknown host action: "+g);if(!m.enabled||!m.visible)throw new xe("ActionUnavailable","Host action is unavailable: "+g);let v=new AbortController;d.add(v);try{await s({editor:e,signal:v.signal})}catch(E){throw E instanceof xe?E:new xe(typeof E?.code=="string"?E.code:"HostActionFailed",E?.message??String(E),{cause:E})}finally{d.delete(v)}},async setActionState(g,s){if(f(),!r.has(g))throw new TypeError("Unknown host action: "+g);if(!s||typeof s!="object"||Array.isArray(s)||Object.keys(s).some(v=>!["label","enabled","visible"].includes(v)))throw new TypeError("Invalid action state");let m={};if(s.label!==void 0){if(typeof s.label!="string"||!s.label.trim())throw new TypeError("Action label must be a nonempty string");m.label=s.label}for(let v of["enabled","visible"])if(s[v]!==void 0){if(typeof s[v]!="boolean")throw new TypeError("Action "+v+" must be a boolean");m[v]=s[v]}n=Object.freeze({...n,actions:Object.freeze(n.actions.map(v=>v.id===g?Object.freeze({...v,...m}):v))});for(let v of c)try{v(n)}catch(E){console.error("Editor UI listener failed",E)}}})}import{cloneElement as mr,createContext as qt,forwardRef as fr,useContext as Vt,useLayoutEffect as gr,useMemo as hr,useRef as jt,useState as br}from"react";import{Kbd as yr,Popover as ot,Tooltip as vr,UnstyledButton as xr}from"@mantine/core";import{AlignBottomSimple as No,AlignCenterVerticalSimple as Oo,AlignTopSimple as Uo,ArrowBendRightUp as Mo,ArrowBendUpLeft as Ao,ArrowBendUpRight as Do,ArrowDownRight as Lo,ArrowElbowRightUp as Bo,ArrowRight as Ho,ArrowUpRight as jo,Browser as qo,Circle as Vo,Cloud as Zo,Copy as Fo,Cursor as Ko,Diamond as Wo,DotsThreeVertical as Go,GearSix as _o,Hash as Qo,MagnifyingGlass as $o,MagnifyingGlassMinus as Xo,MagnifyingGlassPlus as Jo,Minus as Lt,Palette as Bt,Path as Yo,Pill as er,Prohibit as tr,Question as or,Rectangle as Ht,Scribble as rr,Star as nr,TextAlignCenter as Mt,TextAlignLeft as ir,TextAlignRight as lr,TextB as sr,Textbox as At,TextItalic as ar,TextT as Ae,Trash as dr,X as cr}from"@phosphor-icons/react";import{jsx as M}from"react/jsx-runtime";var ur={undo:Ao,redo:Do,arrow:Lo,rectangle:Ht,ellipse:Vo,diamond:Wo,text:Ae,capsule:er,star:nr,cloud:Zo,select:Ko,sketchyMode:rr,zoomIn:Jo,zoomOut:Xo,settings:_o,drawingProperties:Bt,help:or,editText:At,search:$o,bold:sr,italic:ar,textAlign:Mt,textSizeSmall:Ae,textSizeMedium:Ae,textSizeLarge:Ae,textAlignLeft:ir,textAlignCenter:Mt,textAlignRight:lr,textAlignTop:Uo,textAlignMiddle:Oo,textAlignBottom:No,lineRouting:Yo,routingStraight:jo,routingOrthogonal:Bo,routingCurved:Mo,groupTheme:qo,groupTitleStyle:At,numbering:Qo,moreOptions:Go,copy:Fo,delete:dr,close:cr,transparent:tr};var pr={roundedCorner:{viewBox:"0 0 24 24",path:"M3,21V19H5v2H3Zm0-4V15H5v2H3Zm0-4V11H5v2H3ZM3,9V7H5V9H3ZM3,5V3H5V5H3ZM7,21V19H9v2H7ZM7,5V3H9V5H7Zm4,16V19h2v2H11Zm4,0V19h2v2H15Zm4,0V19h2v2H19Zm0-4V15h2v2H19Zm2-4H19V8q0-1.25-0.88-2.13T16,5H11V3h5q2.07,0 3.54,1.46Q21,5.93 21,8v5Z"},lineStyle:{viewBox:"0 -960 960 960",path:"M120-160v-80h80v80h-80Zm0-160v-80h200v80H120Zm0-160v-80h320v80H120Zm0-160v-160h720v160H120Zm160 480v-80h80v80h-80Zm100-160v-80h200v80H380Zm60 160v-80h80v80h-80Zm80-320v-80h320v80H520Zm80 320v-80h80v80h-80Zm40-160v-80h200v80H640Zm120 160v-80h80v80h-80Z"},lineEndArrowNotch:{viewBox:"0 -960 960 960",path:"m440-200 137-240H80v-80h497L440-760l440 280-440 280Z"},lineEndCircle:{viewBox:"0 -960 960 960",path:"M640-240q-90 0-156.5-57T403-440H80v-80h323q14-86 80.5-143T640-720q100 0 170 70t70 170q0 100-70 170t-170 70Z"},lineEndDiamond:{viewBox:"0 -960 960 960",path:"M600-200 360-440H80v-80h280l240-240 280 280-280 280Z"}};function et({name:e,size:t,mirrored:o=!1,style:r}){let n=pr[e];return M("svg",{viewBox:n.viewBox,width:t,height:t,fill:"currentColor","aria-hidden":"true",style:r,children:M("g",{transform:o?"translate(960 0) scale(-1 1)":void 0,children:M("path",{d:n.path})})})}function H({name:e,style:t}){if(e==="strokeColor"||e==="strokeFillColor")return M(ue,{style:t});if(e==="lineStartStyle"||e==="lineEndStyle")return M(ke,{value:1,start:e==="lineStartStyle",style:t});if(e==="strokeStyle")return M(et,{name:"lineStyle",size:19,style:t});if(e==="cornerRadius")return M(et,{name:"roundedCorner",size:19,style:t});if(e==="swapLineEndpoints")return M("svg",{viewBox:"0 0 1024 1024",width:"19",height:"19",fill:"currentColor","aria-hidden":"true",style:t,children:M("path",{d:"M723.498667 512l-170.666667-170.666667v341.333334z m-426.666667 0l170.666667 170.666667V341.333333z"})});let o=ur[e]??Ht;return M(o,{size:e==="textSizeSmall"?14:e==="textSizeLarge"?24:19,weight:"regular","aria-hidden":"true",style:t})}function ue({fill:e="none",style:t}){return M(Bt,{size:20,weight:"duotone",className:"dm-palette","aria-hidden":"true",style:{"--dm-palette-fill":e,...t}})}var Dt={Solid:"M134.613333 776.106667l-41.130666-71.253334L886.272 245.333333l41.130667 71.253334z",Dashed:"M124.373333 781.141333l-41.173333-71.253333 127.744-75.52 41.130667 71.253333z m238.165334-135.765333l-41.130667-71.253333 131.242667-75.776 41.130666 71.253333z m238.08-139.178667l-41.173334-71.253333 120.234667-69.418667 41.130667 71.253334z m224.853333-129.877333l-41.088-71.253333 120.234667-69.418667 41.130666 71.253333z",Dotted:"M122.368 781.866667l-41.130667-71.253334 53.802667-32.853333 41.130667 71.253333z m112.384-63.104l-41.173333-71.253334 57.344-33.066666 41.130666 71.253333z m116.309333-66.944l-41.130666-71.253334 57.301333-33.066666 41.130667 71.253333z m113.109334-63.786667l-41.130667-71.253333 57.301333-33.066667 41.130667 71.253333z m110.848-64l-41.130667-71.253333 57.301333-33.066667 41.130667 71.253333z m108.885333-64.512l-41.173333-71.253333 57.344-33.109334 41.130666 71.253334z m104.106667-60.117333l-41.173334-71.253334 57.344-33.066666 41.130667 71.253333z m102.272-62.72l-41.130667-71.253334 57.301333-33.066666 41.130667 71.253333z"};function tt({width:e,pattern:t}){return t===void 0?M(Lt,{size:20,weight:e===0?"thin":e===2?"bold":"regular","aria-hidden":"true"}):M("svg",{viewBox:"0 0 1024 1024",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:M("path",{d:Dt[t]??Dt.Solid})})}function ke({value:e,start:t=!1,style:o}){return e<=2?M(e===0?Lt:Ho,{size:22,weight:e===2?"fill":"regular",mirrored:t,"aria-hidden":"true",style:o}):M(et,{name:e===3?"lineEndArrowNotch":e===4?"lineEndCircle":"lineEndDiamond",size:22,mirrored:t,style:o})}import{jsx as ee,jsxs as Zt}from"react/jsx-runtime";var rt=qt(null),De=qt(void 0);function N(){let e=Vt(rt);if(!e)throw new Error("Editor controls need EditorUi");return e}var C=e=>e?.state==="Uniform"?e.value:void 0,Le={undo:"Undo",redo:"Redo",arrow:"Arrow",rectangle:"Rectangle",ellipse:"Ellipse",diamond:"Diamond",text:"Text",sketchyMode:"Sketchy mode",capsule:"Capsule",star:"Star",cloud:"Cloud",zoomIn:"Zoom in",zoomOut:"Zoom out",resetZoom:"Reset zoom",settings:"Settings",drawingProperties:"Drawing properties",help:"Help",strokeFillColor:"Border and Fill Color",strokeColor:"Color",strokeStyle:"Line style",cornerRadius:"Round corners",editText:"Edit text",textSizeSmall:"Small text",textSizeMedium:"Medium text",textSizeLarge:"Large text",bold:"Bold",italic:"Italic",textAlign:"Text alignment",lineStartStyle:"Start style",lineEndStyle:"End style",swapLineEndpoints:"Swap endpoints",lineRouting:"Connector type",groupTheme:"Group theme",groupTitleStyle:"Title style",numbering:"Numbering",moreOptions:"More options",copy:"Copy selection",paste:"Paste selection",delete:"Delete selection",cancel:"Cancel interaction",pan:"Pan canvas",quickInsert:"Quick insert"},we={undo:"Ctrl/\u2318 Z",redo:"Ctrl/\u2318 Shift Z",arrow:"A",rectangle:"R",ellipse:"O",diamond:"D",text:"T",sketchyMode:"S",bold:"Ctrl/\u2318 B",italic:"Ctrl/\u2318 I",editText:"Enter",copy:"Ctrl/\u2318 C",paste:"Ctrl/\u2318 V",delete:"Delete",cancel:"Escape",pan:"Space (hold)",quickInsert:"/"},z=fr(function({icon:t,children:o,selected:r,shortcut:n,className:i="",...c},d){let{ui:u}=N(),f=c["aria-label"]??Le[t??""]??t??"",p=Vt(De)??u.tooltip.position;return ee(vr,{label:Zt("span",{style:{display:"inline-flex",alignItems:"center",gap:8},children:[f,n&&ee(yr,{size:"xs",children:n})]}),position:p,offset:12,openDelay:u.tooltip.delay,disabled:!u.tooltip.visible,events:{hover:!0,focus:!0,touch:!1},withinPortal:!1,withArrow:!0,zIndex:100,children:ee(xr,{ref:d,...c,className:"dm-tool "+i,"aria-label":f,"aria-pressed":r,"data-selected":r===!0?"":void 0,children:o??ee(H,{name:t??""})})})});function re({id:e,button:t,children:o,label:r,nested:n=!1}){let{panel:i,setPanel:c,state:d}=N(),[u,f]=br(!1),p=n?u:i===e,y=m=>n?f(m):c(m?e:null),x=hr(()=>typeof document>"u"||!document.activeElement?.matches(".drawmotive-canvas-host canvas"),[p]),g=jt(null),s=jt(d.busy);return gr(()=>{let m=g.current,v=m?.ownerDocument;p&&(s.current||d.busy)&&v&&v.activeElement===v.body&&m?.focus({preventScroll:!0}),s.current=d.busy},[p,d.busy]),Zt(ot,{opened:p,onChange:y,position:"top-start",offset:5,withinPortal:!1,trapFocus:!0,returnFocus:x,transitionProps:{duration:0},classNames:{dropdown:"dm-panel"},children:[ee(ot.Target,{children:mr(t,{onClick:m=>{t.props.onClick?.(m),y(!p)}})}),ee(ot.Dropdown,{ref:g,tabIndex:-1,role:"dialog","aria-label":r??Le[e]??e,children:o})]})}var Be=()=>ee("span",{className:"dm-separator",role:"separator","aria-orientation":"vertical"}),He=({children:e})=>ee("div",{className:"dm-panel-heading",children:e});function nt(e="Foreground"){return"--dm-color-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase().replace(/[^a-z-]/g,"")}function ne(e,t){if(t!=null){let o=Number(t).toString(16).padStart(8,"0");return"#"+o.slice(2)+o.slice(0,2)}return e==="Transparent"?"transparent":"var("+nt(e??void 0)+", currentColor)"}import{forwardRef as kr,useEffect as Ft,useImperativeHandle as wr,useRef as it}from"react";import{Tooltip as Sr}from"@mantine/core";import{jsx as Kt}from"react/jsx-runtime";var Er=kr(function({canvas:t,instruction:o,onMouseEnter:r,onMouseLeave:n},i){let c=it({onMouseEnter:r,onMouseLeave:n}),d=it(null),u=it(t.matches(":hover"));return c.current={onMouseEnter:r,onMouseLeave:n},wr(i,()=>t,[t]),Ft(()=>{let f=g=>{u.current=!0,d.current=g,c.current.onMouseEnter?.(g)},p=g=>{u.current=!1,c.current.onMouseLeave?.(g)},y=g=>{d.current=g},x=g=>{if(!t.hasPointerCapture(g.pointerId))return;let s=t.ownerDocument.elementFromPoint(g.clientX,g.clientY)===t;s&&!u.current?f(g):!s&&u.current&&p(g)};return t.addEventListener("mouseenter",f),t.addEventListener("mouseleave",p),t.addEventListener("mousemove",y),t.addEventListener("pointermove",x),()=>{t.removeEventListener("mouseenter",f),t.removeEventListener("mouseleave",p),t.removeEventListener("mousemove",y),t.removeEventListener("pointermove",x)}},[t]),Ft(()=>{o&&u.current&&d.current&&c.current.onMouseEnter?.(d.current)},[o]),null});function Wt({container:e}){let{state:t,ui:o}=N(),r=e.querySelector(".drawmotive-canvas-host canvas");if(!r)return null;let n=o.tooltip.visible&&t.editingEnabled&&t.health==="healthy"?t.prompt??null:null;return Kt(Sr.Floating,{label:n??"",disabled:!n,defaultOpened:r.matches(":hover"),withinPortal:!1,offset:18,zIndex:100,role:"tooltip","aria-live":"polite","data-testid":"creation-tooltip",children:Kt(Er,{canvas:r,instruction:n})})}import{Kbd as Tr,Tooltip as Gt}from"@mantine/core";function _t(e){let t={backgroundColor:"var(--mantine-color-gray-"+(e?"2":"9")+")",color:"var(--mantine-color-"+(e?"black":"white")+")"};return{components:{Tooltip:Gt.extend({styles:{tooltip:t}}),TooltipFloating:Gt.Floating.extend({styles:{tooltip:t}}),Kbd:Tr.extend({styles:{root:{borderColor:"var(--mantine-color-"+(e?"dark-4":"gray-3")+")",color:"var(--mantine-color-"+(e?"dark-0":"gray-7")+")",backgroundColor:"var(--mantine-color-"+(e?"dark-6":"gray-0")+")"}}})}}}import{forwardRef as Cr}from"react";import{Checkbox as Pr,CloseButton as Ir,Loader as Qt,NativeSelect as zr,PasswordInput as Rr}from"@mantine/core";import{CaretUpDown as Nr,Check as Or,Eye as Ur,EyeSlash as Mr,Minus as Ar,SpinnerGap as Dr,X as Lr}from"@phosphor-icons/react";import{jsx as Se}from"react/jsx-runtime";var Br=({indeterminate:e,...t})=>Se(e?Ar:Or,{...t,size:"100%",weight:"bold","aria-hidden":"true"});function Hr({reveal:e}){return Se(e?Mr:Ur,{size:"var(--psi-icon-size)",weight:"regular","aria-hidden":"true"})}var jr=Cr(({className:e,style:t,size:o,...r},n)=>Se(Dr,{...r,ref:n,size:"var(--loader-size)",weight:"regular","aria-hidden":"true",className:["dm-phosphor-loader",e].filter(Boolean).join(" "),style:{color:"var(--loader-color)",...t}})),lt={components:{Checkbox:Pr.extend({defaultProps:{icon:Br}}),CloseButton:Ir.extend({defaultProps:{icon:Se(Lr,{size:"var(--cb-icon-size, 70%)",weight:"regular","aria-hidden":"true"})}}),NativeSelect:zr.extend({defaultProps:{rightSection:Se(Nr,{size:"1em",weight:"regular","aria-hidden":"true"})}}),PasswordInput:Rr.extend({defaultProps:{visibilityToggleIcon:Hr}}),Loader:Qt.extend({defaultProps:{loaders:{...Qt.defaultLoaders,phosphor:jr},type:"phosphor"}})}};import{NativeSelect as $t}from"@mantine/core";import{Fragment as ct,jsx as k,jsxs as pe}from"react/jsx-runtime";var Xt=["Transparent","Foreground","PrimaryStroke","SecondaryStroke","AccentStroke","SuccessStroke","WarningStroke"],qr=["Transparent","Background","PrimaryFill","SecondaryFill","AccentFill","SuccessFill","WarningFill"],Vr=["Foreground","Background",...Xt.slice(2)],Zr=["PrimaryStroke","SecondaryStroke","AccentStroke","SuccessStroke","WarningStroke"];function je({fill:e=!1,target:t}){let{selection:o,edit:r}=N(),n=t?.properties??o.properties;return k(ct,{children:(e?[!1,!0]:[!1]).map(i=>{let c=i?qr:e?Xt:Vr,d=C(i?n.fillColor:n.strokeColor);return pe("div",{children:[k(He,{children:i?"Fill Color":e?"Border Color":"Color"}),k("div",{className:"dm-panel-row",children:c.map(u=>k(z,{"aria-label":u==="Transparent"?i?"No Fill":"No Border":u.replace(/(Stroke|Fill)$/,"")+" color",selected:d?.role===u&&d.argb===null,"data-testid":"panel-"+(i?"fill":"stroke")+"-color-"+u.toLowerCase(),onClick:()=>{r(i?"Change fill color":"Change stroke color",f=>{let p=f.capabilities.text?["fontStyle","color"]:["data","paintStyle",i?"fillColor":"color"];return[R(f,p,de(f,"colors",u))]},t)},children:u==="Transparent"?k(H,{name:"transparent",style:{color:"var(--dm-color-secondary-stroke)"}}):k(ue,{fill:i?ne(u):"none",style:{color:ne(u)}})},u))})]},String(i))})})}function Jt(){let{selection:e,edit:t}=N(),o=e.properties;return pe(ct,{children:[k(He,{children:"Line Width"}),k("div",{className:"dm-panel-row",children:["Thin","Normal","Bold"].map((r,n)=>k(z,{"aria-label":r+" line",selected:C(o.strokeWidth)===r,"data-testid":"panel-stroke-width-"+n,onClick:()=>{t("Change stroke width",i=>[R(i,["data","paintStyle","strokeWidth"],de(i,"lineWidths",r))])},children:k(tt,{width:n})},r))}),k(He,{children:"Line Style"}),k("div",{className:"dm-panel-row",children:["Solid","Dashed","Dotted"].map((r,n)=>k(z,{"aria-label":r+" line",selected:C(o.strokeStyle)===r,"data-testid":"panel-stroke-style-"+n,onClick:()=>{t("Change stroke style",i=>[R(i,["data","paintStyle","strokeClass"],r)])},children:k(tt,{pattern:r})},r))})]})}function st({target:e}){let{selection:t,edit:o}=N(),r=e?[e]:Z(t.items),n=e?.properties??t.properties;return k(ct,{children:[!1,...r.every(i=>i.capabilities.verticalTextAlignment)?[!0]:[]].map(i=>k("div",{className:"dm-panel-row",children:(i?["Top","Center","Bottom"]:["Left","Center","Right"]).map(c=>k(z,{"aria-label":(i?"Vertical ":"Horizontal ")+c,selected:C(i?n.verticalAlignment:n.horizontalAlignment)===c,"data-testid":"panel-text-align-"+(i?"vertical":"horizontal")+"-"+c.toLowerCase(),onClick:()=>{o("Change text alignment",d=>[R(d,["fontStyle",i?"verticalTextAlign":"textAlign"],c)],e)},children:k(H,{name:"textAlign"+(i&&c==="Center"?"Middle":c)})},c))},String(i)))})}function at({start:e}){let{selection:t,edit:o}=N(),r=C(e?t.properties.lineStartStyle:t.properties.lineEndStyle);return k("div",{className:"dm-endpoint-grid",children:["None","Simple arrow","Filled arrow","Open arrow","Circle","Diamond"].map((n,i)=>k(z,{"aria-label":n,selected:r===i,"data-testid":"panel-line-"+(e?"start":"end")+"-style-"+i,onClick:()=>{o("Change endpoint style",c=>[R(c,[e?"startStyle":"endStyle"],i)])},children:k(ke,{value:i,start:e})},n))})}function Yt(){let{selection:e,edit:t}=N(),o=e.items.every(r=>r.capabilities.connectorRouting);return k("div",{className:"dm-panel-row",children:["Straight","Orthogonal","Curved"].map((r,n)=>k(z,{"aria-label":r,selected:C(e.properties.lineRouting)===r,disabled:r!=="Straight"&&!o,"data-testid":"panel-line-connector-style-"+n,onClick:()=>{t("Change routing",i=>[F(i,"setRoutingMode",r)])},children:k(H,{name:"routing"+r})},r))})}function dt({inline:e=!1}){let{selection:t,edit:o}=N(),r=t.properties;return pe("div",{className:e?"dm-group-controls":"dm-panel-stack",children:[k($t,{"aria-label":"Group theme color",label:e?void 0:"Group theme color",size:"xs",value:C(r.groupColorRole)??"auto",data:[{value:"auto",label:r.groupColorRole.state==="Mixed"?"Mixed":"Theme default"},...Zr.map(n=>({value:n,label:n.replace("Stroke","")}))],onChange:n=>{let i=n.currentTarget.value;o("Change group theme color",c=>[F(c,"setThemeColorRole",i==="auto"?null:i)])}}),k(z,{icon:"groupTheme","aria-label":"Toggle title background","data-testid":"group-title-background",selected:C(r.groupHeaderVisible)===!0,onClick:()=>{o("Toggle title background",n=>[F(n,"setHeaderVisible",C(r.groupHeaderVisible)!==!0)])}}),k(eo,{label:"Restore group theme defaults",prompt:"Theme defaults",testId:"group-theme-reset",choices:["All","Border","Body","Line","Corners","Opacity","Header"],onChange:n=>o("Restore group style",i=>[F(i,"resetStyle",n)])})]})}function eo({label:e,prompt:t,testId:o,choices:r,onChange:n}){return k($t,{"aria-label":e,"data-testid":o,size:"xs",value:"prompt",data:[{value:"prompt",label:t??e},...r.map(i=>({value:i,label:"Restore "+i.toLowerCase()}))],onChange:i=>{i.currentTarget.value!=="prompt"&&n(i.currentTarget.value)}})}function to(){let{selection:e,edit:t}=N(),o=e.items[0]?.boundText;return o?pe("div",{className:"dm-title-controls",children:[k(re,{id:"title-color",label:"Title color",nested:!0,button:k(z,{icon:"strokeColor"}),children:k(je,{target:o})}),k(Be,{}),k(Fr,{target:o}),k(re,{id:"title-align",label:"Title alignment",nested:!0,button:k(z,{icon:"textAlign"}),children:k(st,{target:o})}),k(eo,{label:"Restore title theme style",prompt:"Title theme defaults",testId:"group-title-theme-reset",choices:["All","Color","Size","Weight","Slant","Alignment"],onChange:r=>t("Restore title style",n=>[F(n,"resetTitleStyle",r)])})]}):null}function Fr({target:e}){let{edit:t}=N(),o=e.properties;return pe("div",{className:"dm-panel-row",children:[k("span",{className:"dm-button-group",children:["Small","Medium","Large"].map(r=>k(z,{icon:"textSize"+r,selected:C(o.textSize)===r,onClick:()=>{t("Set text size",n=>[R(n,["fontStyle","size"],de(n,"fontSizes",r))],e)}},r))}),k(z,{icon:"bold",selected:C(o.bold)===!0,onClick:()=>{t("Toggle bold",r=>[R(r,["fontStyle","weight"],C(o.bold)===!0?400:700)],e)}}),k(z,{icon:"italic",selected:C(o.italic)===!0,onClick:()=>{t("Toggle italic",r=>[R(r,["fontStyle","slant"],C(o.italic)===!0?"Upright":"Italic")],e)}})]})}function oo({copy:e}){let{editor:t,selection:o,run:r,setPanel:n}=N();return k("div",{className:"dm-panel-stack",children:["Copy","Delete"].map(i=>pe(z,{"aria-label":i,"data-testid":"panel-more-options-"+i.toLowerCase(),className:"dm-menu-item",onClick:()=>{r(async()=>{i==="Copy"?await e():await t.deleteSelection(o.token),n(null)})},children:[k(H,{name:i.toLowerCase()}),k("span",{children:i})]},i))})}import{useEffect as Kr,useRef as Ee}from"react";import{getHotkeyHandler as Wr,useHotkeys as Gr}from"@mantine/hooks";var _r=["alt","shift","ctrl","meta"].reduce((e,t)=>[...e,...e.map(o=>t+"+"+o)],["escape"]);function ro(e){let t=Ee(e);t.current=e;let o=Ee(new Set),r=Ee(0),n=Ee(null),i=Ee({alt:!1,shift:!1}),c=s=>s.code||s.key,d=()=>e.container.querySelector(".drawmotive-canvas-host"),u=s=>s.target===d()?.querySelector("canvas"),f=s=>s.isComposing||s.keyCode===229||["Process","Dead","Unidentified"].includes(s.key),p=()=>{let s=e.state();return e.editor.lifecycle==="ready"&&s.editingEnabled&&s.health==="healthy"};function y(s,m,{busy:v=!1,pointer:E=!1,available:h=!0,key:a="document"}={}){if(!(!u(s)||f(s)||!p())){if(o.current.has(c(s))){s.preventDefault();return}if(!(!h||!v&&e.state().busy||!E&&r.current!==0)){if(s.repeat){s.preventDefault();return}o.current.add(c(s)),s.preventDefault(),e.run(m,a)}}}function x(s,m){let v=e.selection(),E=v&&be(v),h=E&&Z(E.items);y(s,()=>{let a=E.properties[m],T=a.state==="Uniform"&&a.value===!0;return e.editor.editScene(Oe(E,"Toggle "+m,A=>[R(A,["fontStyle",m==="bold"?"weight":"slant"],m==="bold"?T?400:700:T?"Upright":"Italic")]))},{available:!!h?.length&&h.every(a=>a.capabilities.text)})}let g=[...Object.entries({a:"arrow",r:"rectangle",o:"ellipse",d:"diamond",t:"text"}).map(([s,m])=>[s,v=>y(v,()=>e.activateTool(m),{available:e.ui.buttons[m]})]),["/",s=>{s.key!=="/"||s.altKey||s.ctrlKey||s.metaKey||s.shiftKey||y(s,async()=>e.openQuickInsert(),{available:e.ui.enabled})}],["s",s=>y(s,()=>e.editor.setSketchyMode(!e.state().sketchyMode),{available:e.ui.buttons.sketchyMode})],["mod+z",s=>y(s,()=>e.editor.undo(),{available:e.state().canUndo})],["mod+shift+z",s=>y(s,()=>e.editor.redo(),{available:e.state().canRedo})],["mod+y",s=>y(s,()=>e.editor.redo(),{available:e.state().canRedo})],["delete",s=>y(s,()=>e.editor.deleteSelection(e.selection().token),{available:!!e.selection()?.items.length})],["mod+c",s=>y(s,()=>e.editor.copyToClipboard(e.selection().token),{available:!!e.selection()?.items.length})],["mod+v",s=>y(s,()=>e.editor.pasteFromClipboard())],["mod+b",s=>x(s,"bold")],["mod+i",s=>x(s,"italic")],["enter",s=>{let m=e.selection(),v=m&&Z(m.items)[0];y(s,()=>e.editor.beginTextEditing(v.id),{available:e.editor.textEditing!=="disabled"&&!!v?.capabilities.editText})}],..._r.map(s=>[s,m=>{m.target instanceof e.container.ownerDocument.defaultView.HTMLElement&&d()?.contains(m.target)&&m.target.matches('[data-testid="d-canvas-content-editable"]')&&!f(m)&&p()?(m.preventDefault(),e.run(()=>e.editor.cancelInteraction(),"interaction")):y(m,()=>e.editor.cancelInteraction(),{busy:!0,pointer:!0,key:"interaction"})}]),["space",s=>y(s,()=>{let m={release:!1,started:e.editor.beginPan()};return n.current=m,m.started},{available:!n.current&&e.state().tool==="select",key:"pan"})]];Gr(g.map(([s,m])=>[s,m,{preventDefault:!1,usePhysicalKeys:s!=="/"}]),[],!0),Kr(()=>{let{container:s}=e,m=s.ownerDocument,v=m.defaultView;function E(){let w=n.current;!w||w.release||(w.release=!0,(async()=>{try{await w.started&&t.current.editor.lifecycle==="ready"&&await t.current.editor.endPan()}finally{n.current===w&&(n.current=null)}})().catch(q=>t.current.report(q)))}function h(w,q){if(i.current.alt===w&&i.current.shift===q)return;i.current={alt:w,shift:q};let Q=t.current.state();t.current.editor.lifecycle==="ready"&&Q.editingEnabled&&Q.health==="healthy"&&t.current.editor.updateInteractionModifiers({alt:w,shift:q}).catch($=>t.current.report($))}function a(){let w=r.current!==0;o.current.clear(),r.current=0,E();let q=t.current.state();w&&t.current.editor.lifecycle==="ready"&&q.editingEnabled&&q.health==="healthy"&&t.current.editor.cancelInteraction().catch(Q=>t.current.report(Q)),h(!1,!1)}function T(w){if(u(w)){if(["pointercancel","lostpointercapture"].includes(w.type)){(w.type==="pointercancel"||r.current!==0)&&a();return}i.current={alt:w.altKey,shift:w.shiftKey},r.current=w.buttons}else["pointerup","pointercancel"].includes(w.type)&&(r.current=w.buttons)}function A(w){!["Alt","Shift"].includes(w.key)||f(w)||(u(w)||i.current.alt||i.current.shift)&&h(w.altKey,w.shiftKey)}let _=Wr([["space",E,{preventDefault:!1,usePhysicalKeys:!0}]]);function Pe(w){o.current.delete(c(w)),A(w),n.current&&(w.code==="Space"||w.key===" ")?E():_(w)}function le(w){u(w)||a()}function me(){m.visibilityState==="hidden"&&a()}let Ie=["pointerdown","pointermove","pointerup","pointercancel","lostpointercapture"];for(let w of Ie)m.addEventListener(w,T,!0);return m.addEventListener("keydown",A,!0),m.addEventListener("keyup",Pe,!0),m.addEventListener("focusin",le,!0),m.addEventListener("visibilitychange",me),v.addEventListener("blur",a),()=>{a();for(let w of Ie)m.removeEventListener(w,T,!0);m.removeEventListener("keydown",A,!0),m.removeEventListener("keyup",Pe,!0),m.removeEventListener("focusin",le,!0),m.removeEventListener("visibilitychange",me),v.removeEventListener("blur",a)}},[e.editor,e.container])}import{Checkbox as co}from"@mantine/core";import{useEffect as io,useRef as mt,useState as ft}from"react";import{Checkbox as rn,Divider as nn,NativeSelect as lo}from"@mantine/core";import{useState as Qr}from"react";import{Button as ut,Checkbox as $r,Divider as Xr,Group as Jr,NativeSelect as Yr,TextInput as en}from"@mantine/core";import{Fragment as on,jsx as W,jsxs as qe}from"react/jsx-runtime";function pt({disabled:e,onReset:t}){return W(ut,{size:"compact-xs",variant:"default",disabled:e,style:{alignSelf:"flex-start"},onClick:()=>{t()},children:"Reset numbering"})}function no({item:e}){let{selection:t,state:o,edit:r}=N(),n=_e(e);if(!t||!n)return null;let i=t.revision!==o.revision||o.busy||!o.editingEnabled||o.health!=="healthy",c=e.model.autoNumber,d=e.model.autoNumberMode,u=d==="Enable"||d==="Disable"||d==="Inherit",f="Automatic numbering in group",p=y=>r("Change group automatic numbering",x=>[R(x,[u?"autoNumberMode":"autoNumber"],y)],e);return qe("div",{className:"dm-panel-stack dm-numbering-panel",children:[W(tn,{numbering:n,disabled:i,onChange:y=>r(y===null?"Clear badge number":"Change badge number",x=>[F(x,"setBadgeNumber",y)],e)},t.revision),e.capabilities.group&&(u||typeof c=="boolean")&&qe(on,{children:[W(Xr,{}),u?W(Yr,{label:f,size:"xs",value:d,disabled:i,data:[{value:"Enable",label:"Enable"},{value:"Disable",label:"Disable"},{value:"Inherit",label:"Inherit parent"}],onChange:y=>{p(y.currentTarget.value)}}):W($r,{label:f,size:"xs",checked:c===!0,disabled:i,onChange:y=>{p(y.currentTarget.checked)}}),W(pt,{disabled:i,onReset:()=>r("Reset group numbering",y=>[F(y,"resetNumbering",!1)],e)})]})]})}function tn({numbering:{number:e,prefix:t,maximum:o},disabled:r,onChange:n}){let i=e===null?"":String(e),[c,d]=Qr(i),u=Number(c),f=/^[0-9]+$/.test(c)&&Number.isSafeInteger(u)&&u>=1&&u<=o,p=!r&&f&&u!==e;return qe("form",{className:"dm-panel-stack",onSubmit:y=>{y.preventDefault(),p&&n(u)},children:[W(en,{label:"Local number",size:"xs",value:c,inputMode:"numeric",disabled:r||o<1,leftSection:t&&W("span",{className:"dm-number-prefix","data-testid":"number-prefix","aria-hidden":"true",children:t}),leftSectionWidth:t?`clamp(1.75rem, calc(${t.length}ch + .75rem), 60%)`:void 0,leftSectionPointerEvents:"none",description:t&&"Group prefix "+t,descriptionProps:{style:{display:"none"}},error:c!==i&&c!==""&&!f&&"Enter a whole number from 1 to "+o+".",onChange:y=>d(y.currentTarget.value)}),qe(Jr,{gap:6,children:[W(ut,{type:"submit",size:"compact-xs",disabled:!p,children:"Apply"}),W(ut,{type:"button",size:"compact-xs",variant:"default",disabled:r||e===null,onClick:()=>{n(null)},children:"Clear"})]})]})}import{Fragment as ln,jsx as J,jsxs as gt}from"react/jsx-runtime";var so={root:"dm-drawing-property",label:"dm-drawing-property-label",wrapper:"dm-drawing-property-input"};function ao(){let{editor:e,state:t,run:o}=N(),[r,n]=ft(null),[i,c]=ft(null),[d,u]=ft(0),f=mt(!1),p=mt(t.revision),y=mt(null);p.current=t.revision,io(()=>(f.current=!0,()=>{f.current=!1}),[]),io(()=>{let a=t.revision;!a||t.busy||y.current===a||(y.current=a,c(null),e.getScene().then(T=>{if(!(!f.current||p.current!==a)){if(T.revision!==a)throw new Error("The drawing changed. Read its properties again.");n(T)}}).catch(T=>{f.current&&p.current===a&&c(T)}))},[e,t.revision,t.busy,d]);let x=r?.revision===t.revision,g=r?.metadata.model,s=!x||t.busy||!t.editingEnabled||t.health!=="healthy",m=typeof g?.theme=="string"?g.theme:"default",v=g?.style===1?"1":"0",E=async(a,T)=>{s||!r||await o(()=>e.editScene({revision:r.revision,description:a,changes:[T]}))},h=g?.autoNumber;return gt("div",{className:"dm-panel-stack dm-drawing-properties","aria-busy":!x&&!i,children:[J(lo,{label:"Theme",classNames:so,value:m,disabled:s,"data-testid":"drawing-theme",data:[{value:"default",label:"Default"},{value:"minimal",label:"Minimal"}],onChange:a=>{E("Change drawing theme",{path:["theme"],value:a.currentTarget.value})}}),J("p",{className:"dm-property-description",children:m==="minimal"?"Apple-inspired cards in graphite, ceramic and titanium finishes.":"Balanced colors and classic outlines."}),J(lo,{label:"Drawing style",classNames:so,value:v,disabled:s,"data-testid":"drawing-style",data:[{value:"0",label:"Formal"},{value:"1",label:"Draft"}],onChange:a=>{E("Change drawing style",{path:["style"],value:Number(a.currentTarget.value)})}}),J("p",{className:"dm-property-description",children:v==="1"?"Hand-drawn strokes and handwriting.":"Precise strokes and clean typography."}),typeof h=="boolean"&>(ln,{children:[J(nn,{}),J(rn,{label:"Automatic numbering in this diagram",size:"xs",checked:h,disabled:s,onChange:a=>{E("Change automatic numbering",{path:["autoNumber"],value:a.currentTarget.checked})}}),J(pt,{disabled:s,onReset:()=>E("Reset numbering",{op:"call",path:["resetNumbering"],arguments:[!1]})})]}),i!=null&>("div",{role:"alert",children:[J("p",{children:i?.message??String(i)}),J(z,{"aria-label":"Read drawing properties again",onClick:()=>{y.current=null,u(a=>a+1)},children:"Try again"})]})]})}import{jsx as Y,jsxs as Te}from"react/jsx-runtime";function uo({preferences:e,onChange:t}){return Te("div",{className:"dm-settings",children:[Y("header",{className:"dm-settings-header",children:Y("h2",{children:"Settings"})}),Te("section",{className:"dm-settings-section","aria-label":"View",children:[Te("div",{className:"dm-settings-section-heading",children:[Y("h3",{children:"View"}),Y("p",{children:"Only on this device."})]}),Y(co,{label:"Dark Theme","data-testid":"settings-dark-theme",checked:e.darkTheme??!1,onChange:o=>{t({darkTheme:o.currentTarget.checked})}}),Y(co,{label:"Show and Snap to Grid","data-testid":"settings-show-grid",checked:e.showGrid??!0,onChange:o=>{t({showGrid:o.currentTarget.checked,snapToGrid:o.currentTarget.checked})}})]}),Te("section",{className:"dm-settings-section","aria-label":"Drawing",children:[Te("div",{className:"dm-settings-section-heading",children:[Y("h3",{children:"Drawing"}),Y("p",{children:"Saved with this drawing."})]}),Y(ao,{})]})]})}import{useId as sn,useLayoutEffect as ho,useRef as an,useState as bo}from"react";import{FocusTrap as dn}from"@mantine/core";var Ce=Object.freeze([{id:"arrow",label:"Arrow",aliases:"line connector"},{id:"rectangle",label:"Rectangle",aliases:"box square shape"},{id:"ellipse",label:"Ellipse",aliases:"circle oval shape"},{id:"diamond",label:"Diamond",aliases:"decision rhombus shape"},{id:"text",label:"Text",aliases:"label note"}]),mo="drawmotive.quick-insert.v1";function po(e){try{let t=e().getItem(mo);if(t===null)return{};let o=JSON.parse(t),r={};if(o?.version!==1)return null;for(let{id:n}of Ce){let i=o.usage?.[n];Number.isSafeInteger(i?.count)&&i.count>0&&Number.isSafeInteger(i.lastUsed)&&i.lastUsed>0&&(r[n]={count:i.count,lastUsed:i.lastUsed})}return r}catch{return null}}function ht(e,t,o=1){let r=Object.keys(e).sort((n,i)=>e[n].lastUsed-e[i].lastUsed);r.forEach((n,i)=>{e[n].lastUsed=i+1}),e[t]={count:Math.min((e[t]?.count??0)+o,Number.MAX_SAFE_INTEGER),lastUsed:r.length+1}}function fo(e){let t=po(e)??{},o={};function r(){let n=po(e);if(n!==null){for(let i of Object.keys(o).sort((c,d)=>o[c].lastUsed-o[d].lastUsed))ht(n,i,o[i].count);t=n}}return{read(){return r(),structuredClone(t)},record(n){if(Ce.some(i=>i.id===n)){r(),ht(t,n);try{e().setItem(mo,JSON.stringify({version:1,usage:t})),o={}}catch{ht(o,n)}}}}}function go(e,t,o=Ce){let r=e.trim().toLowerCase().split(/\s+/).filter(Boolean),n=o.filter(f=>r.every(p=>(f.label+" "+(f.group??"")+" "+f.aliases).toLowerCase().includes(p)));if(!n.length)return[];let i=new Map,c=n.filter(f=>!f.group);for(let f of n)f.group&&(i.has(f.group)||i.set(f.group,[]),i.get(f.group).push(f));let d=r.length?[]:n.filter(f=>t[f.id]).sort((f,p)=>t[p.id].lastUsed-t[f.id].lastUsed).slice(0,3),u=r.length?[]:n.filter(f=>t[f.id]?.count>1).sort((f,p)=>t[p.id].count-t[f.id].count||t[p.id].lastUsed-t[f.id].lastUsed).slice(0,3);return[...c.length?[{key:"ungrouped",label:null,items:c}]:[],...d.length?[{key:"recent",label:"Recent",items:d}]:[],...u.length?[{key:"frequent",label:"Frequently used",items:u}]:[],...Array.from(i,([f,p])=>({key:"group:"+f,label:f,items:p}))]}import{jsx as O,jsxs as ie}from"react/jsx-runtime";function yo({container:e,usage:t,objects:o,disabled:r,onSelect:n,onClose:i}){let[c,d]=bo(""),[u,f]=bo(0),p=sn(),y=an(null),x=go(c,t,o),g=x.flatMap(h=>h.items),s=Math.min(u,Math.max(0,g.length-1)),m=g[s],v=m?(m.group?m.group+" / ":"")+m.label:"No objects found";ho(()=>{y.current?.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"})},[s,c]),ho(()=>()=>{let h=e.ownerDocument;(y.current?.contains(h.activeElement)||h.activeElement===h.body)&&e.querySelector(".drawmotive-canvas-host canvas")?.focus({preventScroll:!0})},[e]);let E=0;return O("div",{className:"dm-quick-insert-backdrop",onPointerDown:h=>{h.target===h.currentTarget&&(h.preventDefault(),i())},children:O(dn,{active:!0,innerRef:y,children:ie("div",{className:"dm-quick-insert",role:"dialog","aria-modal":"true","aria-label":"Quick insert","aria-busy":r,onKeyDown:h=>{h.nativeEvent.isComposing||h.keyCode===229||h.key==="Escape"&&(h.preventDefault(),h.stopPropagation(),i())},children:[ie("div",{className:"dm-quick-insert-query",children:[O(H,{name:"search"}),O("input",{"data-autofocus":!0,role:"combobox","aria-label":"Search objects","aria-expanded":"true","aria-autocomplete":"list","aria-controls":p+"-list","aria-activedescendant":g.length?p+"-"+s:void 0,"aria-describedby":p+"-hint",className:"dm-quick-insert-search",placeholder:"Search objects\u2026",value:c,readOnly:r,"aria-disabled":r,onChange:h=>{d(h.target.value),f(0)},onKeyDown:h=>{if(!(h.nativeEvent.isComposing||h.keyCode===229||h.altKey||h.ctrlKey||h.metaKey)&&["ArrowDown","ArrowUp","Home","End","Enter"].includes(h.key)){if(c&&["Home","End"].includes(h.key))return;h.preventDefault(),h.key==="Enter"?!h.repeat&&g[s]&&!r&&n(g[s].id):g.length&&f(h.key==="Home"?0:h.key==="End"?g.length-1:(s+(h.key==="ArrowDown"?1:-1)+g.length)%g.length)}}}),O("span",{className:"dm-quick-insert-count","aria-label":"Matching objects",children:new Set(g.map(h=>h.id)).size}),O("button",{type:"button",className:"dm-quick-insert-close","aria-label":"Close quick insert",title:"Close (Esc)",onPointerDown:h=>h.preventDefault(),onClick:i,children:O(H,{name:"close"})})]}),ie("div",{id:p+"-list",className:"dm-quick-insert-results",role:"listbox","aria-label":"Objects",children:[x.map(h=>ie("div",{className:"dm-quick-insert-group",role:"group","aria-label":h.label??"Objects","data-ungrouped":h.label===null||void 0,children:[h.label&&O("div",{className:"dm-quick-insert-group-label","aria-hidden":"true",children:h.label}),O("div",{className:"dm-quick-insert-grid",children:h.items.map(a=>{let T=E++;return ie("button",{id:p+"-"+T,type:"button",className:"dm-quick-insert-option",role:"option","aria-selected":T===s,tabIndex:-1,disabled:r,"aria-label":(a.group?a.group+" / ":"")+a.label,title:(a.group?a.group+" / ":"")+a.label+(a.shortcut?" ("+a.shortcut+")":""),onPointerMove:()=>f(T),onPointerDown:A=>A.preventDefault(),onClick:()=>{n(a.id)},children:[a.iconUrl?O("img",{src:a.iconUrl,alt:"","aria-hidden":"true"}):O(H,{name:a.id}),O("span",{children:a.label})]},a.id)})})]},h.key)),!g.length&&O("div",{className:"dm-quick-insert-empty",role:"status",children:"No objects found"})]}),ie("div",{className:"dm-quick-insert-hint",children:[O("span",{className:"dm-quick-insert-detail",title:v,children:v}),m?.shortcut&&O("kbd",{title:"Tool shortcut",children:m.shortcut}),ie("span",{id:p+"-hint",className:"dm-quick-insert-keys","aria-label":"Up and down to navigate, Enter to choose, Escape to close",children:["\u2191\u2193 ",O("kbd",{children:"\u21B5"})," ",O("kbd",{children:"Esc"})]})]})]})})})}import{jsx as S,jsxs as G}from"react/jsx-runtime";var vo={revision:null,health:"healthy",editingEnabled:!1,busy:!0,canUndo:!1,canRedo:!1};function fn(e,t){let o=ce.find(n=>n===t);if(o===void 0||o==="sketchyMode")throw new TypeError("Unknown drawing tool: "+t);return e.setTool.call(e,o)}function Ze(e){let t=te({editor:e.editor,key:0});return t.current.editor!==e.editor&&(t.current={editor:e.editor,key:t.current.key+1}),S(gn,{...e},t.current.key)}function gn(e){let[t,o]=j(null);bt(()=>{if(e.controller)return;let n=Ye(e.editor,e.options);return o({editor:e.editor,options:e.options,controller:n}),()=>n.dispose()},[e.editor,e.options,e.controller]);let r=e.controller??(t?.editor===e.editor&&t.options===e.options?t.controller:null);if(!r)return null;if(r.editor!==e.editor)throw new TypeError("UI controller belongs to a different editor");return S(hn,{...e,controller:r})}function hn({editor:e,controller:t,container:o,slots:r={},colorScheme:n,className:i="",style:c,onError:d}){let[u,f]=j(t.ui),[p,y]=j(vo),[x,g]=j(null),[s,m]=j({}),[v,E]=j(null),[h,a]=j(null),[T,A]=j(new Set),[_,Pe]=j(e.lifecycle!=="ready"),[le,me]=j(null),[Ie,w]=j(!1),[q]=j(()=>fo(()=>o.ownerDocument.defaultView.localStorage)),Q=c?.fontFamily,$=te(!1),fe=te(new Set),ze=te(null),se=te(null),Re=te(null),vt=te(vo),[ko,wo]=j({left:0,top:0}),xt=te(d);xt.current=d;let ge=Ve(l=>{if($.current){a(l);try{xt.current?.(l)}catch{}}},[]);bt(()=>{if(_)return;$.current=!0;let l=!1,b=0,I=0,D=[e.onStateChanged(P=>{vt.current=P,y(P)}),t.onChanged(f),e.onEvent("selectionChanged",P=>{let V=Re.current;b++,Re.current=P,g(be(P)),V&&(V.token.session!==P.token.session||V.token.version!==P.token.version)&&E(K=>K==="settings"||K==="drawingProperties"?K:null)}),e.onPreferencesChanged(P=>{I++,m(P)}),e.onDisposed(()=>Pe(!0))],L=P=>{l||ge(P)};return e.getSelection().then(P=>{!l&&b===0&&(Re.current=P,g(be(P)))},L),e.getPreferences().then(P=>{!l&&I===0&&m(P)},L),()=>{l=!0,$.current=!1,D.forEach(P=>P())}},[e,t,_,ge]);let X=Ve(async(l,b="document")=>{if(!$.current||fe.current.has(b))return!1;fe.current.add(b),A(new Set(fe.current)),a(null);try{return await l(),!0}catch(I){return ge(I),!1}finally{fe.current.delete(b),$.current&&A(new Set(fe.current))}},[ge]),ae=Ve((l,b,I)=>x?X(async()=>{me(x.token);try{await e.editScene(Oe(x,l,b,I))}finally{$.current&&me(null)}}):Promise.resolve(!1),[e,x,X]),Fe=Ve(async l=>{await fn(e,l),$.current&&q.record(l)},[e,q]);ro({editor:e,container:o,ui:u,state:()=>vt.current,selection:()=>Re.current,run:X,report:ge,activateTool:Fe,openQuickInsert:()=>{E(null),w(!0)}});let So=async l=>{await X(()=>e.setPreferences(l),"preferences")},kt=x?Z(x.items):[],Ke=kt[0],he=Et(kt,u.contextToolbar).filter(l=>l!=="editText"||e.textEditing!=="disabled"),oe=!p.editingEnabled||p.health!=="healthy"||p.busy||T.has("document");bt(()=>{(_||!u.enabled||!p.editingEnabled||p.health!=="healthy"||p.busy)&&w(!1)},[_,u.enabled,p.editingEnabled,p.health,p.busy]);let Eo=le!==null&&le.session===x?.token.session&&le.version===x?.token.version,To=!p.busy||Eo;if(cn(()=>{if(_||!ze.current)return;let l=ze.current,b=o.querySelector("canvas"),I=o.ownerDocument.defaultView;function D(){if(!l||!b||!se.current||!x?.anchor)return;let P=Ct(x.anchor,b.getBoundingClientRect(),{width:b.clientWidth,height:b.clientHeight},l.getBoundingClientRect(),{width:l.clientWidth,height:l.clientHeight}),V=Tt(P,{width:se.current.offsetWidth,height:se.current.offsetHeight},{width:l.clientWidth,height:l.clientHeight});wo(K=>K.left===V.left&&K.top===V.top?K:V)}D();let L=new I.ResizeObserver(D);return L.observe(l),b&&L.observe(b),se.current&&L.observe(se.current),I.addEventListener("scroll",D,!0),()=>{L.disconnect(),I.removeEventListener("scroll",D,!0)}},[o,x,_,u.enabled,p.busy,he.join(",")]),_||!u.enabled)return null;let We=n??(s.darkTheme?"dark":"light"),Ne=x?.items[0]?.resolved.themeColors,Co=Object.fromEntries(Ne&&typeof Ne=="object"&&!Array.isArray(Ne)?Object.entries(Ne).filter(([,l])=>typeof l=="string").map(([l,b])=>[nt(l),b]):[]),Po={editor:e,ui:u,state:{...p,busy:p.busy||T.has("document")},selection:x,panel:v,setPanel:E,run:X,edit:ae};function wt(l){if(!u.buttons[l])return null;let b=l==="undo"?!p.canUndo||oe:l==="redo"?!p.canRedo||oe:ce.some(D=>D===l)?oe:!1;if(l==="settings"||l==="drawingProperties")return G(re,{id:l,label:"Settings",button:S(z,{icon:"settings"}),children:[" ",S(uo,{preferences:s,onChange:So})]},l);if(l==="help")return G(re,{id:"help",button:S(z,{icon:l}),children:[" ",G("div",{className:"dm-help",children:[S("strong",{children:"Keyboard shortcuts"}),Object.entries(we).map(([D,L])=>G("div",{children:[Le[D],S("kbd",{children:L})]},D))]})]},l);let I=()=>l==="undo"||l==="redo"?e[l]():l==="sketchyMode"?e.setSketchyMode(!p.sketchyMode):l==="zoomIn"||l==="zoomOut"||l==="resetZoom"?e.zoom(l==="zoomIn"?"in":l==="zoomOut"?"out":"reset"):Fe(l);return S(z,{icon:l,shortcut:we[l],disabled:b,selected:l==="sketchyMode"?p.sketchyMode:p.tool===l,onClick:()=>{X(I,["zoomIn","zoomOut","resetZoom"].includes(l)?"viewport":"document")},children:l==="resetZoom"?G("span",{className:"dm-zoom",children:[Math.round((p.zoom??1)*100),"%"]}):void 0},l)}function Io(l){if(l.startsWith("slot."))return r[l.slice(5)]==null?null:S("span",{className:"dm-slot",children:r[l.slice(5)]},l);if(!l.startsWith("host."))return wt(l);let b=u.actions.find(I=>I.id===l);return b?.visible?G(z,{"aria-label":b.label,disabled:!b.enabled||T.has(l),className:"dm-host-action",onClick:()=>{X(()=>t.invokeAction(l),l)},children:[b.icon&&S(H,{name:b.icon}),S("span",{children:T.has(l)?b.label+"\u2026":b.label})]},l):null}async function zo(){x&&await e.copyToClipboard(x.token)}function St(l){if(l==="groupTheme")return S(dt,{inline:!0},l);let b=x.properties,I="context-toolbar-"+({strokeFillColor:"fill-color",strokeColor:"stroke-color",strokeStyle:"stroke-style",lineStartStyle:"line-start-style",lineEndStyle:"line-end-style",lineRouting:"line-connector-type",moreOptions:"more-options",groupTitleStyle:"group-title-style"}[l]??l.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()),D=l==="bold"?C(b.bold):l==="italic"?C(b.italic):l==="cornerRadius"?(C(b.cornerRadius)??0)>0:l.startsWith("textSize")?C(b.textSize)===l.slice(8):void 0,L=()=>l==="editText"?X(()=>e.beginTextEditing(Ke?.id)):l.startsWith("textSize")?ae("Set text size",B=>[R(B,["fontStyle","size"],de(B,"fontSizes",l.slice(8)))]):l==="bold"?ae("Toggle bold",B=>[R(B,["fontStyle","weight"],C(b.bold)===!0?400:700)]):l==="italic"?ae("Toggle italic",B=>[R(B,["fontStyle","slant"],C(b.italic)===!0?"Upright":"Italic")]):l==="cornerRadius"?ae("Toggle corner radius",B=>[F(B,"toggleCornerRadius")]):ae("Swap endpoints",B=>[R(B,["startStyle"],B.model.endStyle),R(B,["endStyle"],B.model.startStyle)]),P=l==="strokeFillColor"?G("span",{className:"dm-stroke-fill","data-transparent":C(b.fillColor)?.role==="Transparent"?"":void 0,children:[S(ue,{fill:ne(C(b.fillColor)?.role,C(b.fillColor)?.argb),style:{color:ne(C(b.fillColor)?.role==="Transparent"?"SecondaryStroke":C(b.fillColor)?.role)}}),S(ue,{style:{color:ne(C(b.strokeColor)?.role,C(b.strokeColor)?.argb)}})]}):l==="lineStartStyle"||l==="lineEndStyle"?S(ke,{value:C(l==="lineStartStyle"?b.lineStartStyle:b.lineEndStyle)??0,start:l==="lineStartStyle"}):void 0,V=Ge.includes(l),K=S(z,{icon:l,"data-testid":I,selected:D,shortcut:we[l],disabled:l==="swapLineEndpoints"&&b.lineStartStyle.state==="Uniform"&&b.lineEndStyle.state==="Uniform"&&C(b.lineStartStyle)===C(b.lineEndStyle),onClick:V?void 0:()=>{L()},children:P});return V?S(re,{id:l,button:K,children:{strokeFillColor:S(je,{fill:!0}),strokeColor:S(je,{}),strokeStyle:S(Jt,{}),textAlign:S(st,{}),lineStartStyle:S(at,{start:!0}),lineEndStyle:S(at,{start:!1}),lineRouting:S(Yt,{}),groupTheme:S(dt,{}),groupTitleStyle:S(to,{}),numbering:S(no,{item:Ke}),moreOptions:S(oo,{copy:zo})}[l]},l):S("span",{children:K},l)}return S("div",{ref:ze,className:"dm-editor-ui "+i,style:{fontFamily:Q,...Co,...c},"data-mantine-color-scheme":We,children:S(pn,{inherit:!1,children:S(un,{forceColorScheme:We,theme:mn(lt,_t(We==="dark"),Q?{fontFamily:Q,headings:{fontFamily:Q}}:{}),cssVariablesSelector:".dm-editor-ui",getRootElement:()=>ze.current??void 0,children:G(rt.Provider,{value:Po,children:[Object.entries(u.regions).map(([l,b])=>{let I=b.items.map(Io).filter(Boolean);return b.visible&&I.length>0?S(De.Provider,{value:l.startsWith("top")?"bottom":"top",children:S("div",{className:"dm-toolbar dm-corner dm-"+l,role:"toolbar","aria-label":l+" toolbar","data-region":l,children:I})},l):null}),u.drawingToolbar.visible&&u.drawingToolbar.tools.some(l=>u.buttons[l])&&S(De.Provider,{value:{left:"right",right:"left",top:"bottom",bottom:"top"}[u.drawingToolbar.position],children:S("fieldset",{className:"dm-toolbar dm-drawing dm-"+u.drawingToolbar.position,disabled:oe,"aria-label":"Drawing tools","data-testid":"drawing-toolbar",children:u.drawingToolbar.tools.map(wt)})}),S(Wt,{container:o}),Ie&&S(yo,{container:o,usage:q.read(),disabled:oe,objects:Ce.filter(l=>u.buttons[l.id]).map(l=>({...l,shortcut:we[l.id]})),onClose:()=>w(!1),onSelect:async l=>{oe||!u.buttons[l]||await X(()=>Fe(l))&&w(!1)}}),x&&x.anchor&&he.length>0&&To&&S("fieldset",{ref:se,className:"dm-toolbar dm-context",disabled:oe,style:ko,"aria-label":"Selection tools","data-testid":"context-toolbar","data-item-id":Ke?.id,children:he.map((l,b)=>{if(l.startsWith("textSize")&&he[b-1]?.startsWith("textSize"))return null;let I=l.startsWith("textSize")?he.slice(b).filter((D,L,P)=>P.slice(0,L+1).every(V=>V.startsWith("textSize"))):null;return G("span",{className:"dm-context-entry",children:[b>0&&(I||["bold","textAlign","strokeColor","strokeFillColor","moreOptions"].includes(l))&&S(Be,{}),I?S("span",{className:"dm-button-group",children:I.map(St)}):St(l)]},l)})}),h!=null&&G("div",{className:"dm-error",role:"alert",children:[S("span",{children:h?.message??String(h)}),S(z,{"aria-label":"Dismiss error",icon:"close",onClick:()=>a(null)})]})]})})})})}import{createRoot as bn}from"react-dom/client";import{jsx as vn}from"react/jsx-runtime";function yn({editor:e,container:t,...o}){let r=t.ownerDocument.defaultView,n=t.style.position,i=r.getComputedStyle(t).position==="static";i&&(t.style.position="relative");let c=t.ownerDocument.createElement("div");c.style.cssText="position:absolute;inset:0;pointer-events:none;",t.append(c);let d=bn(c),u=!1,f,p=()=>{u||(u=!0,f?.(),d.unmount(),c.remove(),i&&t.style.position==="relative"&&(t.style.position=n))};return d.render(vn(Ze,{editor:e,container:t,...o})),f=e.onDisposed(p),{dispose:p}}import{jsx as xo,jsxs as Sn}from"react/jsx-runtime";function pl({className:e,style:t,slots:o,colorScheme:r,onReady:n,onError:i,ui:c,...d}){let u=yt(null),f=yt({onReady:n,onError:i});f.current={onReady:n,onError:i};let p=yt(Promise.resolve()),[y,x]=kn(null);return xn(()=>{let g=!1,s,m,v=new AbortController,E=()=>v.abort(d.signal?.reason);d.signal?.addEventListener("abort",E,{once:!0}),d.signal?.aborted&&E(),x(null);let h=p.current,a=h.then(async()=>{if(g)return;let T=await wn({...d,container:u.current,signal:v.signal});s=T,!g&&(m=T.onDisposed(()=>x(null)),x(T),f.current.onReady?.(T))});return a.catch(T=>{g||f.current.onError?.(T)}),()=>{g=!0,v.abort(),d.signal?.removeEventListener("abort",E),m?.(),p.current=h.then(()=>a.catch(T=>{if(T?.code==="DisposeCleanupUnconfirmed")throw T})).then(async()=>{s&&await s.dispose()}),p.current.catch(T=>f.current.onError?.(T))}},[d.assetBaseUrl,d.licenseKey,d.textEditing,c,d.persistence,d.workerFactory,d.workerUrls,d.signal,d.title,d.startupTimeoutMs,d.disposeTimeoutMs]),Sn("div",{className:e,style:{position:"relative",width:"100%",height:"100%",...t},children:[xo("div",{ref:u,style:{position:"absolute",inset:0}}),y&&xo(Ze,{options:c,editor:y,container:u.current,slots:o,colorScheme:r,onError:i})]})}export{pl as Editor,Ze as EditorUi,Ye as createEditorUiController,yn as mountEditorUi,lt as phosphorTheme};
|
|
1
|
+
import{useEffect as ri,useRef as Ht,useState as ni}from"react";import{createEditor as ii}from"@drawmotive/editor";import{useCallback as dt,useEffect as Lt,useLayoutEffect as Ko,useRef as he,useState as oe}from"react";import{Loader as Kn,MantineProvider as Wn,MantineThemeProvider as _n,mergeThemeOverrides as Qn}from"@mantine/core";var li=Object.freeze(["strokeFillColor","strokeColor","strokeStyle","cornerRadius","editText","textSizeSmall","textSizeMedium","textSizeLarge","bold","italic","textAlign","lineStartStyle","lineEndStyle","swapLineEndpoints","lineRouting","groupTheme","groupTitleStyle","numbering","group","moreOptions"]),pt=Object.freeze(["strokeFillColor","strokeColor","strokeStyle","textAlign","lineStartStyle","lineEndStyle","lineRouting","groupTitleStyle","numbering","moreOptions"]);function se(e){let t=e.length===2&&e.find(r=>r.kind==="BoundText"&&e.some(o=>o.id===r.bindingItemId));return t?[t]:e}function mt(e){let t=e.resolved?.numbering;if(!t||typeof t!="object"||Array.isArray(t))return;let{number:r,prefix:o,maximum:n,drawingEnabled:i}=t;if((r===null||Number.isSafeInteger(r)&&r>0)&&typeof o=="string"&&Number.isSafeInteger(n)&&n>=0&&typeof i=="boolean")return t}function Kt(e,t,r=0){if(e=se(e),!t.visible||!e.length||e.some(i=>t.objectTypes&&!t.objectTypes.includes(i.kind)))return[];let o=i=>e.every(s=>s.capabilities[i]),n=[];return o("text")?n.push("strokeColor","textSizeSmall","textSizeMedium","textSizeLarge","bold","italic","textAlign"):(o("line")&&n.push("lineStartStyle","swapLineEndpoints","lineEndStyle","lineRouting"),o("group")&&(n.push("groupTheme"),e.length===1&&o("groupTitle")&&n.push("groupTitleStyle")),o("stroke")&&n.push(o("fill")?"strokeFillColor":"strokeColor"),o("stroke")&&n.push("strokeStyle"),o("cornerRadius")&&n.push("cornerRadius")),o("editText")&&e.length===1&&n.push("editText"),e.length===1&&mt(e[0])&&n.push("numbering"),r>1&&n.push("group"),n.push("moreOptions"),n.filter(i=>(!t.tools||t.tools.includes(i))&&(!pt.includes(i)||!t.panels||t.panels.includes(i)))}function Wt(e,t,r){let o=(n,i,s)=>Math.max(4,Math.min(n,i-s-4));return{left:o(e.left,r.width,t.width),top:o(e.top-t.height-10>=4?e.top-t.height-10:e.bottom+10,r.height,t.height)}}function $e(e,t,r,o,n){let i=c=>(t.left-o.left+c*t.width/(r.width||1))*(n.width||1)/(o.width||1),s=c=>(t.top-o.top+c*t.height/(r.height||1))*(n.height||1)/(o.height||1);return{left:i(e.left),top:s(e.top),right:i(e.right),bottom:s(e.bottom)}}var Qt=Object.freeze({state:"Unavailable"}),J=e=>({state:"Uniform",value:e}),$t=["strokeColor","fillColor","strokeWidth","strokeStyle","cornerRadius","textSize","resolvedTextSize","bold","italic","horizontalAlignment","verticalAlignment","lineStartStyle","lineEndStyle","lineRouting","groupColorRole","groupHeaderVisible"],ft=(e,t,r)=>Object.entries(e.resolved?.themeValues?.[t]??{}).find(([,o])=>o===r)?.[0]??null,_t=(e,t)=>{let r=ft(e,"colors",t);return{role:r,argb:r===null?t??null:null}};function Ie(e,t,r){let o=e.resolved?.themeValues?.[t]?.[r];if(o===void 0)throw new Error("The selection does not provide the requested theme role: "+r);return o}function Xt(e){let t=e.model,r=e.capabilities,o=e.resolved??{},n=t.data?.paintStyle??{},i=t.fontStyle??{},s=o.fontStyle??{},c=Object.fromEntries($t.map(m=>[m,Qt]));return c.strokeColor=J(_t(e,r.text?i.color:n.color)),r.text?(Object.assign(c,{textSize:J(ft(e,"fontSizes",i.size)??i.size),resolvedTextSize:J(s.size),bold:J(s.weight===700),italic:J(s.slant==="Italic"),horizontalAlignment:J(s.textAlign??"Center")}),r.verticalTextAlignment&&(c.verticalAlignment=J(s.verticalTextAlign??"Center"))):(c.strokeWidth=J(ft(e,"lineWidths",n.strokeWidth)??n.strokeWidth),c.strokeStyle=J(n.strokeClass??"Solid"),r.fill&&(c.fillColor=J(_t(e,n.fillColor))),r.cornerRadius&&(c.cornerRadius=J(o.cornerRadius??0))),r.line&&Object.assign(c,{lineStartStyle:J(t.startStyle??0),lineEndStyle:J(t.endStyle??1),lineRouting:J(r.connectorRouting?t.routing??"Straight":"Straight")}),r.group&&Object.assign(c,{groupColorRole:J(o.groupColorRole??null),groupHeaderVisible:J(o.groupHeaderVisible??!0)}),{...e,properties:c,...e.boundText?{boundText:Xt(e.boundText)}:{}}}function Me(e){let t=e.items.map(Xt),r=se(t),o=Object.fromEntries($t.map(n=>{let i=r.map(c=>c.properties[n]);if(!i.length||i.some(c=>c.state==="Unavailable"))return[n,Qt];let s=i[0];return[n,i.every(c=>JSON.stringify(c.value)===JSON.stringify(s.value))?s:{state:"Mixed"}]}));return{...e,items:t,properties:o}}var V=(e,t,r)=>({itemId:e.id,path:t,value:r}),de=(e,t,...r)=>({itemId:e.id,op:"call",path:[t],arguments:r});function Xe(e,t,r,o){return{revision:e.revision,description:t,token:e.token,changes:(o?[o]:se(e.items)).flatMap(r)}}import{EditorError as Ae}from"@drawmotive/editor";var Ye=Object.freeze(["undo","redo","selectObjects","arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode","drawingProperties","zoomIn","zoomOut","resetZoom","settings","help"]),ht=Object.freeze(["topLeft","topRight","bottomLeft","bottomRight"]),Re=Object.freeze(["arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode"]),eo=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Jt=e=>typeof e=="string"&&/^host[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e),nr=e=>typeof e=="string"&&/^slot[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e);function je(e,t,r){if(!eo(e))throw new TypeError(r+" must be an object");for(let o of Object.keys(e))if(!t.includes(o))throw new TypeError("Unknown "+r+" option: "+o)}function Ue(e,t){if(typeof e!="boolean")throw new TypeError(t+" must be a boolean");return e}function Yt(e,t){if(typeof e!="string"||!e.trim())throw new TypeError(t+" must be a nonempty string");return e}function gt(e,t,r=o=>typeof o=="string"&&!!o.trim()){if(!Array.isArray(e)||e.some(o=>!r(o))||new Set(e).size!==e.length)throw new TypeError(t+" must contain distinct valid IDs");return Object.freeze([...e])}function Je(e,t,r){return e===void 0?{}:typeof e=="boolean"?{visible:e}:(je(e,["visible",...t],r),e.visible!==void 0&&Ue(e.visible,r+".visible"),e)}function bt(e={}){e===!1&&(e={enabled:!1}),je(e,["enabled","buttons","actions","regions","drawingToolbar","contextToolbar","tooltip"],"ui");let t=e.enabled===void 0?!0:Ue(e.enabled,"ui.enabled"),r=e.buttons??{};je(r,Ye,"ui.buttons");let o=Object.fromEntries(Ye.map(u=>[u,u!=="help"]));for(let[u,E]of Object.entries(r))o[u]=Ue(E,"ui.buttons."+u);let n=new Map;if(e.actions!==void 0&&!Array.isArray(e.actions))throw new TypeError("ui.actions must be an array");let i=(e.actions??[]).map(u=>{if(je(u,["id","label","icon","visible","enabled","onInvoke"],"action"),!Jt(u.id))throw new TypeError("Action id must use the host. namespace");if(n.has(u.id))throw new TypeError("Duplicate action id: "+u.id);if(typeof u.onInvoke!="function")throw new TypeError("Action "+u.id+" requires an onInvoke handler");let E={id:u.id,label:Yt(u.label,"Action label"),enabled:u.enabled===void 0?!0:Ue(u.enabled,"Action enabled"),visible:u.visible===void 0?!0:Ue(u.visible,"Action visible")};return u.icon!==void 0&&(E.icon=Yt(u.icon,"Action icon")),n.set(u.id,u.onInvoke),Object.freeze(E)}),s=e.regions??{};je(s,ht,"ui.regions");let c=new Set(Object.values(s).flatMap(u=>eo(u)&&Array.isArray(u.items)?u.items.filter(Jt):[])),m={topLeft:["undo","redo","selectObjects"],topRight:["help",...i.filter(u=>!c.has(u.id)).map(u=>u.id)],bottomLeft:[],bottomRight:["zoomOut","resetZoom","zoomIn","settings"]},l=Object.fromEntries(ht.map(u=>{let E=Je(s[u],["items"],"ui.regions."+u);return[u,Object.freeze({visible:t&&(E.visible??!0),items:gt(E.items??m[u],"ui.regions."+u+".items",R=>Ye.includes(R)||n.has(R)||nr(R))})]})),p=Je(e.drawingToolbar,["position","tools"],"ui.drawingToolbar"),g=p.position??"left";if(!["left","right","top","bottom"].includes(g))throw new TypeError("ui.drawingToolbar.position must be left, right, top or bottom");let x=Object.freeze({visible:t&&(p.visible??!0),position:g,tools:gt(p.tools??Re.filter(u=>u!=="sketchyMode"),"ui.drawingToolbar.tools",u=>Re.includes(u))}),y=Je(e.contextToolbar,["objectTypes","tools","panels"],"ui.contextToolbar"),h={visible:t&&(y.visible??!0)};for(let u of["objectTypes","tools","panels"])y[u]!==void 0&&(h[u]=gt(y[u],"ui.contextToolbar."+u));let d=Je(e.tooltip,["position","delay"],"ui.tooltip"),f=d.position??"top",w=d.delay??250;if(!["top","bottom","left","right"].includes(f))throw new TypeError("ui.tooltip.position must be top, bottom, left or right");if(!Number.isFinite(w)||w<0)throw new TypeError("ui.tooltip.delay must be nonnegative");let b=Object.freeze({visible:d.visible??!0,position:f,delay:w});return Object.freeze({ui:Object.freeze({enabled:t,buttons:Object.freeze(o),actions:Object.freeze(i),regions:Object.freeze(l),drawingToolbar:x,contextToolbar:Object.freeze(h),tooltip:b}),handlers:n})}function yt(e,t){let{ui:r,handlers:o}=bt(t),n=r,i=!1,s=new Set,c=new Set,m=()=>new Ae("EditorDisposed","Editor UI has been disposed"),l=()=>{if(i||e.lifecycle!=="ready")throw m()},p,g,x=()=>{if(!i){i=!0,p?.(),g?.();for(let y of c)y.abort(m());c.clear(),o.clear(),s.clear()}};return e.lifecycle==="ready"?(g=e.onEvent("disposing",x),p=e.onDisposed(x)):x(),Object.freeze({get ui(){return n},editor:e,dispose:x,onChanged(y){if(l(),typeof y!="function")throw new TypeError("Listener must be a function");s.add(y);try{y(n)}catch(h){throw s.delete(y),h}return()=>s.delete(y)},async invokeAction(y){l();let h=o.get(y),d=n.actions.find(w=>w.id===y);if(!h)throw new Ae("UnknownAction","Unknown host action: "+y);if(!d.enabled||!d.visible)throw new Ae("ActionUnavailable","Host action is unavailable: "+y);let f=new AbortController;c.add(f);try{await h({editor:e,signal:f.signal})}catch(w){throw w instanceof Ae?w:new Ae(typeof w?.code=="string"?w.code:"HostActionFailed",w?.message??String(w),{cause:w})}finally{c.delete(f)}},async setActionState(y,h){if(l(),!o.has(y))throw new TypeError("Unknown host action: "+y);if(!h||typeof h!="object"||Array.isArray(h)||Object.keys(h).some(f=>!["label","enabled","visible"].includes(f)))throw new TypeError("Invalid action state");let d={};if(h.label!==void 0){if(typeof h.label!="string"||!h.label.trim())throw new TypeError("Action label must be a nonempty string");d.label=h.label}for(let f of["enabled","visible"])if(h[f]!==void 0){if(typeof h[f]!="boolean")throw new TypeError("Action "+f+" must be a boolean");d[f]=h[f]}n=Object.freeze({...n,actions:Object.freeze(n.actions.map(f=>f.id===y?Object.freeze({...f,...d}):f))});for(let f of s)try{f(n)}catch(w){console.error("Editor UI listener failed",w)}}})}import{cloneElement as Fr,createContext as so,forwardRef as Zr,useContext as co,useLayoutEffect as Kr,useMemo as Wr,useRef as lo,useState as _r}from"react";import{Kbd as Qr,Popover as wt,Tooltip as $r,UnstyledButton as Xr}from"@mantine/core";import{AlignBottomSimple as ir,AlignCenterVerticalSimple as ar,AlignTopSimple as lr,ArrowBendRightUp as sr,ArrowBendUpLeft as dr,ArrowBendUpRight as cr,ArrowDownRight as ur,ArrowElbowRightUp as pr,ArrowRight as mr,ArrowUpRight as fr,Browser as gr,Circle as hr,Cloud as br,Copy as yr,Cursor as vr,Diamond as xr,DotsThreeVertical as wr,GearSix as kr,Hash as Sr,Image as Er,SelectionAll as Cr,SelectionPlus as Tr,MagnifyingGlass as Pr,MagnifyingGlassMinus as Ir,MagnifyingGlassPlus as Rr,Minus as no,Palette as io,Path as Or,Pill as zr,Prohibit as Nr,Question as Dr,Rectangle as ao,Scribble as Mr,Star as jr,TextAlignCenter as to,TextAlignLeft as Ur,TextAlignRight as Ar,TextB as Br,Textbox as oo,TextItalic as Lr,TextT as et,Trash as Hr,X as Gr}from"@phosphor-icons/react";import{jsx as Y}from"react/jsx-runtime";var qr={undo:dr,redo:cr,arrow:ur,rectangle:ao,ellipse:hr,diamond:xr,text:et,capsule:zr,star:jr,cloud:br,select:vr,sketchyMode:Mr,zoomIn:Rr,zoomOut:Ir,settings:kr,drawingProperties:io,help:Dr,editText:oo,search:Pr,bold:Br,italic:Lr,textAlign:to,textSizeSmall:et,textSizeMedium:et,textSizeLarge:et,textAlignLeft:Ur,textAlignCenter:to,textAlignRight:Ar,textAlignTop:lr,textAlignMiddle:ar,textAlignBottom:ir,lineRouting:Or,routingStraight:fr,routingOrthogonal:pr,routingCurved:sr,group:Tr,selectObjects:Cr,groupTheme:gr,groupTitleStyle:oo,numbering:Sr,moreOptions:wr,copy:yr,image:Er,delete:Hr,close:Gr,transparent:Nr};var Vr={roundedCorner:{viewBox:"0 0 24 24",path:"M3,21V19H5v2H3Zm0-4V15H5v2H3Zm0-4V11H5v2H3ZM3,9V7H5V9H3ZM3,5V3H5V5H3ZM7,21V19H9v2H7ZM7,5V3H9V5H7Zm4,16V19h2v2H11Zm4,0V19h2v2H15Zm4,0V19h2v2H19Zm0-4V15h2v2H19Zm2-4H19V8q0-1.25-0.88-2.13T16,5H11V3h5q2.07,0 3.54,1.46Q21,5.93 21,8v5Z"},lineStyle:{viewBox:"0 -960 960 960",path:"M120-160v-80h80v80h-80Zm0-160v-80h200v80H120Zm0-160v-80h320v80H120Zm0-160v-160h720v160H120Zm160 480v-80h80v80h-80Zm100-160v-80h200v80H380Zm60 160v-80h80v80h-80Zm80-320v-80h320v80H520Zm80 320v-80h80v80h-80Zm40-160v-80h200v80H640Zm120 160v-80h80v80h-80Z"},lineEndArrowNotch:{viewBox:"0 -960 960 960",path:"m440-200 137-240H80v-80h497L440-760l440 280-440 280Z"},lineEndCircle:{viewBox:"0 -960 960 960",path:"M640-240q-90 0-156.5-57T403-440H80v-80h323q14-86 80.5-143T640-720q100 0 170 70t70 170q0 100-70 170t-170 70Z"},lineEndDiamond:{viewBox:"0 -960 960 960",path:"M600-200 360-440H80v-80h280l240-240 280 280-280 280Z"}};function vt({name:e,size:t,mirrored:r=!1,style:o}){let n=Vr[e];return Y("svg",{viewBox:n.viewBox,width:t,height:t,fill:"currentColor","aria-hidden":"true",style:o,children:Y("g",{transform:r?"translate(960 0) scale(-1 1)":void 0,children:Y("path",{d:n.path})})})}function ee({name:e,style:t}){if(e==="strokeColor"||e==="strokeFillColor")return Y(Oe,{style:t});if(e==="lineStartStyle"||e==="lineEndStyle")return Y(Be,{value:1,start:e==="lineStartStyle",style:t});if(e==="strokeStyle")return Y(vt,{name:"lineStyle",size:19,style:t});if(e==="cornerRadius")return Y(vt,{name:"roundedCorner",size:19,style:t});if(e==="swapLineEndpoints")return Y("svg",{viewBox:"0 0 1024 1024",width:"19",height:"19",fill:"currentColor","aria-hidden":"true",style:t,children:Y("path",{d:"M723.498667 512l-170.666667-170.666667v341.333334z m-426.666667 0l170.666667 170.666667V341.333333z"})});let r=qr[e]??ao;return Y(r,{size:e==="textSizeSmall"?14:e==="textSizeLarge"?24:19,weight:"regular","aria-hidden":"true",style:t})}function Oe({fill:e="none",style:t}){return Y(io,{size:20,weight:"duotone",className:"dm-palette","aria-hidden":"true",style:{"--dm-palette-fill":e,...t}})}var ro={Solid:"M134.613333 776.106667l-41.130666-71.253334L886.272 245.333333l41.130667 71.253334z",Dashed:"M124.373333 781.141333l-41.173333-71.253333 127.744-75.52 41.130667 71.253333z m238.165334-135.765333l-41.130667-71.253333 131.242667-75.776 41.130666 71.253333z m238.08-139.178667l-41.173334-71.253333 120.234667-69.418667 41.130667 71.253334z m224.853333-129.877333l-41.088-71.253333 120.234667-69.418667 41.130666 71.253333z",Dotted:"M122.368 781.866667l-41.130667-71.253334 53.802667-32.853333 41.130667 71.253333z m112.384-63.104l-41.173333-71.253334 57.344-33.066666 41.130666 71.253333z m116.309333-66.944l-41.130666-71.253334 57.301333-33.066666 41.130667 71.253333z m113.109334-63.786667l-41.130667-71.253333 57.301333-33.066667 41.130667 71.253333z m110.848-64l-41.130667-71.253333 57.301333-33.066667 41.130667 71.253333z m108.885333-64.512l-41.173333-71.253333 57.344-33.109334 41.130666 71.253334z m104.106667-60.117333l-41.173334-71.253334 57.344-33.066666 41.130667 71.253333z m102.272-62.72l-41.130667-71.253334 57.301333-33.066666 41.130667 71.253333z"};function xt({width:e,pattern:t}){return t===void 0?Y(no,{size:20,weight:e===0?"thin":e===2?"bold":"regular","aria-hidden":"true"}):Y("svg",{viewBox:"0 0 1024 1024",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:Y("path",{d:ro[t]??ro.Solid})})}function Be({value:e,start:t=!1,style:r}){return e<=2?Y(e===0?no:mr,{size:22,weight:e===2?"fill":"regular",mirrored:t,"aria-hidden":"true",style:r}):Y(vt,{name:e===3?"lineEndArrowNotch":e===4?"lineEndCircle":"lineEndDiamond",size:22,mirrored:t,style:r})}import{jsx as Se,jsxs as uo}from"react/jsx-runtime";var kt=so(null),tt=so(void 0);function K(){let e=co(kt);if(!e)throw new Error("Editor controls need EditorUi");return e}var O=e=>e?.state==="Uniform"?e.value:void 0,Le={undo:"Undo",redo:"Redo",arrow:"Arrow",rectangle:"Rectangle",ellipse:"Ellipse",diamond:"Diamond",text:"Text",sketchyMode:"Sketchy mode",capsule:"Capsule",star:"Star",cloud:"Cloud",zoomIn:"Zoom in",zoomOut:"Zoom out",resetZoom:"Reset zoom",settings:"Settings",drawingProperties:"Drawing properties",help:"Help",strokeFillColor:"Border and Fill Color",strokeColor:"Color",strokeStyle:"Line style",cornerRadius:"Round corners",editText:"Edit text",textSizeSmall:"Small text",textSizeMedium:"Medium text",textSizeLarge:"Large text",bold:"Bold",italic:"Italic",textAlign:"Text alignment",lineStartStyle:"Start style",lineEndStyle:"End style",swapLineEndpoints:"Swap endpoints",lineRouting:"Connector type",groupTheme:"Group theme",groupTitleStyle:"Title style",numbering:"Numbering",moreOptions:"More options",group:"Group",ungroup:"Ungroup",deleteGroup:"Ungroup selected frame",renameGroup:"Rename group",selectObjects:"Select objects\u2026",copy:"Copy selection",paste:"Paste selection",delete:"Delete selection",cancel:"Cancel interaction",pan:"Pan canvas",quickInsert:"Quick insert"},ze={undo:"Ctrl/\u2318 Z",redo:"Ctrl/\u2318 Shift Z",arrow:"A",rectangle:"R",ellipse:"O",diamond:"D",text:"T",sketchyMode:"S",bold:"Ctrl/\u2318 B",italic:"Ctrl/\u2318 I",editText:"Enter",group:"Ctrl/\u2318 G",ungroup:"Ctrl/\u2318 Shift G",renameGroup:"Enter",copy:"Ctrl/\u2318 C",paste:"Ctrl/\u2318 V",delete:"Delete",deleteGroup:"Delete",cancel:"Escape",pan:"Space (hold)",quickInsert:"/"},D=Zr(function({icon:t,children:r,selected:o,shortcut:n,className:i="",...s},c){let{ui:m}=K(),l=s["aria-label"]??Le[t??""]??t??"",p=co(tt)??m.tooltip.position;return Se($r,{label:uo("span",{style:{display:"inline-flex",alignItems:"center",gap:8},children:[l,n&&Se(Qr,{size:"xs",children:n})]}),position:p,offset:12,openDelay:m.tooltip.delay,disabled:!m.tooltip.visible,events:{hover:!0,focus:!0,touch:!1},withinPortal:!1,withArrow:!0,zIndex:100,children:Se(Xr,{ref:c,...s,className:"dm-tool "+i,"aria-label":l,"aria-pressed":o,"data-selected":o===!0?"":void 0,children:r??Se(ee,{name:t??""})})})});function Ce({id:e,button:t,children:r,label:o,nested:n=!1,position:i="top-start"}){let{panel:s,setPanel:c,state:m}=K(),[l,p]=_r(!1),g=n?l:s===e,x=f=>n?p(f):c(f?e:null),y=Wr(()=>typeof document>"u"||!document.activeElement?.matches(".drawmotive-canvas-host canvas"),[g]),h=lo(null),d=lo(m.busy);return Kr(()=>{let f=h.current,w=f?.ownerDocument;g&&(d.current||m.busy)&&w&&w.activeElement===w.body&&f?.focus({preventScroll:!0}),d.current=m.busy},[g,m.busy]),uo(wt,{opened:g,onChange:x,position:i,offset:5,withinPortal:!1,trapFocus:!0,returnFocus:y,transitionProps:{duration:0},classNames:{dropdown:e==="moreOptions"?"dm-panel dm-more-options":"dm-panel"},children:[Se(wt.Target,{children:Fr(t,{onClick:f=>{t.props.onClick?.(f),x(!g)}})}),Se(wt.Dropdown,{ref:h,tabIndex:-1,role:"dialog","aria-label":o??Le[e]??e,children:r})]})}var ot=()=>Se("span",{className:"dm-separator",role:"separator","aria-orientation":"vertical"}),rt=({children:e})=>Se("div",{className:"dm-panel-heading",children:e});function St(e="Foreground"){return"--dm-color-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase().replace(/[^a-z-]/g,"")}function Te(e,t){if(t!=null){let r=Number(t).toString(16).padStart(8,"0");return"#"+r.slice(2)+r.slice(0,2)}return e==="Transparent"?"transparent":"var("+St(e??void 0)+", currentColor)"}import{forwardRef as Jr,useEffect as po,useImperativeHandle as Yr,useRef as Et}from"react";import{Tooltip as en}from"@mantine/core";import{jsx as mo}from"react/jsx-runtime";var tn=Jr(function({canvas:t,instruction:r,onMouseEnter:o,onMouseLeave:n},i){let s=Et({onMouseEnter:o,onMouseLeave:n}),c=Et(null),m=Et(t.matches(":hover"));return s.current={onMouseEnter:o,onMouseLeave:n},Yr(i,()=>t,[t]),po(()=>{let l=y=>{m.current=!0,c.current=y,s.current.onMouseEnter?.(y)},p=y=>{m.current=!1,s.current.onMouseLeave?.(y)},g=y=>{c.current=y},x=y=>{if(!t.hasPointerCapture(y.pointerId))return;let h=t.ownerDocument.elementFromPoint(y.clientX,y.clientY)===t;h&&!m.current?l(y):!h&&m.current&&p(y)};return t.addEventListener("mouseenter",l),t.addEventListener("mouseleave",p),t.addEventListener("mousemove",g),t.addEventListener("pointermove",x),()=>{t.removeEventListener("mouseenter",l),t.removeEventListener("mouseleave",p),t.removeEventListener("mousemove",g),t.removeEventListener("pointermove",x)}},[t]),po(()=>{r&&m.current&&c.current&&s.current.onMouseEnter?.(c.current)},[r]),null});function fo({container:e}){let{state:t,ui:r}=K(),o=e.querySelector(".drawmotive-canvas-host canvas");if(!o)return null;let n=r.tooltip.visible&&t.editingEnabled&&t.health==="healthy"?t.prompt??null:null;return mo(en.Floating,{label:n??"",disabled:!n,defaultOpened:o.matches(":hover"),withinPortal:!1,offset:18,zIndex:100,role:"tooltip","aria-live":"polite","data-testid":"creation-tooltip",children:mo(tn,{canvas:o,instruction:n})})}import{Kbd as on,Tooltip as go}from"@mantine/core";function ho(e){let t={backgroundColor:"var(--mantine-color-gray-"+(e?"2":"9")+")",color:"var(--mantine-color-"+(e?"black":"white")+")"};return{components:{Tooltip:go.extend({styles:{tooltip:t}}),TooltipFloating:go.Floating.extend({styles:{tooltip:t}}),Kbd:on.extend({styles:{root:{borderColor:"var(--mantine-color-"+(e?"dark-4":"gray-3")+")",color:"var(--mantine-color-"+(e?"dark-0":"gray-7")+")",backgroundColor:"var(--mantine-color-"+(e?"dark-6":"gray-0")+")"}}})}}}import{forwardRef as rn}from"react";import{Checkbox as nn,CloseButton as an,Loader as bo,NativeSelect as ln,PasswordInput as sn}from"@mantine/core";import{CaretUpDown as dn,Check as cn,Eye as un,EyeSlash as pn,Minus as mn,SpinnerGap as fn,X as gn}from"@phosphor-icons/react";import{jsx as He}from"react/jsx-runtime";var hn=({indeterminate:e,...t})=>He(e?mn:cn,{...t,size:"100%",weight:"bold","aria-hidden":"true"});function bn({reveal:e}){return He(e?pn:un,{size:"var(--psi-icon-size)",weight:"regular","aria-hidden":"true"})}var yn=rn(({className:e,style:t,size:r,...o},n)=>He(fn,{...o,ref:n,size:"var(--loader-size)",weight:"regular","aria-hidden":"true",className:["dm-phosphor-loader",e].filter(Boolean).join(" "),style:{color:"var(--loader-color)",...t}})),Ct={components:{Checkbox:nn.extend({defaultProps:{icon:hn}}),CloseButton:an.extend({defaultProps:{icon:He(gn,{size:"var(--cb-icon-size, 70%)",weight:"regular","aria-hidden":"true"})}}),NativeSelect:ln.extend({defaultProps:{rightSection:He(dn,{size:"1em",weight:"regular","aria-hidden":"true"})}}),PasswordInput:sn.extend({defaultProps:{visibilityToggleIcon:bn}}),Loader:bo.extend({defaultProps:{loaders:{...bo.defaultLoaders,phosphor:yn},type:"phosphor"}})}};import{NativeSelect as yo}from"@mantine/core";import{Fragment as Rt,jsx as P,jsxs as ye}from"react/jsx-runtime";var vo=["Transparent","Foreground","PrimaryStroke","SecondaryStroke","AccentStroke","SuccessStroke","WarningStroke"],vn=["Transparent","Background","PrimaryFill","SecondaryFill","AccentFill","SuccessFill","WarningFill"],xn=["Foreground","Background",...vo.slice(2)],wn=["PrimaryStroke","SecondaryStroke","AccentStroke","SuccessStroke","WarningStroke"];function nt({fill:e=!1,target:t}){let{selection:r,edit:o}=K(),n=t?.properties??r.properties;return P(Rt,{children:(e?[!1,!0]:[!1]).map(i=>{let s=i?vn:e?vo:xn,c=O(i?n.fillColor:n.strokeColor),m=i?"fill color":e?"border color":"color";return ye("div",{children:[P(rt,{children:i?"Fill Color":e?"Border Color":"Color"}),P("div",{className:"dm-panel-row",children:s.map(l=>P(D,{"aria-label":l==="Transparent"?i?"No Fill":"No Border":`${l.replace(/(Stroke|Fill)$/,"")} ${m}`,selected:c?.role===l&&c.argb===null,"data-testid":"panel-"+(i?"fill":"stroke")+"-color-"+l.toLowerCase(),onClick:()=>{o(i?"Change fill color":"Change stroke color",p=>{let g=p.capabilities.text?["fontStyle","color"]:["data","paintStyle",i?"fillColor":"color"];return[V(p,g,Ie(p,"colors",l))]},t)},children:l==="Transparent"?P(ee,{name:"transparent",style:{color:"var(--dm-color-secondary-stroke)"}}):P(Oe,{fill:i?Te(l):"none",style:{color:Te(l)}})},l))})]},String(i))})})}function xo(){let{selection:e,edit:t}=K(),r=e.properties;return ye(Rt,{children:[P(rt,{children:"Line Width"}),P("div",{className:"dm-panel-row",children:["Thin","Normal","Bold"].map((o,n)=>P(D,{"aria-label":o+" line",selected:O(r.strokeWidth)===o,"data-testid":"panel-stroke-width-"+n,onClick:()=>{t("Change stroke width",i=>[V(i,["data","paintStyle","strokeWidth"],Ie(i,"lineWidths",o))])},children:P(xt,{width:n})},o))}),P(rt,{children:"Line Style"}),P("div",{className:"dm-panel-row",children:["Solid","Dashed","Dotted"].map((o,n)=>P(D,{"aria-label":o+" line",selected:O(r.strokeStyle)===o,"data-testid":"panel-stroke-style-"+n,onClick:()=>{t("Change stroke style",i=>[V(i,["data","paintStyle","strokeClass"],o)])},children:P(xt,{pattern:o})},o))})]})}function Tt({target:e}){let{selection:t,edit:r}=K(),o=e?[e]:se(t.items),n=e?.properties??t.properties;return P(Rt,{children:[!1,...o.every(i=>i.capabilities.verticalTextAlignment)?[!0]:[]].map(i=>P("div",{className:"dm-panel-row",children:(i?["Top","Center","Bottom"]:["Left","Center","Right"]).map(s=>P(D,{"aria-label":(i?"Vertical ":"Horizontal ")+s,selected:O(i?n.verticalAlignment:n.horizontalAlignment)===s,"data-testid":"panel-text-align-"+(i?"vertical":"horizontal")+"-"+s.toLowerCase(),onClick:()=>{r("Change text alignment",c=>[V(c,["fontStyle",i?"verticalTextAlign":"textAlign"],s)],e)},children:P(ee,{name:"textAlign"+(i&&s==="Center"?"Middle":s)})},s))},String(i)))})}function Pt({start:e}){let{selection:t,edit:r}=K(),o=O(e?t.properties.lineStartStyle:t.properties.lineEndStyle);return P("div",{className:"dm-endpoint-grid",children:["None","Simple arrow","Filled arrow","Open arrow","Circle","Diamond"].map((n,i)=>P(D,{"aria-label":n,selected:o===i,"data-testid":"panel-line-"+(e?"start":"end")+"-style-"+i,onClick:()=>{r("Change endpoint style",s=>[V(s,[e?"startStyle":"endStyle"],i)])},children:P(Be,{value:i,start:e})},n))})}function wo(){let{selection:e,edit:t}=K(),r=e.items.every(o=>o.capabilities.connectorRouting);return P("div",{className:"dm-panel-row",children:["Straight","Orthogonal","Curved"].map((o,n)=>P(D,{"aria-label":o,selected:O(e.properties.lineRouting)===o,disabled:o!=="Straight"&&!r,"data-testid":"panel-line-connector-style-"+n,onClick:()=>{t("Change routing",i=>[de(i,"setRoutingMode",o)])},children:P(ee,{name:"routing"+o})},o))})}function It({inline:e=!1}){let{selection:t,edit:r}=K(),o=t.properties;return ye("div",{className:e?"dm-group-controls":"dm-panel-stack",children:[P(yo,{"aria-label":"Group theme color",label:e?void 0:"Group theme color",size:"xs",value:O(o.groupColorRole)??"auto",data:[{value:"auto",label:o.groupColorRole.state==="Mixed"?"Mixed":"Theme default"},...wn.map(n=>({value:n,label:n.replace("Stroke","")}))],onChange:n=>{let i=n.currentTarget.value;r("Change group theme color",s=>[de(s,"setThemeColorRole",i==="auto"?null:i)])}}),P(D,{icon:"groupTheme","aria-label":"Toggle title background","data-testid":"group-title-background",selected:O(o.groupHeaderVisible)===!0,onClick:()=>{r("Toggle title background",n=>[de(n,"setHeaderVisible",O(o.groupHeaderVisible)!==!0)])}}),P(ko,{label:"Restore group theme defaults",prompt:"Theme defaults",testId:"group-theme-reset",choices:["All","Border","Body","Line","Corners","Opacity","Header"],onChange:n=>r("Restore group style",i=>[de(i,"resetStyle",n)])})]})}function ko({label:e,prompt:t,testId:r,choices:o,onChange:n}){return P(yo,{"aria-label":e,"data-testid":r,size:"xs",value:"prompt",data:[{value:"prompt",label:t??e},...o.map(i=>({value:i,label:"Restore "+i.toLowerCase()}))],onChange:i=>{i.currentTarget.value!=="prompt"&&n(i.currentTarget.value)}})}function So(){let{selection:e,edit:t}=K(),r=e.items[0]?.boundText;return r?ye("div",{className:"dm-title-controls",children:[P(Ce,{id:"title-color",label:"Title color",nested:!0,button:P(D,{icon:"strokeColor"}),children:P(nt,{target:r})}),P(ot,{}),P(kn,{target:r}),P(Ce,{id:"title-align",label:"Title alignment",nested:!0,button:P(D,{icon:"textAlign"}),children:P(Tt,{target:r})}),P(ko,{label:"Restore title theme style",prompt:"Title theme defaults",testId:"group-title-theme-reset",choices:["All","Color","Size","Weight","Slant","Alignment"],onChange:o=>t("Restore title style",n=>[de(n,"resetTitleStyle",o)])})]}):null}function kn({target:e}){let{edit:t}=K(),r=e.properties;return ye("div",{className:"dm-panel-row",children:[P("span",{className:"dm-button-group",children:["Small","Medium","Large"].map(o=>P(D,{icon:"textSize"+o,selected:O(r.textSize)===o,onClick:()=>{t("Set text size",n=>[V(n,["fontStyle","size"],Ie(n,"fontSizes",o))],e)}},o))}),P(D,{icon:"bold",selected:O(r.bold)===!0,onClick:()=>{t("Toggle bold",o=>[V(o,["fontStyle","weight"],O(r.bold)===!0?400:700)],e)}}),P(D,{icon:"italic",selected:O(r.italic)===!0,onClick:()=>{t("Toggle italic",o=>[V(o,["fontStyle","slant"],O(r.italic)===!0?"Upright":"Italic")],e)}})]})}function Eo({copy:e,nodeImage:t,groupActions:r,ungroup:o}){let{editor:n,selection:i,run:s,setPanel:c}=K(),m=t?.hasImage?"Replace image":"Add image";return ye("div",{className:"dm-panel-stack",children:[r,t&&ye(D,{"aria-label":m,className:"dm-menu-item",onClick:t.choose,children:[P(ee,{name:"image"}),P("span",{children:m})]}),t?.hasImage&&ye(D,{"aria-label":"Remove image",className:"dm-menu-item",onClick:t.remove,children:[P(ee,{name:"delete"}),P("span",{children:"Remove image"})]}),["Copy","Delete"].map(l=>ye(D,{"aria-label":l,"data-testid":"panel-more-options-"+l.toLowerCase(),className:"dm-menu-item",onClick:()=>{l==="Delete"&&o?o():s(async()=>{l==="Copy"?await e():await n.deleteSelection(i.token),c(null)})},children:[P(ee,{name:l.toLowerCase()}),P("span",{children:l})]},l))]})}import{useEffect as Sn,useRef as Ge}from"react";import{getHotkeyHandler as En,useHotkeys as Cn}from"@mantine/hooks";var Tn=["alt","shift","ctrl","meta"].reduce((e,t)=>[...e,...e.map(r=>t+"+"+r)],["escape"]);function Co(e){let t=Ge(e);t.current=e;let r=Ge(new Set),o=Ge(0),n=Ge(null),i=Ge({alt:!1,shift:!1}),s=d=>d.code||d.key,c=()=>e.container.querySelector(".drawmotive-canvas-host"),m=d=>d.target===c()?.querySelector("canvas"),l=d=>d.isComposing||d.keyCode===229||["Process","Dead","Unidentified"].includes(d.key),p=()=>{let d=e.state();return e.editor.lifecycle==="ready"&&d.editingEnabled&&d.health==="healthy"};function g(d,f,{busy:w=!1,pointer:b=!1,available:u=!0,key:E="document"}={}){if(!(!m(d)||l(d)||!p())){if(r.current.has(s(d))){d.preventDefault();return}if(!(!u||!w&&e.state().busy||!b&&o.current!==0)){if(d.repeat){d.preventDefault();return}r.current.add(s(d)),d.preventDefault(),e.run(f,E)}}}function x(d,f){let w=e.selection(),b=w&&Me(w),u=b&&se(b.items);g(d,()=>{let E=b.properties[f],R=E.state==="Uniform"&&E.value===!0;return e.editor.editScene(Xe(b,"Toggle "+f,M=>[V(M,["fontStyle",f==="bold"?"weight":"slant"],f==="bold"?R?400:700:R?"Upright":"Italic")]))},{available:!!u?.length&&u.every(E=>E.capabilities.text)})}let y=()=>{let d=e.selection()?.items;return d?.length===1&&d[0].kind==="Group"},h=[...Object.entries({a:"arrow",r:"rectangle",o:"ellipse",d:"diamond",t:"text"}).map(([d,f])=>[d,w=>g(w,()=>e.activateTool(f),{available:e.ui.buttons[f]})]),["/",d=>{d.key!=="/"||d.altKey||d.ctrlKey||d.metaKey||d.shiftKey||g(d,async()=>e.openQuickInsert(),{available:e.ui.enabled})}],["s",d=>g(d,()=>e.editor.setSketchyMode(!e.state().sketchyMode),{available:e.ui.buttons.sketchyMode})],["mod+z",d=>g(d,()=>e.editor.undo(),{available:e.state().canUndo})],["mod+shift+z",d=>g(d,()=>e.editor.redo(),{available:e.state().canRedo})],["mod+y",d=>g(d,()=>e.editor.redo(),{available:e.state().canRedo})],["mod+g",d=>g(d,()=>e.groups.create(),{available:!!e.groups&&!!e.selection()?.items.length,key:"group-shortcut"})],["mod+shift+g",d=>g(d,()=>e.groups.ungroup(),{available:!!e.groups&&y(),key:"group-shortcut"})],["delete",d=>{e.groups&&y()?g(d,()=>e.groups.ungroup(),{key:"group-shortcut"}):g(d,()=>e.editor.deleteSelection(e.selection().token),{available:!!e.selection()?.items.length})}],["mod+c",d=>g(d,()=>e.editor.copyToClipboard(e.selection().token),{available:!!e.selection()?.items.length})],["mod+v",d=>g(d,()=>e.editor.pasteFromClipboard())],["mod+b",d=>x(d,"bold")],["mod+i",d=>x(d,"italic")],["enter",d=>{let f=e.selection(),w=f&&se(f.items)[0],b=e.editor.textEditing!=="disabled"&&!!w?.capabilities.editText;e.groups&&y()?g(d,()=>e.groups.rename(w.id),{available:b,key:"group-shortcut"}):g(d,()=>e.editor.beginTextEditing(w.id),{available:b})}],...Tn.map(d=>[d,f=>{f.target instanceof e.container.ownerDocument.defaultView.HTMLElement&&c()?.contains(f.target)&&f.target.matches('[data-testid="d-canvas-content-editable"]')&&!l(f)&&p()?(f.preventDefault(),e.run(()=>e.editor.cancelInteraction(),"interaction")):g(f,()=>e.editor.cancelInteraction(),{busy:!0,pointer:!0,key:"interaction"})}]),["space",d=>g(d,()=>{let f={release:!1,started:e.editor.beginPan()};return n.current=f,f.started},{available:!n.current&&e.state().tool==="select",key:"pan"})]];Cn(h.map(([d,f])=>[d,f,{preventDefault:!1,usePhysicalKeys:d!=="/"}]),[],!0),Sn(()=>{let{container:d}=e,f=d.ownerDocument,w=f.defaultView;function b(){let k=n.current;!k||k.release||(k.release=!0,(async()=>{try{await k.started&&t.current.editor.lifecycle==="ready"&&await t.current.editor.endPan()}finally{n.current===k&&(n.current=null)}})().catch(G=>t.current.report(G)))}function u(k,G){if(i.current.alt===k&&i.current.shift===G)return;i.current={alt:k,shift:G};let U=t.current.state();t.current.editor.lifecycle==="ready"&&U.editingEnabled&&U.health==="healthy"&&t.current.editor.updateInteractionModifiers({alt:k,shift:G}).catch(W=>t.current.report(W))}function E(){let k=o.current!==0;r.current.clear(),o.current=0,b();let G=t.current.state();k&&t.current.editor.lifecycle==="ready"&&G.editingEnabled&&G.health==="healthy"&&t.current.editor.cancelInteraction().catch(U=>t.current.report(U)),u(!1,!1)}function R(k){if(m(k)){if(["pointercancel","lostpointercapture"].includes(k.type)){(k.type==="pointercancel"||o.current!==0)&&E();return}i.current={alt:k.altKey,shift:k.shiftKey},o.current=k.buttons}else["pointerup","pointercancel"].includes(k.type)&&(o.current=k.buttons)}function M(k){!["Alt","Shift"].includes(k.key)||l(k)||(m(k)||i.current.alt||i.current.shift)&&u(k.altKey,k.shiftKey)}let ue=En([["space",b,{preventDefault:!1,usePhysicalKeys:!0}]]);function H(k){r.current.delete(s(k)),M(k),n.current&&(k.code==="Space"||k.key===" ")?b():ue(k)}function B(k){m(k)||E()}function ie(){f.visibilityState==="hidden"&&E()}let te=["pointerdown","pointermove","pointerup","pointercancel","lostpointercapture"];for(let k of te)f.addEventListener(k,R,!0);return f.addEventListener("keydown",M,!0),f.addEventListener("keyup",H,!0),f.addEventListener("focusin",B,!0),f.addEventListener("visibilitychange",ie),w.addEventListener("blur",E),()=>{E();for(let k of te)f.removeEventListener(k,R,!0);f.removeEventListener("keydown",M,!0),f.removeEventListener("keyup",H,!0),f.removeEventListener("focusin",B,!0),f.removeEventListener("visibilitychange",ie),w.removeEventListener("blur",E)}},[e.editor,e.container])}import{Checkbox as zo}from"@mantine/core";import{useEffect as Po,useRef as Nt,useState as Dt}from"react";import{Checkbox as jn,Divider as Un,NativeSelect as Io}from"@mantine/core";import{useState as Pn}from"react";import{Button as Ot,Checkbox as In,Divider as Rn,Group as On,NativeSelect as zn,TextInput as Nn}from"@mantine/core";import{Fragment as Mn,jsx as ge,jsxs as it}from"react/jsx-runtime";function zt({disabled:e,onReset:t}){return ge(Ot,{size:"compact-xs",variant:"default",disabled:e,style:{alignSelf:"flex-start"},onClick:()=>{t()},children:"Reset numbering"})}function To({item:e}){let{selection:t,state:r,edit:o}=K(),n=mt(e);if(!t||!n)return null;let i=t.revision!==r.revision||r.busy||!r.editingEnabled||r.health!=="healthy",s=e.model.autoNumber,c=e.model.autoNumberMode,m=c==="Enable"||c==="Disable"||c==="Inherit",l="Automatic numbering in group",p=g=>o("Change group automatic numbering",x=>[V(x,[m?"autoNumberMode":"autoNumber"],g)],e);return it("div",{className:"dm-panel-stack dm-numbering-panel",children:[ge(Dn,{numbering:n,disabled:i,onChange:g=>o(g===null?"Clear badge number":"Change badge number",x=>[de(x,"setBadgeNumber",g)],e)},t.revision),e.capabilities.group&&(m||typeof s=="boolean")&&it(Mn,{children:[ge(Rn,{}),m?ge(zn,{label:l,size:"xs",value:c,disabled:i,data:[{value:"Enable",label:"Enable"},{value:"Disable",label:"Disable"},{value:"Inherit",label:"Inherit parent"}],onChange:g=>{p(g.currentTarget.value)}}):ge(In,{label:l,size:"xs",checked:s===!0,disabled:i,onChange:g=>{p(g.currentTarget.checked)}}),ge(zt,{disabled:i,onReset:()=>o("Reset group numbering",g=>[de(g,"resetNumbering",!1)],e)})]})]})}function Dn({numbering:{number:e,prefix:t,maximum:r},disabled:o,onChange:n}){let i=e===null?"":String(e),[s,c]=Pn(i),m=Number(s),l=/^[0-9]+$/.test(s)&&Number.isSafeInteger(m)&&m>=1&&m<=r,p=!o&&l&&m!==e;return it("form",{className:"dm-panel-stack",onSubmit:g=>{g.preventDefault(),p&&n(m)},children:[ge(Nn,{label:"Local number",size:"xs",value:s,inputMode:"numeric",disabled:o||r<1,leftSection:t&&ge("span",{className:"dm-number-prefix","data-testid":"number-prefix","aria-hidden":"true",children:t}),leftSectionWidth:t?`clamp(1.75rem, calc(${t.length}ch + .75rem), 60%)`:void 0,leftSectionPointerEvents:"none",description:t&&"Group prefix "+t,descriptionProps:{style:{display:"none"}},error:s!==i&&s!==""&&!l&&"Enter a whole number from 1 to "+r+".",onChange:g=>c(g.currentTarget.value)}),it(On,{gap:6,children:[ge(Ot,{type:"submit",size:"compact-xs",disabled:!p,children:"Apply"}),ge(Ot,{type:"button",size:"compact-xs",variant:"default",disabled:o||e===null,onClick:()=>{n(null)},children:"Clear"})]})]})}import{Fragment as An,jsx as ve,jsxs as Mt}from"react/jsx-runtime";var Ro={root:"dm-drawing-property",label:"dm-drawing-property-label",wrapper:"dm-drawing-property-input"};function Oo(){let{editor:e,state:t,run:r}=K(),[o,n]=Dt(null),[i,s]=Dt(null),[c,m]=Dt(0),l=Nt(!1),p=Nt(t.revision),g=Nt(null);p.current=t.revision,Po(()=>(l.current=!0,()=>{l.current=!1}),[]),Po(()=>{let u=t.revision;!u||t.busy||g.current===u||(g.current=u,s(null),e.getScene().then(E=>{if(!(!l.current||p.current!==u)){if(E.revision!==u)throw new Error("The drawing changed. Read its properties again.");n(E)}}).catch(E=>{l.current&&p.current===u&&s(E)}))},[e,t.revision,t.busy,c]);let x=o?.revision===t.revision,y=o?.metadata.model,h=!x||t.busy||!t.editingEnabled||t.health!=="healthy",d=typeof y?.theme=="string"?y.theme:"default",f=y?.style===1?"1":"0",w=async(u,E)=>{h||!o||await r(()=>e.editScene({revision:o.revision,description:u,changes:[E]}))},b=y?.autoNumber;return Mt("div",{className:"dm-panel-stack dm-drawing-properties","aria-busy":!x&&!i,children:[ve(Io,{label:"Theme",classNames:Ro,value:d,disabled:h,"data-testid":"drawing-theme",data:[{value:"default",label:"Default"},{value:"minimal",label:"Minimal"}],onChange:u=>{w("Change drawing theme",{path:["theme"],value:u.currentTarget.value})}}),ve("p",{className:"dm-property-description",children:d==="minimal"?"Apple-inspired cards in graphite, ceramic and titanium finishes.":"Balanced colors and classic outlines."}),ve(Io,{label:"Drawing style",classNames:Ro,value:f,disabled:h,"data-testid":"drawing-style",data:[{value:"0",label:"Formal"},{value:"1",label:"Draft"}],onChange:u=>{w("Change drawing style",{path:["style"],value:Number(u.currentTarget.value)})}}),ve("p",{className:"dm-property-description",children:f==="1"?"Hand-drawn strokes and handwriting.":"Precise strokes and clean typography."}),typeof b=="boolean"&&Mt(An,{children:[ve(Un,{}),ve(jn,{label:"Automatic numbering in this diagram",size:"xs",checked:b,disabled:h,onChange:u=>{w("Change automatic numbering",{path:["autoNumber"],value:u.currentTarget.checked})}}),ve(zt,{disabled:h,onReset:()=>w("Reset numbering",{op:"call",path:["resetNumbering"],arguments:[!1]})})]}),i!=null&&Mt("div",{role:"alert",children:[ve("p",{children:i?.message??String(i)}),ve(D,{"aria-label":"Read drawing properties again",onClick:()=>{g.current=null,m(u=>u+1)},children:"Try again"})]})]})}import{jsx as xe,jsxs as qe}from"react/jsx-runtime";function No({preferences:e,onChange:t}){return qe("div",{className:"dm-settings",children:[xe("header",{className:"dm-settings-header",children:xe("h2",{children:"Settings"})}),qe("section",{className:"dm-settings-section","aria-label":"View",children:[qe("div",{className:"dm-settings-section-heading",children:[xe("h3",{children:"View"}),xe("p",{children:"Only on this device."})]}),xe(zo,{label:"Dark Theme","data-testid":"settings-dark-theme",checked:e.darkTheme??!1,onChange:r=>{t({darkTheme:r.currentTarget.checked})}}),xe(zo,{label:"Show and Snap to Grid","data-testid":"settings-show-grid",checked:e.showGrid??!0,onChange:r=>{t({showGrid:r.currentTarget.checked,snapToGrid:r.currentTarget.checked})}})]}),qe("section",{className:"dm-settings-section","aria-label":"Drawing",children:[qe("div",{className:"dm-settings-section-heading",children:[xe("h3",{children:"Drawing"}),xe("p",{children:"Saved with this drawing."})]}),xe(Oo,{})]})]})}import{useEffect as Ve,useRef as ce,useState as ke}from"react";import{Button as we,Checkbox as Bn,FocusTrap as jo}from"@mantine/core";import{Fragment as st,jsx as z,jsxs as F}from"react/jsx-runtime";function Ln(e){let t=e;return typeof t.getGroupContext=="function"&&typeof t.selectObjects=="function"&&typeof t.createGroup=="function"&&typeof t.ungroup=="function"&&typeof t.previewGroupPlacement=="function"&&typeof t.commitGroupPlacement=="function"?t:null}var jt={x:0,y:0},Ut={ArrowUp:{x:0,y:-8},ArrowDown:{x:0,y:8},ArrowLeft:{x:-8,y:0},ArrowRight:{x:8,y:0}},lt=e=>e.querySelector(".drawmotive-canvas-host canvas"),Uo=e=>e?.code,Do=e=>e?.message??String(e),Mo=e=>["StaleSelection","StaleRevision","StaleGroupDestination"].includes(Uo(e)??"");function at(e,t){return e.revision===t?.revision&&e.token.session===t.token.session&&e.token.version===t.token.version}function Fe(e,t){let r=[];for(let o=e.find(n=>n.id===t);o;o=e.find(n=>n.id===o?.parentId)){let n=e.filter(s=>s.parentId===o?.parentId&&s.label===o.label),i=n.map(s=>s.id).sort().indexOf(o.id);r.unshift(n.length>1?o.label+" ("+(i+1)+")":o.label)}return["Drawing",...r].join(" / ")}function At({title:e,children:t,onClose:r,busy:o}){return z("div",{className:"dm-group-backdrop",children:z(jo,{active:!0,children:F("section",{className:"dm-group-dialog",role:"dialog","aria-modal":"true","aria-label":e,"aria-busy":o,onKeyDown:n=>{n.key!=="Escape"||n.nativeEvent.isComposing||n.keyCode===229||(n.preventDefault(),n.stopPropagation(),o||r())},children:[z("h2",{children:e}),t]})})})}function Hn({context:e,contents:t,initialIds:r,busy:o,onClose:n,onApply:i}){let s=t?e.objects.filter(l=>l.parentId===e.groupId):e.objects,[c,m]=ke(()=>new Set(r.filter(l=>s.some(p=>p.id===l))));return F(At,{title:t?"Group contents":"Select objects",busy:o,onClose:n,children:[t&&z("p",{"aria-label":"Group path",children:Fe(e.objects,e.groupId)}),F("div",{className:"dm-group-rows",children:[s.map((l,p)=>z(Bn,{label:F(st,{children:[z("span",{children:l.label}),!t&&l.parentId!==null&&z("small",{children:Fe(e.objects,l.parentId)}),s.some(g=>g.id!==l.id&&g.parentId===l.parentId&&g.label===l.label)&&z("small",{children:Fe(e.objects,l.id)})]}),disabled:o,checked:c.has(l.id),"data-autofocus":p===0||void 0,onChange:g=>{let x=g.currentTarget.checked;m(y=>{let h=new Set(y);return x?h.add(l.id):h.delete(l.id),h})}},l.id)),!s.length&&z("p",{children:t?"This group is empty.":"This drawing is empty."})]}),F("div",{className:"dm-group-actions",children:[F("span",{"aria-live":"polite",children:[c.size," selected"]}),z(we,{variant:"default",onClick:n,disabled:o,"data-autofocus":!s.length||void 0,children:"Cancel"}),z(we,{onClick:()=>i([...c]),disabled:o||c.size===0,children:"Apply"})]})]})}function Gn({preview:e,container:t,overlay:r,ghosts:o}){let n=lt(t);if(!n||!r)return null;let i=s=>{let c=$e(s,n.getBoundingClientRect(),{width:n.clientWidth,height:n.clientHeight},r.getBoundingClientRect(),{width:r.clientWidth,height:r.clientHeight});return{top:c.top,left:c.left,width:c.right-c.left,height:c.bottom-c.top}};return F("div",{className:"dm-group-preview","data-valid":e.valid,"aria-hidden":"true",children:[e.targetBounds&&z("span",{className:"dm-group-preview-target",style:i(e.targetBounds)}),o&&e.bounds.map((s,c)=>z("span",{className:"dm-group-preview-ghost",style:i(s)},c))]})}function qn({api:e,context:t,container:r,overlay:o,initialDestination:n,prepareDestination:i,onDestination:s,onClose:c,onFailure:m,onCommit:l,busy:p}){let[g,x]=ke(n),[y,h]=ke(!1),[d,f]=ke(null),[w,b]=ke(t.placementBounds),u=ce(0),E=ce(null),R=ce(jt),M=ce(null),ue=ce(!1),H=ce(!1),B=Fe(t.objects,g);function ie(C){return{guard:t.guard,destinationId:g,offset:C}}function te(C){M.current=C,!ue.current&&(ue.current=!0,(async()=>{try{for(;H.current&&M.current;){let L=M.current,q=await e.previewGroupPlacement(L);!H.current||L!==M.current||(M.current=null,f(q))}}catch(L){M.current=null,H.current&&m(L)}finally{ue.current=!1}})())}Ve(()=>(H.current=!0,k(n),()=>{H.current=!1,M.current=null}),[]);function k(C){x(C),s(C),f(null);let L=++u.current;M.current=null,i(C).then(q=>{!H.current||L!==u.current||(b(q.placementBounds),te({guard:q.guard,destinationId:C,offset:jt}))},q=>{H.current&&L===u.current&&m(q)})}function G(C,L){let q=lt(r),ae=w;if(!q||!ae)return R.current;let pe=q.getBoundingClientRect();return{x:(C-pe.left)*q.clientWidth/pe.width-(ae.left+ae.right)/2,y:(L-pe.top)*q.clientHeight/pe.height-(ae.top+ae.bottom)/2}}function U(C){R.current=C,te(ie(C))}let W=d&&z(Gn,{preview:d,container:r,overlay:o,ghosts:y});return y?z(jo,{active:!0,children:z("div",{children:F("div",{ref:E,"data-autofocus":!0,className:"dm-group-placement",role:"region","aria-label":"Place selection",tabIndex:0,"aria-busy":p,onPointerMove:C=>{!p&&C.pointerType!=="touch"&&U(G(C.clientX,C.clientY))},onPointerCancel:()=>{p||c()},onClick:C=>{if(p||C.target.closest(".dm-group-placement-info"))return;let L=G(C.clientX,C.clientY);U(L),l(ie(L),B)},onKeyDown:C=>{if(!(C.nativeEvent.isComposing||C.keyCode===229)){if(C.key==="Escape")C.preventDefault(),C.stopPropagation(),p||c();else if(!C.altKey&&!C.ctrlKey&&!C.metaKey&&C.target===E.current&&(C.key==="Enter"||Object.hasOwn(Ut,C.key))){if(C.preventDefault(),C.stopPropagation(),p)return;C.key==="Enter"?C.repeat||l(ie(R.current),B):U({x:R.current.x+Ut[C.key].x,y:R.current.y+Ut[C.key].y})}}},children:[W,F("div",{className:"dm-group-placement-info",children:[z("strong",{children:"Move to "+B}),F("span",{"aria-live":"polite",children:[d?.valid?"Click, tap, or press Enter to place.":d?.reason??"Checking placement\u2026",z("br",{}),"Arrow keys move the selection."]}),z(we,{variant:"default",disabled:p,onClick:c,children:"Cancel"})]})]})})}):F(st,{children:[W,F(At,{title:"Move to group",onClose:c,busy:p,children:[z("div",{className:"dm-group-destinations",role:"group","aria-label":"Destination",children:t.destinationIds.map(C=>z(we,{variant:C===g?"light":"subtle","aria-pressed":C===g,disabled:p,"data-autofocus":C===n||void 0,onClick:()=>k(C),children:Fe(t.objects,C)},C??""))}),z("p",{"aria-live":"polite",children:d?.reason??(d?"":"Checking destination\u2026")}),F("div",{className:"dm-group-actions",children:[z(we,{variant:"default",disabled:p,onClick:c,children:"Cancel"}),d?.valid?z(we,{disabled:p,onClick:()=>l(ie(jt),B),children:"Move here"}):z(we,{disabled:!d||p,onClick:()=>h(!0),children:"Choose location"})]})]})]})}function Ao({editor:e,container:t,overlay:r,selection:o,revision:n,enabled:i,busy:s,setPanel:c,run:m}){let l=Ln(e),[p,g]=ke(null),[x,y]=ke(!1),[h,d]=ke(null),[f,w]=ke(""),b=ce(null),u=ce(null),E=ce(!1),R=ce(!1),M=ce(o);M.current=o;let ue=!!l&&!x,H=i&&ue,B=p&&at(p.guard,o)?p:null;function ie(){let v=t.ownerDocument.activeElement,I=t.ownerDocument.defaultView;b.current=v instanceof I.HTMLElement?v.closest(".dm-panel")?"more":v:null}function te(){let v=b.current;b.current=null,t.ownerDocument.defaultView.requestAnimationFrame(()=>{if(!R.current)return;let I=v==="more"?r.current?.querySelector('[data-testid="context-toolbar-more-options"]'):v;(I?.isConnected&&!I.matches(":disabled")&&I!==t.ownerDocument.body?I:lt(t))?.focus({preventScroll:!0})})}function k(v=""){d(null),v&&w(v),te()}function G(v){Mo(v)?k(Do(v)):w(Do(v))}Ve(()=>(R.current=!0,()=>{R.current=!1}),[]),Ve(()=>{if(!l||!H||!o||s)return;let v=!0;return l.getGroupContext().then(I=>{v&&g(I)},I=>{v&&Uo(I)==="UnsupportedOperation"&&y(!0)}),()=>{v=!1}},[l,H,s,o?.revision,o?.token.session,o?.token.version]),Ve(()=>{if(!h||E.current)return;if(!H){k();return}if(at(h.context.guard,o)&&h.context.guard.revision===n)return;let v=h.kind==="move"?u.current:null;v&&l&&n!==h.context.guard.revision?(k("The drawing changed. Choose the destination again."),l.getGroupContext({includeObjects:!0}).then(I=>{R.current&&!I.objects.some(N=>N.id===v)&&w("The destination group was removed.")},()=>{})):k("The drawing or selection changed. Open the group action again.")},[h,H,o?.revision,o?.token.session,o?.token.version,n]),Ve(()=>{if(!f||h)return;let v=t.ownerDocument.defaultView.setTimeout(()=>w(""),6500);return()=>t.ownerDocument.defaultView.clearTimeout(v)},[t,f,h]);async function U(v,I=!1){!H||s||E.current||(I&&(ie(),c(null)),w(""),await m(async()=>{E.current=!0;try{await v()}catch(N){if(!R.current)return;G(N),I&&!Mo(N)&&te()}finally{E.current=!1}}))}async function W(v=!1){let I=M.current,N=await l.getGroupContext({includeObjects:v});if(!at(N.guard,I)||!at(N.guard,M.current))throw Object.assign(new Error("The selection changed. Open the group action again."),{code:"StaleSelection"});return N}async function C(v,I){let N=lt(t),_=I.objects.find(Q=>Q.id===v)?.bounds;return!N||!_||_.left>=0&&_.top>=0&&_.right<=N.clientWidth&&_.bottom<=N.clientHeight?I:(await e.fitViewport(),W(!0))}function L(v,I=!1){return U(async()=>{let N=await W(!0);R.current&&(u.current=I?N.moveOutDestinationId:N.destinationIds[0]??null,d({kind:v,context:N,selected:M.current?.items.map(_=>_.id)??[]}))},!0)}function q(){return U(async()=>{let{guard:v,createError:I,eligibleCount:N}=await W();if(I){k(I);return}await l.createGroup(v),R.current&&k("Group created with "+N+(N===1?" object":" objects"))},!0)}function ae(v){return U(async()=>{if(await W(),await e.beginTextEditing(v),e.textEditing!=="inline")return;let I=t.ownerDocument;t.querySelector('[data-testid="d-canvas-content-editable"]')?.addEventListener("blur",()=>{I.defaultView.requestAnimationFrame(()=>{R.current&&I.activeElement===I.body&&te()})},{once:!0})},!0)}function pe(){return U(async()=>{let{parentId:v,guard:I}=await W();v!==null&&(await l.selectObjects([v],I),R.current&&k("Parent group selected"))},!0)}function Ne(){return U(async()=>{let v=await W();!R.current||!v.groupId||(v.connectorCount?d({kind:"ungroup",context:v,selected:[]}):(await l.ungroup(v.guard,!1),R.current&&k("Group removed")))},!0)}function me(v,I,N){return z(D,{"aria-label":v,"aria-description":N,className:"dm-menu-item",onClick:()=>{I()},children:F("span",{children:[v,N&&" ("+N+")"]})})}let Ke=H&&B&&!B.createError&&B.eligibleCount>1?B.eligibleCount:0,We=H&&B&&o?.items.length?F(st,{children:[!Ke&&me("Group",q,B.eligibleCount+" eligible"),B.groupId&&me("Group contents",()=>L("contents")),B.groupId&&e.textEditing!=="disabled"&&me("Rename group",()=>ae(B.groupId)),B.parentId&&me("Select parent group",pe),B.destinationIds.length>0&&B.placementBounds&&me("Move to group\u2026",()=>L("move")),B.canMoveOut&&me("Move out of group",()=>L("move",!0)),B.groupId&&me("Ungroup",Ne)]}):null,Ee=F(st,{children:[z("div",{className:"dm-object-drop-layout dm-group-status",role:"status","aria-label":"Group status",children:f}),h&&(h.kind==="move"?z(qn,{api:l,context:h.context,container:t,overlay:r.current,initialDestination:u.current,prepareDestination:v=>C(v,h.context),onDestination:v=>{u.current=v},onClose:()=>k(),busy:s,onFailure:G,onCommit:(v,I)=>{U(async()=>{let N=await l.previewGroupPlacement(v);if(!N.valid){w(N.reason??"The selection cannot be placed here.");return}await l.commitGroupPlacement(v),R.current&&k("Moved selection to "+I)})}}):h.kind==="ungroup"?F(At,{title:"Ungroup",busy:s,onClose:()=>k(),children:[F("p",{children:[h.context.connectorCount," ",h.context.connectorCount===1?"connector attaches":"connectors attach"," directly to this group."]}),z("p",{children:"Detaching switches the affected connectors to straight routing and clears their waypoints."}),F("div",{className:"dm-group-actions",children:[z(we,{variant:"default","data-autofocus":!0,disabled:s,onClick:()=>k(),children:"Cancel"}),z(we,{color:"red",disabled:s,onClick:()=>{U(async()=>{await l.ungroup(h.context.guard,!0),R.current&&k("Group removed and connectors detached")})},children:"Ungroup and detach"})]})]}):z(Hn,{context:h.context,contents:h.kind==="contents",initialIds:h.selected,busy:s,onClose:()=>k(),onApply:v=>{U(async()=>{await l.selectObjects(v,h.context.guard),R.current&&k(v.length+(v.length===1?" object selected":" objects selected"))})}}))]});return{supported:ue,available:H&&o!==null,primary:Ke,menu:We,chrome:Ee,create:q,ungroup:Ne,rename:ae,selectObjects:()=>L("objects")}}import{useId as Vn,useLayoutEffect as qo,useRef as Fn,useState as Vo}from"react";import{FocusTrap as Zn}from"@mantine/core";var Ze=Object.freeze([{id:"arrow",label:"Arrow",aliases:"line connector"},{id:"rectangle",label:"Rectangle",aliases:"box square shape"},{id:"ellipse",label:"Ellipse",aliases:"circle oval shape"},{id:"diamond",label:"Diamond",aliases:"decision rhombus shape"},{id:"text",label:"Text",aliases:"label note"}]),Lo="drawmotive.quick-insert.v1";function Bo(e){try{let t=e().getItem(Lo);if(t===null)return{};let r=JSON.parse(t),o={};if(r?.version!==1)return null;for(let{id:n}of Ze){let i=r.usage?.[n];Number.isSafeInteger(i?.count)&&i.count>0&&Number.isSafeInteger(i.lastUsed)&&i.lastUsed>0&&(o[n]={count:i.count,lastUsed:i.lastUsed})}return o}catch{return null}}function Bt(e,t,r=1){let o=Object.keys(e).sort((n,i)=>e[n].lastUsed-e[i].lastUsed);o.forEach((n,i)=>{e[n].lastUsed=i+1}),e[t]={count:Math.min((e[t]?.count??0)+r,Number.MAX_SAFE_INTEGER),lastUsed:o.length+1}}function Ho(e){let t=Bo(e)??{},r={};function o(){let n=Bo(e);if(n!==null){for(let i of Object.keys(r).sort((s,c)=>r[s].lastUsed-r[c].lastUsed))Bt(n,i,r[i].count);t=n}}return{read(){return o(),structuredClone(t)},record(n){if(Ze.some(i=>i.id===n)){o(),Bt(t,n);try{e().setItem(Lo,JSON.stringify({version:1,usage:t})),r={}}catch{Bt(r,n)}}}}}function Go(e,t,r=Ze){let o=e.trim().toLowerCase().split(/\s+/).filter(Boolean),n=r.filter(l=>o.every(p=>(l.label+" "+(l.group??"")+" "+l.aliases).toLowerCase().includes(p)));if(!n.length)return[];let i=new Map,s=n.filter(l=>!l.group);for(let l of n)l.group&&(i.has(l.group)||i.set(l.group,[]),i.get(l.group).push(l));let c=o.length?[]:n.filter(l=>t[l.id]).sort((l,p)=>t[p.id].lastUsed-t[l.id].lastUsed).slice(0,3),m=o.length?[]:n.filter(l=>t[l.id]?.count>1).sort((l,p)=>t[p.id].count-t[l.id].count||t[p.id].lastUsed-t[l.id].lastUsed).slice(0,3);return[...s.length?[{key:"ungrouped",label:null,items:s}]:[],...c.length?[{key:"recent",label:"Recent",items:c}]:[],...m.length?[{key:"frequent",label:"Frequently used",items:m}]:[],...Array.from(i,([l,p])=>({key:"group:"+l,label:l,items:p}))]}import{jsx as X,jsxs as Pe}from"react/jsx-runtime";function Fo({container:e,usage:t,objects:r,disabled:o,onSelect:n,onClose:i}){let[s,c]=Vo(""),[m,l]=Vo(0),p=Vn(),g=Fn(null),x=Go(s,t,r),y=x.flatMap(b=>b.items),h=Math.min(m,Math.max(0,y.length-1)),d=y[h],f=d?(d.group?d.group+" / ":"")+d.label:"No objects found";qo(()=>{g.current?.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"})},[h,s]),qo(()=>()=>{let b=e.ownerDocument;(g.current?.contains(b.activeElement)||b.activeElement===b.body)&&e.querySelector(".drawmotive-canvas-host canvas")?.focus({preventScroll:!0})},[e]);let w=0;return X("div",{className:"dm-quick-insert-backdrop",onPointerDown:b=>{b.target===b.currentTarget&&(b.preventDefault(),i())},children:X(Zn,{active:!0,innerRef:g,children:Pe("div",{className:"dm-quick-insert",role:"dialog","aria-modal":"true","aria-label":"Quick insert","aria-busy":o,onKeyDown:b=>{b.nativeEvent.isComposing||b.keyCode===229||b.key==="Escape"&&(b.preventDefault(),b.stopPropagation(),i())},children:[Pe("div",{className:"dm-quick-insert-query",children:[X(ee,{name:"search"}),X("input",{"data-autofocus":!0,role:"combobox","aria-label":"Search objects","aria-expanded":"true","aria-autocomplete":"list","aria-controls":p+"-list","aria-activedescendant":y.length?p+"-"+h:void 0,"aria-describedby":p+"-hint",className:"dm-quick-insert-search",placeholder:"Search objects\u2026",value:s,readOnly:o,"aria-disabled":o,onChange:b=>{c(b.target.value),l(0)},onKeyDown:b=>{if(!(b.nativeEvent.isComposing||b.keyCode===229||b.altKey||b.ctrlKey||b.metaKey)&&["ArrowDown","ArrowUp","Home","End","Enter"].includes(b.key)){if(s&&["Home","End"].includes(b.key))return;b.preventDefault(),b.key==="Enter"?!b.repeat&&y[h]&&!o&&n(y[h].id):y.length&&l(b.key==="Home"?0:b.key==="End"?y.length-1:(h+(b.key==="ArrowDown"?1:-1)+y.length)%y.length)}}}),X("span",{className:"dm-quick-insert-count","aria-label":"Matching objects",children:new Set(y.map(b=>b.id)).size}),X("button",{type:"button",className:"dm-quick-insert-close","aria-label":"Close quick insert",title:"Close (Esc)",onPointerDown:b=>b.preventDefault(),onClick:i,children:X(ee,{name:"close"})})]}),Pe("div",{id:p+"-list",className:"dm-quick-insert-results",role:"listbox","aria-label":"Objects",children:[x.map(b=>Pe("div",{className:"dm-quick-insert-group",role:"group","aria-label":b.label??"Objects","data-ungrouped":b.label===null||void 0,children:[b.label&&X("div",{className:"dm-quick-insert-group-label","aria-hidden":"true",children:b.label}),X("div",{className:"dm-quick-insert-grid",children:b.items.map(u=>{let E=w++;return Pe("button",{id:p+"-"+E,type:"button",className:"dm-quick-insert-option",role:"option","aria-selected":E===h,tabIndex:-1,disabled:o,"aria-label":(u.group?u.group+" / ":"")+u.label,title:(u.group?u.group+" / ":"")+u.label+(u.shortcut?" ("+u.shortcut+")":""),onPointerMove:()=>l(E),onPointerDown:R=>R.preventDefault(),onClick:()=>{n(u.id)},children:[u.iconUrl?X("img",{src:u.iconUrl,alt:"","aria-hidden":"true"}):X(ee,{name:u.id}),X("span",{children:u.label})]},u.id)})})]},b.key)),!y.length&&X("div",{className:"dm-quick-insert-empty",role:"status",children:"No objects found"})]}),Pe("div",{className:"dm-quick-insert-hint",children:[X("span",{className:"dm-quick-insert-detail",title:f,children:f}),d?.shortcut&&X("kbd",{title:"Tool shortcut",children:d.shortcut}),Pe("span",{id:p+"-hint",className:"dm-quick-insert-keys","aria-label":"Up and down to navigate, Enter to choose, Escape to close",children:["\u2191\u2193 ",X("kbd",{children:"\u21B5"})," ",X("kbd",{children:"Esc"})]})]})]})})})}import{jsx as T,jsxs as ne}from"react/jsx-runtime";var Zo={revision:null,health:"healthy",editingEnabled:!1,busy:!0,canUndo:!1,canRedo:!1};function $n(e,t){let r=Re.find(n=>n===t);if(r===void 0||r==="sketchyMode")throw new TypeError("Unknown drawing tool: "+t);return e.setTool.call(e,r)}function ct(e){let t=he({editor:e.editor,key:0});return t.current.editor!==e.editor&&(t.current={editor:e.editor,key:t.current.key+1}),T(Xn,{...e},t.current.key)}function Xn(e){let[t,r]=oe(null);Lt(()=>{if(e.controller)return;let n=yt(e.editor,e.options);return r({editor:e.editor,options:e.options,controller:n}),()=>n.dispose()},[e.editor,e.options,e.controller]);let o=e.controller??(t?.editor===e.editor&&t.options===e.options?t.controller:null);if(!o)return null;if(o.editor!==e.editor)throw new TypeError("UI controller belongs to a different editor");return T(Yn,{...e,controller:o})}function Jn({editor:e,container:t}){let[r,o]=oe(null);return Ko(()=>{if(o(null),e.lifecycle!=="ready")return;let n="drawmotive:object-drop-layout",i=t.ownerDocument.defaultView,s;function c(p){let g=p.detail;g!==null&&typeof g!="string"||(i.clearTimeout(s),o(null),g!==null&&(s=i.setTimeout(()=>o(g),500)))}function m(){i.clearTimeout(s),t.removeEventListener(n,c)}t.addEventListener(n,c);let l=e.onEvent("disposing",()=>{m(),o(null)});return()=>{l(),m()}},[t,e]),r&&ne("div",{className:"dm-object-drop-layout",role:"status","aria-label":r,"data-testid":"object-drop-layout",children:[T(Kn,{size:18,color:"var(--dm-text)","aria-hidden":!0}),r]})}function Yn({editor:e,controller:t,container:r,slots:o={},colorScheme:n,className:i="",style:s,onError:c}){let[m,l]=oe(t.ui),[p,g]=oe(Zo),[x,y]=oe(null),[h,d]=oe({}),[f,w]=oe(null),[b,u]=oe(null),[E,R]=oe(new Set),[M,ue]=oe(e.lifecycle!=="ready"),[H,B]=oe(null),[ie,te]=oe(!1),[k]=oe(()=>Ho(()=>r.ownerDocument.defaultView.localStorage)),G=s?.fontFamily,U=he(!1),W=he(new Set),C=he(null),L=he(null),q=he(null),ae=he(null),pe=he(null),Ne=he(Zo),[me,Ke]=oe({left:0,top:0}),We=he(c);We.current=c;let Ee=dt(a=>{if(U.current){u(a);try{We.current?.(a)}catch{}}},[]);Lt(()=>{if(M)return;U.current=!0;let a=!1,S=0,j=0,Z=[e.onStateChanged(A=>{Ne.current=A,g(A)}),t.onChanged(l),e.onEvent("selectionChanged",A=>{let le=q.current;S++,q.current=A,y(Me(A)),le&&(le.token.session!==A.token.session||le.token.version!==A.token.version)&&w(fe=>fe==="settings"||fe==="drawingProperties"?fe:null)}),e.onPreferencesChanged(A=>{j++,d(A)}),e.onDisposed(()=>ue(!0))],$=A=>{a||Ee(A)};return e.getSelection().then(A=>{!a&&S===0&&(q.current=A,y(Me(A)))},$),e.getPreferences().then(A=>{!a&&j===0&&d(A)},$),()=>{a=!0,U.current=!1,Z.forEach(A=>A())}},[e,t,M,Ee]);let v=dt(async(a,S="document")=>{if(!U.current||W.current.has(S))return!1;W.current.add(S),R(new Set(W.current)),u(null);try{return await a(),!0}catch(j){return Ee(j),!1}finally{W.current.delete(S),U.current&&R(new Set(W.current))}},[Ee]),I=dt((a,S,j)=>x?v(async()=>{B(x.token);try{await e.editScene(Xe(x,a,S,j))}finally{U.current&&B(null)}}):Promise.resolve(!1),[e,x,v]),N=dt(async a=>{await $n(e,a),U.current&&k.record(a)},[e,k]),_=!p.editingEnabled||p.health!=="healthy"||p.busy||E.has("document"),Q=Ao({editor:e,container:r,overlay:C,selection:x,revision:p.revision,enabled:!M&&m.enabled&&p.editingEnabled&&p.health==="healthy",busy:_,setPanel:w,run:v});Co({editor:e,container:r,ui:m,state:()=>Ne.current,selection:()=>q.current,run:v,report:Ee,activateTool:N,groups:Q.available?Q:void 0,openQuickInsert:()=>{w(null),te(!0)}});let _o=async a=>{await v(()=>e.setPreferences(a),"preferences")},Gt=x?se(x.items):[],be=Gt[0],De=Kt(Gt,m.contextToolbar,Q.primary).filter(a=>a!=="editText"||e.textEditing!=="disabled");Lt(()=>{(M||!m.enabled||!p.editingEnabled||p.health!=="healthy"||p.busy)&&te(!1)},[M,m.enabled,p.editingEnabled,p.health,p.busy]);let Qo=H!==null&&H.session===x?.token.session&&H.version===x?.token.version,$o=!p.busy||Qo;if(Ko(()=>{if(M||!C.current)return;let a=C.current,S=r.querySelector("canvas"),j=r.ownerDocument.defaultView;function Z(){if(!a||!S||!L.current||!x?.anchor)return;let A=$e(x.anchor,S.getBoundingClientRect(),{width:S.clientWidth,height:S.clientHeight},a.getBoundingClientRect(),{width:a.clientWidth,height:a.clientHeight}),le=Wt(A,{width:L.current.offsetWidth,height:L.current.offsetHeight},{width:a.clientWidth,height:a.clientHeight});Ke(fe=>fe.left===le.left&&fe.top===le.top?fe:le)}Z();let $=new j.ResizeObserver(Z);return $.observe(a),S&&$.observe(S),L.current&&$.observe(L.current),j.addEventListener("scroll",Z,!0),()=>{$.disconnect(),j.removeEventListener("scroll",Z,!0)}},[r,x,M,m.enabled,p.busy,De.join(",")]),M||!m.enabled)return null;let ut=n??(h.darkTheme?"dark":"light"),_e=x?.items[0]?.resolved.themeColors,Xo=Object.fromEntries(_e&&typeof _e=="object"&&!Array.isArray(_e)?Object.entries(_e).filter(([,a])=>typeof a=="string").map(([a,S])=>[St(a),S]):[]),Jo={editor:e,ui:m,state:{...p,busy:p.busy||E.has("document")},selection:x,panel:f,setPanel:w,run:v,edit:I};function qt(a){if(!m.buttons[a])return null;if(a==="selectObjects")return Q.available?T(D,{icon:a,disabled:_,onClick:()=>{Q.selectObjects()}},a):null;let S=a==="undo"?!p.canUndo||_:a==="redo"?!p.canRedo||_:Re.some(Z=>Z===a)?_:!1;if(a==="settings"||a==="drawingProperties")return ne(Ce,{id:a,label:"Settings",button:T(D,{icon:"settings"}),children:[" ",T(No,{preferences:h,onChange:_o})]},a);if(a==="help")return ne(Ce,{id:"help",button:T(D,{icon:a}),children:[" ",ne("div",{className:"dm-help",children:[T("strong",{children:"Keyboard shortcuts"}),Object.entries(ze).filter(([Z])=>Q.supported||!["group","ungroup","renameGroup","deleteGroup"].includes(Z)).map(([Z,$])=>ne("div",{children:[Le[Z],T("kbd",{children:$})]},Z))]})]},a);let j=()=>a==="undo"||a==="redo"?e[a]():a==="sketchyMode"?e.setSketchyMode(!p.sketchyMode):a==="zoomIn"||a==="zoomOut"||a==="resetZoom"?e.zoom(a==="zoomIn"?"in":a==="zoomOut"?"out":"reset"):N(a);return T(D,{icon:a,shortcut:ze[a],disabled:S,selected:a==="sketchyMode"?p.sketchyMode:p.tool===a,onClick:()=>{v(j,["zoomIn","zoomOut","resetZoom"].includes(a)?"viewport":"document")},children:a==="resetZoom"?ne("span",{className:"dm-zoom",children:[Math.round((p.zoom??1)*100),"%"]}):void 0},a)}function Yo(a){if(a.startsWith("slot."))return o[a.slice(5)]==null?null:T("span",{className:"dm-slot",children:o[a.slice(5)]},a);if(!a.startsWith("host."))return qt(a);let S=m.actions.find(j=>j.id===a);return S?.visible?ne(D,{"aria-label":S.label,disabled:!S.enabled||E.has(a),className:"dm-host-action",onClick:()=>{v(()=>t.invokeAction(a),a)},children:[S.icon&&T(ee,{name:S.icon}),T("span",{children:E.has(a)?S.label+"\u2026":S.label})]},a):null}let Qe=e.setNodeImage,Vt=x?.items.length===1?be?.resolved.nodeImage:void 0,er=x&&typeof Vt=="boolean"&&typeof Qe=="function"?{hasImage:Vt,choose(){let a=ae.current;if(!a)return;let{token:S,revision:j}=x,{id:Z}=be;pe.current=$=>{v(async()=>{if($.size>16*1024*1024)throw new RangeError("The image input exceeds the supported size.");let A=new Uint8Array(await $.arrayBuffer());U.current&&e.lifecycle==="ready"&&await Qe.call(e,S,j,Z,A)})},a.value="",a.click(),w(null)},remove(){v(async()=>{await Qe.call(e,x.token,x.revision,be.id,null),U.current&&w(null)})}}:void 0;async function tr(){x&&await e.copyToClipboard(x.token)}function Ft(a){if(a==="group")return ne(D,{icon:a,shortcut:ze[a],"data-testid":"context-toolbar-group","aria-description":Q.primary+" eligible objects",onClick:()=>{Q.create()},children:[T(ee,{name:a}),ne("span",{children:["Group (",Q.primary,")"]})]});if(a==="groupTheme")return T(It,{inline:!0},a);let S=x.properties,j="context-toolbar-"+({strokeFillColor:"fill-color",strokeColor:"stroke-color",strokeStyle:"stroke-style",lineStartStyle:"line-start-style",lineEndStyle:"line-end-style",lineRouting:"line-connector-type",moreOptions:"more-options",groupTitleStyle:"group-title-style"}[a]??a.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()),Z=a==="bold"?O(S.bold):a==="italic"?O(S.italic):a==="cornerRadius"?(O(S.cornerRadius)??0)>0:a.startsWith("textSize")?O(S.textSize)===a.slice(8):void 0,$=a==="editText"&&Q.available&&be?.kind==="Group",A=()=>$?Q.rename(be.id):a==="editText"?v(()=>e.beginTextEditing(be?.id)):a.startsWith("textSize")?I("Set text size",re=>[V(re,["fontStyle","size"],Ie(re,"fontSizes",a.slice(8)))]):a==="bold"?I("Toggle bold",re=>[V(re,["fontStyle","weight"],O(S.bold)===!0?400:700)]):a==="italic"?I("Toggle italic",re=>[V(re,["fontStyle","slant"],O(S.italic)===!0?"Upright":"Italic")]):a==="cornerRadius"?I("Toggle corner radius",re=>[de(re,"toggleCornerRadius")]):I("Swap endpoints",re=>[V(re,["startStyle"],re.model.endStyle),V(re,["endStyle"],re.model.startStyle)]),le=a==="strokeFillColor"?ne("span",{className:"dm-stroke-fill","data-transparent":O(S.fillColor)?.role==="Transparent"?"":void 0,children:[T(Oe,{fill:Te(O(S.fillColor)?.role,O(S.fillColor)?.argb),style:{color:Te(O(S.fillColor)?.role==="Transparent"?"SecondaryStroke":O(S.fillColor)?.role)}}),T(Oe,{style:{color:Te(O(S.strokeColor)?.role,O(S.strokeColor)?.argb)}})]}):a==="lineStartStyle"||a==="lineEndStyle"?T(Be,{value:O(a==="lineStartStyle"?S.lineStartStyle:S.lineEndStyle)??0,start:a==="lineStartStyle"}):void 0,fe=pt.includes(a),Zt=T(D,{icon:a,"aria-label":$?Le.renameGroup:void 0,"data-testid":j,selected:Z,shortcut:ze[a],disabled:a==="swapLineEndpoints"&&S.lineStartStyle.state==="Uniform"&&S.lineEndStyle.state==="Uniform"&&O(S.lineStartStyle)===O(S.lineEndStyle),onClick:fe?void 0:()=>{A()},children:le});if(!fe)return T("span",{children:Zt},a);let or={strokeFillColor:T(nt,{fill:!0}),strokeColor:T(nt,{}),strokeStyle:T(xo,{}),textAlign:T(Tt,{}),lineStartStyle:T(Pt,{start:!0}),lineEndStyle:T(Pt,{start:!1}),lineRouting:T(wo,{}),groupTheme:T(It,{}),groupTitleStyle:T(So,{}),numbering:T(To,{item:be}),moreOptions:T(Eo,{copy:tr,nodeImage:er,groupActions:Q.menu,ungroup:Q.available&&x?.items.length===1&&be?.kind==="Group"?Q.ungroup:void 0})},rr=a==="moreOptions"&&me.top<(C.current?.clientHeight??0)/2?"bottom-start":"top-start";return T(Ce,{id:a,button:Zt,position:rr,children:or[a]},a)}return T("div",{ref:C,className:"dm-editor-ui "+i,style:{fontFamily:G,...Xo,...s},"data-mantine-color-scheme":ut,children:T(_n,{inherit:!1,children:T(Wn,{forceColorScheme:ut,theme:Qn(Ct,ho(ut==="dark"),G?{fontFamily:G,headings:{fontFamily:G}}:{}),cssVariablesSelector:".dm-editor-ui",getRootElement:()=>C.current??void 0,children:ne(kt.Provider,{value:Jo,children:[T(Jn,{editor:e,container:r}),typeof Qe=="function"&&T("input",{ref:ae,type:"file",accept:"image/*",hidden:!0,onChange:a=>{let S=pe.current,j=a.currentTarget.files?.[0];pe.current=null,j&&S?.(j)}}),Object.entries(m.regions).map(([a,S])=>{let j=S.items.map(Yo).filter(Boolean);return S.visible&&j.length>0?T(tt.Provider,{value:a.startsWith("top")?"bottom":"top",children:T("div",{className:"dm-toolbar dm-corner dm-"+a,role:"toolbar","aria-label":a+" toolbar","data-region":a,children:j})},a):null}),m.drawingToolbar.visible&&m.drawingToolbar.tools.some(a=>m.buttons[a])&&T(tt.Provider,{value:{left:"right",right:"left",top:"bottom",bottom:"top"}[m.drawingToolbar.position],children:T("fieldset",{className:"dm-toolbar dm-drawing dm-"+m.drawingToolbar.position,disabled:_,"aria-label":"Drawing tools","data-testid":"drawing-toolbar",children:m.drawingToolbar.tools.map(qt)})}),T(fo,{container:r}),ie&&T(Fo,{container:r,usage:k.read(),disabled:_,objects:Ze.filter(a=>m.buttons[a.id]).map(a=>({...a,shortcut:ze[a.id]})),onClose:()=>te(!1),onSelect:async a=>{_||!m.buttons[a]||await v(()=>N(a))&&te(!1)}}),x&&x.anchor&&De.length>0&&$o&&T("fieldset",{ref:L,className:"dm-toolbar dm-context",disabled:_,style:me,"aria-label":"Selection tools","data-testid":"context-toolbar","data-item-id":be?.id,children:De.map((a,S)=>{if(a.startsWith("textSize")&&De[S-1]?.startsWith("textSize"))return null;let j=a.startsWith("textSize")?De.slice(S).filter((Z,$,A)=>A.slice(0,$+1).every(le=>le.startsWith("textSize"))):null;return ne("span",{className:"dm-context-entry",children:[S>0&&(j||["bold","textAlign","strokeColor","strokeFillColor","group","moreOptions"].includes(a))&&T(ot,{}),j?T("span",{className:"dm-button-group",children:j.map(Ft)}):Ft(a)]},a)})}),Q.chrome,b!=null&&ne("div",{className:"dm-error",role:"alert",children:[T("span",{children:b?.message??String(b)}),T(D,{"aria-label":"Dismiss error",icon:"close",onClick:()=>u(null)})]})]})})})})}import{createRoot as ei}from"react-dom/client";import{jsx as oi}from"react/jsx-runtime";function ti({editor:e,container:t,...r}){let o=t.ownerDocument.defaultView,n=t.style.position,i=o.getComputedStyle(t).position==="static";i&&(t.style.position="relative");let s=t.ownerDocument.createElement("div");s.style.cssText="position:absolute;inset:0;pointer-events:none;",t.append(s);let c=ei(s),m=!1,l,p=()=>{m||(m=!0,l?.(),c.unmount(),s.remove(),i&&t.style.position==="relative"&&(t.style.position=n))};return c.render(oi(ct,{editor:e,container:t,...r})),l=e.onDisposed(p),{dispose:p}}import{jsx as Wo,jsxs as ai}from"react/jsx-runtime";function tl({className:e,style:t,slots:r,colorScheme:o,onReady:n,onError:i,ui:s,...c}){let m=Ht(null),l=Ht({onReady:n,onError:i});l.current={onReady:n,onError:i};let p=Ht(Promise.resolve()),[g,x]=ni(null);return ri(()=>{let y=!1,h,d,f=new AbortController,w=()=>f.abort(c.signal?.reason);c.signal?.addEventListener("abort",w,{once:!0}),c.signal?.aborted&&w(),x(null);let b=p.current,u=b.then(async()=>{if(y)return;let E=await ii({...c,container:m.current,signal:f.signal});h=E,!y&&(d=E.onDisposed(()=>x(null)),x(E),l.current.onReady?.(E))});return u.catch(E=>{y||l.current.onError?.(E)}),()=>{y=!0,f.abort(),c.signal?.removeEventListener("abort",w),d?.(),p.current=b.then(()=>u.catch(E=>{if(E?.code==="DisposeCleanupUnconfirmed")throw E})).then(async()=>{h&&await h.dispose()}),p.current.catch(E=>l.current.onError?.(E))}},[c.assetBaseUrl,c.licenseKey,c.textEditing,s,c.persistence,c.workerFactory,c.workerUrls,c.signal,c.title,c.startupTimeoutMs,c.disposeTimeoutMs]),ai("div",{className:e,style:{position:"relative",width:"100%",height:"100%",...t},children:[Wo("div",{ref:m,style:{position:"absolute",inset:0}}),g&&Wo(ct,{options:s,editor:g,container:m.current,slots:r,colorScheme:o,onError:i})]})}export{tl as Editor,ct as EditorUi,yt as createEditorUiController,ti as mountEditorUi,Ct as phosphorTheme};
|
|
2
2
|
/*! Material Symbols Outlined | Copyright Google LLC | Apache-2.0
|
|
3
3
|
* See MaterialSymbols-LICENSE.txt and MaterialSymbols-NOTICE.txt in the distribution. */
|
package/dist/panels.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
1
2
|
import type { UiSelectedObject } from './selection-model.js';
|
|
2
3
|
export declare function Colors({ fill, target }: {
|
|
3
4
|
fill?: boolean;
|
|
@@ -25,6 +26,13 @@ export declare function TitlePanel(): import("react").JSX.Element | null;
|
|
|
25
26
|
export declare function TextButtons({ target }: {
|
|
26
27
|
target: UiSelectedObject;
|
|
27
28
|
}): import("react").JSX.Element;
|
|
28
|
-
export declare function MorePanel({ copy }: {
|
|
29
|
+
export declare function MorePanel({ copy, nodeImage, groupActions, ungroup }: {
|
|
29
30
|
copy: () => Promise<unknown>;
|
|
31
|
+
nodeImage?: {
|
|
32
|
+
hasImage: boolean;
|
|
33
|
+
choose(): void;
|
|
34
|
+
remove(): void;
|
|
35
|
+
};
|
|
36
|
+
groupActions?: ReactNode;
|
|
37
|
+
ungroup?: () => Promise<void>;
|
|
30
38
|
}): import("react").JSX.Element;
|
package/dist/ui-controller.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EditorError as T}from"@drawmotive/editor";var E=Object.freeze(["undo","redo","arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode","drawingProperties","zoomIn","zoomOut","resetZoom","settings","help"]),k=Object.freeze(["topLeft","topRight","bottomLeft","bottomRight"]),x=Object.freeze(["arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode"]),S=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),D=e=>typeof e=="string"&&/^host[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e),_=e=>typeof e=="string"&&/^slot[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e);function g(e,i,l){if(!S(e))throw new TypeError(l+" must be an object");for(let c of Object.keys(e))if(!i.includes(c))throw new TypeError("Unknown "+l+" option: "+c)}function O(e,i){if(typeof e!="boolean")throw new TypeError(i+" must be a boolean");return e}function U(e,i){if(typeof e!="string"||!e.trim())throw new TypeError(i+" must be a nonempty string");return e}function I(e,i,l=c=>typeof c=="string"&&!!c.trim()){if(!Array.isArray(e)||e.some(c=>!l(c))||new Set(e).size!==e.length)throw new TypeError(i+" must contain distinct valid IDs");return Object.freeze([...e])}function
|
|
1
|
+
import{EditorError as T}from"@drawmotive/editor";var E=Object.freeze(["undo","redo","selectObjects","arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode","drawingProperties","zoomIn","zoomOut","resetZoom","settings","help"]),k=Object.freeze(["topLeft","topRight","bottomLeft","bottomRight"]),x=Object.freeze(["arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode"]),S=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),D=e=>typeof e=="string"&&/^host[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e),_=e=>typeof e=="string"&&/^slot[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e);function g(e,i,l){if(!S(e))throw new TypeError(l+" must be an object");for(let c of Object.keys(e))if(!i.includes(c))throw new TypeError("Unknown "+l+" option: "+c)}function O(e,i){if(typeof e!="boolean")throw new TypeError(i+" must be a boolean");return e}function U(e,i){if(typeof e!="string"||!e.trim())throw new TypeError(i+" must be a nonempty string");return e}function I(e,i,l=c=>typeof c=="string"&&!!c.trim()){if(!Array.isArray(e)||e.some(c=>!l(c))||new Set(e).size!==e.length)throw new TypeError(i+" must contain distinct valid IDs");return Object.freeze([...e])}function A(e,i,l){return e===void 0?{}:typeof e=="boolean"?{visible:e}:(g(e,["visible",...i],l),e.visible!==void 0&&O(e.visible,l+".visible"),e)}function v(e={}){e===!1&&(e={enabled:!1}),g(e,["enabled","buttons","actions","regions","drawingToolbar","contextToolbar","tooltip"],"ui");let i=e.enabled===void 0?!0:O(e.enabled,"ui.enabled"),l=e.buttons??{};g(l,E,"ui.buttons");let c=Object.fromEntries(E.map(t=>[t,t!=="help"]));for(let[t,d]of Object.entries(l))c[t]=O(d,"ui.buttons."+t);let a=new Map;if(e.actions!==void 0&&!Array.isArray(e.actions))throw new TypeError("ui.actions must be an array");let p=(e.actions??[]).map(t=>{if(g(t,["id","label","icon","visible","enabled","onInvoke"],"action"),!D(t.id))throw new TypeError("Action id must use the host. namespace");if(a.has(t.id))throw new TypeError("Duplicate action id: "+t.id);if(typeof t.onInvoke!="function")throw new TypeError("Action "+t.id+" requires an onInvoke handler");let d={id:t.id,label:U(t.label,"Action label"),enabled:t.enabled===void 0?!0:O(t.enabled,"Action enabled"),visible:t.visible===void 0?!0:O(t.visible,"Action visible")};return t.icon!==void 0&&(d.icon=U(t.icon,"Action icon")),a.set(t.id,t.onInvoke),Object.freeze(d)}),f=e.regions??{};g(f,k,"ui.regions");let u=new Set(Object.values(f).flatMap(t=>S(t)&&Array.isArray(t.items)?t.items.filter(D):[])),j={topLeft:["undo","redo","selectObjects"],topRight:["help",...p.filter(t=>!u.has(t.id)).map(t=>t.id)],bottomLeft:[],bottomRight:["zoomOut","resetZoom","zoomIn","settings"]},h=Object.fromEntries(k.map(t=>{let d=A(f[t],["items"],"ui.regions."+t);return[t,Object.freeze({visible:i&&(d.visible??!0),items:I(d.items??j[t],"ui.regions."+t+".items",z=>E.includes(z)||a.has(z)||_(z))})]})),y=A(e.drawingToolbar,["position","tools"],"ui.drawingToolbar"),m=y.position??"left";if(!["left","right","top","bottom"].includes(m))throw new TypeError("ui.drawingToolbar.position must be left, right, top or bottom");let w=Object.freeze({visible:i&&(y.visible??!0),position:m,tools:I(y.tools??x.filter(t=>t!=="sketchyMode"),"ui.drawingToolbar.tools",t=>x.includes(t))}),o=A(e.contextToolbar,["objectTypes","tools","panels"],"ui.contextToolbar"),r={visible:i&&(o.visible??!0)};for(let t of["objectTypes","tools","panels"])o[t]!==void 0&&(r[t]=I(o[t],"ui.contextToolbar."+t));let b=A(e.tooltip,["position","delay"],"ui.tooltip"),n=b.position??"top",s=b.delay??250;if(!["top","bottom","left","right"].includes(n))throw new TypeError("ui.tooltip.position must be top, bottom, left or right");if(!Number.isFinite(s)||s<0)throw new TypeError("ui.tooltip.delay must be nonnegative");let R=Object.freeze({visible:b.visible??!0,position:n,delay:s});return Object.freeze({ui:Object.freeze({enabled:i,buttons:Object.freeze(c),actions:Object.freeze(p),regions:Object.freeze(h),drawingToolbar:w,contextToolbar:Object.freeze(r),tooltip:R}),handlers:a})}function N(e,i){let{ui:l,handlers:c}=v(i),a=l,p=!1,f=new Set,u=new Set,j=()=>new T("EditorDisposed","Editor UI has been disposed"),h=()=>{if(p||e.lifecycle!=="ready")throw j()},y,m,w=()=>{if(!p){p=!0,y?.(),m?.();for(let o of u)o.abort(j());u.clear(),c.clear(),f.clear()}};return e.lifecycle==="ready"?(m=e.onEvent("disposing",w),y=e.onDisposed(w)):w(),Object.freeze({get ui(){return a},editor:e,dispose:w,onChanged(o){if(h(),typeof o!="function")throw new TypeError("Listener must be a function");f.add(o);try{o(a)}catch(r){throw f.delete(o),r}return()=>f.delete(o)},async invokeAction(o){h();let r=c.get(o),b=a.actions.find(s=>s.id===o);if(!r)throw new T("UnknownAction","Unknown host action: "+o);if(!b.enabled||!b.visible)throw new T("ActionUnavailable","Host action is unavailable: "+o);let n=new AbortController;u.add(n);try{await r({editor:e,signal:n.signal})}catch(s){throw s instanceof T?s:new T(typeof s?.code=="string"?s.code:"HostActionFailed",s?.message??String(s),{cause:s})}finally{u.delete(n)}},async setActionState(o,r){if(h(),!c.has(o))throw new TypeError("Unknown host action: "+o);if(!r||typeof r!="object"||Array.isArray(r)||Object.keys(r).some(n=>!["label","enabled","visible"].includes(n)))throw new TypeError("Invalid action state");let b={};if(r.label!==void 0){if(typeof r.label!="string"||!r.label.trim())throw new TypeError("Action label must be a nonempty string");b.label=r.label}for(let n of["enabled","visible"])if(r[n]!==void 0){if(typeof r[n]!="boolean")throw new TypeError("Action "+n+" must be a boolean");b[n]=r[n]}a=Object.freeze({...a,actions:Object.freeze(a.actions.map(n=>n.id===o?Object.freeze({...n,...b}):n))});for(let n of f)try{n(a)}catch(s){console.error("Editor UI listener failed",s)}}})}export{N as createEditorUiController};
|
package/dist/ui-model.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export interface ItemNumbering {
|
|
|
10
10
|
readonly drawingEnabled: boolean;
|
|
11
11
|
}
|
|
12
12
|
export declare function itemNumbering(item: EditorSelectedObject): ItemNumbering | undefined;
|
|
13
|
-
export declare function contextTools(items: readonly EditorSelectedObject[], options: NormalizedUiOptions['contextToolbar']): string[];
|
|
13
|
+
export declare function contextTools(items: readonly EditorSelectedObject[], options: NormalizedUiOptions['contextToolbar'], groupCount?: number): string[];
|
|
14
14
|
export declare function placeFloating(anchor: EditorScreenBounds, size: {width:number;height:number}, viewport: {width:number;height:number}): {left:number;top:number};
|
|
15
15
|
export declare function mapCanvasBounds(bounds: EditorScreenBounds, canvas: EditorScreenBounds & {width:number;height:number}, canvasSize: {width:number;height:number}, host: EditorScreenBounds & {width:number;height:number}, hostSize: {width:number;height:number}): EditorScreenBounds;
|
package/dist/ui-options.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { EditorInstance } from '@drawmotive/editor';
|
|
|
2
2
|
/** Creation tools and the document's sketch mode toggle share toolbar configuration. */
|
|
3
3
|
export type DrawingToolId = 'arrow' | 'rectangle' | 'ellipse' | 'diamond' | 'capsule' | 'star' | 'cloud' | 'text' | 'sketchyMode';
|
|
4
4
|
/** drawingProperties is a legacy Settings entry; defaults expose only settings. */
|
|
5
|
-
export type EditorButtonId = 'undo' | 'redo' | DrawingToolId | 'drawingProperties' | 'zoomIn' | 'zoomOut' | 'resetZoom' | 'settings' | 'help';
|
|
5
|
+
export type EditorButtonId = 'undo' | 'redo' | 'selectObjects' | DrawingToolId | 'drawingProperties' | 'zoomIn' | 'zoomOut' | 'resetZoom' | 'settings' | 'help';
|
|
6
6
|
export type EditorRegionId = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
|
|
7
7
|
/** Slots name React content resolved by the local UI; elements never cross a port. */
|
|
8
8
|
export type EditorRegionItem = EditorButtonId | `host.${string}` | `slot.${string}`;
|
|
@@ -11,6 +11,11 @@ interface HotkeyContext {
|
|
|
11
11
|
report(reason: unknown): void;
|
|
12
12
|
activateTool(tool: QuickInsertTool): Promise<void>;
|
|
13
13
|
openQuickInsert(): void;
|
|
14
|
+
groups?: {
|
|
15
|
+
create(): Promise<void>;
|
|
16
|
+
ungroup(): Promise<void>;
|
|
17
|
+
rename(id: string): Promise<void>;
|
|
18
|
+
};
|
|
14
19
|
}
|
|
15
20
|
/** Mantine owns key matching. Native methods receive only semantic intent;
|
|
16
21
|
* canvas scope and held-input cleanup stay in the shared browser document. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drawmotive/editor-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Reusable React drawing controls for the DrawMotive canvas editor.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"prepack": "npm run release:check && npm run build"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@drawmotive/editor": "0.3.
|
|
59
|
+
"@drawmotive/editor": "0.3.6",
|
|
60
60
|
"@mantine/core": "9.8.1",
|
|
61
61
|
"@mantine/hooks": "9.8.1",
|
|
62
62
|
"@phosphor-icons/react": "2.1.10"
|