js-draw 0.18.2 → 0.19.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.
Files changed (227) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/bundle.js +2 -2
  3. package/dist/bundledStyles.js +1 -0
  4. package/dist/cjs/src/Color4.d.ts +8 -0
  5. package/dist/cjs/src/Color4.js +67 -0
  6. package/dist/cjs/src/Editor.d.ts +2 -2
  7. package/dist/cjs/src/Editor.js +2 -2
  8. package/dist/cjs/src/SVGLoader.js +8 -5
  9. package/dist/cjs/src/components/AbstractComponent.d.ts +2 -2
  10. package/dist/cjs/src/components/AbstractComponent.js +3 -3
  11. package/dist/cjs/src/components/ImageBackground.js +1 -1
  12. package/dist/cjs/src/components/RestylableComponent.d.ts +21 -2
  13. package/dist/cjs/src/components/Stroke.d.ts +35 -0
  14. package/dist/cjs/src/components/Stroke.js +36 -2
  15. package/dist/cjs/src/components/TextComponent.d.ts +26 -4
  16. package/dist/cjs/src/components/TextComponent.js +22 -0
  17. package/dist/cjs/src/components/lib.d.ts +3 -2
  18. package/dist/cjs/src/lib.d.ts +30 -0
  19. package/dist/cjs/src/lib.js +30 -0
  20. package/dist/cjs/src/rendering/RenderingStyle.d.ts +4 -4
  21. package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +10 -10
  22. package/dist/cjs/src/rendering/lib.d.ts +2 -0
  23. package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
  24. package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
  25. package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
  26. package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
  27. package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
  28. package/dist/cjs/src/toolbar/IconProvider.d.ts +2 -2
  29. package/dist/cjs/src/toolbar/localization.js +1 -1
  30. package/dist/cjs/src/toolbar/widgets/BaseWidget.js +1 -1
  31. package/dist/cjs/src/tools/SoundUITool.d.ts +24 -0
  32. package/dist/cjs/src/tools/SoundUITool.js +164 -0
  33. package/dist/cjs/src/tools/TextTool.d.ts +2 -2
  34. package/dist/cjs/src/tools/ToolController.js +6 -1
  35. package/dist/cjs/src/tools/lib.d.ts +1 -0
  36. package/dist/cjs/src/tools/lib.js +3 -1
  37. package/dist/cjs/src/tools/localization.d.ts +3 -0
  38. package/dist/cjs/src/tools/localization.js +3 -0
  39. package/dist/mjs/src/Color4.d.ts +8 -0
  40. package/dist/mjs/src/Color4.mjs +64 -0
  41. package/dist/mjs/src/Editor.d.ts +2 -2
  42. package/dist/mjs/src/Editor.mjs +2 -2
  43. package/dist/mjs/src/SVGLoader.mjs +8 -5
  44. package/dist/mjs/src/components/AbstractComponent.d.ts +2 -2
  45. package/dist/mjs/src/components/AbstractComponent.mjs +3 -3
  46. package/dist/mjs/src/components/ImageBackground.mjs +1 -1
  47. package/dist/mjs/src/components/RestylableComponent.d.ts +21 -2
  48. package/dist/mjs/src/components/Stroke.d.ts +35 -0
  49. package/dist/mjs/src/components/Stroke.mjs +36 -2
  50. package/dist/mjs/src/components/TextComponent.d.ts +26 -4
  51. package/dist/mjs/src/components/TextComponent.mjs +22 -0
  52. package/dist/mjs/src/components/lib.d.ts +3 -2
  53. package/dist/mjs/src/lib.d.ts +30 -0
  54. package/dist/mjs/src/lib.mjs +30 -0
  55. package/dist/mjs/src/rendering/RenderingStyle.d.ts +4 -4
  56. package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +10 -10
  57. package/dist/mjs/src/rendering/lib.d.ts +2 -0
  58. package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
  59. package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
  60. package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
  61. package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
  62. package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
  63. package/dist/mjs/src/toolbar/IconProvider.d.ts +2 -2
  64. package/dist/mjs/src/toolbar/localization.mjs +1 -1
  65. package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +1 -1
  66. package/dist/mjs/src/tools/SoundUITool.d.ts +24 -0
  67. package/dist/mjs/src/tools/SoundUITool.mjs +158 -0
  68. package/dist/mjs/src/tools/TextTool.d.ts +2 -2
  69. package/dist/mjs/src/tools/ToolController.mjs +6 -1
  70. package/dist/mjs/src/tools/lib.d.ts +1 -0
  71. package/dist/mjs/src/tools/lib.mjs +1 -0
  72. package/dist/mjs/src/tools/localization.d.ts +3 -0
  73. package/dist/mjs/src/tools/localization.mjs +3 -0
  74. package/package.json +6 -4
  75. package/src/Editor.css +2 -2
  76. package/src/tools/SoundUITool.css +15 -0
  77. package/src/tools/tools.css +4 -0
  78. package/src/Color4.test.ts +0 -40
  79. package/src/Color4.ts +0 -236
  80. package/src/Editor.loadFrom.test.ts +0 -24
  81. package/src/Editor.toSVG.test.ts +0 -111
  82. package/src/Editor.ts +0 -1122
  83. package/src/EditorImage.test.ts +0 -120
  84. package/src/EditorImage.ts +0 -603
  85. package/src/EventDispatcher.test.ts +0 -123
  86. package/src/EventDispatcher.ts +0 -71
  87. package/src/Pointer.ts +0 -127
  88. package/src/SVGLoader.test.ts +0 -114
  89. package/src/SVGLoader.ts +0 -511
  90. package/src/UndoRedoHistory.test.ts +0 -33
  91. package/src/UndoRedoHistory.ts +0 -102
  92. package/src/Viewport.ts +0 -319
  93. package/src/bundle/bundled.ts +0 -7
  94. package/src/commands/Command.ts +0 -45
  95. package/src/commands/Duplicate.ts +0 -48
  96. package/src/commands/Erase.ts +0 -74
  97. package/src/commands/SerializableCommand.ts +0 -49
  98. package/src/commands/UnresolvedCommand.ts +0 -37
  99. package/src/commands/invertCommand.ts +0 -51
  100. package/src/commands/lib.ts +0 -16
  101. package/src/commands/localization.ts +0 -47
  102. package/src/commands/uniteCommands.test.ts +0 -23
  103. package/src/commands/uniteCommands.ts +0 -135
  104. package/src/components/AbstractComponent.transformBy.test.ts +0 -22
  105. package/src/components/AbstractComponent.ts +0 -364
  106. package/src/components/ImageBackground.test.ts +0 -35
  107. package/src/components/ImageBackground.ts +0 -176
  108. package/src/components/ImageComponent.ts +0 -171
  109. package/src/components/RestylableComponent.ts +0 -142
  110. package/src/components/SVGGlobalAttributesObject.ts +0 -81
  111. package/src/components/Stroke.test.ts +0 -139
  112. package/src/components/Stroke.ts +0 -245
  113. package/src/components/TextComponent.test.ts +0 -99
  114. package/src/components/TextComponent.ts +0 -315
  115. package/src/components/UnknownSVGObject.test.ts +0 -10
  116. package/src/components/UnknownSVGObject.ts +0 -60
  117. package/src/components/builders/ArrowBuilder.ts +0 -107
  118. package/src/components/builders/FreehandLineBuilder.ts +0 -212
  119. package/src/components/builders/LineBuilder.ts +0 -77
  120. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
  121. package/src/components/builders/RectangleBuilder.ts +0 -74
  122. package/src/components/builders/types.ts +0 -15
  123. package/src/components/lib.ts +0 -25
  124. package/src/components/localization.ts +0 -22
  125. package/src/components/util/StrokeSmoother.ts +0 -293
  126. package/src/components/util/describeComponentList.ts +0 -18
  127. package/src/lib.ts +0 -37
  128. package/src/localization.ts +0 -34
  129. package/src/localizations/de.ts +0 -98
  130. package/src/localizations/en.ts +0 -8
  131. package/src/localizations/es.ts +0 -74
  132. package/src/localizations/getLocalizationTable.test.ts +0 -27
  133. package/src/localizations/getLocalizationTable.ts +0 -55
  134. package/src/math/LineSegment2.test.ts +0 -99
  135. package/src/math/LineSegment2.ts +0 -160
  136. package/src/math/Mat33.test.ts +0 -244
  137. package/src/math/Mat33.ts +0 -437
  138. package/src/math/Path.fromString.test.ts +0 -223
  139. package/src/math/Path.test.ts +0 -198
  140. package/src/math/Path.toString.test.ts +0 -77
  141. package/src/math/Path.ts +0 -790
  142. package/src/math/Rect2.test.ts +0 -204
  143. package/src/math/Rect2.ts +0 -315
  144. package/src/math/Triangle.ts +0 -29
  145. package/src/math/Vec2.test.ts +0 -30
  146. package/src/math/Vec2.ts +0 -18
  147. package/src/math/Vec3.test.ts +0 -44
  148. package/src/math/Vec3.ts +0 -218
  149. package/src/math/lib.ts +0 -15
  150. package/src/math/rounding.test.ts +0 -65
  151. package/src/math/rounding.ts +0 -156
  152. package/src/rendering/Display.ts +0 -249
  153. package/src/rendering/RenderingStyle.test.ts +0 -68
  154. package/src/rendering/RenderingStyle.ts +0 -55
  155. package/src/rendering/TextRenderingStyle.ts +0 -45
  156. package/src/rendering/caching/CacheRecord.test.ts +0 -49
  157. package/src/rendering/caching/CacheRecord.ts +0 -77
  158. package/src/rendering/caching/CacheRecordManager.ts +0 -71
  159. package/src/rendering/caching/RenderingCache.test.ts +0 -44
  160. package/src/rendering/caching/RenderingCache.ts +0 -66
  161. package/src/rendering/caching/RenderingCacheNode.ts +0 -405
  162. package/src/rendering/caching/testUtils.ts +0 -35
  163. package/src/rendering/caching/types.ts +0 -34
  164. package/src/rendering/lib.ts +0 -6
  165. package/src/rendering/localization.ts +0 -20
  166. package/src/rendering/renderers/AbstractRenderer.ts +0 -222
  167. package/src/rendering/renderers/CanvasRenderer.ts +0 -296
  168. package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
  169. package/src/rendering/renderers/DummyRenderer.ts +0 -136
  170. package/src/rendering/renderers/SVGRenderer.ts +0 -354
  171. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
  172. package/src/testing/beforeEachFile.ts +0 -8
  173. package/src/testing/createEditor.ts +0 -11
  174. package/src/testing/global.d.ts +0 -17
  175. package/src/testing/lib.ts +0 -3
  176. package/src/testing/loadExpectExtensions.ts +0 -25
  177. package/src/testing/sendPenEvent.ts +0 -31
  178. package/src/testing/sendTouchEvent.ts +0 -78
  179. package/src/toolbar/HTMLToolbar.ts +0 -492
  180. package/src/toolbar/IconProvider.ts +0 -736
  181. package/src/toolbar/lib.ts +0 -4
  182. package/src/toolbar/localization.ts +0 -106
  183. package/src/toolbar/makeColorInput.ts +0 -145
  184. package/src/toolbar/types.ts +0 -5
  185. package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
  186. package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
  187. package/src/toolbar/widgets/BaseWidget.ts +0 -377
  188. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
  189. package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
  190. package/src/toolbar/widgets/HandToolWidget.ts +0 -250
  191. package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
  192. package/src/toolbar/widgets/OverflowWidget.ts +0 -92
  193. package/src/toolbar/widgets/PenToolWidget.ts +0 -288
  194. package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
  195. package/src/toolbar/widgets/TextToolWidget.ts +0 -145
  196. package/src/toolbar/widgets/lib.ts +0 -13
  197. package/src/tools/BaseTool.ts +0 -76
  198. package/src/tools/Eraser.test.ts +0 -103
  199. package/src/tools/Eraser.ts +0 -139
  200. package/src/tools/FindTool.ts +0 -152
  201. package/src/tools/PanZoom.test.ts +0 -310
  202. package/src/tools/PanZoom.ts +0 -520
  203. package/src/tools/PasteHandler.ts +0 -95
  204. package/src/tools/Pen.test.ts +0 -194
  205. package/src/tools/Pen.ts +0 -226
  206. package/src/tools/PipetteTool.ts +0 -55
  207. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
  208. package/src/tools/SelectionTool/Selection.ts +0 -607
  209. package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
  210. package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
  211. package/src/tools/SelectionTool/SelectionTool.ts +0 -480
  212. package/src/tools/SelectionTool/TransformMode.ts +0 -114
  213. package/src/tools/SelectionTool/types.ts +0 -11
  214. package/src/tools/TextTool.ts +0 -326
  215. package/src/tools/ToolController.ts +0 -178
  216. package/src/tools/ToolEnabledGroup.ts +0 -14
  217. package/src/tools/ToolSwitcherShortcut.ts +0 -39
  218. package/src/tools/ToolbarShortcutHandler.ts +0 -34
  219. package/src/tools/UndoRedoShortcut.test.ts +0 -56
  220. package/src/tools/UndoRedoShortcut.ts +0 -25
  221. package/src/tools/lib.ts +0 -21
  222. package/src/tools/localization.ts +0 -66
  223. package/src/types.ts +0 -234
  224. package/src/util/assertions.ts +0 -55
  225. package/src/util/fileToBase64.ts +0 -18
  226. package/src/util/untilNextAnimationFrame.ts +0 -9
  227. package/src/util/waitForTimeout.ts +0 -9
