js-draw 1.25.0 → 1.27.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. package/LICENSE +1 -1
  2. package/dist/Editor.css +1 -1935
  3. package/dist/bundle.js +478 -4
  4. package/dist/bundledStyles.js +1 -1
  5. package/dist/cjs/Editor.d.ts +0 -2
  6. package/dist/cjs/Editor.js +1 -1
  7. package/dist/cjs/bundle/bundled.js +2 -1
  8. package/dist/cjs/components/AbstractComponent.d.ts +15 -0
  9. package/dist/cjs/components/AbstractComponent.js +16 -0
  10. package/dist/cjs/components/Stroke.d.ts +1 -0
  11. package/dist/cjs/components/Stroke.js +7 -0
  12. package/dist/cjs/image/EditorImage.d.ts +2 -1
  13. package/dist/cjs/image/EditorImage.js +21 -6
  14. package/dist/cjs/toolbar/AbstractToolbar.js +9 -2
  15. package/dist/cjs/toolbar/IconProvider.d.ts +2 -1
  16. package/dist/cjs/toolbar/IconProvider.js +18 -8
  17. package/dist/cjs/toolbar/localization.d.ts +2 -0
  18. package/dist/cjs/toolbar/localization.js +2 -0
  19. package/dist/cjs/toolbar/widgets/BaseWidget.js +6 -1
  20. package/dist/cjs/toolbar/widgets/HandToolWidget.js +3 -3
  21. package/dist/cjs/toolbar/widgets/SelectionToolWidget.d.ts +7 -0
  22. package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +109 -28
  23. package/dist/cjs/toolbar/widgets/components/makeButtonGrid.d.ts +17 -0
  24. package/dist/cjs/toolbar/widgets/components/makeButtonGrid.js +40 -0
  25. package/dist/cjs/tools/SelectionTool/Selection.d.ts +2 -3
  26. package/dist/cjs/tools/SelectionTool/Selection.js +30 -46
  27. package/dist/cjs/tools/SelectionTool/SelectionBuilders/LassoSelectionBuilder.d.ts +17 -0
  28. package/dist/cjs/tools/SelectionTool/SelectionBuilders/LassoSelectionBuilder.js +67 -0
  29. package/dist/cjs/tools/SelectionTool/SelectionBuilders/RectSelectionBuilder.d.ts +13 -0
  30. package/dist/cjs/tools/SelectionTool/SelectionBuilders/RectSelectionBuilder.js +33 -0
  31. package/dist/cjs/tools/SelectionTool/SelectionBuilders/SelectionBuilder.d.ts +15 -0
  32. package/dist/cjs/tools/SelectionTool/SelectionBuilders/SelectionBuilder.js +39 -0
  33. package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.d.ts +3 -1
  34. package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +13 -4
  35. package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +10 -2
  36. package/dist/cjs/tools/SelectionTool/SelectionTool.js +68 -55
  37. package/dist/cjs/tools/SelectionTool/types.d.ts +4 -0
  38. package/dist/cjs/tools/SelectionTool/types.js +6 -1
  39. package/dist/cjs/tools/TextTool.js +5 -2
  40. package/dist/cjs/tools/lib.d.ts +1 -1
  41. package/dist/cjs/tools/lib.js +2 -1
  42. package/dist/cjs/util/ReactiveValue.js +2 -6
  43. package/dist/cjs/util/assertions.d.ts +7 -6
  44. package/dist/cjs/util/assertions.js +35 -29
  45. package/dist/cjs/version.js +1 -1
  46. package/dist/mjs/Editor.d.ts +0 -2
  47. package/dist/mjs/Editor.mjs +1 -1
  48. package/dist/mjs/bundle/bundled.mjs +2 -1
  49. package/dist/mjs/components/AbstractComponent.d.ts +15 -0
  50. package/dist/mjs/components/AbstractComponent.mjs +16 -0
  51. package/dist/mjs/components/Stroke.d.ts +1 -0
  52. package/dist/mjs/components/Stroke.mjs +7 -0
  53. package/dist/mjs/image/EditorImage.d.ts +2 -1
  54. package/dist/mjs/image/EditorImage.mjs +21 -6
  55. package/dist/mjs/toolbar/AbstractToolbar.mjs +9 -2
  56. package/dist/mjs/toolbar/IconProvider.d.ts +2 -1
  57. package/dist/mjs/toolbar/IconProvider.mjs +18 -8
  58. package/dist/mjs/toolbar/localization.d.ts +2 -0
  59. package/dist/mjs/toolbar/localization.mjs +2 -0
  60. package/dist/mjs/toolbar/widgets/BaseWidget.mjs +6 -1
  61. package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +3 -3
  62. package/dist/mjs/toolbar/widgets/SelectionToolWidget.d.ts +7 -0
  63. package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +109 -28
  64. package/dist/mjs/toolbar/widgets/components/makeButtonGrid.d.ts +17 -0
  65. package/dist/mjs/toolbar/widgets/components/makeButtonGrid.mjs +35 -0
  66. package/dist/mjs/tools/SelectionTool/Selection.d.ts +2 -3
  67. package/dist/mjs/tools/SelectionTool/Selection.mjs +30 -46
  68. package/dist/mjs/tools/SelectionTool/SelectionBuilders/LassoSelectionBuilder.d.ts +17 -0
  69. package/dist/mjs/tools/SelectionTool/SelectionBuilders/LassoSelectionBuilder.mjs +61 -0
  70. package/dist/mjs/tools/SelectionTool/SelectionBuilders/RectSelectionBuilder.d.ts +13 -0
  71. package/dist/mjs/tools/SelectionTool/SelectionBuilders/RectSelectionBuilder.mjs +27 -0
  72. package/dist/mjs/tools/SelectionTool/SelectionBuilders/SelectionBuilder.d.ts +15 -0
  73. package/dist/mjs/tools/SelectionTool/SelectionBuilders/SelectionBuilder.mjs +36 -0
  74. package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.d.ts +3 -1
  75. package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +13 -4
  76. package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +10 -2
  77. package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +68 -55
  78. package/dist/mjs/tools/SelectionTool/types.d.ts +4 -0
  79. package/dist/mjs/tools/SelectionTool/types.mjs +5 -0
  80. package/dist/mjs/tools/TextTool.mjs +5 -2
  81. package/dist/mjs/tools/lib.d.ts +1 -1
  82. package/dist/mjs/tools/lib.mjs +1 -1
  83. package/dist/mjs/util/ReactiveValue.mjs +2 -6
  84. package/dist/mjs/util/assertions.d.ts +7 -6
  85. package/dist/mjs/util/assertions.mjs +28 -24
  86. package/dist/mjs/version.mjs +1 -1
  87. package/package.json +4 -4
  88. package/src/toolbar/EdgeToolbar.scss +6 -1
  89. package/src/toolbar/widgets/components/components.scss +1 -0
  90. package/src/toolbar/widgets/components/makeButtonGrid.scss +25 -0
  91. package/src/tools/SelectionTool/SelectionTool.scss +12 -1
  92. package/src/tools/util/createMenuOverlay.scss +5 -3
