js-draw 1.17.0 → 1.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. package/README.md +70 -10
  2. package/dist/Editor.css +35 -3
  3. package/dist/bundle.js +2 -2
  4. package/dist/bundledStyles.js +1 -1
  5. package/dist/cjs/Editor.d.ts +38 -21
  6. package/dist/cjs/Editor.js +11 -2
  7. package/dist/cjs/{SVGLoader.d.ts → SVGLoader/index.d.ts} +1 -1
  8. package/dist/cjs/{SVGLoader.js → SVGLoader/index.js} +12 -29
  9. package/dist/cjs/SVGLoader/utils/determineFontSize.d.ts +3 -0
  10. package/dist/cjs/SVGLoader/utils/determineFontSize.js +27 -0
  11. package/dist/cjs/Viewport.d.ts +33 -1
  12. package/dist/cjs/components/AbstractComponent.d.ts +17 -5
  13. package/dist/cjs/components/AbstractComponent.js +15 -15
  14. package/dist/cjs/components/Stroke.d.ts +4 -1
  15. package/dist/cjs/components/Stroke.js +158 -2
  16. package/dist/cjs/components/TextComponent.js +3 -1
  17. package/dist/cjs/components/builders/PolylineBuilder.d.ts +1 -1
  18. package/dist/cjs/components/builders/PolylineBuilder.js +9 -2
  19. package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
  20. package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +44 -51
  21. package/dist/cjs/image/EditorImage.js +1 -1
  22. package/dist/cjs/localizations/de.js +1 -1
  23. package/dist/cjs/localizations/es.js +1 -1
  24. package/dist/cjs/rendering/caching/RenderingCacheNode.js +20 -15
  25. package/dist/cjs/testing/createEditor.d.ts +2 -2
  26. package/dist/cjs/testing/createEditor.js +2 -2
  27. package/dist/cjs/testing/findNodeWithText.d.ts +3 -0
  28. package/dist/cjs/testing/findNodeWithText.js +16 -0
  29. package/dist/cjs/testing/firstElementAncestorOfNode.d.ts +3 -0
  30. package/dist/cjs/testing/firstElementAncestorOfNode.js +13 -0
  31. package/dist/cjs/testing/sendKeyPressRelease.d.ts +3 -0
  32. package/dist/cjs/testing/sendKeyPressRelease.js +8 -0
  33. package/dist/cjs/testing/sendPenEvent.d.ts +2 -2
  34. package/dist/cjs/testing/sendPenEvent.js +26 -3
  35. package/dist/cjs/toolbar/IconProvider.d.ts +3 -1
  36. package/dist/cjs/toolbar/IconProvider.js +15 -3
  37. package/dist/cjs/toolbar/localization.d.ts +8 -1
  38. package/dist/cjs/toolbar/localization.js +9 -2
  39. package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +1 -0
  40. package/dist/cjs/toolbar/widgets/BaseWidget.js +1 -0
  41. package/dist/cjs/toolbar/widgets/EraserToolWidget.d.ts +6 -1
  42. package/dist/cjs/toolbar/widgets/EraserToolWidget.js +45 -5
  43. package/dist/cjs/toolbar/widgets/InsertImageWidget/ImageWrapper.d.ts +22 -0
  44. package/dist/cjs/toolbar/widgets/InsertImageWidget/ImageWrapper.js +58 -0
  45. package/dist/cjs/toolbar/widgets/InsertImageWidget/fileToImages.d.ts +3 -0
  46. package/dist/cjs/toolbar/widgets/InsertImageWidget/fileToImages.js +21 -0
  47. package/dist/cjs/toolbar/widgets/InsertImageWidget/index.d.ts +37 -0
  48. package/dist/cjs/toolbar/widgets/InsertImageWidget/index.js +281 -0
  49. package/dist/cjs/toolbar/widgets/PenToolWidget.js +10 -3
  50. package/dist/cjs/toolbar/widgets/PenToolWidget.test.d.ts +1 -0
  51. package/dist/cjs/toolbar/widgets/TextToolWidget.js +5 -3
  52. package/dist/cjs/toolbar/widgets/TextToolWidget.test.d.ts +1 -0
  53. package/dist/cjs/toolbar/widgets/components/makeFileInput.d.ts +12 -2
  54. package/dist/cjs/toolbar/widgets/components/makeFileInput.js +102 -45
  55. package/dist/cjs/toolbar/widgets/components/makeFileInput.test.d.ts +1 -0
  56. package/dist/cjs/toolbar/widgets/components/makeSnappedList.d.ts +15 -0
  57. package/dist/cjs/toolbar/widgets/components/makeSnappedList.js +103 -0
  58. package/dist/cjs/toolbar/widgets/keybindings.js +1 -1
  59. package/dist/cjs/tools/Eraser.d.ts +31 -6
  60. package/dist/cjs/tools/Eraser.js +161 -21
  61. package/dist/cjs/tools/PasteHandler.js +0 -1
  62. package/dist/cjs/tools/SelectionTool/Selection.d.ts +2 -2
  63. package/dist/cjs/tools/SelectionTool/Selection.js +20 -20
  64. package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +8 -2
  65. package/dist/cjs/tools/SelectionTool/SelectionHandle.js +6 -0
  66. package/dist/cjs/tools/SelectionTool/SelectionTool.js +1 -1
  67. package/dist/cjs/tools/SelectionTool/types.d.ts +19 -0
  68. package/dist/cjs/tools/TextTool.js +2 -1
  69. package/dist/cjs/tools/TextTool.test.d.ts +1 -0
  70. package/dist/cjs/tools/ToolController.d.ts +2 -0
  71. package/dist/cjs/tools/ToolController.js +10 -1
  72. package/dist/cjs/tools/lib.d.ts +1 -4
  73. package/dist/cjs/tools/lib.js +2 -4
  74. package/dist/cjs/util/ReactiveValue.d.ts +2 -0
  75. package/dist/cjs/util/ReactiveValue.js +11 -0
  76. package/dist/cjs/util/bytesToSizeString.d.ts +8 -0
  77. package/dist/cjs/util/bytesToSizeString.js +26 -0
  78. package/dist/cjs/util/bytesToSizeString.test.d.ts +1 -0
  79. package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.js +10 -6
  80. package/dist/cjs/util/waitForAll.d.ts +2 -0
  81. package/dist/cjs/util/waitForAll.js +2 -0
  82. package/dist/cjs/util/waitForImageLoaded.js +3 -0
  83. package/dist/cjs/util/waitForTimeout.d.ts +1 -0
  84. package/dist/cjs/util/waitForTimeout.js +1 -1
  85. package/dist/cjs/version.js +1 -1
  86. package/dist/mjs/Editor.d.ts +38 -21
  87. package/dist/mjs/Editor.mjs +11 -2
  88. package/dist/mjs/{SVGLoader.d.ts → SVGLoader/index.d.ts} +1 -1
  89. package/dist/mjs/{SVGLoader.mjs → SVGLoader/index.mjs} +12 -29
  90. package/dist/mjs/SVGLoader/index.test.d.ts +1 -0
  91. package/dist/mjs/SVGLoader/utils/determineFontSize.d.ts +3 -0
  92. package/dist/mjs/SVGLoader/utils/determineFontSize.mjs +25 -0
  93. package/dist/mjs/Viewport.d.ts +33 -1
  94. package/dist/mjs/components/AbstractComponent.d.ts +17 -5
  95. package/dist/mjs/components/AbstractComponent.mjs +15 -15
  96. package/dist/mjs/components/Stroke.d.ts +4 -1
  97. package/dist/mjs/components/Stroke.mjs +159 -3
  98. package/dist/mjs/components/TextComponent.mjs +3 -1
  99. package/dist/mjs/components/builders/PolylineBuilder.d.ts +1 -1
  100. package/dist/mjs/components/builders/PolylineBuilder.mjs +10 -3
  101. package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
  102. package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +45 -52
  103. package/dist/mjs/image/EditorImage.mjs +1 -1
  104. package/dist/mjs/localizations/de.mjs +1 -1
  105. package/dist/mjs/localizations/es.mjs +1 -1
  106. package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +20 -15
  107. package/dist/mjs/testing/createEditor.d.ts +2 -2
  108. package/dist/mjs/testing/createEditor.mjs +2 -2
  109. package/dist/mjs/testing/findNodeWithText.d.ts +3 -0
  110. package/dist/mjs/testing/findNodeWithText.mjs +14 -0
  111. package/dist/mjs/testing/firstElementAncestorOfNode.d.ts +3 -0
  112. package/dist/mjs/testing/firstElementAncestorOfNode.mjs +11 -0
  113. package/dist/mjs/testing/sendKeyPressRelease.d.ts +3 -0
  114. package/dist/mjs/testing/sendKeyPressRelease.mjs +6 -0
  115. package/dist/mjs/testing/sendPenEvent.d.ts +2 -2
  116. package/dist/mjs/testing/sendPenEvent.mjs +3 -3
  117. package/dist/mjs/toolbar/IconProvider.d.ts +3 -1
  118. package/dist/mjs/toolbar/IconProvider.mjs +15 -3
  119. package/dist/mjs/toolbar/localization.d.ts +8 -1
  120. package/dist/mjs/toolbar/localization.mjs +9 -2
  121. package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +1 -0
  122. package/dist/mjs/toolbar/widgets/BaseWidget.mjs +1 -0
  123. package/dist/mjs/toolbar/widgets/EraserToolWidget.d.ts +6 -1
  124. package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +47 -6
  125. package/dist/mjs/toolbar/widgets/InsertImageWidget/ImageWrapper.d.ts +22 -0
  126. package/dist/mjs/toolbar/widgets/InsertImageWidget/ImageWrapper.mjs +54 -0
  127. package/dist/mjs/toolbar/widgets/InsertImageWidget/fileToImages.d.ts +3 -0
  128. package/dist/mjs/toolbar/widgets/InsertImageWidget/fileToImages.mjs +16 -0
  129. package/dist/mjs/toolbar/widgets/InsertImageWidget/index.d.ts +37 -0
  130. package/dist/mjs/toolbar/widgets/InsertImageWidget/index.mjs +276 -0
  131. package/dist/mjs/toolbar/widgets/InsertImageWidget/index.test.d.ts +1 -0
  132. package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +10 -3
  133. package/dist/mjs/toolbar/widgets/PenToolWidget.test.d.ts +1 -0
  134. package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +5 -3
  135. package/dist/mjs/toolbar/widgets/TextToolWidget.test.d.ts +1 -0
  136. package/dist/mjs/toolbar/widgets/components/makeFileInput.d.ts +12 -2
  137. package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +102 -45
  138. package/dist/mjs/toolbar/widgets/components/makeFileInput.test.d.ts +1 -0
  139. package/dist/mjs/toolbar/widgets/components/makeSnappedList.d.ts +15 -0
  140. package/dist/mjs/toolbar/widgets/components/makeSnappedList.mjs +98 -0
  141. package/dist/mjs/toolbar/widgets/keybindings.mjs +1 -1
  142. package/dist/mjs/tools/Eraser.d.ts +31 -6
  143. package/dist/mjs/tools/Eraser.mjs +161 -22
  144. package/dist/mjs/tools/PasteHandler.mjs +0 -1
  145. package/dist/mjs/tools/SelectionTool/Selection.d.ts +2 -2
  146. package/dist/mjs/tools/SelectionTool/Selection.mjs +20 -20
  147. package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +8 -2
  148. package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +6 -0
  149. package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +1 -1
  150. package/dist/mjs/tools/SelectionTool/types.d.ts +19 -0
  151. package/dist/mjs/tools/TextTool.mjs +2 -1
  152. package/dist/mjs/tools/TextTool.test.d.ts +1 -0
  153. package/dist/mjs/tools/ToolController.d.ts +2 -0
  154. package/dist/mjs/tools/ToolController.mjs +10 -1
  155. package/dist/mjs/tools/lib.d.ts +1 -4
  156. package/dist/mjs/tools/lib.mjs +1 -4
  157. package/dist/mjs/util/ReactiveValue.d.ts +2 -0
  158. package/dist/mjs/util/ReactiveValue.mjs +11 -0
  159. package/dist/mjs/util/bytesToSizeString.d.ts +8 -0
  160. package/dist/mjs/util/bytesToSizeString.mjs +24 -0
  161. package/dist/mjs/util/bytesToSizeString.test.d.ts +1 -0
  162. package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.mjs +10 -6
  163. package/dist/mjs/util/waitForAll.d.ts +2 -0
  164. package/dist/mjs/util/waitForAll.mjs +2 -0
  165. package/dist/mjs/util/waitForImageLoaded.mjs +3 -0
  166. package/dist/mjs/util/waitForTimeout.d.ts +1 -0
  167. package/dist/mjs/util/waitForTimeout.mjs +1 -1
  168. package/dist/mjs/version.mjs +1 -1
  169. package/package.json +4 -4
  170. package/src/toolbar/toolbar.scss +1 -7
  171. package/src/toolbar/widgets/{InsertImageWidget.scss → InsertImageWidget/index.scss} +3 -2
  172. package/src/toolbar/widgets/components/components.scss +2 -1
  173. package/src/toolbar/widgets/components/makeFileInput.scss +14 -1
  174. package/src/toolbar/widgets/components/makeSnappedList.scss +28 -0
  175. package/src/toolbar/widgets/widgets.scss +7 -0
  176. package/dist/cjs/toolbar/widgets/InsertImageWidget.d.ts +0 -22
  177. package/dist/cjs/toolbar/widgets/InsertImageWidget.js +0 -269
  178. package/dist/mjs/toolbar/widgets/InsertImageWidget.d.ts +0 -22
  179. package/dist/mjs/toolbar/widgets/InsertImageWidget.mjs +0 -264
  180. /package/dist/cjs/{SVGLoader.test.d.ts → SVGLoader/index.test.d.ts} +0 -0
  181. /package/dist/{mjs/SVGLoader.test.d.ts → cjs/toolbar/widgets/InsertImageWidget/index.test.d.ts} +0 -0
