js-draw 0.15.2 → 0.16.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 (59) hide show
  1. package/.github/ISSUE_TEMPLATE/translation.yml +56 -0
  2. package/CHANGELOG.md +6 -0
  3. package/dist/bundle.js +1 -1
  4. package/dist/src/Editor.d.ts +11 -0
  5. package/dist/src/Editor.js +52 -4
  6. package/dist/src/EditorImage.d.ts +11 -11
  7. package/dist/src/EditorImage.js +54 -18
  8. package/dist/src/Viewport.d.ts +5 -0
  9. package/dist/src/Viewport.js +11 -0
  10. package/dist/src/components/AbstractComponent.d.ts +1 -0
  11. package/dist/src/components/AbstractComponent.js +5 -0
  12. package/dist/src/components/ImageBackground.d.ts +2 -1
  13. package/dist/src/components/ImageBackground.js +8 -1
  14. package/dist/src/localizations/es.js +1 -1
  15. package/dist/src/toolbar/HTMLToolbar.d.ts +25 -2
  16. package/dist/src/toolbar/HTMLToolbar.js +127 -15
  17. package/dist/src/toolbar/IconProvider.d.ts +2 -0
  18. package/dist/src/toolbar/IconProvider.js +44 -0
  19. package/dist/src/toolbar/localization.d.ts +5 -0
  20. package/dist/src/toolbar/localization.js +5 -0
  21. package/dist/src/toolbar/widgets/ActionButtonWidget.d.ts +3 -1
  22. package/dist/src/toolbar/widgets/ActionButtonWidget.js +5 -1
  23. package/dist/src/toolbar/widgets/BaseToolWidget.d.ts +1 -1
  24. package/dist/src/toolbar/widgets/BaseToolWidget.js +2 -1
  25. package/dist/src/toolbar/widgets/BaseWidget.d.ts +7 -2
  26. package/dist/src/toolbar/widgets/BaseWidget.js +23 -1
  27. package/dist/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +19 -0
  28. package/dist/src/toolbar/widgets/DocumentPropertiesWidget.js +135 -0
  29. package/dist/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
  30. package/dist/src/toolbar/widgets/OverflowWidget.js +65 -0
  31. package/dist/src/toolbar/widgets/lib.d.ts +1 -0
  32. package/dist/src/toolbar/widgets/lib.js +1 -0
  33. package/dist/src/tools/PasteHandler.js +2 -2
  34. package/dist/src/tools/SelectionTool/Selection.d.ts +2 -1
  35. package/dist/src/tools/SelectionTool/Selection.js +2 -1
  36. package/package.json +1 -1
  37. package/src/Editor.loadFrom.test.ts +24 -0
  38. package/src/Editor.ts +59 -4
  39. package/src/EditorImage.ts +66 -23
  40. package/src/Viewport.ts +13 -0
  41. package/src/components/AbstractComponent.ts +6 -0
  42. package/src/components/ImageBackground.test.ts +35 -0
  43. package/src/components/ImageBackground.ts +10 -1
  44. package/src/localizations/es.ts +8 -0
  45. package/src/math/Mat33.test.ts +30 -5
  46. package/src/rendering/renderers/CanvasRenderer.ts +1 -1
  47. package/src/toolbar/HTMLToolbar.ts +164 -16
  48. package/src/toolbar/IconProvider.ts +46 -0
  49. package/src/toolbar/localization.ts +10 -0
  50. package/src/toolbar/toolbar.css +2 -0
  51. package/src/toolbar/widgets/ActionButtonWidget.ts +5 -0
  52. package/src/toolbar/widgets/BaseToolWidget.ts +3 -1
  53. package/src/toolbar/widgets/BaseWidget.ts +34 -2
  54. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +185 -0
  55. package/src/toolbar/widgets/OverflowWidget.css +9 -0
  56. package/src/toolbar/widgets/OverflowWidget.ts +83 -0
  57. package/src/toolbar/widgets/lib.ts +2 -1
  58. package/src/tools/PasteHandler.ts +3 -2
  59. package/src/tools/SelectionTool/Selection.ts +2 -1