@@ -1,5 +1,9 @@
1
1
  import type { Rect2, Point2 } from '@js-draw/math';
2
2
  import Pointer from '../../Pointer';
3
+ export declare enum SelectionMode {
4
+ Lasso = "lasso",
5
+ Rectangle = "rect"
6
+ }
3
7
  export declare enum ResizeMode {
4
8
  Both = 0,
5
9
  HorizontalOnly = 1,
@@ -1,3 +1,8 @@
1
+ export var SelectionMode;
2
+ (function (SelectionMode) {
3
+ SelectionMode["Lasso"] = "lasso";
4
+ SelectionMode["Rectangle"] = "rect";
5
+ })(SelectionMode || (SelectionMode = {}));
1
6
  export var ResizeMode;
2
7
  (function (ResizeMode) {
3
8
  ResizeMode[ResizeMode["Both"] = 0] = "Both";
@@ -158,12 +158,15 @@ export default class TextTool extends BaseTool {
158
158
  }
159
159
  };
160
160
  this.textInputElem.onblur = () => {
161
+ const input = this.textInputElem;
161
162
  // Delay removing the input -- flushInput may be called within a blur()
162
163
  // event handler
163
164
  const removeInput = false;
164
- const input = this.textInputElem;
165
165
  this.flushInput(removeInput);
166
166
  this.textInputElem = null;
167
+ if (input) {
168
+ input.classList.add('-hiding');
169
+ }
167
170
  setTimeout(() => {
168
171
  input?.remove();
169
172
  }, 0);
@@ -203,7 +206,7 @@ export default class TextTool extends BaseTool {
203
206
  if (allPointers.length === 1) {
204
207
  // Are we clicking on a text node?
205
208
  const canvasPos = current.canvasPos;
206
- const halfTestRegionSize = Vec2.of(2.5, 2.5).times(this.editor.viewport.getSizeOfPixelOnCanvas());
209
+ const halfTestRegionSize = Vec2.of(4, 4).times(this.editor.viewport.getSizeOfPixelOnCanvas());
207
210
  const testRegion = Rect2.fromCorners(canvasPos.minus(halfTestRegionSize), canvasPos.plus(halfTestRegionSize));
208
211
  const targetNodes = this.editor.image.getElementsIntersectingRegion(testRegion);
209
212
  let targetTextNodes = targetNodes.filter((node) => node instanceof TextComponent);
@@ -7,7 +7,7 @@ export { default as ToolSwitcherShortcut } from './ToolSwitcherShortcut';
7
7
  export { default as PanZoomTool, PanZoomMode } from './PanZoom';
8
8
  export { default as PenTool, PenStyle } from './Pen';
9
9
  export { default as TextTool } from './TextTool';
10
- export { default as SelectionTool } from './SelectionTool/SelectionTool';
10
+ export { default as SelectionTool, SelectionMode } from './SelectionTool/SelectionTool';
11
11
  export { default as SelectAllShortcutHandler } from './SelectionTool/SelectAllShortcutHandler';
12
12
  export { default as EraserTool, EraserMode } from './Eraser';
13
13
  export { default as PasteHandler } from './PasteHandler';
@@ -7,7 +7,7 @@ export { default as ToolSwitcherShortcut } from './ToolSwitcherShortcut.mjs';
7
7
  export { default as PanZoomTool, PanZoomMode } from './PanZoom.mjs';
8
8
  export { default as PenTool } from './Pen.mjs';
9
9
  export { default as TextTool } from './TextTool.mjs';
10
- export { default as SelectionTool } from './SelectionTool/SelectionTool.mjs';
10
+ export { default as SelectionTool, SelectionMode } from './SelectionTool/SelectionTool.mjs';
11
11
  export { default as SelectAllShortcutHandler } from './SelectionTool/SelectAllShortcutHandler.mjs';
12
12
  export { default as EraserTool, EraserMode } from './Eraser.mjs';
13
13
  export { default as PasteHandler } from './PasteHandler.mjs';
@@ -69,9 +69,7 @@ export class ReactiveValue {
69
69
  */
70
70
  static fromCallback(callback, sourceValues) {
71
71
  const result = new ReactiveValueImpl(callback());
72
- const resultRef = window.WeakRef
73
- ? new window.WeakRef(result)
74
- : { deref: () => result };
72
+ const resultRef = typeof WeakRef !== 'undefined' ? new WeakRef(result) : { deref: () => result };
75
73
  for (const value of sourceValues) {
76
74
  const listener = value.onUpdate(() => {
77
75
  // Use resultRef to allow `result` to be garbage collected
@@ -114,9 +112,7 @@ export class ReactiveValue {
114
112
  export class MutableReactiveValue extends ReactiveValue {
115
113
  static fromProperty(sourceValue, propertyName) {
116
114
  const child = ReactiveValue.fromInitialValue(sourceValue.get()[propertyName]);
117
- const childRef = window.WeakRef
118
- ? new window.WeakRef(child)
119
- : { deref: () => child };
115
+ const childRef = typeof WeakRef !== 'undefined' ? new WeakRef(child) : { deref: () => child };
120
116
  // When the source is updated...
121
117
  const sourceListener = sourceValue.onUpdate((newValue) => {
122
118
  const childValue = childRef.deref();
@@ -2,7 +2,7 @@
2
2
  * Compile-time assertion that a branch of code is unreachable.
3
3
  * @internal
4
4
  */
5
- export declare const assertUnreachable: (key: never) => never;
5
+ export declare function assertUnreachable(key: never): never;
6
6
  /**
7
7
  * Throws an exception if the typeof given value is not a number or `value` is NaN.
8
8
  *
@@ -13,15 +13,16 @@ export declare const assertUnreachable: (key: never) => never;
13
13
  *
14
14
  * assertIsNumber('hello, world'); // throws an Error.
15
15
  * ```
16
- *
17
- *
18
16
  */
19
- export declare const assertIsNumber: (value: any, allowNaN?: boolean) => value is number;
17
+ export declare function assertIsNumber(value: unknown, allowNaN?: boolean): asserts value is number;
18
+ export declare function assertIsArray(values: unknown): asserts values is unknown[];
20
19
  /**
21
20
  * Throws if any of `values` is not of type number.
22
21
  */
23
- export declare const assertIsNumberArray: (values: any[], allowNaN?: boolean) => values is number[];
22
+ export declare function assertIsNumberArray(values: unknown, allowNaN?: boolean): asserts values is number[];
24
23
  /**
25
24
  * Throws an exception if `typeof value` is not a boolean.
26
25
  */
27
- export declare const assertIsBoolean: (value: any) => value is boolean;
26
+ export declare function assertIsBoolean(value: unknown): asserts value is boolean;
27
+ export declare function assertTruthy<T>(value: T | null | undefined | false | 0): asserts value is T;
28
+ export declare function assertIsObject(value: unknown): asserts value is Record<string, unknown>;
@@ -1,11 +1,13 @@
1
+ // Note: Arrow functions cannot be used for type assertions. See
2
+ // https://github.com/microsoft/TypeScript/issues/34523
1
3
  /**
2
4
  * Compile-time assertion that a branch of code is unreachable.
3
5
  * @internal
4
6
  */
5
- export const assertUnreachable = (key) => {
7
+ export function assertUnreachable(key) {
6
8
  // See https://stackoverflow.com/a/39419171/17055750
7
9
  throw new Error(`Should be unreachable. Key: ${key}.`);
8
- };
10
+ }
9
11
  /**
10
12
  * Throws an exception if the typeof given value is not a number or `value` is NaN.
11
13
  *
@@ -16,40 +18,42 @@ export const assertUnreachable = (key) => {
16
18
  *
17
19
  * assertIsNumber('hello, world'); // throws an Error.
18
20
  * ```
19
- *
20
- *
21
21
  */
22
- export const assertIsNumber = (value, allowNaN = false) => {
22
+ export function assertIsNumber(value, allowNaN = false) {
23
23
  if (typeof value !== 'number' || (!allowNaN && isNaN(value))) {
24
24
  throw new Error('Given value is not a number');
25
- // return false;
26
25
  }
27
- return true;
28
- };
26
+ }
27
+ export function assertIsArray(values) {
28
+ if (!Array.isArray(values)) {
29
+ throw new Error('Asserting isArray: Given entity is not an array');
30
+ }
31
+ }
29
32
  /**
30
33
  * Throws if any of `values` is not of type number.
31
34
  */
32
- export const assertIsNumberArray = (values, allowNaN = false) => {
33
- if (typeof values !== 'object') {
34
- throw new Error('Asserting isNumberArray: Given entity is not an array');
35
- }
36
- if (!assertIsNumber(values['length'])) {
37
- return false;
38
- }
35
+ export function assertIsNumberArray(values, allowNaN = false) {
36
+ assertIsArray(values);
37
+ assertIsNumber(values.length);
39
38
  for (const value of values) {
40
- if (!assertIsNumber(value, allowNaN)) {
41
- return false;
42
- }
39
+ assertIsNumber(value, allowNaN);
43
40
  }
44
- return true;
45
- };
41
+ }
46
42
  /**
47
43
  * Throws an exception if `typeof value` is not a boolean.
48
44
  */
49
- export const assertIsBoolean = (value) => {
45
+ export function assertIsBoolean(value) {
50
46
  if (typeof value !== 'boolean') {
51
47
  throw new Error('Given value is not a boolean');
52
- // return false;
53
48
  }
54
- return true;
55
- };
49
+ }
50
+ export function assertTruthy(value) {
51
+ if (!value) {
52
+ throw new Error(`${JSON.stringify(value)} is not truthy`);
53
+ }
54
+ }
55
+ export function assertIsObject(value) {
56
+ if (typeof value !== 'object') {
57
+ throw new Error(`AssertIsObject: Given entity is not an object (type = ${typeof value})`);
58
+ }
59
+ }
@@ -4,5 +4,5 @@
4
4
  * @internal
5
5
  */
6
6
  export default {
7
- number: '1.25.0',
7
+ number: '1.27.1',
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-draw",
3
- "version": "1.25.0",
3
+ "version": "1.27.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.25.0",
67
+ "@js-draw/math": "^1.27.1",
68
68
  "@melloware/coloris": "0.22.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@js-draw/build-tool": "^1.25.0",
71
+ "@js-draw/build-tool": "^1.27.1",
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": "8ecc7be6d8b1b00c25fe7d3ed6c5fee239451dfa"
89
+ "gitHead": "e11574b7b329e7867358c400457a3d99b1d2c469"
90
90
  }
@@ -340,7 +340,7 @@
340
340
  transition: 0.2s ease box-shadow;
341
341
 
342
342
  &:not(:disabled):hover {
343
- box-shadow: 0 1px 2px var(--shadow-color);
343
+ box-shadow: 0 0px 2px var(--shadow-color);
344
344
  }
345
345
 
346
346
  &:disabled {
@@ -360,6 +360,11 @@
360
360
  @include labelVisibleOnHover.label-visible-on-hover('label > .button-label-text');
361
361
  }
362
362
 
363
+ .toolbar-button-grid button {
364
+ --button-label-hover-offset-y: 0;
365
+ @include labelVisibleOnHover.label-visible-on-hover('label');
366
+ }
367
+
363
368
  .toolbar-help-overlay-button {
364
369
  align-items: last baseline;
365
370
  }
@@ -4,3 +4,4 @@
4
4
  @use './makeFileInput.scss';
5
5
  @use './makeGridSelector.scss';
6
6
  @use './makeSnappedList.scss';
7
+ @use './makeButtonGrid.scss';
@@ -0,0 +1,25 @@
1
+ .toolbar-button-grid {
2
+ display: grid;
3
+ grid-template-columns: repeat(var(--column-count), 1fr);
4
+ justify-items: center;
5
+ --button-size: 30px;
6
+
7
+ > .button {
8
+ font-size: 1em;
9
+ width: min-content;
10
+
11
+ > .icon {
12
+ max-width: var(--button-size);
13
+ max-height: var(--button-size);
14
+
15
+ // Ensures that all icons have the same base size
16
+ width: 48px;
17
+ height: 48px;
18
+ }
19
+
20
+ > label {
21
+ display: block;
22
+ font-weight: normal;
23
+ }
24
+ }
25
+ }
@@ -85,12 +85,17 @@
85
85
  > button {
86
86
  max-height: var(--vertical-offset);
87
87
  background-color: var(--background-color-1);
88
+
89
+ width: 24px;
90
+ height: 24px;
91
+ padding: 6px;
88
92
  font-size: 14px;
93
+ user-select: none;
94
+ -webkit-user-select: none;
89
95
 
90
96
  color: var(--foreground-color-1);
91
97
  border: 0.5px solid var(--foreground-color-1);
92
98
  border-radius: 3px;
93
- padding: 3px;
94
99
  opacity: 0.8;
95
100
 
96
101
  &:hover,
@@ -102,6 +107,11 @@
102
107
  }
103
108
 
104
109
  transition: 0.2s ease opacity;
110
+
111
+ > .icon {
112
+ width: 100%;
113
+ height: 100%;
114
+ }
105
115
  }
106
116
  }
107
117
 
@@ -146,6 +156,7 @@
146
156
 
147
157
  &.-empty {
148
158
  opacity: 0;
159
+ display: none;
149
160
  }
150
161
 
151
162
  &.-hide-handles .selection-tool-handle {
@@ -31,7 +31,8 @@
31
31
 
32
32
  overflow: clip;
33
33
  border-radius: 6px;
34
- box-shadow: 0px 1px 2px var(--shadow-color);
34
+ box-shadow: 0px 0px 2px var(--shadow-color);
35
+ background-color: var(--background-color-1);
35
36
  }
36
37
 
37
38
  &::backdrop {
@@ -47,7 +48,7 @@
47
48
  padding-top: 6px;
48
49
  padding-bottom: 6px;
49
50
 
50
- background-color: var(--background-color-1);
51
+ background-color: transparent;
51
52
  color: var(--foreground-color-1);
52
53
  --icon-color: currentColor;
53
54
 
@@ -65,9 +66,10 @@
65
66
  width: 1em;
66
67
  height: 1em;
67
68
  flex-shrink: 0;
69
+ align-self: center;
68
70
 
69
71
  // RTL support:
70
72
  margin-inline-start: 0em;
71
- margin-inline-end: 0.25em;
73
+ margin-inline-end: 0.32em;
72
74
  }
73
75
  }