@@ -18,9 +18,10 @@ export default class TextTool extends BaseTool {
18
18
  this.textMeasuringCtx = null;
19
19
  this.textScale = Vec2.of(1, 1);
20
20
  this.removeExistingCommand = null;
21
+ const editorFonts = editor.getCurrentSettings().text?.fonts ?? [];
21
22
  this.textStyleValue = ReactiveValue.fromInitialValue({
22
23
  size: 32,
23
- fontFamily: 'sans-serif',
24
+ fontFamily: editorFonts.length > 0 ? editorFonts[0] : 'sans-serif',
24
25
  renderingStyle: {
25
26
  fill: Color4.purple,
26
27
  },
@@ -0,0 +1 @@
1
+ export {};
@@ -55,6 +55,8 @@ export default class ToolController implements InputEventListener {
55
55
  insertToolsAfter(insertAfter: BaseTool, toolsToInsert: BaseTool[]): void;
56
56
  /** @see {@link insertToolsAfter} */
57
57
  insertToolsBefore(insertBefore: BaseTool, toolsToInsert: BaseTool[]): void;
58
+ /** @internal */
59
+ changeActiveToolTo(tool: BaseTool): void;
58
60
  private onEventInternal;
59
61
  /** Alias for {@link dispatchInputEvent}. */
60
62
  onEvent(event: InputEvt): boolean;
@@ -34,6 +34,7 @@ export default class ToolController {
34
34
  const secondaryPenTool = new Pen(editor, localization.penTool(2), { color: Color4.clay, thickness: 4 });
35
35
  // Stabilize the secondary pen tool.
36
36
  secondaryPenTool.setInputMapper(new InputStabilizer(editor.viewport));
37
+ const eraser = new Eraser(editor, localization.eraserTool);
37
38
  const primaryTools = [
38
39
  // Three pens
39
40
  primaryPenTool,
@@ -44,7 +45,7 @@ export default class ToolController {
44
45
  thickness: 40,
45
46
  factory: makePressureSensitiveFreehandLineBuilder
46
47
  }),
47
- new Eraser(editor, localization.eraserTool),
48
+ eraser,
48
49
  new SelectionTool(editor, localization.selectionTool),
49
50
  new TextTool(editor, localization.textTool, localization),
50
51
  new PanZoom(editor, PanZoomMode.SinglePointerGestures, localization.anyDevicePanning),
@@ -62,6 +63,7 @@ export default class ToolController {
62
63
  new UndoRedoShortcut(editor),
63
64
  new ToolbarShortcutHandler(editor),
64
65
  new ToolSwitcherShortcut(editor),
66
+ eraser.makeEraserSwitcherTool(),
65
67
  new FindTool(editor),
66
68
  new PasteHandler(editor),
67
69
  new SelectAllShortcutHandler(editor),
@@ -180,6 +182,13 @@ export default class ToolController {
180
182
  insertToolsBefore(insertBefore, toolsToInsert) {
181
183
  this.insertTools(insertBefore, toolsToInsert, 'before');
182
184
  }
185
+ /** @internal */
186
+ changeActiveToolTo(tool) {
187
+ if (!tool.isEnabled()) {
188
+ tool.setEnabled(true);
189
+ }
190
+ this.activeTool = tool;
191
+ }
183
192
  // @internal use `dispatchEvent` rather than calling `onEvent` directly.
184
193
  onEventInternal(event) {
185
194
  const isEditorReadOnly = this.isEditorReadOnly.get();
@@ -1,6 +1,3 @@
1
- /**
2
- * @packageDocumentation
3
- */
4
1
  export { default as BaseTool } from './BaseTool';
5
2
  export { default as ToolController } from './ToolController';
6
3
  export { default as ToolEnabledGroup } from './ToolEnabledGroup';
@@ -11,7 +8,7 @@ export { default as PenTool, PenStyle } from './Pen';
11
8
  export { default as TextTool } from './TextTool';
12
9
  export { default as SelectionTool } from './SelectionTool/SelectionTool';
13
10
  export { default as SelectAllShortcutHandler } from './SelectionTool/SelectAllShortcutHandler';
14
- export { default as EraserTool } from './Eraser';
11
+ export { default as EraserTool, EraserMode } from './Eraser';
15
12
  export { default as PasteHandler } from './PasteHandler';
16
13
  export { default as SoundUITool } from './SoundUITool';
17
14
  export { default as ToolbarShortcutHandler } from './ToolbarShortcutHandler';
@@ -1,6 +1,3 @@
1
- /**
2
- * @packageDocumentation
3
- */
4
1
  export { default as BaseTool } from './BaseTool.mjs';
5
2
  export { default as ToolController } from './ToolController.mjs';
6
3
  export { default as ToolEnabledGroup } from './ToolEnabledGroup.mjs';
@@ -11,7 +8,7 @@ export { default as PenTool } from './Pen.mjs';
11
8
  export { default as TextTool } from './TextTool.mjs';
12
9
  export { default as SelectionTool } from './SelectionTool/SelectionTool.mjs';
13
10
  export { default as SelectAllShortcutHandler } from './SelectionTool/SelectAllShortcutHandler.mjs';
14
- export { default as EraserTool } from './Eraser.mjs';
11
+ export { default as EraserTool, EraserMode } from './Eraser.mjs';
15
12
  export { default as PasteHandler } from './PasteHandler.mjs';
16
13
  export { default as SoundUITool } from './SoundUITool.mjs';
17
14
  export { default as ToolbarShortcutHandler } from './ToolbarShortcutHandler.mjs';
@@ -33,6 +33,8 @@ export declare abstract class ReactiveValue<T> {
33
33
  * @see {@link onUpdate}.
34
34
  */
35
35
  abstract onUpdateAndNow(callback: UpdateCallback<T>): ListenerResult;
36
+ /** Returns a promise that resolves when this value is next changed. */
37
+ waitForNextUpdate(): Promise<T>;
36
38
  /** Creates a `ReactiveValue` with an initial value, `initialValue`. */
37
39
  static fromInitialValue<T>(initialValue: T): MutableReactiveValue<T>;
38
40
  /** Returns a `ReactiveValue` that is **known** will never change. */
@@ -35,6 +35,15 @@ const noOpSetUpdateListener = () => {
35
35
  * Avoid extending this class from an external library, as that may not be stable.
36
36
  */
37
37
  export class ReactiveValue {
38
+ /** Returns a promise that resolves when this value is next changed. */
39
+ waitForNextUpdate() {
40
+ return new Promise(resolve => {
41
+ const listener = this.onUpdate(value => {
42
+ listener.remove();
43
+ resolve(value);
44
+ });
45
+ });
46
+ }
38
47
  /** Creates a `ReactiveValue` with an initial value, `initialValue`. */
39
48
  static fromInitialValue(initialValue) {
40
49
  return new ReactiveValueImpl(initialValue);
@@ -48,6 +57,8 @@ export class ReactiveValue {
48
57
  callback(value);
49
58
  return noOpUpdateListenerResult;
50
59
  },
60
+ // Never resolves -- immutable.
61
+ waitForNextUpdate: () => new Promise(() => { }),
51
62
  };
52
63
  }
53
64
  /**
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns a size in bytes, KiB, or MiB with units suffix.
3
+ */
4
+ declare const bytesToSizeString: (sizeBytes: number) => {
5
+ size: number;
6
+ units: string;
7
+ };
8
+ export default bytesToSizeString;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Returns a size in bytes, KiB, or MiB with units suffix.
3
+ */
4
+ const bytesToSizeString = (sizeBytes) => {
5
+ const sizeInKiB = sizeBytes / 1024;
6
+ const sizeInMiB = sizeInKiB / 1024;
7
+ const sizeInGiB = sizeInMiB / 1024;
8
+ let units = 'B';
9
+ let size = sizeBytes;
10
+ if (sizeInGiB >= 1) {
11
+ size = sizeInGiB;
12
+ units = 'GiB';
13
+ }
14
+ else if (sizeInMiB >= 1) {
15
+ size = sizeInMiB;
16
+ units = 'MiB';
17
+ }
18
+ else if (sizeInKiB >= 1) {
19
+ size = sizeInKiB;
20
+ units = 'KiB';
21
+ }
22
+ return { size, units };
23
+ };
24
+ export default bytesToSizeString;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,17 @@
1
1
  const stopPropagationOfScrollingWheelEvents = (scrollingContainer) => {
2
+ const scrollsAxis = (delta, clientSize, scrollOffset, scrollSize) => {
3
+ const hasScroll = clientSize !== scrollSize && delta !== 0;
4
+ const eventScrollsPastStart = scrollOffset + delta <= 0;
5
+ const scrollEnd = scrollOffset + clientSize;
6
+ const eventScrollsPastEnd = scrollEnd + delta > scrollSize;
7
+ return hasScroll && !eventScrollsPastStart && !eventScrollsPastEnd;
8
+ };
2
9
  scrollingContainer.onwheel = (event) => {
3
- const hasScroll = scrollingContainer.clientWidth !== scrollingContainer.scrollWidth
4
- && event.deltaX !== 0;
5
- const eventScrollsPastLeft = scrollingContainer.scrollLeft + event.deltaX <= 0;
6
- const scrollRight = scrollingContainer.scrollLeft + scrollingContainer.clientWidth;
7
- const eventScrollsPastRight = scrollRight + event.deltaX > scrollingContainer.scrollWidth;
10
+ const scrollsX = scrollsAxis(event.deltaX, scrollingContainer.clientWidth, scrollingContainer.scrollLeft, scrollingContainer.scrollWidth);
11
+ const scrollsY = scrollsAxis(event.deltaY, scrollingContainer.clientHeight, scrollingContainer.scrollTop, scrollingContainer.scrollHeight);
8
12
  // Stop the editor from receiving the event if it will scroll the pen type selector
9
13
  // instead.
10
- if (hasScroll && !eventScrollsPastLeft && !eventScrollsPastRight) {
14
+ if (scrollsX || scrollsY) {
11
15
  event.stopPropagation();
12
16
  }
13
17
  };
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Resolves when all given promises have resolved. If no promises are given,
3
3
  * does not return a Promise.
4
+ *
5
+ * If all elements of `results` are known to be `Promise`s, use `Promise.all`.
4
6
  */
5
7
  declare const waitForAll: (results: (Promise<void> | void)[]) => Promise<void> | void;
6
8
  export default waitForAll;
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Resolves when all given promises have resolved. If no promises are given,
3
3
  * does not return a Promise.
4
+ *
5
+ * If all elements of `results` are known to be `Promise`s, use `Promise.all`.
4
6
  */
5
7
  const waitForAll = (results) => {
6
8
  // If any are Promises...
@@ -2,7 +2,10 @@ const waitForImageLoad = async (image) => {
2
2
  if (!image.complete) {
3
3
  await new Promise((resolve, reject) => {
4
4
  image.onload = event => resolve(event);
5
+ // TODO(v2): Return a `new Error(event.message)`
6
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- Forwarding an error-like object.
5
7
  image.onerror = event => reject(event);
8
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- Forwarding an error-like object.
6
9
  image.onabort = event => reject(event);
7
10
  });
8
11
  }
@@ -1,2 +1,3 @@
1
+ /** Returns a promise that resolves after `timeout` milliseconds. */
1
2
  declare const waitForTimeout: (timeout: number) => Promise<void>;
2
3
  export default waitForTimeout;
@@ -1,4 +1,4 @@
1
- // Returns a promise that resolves after `timeout` milliseconds.
1
+ /** Returns a promise that resolves after `timeout` milliseconds. */
2
2
  const waitForTimeout = (timeout) => {
3
3
  return new Promise(resolve => {
4
4
  setTimeout(() => resolve(), timeout);
@@ -4,5 +4,5 @@
4
4
  * @internal
5
5
  */
6
6
  export default {
7
- number: '1.17.0',
7
+ number: '1.19.1',
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-draw",
3
- "version": "1.17.0",
3
+ "version": "1.19.1",
4
4
  "description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
5
5
  "types": "./dist/mjs/lib.d.ts",
6
6
  "main": "./dist/cjs/lib.js",
@@ -64,11 +64,11 @@
64
64
  "postpack": "ts-node tools/copyREADME.ts revert"
65
65
  },
66
66
  "dependencies": {
67
- "@js-draw/math": "^1.17.0",
67
+ "@js-draw/math": "^1.19.0",
68
68
  "@melloware/coloris": "0.22.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@js-draw/build-tool": "^1.17.0",
71
+ "@js-draw/build-tool": "^1.19.0",
72
72
  "@types/jest": "29.5.5",
73
73
  "@types/jsdom": "21.1.3"
74
74
  },
@@ -86,5 +86,5 @@
86
86
  "freehand",
87
87
  "svg"
88
88
  ],
89
- "gitHead": "d0eff585750ab5670af3acda8ddff090e8825bd3"
89
+ "gitHead": "50fa44a2bb68b93d24efea433760a5e45c56293f"
90
90
  }
@@ -1,10 +1,4 @@
1
- @use "./widgets/InsertImageWidget.scss";
2
- @use "./widgets/OverflowWidget.css";
3
- @use "./widgets/PenToolWidget.scss";
4
- @use "./widgets/HandToolWidget.scss";
5
- @use "./widgets/SelectionToolWidget.scss";
6
- @use "./widgets/DocumentPropertiesWidget.scss";
7
- @use "./widgets/components/components.scss";
1
+ @use "./widgets/widgets.scss";
8
2
 
9
3
  @use "./AbstractToolbar.scss";
10
4
  @use "./EdgeToolbar.scss";
@@ -11,8 +11,8 @@ $image-widget-selector: '.insert-image-widget-dropdown-content';
11
11
  }
12
12
 
13
13
  img {
14
- max-width: min(50vw, 75%);
15
- max-height: min(300px, 50vh);
14
+ max-width: 100%;
15
+ max-height: 100%;
16
16
 
17
17
  /* Center */
18
18
  display: block;
@@ -23,6 +23,7 @@ $image-widget-selector: '.insert-image-widget-dropdown-content';
23
23
  .insert-image-image-status-view {
24
24
  display: flex;
25
25
  justify-content: space-between;
26
+ padding-bottom: 0;
26
27
  }
27
28
 
28
29
  .action-button-row {
@@ -2,4 +2,5 @@
2
2
  @use "./makeColorInput.scss";
3
3
  @use "./makeSeparator.scss";
4
4
  @use "./makeFileInput.scss";
5
- @use "./makeGridSelector.scss";
5
+ @use "./makeGridSelector.scss";
6
+ @use "./makeSnappedList.scss";
@@ -2,7 +2,11 @@
2
2
  .toolbar-element .toolbar--file-input-container {
3
3
  display: flex;
4
4
 
5
- > input[type="file"] {
5
+ &.-loading {
6
+ opacity: 0.8;
7
+ }
8
+
9
+ > input.file-input {
6
10
  // Hide in a way such that screen readers can still access the
7
11
  // input.
8
12
  opacity: 0;
@@ -11,6 +15,11 @@
11
15
  min-width: 0 !important;
12
16
  max-width: 0;
13
17
  height: 0;
18
+
19
+ // Needed when the input is a button.
20
+ overflow: hidden;
21
+ padding: 0;
22
+ margin: 0;
14
23
  }
15
24
 
16
25
  > label {
@@ -28,6 +37,10 @@
28
37
  in srgb, var(--foreground-color-1), transparent
29
38
  );
30
39
 
40
+ > .cancel-button {
41
+ display: block;
42
+ }
43
+
31
44
  > .toolbar--file-input-description {
32
45
  background-color: var(--background-color-3);
33
46
  color: var(--foreground-color-3);
@@ -0,0 +1,28 @@
1
+
2
+ // Repeat for specificity.
3
+ // TODO(v2): Refactor everything to use RCSS.
4
+ :root .toolbar-snapped-scroll-list.toolbar-snapped-scroll-list.toolbar-snapped-scroll-list {
5
+ overflow-y: auto;
6
+ scroll-snap-type: y mandatory;
7
+ height: min(200px, 50vh);
8
+ display: flex;
9
+ flex-direction: column;
10
+
11
+ > .item {
12
+ height: 100%;
13
+ width: 100%;
14
+ flex-shrink: 0;
15
+
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+
20
+ scroll-snap-align: start;
21
+ scroll-snap-stop: always;
22
+ box-sizing: border-box;
23
+ }
24
+
25
+ &.-empty {
26
+ display: none;
27
+ }
28
+ }
@@ -0,0 +1,7 @@
1
+ @use "./InsertImageWidget/index.scss";
2
+ @use "./OverflowWidget.css";
3
+ @use "./PenToolWidget.scss";
4
+ @use "./HandToolWidget.scss";
5
+ @use "./SelectionToolWidget.scss";
6
+ @use "./DocumentPropertiesWidget.scss";
7
+ @use "./components/components.scss";
@@ -1,22 +0,0 @@
1
- import Editor from '../../Editor';
2
- import { ToolbarLocalization } from '../localization';
3
- import BaseWidget from './BaseWidget';
4
- export default class InsertImageWidget extends BaseWidget {
5
- private imagePreview;
6
- private image;
7
- private selectedFiles;
8
- private imageAltTextInput;
9
- private statusView;
10
- private submitButton;
11
- constructor(editor: Editor, localization?: ToolbarLocalization);
12
- protected getTitle(): string;
13
- protected createIcon(): Element | null;
14
- protected setDropdownVisible(visible: boolean): void;
15
- protected handleClick(): void;
16
- private static nextInputId;
17
- protected fillDropdown(dropdown: HTMLElement): boolean;
18
- private onImageDataUpdate;
19
- private hideDialog;
20
- private updateImageSizeDisplay;
21
- private updateInputs;
22
- }