@@ -0,0 +1,83 @@
1
+ import Editor from '../../Editor';
2
+ import { ToolbarLocalization } from '../localization';
3
+ import BaseWidget from './BaseWidget';
4
+
5
+
6
+ export default class OverflowWidget extends BaseWidget {
7
+ private overflowChildren: BaseWidget[] = [];
8
+ private overflowContainer: HTMLElement;
9
+
10
+ public constructor(editor: Editor, localizationTable?: ToolbarLocalization) {
11
+ super(editor, 'overflow-widget', localizationTable);
12
+
13
+ // Make the dropdown openable
14
+ this.container.classList.add('dropdownShowable');
15
+ this.overflowContainer ??= document.createElement('div');
16
+ }
17
+
18
+ protected getTitle(): string {
19
+ return this.localizationTable.toggleOverflow;
20
+ }
21
+
22
+ protected createIcon(): Element | null {
23
+ return this.editor.icons.makeOverflowIcon();
24
+ }
25
+
26
+ protected handleClick(): void {
27
+ this.setDropdownVisible(!this.isDropdownVisible());
28
+ }
29
+
30
+ protected fillDropdown(dropdown: HTMLElement) {
31
+ this.overflowContainer ??= document.createElement('div');
32
+ if (this.overflowContainer.parentElement) {
33
+ this.overflowContainer.remove();
34
+ }
35
+
36
+ this.overflowContainer.classList.add('toolbar-overflow-widget-overflow-list');
37
+ dropdown.appendChild(this.overflowContainer);
38
+
39
+ return true;
40
+ }
41
+
42
+ /**
43
+ * Removes all `BaseWidget`s from this and returns them.
44
+ */
45
+ public clearChildren(): BaseWidget[] {
46
+ this.overflowContainer.replaceChildren();
47
+
48
+ const overflowChildren = this.overflowChildren;
49
+ this.overflowChildren = [];
50
+ return overflowChildren;
51
+ }
52
+
53
+ public getChildWidgets(): BaseWidget[] {
54
+ return [ ...this.overflowChildren ];
55
+ }
56
+
57
+ public hasAsChild(widget: BaseWidget) {
58
+ for (const otherWidget of this.overflowChildren) {
59
+ if (widget === otherWidget) {
60
+ return true;
61
+ }
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ /**
68
+ * Adds `widget` to this.
69
+ * `widget`'s previous parent is still responsible
70
+ * for serializing/deserializing its state.
71
+ */
72
+ public addToOverflow(widget: BaseWidget) {
73
+ this.overflowChildren.push(widget);
74
+ widget.addTo(this.overflowContainer);
75
+ widget.setIsToplevel(false);
76
+ }
77
+
78
+ // This always returns false.
79
+ // Don't try to move the overflow menu to itself.
80
+ public canBeInOverflowMenu(): boolean {
81
+ return false;
82
+ }
83
+ }
@@ -9,4 +9,5 @@ export { default as HandToolWidget } from './HandToolWidget';
9
9
  export { default as SelectionToolWidget } from './SelectionToolWidget';
10
10
  export { default as EraserToolWidget } from './EraserToolWidget';
11
11
 
12
- export { default as InsertImageWidget } from './InsertImageWidget';
12
+ export { default as InsertImageWidget } from './InsertImageWidget';
13
+ export { default as DocumentPropertiesWidget } from './DocumentPropertiesWidget';
@@ -1,8 +1,9 @@
1
1
  import Editor from '../Editor';
2
- import { AbstractComponent, TextComponent } from '../components/lib';
2
+ import AbstractComponent from '../components/AbstractComponent';
3
+ import TextComponent from '../components/TextComponent';
3
4
  import SVGLoader from '../SVGLoader';
4
5
  import { PasteEvent } from '../types';
5
- import { Mat33 } from '../math/lib';
6
+ import Mat33 from '../math/Mat33';
6
7
  import BaseTool from './BaseTool';
7
8
  import TextTool from './TextTool';
8
9
  import Color4 from '../Color4';
@@ -5,7 +5,8 @@
5
5
 
6
6
  import SerializableCommand from '../../commands/SerializableCommand';
7
7
  import Editor from '../../Editor';
8
- import { Mat33, Rect2 } from '../../math/lib';
8
+ import Mat33 from '../../math/Mat33';
9
+ import Rect2 from '../../math/Rect2';
9
10
  import { Point2, Vec2 } from '../../math/Vec2';
10
11
  import Pointer from '../../Pointer';
11
12
  import SelectionHandle, { HandleShape, handleSize } from './SelectionHandle';