@drawmotive/editor-ui 0.0.0-stage → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +163 -2
- package/dist/MaterialSymbols-LICENSE.txt +202 -0
- package/dist/MaterialSymbols-NOTICE.txt +20 -0
- package/dist/controls.d.ts +41 -0
- package/dist/creation-tooltip.d.ts +4 -0
- package/dist/drawing-properties.d.ts +2 -0
- package/dist/editor-ui.d.ts +18 -0
- package/dist/icons.d.ts +22 -0
- package/dist/index.css +1 -0
- package/dist/index.css.d.ts +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +3 -0
- package/dist/mantine-icons.d.ts +3 -0
- package/dist/mount.d.ts +5 -0
- package/dist/panels.d.ts +30 -0
- package/dist/quick-insert-model.d.ts +10 -0
- package/dist/quick-insert.d.ts +12 -0
- package/dist/selection-model.d.ts +22 -0
- package/dist/settings.d.ts +6 -0
- package/dist/tooltip-theme.d.ts +3 -0
- package/dist/ui-controller.d.ts +11 -0
- package/dist/ui-controller.js +1 -0
- package/dist/ui-model.d.ts +8 -0
- package/dist/ui-options-runtime.d.ts +6 -0
- package/dist/ui-options.d.ts +92 -0
- package/dist/use-editor-hotkeys.d.ts +18 -0
- package/package.json +73 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 drawmotive
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @drawmotive/editor-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reusable drawing toolbars, selection properties, settings, help, tooltips and
|
|
4
|
+
keyboard controls for the [DrawMotive canvas SDK](https://github.com/drawmotive/drawmotive).
|
|
5
|
+
Use the React components or mount the same controls in an ordinary DOM host.
|
|
6
|
+
|
|
7
|
+
The initial source and external-package checks use the real public
|
|
8
|
+
`@drawmotive/editor@0.3.2` types and base canvas API. Its published native runtime
|
|
9
|
+
does not provide this source's capsule, star and cloud tools or native licensing. Full toolbar support
|
|
10
|
+
requires an upcoming coordinated Editor release, so initial npm publication is
|
|
11
|
+
blocked by the factual release target. Editor 0.3.1 and earlier use a different
|
|
12
|
+
embedding API and are not supported. React and React DOM 19.3.1 are peers; Mantine
|
|
13
|
+
9.7.4 and Phosphor 2.1.10 are package dependencies. The canvas SDK remains
|
|
14
|
+
independent of React, Mantine and this package.
|
|
15
|
+
|
|
16
|
+
After the first compatible coordinated npm release, install the UI and SDK:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @drawmotive/editor-ui @drawmotive/editor react@19.3.1 react-dom@19.3.1
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## React hosting
|
|
23
|
+
|
|
24
|
+
Import the Mantine base styles and the editor stylesheet once. `Editor` creates
|
|
25
|
+
and disposes its own public canvas instance. The host provides a sized container
|
|
26
|
+
and serves the SDK runtime assets. Prepare those assets with the SDK's
|
|
27
|
+
`drawmotive-copy-assets` command; see the SDK documentation for deployment paths.
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import '@mantine/core/styles.css';
|
|
31
|
+
import '@drawmotive/editor-ui/styles.css';
|
|
32
|
+
import { Editor } from '@drawmotive/editor-ui';
|
|
33
|
+
|
|
34
|
+
export function Drawing() {
|
|
35
|
+
return <Editor assetBaseUrl="/editor/" style={{ height: 600 }} />;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For an editor owned by the host, use `EditorUi` and pass its public editor
|
|
40
|
+
instance and canvas container. `EditorUi` supplies its own Mantine provider.
|
|
41
|
+
Unmounting these controls leaves the host's editor alive.
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { EditorUi } from '@drawmotive/editor-ui';
|
|
45
|
+
import type { EditorInstance } from '@drawmotive/editor';
|
|
46
|
+
|
|
47
|
+
export function DrawingControls({ editor, container }: {
|
|
48
|
+
editor: EditorInstance;
|
|
49
|
+
container: HTMLElement;
|
|
50
|
+
}) {
|
|
51
|
+
return <EditorUi editor={editor} container={container} />;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## DOM hosting
|
|
56
|
+
|
|
57
|
+
`mountEditorUi()` uses the same controls without requiring a React application.
|
|
58
|
+
Bundle this ESM entry and its external dependencies with your browser tooling.
|
|
59
|
+
The UI stylesheet is a separate exported asset and is marked as a bundler side
|
|
60
|
+
effect. The host continues to own SDK runtime assets and Worker transport.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import '@mantine/core/styles.css';
|
|
64
|
+
import '@drawmotive/editor-ui/styles.css';
|
|
65
|
+
import { createEditor } from '@drawmotive/editor';
|
|
66
|
+
import { mountEditorUi } from '@drawmotive/editor-ui';
|
|
67
|
+
|
|
68
|
+
const container = document.getElementById('editor');
|
|
69
|
+
const editor = await createEditor({ container, assetBaseUrl: '/editor/' });
|
|
70
|
+
const controls = mountEditorUi({ editor, container });
|
|
71
|
+
|
|
72
|
+
async function closeDrawing() {
|
|
73
|
+
controls.dispose();
|
|
74
|
+
await editor.dispose();
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The container must have a usable size. Imperative mounting supplies relative
|
|
79
|
+
positioning when needed and restores it on disposal. Native canvas input, grips
|
|
80
|
+
and inline text remain owned by the SDK. The controls use Mantine's default
|
|
81
|
+
typography and colors, independently of drawing themes, styles and surrounding
|
|
82
|
+
Mantine provider overrides. Drawing palette swatches preview document colors;
|
|
83
|
+
inline text editing retains the document's typography. Keep the supported SDK
|
|
84
|
+
version installed for canvas host DOM integration.
|
|
85
|
+
|
|
86
|
+
## Host options and ownership
|
|
87
|
+
|
|
88
|
+
`EditorUi` and `mountEditorUi()` accept `options`, `slots`, `colorScheme`,
|
|
89
|
+
`className`, `style` and `onError`. The React `Editor` wrapper accepts the same UI
|
|
90
|
+
configuration as `ui`, plus ordinary public editor creation options.
|
|
91
|
+
With the matching SDK/native runtime, this includes the optional `licenseKey`
|
|
92
|
+
deployment prop. Changing it disposes the previous native session before creating
|
|
93
|
+
its successor. Bottom controls retain their original corner positions; native
|
|
94
|
+
branding sits at the canvas bottom center and may overlap controls on narrow
|
|
95
|
+
hosts. No branding text or license validation is implemented by this React package.
|
|
96
|
+
See [Editor licensing](https://textgraph.dev/editor/licensing) for the optional
|
|
97
|
+
official removal service and the SDK's immutable `getLicenseStatus()` snapshot.
|
|
98
|
+
|
|
99
|
+
Options control button visibility, corner regions, drawing/context toolbars,
|
|
100
|
+
tooltips and host actions. Slots contain host React elements. Host actions use
|
|
101
|
+
IDs such as `host.save` and receive the public editor and a cancellation signal.
|
|
102
|
+
Authentication, application navigation, collaboration transport and document
|
|
103
|
+
storage belong to the embedding host.
|
|
104
|
+
|
|
105
|
+
For changing action labels or availability, create a controller with
|
|
106
|
+
`createEditorUiController(editor, options)`, pass it as `controller`, and use
|
|
107
|
+
`setActionState()` or `invokeAction()`. The controller is exported from the main
|
|
108
|
+
entry and the framework-independent `@drawmotive/editor-ui/controller` entry.
|
|
109
|
+
An explicit controller belongs to its host and must be disposed by that host.
|
|
110
|
+
Without one, the controls own and dispose their controller. Closing the public
|
|
111
|
+
editor cancels action signals immediately; cancellation cannot undo an external
|
|
112
|
+
write.
|
|
113
|
+
|
|
114
|
+
Press `/` on an idle editable canvas for Quick insert. Text fields retain literal
|
|
115
|
+
slash input. Recent and frequently used tools use browser-local history, with an
|
|
116
|
+
in-memory fallback when storage is unavailable. Settings groups local View
|
|
117
|
+
preferences and saved Drawing properties in one panel. Drawing properties edit
|
|
118
|
+
document metadata through native transactions; View controls local appearance
|
|
119
|
+
and grid preferences. The legacy `drawingProperties` toolbar ID opens this same
|
|
120
|
+
Settings panel; default controls use only `settings`. Hiding controls does not
|
|
121
|
+
change native editing permissions or the SDK's `textEditing` policy.
|
|
122
|
+
|
|
123
|
+
## Development and verification
|
|
124
|
+
|
|
125
|
+
Use Node.js 22 or later and npm. The committed lockfile resolves dependencies
|
|
126
|
+
from the public registry, without a parent workspace.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm ci
|
|
130
|
+
npm test
|
|
131
|
+
npm run build
|
|
132
|
+
npx playwright install chromium
|
|
133
|
+
npm run test:browser
|
|
134
|
+
npm run test:package
|
|
135
|
+
npm pack --ignore-scripts
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`test:package` packs the built library, installs it in a temporary external
|
|
139
|
+
consumer, compiles its public types, and bundles and mounts the real UI around
|
|
140
|
+
the public SDK with an isolated native-runtime fixture. Browser tests exercise
|
|
141
|
+
existing controls and lifecycle behavior without building .NET. The package check
|
|
142
|
+
also verifies that ordinary `npm pack` fails with the staged release reason.
|
|
143
|
+
The explicit archive command above skips release scripts only to inspect the
|
|
144
|
+
fixture; it does not establish native toolbar compatibility or release readiness.
|
|
145
|
+
|
|
146
|
+
`npm run preview` serves the component preview at
|
|
147
|
+
[http://127.0.0.1:4187/test/browser/quick-insert-preview.html](http://127.0.0.1:4187/test/browser/quick-insert-preview.html)
|
|
148
|
+
after building. Its attributed cloud examples and standalone bundles are test
|
|
149
|
+
fixtures, excluded from the npm archive.
|
|
150
|
+
|
|
151
|
+
The integration repository projects coordinated release metadata and shared
|
|
152
|
+
checks into `.release/`. Ordinary `npm pack` validates that authority before
|
|
153
|
+
building and intentionally rejects the initial staged target. The plan records
|
|
154
|
+
the intended coordinated identity; the factual target remains blocked until the
|
|
155
|
+
compatible Editor package is published and preparation advances its exact lock.
|
|
156
|
+
Publication accepts only a reviewed retained archive through the
|
|
157
|
+
protected workflow; it does not rebuild or publish from a dependency install.
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
MIT; see [LICENSE](LICENSE). Embedded Material Symbols paths retain their
|
|
162
|
+
[Apache 2.0 license](src/MaterialSymbols-LICENSE.txt) and
|
|
163
|
+
[notice](src/MaterialSymbols-NOTICE.txt). Both files accompany the npm library.
|
|
164
|
+
Redistributors embedding those paths must preserve the notices.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Material Symbols Outlined
|
|
2
|
+
Copyright Google LLC.
|
|
3
|
+
Licensed under the Apache License, Version 2.0.
|
|
4
|
+
See MaterialSymbols-LICENSE.txt for the complete license.
|
|
5
|
+
|
|
6
|
+
Upstream project: https://github.com/google/material-design-icons
|
|
7
|
+
Upstream revision: 10ecc14790612ca8fd164e3f4ffe9c16fc50d5b7
|
|
8
|
+
|
|
9
|
+
SVG paths embedded in icons.tsx:
|
|
10
|
+
- rounded_corner: user-supplied 24-unit SVG path.
|
|
11
|
+
- line_style: outlined, 24px, default weight, unmodified upstream path.
|
|
12
|
+
- line_end_arrow_notch: outlined, 24px, default weight, unmodified upstream path.
|
|
13
|
+
- line_end_circle: outlined, fill=1, 24px, default weight, unmodified upstream path.
|
|
14
|
+
- line_end_diamond: outlined, fill=1, 24px, default weight, unmodified upstream path.
|
|
15
|
+
|
|
16
|
+
Source directory at the pinned revision:
|
|
17
|
+
https://github.com/google/material-design-icons/tree/10ecc14790612ca8fd164e3f4ffe9c16fc50d5b7/symbols/web
|
|
18
|
+
|
|
19
|
+
Adaptations are limited to React SVG attributes, currentColor, display size and
|
|
20
|
+
horizontal mirroring of endpoint icons. No upstream path geometry is redrawn.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import type { EditorInstance, EditorState } from '@drawmotive/editor';
|
|
3
|
+
import type { SelectionEdit, UiSelection, UiValue } from './selection-model.js';
|
|
4
|
+
import type { NormalizedUiOptions } from './ui-options.js';
|
|
5
|
+
export interface UiContextValue {
|
|
6
|
+
editor: EditorInstance;
|
|
7
|
+
ui: NormalizedUiOptions;
|
|
8
|
+
state: EditorState;
|
|
9
|
+
selection: UiSelection | null;
|
|
10
|
+
panel: string | null;
|
|
11
|
+
setPanel(panel: string | null): void;
|
|
12
|
+
run(action: () => Promise<unknown>, key?: string): Promise<boolean>;
|
|
13
|
+
edit: SelectionEdit;
|
|
14
|
+
}
|
|
15
|
+
export declare const UiContext: import("react").Context<UiContextValue | null>;
|
|
16
|
+
/** Toolbar location owns the inward hint direction; other controls use the host's fallback. */
|
|
17
|
+
export declare const ToolbarTooltipPosition: import("react").Context<"bottom" | "left" | "right" | "top" | undefined>;
|
|
18
|
+
export declare function useUi(): UiContextValue;
|
|
19
|
+
export declare const uniform: <T>(value: UiValue<T> | undefined) => T | undefined;
|
|
20
|
+
export declare const LABELS: Record<string, string>;
|
|
21
|
+
export declare const SHORTCUTS: Record<string, string>;
|
|
22
|
+
interface ToolButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
23
|
+
icon?: string;
|
|
24
|
+
selected?: boolean | 'mixed';
|
|
25
|
+
shortcut?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const ToolButton: import("react").ForwardRefExoticComponent<ToolButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
28
|
+
export declare function PanelButton({ id, button, children, label, nested }: {
|
|
29
|
+
id: string;
|
|
30
|
+
button: ReactElement<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
label?: string;
|
|
33
|
+
nested?: boolean;
|
|
34
|
+
}): import("react").JSX.Element;
|
|
35
|
+
export declare const Separator: () => import("react").JSX.Element;
|
|
36
|
+
export declare const PanelHeading: ({ children }: {
|
|
37
|
+
children: ReactNode;
|
|
38
|
+
}) => import("react").JSX.Element;
|
|
39
|
+
export declare function colorVariable(role?: string): string;
|
|
40
|
+
export declare function colorCss(role?: string | null, argb?: string | null): string;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { EditorInstance } from '@drawmotive/editor';
|
|
3
|
+
import { type EditorUiController } from './ui-controller.js';
|
|
4
|
+
import { type EditorUiOptions } from './ui-options.js';
|
|
5
|
+
export interface EditorUiProps {
|
|
6
|
+
editor: EditorInstance;
|
|
7
|
+
options?: EditorUiOptions | false;
|
|
8
|
+
controller?: EditorUiController;
|
|
9
|
+
/** The container owning the native canvas. Portals remain inside this element. */
|
|
10
|
+
container: HTMLElement;
|
|
11
|
+
slots?: Readonly<Record<string, ReactNode>>;
|
|
12
|
+
colorScheme?: 'light' | 'dark';
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: CSSProperties;
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
16
|
+
}
|
|
17
|
+
/** Local UI observes immutable snapshots; every edit submits one native batch transaction. */
|
|
18
|
+
export declare function EditorUi(props: EditorUiProps): import("react").JSX.Element;
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
/** Ordinary controls use Phosphor; explicit sourced exceptions inherit the same theme color. */
|
|
3
|
+
export declare function Icon({ name, style }: {
|
|
4
|
+
name: string;
|
|
5
|
+
style?: CSSProperties;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
/** The native duotone layer carries fill independently of the palette outline. */
|
|
8
|
+
export declare function PaletteIcon({ fill, style }: {
|
|
9
|
+
fill?: string;
|
|
10
|
+
style?: CSSProperties;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
/** Width choices use Phosphor weights; pattern choices retain the historical SVGs. */
|
|
13
|
+
export declare function StrokeIcon({ width, pattern }: {
|
|
14
|
+
width?: number;
|
|
15
|
+
pattern?: string;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
/** Preserve the engine's six endpoint meanings in Y-down coordinates. */
|
|
18
|
+
export declare function EndpointIcon({ value, start, style }: {
|
|
19
|
+
value: number;
|
|
20
|
+
start?: boolean;
|
|
21
|
+
style?: CSSProperties;
|
|
22
|
+
}): import("react").JSX.Element;
|
package/dist/index.css
ADDED
|
@@ -0,0 +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}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { EditorCreateOptions, EditorInstance } from '@drawmotive/editor';
|
|
3
|
+
import { EditorUi, type EditorUiProps } from './editor-ui.js';
|
|
4
|
+
export { EditorUi };
|
|
5
|
+
export type { EditorUiProps };
|
|
6
|
+
export type { EditorUiOptions, EditorUiAction, EditorRegionId, EditorButtonId } from './ui-options.js';
|
|
7
|
+
import type { EditorUiOptions } from './ui-options.js';
|
|
8
|
+
export interface EditorProps extends Omit<EditorCreateOptions, 'container'> {
|
|
9
|
+
ui?: EditorUiOptions | false;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
slots?: Readonly<Record<string, ReactNode>>;
|
|
13
|
+
colorScheme?: 'light' | 'dark';
|
|
14
|
+
onReady?: (editor: EditorInstance) => void;
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
16
|
+
}
|
|
17
|
+
/** React owns the host; Blazor owns only its canvas and native inline-editing DOM. */
|
|
18
|
+
export declare function Editor({ className, style, slots, colorScheme, onReady, onError, ui, ...options }: EditorProps): import("react").JSX.Element;
|
|
19
|
+
export { mountEditorUi } from './mount.js';
|
|
20
|
+
export { phosphorTheme } from './mantine-icons.js';
|
|
21
|
+
export { createEditorUiController } from './ui-controller.js';
|
|
22
|
+
export type { EditorUiController } from './ui-controller.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +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};
|
|
2
|
+
/*! Material Symbols Outlined | Copyright Google LLC | Apache-2.0
|
|
3
|
+
* See MaterialSymbols-LICENSE.txt and MaterialSymbols-NOTICE.txt in the distribution. */
|
package/dist/mount.d.ts
ADDED
package/dist/panels.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { UiSelectedObject } from './selection-model.js';
|
|
2
|
+
export declare function Colors({ fill, target }: {
|
|
3
|
+
fill?: boolean;
|
|
4
|
+
target?: UiSelectedObject;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
export declare function StrokePanel(): import("react").JSX.Element;
|
|
7
|
+
export declare function AlignPanel({ target }: {
|
|
8
|
+
target?: UiSelectedObject;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export declare function EndpointPanel({ start }: {
|
|
11
|
+
start: boolean;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
export declare function RoutingPanel(): import("react").JSX.Element;
|
|
14
|
+
export declare function GroupPanel({ inline }: {
|
|
15
|
+
inline?: boolean;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
export declare function ResetSelect({ label, prompt, testId, choices, onChange }: {
|
|
18
|
+
label: string;
|
|
19
|
+
prompt?: string;
|
|
20
|
+
testId: string;
|
|
21
|
+
choices: string[];
|
|
22
|
+
onChange: (value: string) => Promise<unknown>;
|
|
23
|
+
}): import("react").JSX.Element;
|
|
24
|
+
export declare function TitlePanel(): import("react").JSX.Element | null;
|
|
25
|
+
export declare function TextButtons({ target }: {
|
|
26
|
+
target: UiSelectedObject;
|
|
27
|
+
}): import("react").JSX.Element;
|
|
28
|
+
export declare function MorePanel({ copy }: {
|
|
29
|
+
copy: () => Promise<unknown>;
|
|
30
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type QuickInsertTool = 'arrow' | 'rectangle' | 'ellipse' | 'diamond' | 'text';
|
|
2
|
+
/** Catalog presentation is independent of the command invoked by the owning host. */
|
|
3
|
+
export interface QuickInsertObject<Id extends string = string> {
|
|
4
|
+
id: Id; label: string; aliases: string; group?: string; iconUrl?: string; shortcut?: string;
|
|
5
|
+
}
|
|
6
|
+
export type QuickInsertUsage = Partial<Record<string, { count: number; lastUsed: number }>>;
|
|
7
|
+
export interface QuickInsertHistory { read(): QuickInsertUsage; record(id: string): void; }
|
|
8
|
+
export declare const QUICK_INSERT_OBJECTS: readonly QuickInsertObject<QuickInsertTool>[];
|
|
9
|
+
export declare function createQuickInsertHistory(getStorage: () => Pick<Storage, 'getItem' | 'setItem'>): QuickInsertHistory;
|
|
10
|
+
export declare function quickInsertGroups<Id extends string = QuickInsertTool>(query: string, usage: QuickInsertUsage, catalog?: readonly QuickInsertObject<Id>[]): { key: string; label: string | null; items: QuickInsertObject<Id>[] }[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type QuickInsertObject, type QuickInsertUsage } from './quick-insert-model.js';
|
|
2
|
+
interface QuickInsertProps<Id extends string> {
|
|
3
|
+
container: HTMLElement;
|
|
4
|
+
usage: QuickInsertUsage;
|
|
5
|
+
objects: readonly QuickInsertObject<Id>[];
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
onSelect(id: Id): Promise<void>;
|
|
8
|
+
onClose(): void;
|
|
9
|
+
}
|
|
10
|
+
/** Catalog discovery reports selection to its owner; this component never creates scene geometry. */
|
|
11
|
+
export declare function QuickInsert<Id extends string>({ container, usage, objects, disabled, onSelect, onClose }: QuickInsertProps<Id>): import("react").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EditorModelValue, EditorSceneChange, EditorSelectedObject, EditorSelectionSnapshot } from '@drawmotive/editor';
|
|
2
|
+
export type UiValue<T> = { readonly state: 'Unavailable' | 'Mixed'; readonly value?: T | null } | { readonly state: 'Uniform'; readonly value: T };
|
|
3
|
+
export interface UiColorValue { readonly role: string | null; readonly argb: string | null; }
|
|
4
|
+
/** The built-in toolbar's view, separate from the extensible public model contract. */
|
|
5
|
+
export interface UiPropertyValues {
|
|
6
|
+
readonly strokeColor: UiValue<UiColorValue>; readonly fillColor: UiValue<UiColorValue>;
|
|
7
|
+
readonly strokeWidth: UiValue<string | number>; readonly strokeStyle: UiValue<string>; readonly cornerRadius: UiValue<number>;
|
|
8
|
+
readonly textSize: UiValue<string | number>; readonly resolvedTextSize: UiValue<number>; readonly bold: UiValue<boolean>; readonly italic: UiValue<boolean>;
|
|
9
|
+
readonly horizontalAlignment: UiValue<string>; readonly verticalAlignment: UiValue<string>;
|
|
10
|
+
readonly lineStartStyle: UiValue<number>; readonly lineEndStyle: UiValue<number>; readonly lineRouting: UiValue<string>;
|
|
11
|
+
readonly groupColorRole: UiValue<string | null>; readonly groupHeaderVisible: UiValue<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export interface UiSelectedObject extends Omit<EditorSelectedObject, 'boundText'> { readonly properties: UiPropertyValues; readonly boundText?: UiSelectedObject | null; }
|
|
14
|
+
export interface UiSelection extends Omit<EditorSelectionSnapshot, 'items'> { readonly items: readonly UiSelectedObject[]; readonly properties: UiPropertyValues; }
|
|
15
|
+
export type SelectionEdit = (description: string, changes: (item: UiSelectedObject) => readonly EditorSceneChange[], target?: UiSelectedObject) => Promise<boolean>;
|
|
16
|
+
export declare function projectSelection(selection: EditorSelectionSnapshot): UiSelection;
|
|
17
|
+
/** Uses the native role map instead of duplicating persisted scalar identities. */
|
|
18
|
+
export declare function themeValue(item: EditorSelectedObject, domain: 'colors', role: string): string;
|
|
19
|
+
export declare function themeValue(item: EditorSelectedObject, domain: 'fontSizes' | 'lineWidths', role: string): number;
|
|
20
|
+
export declare function setModel(item: EditorSelectedObject, path: readonly string[], value: EditorModelValue): EditorSceneChange;
|
|
21
|
+
export declare function callModel(item: EditorSelectedObject, method: string, ...args: EditorModelValue[]): EditorSceneChange;
|
|
22
|
+
export declare function selectionEdit(selection: UiSelection, description: string, changes: (item: UiSelectedObject) => readonly EditorSceneChange[], target?: UiSelectedObject): import('@drawmotive/editor').EditorSceneEdit;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EditorPreferences } from '@drawmotive/editor';
|
|
2
|
+
/** One settings surface keeps local preferences distinct from native document edits. */
|
|
3
|
+
export declare function SettingsPanel({ preferences, onChange }: {
|
|
4
|
+
preferences: EditorPreferences;
|
|
5
|
+
onChange: (value: EditorPreferences) => Promise<unknown>;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EditorInstance } from '@drawmotive/editor';
|
|
2
|
+
import type { EditorUiOptions, NormalizedUiOptions, EditorUiActionState } from './ui-options.js';
|
|
3
|
+
export interface EditorUiController {
|
|
4
|
+
readonly editor: EditorInstance;
|
|
5
|
+
readonly ui: NormalizedUiOptions;
|
|
6
|
+
onChanged(listener: (ui: NormalizedUiOptions) => void): () => void;
|
|
7
|
+
invokeAction(id: string): Promise<void>;
|
|
8
|
+
setActionState(id: string, state: EditorUiActionState): Promise<void>;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createEditorUiController(editor: EditorInstance, options?: EditorUiOptions | false): EditorUiController;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EditorError as T}from"@drawmotive/editor";var E=Object.freeze(["undo","redo","arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode","drawingProperties","zoomIn","zoomOut","resetZoom","settings","help"]),k=Object.freeze(["topLeft","topRight","bottomLeft","bottomRight"]),x=Object.freeze(["arrow","rectangle","ellipse","diamond","capsule","star","cloud","text","sketchyMode"]),S=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),D=e=>typeof e=="string"&&/^host[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e),_=e=>typeof e=="string"&&/^slot[.][A-Za-z0-9][A-Za-z0-9._-]*$/.test(e);function g(e,i,l){if(!S(e))throw new TypeError(l+" must be an object");for(let c of Object.keys(e))if(!i.includes(c))throw new TypeError("Unknown "+l+" option: "+c)}function O(e,i){if(typeof e!="boolean")throw new TypeError(i+" must be a boolean");return e}function U(e,i){if(typeof e!="string"||!e.trim())throw new TypeError(i+" must be a nonempty string");return e}function I(e,i,l=c=>typeof c=="string"&&!!c.trim()){if(!Array.isArray(e)||e.some(c=>!l(c))||new Set(e).size!==e.length)throw new TypeError(i+" must contain distinct valid IDs");return Object.freeze([...e])}function j(e,i,l){return e===void 0?{}:typeof e=="boolean"?{visible:e}:(g(e,["visible",...i],l),e.visible!==void 0&&O(e.visible,l+".visible"),e)}function v(e={}){e===!1&&(e={enabled:!1}),g(e,["enabled","buttons","actions","regions","drawingToolbar","contextToolbar","tooltip"],"ui");let i=e.enabled===void 0?!0:O(e.enabled,"ui.enabled"),l=e.buttons??{};g(l,E,"ui.buttons");let c=Object.fromEntries(E.map(t=>[t,t!=="help"]));for(let[t,d]of Object.entries(l))c[t]=O(d,"ui.buttons."+t);let a=new Map;if(e.actions!==void 0&&!Array.isArray(e.actions))throw new TypeError("ui.actions must be an array");let p=(e.actions??[]).map(t=>{if(g(t,["id","label","icon","visible","enabled","onInvoke"],"action"),!D(t.id))throw new TypeError("Action id must use the host. namespace");if(a.has(t.id))throw new TypeError("Duplicate action id: "+t.id);if(typeof t.onInvoke!="function")throw new TypeError("Action "+t.id+" requires an onInvoke handler");let d={id:t.id,label:U(t.label,"Action label"),enabled:t.enabled===void 0?!0:O(t.enabled,"Action enabled"),visible:t.visible===void 0?!0:O(t.visible,"Action visible")};return t.icon!==void 0&&(d.icon=U(t.icon,"Action icon")),a.set(t.id,t.onInvoke),Object.freeze(d)}),f=e.regions??{};g(f,k,"ui.regions");let u=new Set(Object.values(f).flatMap(t=>S(t)&&Array.isArray(t.items)?t.items.filter(D):[])),A={topLeft:["undo","redo"],topRight:["help",...p.filter(t=>!u.has(t.id)).map(t=>t.id)],bottomLeft:[],bottomRight:["zoomOut","resetZoom","zoomIn","settings"]},h=Object.fromEntries(k.map(t=>{let d=j(f[t],["items"],"ui.regions."+t);return[t,Object.freeze({visible:i&&(d.visible??!0),items:I(d.items??A[t],"ui.regions."+t+".items",z=>E.includes(z)||a.has(z)||_(z))})]})),y=j(e.drawingToolbar,["position","tools"],"ui.drawingToolbar"),m=y.position??"left";if(!["left","right","top","bottom"].includes(m))throw new TypeError("ui.drawingToolbar.position must be left, right, top or bottom");let w=Object.freeze({visible:i&&(y.visible??!0),position:m,tools:I(y.tools??x.filter(t=>t!=="sketchyMode"),"ui.drawingToolbar.tools",t=>x.includes(t))}),o=j(e.contextToolbar,["objectTypes","tools","panels"],"ui.contextToolbar"),r={visible:i&&(o.visible??!0)};for(let t of["objectTypes","tools","panels"])o[t]!==void 0&&(r[t]=I(o[t],"ui.contextToolbar."+t));let b=j(e.tooltip,["position","delay"],"ui.tooltip"),n=b.position??"top",s=b.delay??250;if(!["top","bottom","left","right"].includes(n))throw new TypeError("ui.tooltip.position must be top, bottom, left or right");if(!Number.isFinite(s)||s<0)throw new TypeError("ui.tooltip.delay must be nonnegative");let R=Object.freeze({visible:b.visible??!0,position:n,delay:s});return Object.freeze({ui:Object.freeze({enabled:i,buttons:Object.freeze(c),actions:Object.freeze(p),regions:Object.freeze(h),drawingToolbar:w,contextToolbar:Object.freeze(r),tooltip:R}),handlers:a})}function N(e,i){let{ui:l,handlers:c}=v(i),a=l,p=!1,f=new Set,u=new Set,A=()=>new T("EditorDisposed","Editor UI has been disposed"),h=()=>{if(p||e.lifecycle!=="ready")throw A()},y,m,w=()=>{if(!p){p=!0,y?.(),m?.();for(let o of u)o.abort(A());u.clear(),c.clear(),f.clear()}};return e.lifecycle==="ready"?(m=e.onEvent("disposing",w),y=e.onDisposed(w)):w(),Object.freeze({get ui(){return a},editor:e,dispose:w,onChanged(o){if(h(),typeof o!="function")throw new TypeError("Listener must be a function");f.add(o);try{o(a)}catch(r){throw f.delete(o),r}return()=>f.delete(o)},async invokeAction(o){h();let r=c.get(o),b=a.actions.find(s=>s.id===o);if(!r)throw new T("UnknownAction","Unknown host action: "+o);if(!b.enabled||!b.visible)throw new T("ActionUnavailable","Host action is unavailable: "+o);let n=new AbortController;u.add(n);try{await r({editor:e,signal:n.signal})}catch(s){throw s instanceof T?s:new T(typeof s?.code=="string"?s.code:"HostActionFailed",s?.message??String(s),{cause:s})}finally{u.delete(n)}},async setActionState(o,r){if(h(),!c.has(o))throw new TypeError("Unknown host action: "+o);if(!r||typeof r!="object"||Array.isArray(r)||Object.keys(r).some(n=>!["label","enabled","visible"].includes(n)))throw new TypeError("Invalid action state");let b={};if(r.label!==void 0){if(typeof r.label!="string"||!r.label.trim())throw new TypeError("Action label must be a nonempty string");b.label=r.label}for(let n of["enabled","visible"])if(r[n]!==void 0){if(typeof r[n]!="boolean")throw new TypeError("Action "+n+" must be a boolean");b[n]=r[n]}a=Object.freeze({...a,actions:Object.freeze(a.actions.map(n=>n.id===o?Object.freeze({...n,...b}):n))});for(let n of f)try{n(a)}catch(s){console.error("Editor UI listener failed",s)}}})}export{N as createEditorUiController};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EditorSelectedObject, EditorScreenBounds } from '@drawmotive/editor';
|
|
2
|
+
import type { NormalizedUiOptions } from './ui-options.js';
|
|
3
|
+
export declare const CONTEXT_TOOL_IDS: readonly string[];
|
|
4
|
+
export declare const CONTEXT_PANEL_IDS: readonly string[];
|
|
5
|
+
export declare function selectionSubjects(items: readonly EditorSelectedObject[]): readonly EditorSelectedObject[];
|
|
6
|
+
export declare function contextTools(items: readonly EditorSelectedObject[], options: NormalizedUiOptions['contextToolbar']): string[];
|
|
7
|
+
export declare function placeFloating(anchor: EditorScreenBounds, size: {width:number;height:number}, viewport: {width:number;height:number}): {left:number;top:number};
|
|
8
|
+
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;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EditorButtonId, EditorRegionId, DrawingToolId, EditorUiOptions, NormalizedUiConfiguration } from './ui-options.js';
|
|
2
|
+
|
|
3
|
+
export declare const EDITOR_BUTTON_IDS: readonly EditorButtonId[];
|
|
4
|
+
export declare const EDITOR_REGION_IDS: readonly EditorRegionId[];
|
|
5
|
+
export declare const DRAWING_TOOL_IDS: readonly DrawingToolId[];
|
|
6
|
+
export declare function normalizeUiOptions(options?: EditorUiOptions | false): NormalizedUiConfiguration;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { EditorInstance } from '@drawmotive/editor';
|
|
2
|
+
/** Creation tools and the document's sketch mode toggle share toolbar configuration. */
|
|
3
|
+
export type DrawingToolId = 'arrow' | 'rectangle' | 'ellipse' | 'diamond' | 'capsule' | 'star' | 'cloud' | 'text' | 'sketchyMode';
|
|
4
|
+
/** drawingProperties is a legacy Settings entry; defaults expose only settings. */
|
|
5
|
+
export type EditorButtonId = 'undo' | 'redo' | DrawingToolId | 'drawingProperties' | 'zoomIn' | 'zoomOut' | 'resetZoom' | 'settings' | 'help';
|
|
6
|
+
export type EditorRegionId = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
|
|
7
|
+
/** Slots name React content resolved by the local UI; elements never cross a port. */
|
|
8
|
+
export type EditorRegionItem = EditorButtonId | `host.${string}` | `slot.${string}`;
|
|
9
|
+
export interface EditorUiActionState {
|
|
10
|
+
label?: string;
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
visible?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface EditorUiAction extends EditorUiActionState {
|
|
15
|
+
id: `host.${string}`;
|
|
16
|
+
label: string;
|
|
17
|
+
icon?: string;
|
|
18
|
+
onInvoke(context: {
|
|
19
|
+
editor: EditorInstance;
|
|
20
|
+
signal: AbortSignal;
|
|
21
|
+
}): void | Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface EditorRegionOptions {
|
|
24
|
+
visible?: boolean;
|
|
25
|
+
/** Item order is preserved. Hidden buttons retain their semantic capabilities. */
|
|
26
|
+
items?: readonly EditorRegionItem[];
|
|
27
|
+
}
|
|
28
|
+
export interface DrawingToolbarOptions {
|
|
29
|
+
visible?: boolean;
|
|
30
|
+
position?: 'left' | 'right' | 'top' | 'bottom';
|
|
31
|
+
tools?: readonly DrawingToolId[];
|
|
32
|
+
}
|
|
33
|
+
export interface ContextToolbarOptions {
|
|
34
|
+
visible?: boolean;
|
|
35
|
+
/** Omitted lists include every supported object type, tool or panel. */
|
|
36
|
+
objectTypes?: readonly string[];
|
|
37
|
+
tools?: readonly string[];
|
|
38
|
+
panels?: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
export interface EditorTooltipOptions {
|
|
41
|
+
visible?: boolean;
|
|
42
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
43
|
+
delay?: number;
|
|
44
|
+
}
|
|
45
|
+
/** Private web chrome configuration; no native runtime or account state. */
|
|
46
|
+
export interface EditorUiOptions {
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
buttons?: Partial<Record<EditorButtonId, boolean>>;
|
|
49
|
+
actions?: readonly EditorUiAction[];
|
|
50
|
+
regions?: Partial<Record<EditorRegionId, boolean | EditorRegionOptions>>;
|
|
51
|
+
drawingToolbar?: boolean | DrawingToolbarOptions;
|
|
52
|
+
contextToolbar?: boolean | ContextToolbarOptions;
|
|
53
|
+
tooltip?: boolean | EditorTooltipOptions;
|
|
54
|
+
}
|
|
55
|
+
export interface EditorActionDescriptor {
|
|
56
|
+
readonly id: `host.${string}`;
|
|
57
|
+
readonly label: string;
|
|
58
|
+
readonly enabled: boolean;
|
|
59
|
+
readonly visible: boolean;
|
|
60
|
+
readonly icon?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface NormalizedUiOptions {
|
|
63
|
+
readonly enabled: boolean;
|
|
64
|
+
readonly buttons: Readonly<Record<EditorButtonId, boolean>>;
|
|
65
|
+
readonly actions: readonly EditorActionDescriptor[];
|
|
66
|
+
readonly regions: Readonly<Record<EditorRegionId, {
|
|
67
|
+
readonly visible: boolean;
|
|
68
|
+
readonly items: readonly EditorRegionItem[];
|
|
69
|
+
}>>;
|
|
70
|
+
readonly drawingToolbar: {
|
|
71
|
+
readonly visible: boolean;
|
|
72
|
+
readonly position: NonNullable<DrawingToolbarOptions['position']>;
|
|
73
|
+
readonly tools: readonly DrawingToolId[];
|
|
74
|
+
};
|
|
75
|
+
readonly contextToolbar: {
|
|
76
|
+
readonly visible: boolean;
|
|
77
|
+
readonly objectTypes?: readonly string[];
|
|
78
|
+
readonly tools?: readonly string[];
|
|
79
|
+
readonly panels?: readonly string[];
|
|
80
|
+
};
|
|
81
|
+
readonly tooltip: {
|
|
82
|
+
readonly visible: boolean;
|
|
83
|
+
readonly position: 'top' | 'bottom' | 'left' | 'right';
|
|
84
|
+
readonly delay: number;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export interface NormalizedUiConfiguration {
|
|
88
|
+
readonly ui: NormalizedUiOptions;
|
|
89
|
+
/** Only the local host owns callbacks and cancels them during disposal. */
|
|
90
|
+
readonly handlers: Map<string, EditorUiAction['onInvoke']>;
|
|
91
|
+
}
|
|
92
|
+
export { EDITOR_BUTTON_IDS, EDITOR_REGION_IDS, DRAWING_TOOL_IDS, normalizeUiOptions } from './ui-options-runtime.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EditorInstance, EditorSelectionSnapshot, EditorState } from '@drawmotive/editor';
|
|
2
|
+
import type { NormalizedUiOptions } from './ui-options.js';
|
|
3
|
+
import type { QuickInsertTool } from './quick-insert-model.js';
|
|
4
|
+
interface HotkeyContext {
|
|
5
|
+
editor: EditorInstance;
|
|
6
|
+
container: HTMLElement;
|
|
7
|
+
ui: NormalizedUiOptions;
|
|
8
|
+
state(): EditorState;
|
|
9
|
+
selection(): EditorSelectionSnapshot | null;
|
|
10
|
+
run(action: () => Promise<unknown>, key?: string): Promise<boolean>;
|
|
11
|
+
report(reason: unknown): void;
|
|
12
|
+
activateTool(tool: QuickInsertTool): Promise<void>;
|
|
13
|
+
openQuickInsert(): void;
|
|
14
|
+
}
|
|
15
|
+
/** Mantine owns key matching. Native methods receive only semantic intent;
|
|
16
|
+
* canvas scope and held-input cleanup stay in the shared browser document. */
|
|
17
|
+
export declare function useEditorHotkeys(context: HotkeyContext): void;
|
|
18
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drawmotive/editor-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "Reusable React drawing controls for the DrawMotive canvas editor.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./controller": {
|
|
13
|
+
"types": "./dist/ui-controller.d.ts",
|
|
14
|
+
"default": "./dist/ui-controller.js"
|
|
15
|
+
},
|
|
16
|
+
"./styles.css": {
|
|
17
|
+
"types": "./dist/index.css.d.ts",
|
|
18
|
+
"default": "./dist/index.css"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/index.js",
|
|
23
|
+
"dist/index.css",
|
|
24
|
+
"dist/ui-controller.js",
|
|
25
|
+
"dist/*.d.ts",
|
|
26
|
+
"dist/MaterialSymbols-LICENSE.txt",
|
|
27
|
+
"dist/MaterialSymbols-NOTICE.txt"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": [
|
|
30
|
+
"**/*.css"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/drawmotive/editor-ui.git"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/drawmotive/editor-ui#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/drawmotive/editor-ui/issues"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/",
|
|
47
|
+
"tag": "latest"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "node scripts/build.mjs",
|
|
51
|
+
"test": "node --test --test-concurrency=1 test/*.test.mjs",
|
|
52
|
+
"test:package": "node --test --test-concurrency=1 test/*.package.mjs",
|
|
53
|
+
"test:browser": "playwright test",
|
|
54
|
+
"preview": "node test/serve.mjs",
|
|
55
|
+
"release:check": "node .release/check.cjs --ready",
|
|
56
|
+
"prepack": "npm run release:check && npm run build"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@drawmotive/editor": "0.3.3",
|
|
60
|
+
"@mantine/core": "9.7.4",
|
|
61
|
+
"@mantine/hooks": "9.7.4",
|
|
62
|
+
"@phosphor-icons/react": "2.1.10"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"react": "19.3.1",
|
|
66
|
+
"react-dom": "19.3.1"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@playwright/test": "1.63.0",
|
|
70
|
+
"@types/react": "19.3.0",
|
|
71
|
+
"@types/react-dom": "19.3.0",
|
|
72
|
+
"esbuild": "0.28.2",
|
|
73
|
+
"typescript": "^7.0.2"
|
|
74
|
+
}
|
|
75
|
+
}
|