@drawmotive/editor-ui 0.3.3 → 0.3.5

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/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";.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-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-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}}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{useEffect as tn,useRef as pt,useState as on}from"react";import{createEditor as rn}from"@drawmotive/editor";import{useCallback as je,useEffect as ct,useLayoutEffect as Kr,useRef as Y,useState as j}from"react";import{MantineProvider as Wr,MantineThemeProvider as _r,mergeThemeOverrides as Gr}from"@mantine/core";var sn=Object.freeze(["strokeFillColor","strokeColor","strokeStyle","cornerRadius","editText","textSizeSmall","textSizeMedium","textSizeLarge","bold","italic","textAlign","lineStartStyle","lineEndStyle","swapLineEndpoints","lineRouting","groupTheme","groupTitleStyle","moreOptions"]),Fe=Object.freeze(["strokeFillColor","strokeColor","strokeStyle","textAlign","lineStartStyle","lineEndStyle","lineRouting","groupTitleStyle","moreOptions"]);function Z(e){let t=e.length===2&&e.find(r=>r.kind==="BoundText"&&e.some(o=>o.id===r.bindingItemId));return t?[t]:e}function yt(e,t){if(e=Z(e),!t.visible||!e.length||e.some(n=>t.objectTypes&&!t.objectTypes.includes(n.kind)))return[];let r=n=>e.every(i=>i.capabilities[n]),o=[];return r("text")?o.push("strokeColor","textSizeSmall","textSizeMedium","textSizeLarge","bold","italic","textAlign"):(r("line")&&o.push("lineStartStyle","swapLineEndpoints","lineEndStyle","lineRouting"),r("group")&&(o.push("groupTheme"),e.length===1&&r("groupTitle")&&o.push("groupTitleStyle")),r("stroke")&&o.push(r("fill")?"strokeFillColor":"strokeColor"),r("stroke")&&o.push("strokeStyle"),r("cornerRadius")&&o.push("cornerRadius")),r("editText")&&e.length===1&&o.push("editText"),o.push("moreOptions"),o.filter(n=>(!t.tools||t.tools.includes(n))&&(!Fe.includes(n)||!t.panels||t.panels.includes(n)))}function vt(e,t,r){let o=(n,i,c)=>Math.max(4,Math.min(n,i-c-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 xt(e,t,r,o,n){let i=d=>(t.left-o.left+d*t.width/(r.width||1))*(n.width||1)/(o.width||1),c=d=>(t.top-o.top+d*t.height/(r.height||1))*(n.height||1)/(o.height||1);return{left:i(e.left),top:c(e.top),right:i(e.right),bottom:c(e.bottom)}}var kt=Object.freeze({state:"Unavailable"}),U=e=>({state:"Uniform",value:e}),St=["strokeColor","fillColor","strokeWidth","strokeStyle","cornerRadius","textSize","resolvedTextSize","bold","italic","horizontalAlignment","verticalAlignment","lineStartStyle","lineEndStyle","lineRouting","groupColorRole","groupHeaderVisible"],Ke=(e,t,r)=>Object.entries(e.resolved?.themeValues?.[t]??{}).find(([,o])=>o===r)?.[0]??null,wt=(e,t)=>{let r=Ke(e,"colors",t);return{role:r,argb:r===null?t??null:null}};function se(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 Et(e){let t=e.model,r=e.capabilities,o=e.resolved??{},n=t.data?.paintStyle??{},i=t.fontStyle??{},c=o.fontStyle??{},d=Object.fromEntries(St.map(f=>[f,kt]));return d.strokeColor=U(wt(e,r.text?i.color:n.color)),r.text?(Object.assign(d,{textSize:U(Ke(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")}),r.verticalTextAlignment&&(d.verticalAlignment=U(c.verticalTextAlign??"Center"))):(d.strokeWidth=U(Ke(e,"lineWidths",n.strokeWidth)??n.strokeWidth),d.strokeStyle=U(n.strokeClass??"Solid"),r.fill&&(d.fillColor=U(wt(e,n.fillColor))),r.cornerRadius&&(d.cornerRadius=U(o.cornerRadius??0))),r.line&&Object.assign(d,{lineStartStyle:U(t.startStyle??0),lineEndStyle:U(t.endStyle??1),lineRouting:U(r.connectorRouting?t.routing??"Straight":"Straight")}),r.group&&Object.assign(d,{groupColorRole:U(o.groupColorRole??null),groupHeaderVisible:U(o.groupHeaderVisible??!0)}),{...e,properties:d,...e.boundText?{boundText:Et(e.boundText)}:{}}}function he(e){let t=e.items.map(Et),r=Z(t),o=Object.fromEntries(St.map(n=>{let i=r.map(d=>d.properties[n]);if(!i.length||i.some(d=>d.state==="Unavailable"))return[n,kt];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:o}}var R=(e,t,r)=>({itemId:e.id,path:t,value:r}),X=(e,t,...r)=>({itemId:e.id,op:"call",path:[t],arguments:r});function Oe(e,t,r,o){return{revision:e.revision,description:t,token:e.token,changes:(o?[o]:Z(e.items)).flatMap(r)}}import{EditorError as ve}from"@drawmotive/editor";var Me=Object.freeze(["undo","redo","arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode","drawingProperties","zoomIn","zoomOut","resetZoom","settings","help"]),_e=Object.freeze(["topLeft","topRight","bottomLeft","bottomRight"]),ae=Object.freeze(["arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode"]),Pt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Tt=e=>typeof e=="string"&&/^host[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e),Eo=e=>typeof e=="string"&&/^slot[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e);function be(e,t,r){if(!Pt(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 ye(e,t){if(typeof e!="boolean")throw new TypeError(t+" must be a boolean");return e}function Ct(e,t){if(typeof e!="string"||!e.trim())throw new TypeError(t+" must be a nonempty string");return e}function We(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 Ue(e,t,r){return e===void 0?{}:typeof e=="boolean"?{visible:e}:(be(e,["visible",...t],r),e.visible!==void 0&&ye(e.visible,r+".visible"),e)}function Ge(e={}){e===!1&&(e={enabled:!1}),be(e,["enabled","buttons","actions","regions","drawingToolbar","contextToolbar","tooltip"],"ui");let t=e.enabled===void 0?!0:ye(e.enabled,"ui.enabled"),r=e.buttons??{};be(r,Me,"ui.buttons");let o=Object.fromEntries(Me.map(a=>[a,a!=="help"]));for(let[a,T]of Object.entries(r))o[a]=ye(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(be(a,["id","label","icon","visible","enabled","onInvoke"],"action"),!Tt(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:Ct(a.label,"Action label"),enabled:a.enabled===void 0?!0:ye(a.enabled,"Action enabled"),visible:a.visible===void 0?!0:ye(a.visible,"Action visible")};return a.icon!==void 0&&(T.icon=Ct(a.icon,"Action icon")),n.set(a.id,a.onInvoke),Object.freeze(T)}),c=e.regions??{};be(c,_e,"ui.regions");let d=new Set(Object.values(c).flatMap(a=>Pt(a)&&Array.isArray(a.items)?a.items.filter(Tt):[])),f={topLeft:["undo","redo"],topRight:["help",...i.filter(a=>!d.has(a.id)).map(a=>a.id)],bottomLeft:[],bottomRight:["zoomOut","resetZoom","zoomIn","settings"]},g=Object.fromEntries(_e.map(a=>{let T=Ue(c[a],["items"],"ui.regions."+a);return[a,Object.freeze({visible:t&&(T.visible??!0),items:We(T.items??f[a],"ui.regions."+a+".items",N=>Me.includes(N)||n.has(N)||Eo(N))})]})),m=Ue(e.drawingToolbar,["position","tools"],"ui.drawingToolbar"),E=m.position??"left";if(!["left","right","top","bottom"].includes(E))throw new TypeError("ui.drawingToolbar.position must be left, right, top or bottom");let x=Object.freeze({visible:t&&(m.visible??!0),position:E,tools:We(m.tools??ae.filter(a=>a!=="sketchyMode"),"ui.drawingToolbar.tools",a=>ae.includes(a))}),h=Ue(e.contextToolbar,["objectTypes","tools","panels"],"ui.contextToolbar"),s={visible:t&&(h.visible??!0)};for(let a of["objectTypes","tools","panels"])h[a]!==void 0&&(s[a]=We(h[a],"ui.contextToolbar."+a));let u=Ue(e.tooltip,["position","delay"],"ui.tooltip"),y=u.position??"top",S=u.delay??250;if(!["top","bottom","left","right"].includes(y))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 p=Object.freeze({visible:u.visible??!0,position:y,delay:S});return Object.freeze({ui:Object.freeze({enabled:t,buttons:Object.freeze(o),actions:Object.freeze(i),regions:Object.freeze(g),drawingToolbar:x,contextToolbar:Object.freeze(s),tooltip:p}),handlers:n})}function Qe(e,t){let{ui:r,handlers:o}=Ge(t),n=r,i=!1,c=new Set,d=new Set,f=()=>new ve("EditorDisposed","Editor UI has been disposed"),g=()=>{if(i||e.lifecycle!=="ready")throw f()},m,E,x=()=>{if(!i){i=!0,m?.(),E?.();for(let h of d)h.abort(f());d.clear(),o.clear(),c.clear()}};return e.lifecycle==="ready"?(E=e.onEvent("disposing",x),m=e.onDisposed(x)):x(),Object.freeze({get ui(){return n},editor:e,dispose:x,onChanged(h){if(g(),typeof h!="function")throw new TypeError("Listener must be a function");c.add(h);try{h(n)}catch(s){throw c.delete(h),s}return()=>c.delete(h)},async invokeAction(h){g();let s=o.get(h),u=n.actions.find(S=>S.id===h);if(!s)throw new ve("UnknownAction","Unknown host action: "+h);if(!u.enabled||!u.visible)throw new ve("ActionUnavailable","Host action is unavailable: "+h);let y=new AbortController;d.add(y);try{await s({editor:e,signal:y.signal})}catch(S){throw S instanceof ve?S:new ve(typeof S?.code=="string"?S.code:"HostActionFailed",S?.message??String(S),{cause:S})}finally{d.delete(y)}},async setActionState(h,s){if(g(),!o.has(h))throw new TypeError("Unknown host action: "+h);if(!s||typeof s!="object"||Array.isArray(s)||Object.keys(s).some(y=>!["label","enabled","visible"].includes(y)))throw new TypeError("Invalid action state");let u={};if(s.label!==void 0){if(typeof s.label!="string"||!s.label.trim())throw new TypeError("Action label must be a nonempty string");u.label=s.label}for(let y of["enabled","visible"])if(s[y]!==void 0){if(typeof s[y]!="boolean")throw new TypeError("Action "+y+" must be a boolean");u[y]=s[y]}n=Object.freeze({...n,actions:Object.freeze(n.actions.map(y=>y.id===h?Object.freeze({...y,...u}):y))});for(let y of c)try{y(n)}catch(S){console.error("Editor UI listener failed",S)}}})}import{cloneElement as lr,createContext as Nt,forwardRef as sr,useContext as Dt,useLayoutEffect as ar,useMemo as dr,useRef as At,useState as cr}from"react";import{Kbd as pr,Popover as Je,Tooltip as ur,UnstyledButton as mr}from"@mantine/core";import{AlignBottomSimple as To,AlignCenterVerticalSimple as Co,AlignTopSimple as Po,ArrowBendRightUp as Io,ArrowBendUpLeft as zo,ArrowBendUpRight as Ro,ArrowDownRight as Oo,ArrowElbowRightUp as Uo,ArrowRight as Mo,ArrowUpRight as Ao,Browser as No,Circle as Do,Cloud as Lo,Copy as Ho,Cursor as Bo,Diamond as jo,DotsThreeVertical as qo,GearSix as Vo,MagnifyingGlass as Zo,MagnifyingGlassMinus as Fo,MagnifyingGlassPlus as Ko,Minus as Ot,Palette as Ut,Path as Wo,Pill as _o,Prohibit as Go,Question as Qo,Rectangle as Mt,Scribble as $o,Star as Xo,TextAlignCenter as It,TextAlignLeft as Jo,TextAlignRight as Yo,TextB as er,Textbox as zt,TextItalic as tr,TextT as Ae,Trash as or,X as rr}from"@phosphor-icons/react";import{jsx as M}from"react/jsx-runtime";var nr={undo:zo,redo:Ro,arrow:Oo,rectangle:Mt,ellipse:Do,diamond:jo,text:Ae,capsule:_o,star:Xo,cloud:Lo,select:Bo,sketchyMode:$o,zoomIn:Ko,zoomOut:Fo,settings:Vo,drawingProperties:Ut,help:Qo,editText:zt,search:Zo,bold:er,italic:tr,textAlign:It,textSizeSmall:Ae,textSizeMedium:Ae,textSizeLarge:Ae,textAlignLeft:Jo,textAlignCenter:It,textAlignRight:Yo,textAlignTop:Po,textAlignMiddle:Co,textAlignBottom:To,lineRouting:Wo,routingStraight:Ao,routingOrthogonal:Uo,routingCurved:Io,groupTheme:No,groupTitleStyle:zt,moreOptions:qo,copy:Ho,delete:or,close:rr,transparent:Go};var ir={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 $e({name:e,size:t,mirrored:r=!1,style:o}){let n=ir[e];return M("svg",{viewBox:n.viewBox,width:t,height:t,fill:"currentColor","aria-hidden":"true",style:o,children:M("g",{transform:r?"translate(960 0) scale(-1 1)":void 0,children:M("path",{d:n.path})})})}function B({name:e,style:t}){if(e==="strokeColor"||e==="strokeFillColor")return M(de,{style:t});if(e==="lineStartStyle"||e==="lineEndStyle")return M(xe,{value:1,start:e==="lineStartStyle",style:t});if(e==="strokeStyle")return M($e,{name:"lineStyle",size:19,style:t});if(e==="cornerRadius")return M($e,{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 r=nr[e]??Mt;return M(r,{size:e==="textSizeSmall"?14:e==="textSizeLarge"?24:19,weight:"regular","aria-hidden":"true",style:t})}function de({fill:e="none",style:t}){return M(Ut,{size:20,weight:"duotone",className:"dm-palette","aria-hidden":"true",style:{"--dm-palette-fill":e,...t}})}var Rt={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 Xe({width:e,pattern:t}){return t===void 0?M(Ot,{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:Rt[t]??Rt.Solid})})}function xe({value:e,start:t=!1,style:r}){return e<=2?M(e===0?Ot:Mo,{size:22,weight:e===2?"fill":"regular",mirrored:t,"aria-hidden":"true",style:r}):M($e,{name:e===3?"lineEndArrowNotch":e===4?"lineEndCircle":"lineEndDiamond",size:22,mirrored:t,style:r})}import{jsx as J,jsxs as Lt}from"react/jsx-runtime";var Ye=Nt(null),Ne=Nt(void 0);function A(){let e=Dt(Ye);if(!e)throw new Error("Editor controls need EditorUi");return e}var C=e=>e?.state==="Uniform"?e.value:void 0,De={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",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=sr(function({icon:t,children:r,selected:o,shortcut:n,className:i="",...c},d){let{ui:f}=A(),g=c["aria-label"]??De[t??""]??t??"",m=Dt(Ne)??f.tooltip.position;return J(ur,{label:Lt("span",{style:{display:"inline-flex",alignItems:"center",gap:8},children:[g,n&&J(pr,{size:"xs",children:n})]}),position:m,offset:12,openDelay:f.tooltip.delay,disabled:!f.tooltip.visible,events:{hover:!0,focus:!0,touch:!1},withinPortal:!1,withArrow:!0,zIndex:100,children:J(mr,{ref:d,...c,className:"dm-tool "+i,"aria-label":g,"aria-pressed":o,"data-selected":o===!0?"":void 0,children:r??J(B,{name:t??""})})})});function te({id:e,button:t,children:r,label:o,nested:n=!1}){let{panel:i,setPanel:c,state:d}=A(),[f,g]=cr(!1),m=n?f:i===e,E=u=>n?g(u):c(u?e:null),x=dr(()=>typeof document>"u"||!document.activeElement?.matches(".drawmotive-canvas-host canvas"),[m]),h=At(null),s=At(d.busy);return ar(()=>{let u=h.current,y=u?.ownerDocument;m&&(s.current||d.busy)&&y&&y.activeElement===y.body&&u?.focus({preventScroll:!0}),s.current=d.busy},[m,d.busy]),Lt(Je,{opened:m,onChange:E,position:"top-start",offset:5,withinPortal:!1,trapFocus:!0,returnFocus:x,transitionProps:{duration:0},classNames:{dropdown:"dm-panel"},children:[J(Je.Target,{children:lr(t,{onClick:u=>{t.props.onClick?.(u),E(!m)}})}),J(Je.Dropdown,{ref:h,tabIndex:-1,role:"dialog","aria-label":o??De[e]??e,children:r})]})}var Le=()=>J("span",{className:"dm-separator",role:"separator","aria-orientation":"vertical"}),He=({children:e})=>J("div",{className:"dm-panel-heading",children:e});function et(e="Foreground"){return"--dm-color-"+e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase().replace(/[^a-z-]/g,"")}function oe(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("+et(e??void 0)+", currentColor)"}import{forwardRef as fr,useEffect as Ht,useImperativeHandle as gr,useRef as tt}from"react";import{Tooltip as hr}from"@mantine/core";import{jsx as Bt}from"react/jsx-runtime";var br=fr(function({canvas:t,instruction:r,onMouseEnter:o,onMouseLeave:n},i){let c=tt({onMouseEnter:o,onMouseLeave:n}),d=tt(null),f=tt(t.matches(":hover"));return c.current={onMouseEnter:o,onMouseLeave:n},gr(i,()=>t,[t]),Ht(()=>{let g=h=>{f.current=!0,d.current=h,c.current.onMouseEnter?.(h)},m=h=>{f.current=!1,c.current.onMouseLeave?.(h)},E=h=>{d.current=h},x=h=>{if(!t.hasPointerCapture(h.pointerId))return;let s=t.ownerDocument.elementFromPoint(h.clientX,h.clientY)===t;s&&!f.current?g(h):!s&&f.current&&m(h)};return t.addEventListener("mouseenter",g),t.addEventListener("mouseleave",m),t.addEventListener("mousemove",E),t.addEventListener("pointermove",x),()=>{t.removeEventListener("mouseenter",g),t.removeEventListener("mouseleave",m),t.removeEventListener("mousemove",E),t.removeEventListener("pointermove",x)}},[t]),Ht(()=>{r&&f.current&&d.current&&c.current.onMouseEnter?.(d.current)},[r]),null});function jt({container:e}){let{state:t,ui:r}=A(),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 Bt(hr.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:Bt(br,{canvas:o,instruction:n})})}import{Kbd as yr,Tooltip as qt}from"@mantine/core";function Vt(e){let t={backgroundColor:"var(--mantine-color-gray-"+(e?"2":"9")+")",color:"var(--mantine-color-"+(e?"black":"white")+")"};return{components:{Tooltip:qt.extend({styles:{tooltip:t}}),TooltipFloating:qt.Floating.extend({styles:{tooltip:t}}),Kbd:yr.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 vr}from"react";import{Checkbox as xr,CloseButton as wr,Loader as Zt,NativeSelect as kr,PasswordInput as Sr}from"@mantine/core";import{CaretUpDown as Er,Check as Tr,Eye as Cr,EyeSlash as Pr,Minus as Ir,SpinnerGap as zr,X as Rr}from"@phosphor-icons/react";import{jsx as ke}from"react/jsx-runtime";var Or=({indeterminate:e,...t})=>ke(e?Ir:Tr,{...t,size:"100%",weight:"bold","aria-hidden":"true"});function Ur({reveal:e}){return ke(e?Pr:Cr,{size:"var(--psi-icon-size)",weight:"regular","aria-hidden":"true"})}var Mr=vr(({className:e,style:t,size:r,...o},n)=>ke(zr,{...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}})),ot={components:{Checkbox:xr.extend({defaultProps:{icon:Or}}),CloseButton:wr.extend({defaultProps:{icon:ke(Rr,{size:"var(--cb-icon-size, 70%)",weight:"regular","aria-hidden":"true"})}}),NativeSelect:kr.extend({defaultProps:{rightSection:ke(Er,{size:"1em",weight:"regular","aria-hidden":"true"})}}),PasswordInput:Sr.extend({defaultProps:{visibilityToggleIcon:Ur}}),Loader:Zt.extend({defaultProps:{loaders:{...Zt.defaultLoaders,phosphor:Mr},type:"phosphor"}})}};import{NativeSelect as Ft}from"@mantine/core";import{Fragment as lt,jsx as v,jsxs as ce}from"react/jsx-runtime";var Kt=["Transparent","Foreground","PrimaryStroke","SecondaryStroke","AccentStroke","SuccessStroke","WarningStroke"],Ar=["Transparent","Background","PrimaryFill","SecondaryFill","AccentFill","SuccessFill","WarningFill"],Nr=["Foreground","Background",...Kt.slice(2)],Dr=["PrimaryStroke","SecondaryStroke","AccentStroke","SuccessStroke","WarningStroke"];function Be({fill:e=!1,target:t}){let{selection:r,edit:o}=A(),n=t?.properties??r.properties;return v(lt,{children:(e?[!1,!0]:[!1]).map(i=>{let c=i?Ar:e?Kt:Nr,d=C(i?n.fillColor:n.strokeColor);return ce("div",{children:[v(He,{children:i?"Fill Color":e?"Border Color":"Color"}),v("div",{className:"dm-panel-row",children:c.map(f=>v(z,{"aria-label":f==="Transparent"?i?"No Fill":"No Border":f.replace(/(Stroke|Fill)$/,"")+" color",selected:d?.role===f&&d.argb===null,"data-testid":"panel-"+(i?"fill":"stroke")+"-color-"+f.toLowerCase(),onClick:()=>{o(i?"Change fill color":"Change stroke color",g=>{let m=g.capabilities.text?["fontStyle","color"]:["data","paintStyle",i?"fillColor":"color"];return[R(g,m,se(g,"colors",f))]},t)},children:f==="Transparent"?v(B,{name:"transparent",style:{color:"var(--dm-color-secondary-stroke)"}}):v(de,{fill:i?oe(f):"none",style:{color:oe(f)}})},f))})]},String(i))})})}function Wt(){let{selection:e,edit:t}=A(),r=e.properties;return ce(lt,{children:[v(He,{children:"Line Width"}),v("div",{className:"dm-panel-row",children:["Thin","Normal","Bold"].map((o,n)=>v(z,{"aria-label":o+" line",selected:C(r.strokeWidth)===o,"data-testid":"panel-stroke-width-"+n,onClick:()=>{t("Change stroke width",i=>[R(i,["data","paintStyle","strokeWidth"],se(i,"lineWidths",o))])},children:v(Xe,{width:n})},o))}),v(He,{children:"Line Style"}),v("div",{className:"dm-panel-row",children:["Solid","Dashed","Dotted"].map((o,n)=>v(z,{"aria-label":o+" line",selected:C(r.strokeStyle)===o,"data-testid":"panel-stroke-style-"+n,onClick:()=>{t("Change stroke style",i=>[R(i,["data","paintStyle","strokeClass"],o)])},children:v(Xe,{pattern:o})},o))})]})}function rt({target:e}){let{selection:t,edit:r}=A(),o=e?[e]:Z(t.items),n=e?.properties??t.properties;return v(lt,{children:[!1,...o.every(i=>i.capabilities.verticalTextAlignment)?[!0]:[]].map(i=>v("div",{className:"dm-panel-row",children:(i?["Top","Center","Bottom"]:["Left","Center","Right"]).map(c=>v(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:()=>{r("Change text alignment",d=>[R(d,["fontStyle",i?"verticalTextAlign":"textAlign"],c)],e)},children:v(B,{name:"textAlign"+(i&&c==="Center"?"Middle":c)})},c))},String(i)))})}function nt({start:e}){let{selection:t,edit:r}=A(),o=C(e?t.properties.lineStartStyle:t.properties.lineEndStyle);return v("div",{className:"dm-endpoint-grid",children:["None","Simple arrow","Filled arrow","Open arrow","Circle","Diamond"].map((n,i)=>v(z,{"aria-label":n,selected:o===i,"data-testid":"panel-line-"+(e?"start":"end")+"-style-"+i,onClick:()=>{r("Change endpoint style",c=>[R(c,[e?"startStyle":"endStyle"],i)])},children:v(xe,{value:i,start:e})},n))})}function _t(){let{selection:e,edit:t}=A(),r=e.items.every(o=>o.capabilities.connectorRouting);return v("div",{className:"dm-panel-row",children:["Straight","Orthogonal","Curved"].map((o,n)=>v(z,{"aria-label":o,selected:C(e.properties.lineRouting)===o,disabled:o!=="Straight"&&!r,"data-testid":"panel-line-connector-style-"+n,onClick:()=>{t("Change routing",i=>[X(i,"setRoutingMode",o)])},children:v(B,{name:"routing"+o})},o))})}function it({inline:e=!1}){let{selection:t,edit:r}=A(),o=t.properties;return ce("div",{className:e?"dm-group-controls":"dm-panel-stack",children:[v(Ft,{"aria-label":"Group theme color",label:e?void 0:"Group theme color",size:"xs",value:C(o.groupColorRole)??"auto",data:[{value:"auto",label:o.groupColorRole.state==="Mixed"?"Mixed":"Theme default"},...Dr.map(n=>({value:n,label:n.replace("Stroke","")}))],onChange:n=>{let i=n.currentTarget.value;r("Change group theme color",c=>[X(c,"setThemeColorRole",i==="auto"?null:i)])}}),v(z,{icon:"groupTheme","aria-label":"Toggle title background","data-testid":"group-title-background",selected:C(o.groupHeaderVisible)===!0,onClick:()=>{r("Toggle title background",n=>[X(n,"setHeaderVisible",C(o.groupHeaderVisible)!==!0)])}}),v(Gt,{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=>[X(i,"resetStyle",n)])})]})}function Gt({label:e,prompt:t,testId:r,choices:o,onChange:n}){return v(Ft,{"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 Qt(){let{selection:e,edit:t}=A(),r=e.items[0]?.boundText;return r?ce("div",{className:"dm-title-controls",children:[v(te,{id:"title-color",label:"Title color",nested:!0,button:v(z,{icon:"strokeColor"}),children:v(Be,{target:r})}),v(Le,{}),v(Lr,{target:r}),v(te,{id:"title-align",label:"Title alignment",nested:!0,button:v(z,{icon:"textAlign"}),children:v(rt,{target:r})}),v(Gt,{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=>[X(n,"resetTitleStyle",o)])})]}):null}function Lr({target:e}){let{edit:t}=A(),r=e.properties;return ce("div",{className:"dm-panel-row",children:[v("span",{className:"dm-button-group",children:["Small","Medium","Large"].map(o=>v(z,{icon:"textSize"+o,selected:C(r.textSize)===o,onClick:()=>{t("Set text size",n=>[R(n,["fontStyle","size"],se(n,"fontSizes",o))],e)}},o))}),v(z,{icon:"bold",selected:C(r.bold)===!0,onClick:()=>{t("Toggle bold",o=>[R(o,["fontStyle","weight"],C(r.bold)===!0?400:700)],e)}}),v(z,{icon:"italic",selected:C(r.italic)===!0,onClick:()=>{t("Toggle italic",o=>[R(o,["fontStyle","slant"],C(r.italic)===!0?"Upright":"Italic")],e)}})]})}function $t({copy:e}){let{editor:t,selection:r,run:o,setPanel:n}=A();return v("div",{className:"dm-panel-stack",children:["Copy","Delete"].map(i=>ce(z,{"aria-label":i,"data-testid":"panel-more-options-"+i.toLowerCase(),className:"dm-menu-item",onClick:()=>{o(async()=>{i==="Copy"?await e():await t.deleteSelection(r.token),n(null)})},children:[v(B,{name:i.toLowerCase()}),v("span",{children:i})]},i))})}import{useEffect as Hr,useRef as Se}from"react";import{getHotkeyHandler as Br,useHotkeys as jr}from"@mantine/hooks";var qr=["alt","shift","ctrl","meta"].reduce((e,t)=>[...e,...e.map(r=>t+"+"+r)],["escape"]);function Xt(e){let t=Se(e);t.current=e;let r=Se(new Set),o=Se(0),n=Se(null),i=Se({alt:!1,shift:!1}),c=s=>s.code||s.key,d=()=>e.container.querySelector(".drawmotive-canvas-host"),f=s=>s.target===d()?.querySelector("canvas"),g=s=>s.isComposing||s.keyCode===229||["Process","Dead","Unidentified"].includes(s.key),m=()=>{let s=e.state();return e.editor.lifecycle==="ready"&&s.editingEnabled&&s.health==="healthy"};function E(s,u,{busy:y=!1,pointer:S=!1,available:p=!0,key:a="document"}={}){if(!(!f(s)||g(s)||!m())){if(r.current.has(c(s))){s.preventDefault();return}if(!(!p||!y&&e.state().busy||!S&&o.current!==0)){if(s.repeat){s.preventDefault();return}r.current.add(c(s)),s.preventDefault(),e.run(u,a)}}}function x(s,u){let y=e.selection(),S=y&&he(y),p=S&&Z(S.items);E(s,()=>{let a=S.properties[u],T=a.state==="Uniform"&&a.value===!0;return e.editor.editScene(Oe(S,"Toggle "+u,N=>[R(N,["fontStyle",u==="bold"?"weight":"slant"],u==="bold"?T?400:700:T?"Upright":"Italic")]))},{available:!!p?.length&&p.every(a=>a.capabilities.text)})}let h=[...Object.entries({a:"arrow",r:"rectangle",o:"ellipse",d:"diamond",t:"text"}).map(([s,u])=>[s,y=>E(y,()=>e.activateTool(u),{available:e.ui.buttons[u]})]),["/",s=>{s.key!=="/"||s.altKey||s.ctrlKey||s.metaKey||s.shiftKey||E(s,async()=>e.openQuickInsert(),{available:e.ui.enabled})}],["s",s=>E(s,()=>e.editor.setSketchyMode(!e.state().sketchyMode),{available:e.ui.buttons.sketchyMode})],["mod+z",s=>E(s,()=>e.editor.undo(),{available:e.state().canUndo})],["mod+shift+z",s=>E(s,()=>e.editor.redo(),{available:e.state().canRedo})],["mod+y",s=>E(s,()=>e.editor.redo(),{available:e.state().canRedo})],["delete",s=>E(s,()=>e.editor.deleteSelection(e.selection().token),{available:!!e.selection()?.items.length})],["mod+c",s=>E(s,()=>e.editor.copyToClipboard(e.selection().token),{available:!!e.selection()?.items.length})],["mod+v",s=>E(s,()=>e.editor.pasteFromClipboard())],["mod+b",s=>x(s,"bold")],["mod+i",s=>x(s,"italic")],["enter",s=>{let u=e.selection(),y=u&&Z(u.items)[0];E(s,()=>e.editor.beginTextEditing(y.id),{available:e.editor.textEditing!=="disabled"&&!!y?.capabilities.editText})}],...qr.map(s=>[s,u=>{u.target instanceof e.container.ownerDocument.defaultView.HTMLElement&&d()?.contains(u.target)&&u.target.matches('[data-testid="d-canvas-content-editable"]')&&!g(u)&&m()?(u.preventDefault(),e.run(()=>e.editor.cancelInteraction(),"interaction")):E(u,()=>e.editor.cancelInteraction(),{busy:!0,pointer:!0,key:"interaction"})}]),["space",s=>E(s,()=>{let u={release:!1,started:e.editor.beginPan()};return n.current=u,u.started},{available:!n.current&&e.state().tool==="select",key:"pan"})]];jr(h.map(([s,u])=>[s,u,{preventDefault:!1,usePhysicalKeys:s!=="/"}]),[],!0),Hr(()=>{let{container:s}=e,u=s.ownerDocument,y=u.defaultView;function S(){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 p(w,q){if(i.current.alt===w&&i.current.shift===q)return;i.current={alt:w,shift:q};let _=t.current.state();t.current.editor.lifecycle==="ready"&&_.editingEnabled&&_.health==="healthy"&&t.current.editor.updateInteractionModifiers({alt:w,shift:q}).catch(G=>t.current.report(G))}function a(){let w=o.current!==0;r.current.clear(),o.current=0,S();let q=t.current.state();w&&t.current.editor.lifecycle==="ready"&&q.editingEnabled&&q.health==="healthy"&&t.current.editor.cancelInteraction().catch(_=>t.current.report(_)),p(!1,!1)}function T(w){if(f(w)){if(["pointercancel","lostpointercapture"].includes(w.type)){(w.type==="pointercancel"||o.current!==0)&&a();return}i.current={alt:w.altKey,shift:w.shiftKey},o.current=w.buttons}else["pointerup","pointercancel"].includes(w.type)&&(o.current=w.buttons)}function N(w){!["Alt","Shift"].includes(w.key)||g(w)||(f(w)||i.current.alt||i.current.shift)&&p(w.altKey,w.shiftKey)}let W=Br([["space",S,{preventDefault:!1,usePhysicalKeys:!0}]]);function Ce(w){r.current.delete(c(w)),N(w),n.current&&(w.code==="Space"||w.key===" ")?S():W(w)}function ne(w){f(w)||a()}function ue(){u.visibilityState==="hidden"&&a()}let Pe=["pointerdown","pointermove","pointerup","pointercancel","lostpointercapture"];for(let w of Pe)u.addEventListener(w,T,!0);return u.addEventListener("keydown",N,!0),u.addEventListener("keyup",Ce,!0),u.addEventListener("focusin",ne,!0),u.addEventListener("visibilitychange",ue),y.addEventListener("blur",a),()=>{a();for(let w of Pe)u.removeEventListener(w,T,!0);u.removeEventListener("keydown",N,!0),u.removeEventListener("keyup",Ce,!0),u.removeEventListener("focusin",ne,!0),u.removeEventListener("visibilitychange",ue),y.removeEventListener("blur",a)}},[e.editor,e.container])}import{Checkbox as ro}from"@mantine/core";import{useEffect as Jt,useRef as st,useState as at}from"react";import{NativeSelect as Yt}from"@mantine/core";import{jsx as pe,jsxs as to}from"react/jsx-runtime";var eo={root:"dm-drawing-property",label:"dm-drawing-property-label",wrapper:"dm-drawing-property-input"};function oo(){let{editor:e,state:t,run:r}=A(),[o,n]=at(null),[i,c]=at(null),[d,f]=at(0),g=st(!1),m=st(t.revision),E=st(null);m.current=t.revision,Jt(()=>(g.current=!0,()=>{g.current=!1}),[]),Jt(()=>{let p=t.revision;!p||t.busy||E.current===p||(E.current=p,c(null),e.getScene().then(a=>{if(!(!g.current||m.current!==p)){if(a.revision!==p)throw new Error("The drawing changed. Read its properties again.");n(a)}}).catch(a=>{g.current&&m.current===p&&c(a)}))},[e,t.revision,t.busy,d]);let x=o?.revision===t.revision,h=o?.metadata.model,s=!x||t.busy||!t.editingEnabled||t.health!=="healthy",u=typeof h?.theme=="string"?h.theme:"default",y=h?.style===1?"1":"0",S=async(p,a)=>{s||!o||await r(()=>e.editScene({revision:o.revision,description:"Change drawing "+p,changes:[{path:[p],value:a}]}))};return to("div",{className:"dm-panel-stack dm-drawing-properties","aria-busy":!x&&!i,children:[pe(Yt,{label:"Theme",classNames:eo,value:u,disabled:s,"data-testid":"drawing-theme",data:[{value:"default",label:"Default"},{value:"minimal",label:"Minimal"}],onChange:p=>{S("theme",p.currentTarget.value)}}),pe("p",{className:"dm-property-description",children:u==="minimal"?"Apple-inspired cards in graphite, ceramic and titanium finishes.":"Balanced colors and classic outlines."}),pe(Yt,{label:"Drawing style",classNames:eo,value:y,disabled:s,"data-testid":"drawing-style",data:[{value:"0",label:"Formal"},{value:"1",label:"Draft"}],onChange:p=>{S("style",Number(p.currentTarget.value))}}),pe("p",{className:"dm-property-description",children:y==="1"?"Hand-drawn strokes and handwriting.":"Precise strokes and clean typography."}),i!=null&&to("div",{role:"alert",children:[pe("p",{children:i?.message??String(i)}),pe(z,{"aria-label":"Read drawing properties again",onClick:()=>{E.current=null,f(p=>p+1)},children:"Try again"})]})]})}import{jsx as $,jsxs as Ee}from"react/jsx-runtime";function no({preferences:e,onChange:t}){return Ee("div",{className:"dm-settings",children:[$("header",{className:"dm-settings-header",children:$("h2",{children:"Settings"})}),Ee("section",{className:"dm-settings-section","aria-label":"View",children:[Ee("div",{className:"dm-settings-section-heading",children:[$("h3",{children:"View"}),$("p",{children:"Only on this device."})]}),$(ro,{label:"Dark Theme","data-testid":"settings-dark-theme",checked:e.darkTheme??!1,onChange:r=>{t({darkTheme:r.currentTarget.checked})}}),$(ro,{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})}})]}),Ee("section",{className:"dm-settings-section","aria-label":"Drawing",children:[Ee("div",{className:"dm-settings-section-heading",children:[$("h3",{children:"Drawing"}),$("p",{children:"Saved with this drawing."})]}),$(oo,{})]})]})}import{useId as Vr,useLayoutEffect as co,useRef as Zr,useState as po}from"react";import{FocusTrap as Fr}from"@mantine/core";var Te=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 io(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 Te){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 dt(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 so(e){let t=io(e)??{},r={};function o(){let n=io(e);if(n!==null){for(let i of Object.keys(r).sort((c,d)=>r[c].lastUsed-r[d].lastUsed))dt(n,i,r[i].count);t=n}}return{read(){return o(),structuredClone(t)},record(n){if(Te.some(i=>i.id===n)){o(),dt(t,n);try{e().setItem(lo,JSON.stringify({version:1,usage:t})),r={}}catch{dt(r,n)}}}}}function ao(e,t,r=Te){let o=e.trim().toLowerCase().split(/\s+/).filter(Boolean),n=r.filter(g=>o.every(m=>(g.label+" "+(g.group??"")+" "+g.aliases).toLowerCase().includes(m)));if(!n.length)return[];let i=new Map,c=n.filter(g=>!g.group);for(let g of n)g.group&&(i.has(g.group)||i.set(g.group,[]),i.get(g.group).push(g));let d=o.length?[]:n.filter(g=>t[g.id]).sort((g,m)=>t[m.id].lastUsed-t[g.id].lastUsed).slice(0,3),f=o.length?[]:n.filter(g=>t[g.id]?.count>1).sort((g,m)=>t[m.id].count-t[g.id].count||t[m.id].lastUsed-t[g.id].lastUsed).slice(0,3);return[...c.length?[{key:"ungrouped",label:null,items:c}]:[],...d.length?[{key:"recent",label:"Recent",items:d}]:[],...f.length?[{key:"frequent",label:"Frequently used",items:f}]:[],...Array.from(i,([g,m])=>({key:"group:"+g,label:g,items:m}))]}import{jsx as O,jsxs as re}from"react/jsx-runtime";function uo({container:e,usage:t,objects:r,disabled:o,onSelect:n,onClose:i}){let[c,d]=po(""),[f,g]=po(0),m=Vr(),E=Zr(null),x=ao(c,t,r),h=x.flatMap(p=>p.items),s=Math.min(f,Math.max(0,h.length-1)),u=h[s],y=u?(u.group?u.group+" / ":"")+u.label:"No objects found";co(()=>{E.current?.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"})},[s,c]),co(()=>()=>{let p=e.ownerDocument;(E.current?.contains(p.activeElement)||p.activeElement===p.body)&&e.querySelector(".drawmotive-canvas-host canvas")?.focus({preventScroll:!0})},[e]);let S=0;return O("div",{className:"dm-quick-insert-backdrop",onPointerDown:p=>{p.target===p.currentTarget&&(p.preventDefault(),i())},children:O(Fr,{active:!0,innerRef:E,children:re("div",{className:"dm-quick-insert",role:"dialog","aria-modal":"true","aria-label":"Quick insert","aria-busy":o,onKeyDown:p=>{p.nativeEvent.isComposing||p.keyCode===229||p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),i())},children:[re("div",{className:"dm-quick-insert-query",children:[O(B,{name:"search"}),O("input",{"data-autofocus":!0,role:"combobox","aria-label":"Search objects","aria-expanded":"true","aria-autocomplete":"list","aria-controls":m+"-list","aria-activedescendant":h.length?m+"-"+s:void 0,"aria-describedby":m+"-hint",className:"dm-quick-insert-search",placeholder:"Search objects\u2026",value:c,readOnly:o,"aria-disabled":o,onChange:p=>{d(p.target.value),g(0)},onKeyDown:p=>{if(!(p.nativeEvent.isComposing||p.keyCode===229||p.altKey||p.ctrlKey||p.metaKey)&&["ArrowDown","ArrowUp","Home","End","Enter"].includes(p.key)){if(c&&["Home","End"].includes(p.key))return;p.preventDefault(),p.key==="Enter"?!p.repeat&&h[s]&&!o&&n(h[s].id):h.length&&g(p.key==="Home"?0:p.key==="End"?h.length-1:(s+(p.key==="ArrowDown"?1:-1)+h.length)%h.length)}}}),O("span",{className:"dm-quick-insert-count","aria-label":"Matching objects",children:new Set(h.map(p=>p.id)).size}),O("button",{type:"button",className:"dm-quick-insert-close","aria-label":"Close quick insert",title:"Close (Esc)",onPointerDown:p=>p.preventDefault(),onClick:i,children:O(B,{name:"close"})})]}),re("div",{id:m+"-list",className:"dm-quick-insert-results",role:"listbox","aria-label":"Objects",children:[x.map(p=>re("div",{className:"dm-quick-insert-group",role:"group","aria-label":p.label??"Objects","data-ungrouped":p.label===null||void 0,children:[p.label&&O("div",{className:"dm-quick-insert-group-label","aria-hidden":"true",children:p.label}),O("div",{className:"dm-quick-insert-grid",children:p.items.map(a=>{let T=S++;return re("button",{id:m+"-"+T,type:"button",className:"dm-quick-insert-option",role:"option","aria-selected":T===s,tabIndex:-1,disabled:o,"aria-label":(a.group?a.group+" / ":"")+a.label,title:(a.group?a.group+" / ":"")+a.label+(a.shortcut?" ("+a.shortcut+")":""),onPointerMove:()=>g(T),onPointerDown:N=>N.preventDefault(),onClick:()=>{n(a.id)},children:[a.iconUrl?O("img",{src:a.iconUrl,alt:"","aria-hidden":"true"}):O(B,{name:a.id}),O("span",{children:a.label})]},a.id)})})]},p.key)),!h.length&&O("div",{className:"dm-quick-insert-empty",role:"status",children:"No objects found"})]}),re("div",{className:"dm-quick-insert-hint",children:[O("span",{className:"dm-quick-insert-detail",title:y,children:y}),u?.shortcut&&O("kbd",{title:"Tool shortcut",children:u.shortcut}),re("span",{id:m+"-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 k,jsxs as K}from"react/jsx-runtime";var mo={revision:null,health:"healthy",editingEnabled:!1,busy:!0,canUndo:!1,canRedo:!1};function Qr(e,t){let r=ae.find(n=>n===t);if(r===void 0||r==="sketchyMode")throw new TypeError("Unknown drawing tool: "+t);return e.setTool.call(e,r)}function qe(e){let t=Y({editor:e.editor,key:0});return t.current.editor!==e.editor&&(t.current={editor:e.editor,key:t.current.key+1}),k($r,{...e},t.current.key)}function $r(e){let[t,r]=j(null);ct(()=>{if(e.controller)return;let n=Qe(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 k(Xr,{...e,controller:o})}function Xr({editor:e,controller:t,container:r,slots:o={},colorScheme:n,className:i="",style:c,onError:d}){let[f,g]=j(t.ui),[m,E]=j(mo),[x,h]=j(null),[s,u]=j({}),[y,S]=j(null),[p,a]=j(null),[T,N]=j(new Set),[W,Ce]=j(e.lifecycle!=="ready"),[ne,ue]=j(null),[Pe,w]=j(!1),[q]=j(()=>so(()=>r.ownerDocument.defaultView.localStorage)),_=c?.fontFamily,G=Y(!1),me=Y(new Set),Ie=Y(null),ie=Y(null),ze=Y(null),ut=Y(mo),[go,ho]=j({left:0,top:0}),mt=Y(d);mt.current=d;let fe=je(l=>{if(G.current){a(l);try{mt.current?.(l)}catch{}}},[]);ct(()=>{if(W)return;G.current=!0;let l=!1,b=0,I=0,D=[e.onStateChanged(P=>{ut.current=P,E(P)}),t.onChanged(g),e.onEvent("selectionChanged",P=>{let V=ze.current;b++,ze.current=P,h(he(P)),V&&(V.token.session!==P.token.session||V.token.version!==P.token.version)&&S(F=>F==="settings"||F==="drawingProperties"?F:null)}),e.onPreferencesChanged(P=>{I++,u(P)}),e.onDisposed(()=>Ce(!0))],L=P=>{l||fe(P)};return e.getSelection().then(P=>{!l&&b===0&&(ze.current=P,h(he(P)))},L),e.getPreferences().then(P=>{!l&&I===0&&u(P)},L),()=>{l=!0,G.current=!1,D.forEach(P=>P())}},[e,t,W,fe]);let Q=je(async(l,b="document")=>{if(!G.current||me.current.has(b))return!1;me.current.add(b),N(new Set(me.current)),a(null);try{return await l(),!0}catch(I){return fe(I),!1}finally{me.current.delete(b),G.current&&N(new Set(me.current))}},[fe]),le=je((l,b,I)=>x?Q(async()=>{ue(x.token);try{await e.editScene(Oe(x,l,b,I))}finally{G.current&&ue(null)}}):Promise.resolve(!1),[e,x,Q]),Ve=je(async l=>{await Qr(e,l),G.current&&q.record(l)},[e,q]);Xt({editor:e,container:r,ui:f,state:()=>ut.current,selection:()=>ze.current,run:Q,report:fe,activateTool:Ve,openQuickInsert:()=>{S(null),w(!0)}});let bo=async l=>{await Q(()=>e.setPreferences(l),"preferences")},ft=x?Z(x.items):[],gt=ft[0],ge=yt(ft,f.contextToolbar).filter(l=>l!=="editText"||e.textEditing!=="disabled"),ee=!m.editingEnabled||m.health!=="healthy"||m.busy||T.has("document");ct(()=>{(W||!f.enabled||!m.editingEnabled||m.health!=="healthy"||m.busy)&&w(!1)},[W,f.enabled,m.editingEnabled,m.health,m.busy]);let yo=ne!==null&&ne.session===x?.token.session&&ne.version===x?.token.version,vo=!m.busy||yo;if(Kr(()=>{if(W||!Ie.current)return;let l=Ie.current,b=r.querySelector("canvas"),I=r.ownerDocument.defaultView;function D(){if(!l||!b||!ie.current||!x?.anchor)return;let P=xt(x.anchor,b.getBoundingClientRect(),{width:b.clientWidth,height:b.clientHeight},l.getBoundingClientRect(),{width:l.clientWidth,height:l.clientHeight}),V=vt(P,{width:ie.current.offsetWidth,height:ie.current.offsetHeight},{width:l.clientWidth,height:l.clientHeight});ho(F=>F.left===V.left&&F.top===V.top?F:V)}D();let L=new I.ResizeObserver(D);return L.observe(l),b&&L.observe(b),ie.current&&L.observe(ie.current),I.addEventListener("scroll",D,!0),()=>{L.disconnect(),I.removeEventListener("scroll",D,!0)}},[r,x,W,f.enabled,m.busy,ge.join(",")]),W||!f.enabled)return null;let Ze=n??(s.darkTheme?"dark":"light"),Re=x?.items[0]?.resolved.themeColors,xo=Object.fromEntries(Re&&typeof Re=="object"&&!Array.isArray(Re)?Object.entries(Re).filter(([,l])=>typeof l=="string").map(([l,b])=>[et(l),b]):[]),wo={editor:e,ui:f,state:{...m,busy:m.busy||T.has("document")},selection:x,panel:y,setPanel:S,run:Q,edit:le};function ht(l){if(!f.buttons[l])return null;let b=l==="undo"?!m.canUndo||ee:l==="redo"?!m.canRedo||ee:ae.some(D=>D===l)?ee:!1;if(l==="settings"||l==="drawingProperties")return K(te,{id:l,label:"Settings",button:k(z,{icon:"settings"}),children:[" ",k(no,{preferences:s,onChange:bo})]},l);if(l==="help")return K(te,{id:"help",button:k(z,{icon:l}),children:[" ",K("div",{className:"dm-help",children:[k("strong",{children:"Keyboard shortcuts"}),Object.entries(we).map(([D,L])=>K("div",{children:[De[D],k("kbd",{children:L})]},D))]})]},l);let I=()=>l==="undo"||l==="redo"?e[l]():l==="sketchyMode"?e.setSketchyMode(!m.sketchyMode):l==="zoomIn"||l==="zoomOut"||l==="resetZoom"?e.zoom(l==="zoomIn"?"in":l==="zoomOut"?"out":"reset"):Ve(l);return k(z,{icon:l,shortcut:we[l],disabled:b,selected:l==="sketchyMode"?m.sketchyMode:m.tool===l,onClick:()=>{Q(I,["zoomIn","zoomOut","resetZoom"].includes(l)?"viewport":"document")},children:l==="resetZoom"?K("span",{className:"dm-zoom",children:[Math.round((m.zoom??1)*100),"%"]}):void 0},l)}function ko(l){if(l.startsWith("slot."))return o[l.slice(5)]==null?null:k("span",{className:"dm-slot",children:o[l.slice(5)]},l);if(!l.startsWith("host."))return ht(l);let b=f.actions.find(I=>I.id===l);return b?.visible?K(z,{"aria-label":b.label,disabled:!b.enabled||T.has(l),className:"dm-host-action",onClick:()=>{Q(()=>t.invokeAction(l),l)},children:[b.icon&&k(B,{name:b.icon}),k("span",{children:T.has(l)?b.label+"\u2026":b.label})]},l):null}async function So(){x&&await e.copyToClipboard(x.token)}function bt(l){if(l==="groupTheme")return k(it,{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"?Q(()=>e.beginTextEditing(gt?.id)):l.startsWith("textSize")?le("Set text size",H=>[R(H,["fontStyle","size"],se(H,"fontSizes",l.slice(8)))]):l==="bold"?le("Toggle bold",H=>[R(H,["fontStyle","weight"],C(b.bold)===!0?400:700)]):l==="italic"?le("Toggle italic",H=>[R(H,["fontStyle","slant"],C(b.italic)===!0?"Upright":"Italic")]):l==="cornerRadius"?le("Toggle corner radius",H=>[X(H,"toggleCornerRadius")]):le("Swap endpoints",H=>[R(H,["startStyle"],H.model.endStyle),R(H,["endStyle"],H.model.startStyle)]),P=l==="strokeFillColor"?K("span",{className:"dm-stroke-fill","data-transparent":C(b.fillColor)?.role==="Transparent"?"":void 0,children:[k(de,{fill:oe(C(b.fillColor)?.role,C(b.fillColor)?.argb),style:{color:oe(C(b.fillColor)?.role==="Transparent"?"SecondaryStroke":C(b.fillColor)?.role)}}),k(de,{style:{color:oe(C(b.strokeColor)?.role,C(b.strokeColor)?.argb)}})]}):l==="lineStartStyle"||l==="lineEndStyle"?k(xe,{value:C(l==="lineStartStyle"?b.lineStartStyle:b.lineEndStyle)??0,start:l==="lineStartStyle"}):void 0,V=Fe.includes(l),F=k(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?k(te,{id:l,button:F,children:{strokeFillColor:k(Be,{fill:!0}),strokeColor:k(Be,{}),strokeStyle:k(Wt,{}),textAlign:k(rt,{}),lineStartStyle:k(nt,{start:!0}),lineEndStyle:k(nt,{start:!1}),lineRouting:k(_t,{}),groupTheme:k(it,{}),groupTitleStyle:k(Qt,{}),moreOptions:k($t,{copy:So})}[l]},l):k("span",{children:F},l)}return k("div",{ref:Ie,className:"dm-editor-ui "+i,style:{fontFamily:_,...xo,...c},"data-mantine-color-scheme":Ze,children:k(_r,{inherit:!1,children:k(Wr,{forceColorScheme:Ze,theme:Gr(ot,Vt(Ze==="dark"),_?{fontFamily:_,headings:{fontFamily:_}}:{}),cssVariablesSelector:".dm-editor-ui",getRootElement:()=>Ie.current??void 0,children:K(Ye.Provider,{value:wo,children:[Object.entries(f.regions).map(([l,b])=>{let I=b.items.map(ko).filter(Boolean);return b.visible&&I.length>0?k(Ne.Provider,{value:l.startsWith("top")?"bottom":"top",children:k("div",{className:"dm-toolbar dm-corner dm-"+l,role:"toolbar","aria-label":l+" toolbar","data-region":l,children:I})},l):null}),f.drawingToolbar.visible&&f.drawingToolbar.tools.some(l=>f.buttons[l])&&k(Ne.Provider,{value:{left:"right",right:"left",top:"bottom",bottom:"top"}[f.drawingToolbar.position],children:k("fieldset",{className:"dm-toolbar dm-drawing dm-"+f.drawingToolbar.position,disabled:ee,"aria-label":"Drawing tools","data-testid":"drawing-toolbar",children:f.drawingToolbar.tools.map(ht)})}),k(jt,{container:r}),Pe&&k(uo,{container:r,usage:q.read(),disabled:ee,objects:Te.filter(l=>f.buttons[l.id]).map(l=>({...l,shortcut:we[l.id]})),onClose:()=>w(!1),onSelect:async l=>{ee||!f.buttons[l]||await Q(()=>Ve(l))&&w(!1)}}),x&&x.anchor&&ge.length>0&&vo&&k("fieldset",{ref:ie,className:"dm-toolbar dm-context",disabled:ee,style:go,"aria-label":"Selection tools","data-testid":"context-toolbar","data-item-id":gt?.id,children:ge.map((l,b)=>{if(l.startsWith("textSize")&&ge[b-1]?.startsWith("textSize"))return null;let I=l.startsWith("textSize")?ge.slice(b).filter((D,L,P)=>P.slice(0,L+1).every(V=>V.startsWith("textSize"))):null;return K("span",{className:"dm-context-entry",children:[b>0&&(I||["bold","textAlign","strokeColor","strokeFillColor","moreOptions"].includes(l))&&k(Le,{}),I?k("span",{className:"dm-button-group",children:I.map(bt)}):bt(l)]},l)})}),p!=null&&K("div",{className:"dm-error",role:"alert",children:[k("span",{children:p?.message??String(p)}),k(z,{"aria-label":"Dismiss error",icon:"close",onClick:()=>a(null)})]})]})})})})}import{createRoot as Jr}from"react-dom/client";import{jsx as en}from"react/jsx-runtime";function Yr({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 c=t.ownerDocument.createElement("div");c.style.cssText="position:absolute;inset:0;pointer-events:none;",t.append(c);let d=Jr(c),f=!1,g,m=()=>{f||(f=!0,g?.(),d.unmount(),c.remove(),i&&t.style.position==="relative"&&(t.style.position=n))};return d.render(en(qe,{editor:e,container:t,...r})),g=e.onDisposed(m),{dispose:m}}import{jsx as fo,jsxs as nn}from"react/jsx-runtime";function Bi({className:e,style:t,slots:r,colorScheme:o,onReady:n,onError:i,ui:c,...d}){let f=pt(null),g=pt({onReady:n,onError:i});g.current={onReady:n,onError:i};let m=pt(Promise.resolve()),[E,x]=on(null);return tn(()=>{let h=!1,s,u,y=new AbortController,S=()=>y.abort(d.signal?.reason);d.signal?.addEventListener("abort",S,{once:!0}),d.signal?.aborted&&S(),x(null);let p=m.current,a=p.then(async()=>{if(h)return;let T=await rn({...d,container:f.current,signal:y.signal});s=T,!h&&(u=T.onDisposed(()=>x(null)),x(T),g.current.onReady?.(T))});return a.catch(T=>{h||g.current.onError?.(T)}),()=>{h=!0,y.abort(),d.signal?.removeEventListener("abort",S),u?.(),m.current=p.then(()=>a.catch(T=>{if(T?.code==="DisposeCleanupUnconfirmed")throw T})).then(async()=>{s&&await s.dispose()}),m.current.catch(T=>g.current.onError?.(T))}},[d.assetBaseUrl,d.licenseKey,d.textEditing,c,d.persistence,d.workerFactory,d.workerUrls,d.signal,d.title,d.startupTimeoutMs,d.disposeTimeoutMs]),nn("div",{className:e,style:{position:"relative",width:"100%",height:"100%",...t},children:[fo("div",{ref:f,style:{position:"absolute",inset:0}}),E&&fo(qe,{options:c,editor:E,container:f.current,slots:r,colorScheme:o,onError:i})]})}export{Bi as Editor,qe as EditorUi,Qe as createEditorUiController,Yr as mountEditorUi,ot as phosphorTheme};
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"&&gt(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&&gt("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};
2
2
  /*! Material Symbols Outlined | Copyright Google LLC | Apache-2.0
3
3
  * See MaterialSymbols-LICENSE.txt and MaterialSymbols-NOTICE.txt in the distribution. */
@@ -0,0 +1,9 @@
1
+ import { type UiSelectedObject } from './selection-model.js';
2
+ export declare function ResetNumbering({ disabled, onReset }: {
3
+ disabled: boolean;
4
+ onReset: () => Promise<unknown>;
5
+ }): import("react").JSX.Element;
6
+ /** Each draft belongs to the revision that supplied the displayed prefix and range. */
7
+ export declare function NumberingPanel({ item }: {
8
+ item: UiSelectedObject;
9
+ }): import("react").JSX.Element | null;
@@ -2,7 +2,14 @@ import type { EditorSelectedObject, EditorScreenBounds } from '@drawmotive/edito
2
2
  import type { NormalizedUiOptions } from './ui-options.js';
3
3
  export declare const CONTEXT_TOOL_IDS: readonly string[];
4
4
  export declare const CONTEXT_PANEL_IDS: readonly string[];
5
- export declare function selectionSubjects(items: readonly EditorSelectedObject[]): readonly EditorSelectedObject[];
5
+ export declare function selectionSubjects<T extends EditorSelectedObject>(items: readonly T[]): readonly T[];
6
+ export interface ItemNumbering {
7
+ readonly number: number | null;
8
+ readonly prefix: string;
9
+ readonly maximum: number;
10
+ readonly drawingEnabled: boolean;
11
+ }
12
+ export declare function itemNumbering(item: EditorSelectedObject): ItemNumbering | undefined;
6
13
  export declare function contextTools(items: readonly EditorSelectedObject[], options: NormalizedUiOptions['contextToolbar']): string[];
7
14
  export declare function placeFloating(anchor: EditorScreenBounds, size: {width:number;height:number}, viewport: {width:number;height:number}): {left:number;top:number};
8
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawmotive/editor-ui",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Reusable React drawing controls for the DrawMotive canvas editor.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -56,9 +56,9 @@
56
56
  "prepack": "npm run release:check && npm run build"
57
57
  },
58
58
  "dependencies": {
59
- "@drawmotive/editor": "0.3.3",
60
- "@mantine/core": "9.7.4",
61
- "@mantine/hooks": "9.7.4",
59
+ "@drawmotive/editor": "0.3.5",
60
+ "@mantine/core": "9.8.1",
61
+ "@mantine/hooks": "9.8.1",
62
62
  "@phosphor-icons/react": "2.1.10"
63
63
  },
64
64
  "peerDependencies": {
@@ -66,7 +66,7 @@
66
66
  "react-dom": "19.3.1"
67
67
  },
68
68
  "devDependencies": {
69
- "@playwright/test": "1.63.0",
69
+ "@playwright/test": "1.65.1",
70
70
  "@types/react": "19.3.0",
71
71
  "@types/react-dom": "19.3.0",
72
72
  "esbuild": "0.28.2",