@@ -0,0 +1,158 @@
1
+ import Color4 from '../Color4.mjs';
2
+ import LineSegment2 from '../math/LineSegment2.mjs';
3
+ import BaseTool from './BaseTool.mjs';
4
+ class SoundFeedback {
5
+ constructor() {
6
+ this.closed = false;
7
+ // No AudioContext? Exit!
8
+ if (!window.AudioContext) {
9
+ console.warn('Accessibility sound UI: Unable to open AudioContext.');
10
+ this.closed = true;
11
+ return;
12
+ }
13
+ this.ctx = new AudioContext();
14
+ // Color oscillator and gain
15
+ this.colorOscHue = this.ctx.createOscillator();
16
+ this.colorOscValue = this.ctx.createOscillator();
17
+ this.colorOscSaturation = this.ctx.createOscillator();
18
+ this.colorOscHue.type = 'triangle';
19
+ this.colorOscSaturation.type = 'sine';
20
+ this.colorOscValue.type = 'sawtooth';
21
+ this.valueGain = this.ctx.createGain();
22
+ this.colorOscValue.connect(this.valueGain);
23
+ this.valueGain.gain.setValueAtTime(0.18, this.ctx.currentTime);
24
+ this.colorGain = this.ctx.createGain();
25
+ this.colorOscHue.connect(this.colorGain);
26
+ this.valueGain.connect(this.colorGain);
27
+ this.colorOscSaturation.connect(this.colorGain);
28
+ this.colorGain.connect(this.ctx.destination);
29
+ // Boundary oscillator and gain
30
+ this.boundaryGain = this.ctx.createGain();
31
+ this.boundaryOsc = this.ctx.createOscillator();
32
+ this.boundaryOsc.type = 'sawtooth';
33
+ this.boundaryGain.gain.setValueAtTime(0, this.ctx.currentTime);
34
+ this.boundaryOsc.connect(this.boundaryGain);
35
+ this.boundaryGain.connect(this.ctx.destination);
36
+ // Prepare for the first announcement/feedback.
37
+ this.colorOscHue.start();
38
+ this.colorOscSaturation.start();
39
+ this.colorOscValue.start();
40
+ this.boundaryOsc.start();
41
+ this.pause();
42
+ }
43
+ pause() {
44
+ if (this.closed)
45
+ return;
46
+ this.colorGain.gain.setValueAtTime(0, this.ctx.currentTime);
47
+ void this.ctx.suspend();
48
+ }
49
+ play() {
50
+ if (this.closed)
51
+ return;
52
+ void this.ctx.resume();
53
+ }
54
+ setColor(color) {
55
+ const hsv = color.asHSV();
56
+ // Choose frequencies that roughly correspond to hue, saturation, and value.
57
+ const hueFrequency = (-Math.cos(hsv.x / 2)) * 220 + 440;
58
+ const saturationFrequency = hsv.y * 440 + 220;
59
+ const valueFrequency = (hsv.z + 0.1) * 440;
60
+ // Sigmoid with maximum 0.25 * alpha.
61
+ // Louder for greater value.
62
+ const gain = 0.25 * Math.min(1, color.a) / (1 + Math.exp(-(hsv.z - 0.5) * 3));
63
+ this.colorOscHue.frequency.setValueAtTime(hueFrequency, this.ctx.currentTime);
64
+ this.colorOscSaturation.frequency.setValueAtTime(saturationFrequency, this.ctx.currentTime);
65
+ this.colorOscValue.frequency.setValueAtTime(valueFrequency, this.ctx.currentTime);
66
+ this.valueGain.gain.setValueAtTime((1 - hsv.z) * 0.4, this.ctx.currentTime);
67
+ this.colorGain.gain.setValueAtTime(gain, this.ctx.currentTime);
68
+ }
69
+ announceBoundaryCross(boundaryCrossCount) {
70
+ this.boundaryGain.gain.cancelScheduledValues(this.ctx.currentTime);
71
+ this.boundaryGain.gain.setValueAtTime(0, this.ctx.currentTime);
72
+ this.boundaryGain.gain.linearRampToValueAtTime(0.01, this.ctx.currentTime + 0.1);
73
+ this.boundaryOsc.frequency.setValueAtTime(440 + Math.atan(boundaryCrossCount / 2) * 100, this.ctx.currentTime);
74
+ this.boundaryGain.gain.linearRampToValueAtTime(0, this.ctx.currentTime + 0.25);
75
+ }
76
+ close() {
77
+ this.ctx.close();
78
+ this.closed = true;
79
+ }
80
+ }
81
+ /**
82
+ * This tool, when enabled, plays a sound representing the color of the portion of the display
83
+ * currently under the cursor. This tool adds a button that can be navigated to with the tab key
84
+ * that enables/disables the tool.
85
+ *
86
+ * This allows the user to explore the content of the display without a working screen.
87
+ */
88
+ export default class SoundUITool extends BaseTool {
89
+ constructor(editor, description) {
90
+ super(editor.notifier, description);
91
+ this.editor = editor;
92
+ this.soundFeedback = null;
93
+ // Create a screen-reader-usable method of toggling the tool:
94
+ this.toggleButtonContainer = document.createElement('div');
95
+ this.toggleButtonContainer.classList.add('js-draw-sound-ui-toggle');
96
+ this.toggleButton = document.createElement('button');
97
+ this.toggleButton.onclick = () => {
98
+ this.setEnabled(!this.isEnabled());
99
+ };
100
+ this.toggleButtonContainer.appendChild(this.toggleButton);
101
+ this.updateToggleButtonText();
102
+ editor.createHTMLOverlay(this.toggleButtonContainer);
103
+ }
104
+ updateToggleButtonText() {
105
+ const containerEnabledClass = 'sound-ui-tool-enabled';
106
+ if (this.isEnabled()) {
107
+ this.toggleButton.innerText = this.editor.localization.disableAccessibilityExploreTool;
108
+ this.toggleButtonContainer.classList.add(containerEnabledClass);
109
+ }
110
+ else {
111
+ this.toggleButton.innerText = this.editor.localization.enableAccessibilityExploreTool;
112
+ this.toggleButtonContainer.classList.remove(containerEnabledClass);
113
+ }
114
+ }
115
+ setEnabled(enabled) {
116
+ var _a;
117
+ super.setEnabled(enabled);
118
+ if (!enabled) {
119
+ (_a = this.soundFeedback) === null || _a === void 0 ? void 0 : _a.close();
120
+ this.soundFeedback = null;
121
+ }
122
+ this.updateToggleButtonText();
123
+ }
124
+ onPointerDown({ current, allPointers }) {
125
+ var _a, _b, _c;
126
+ if (!this.soundFeedback) {
127
+ this.soundFeedback = new SoundFeedback();
128
+ }
129
+ // Allow two-finger gestures to move the screen.
130
+ if (allPointers.length >= 2) {
131
+ return false;
132
+ }
133
+ // Accept multiple cursors -- some screen readers require multiple (touch) pointers to interact with
134
+ // an image instead of using the built-in navigation features.
135
+ (_a = this.soundFeedback) === null || _a === void 0 ? void 0 : _a.play();
136
+ (_b = this.soundFeedback) === null || _b === void 0 ? void 0 : _b.setColor((_c = this.editor.display.getColorAt(current.screenPos)) !== null && _c !== void 0 ? _c : Color4.black);
137
+ this.lastPointerPos = current.canvasPos;
138
+ return true;
139
+ }
140
+ onPointerMove({ current }) {
141
+ var _a, _b, _c;
142
+ (_a = this.soundFeedback) === null || _a === void 0 ? void 0 : _a.setColor((_b = this.editor.display.getColorAt(current.screenPos)) !== null && _b !== void 0 ? _b : Color4.black);
143
+ const pointerMotionLine = new LineSegment2(this.lastPointerPos, current.canvasPos);
144
+ const collisions = this.editor.image.getElementsIntersectingRegion(pointerMotionLine.bbox).filter(component => component.intersects(pointerMotionLine));
145
+ this.lastPointerPos = current.canvasPos;
146
+ if (collisions.length > 0) {
147
+ (_c = this.soundFeedback) === null || _c === void 0 ? void 0 : _c.announceBoundaryCross(collisions.length);
148
+ }
149
+ }
150
+ onPointerUp(_event) {
151
+ var _a;
152
+ (_a = this.soundFeedback) === null || _a === void 0 ? void 0 : _a.pause();
153
+ }
154
+ onGestureCancel() {
155
+ var _a;
156
+ (_a = this.soundFeedback) === null || _a === void 0 ? void 0 : _a.pause();
157
+ }
158
+ }
@@ -3,7 +3,7 @@ import Editor from '../Editor';
3
3
  import { PointerEvt } from '../types';
