js-draw 1.18.0 → 1.20.0
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/README.md +51 -0
- package/dist/Editor.css +78 -5
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.d.ts +20 -1
- package/dist/cjs/Editor.js +6 -0
- package/dist/cjs/{SVGLoader.d.ts → SVGLoader/index.d.ts} +1 -1
- package/dist/cjs/{SVGLoader.js → SVGLoader/index.js} +15 -30
- package/dist/cjs/SVGLoader/utils/determineFontSize.d.ts +3 -0
- package/dist/cjs/SVGLoader/utils/determineFontSize.js +27 -0
- package/dist/cjs/Viewport.d.ts +33 -1
- package/dist/cjs/components/TextComponent.js +3 -1
- package/dist/cjs/image/EditorImage.d.ts +2 -1
- package/dist/cjs/image/EditorImage.js +101 -5
- package/dist/cjs/rendering/caching/RenderingCacheNode.js +20 -15
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +4 -4
- package/dist/cjs/testing/findNodeWithText.d.ts +3 -0
- package/dist/cjs/testing/findNodeWithText.js +16 -0
- package/dist/cjs/testing/firstElementAncestorOfNode.d.ts +3 -0
- package/dist/cjs/testing/firstElementAncestorOfNode.js +13 -0
- package/dist/cjs/testing/sendKeyPressRelease.d.ts +3 -0
- package/dist/cjs/testing/sendKeyPressRelease.js +8 -0
- package/dist/cjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/cjs/testing/sendPenEvent.js +26 -3
- package/dist/cjs/toolbar/localization.d.ts +3 -0
- package/dist/cjs/toolbar/localization.js +3 -0
- package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +1 -0
- package/dist/cjs/toolbar/widgets/BaseWidget.js +1 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget/ImageWrapper.d.ts +23 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget/ImageWrapper.js +65 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget/fileToImages.d.ts +3 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget/fileToImages.js +21 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget/index.d.ts +37 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget/index.js +289 -0
- package/dist/cjs/toolbar/widgets/TextToolWidget.js +5 -3
- package/dist/cjs/toolbar/widgets/TextToolWidget.test.d.ts +1 -0
- package/dist/cjs/toolbar/widgets/components/makeFileInput.d.ts +12 -2
- package/dist/cjs/toolbar/widgets/components/makeFileInput.js +113 -45
- package/dist/cjs/toolbar/widgets/components/makeFileInput.test.d.ts +1 -0
- package/dist/cjs/toolbar/widgets/components/makeSnappedList.d.ts +15 -0
- package/dist/cjs/toolbar/widgets/components/makeSnappedList.js +168 -0
- package/dist/cjs/tools/Eraser.d.ts +7 -2
- package/dist/cjs/tools/Eraser.js +76 -6
- package/dist/cjs/tools/PanZoom.d.ts +54 -0
- package/dist/cjs/tools/PanZoom.js +54 -2
- package/dist/cjs/tools/SelectionTool/Selection.d.ts +2 -2
- package/dist/cjs/tools/SelectionTool/Selection.js +20 -20
- package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +8 -2
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +6 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +1 -1
- package/dist/cjs/tools/SelectionTool/types.d.ts +19 -0
- package/dist/cjs/tools/TextTool.js +2 -1
- package/dist/cjs/tools/TextTool.test.d.ts +1 -0
- package/dist/cjs/tools/ToolController.d.ts +2 -0
- package/dist/cjs/tools/ToolController.js +10 -1
- package/dist/cjs/util/ReactiveValue.d.ts +6 -0
- package/dist/cjs/util/ReactiveValue.js +16 -0
- package/dist/cjs/util/bytesToSizeString.d.ts +8 -0
- package/dist/cjs/util/bytesToSizeString.js +26 -0
- package/dist/cjs/util/bytesToSizeString.test.d.ts +1 -0
- package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.js +10 -6
- package/dist/cjs/util/waitForAll.d.ts +2 -0
- package/dist/cjs/util/waitForAll.js +2 -0
- package/dist/cjs/util/waitForImageLoaded.js +3 -0
- package/dist/cjs/util/waitForTimeout.d.ts +1 -0
- package/dist/cjs/util/waitForTimeout.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/Editor.d.ts +20 -1
- package/dist/mjs/Editor.mjs +6 -0
- package/dist/mjs/{SVGLoader.d.ts → SVGLoader/index.d.ts} +1 -1
- package/dist/mjs/{SVGLoader.mjs → SVGLoader/index.mjs} +15 -30
- package/dist/mjs/SVGLoader/index.test.d.ts +1 -0
- package/dist/mjs/SVGLoader/utils/determineFontSize.d.ts +3 -0
- package/dist/mjs/SVGLoader/utils/determineFontSize.mjs +25 -0
- package/dist/mjs/Viewport.d.ts +33 -1
- package/dist/mjs/components/TextComponent.mjs +3 -1
- package/dist/mjs/image/EditorImage.d.ts +2 -1
- package/dist/mjs/image/EditorImage.mjs +101 -5
- package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +20 -15
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +4 -4
- package/dist/mjs/testing/findNodeWithText.d.ts +3 -0
- package/dist/mjs/testing/findNodeWithText.mjs +14 -0
- package/dist/mjs/testing/firstElementAncestorOfNode.d.ts +3 -0
- package/dist/mjs/testing/firstElementAncestorOfNode.mjs +11 -0
- package/dist/mjs/testing/sendKeyPressRelease.d.ts +3 -0
- package/dist/mjs/testing/sendKeyPressRelease.mjs +6 -0
- package/dist/mjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/mjs/testing/sendPenEvent.mjs +3 -3
- package/dist/mjs/toolbar/localization.d.ts +3 -0
- package/dist/mjs/toolbar/localization.mjs +3 -0
- package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +1 -0
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +1 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget/ImageWrapper.d.ts +23 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget/ImageWrapper.mjs +61 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget/fileToImages.d.ts +3 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget/fileToImages.mjs +16 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget/index.d.ts +37 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget/index.mjs +284 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget/index.test.d.ts +1 -0
- package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +5 -3
- package/dist/mjs/toolbar/widgets/TextToolWidget.test.d.ts +1 -0
- package/dist/mjs/toolbar/widgets/components/makeFileInput.d.ts +12 -2
- package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +113 -45
- package/dist/mjs/toolbar/widgets/components/makeFileInput.test.d.ts +1 -0
- package/dist/mjs/toolbar/widgets/components/makeSnappedList.d.ts +15 -0
- package/dist/mjs/toolbar/widgets/components/makeSnappedList.mjs +163 -0
- package/dist/mjs/tools/Eraser.d.ts +7 -2
- package/dist/mjs/tools/Eraser.mjs +76 -6
- package/dist/mjs/tools/PanZoom.d.ts +54 -0
- package/dist/mjs/tools/PanZoom.mjs +54 -2
- package/dist/mjs/tools/SelectionTool/Selection.d.ts +2 -2
- package/dist/mjs/tools/SelectionTool/Selection.mjs +20 -20
- package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +8 -2
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +6 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +1 -1
- package/dist/mjs/tools/SelectionTool/types.d.ts +19 -0
- package/dist/mjs/tools/TextTool.mjs +2 -1
- package/dist/mjs/tools/TextTool.test.d.ts +1 -0
- package/dist/mjs/tools/ToolController.d.ts +2 -0
- package/dist/mjs/tools/ToolController.mjs +10 -1
- package/dist/mjs/util/ReactiveValue.d.ts +6 -0
- package/dist/mjs/util/ReactiveValue.mjs +16 -0
- package/dist/mjs/util/bytesToSizeString.d.ts +8 -0
- package/dist/mjs/util/bytesToSizeString.mjs +24 -0
- package/dist/mjs/util/bytesToSizeString.test.d.ts +1 -0
- package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.mjs +10 -6
- package/dist/mjs/util/waitForAll.d.ts +2 -0
- package/dist/mjs/util/waitForAll.mjs +2 -0
- package/dist/mjs/util/waitForImageLoaded.mjs +3 -0
- package/dist/mjs/util/waitForTimeout.d.ts +1 -0
- package/dist/mjs/util/waitForTimeout.mjs +1 -1
- package/dist/mjs/version.mjs +1 -1
- package/package.json +4 -4
- package/src/toolbar/EdgeToolbar.scss +8 -3
- package/src/toolbar/toolbar.scss +1 -7
- package/src/toolbar/widgets/{InsertImageWidget.scss → InsertImageWidget/index.scss} +3 -2
- package/src/toolbar/widgets/components/components.scss +2 -1
- package/src/toolbar/widgets/components/makeFileInput.scss +14 -1
- package/src/toolbar/widgets/components/makeSnappedList.scss +74 -0
- package/src/toolbar/widgets/widgets.scss +7 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget.d.ts +0 -22
- package/dist/cjs/toolbar/widgets/InsertImageWidget.js +0 -269
- package/dist/mjs/toolbar/widgets/InsertImageWidget.d.ts +0 -22
- package/dist/mjs/toolbar/widgets/InsertImageWidget.mjs +0 -264
- /package/dist/cjs/{SVGLoader.test.d.ts → SVGLoader/index.test.d.ts} +0 -0
- /package/dist/{mjs/SVGLoader.test.d.ts → cjs/toolbar/widgets/InsertImageWidget/index.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -15,6 +15,55 @@
|
|
|
15
15
|
|
|
16
16
|
For example usage, see [one of the examples](https://github.com/personalizedrefrigerator/js-draw/blob/main/docs/examples.md) or read [the documentation](https://personalizedrefrigerator.github.io/js-draw/typedoc/).
|
|
17
17
|
|
|
18
|
+
# Features
|
|
19
|
+
|
|
20
|
+
## Very large zoom range
|
|
21
|
+
|
|
22
|
+
A core feature of `js-draw` is its [large zoom range](https://personalizedrefrigerator.github.io/js-draw/typedoc/interfaces/js_draw.EditorSettings.html#maxZoom) (from roughly 10⁻¹⁰x to 10¹⁰x).
|
|
23
|
+
|
|
24
|
+
<details open><summary><strong>Demo</strong></summary>
|
|
25
|
+
|
|
26
|
+
<video src="https://github.com/personalizedrefrigerator/js-draw/assets/46334387/f1c4afea-d7c8-4c36-835b-e01f2a646424" alt="Video: Shows zooming out further and further" controls></video>
|
|
27
|
+
|
|
28
|
+
</details>
|
|
29
|
+
|
|
30
|
+
Applications using `js-draw` can adjust this zoom range with custom [EditorSettings](https://personalizedrefrigerator.github.io/js-draw/typedoc/interfaces/js_draw.EditorSettings.html).
|
|
31
|
+
|
|
32
|
+
## Touchscreen and stylus support
|
|
33
|
+
|
|
34
|
+
`js-draw` supports touchscreen pinch zoom and rotate gestures. To simplify editing, screen rotation snaps to multiples of 90 degrees.
|
|
35
|
+
|
|
36
|
+
<details><summary><strong>Demo</strong></summary>
|
|
37
|
+
|
|
38
|
+
<video src="https://github.com/personalizedrefrigerator/js-draw/assets/46334387/1f4ebeb1-9d2f-4884-9410-9fb1d5e455ee" alt="Video: Shows canvas being rotated" controls></video>
|
|
39
|
+
|
|
40
|
+
</details>
|
|
41
|
+
|
|
42
|
+
It's also possible to disable touch drawing. This can be useful when drawing with a stylus and can be done with either [PanZoomTool.setMode](https://personalizedrefrigerator.github.io/js-draw/typedoc/classes/js_draw.PanZoomTool.html#setMode) or, by a user, with the "hand" tool menu:
|
|
43
|
+
|
|
44
|
+
<img alt="screenshot: Hand tool menu at the bottom of the screen includes 'lock rotation' and 'touchscreen panning'. 'Touchscreen panning' is highlighted." src="https://github.com/personalizedrefrigerator/js-draw/assets/46334387/d96e2df5-6132-4122-954d-d25402754bc2" width="400"/>
|
|
45
|
+
|
|
46
|
+
## User-configurable tools
|
|
47
|
+
|
|
48
|
+
With the default toolbar, users can change the pen style, color, and more:
|
|
49
|
+
|
|
50
|
+
<img alt="screenshot: Pen configuration menu includes pen size, color, type, stabilization, autocorrect,..." src="https://github.com/personalizedrefrigerator/js-draw/assets/46334387/476ad0e4-1f95-43bf-925d-549292d141e3" width="400"/>
|
|
51
|
+
|
|
52
|
+
It's possible for applications using `js-draw` to [add custom pen types](https://personalizedrefrigerator.github.io/js-draw/typedoc/modules/Additional_Documentation.CustomizingTools__.html) that can also be customized in this way. It's also possible to [save the toolbar state](https://github.com/personalizedrefrigerator/js-draw/blob/main/docs/examples/example-save-restore-toolbar-state/example.ts) and restore it after reloading the app.
|
|
53
|
+
|
|
54
|
+
## More features
|
|
55
|
+
|
|
56
|
+
`js-draw` also supports:
|
|
57
|
+
|
|
58
|
+
- <details><summary>Partial stroke erasing</summary>
|
|
59
|
+
|
|
60
|
+
<video src="https://github.com/personalizedrefrigerator/js-draw/assets/46334387/c8c2b8d5-5537-4df8-a8b5-899c2d7ea5ce"></video>
|
|
61
|
+
|
|
62
|
+
</details>
|
|
63
|
+
- [Collaborative editing](https://github.com/personalizedrefrigerator/js-draw/tree/main/docs/examples/example-collaborative)
|
|
64
|
+
- Saving to and loading from a subset of SVG
|
|
65
|
+
|
|
66
|
+
|
|
18
67
|
# API
|
|
19
68
|
|
|
20
69
|
## Creating an `Editor`
|
|
@@ -329,6 +378,8 @@ body .imageEditorContainer {
|
|
|
329
378
|
```
|
|
330
379
|
disables the dark theme and creates a theme that primarily uses yellow/green colors.
|
|
331
380
|
|
|
381
|
+
See also [adjustEditorThemeForContrast](https://personalizedrefrigerator.github.io/js-draw/typedoc/functions/js_draw.adjustEditorThemeForContrast.html).
|
|
382
|
+
|
|
332
383
|
# Examples and resources
|
|
333
384
|
|
|
334
385
|
- [Examples](https://github.com/personalizedrefrigerator/js-draw/blob/main/docs/examples.md)
|
package/dist/Editor.css
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
min-height: 0;
|
|
7
7
|
}
|
|
8
8
|
:root .insert-image-widget-dropdown-content.insert-image-widget-dropdown-content.insert-image-widget-dropdown-content img {
|
|
9
|
-
max-width:
|
|
10
|
-
max-height:
|
|
9
|
+
max-width: 100%;
|
|
10
|
+
max-height: 100%;
|
|
11
11
|
/* Center */
|
|
12
12
|
display: block;
|
|
13
13
|
margin-left: auto;
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
:root .insert-image-widget-dropdown-content.insert-image-widget-dropdown-content.insert-image-widget-dropdown-content .insert-image-image-status-view {
|
|
17
17
|
display: flex;
|
|
18
18
|
justify-content: space-between;
|
|
19
|
+
padding-bottom: 0;
|
|
19
20
|
}
|
|
20
21
|
:root .insert-image-widget-dropdown-content.insert-image-widget-dropdown-content.insert-image-widget-dropdown-content .action-button-row {
|
|
21
22
|
margin-top: 4px;
|
|
@@ -208,12 +209,18 @@
|
|
|
208
209
|
.toolbar-element .toolbar--file-input-container {
|
|
209
210
|
display: flex;
|
|
210
211
|
}
|
|
211
|
-
.toolbar-element .toolbar--file-input-container
|
|
212
|
+
.toolbar-element .toolbar--file-input-container.-loading {
|
|
213
|
+
opacity: 0.8;
|
|
214
|
+
}
|
|
215
|
+
.toolbar-element .toolbar--file-input-container > input.file-input {
|
|
212
216
|
opacity: 0;
|
|
213
217
|
width: 0;
|
|
214
218
|
min-width: 0 !important;
|
|
215
219
|
max-width: 0;
|
|
216
220
|
height: 0;
|
|
221
|
+
overflow: hidden;
|
|
222
|
+
padding: 0;
|
|
223
|
+
margin: 0;
|
|
217
224
|
}
|
|
218
225
|
.toolbar-element .toolbar--file-input-container > label {
|
|
219
226
|
display: block;
|
|
@@ -225,6 +232,9 @@
|
|
|
225
232
|
in srgb, var(--foreground-color-1), transparent
|
|
226
233
|
);
|
|
227
234
|
}
|
|
235
|
+
.toolbar-element .toolbar--file-input-container > label > .cancel-button {
|
|
236
|
+
display: block;
|
|
237
|
+
}
|
|
228
238
|
.toolbar-element .toolbar--file-input-container > label > .toolbar--file-input-description {
|
|
229
239
|
background-color: var(--background-color-3);
|
|
230
240
|
color: var(--foreground-color-3);
|
|
@@ -307,6 +317,64 @@
|
|
|
307
317
|
--icon-color: var(--selection-foreground-color);
|
|
308
318
|
}
|
|
309
319
|
|
|
320
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list {
|
|
321
|
+
height: min(200px, 50vh);
|
|
322
|
+
position: relative;
|
|
323
|
+
display: flex;
|
|
324
|
+
align-items: center;
|
|
325
|
+
}
|
|
326
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list > .scroller {
|
|
327
|
+
display: flex;
|
|
328
|
+
flex-direction: column;
|
|
329
|
+
overflow-y: auto;
|
|
330
|
+
scroll-snap-type: y mandatory;
|
|
331
|
+
height: 100%;
|
|
332
|
+
width: 100%;
|
|
333
|
+
flex-grow: 1;
|
|
334
|
+
}
|
|
335
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list > .scroller > .item {
|
|
336
|
+
height: 100%;
|
|
337
|
+
width: 100%;
|
|
338
|
+
flex-shrink: 0;
|
|
339
|
+
display: flex;
|
|
340
|
+
justify-content: center;
|
|
341
|
+
align-items: center;
|
|
342
|
+
scroll-snap-align: start;
|
|
343
|
+
scroll-snap-stop: always;
|
|
344
|
+
box-sizing: border-box;
|
|
345
|
+
}
|
|
346
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.-empty {
|
|
347
|
+
display: none;
|
|
348
|
+
}
|
|
349
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list > .page-markers {
|
|
350
|
+
overflow: hidden;
|
|
351
|
+
display: flex;
|
|
352
|
+
flex-direction: column;
|
|
353
|
+
align-items: center;
|
|
354
|
+
max-height: 100%;
|
|
355
|
+
min-height: 0;
|
|
356
|
+
}
|
|
357
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list > .page-markers.-one-element {
|
|
358
|
+
visibility: hidden;
|
|
359
|
+
}
|
|
360
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list > .page-markers > .marker {
|
|
361
|
+
padding: 2px;
|
|
362
|
+
opacity: 0.1;
|
|
363
|
+
cursor: pointer;
|
|
364
|
+
left: 0;
|
|
365
|
+
transition: left 0.2s ease;
|
|
366
|
+
}
|
|
367
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list > .page-markers > .marker > .content {
|
|
368
|
+
background-color: var(--foreground-color-1);
|
|
369
|
+
border-radius: 2px;
|
|
370
|
+
padding: 2px;
|
|
371
|
+
}
|
|
372
|
+
:root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list > .page-markers > .marker.-active {
|
|
373
|
+
position: relative;
|
|
374
|
+
left: 2px;
|
|
375
|
+
opacity: 0.2;
|
|
376
|
+
}
|
|
377
|
+
|
|
310
378
|
/* The *main* root toolbar element */
|
|
311
379
|
.toolbar-root {
|
|
312
380
|
background-color: var(--background-color-1);
|
|
@@ -881,14 +949,19 @@
|
|
|
881
949
|
box-shadow: none;
|
|
882
950
|
border: none;
|
|
883
951
|
padding: 10px;
|
|
884
|
-
color: var(--foreground-color-1);
|
|
885
952
|
transition: 0.2s ease box-shadow;
|
|
886
953
|
font-weight: bold;
|
|
887
954
|
color: var(--primary-action-foreground-color);
|
|
888
955
|
}
|
|
889
|
-
.toolbar-edgemenu-container button:hover {
|
|
956
|
+
.toolbar-edgemenu-container button:not(:disabled):hover {
|
|
890
957
|
box-shadow: 0 1px 2px var(--shadow-color);
|
|
891
958
|
}
|
|
959
|
+
.toolbar-edgemenu-container button:disabled {
|
|
960
|
+
opacity: 0.5;
|
|
961
|
+
font-weight: unset;
|
|
962
|
+
cursor: unset;
|
|
963
|
+
color: var(--foreground-color-1);
|
|
964
|
+
}
|
|
892
965
|
.toolbar-edgemenu-container .toolbar-grid-selector .choice-button {
|
|
893
966
|
--button-label-hover-offset-y: var(--button-size);
|
|
894
967
|
}
|