4
4
  import BaseTool from './BaseTool';
5
5
  import { ToolLocalization } from './localization';
6
- import TextStyle from '../rendering/TextRenderingStyle';
6
+ import TextRenderingStyle from '../rendering/TextRenderingStyle';
7
7
  export default class TextTool extends BaseTool {
8
8
  private editor;
9
9
  private localizationTable;
@@ -28,6 +28,6 @@ export default class TextTool extends BaseTool {
28
28
  setFontFamily(fontFamily: string): void;
29
29
  setColor(color: Color4): void;
30
30
  setFontSize(size: number): void;
31
- getTextStyle(): TextStyle;
31
+ getTextStyle(): TextRenderingStyle;
32
32
  private setTextStyle;
33
33
  }
@@ -14,6 +14,7 @@ import ToolbarShortcutHandler from './ToolbarShortcutHandler.mjs';
14
14
  import { makePressureSensitiveFreehandLineBuilder } from '../components/builders/PressureSensitiveFreehandLineBuilder.mjs';
15
15
  import FindTool from './FindTool.mjs';
16
16
  import SelectAllShortcutHandler from './SelectionTool/SelectAllShortcutHandler.mjs';
17
+ import SoundUITool from './SoundUITool.mjs';
17
18
  export default class ToolController {
18
19
  /** @internal */
19
20
  constructor(editor, localization) {
@@ -32,10 +33,14 @@ export default class ToolController {
32
33
  new Eraser(editor, localization.eraserTool),
33
34
  new SelectionTool(editor, localization.selectionTool),
34
35
  new TextTool(editor, localization.textTool, localization),
35
- new PanZoom(editor, PanZoomMode.SinglePointerGestures, localization.anyDevicePanning)
36
+ new PanZoom(editor, PanZoomMode.SinglePointerGestures, localization.anyDevicePanning),
36
37
  ];
38
+ // Accessibility tools
39
+ const soundExplorer = new SoundUITool(editor, localization.soundExplorer);
40
+ soundExplorer.setEnabled(false);
37
41
  this.tools = [
38
42
  new PipetteTool(editor, localization.pipetteTool),
43
+ soundExplorer,
39
44
  panZoomTool,
40
45
  ...primaryTools,
41
46
  keyboardPanZoomTool,
@@ -13,4 +13,5 @@ export { default as SelectionTool } from './SelectionTool/SelectionTool';
13
13
  export { default as SelectAllShortcutHandler } from './SelectionTool/SelectAllShortcutHandler';
14
14
  export { default as EraserTool } from './Eraser';
15
15
  export { default as PasteHandler } from './PasteHandler';
16
+ export { default as SoundUITool } from './SoundUITool';
16
17
  export { default as ToolbarShortcutHandler } from './ToolbarShortcutHandler';
@@ -13,4 +13,5 @@ export { default as SelectionTool } from './SelectionTool/SelectionTool.mjs';
13
13
  export { default as SelectAllShortcutHandler } from './SelectionTool/SelectAllShortcutHandler.mjs';
14
14
  export { default as EraserTool } from './Eraser.mjs';
15
15
  export { default as PasteHandler } from './PasteHandler.mjs';
16
+ export { default as SoundUITool } from './SoundUITool.mjs';
16
17
  export { default as ToolbarShortcutHandler } from './ToolbarShortcutHandler.mjs';
@@ -13,6 +13,9 @@ export interface ToolLocalization {
13
13
  enterTextToInsert: string;
14
14
  changeTool: string;
15
15
  pasteHandler: string;
16
+ soundExplorer: string;
17
+ disableAccessibilityExploreTool: string;
18
+ enableAccessibilityExploreTool: string;
16
19
  findLabel: string;
17
20
  toNextMatch: string;
18
21
  closeFindDialog: string;
@@ -13,6 +13,9 @@ export const defaultToolLocalization = {
13
13
  enterTextToInsert: 'Text to insert',
14
14
  changeTool: 'Change tool',
15
15
  pasteHandler: 'Copy paste handler',
16
+ soundExplorer: 'Sound-based image exploration',
17
+ disableAccessibilityExploreTool: 'Disable sound-based exploration',
18
+ enableAccessibilityExploreTool: 'Enable sound-based exploration',
16
19
  findLabel: 'Find',
17
20
  toNextMatch: 'Next',
18
21
  closeFindDialog: 'Close',
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "js-draw",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
5
- "types": "./dist/cjs/src/lib.d.ts",
5
+ "types": "./dist/mjs/src/lib.d.ts",
6
6
  "main": "./dist/cjs/src/lib.js",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./dist/cjs/src/lib.d.ts",
9
+ "types": "./dist/mjs/src/lib.d.ts",
10
10
  "import": "./dist/mjs/src/lib.mjs",
11
11
  "require": "./dist/cjs/src/lib.js"
12
12
  },
@@ -20,6 +20,9 @@
20
20
  "types": "./dist/mjs/src/bundle/bundled.d.ts",
21
21
  "default": "./dist/bundle.js"
22
22
  },
23
+ "./bundledStyles": {
24
+ "default": "./dist/bundledStyles.js"
25
+ },
23
26
  "./Editor": {
24
27
  "types": "./dist/mjs/src/Editor.d.ts",
25
28
  "default": "./dist/mjs/src/Editor.mjs"
@@ -79,7 +82,6 @@
79
82
  "postpack": "pinst --enable"
80
83
  },
81
84
  "dependencies": {
82
- "@babel/runtime": "^7.21.0",
83
85
  "@melloware/coloris": "^0.18.0",
84
86
  "bezier-js": "^6.1.3"
85
87
  },
package/src/Editor.css CHANGED
@@ -1,7 +1,6 @@
1
1
 
2
2
  @import url('./toolbar/toolbar.css');
3
- @import url('./tools/SelectionTool/SelectionTool.css');
4
- @import url('./tools/FindTool.css');
3
+ @import url('./tools/tools.css');
5
4
 
6
5
  .imageEditorContainer {
7
6
  /* Deafult colors for the editor */
@@ -83,4 +82,5 @@
83
82
 
84
83
  .imageEditorContainer .textRendererOutputContainer:focus-within {
85
84
  overflow: visible;
85
+ z-index: 5;
86
86
  }
@@ -0,0 +1,15 @@
1
+
2
+ .js-draw-sound-ui-toggle {
3
+ width: 0px;
4
+ height: 0px;
5
+ overflow: hidden;
6
+ }
7
+
8
+ .js-draw-sound-ui-toggle:focus-within, .js-draw-sound-ui-toggle.sound-ui-tool-enabled {
9
+ overflow: visible;
10
+ z-index: 5;
11
+ }
12
+
13
+ .js-draw-sound-ui-toggle:not(:focus-within):not(:hover).sound-ui-tool-enabled {
14
+ opacity: 0.5;
15
+ }
@@ -0,0 +1,4 @@
1
+
2
+ @import url(./SelectionTool/SelectionTool.css);
3
+ @import url(./FindTool.css);
4
+ @import url(./SoundUITool.css);
@@ -1,40 +0,0 @@
1
- import Color4 from './Color4';
2
-
3
- describe('Color4', () => {
4
- it('should convert to #RRGGBB-format hex strings (when no alpha)', () => {
5
- expect(Color4.black.toHexString()).toBe('#000000');
6
- expect(Color4.fromHex('#f0f').toHexString()).toBe('#f000f0');
7
- });
8
-
9
- it('should create #RRGGBBAA-format hex strings when there is an alpha component', () => {
10
- expect(Color4.ofRGBA(1, 1, 1, 0.5).toHexString()).toBe('#ffffff80');
11
- });
12
-
13
- it('should parse rgb and rgba-format strings', () => {
14
- expect(Color4.fromString('rgb(0, 0, 0)')).objEq(Color4.black);
15
- expect(Color4.fromString('rgb ( 255, 0,\t 0)')).objEq(Color4.ofRGBA(1, 0, 0, 1));
16
- expect(Color4.fromString('rgba ( 255, 0,\t 0, 0.5)')).objEq(Color4.ofRGBA(1, 0, 0, 0.5));
17
- expect(Color4.fromString('rgba( 0, 0, 128, 0)')).objEq(Color4.ofRGBA(0, 0, 128/255, 0));
18
- });
19
-
20
- it('should mix blue and red to get dark purple', () => {
21
- expect(Color4.ofRGB(1, 0, 0).mix(Color4.ofRGB(0, 0, 1), 0.5)).objEq(Color4.ofRGB(0.5, 0, 0.5));
22
- expect(Color4.ofRGB(1, 0, 0).mix(Color4.ofRGB(0, 0, 1), 0.1)).objEq(Color4.ofRGB(0.9, 0, 0.1));
23
- });
24
-
25
- it('should mix red and green to get yellow', () => {
26
- expect(Color4.ofRGB(1, 0, 0).mix(Color4.ofRGB(0, 1, 0), 0.3)).objEq(
27
- Color4.ofRGB(0.7, 0.3, 0)
28
- );
29
- });
30
-
31
- it('should mix red with nothing and get red', () => {
32
- expect(Color4.average([ Color4.red ])).objEq(Color4.red);
33
- });
34
-
35
- it('different colors should be different', () => {
36
- expect(Color4.red.eq(Color4.red)).toBe(true);
37
- expect(Color4.red.eq(Color4.green)).toBe(false);
38
- expect(Color4.fromString('#ff000000').eq(Color4.transparent)).toBe(true);
39
- });
40
- });
package/src/Color4.ts DELETED
@@ -1,236 +0,0 @@
1
-
2
- export default class Color4 {
3
- private constructor(
4
- /** Red component. Should be in the range [0, 1]. */
5
- public readonly r: number,
6
-
7
- /** Green component. `g` ∈ [0, 1] */
8
- public readonly g: number,
9
-
10
- /** Blue component. `b` ∈ [0, 1] */
11
- public readonly b: number,
12
-
13
- /** Alpha/transparent component. `a` ∈ [0, 1]. 0 = transparent */
14
- public readonly a: number
15
- ) {
16
- }
17
-
18
- /**
19
- * Create a color from red, green, blue components. The color is fully opaque (`a = 1.0`).
20
- *
21
- * Each component should be in the range [0, 1].
22
- */
23
- public static ofRGB(red: number, green: number, blue: number): Color4 {
24
- return Color4.ofRGBA(red, green, blue, 1.0);
25
- }
26
-
27
- public static ofRGBA(red: number, green: number, blue: number, alpha: number): Color4 {
28
- red = Math.max(0, Math.min(red, 1));
29
- green = Math.max(0, Math.min(green, 1));
30
- blue = Math.max(0, Math.min(blue, 1));
31
- alpha = Math.max(0, Math.min(alpha, 1));
32
-
33
- return new Color4(red, green, blue, alpha);
34
- }
35
-
36
- public static fromHex(hexString: string): Color4 {
37
- // Remove starting '#' (if present)
38
- hexString = (hexString.match(/^[#]?(.*)$/) ?? [])[1];
39
- hexString = hexString.toUpperCase();
40
-
41
- if (!hexString.match(/^[0-9A-F]+$/)) {
42
- throw new Error(`${hexString} is not in a valid format.`);
43
- }
44
-
45
- // RGBA or RGB
46
- if (hexString.length === 3 || hexString.length === 4) {
47
- // Each character is a component
48
- const components = hexString.split('');
49
-
50
- // Convert to RRGGBBAA or RRGGBB format
51
- hexString = components.map(component => `${component}0`).join('');
52
- }
53
-
54
- if (hexString.length === 6) {
55
- // Alpha component
56
- hexString += 'FF';
57
- }
58
-
59
- const components: number[] = [];
60
- for (let i = 2; i <= hexString.length; i += 2) {
61
- const chunk = hexString.substring(i - 2, i);
62
- components.push(parseInt(chunk, 16) / 255);
63
- }
64
-
65
- if (components.length !== 4) {
66
- throw new Error(`Unable to parse ${hexString}: Wrong number of components.`);
67
- }
68
-
69
- return Color4.ofRGBA(components[0], components[1], components[2], components[3]);
70
- }
71
-
72
- /** Like fromHex, but can handle additional colors if an `HTMLCanvasElement` is available. */
73
- public static fromString(text: string): Color4 {
74
- if (text.startsWith('#')) {
75
- return Color4.fromHex(text);
76
- }
77
-
78
- if (text === 'none' || text === 'transparent') {
79
- return Color4.transparent;
80
- }
81
-
82
- // rgba?: Match both rgb and rgba strings.
83
- // ([,0-9.]+): Match any string of only numeric, '.' and ',' characters.
84
- const rgbRegex = /^rgba?\(([,0-9.]+)\)$/i;
85
- const rgbMatch = text.replace(/\s*/g, '').match(rgbRegex);
86
-
87
- if (rgbMatch) {
88
- const componentsListStr = rgbMatch[1];
89
- const componentsList = JSON.parse(`[ ${componentsListStr} ]`);
90
-
91
- if (componentsList.length === 3) {
92
- return Color4.ofRGB(
93
- componentsList[0] / 255, componentsList[1] / 255, componentsList[2] / 255
94
- );
95
- } else if (componentsList.length === 4) {
96
- return Color4.ofRGBA(
97
- componentsList[0] / 255, componentsList[1] / 255, componentsList[2] / 255, componentsList[3]
98
- );
99
- } else {
100
- throw new Error(`RGB string, ${text}, has wrong number of components: ${componentsList.length}`);
101
- }
102
- }
103
-
104
- // Otherwise, try to use an HTMLCanvasElement to determine the color.
105
- // Note: We may be unable to create an HTMLCanvasElement if running as a unit test.
106
- const canvas = document.createElement('canvas');
107
- canvas.width = 1;
108
- canvas.height = 1;
109
-
110
- const ctx = canvas.getContext('2d')!;
111
- ctx.fillStyle = text;
112
- ctx.fillRect(0, 0, 1, 1);
113
-
114
- const data = ctx.getImageData(0, 0, 1, 1);
115
- const red = data.data[0] / 255;
116
- const green = data.data[1] / 255;
117
- const blue = data.data[2] / 255;
118
- const alpha = data.data[3] / 255;
119
-
120
- return Color4.ofRGBA(red, green, blue, alpha);
121
- }
122
-
123
- /** @returns true if `this` and `other` are approximately equal. */
124
- public eq(other: Color4|null|undefined): boolean {
125
- if (other == null) {
126
- return false;
127
- }
128
-
129
- // If both completely transparent,
130
- if (this.a === 0 && other.a === 0) {
131
- return true;
132
- }
133
-
134
- return this.toHexString() === other.toHexString();
135
- }
136
-
137
- /**
138
- * If `fractionTo` is not in the range [0, 1], it will be clamped to the nearest number
139
- * in that range. For example, `a.mix(b, -1)` is equivalent to `a.mix(b, 0)`.
140
- *
141
- * @returns a color `fractionTo` of the way from this color to `other`.
142
- *
143
- * @example
144
- * ```ts
145
- * Color4.ofRGB(1, 0, 0).mix(Color4.ofRGB(0, 1, 0), 0.1) // -> Color4(0.9, 0.1, 0)
146
- * ```
147
- */
148
- public mix(other: Color4, fractionTo: number): Color4 {
149
- fractionTo = Math.min(Math.max(fractionTo, 0), 1);
150
- const fractionOfThis = 1 - fractionTo;
151
- return new Color4(
152
- this.r * fractionOfThis + other.r * fractionTo,
153
- this.g * fractionOfThis + other.g * fractionTo,
154
- this.b * fractionOfThis + other.b * fractionTo,
155
- this.a * fractionOfThis + other.a * fractionTo,
156
- );
157
- }
158
-
159
- /**
160
- * @returns the component-wise average of `colors`, or `Color4.transparent` if `colors` is empty.
161
- */
162
- public static average(colors: Color4[]) {
163
- let averageA = 0;
164
- let averageR = 0;
165
- let averageG = 0;
166
- let averageB = 0;
167
-
168
- for (const color of colors) {
169
- averageA += color.a;
170
- averageR += color.r;
171
- averageG += color.g;
172
- averageB += color.b;
173
- }
174
-
175
- if (colors.length > 0) {
176
- averageA /= colors.length;
177
- averageR /= colors.length;
178
- averageG /= colors.length;
179
- averageB /= colors.length;
180
- }
181
-
182
- return new Color4(averageR, averageG, averageB, averageA);
183
- }
184
-
185
- private hexString: string|null = null;
186
-
187
- /**
188
- * @returns a hexadecimal color string representation of `this`, in the form `#rrggbbaa`.
189
- *
190
- * @example
191
- * ```
192
- * Color4.red.toHexString(); // -> #ff0000ff
193
- * ```
194
- */
195
- public toHexString(): string {
196
- if (this.hexString) {
197
- return this.hexString;
198
- }
199
-
200
- const componentToHex = (component: number): string => {
201
- const res = Math.round(255 * component).toString(16);
202
-
203
- if (res.length === 1) {
204
- return `0${res}`;
205
- }
206
- return res;
207
- };
208
-
209
- const alpha = componentToHex(this.a);
210
- const red = componentToHex(this.r);
211
- const green = componentToHex(this.g);
212
- const blue = componentToHex(this.b);
213
- if (alpha === 'ff') {
214
- return `#${red}${green}${blue}`;
215
- }
216
- this.hexString = `#${red}${green}${blue}${alpha}`;
217
- return this.hexString;
218
- }
219
-
220
- public toString() {
221
- return this.toHexString();
222
- }
223
-
224
- public static transparent = Color4.ofRGBA(0, 0, 0, 0);
225
- public static red = Color4.ofRGB(1.0, 0.0, 0.0);
226
- public static green = Color4.ofRGB(0.0, 1.0, 0.0);
227
- public static blue = Color4.ofRGB(0.0, 0.0, 1.0);
228
- public static purple = Color4.ofRGB(0.5, 0.2, 0.5);
229
- public static yellow = Color4.ofRGB(1, 1, 0.1);
230
- public static clay = Color4.ofRGB(0.8, 0.4, 0.2);
231
- public static black = Color4.ofRGB(0, 0, 0);
232
- public static gray = Color4.ofRGB(0.5, 0.5, 0.5);
233
- public static white = Color4.ofRGB(1, 1, 1);
234
- }
235
-
236
- export { Color4 };
@@ -1,24 +0,0 @@
1
- import Color4 from './Color4';
2
- import { imageBackgroundCSSClassName } from './components/ImageBackground';
3
- import { RestyleableComponent } from './lib';
4
- import SVGLoader from './SVGLoader';
5
- import createEditor from './testing/createEditor';
6
-
7
- describe('Editor.loadFrom', () => {
8
- it('should remove existing BackgroundComponents when loading new BackgroundComponents', async () => {
9
- const editor = createEditor();
10
- await editor.dispatch(editor.setBackgroundColor(Color4.red));
11
-
12
- let backgroundComponents = editor.image.getBackgroundComponents();
13
- expect(backgroundComponents).toHaveLength(1);
14
- expect((backgroundComponents[0] as RestyleableComponent).getStyle().color).objEq(Color4.red);
15
-
16
- await editor.loadFrom(SVGLoader.fromString(`<svg viewBox='0 0 100 100'>
17
- <path class='${imageBackgroundCSSClassName}' d='m0,0 L100,0 L100,100 L0,100 z' fill='#000'/>
18
- </svg>`, true));
19
-
20
- backgroundComponents = editor.image.getBackgroundComponents();
21
- expect(backgroundComponents).toHaveLength(1);
22
- expect((backgroundComponents[0] as RestyleableComponent).getStyle().color).objEq(Color4.black);
23
- });
24
- });