js-draw 0.1.12 → 0.2.1

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 (132) hide show
  1. package/.eslintrc.js +1 -0
  2. package/.firebaserc +5 -0
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +34 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. package/.github/ISSUE_TEMPLATE/translation.md +96 -0
  6. package/.github/workflows/firebase-hosting-merge.yml +25 -0
  7. package/.github/workflows/firebase-hosting-pull-request.yml +22 -0
  8. package/.github/workflows/github-pages.yml +52 -0
  9. package/CHANGELOG.md +9 -0
  10. package/README.md +11 -6
  11. package/dist/bundle.js +1 -1
  12. package/dist/src/Color4.d.ts +19 -0
  13. package/dist/src/Color4.js +24 -3
  14. package/dist/src/Editor.d.ts +129 -2
  15. package/dist/src/Editor.js +94 -17
  16. package/dist/src/EditorImage.d.ts +7 -2
  17. package/dist/src/EditorImage.js +41 -25
  18. package/dist/src/EventDispatcher.d.ts +18 -0
  19. package/dist/src/EventDispatcher.js +19 -4
  20. package/dist/src/Pointer.js +3 -2
  21. package/dist/src/UndoRedoHistory.js +15 -2
  22. package/dist/src/Viewport.js +4 -1
  23. package/dist/src/bundle/bundled.d.ts +1 -2
  24. package/dist/src/bundle/bundled.js +1 -2
  25. package/dist/src/commands/Duplicate.d.ts +1 -1
  26. package/dist/src/commands/Duplicate.js +3 -4
  27. package/dist/src/commands/Erase.d.ts +1 -1
  28. package/dist/src/commands/Erase.js +6 -5
  29. package/dist/src/commands/SerializableCommand.d.ts +4 -5
  30. package/dist/src/commands/SerializableCommand.js +12 -4
  31. package/dist/src/commands/invertCommand.d.ts +4 -0
  32. package/dist/src/commands/invertCommand.js +44 -0
  33. package/dist/src/commands/lib.d.ts +6 -0
  34. package/dist/src/commands/lib.js +6 -0
  35. package/dist/src/commands/localization.d.ts +1 -0
  36. package/dist/src/commands/localization.js +1 -0
  37. package/dist/src/components/AbstractComponent.d.ts +13 -8
  38. package/dist/src/components/AbstractComponent.js +26 -15
  39. package/dist/src/components/SVGGlobalAttributesObject.d.ts +1 -1
  40. package/dist/src/components/SVGGlobalAttributesObject.js +7 -1
  41. package/dist/src/components/Stroke.d.ts +12 -2
  42. package/dist/src/components/Stroke.js +10 -7
  43. package/dist/src/components/Text.d.ts +2 -2
  44. package/dist/src/components/Text.js +6 -6
  45. package/dist/src/components/UnknownSVGObject.d.ts +1 -1
  46. package/dist/src/components/UnknownSVGObject.js +6 -1
  47. package/dist/src/components/lib.d.ts +4 -0
  48. package/dist/src/components/lib.js +4 -0
  49. package/dist/src/lib.d.ts +25 -0
  50. package/dist/src/lib.js +25 -0
  51. package/dist/src/localizations/de.d.ts +3 -0
  52. package/dist/src/localizations/de.js +4 -0
  53. package/dist/src/localizations/getLocalizationTable.js +2 -0
  54. package/dist/src/math/Mat33.d.ts +47 -1
  55. package/dist/src/math/Mat33.js +48 -20
  56. package/dist/src/math/Path.js +3 -3
  57. package/dist/src/math/Rect2.d.ts +2 -2
  58. package/dist/src/math/Vec3.d.ts +62 -0
  59. package/dist/src/math/Vec3.js +62 -14
  60. package/dist/src/math/lib.d.ts +7 -0
  61. package/dist/src/math/lib.js +7 -0
  62. package/dist/src/math/rounding.js +1 -0
  63. package/dist/src/rendering/Display.d.ts +44 -0
  64. package/dist/src/rendering/Display.js +45 -6
  65. package/dist/src/rendering/caching/CacheRecord.d.ts +1 -0
  66. package/dist/src/rendering/caching/CacheRecord.js +3 -0
  67. package/dist/src/rendering/caching/CacheRecordManager.d.ts +4 -3
  68. package/dist/src/rendering/caching/CacheRecordManager.js +16 -4
  69. package/dist/src/rendering/caching/RenderingCache.d.ts +2 -3
  70. package/dist/src/rendering/caching/RenderingCache.js +9 -10
  71. package/dist/src/rendering/caching/types.d.ts +1 -3
  72. package/dist/src/rendering/renderers/CanvasRenderer.js +1 -1
  73. package/dist/src/toolbar/HTMLToolbar.js +1 -0
  74. package/dist/src/toolbar/makeColorInput.js +1 -1
  75. package/dist/src/toolbar/widgets/PenWidget.js +1 -0
  76. package/dist/src/tools/Pen.d.ts +1 -2
  77. package/dist/src/tools/Pen.js +8 -1
  78. package/dist/src/tools/PipetteTool.js +1 -0
  79. package/dist/src/tools/SelectionTool.js +45 -22
  80. package/dist/src/types.d.ts +17 -6
  81. package/dist/src/types.js +7 -5
  82. package/firebase.json +16 -0
  83. package/package.json +118 -101
  84. package/src/Color4.ts +23 -2
  85. package/src/Editor.ts +147 -25
  86. package/src/EditorImage.ts +45 -27
  87. package/src/EventDispatcher.ts +21 -6
  88. package/src/Pointer.ts +3 -2
  89. package/src/UndoRedoHistory.ts +18 -2
  90. package/src/Viewport.ts +5 -2
  91. package/src/bundle/bundled.ts +1 -2
  92. package/src/commands/Duplicate.ts +3 -4
  93. package/src/commands/Erase.ts +6 -5
  94. package/src/commands/SerializableCommand.ts +17 -9
  95. package/src/commands/invertCommand.ts +51 -0
  96. package/src/commands/lib.ts +14 -0
  97. package/src/commands/localization.ts +2 -0
  98. package/src/components/AbstractComponent.ts +31 -20
  99. package/src/components/SVGGlobalAttributesObject.ts +8 -1
  100. package/src/components/Stroke.test.ts +1 -1
  101. package/src/components/Stroke.ts +11 -7
  102. package/src/components/Text.ts +6 -7
  103. package/src/components/UnknownSVGObject.ts +7 -1
  104. package/src/components/lib.ts +9 -0
  105. package/src/lib.ts +28 -0
  106. package/src/localizations/de.ts +98 -0
  107. package/src/localizations/getLocalizationTable.ts +2 -0
  108. package/src/math/Mat33.ts +48 -20
  109. package/src/math/Path.ts +3 -3
  110. package/src/math/Rect2.ts +2 -2
  111. package/src/math/Vec3.ts +62 -14
  112. package/src/math/lib.ts +15 -0
  113. package/src/math/rounding.ts +2 -0
  114. package/src/rendering/Display.ts +46 -6
  115. package/src/rendering/caching/CacheRecord.test.ts +1 -1
  116. package/src/rendering/caching/CacheRecord.ts +4 -0
  117. package/src/rendering/caching/CacheRecordManager.ts +33 -7
  118. package/src/rendering/caching/RenderingCache.ts +10 -15
  119. package/src/rendering/caching/types.ts +1 -6
  120. package/src/rendering/renderers/CanvasRenderer.ts +1 -1
  121. package/src/styles.js +4 -0
  122. package/src/toolbar/HTMLToolbar.ts +1 -0
  123. package/src/toolbar/makeColorInput.ts +1 -1
  124. package/src/toolbar/toolbar.css +8 -2
  125. package/src/toolbar/widgets/PenWidget.ts +2 -0
  126. package/src/tools/PanZoom.ts +0 -1
  127. package/src/tools/Pen.ts +11 -2
  128. package/src/tools/PipetteTool.ts +2 -0
  129. package/src/tools/SelectionTool.ts +46 -18
  130. package/src/types.ts +19 -3
  131. package/tsconfig.json +4 -1
  132. package/typedoc.json +20 -0
package/.eslintrc.js CHANGED
@@ -54,5 +54,6 @@ module.exports = {
54
54
  'ignorePatterns': [
55
55
  '**/*.bundle.js',
56
56
  'dist/',
57
+ 'docs/typedoc/'
57
58
  ],
58
59
  };
package/.firebaserc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "projects": {
3
+ "default": "js-draw"
4
+ }
5
+ }
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report an issue with js-draw.
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ # Describe the bug
11
+ A clear and concise description of what the bug is.
12
+
13
+ # To Reproduce
14
+ Steps to reproduce the behavior:
15
+ 1. Open ...
16
+ 2. Switch to the ... tool.
17
+ 3. ...
18
+
19
+ ## Observed behavior
20
+ A concise description of what happened.
21
+
22
+ ## Expected behavior
23
+ A concise description of what was expected to happen.
24
+
25
+ # Screenshots
26
+ If applicable, add screenshots to help explain the issue.
27
+
28
+ # Platform
29
+ - OS: [e.g. Windows]
30
+ - Browser: [e.g. Firefox, Chrome, Safari]
31
+ - Version: [e.g. 0.2.0]
32
+
33
+ # Additional context
34
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,96 @@
1
+ ---
2
+ name: Translation
3
+ about: Translate the editor to a new language!
4
+ title: ''
5
+ labels: localization
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ # Language name in English
11
+ [e.g. Spanish]
12
+
13
+ # Translations
14
+ Please translate each of the strings in the right column (everything after the `: `) into the target language.
15
+
16
+ Ignore the surrounding single quotes. For example, to translate `insertDrawing: 'Insert Drawing',` to Spanish, please replace it with `insertDrawing: 'Añada dibujo',`.
17
+
18
+ If you're updating an existing translation, please only include the strings you're translating. Similarly, if you don't want to provide localizations for an entire language, only include the strings you did translate.
19
+
20
+ pen: "Pen",
21
+ eraser: "Eraser",
22
+ select: "Select",
23
+ handTool: "Pan",
24
+ zoom: "Zoom",
25
+ resetView: "Reset view",
26
+ thicknessLabel: "Thickness: ",
27
+ colorLabel: "Color: ",
28
+ fontLabel: "Font: ",
29
+ resizeImageToSelection: "Resize image to selection",
30
+ deleteSelection: "Delete selection",
31
+ duplicateSelection: "Duplicate selection",
32
+ undo: "Undo",
33
+ redo: "Redo",
34
+ selectObjectType: "Object type: ",
35
+ pickColorFromScreen: "Pick color from screen",
36
+ clickToPickColorAnnouncement: "Click on the screen to pick a color",
37
+ selectionToolKeyboardShortcuts: "Selection tool: Use arrow keys to move selected items, lowercase/uppercase ‘i’ and ‘o’ to resize.",
38
+ touchPanning: "Touchscreen panning",
39
+ anyDevicePanning: "Any device panning",
40
+ freehandPen: "Freehand",
41
+ arrowPen: "Arrow",
42
+ linePen: "Line",
43
+ outlinedRectanglePen: "Outlined rectangle",
44
+ filledRectanglePen: "Filled rectangle",
45
+ dropdownShown: t=>`Dropdown for ${t} shown`,
46
+ dropdownHidden: t=>`Dropdown for ${t} hidden`,
47
+ zoomLevel: t=>`Zoom: ${t}%`,
48
+ colorChangedAnnouncement: t=>`Color changed to ${t}`,
49
+ penTool: t=>`Pen ${t}`,
50
+ selectionTool: "Selection",
51
+ eraserTool: "Eraser",
52
+ touchPanTool: "Touch panning",
53
+ twoFingerPanZoomTool: "Panning and zooming",
54
+ undoRedoTool: "Undo/Redo",
55
+ rightClickDragPanTool: "Right-click drag",
56
+ pipetteTool: "Pick color from screen",
57
+ keyboardPanZoom: "Keyboard pan/zoom shortcuts",
58
+ textTool: "Text",
59
+ enterTextToInsert: "Text to insert",
60
+ toolEnabledAnnouncement: t=>`${t} enabled`,
61
+ toolDisabledAnnouncement: t=>`${t} disabled`,
62
+ updatedViewport: "Transformed Viewport",
63
+ transformedElements: t=>`Transformed ${t} element${1===t?"":"s"}`,
64
+ resizeOutputCommand: t=>`Resized image to ${t.w}x${t.h}`,
65
+ addElementAction: t=>`Added ${t}`,
66
+ eraseAction: (elemDescription, countErased)=>`Erased ${countErased} ${elemDescription}`,
67
+ duplicateAction: (elemDescription, countErased)=>`Duplicated ${countErased} ${elemDescription}`,
68
+ inverseOf: t=>`Inverse of ${t}`,
69
+ elements: "Elements",
70
+ erasedNoElements: "Erased nothing",
71
+ duplicatedNoElements: "Duplicated nothing",
72
+ rotatedBy: t=>`Rotated by ${Math.abs(t)} degrees ${t<0?"clockwise":"counter-clockwise"}`,
73
+ movedLeft: "Moved left",
74
+ movedUp: "Moved up",
75
+ movedDown: "Moved down",
76
+ movedRight: "Moved right",
77
+ zoomedOut: "Zoomed out",
78
+ zoomedIn: "Zoomed in",
79
+ selectedElements: t=>`Selected ${t} element${ 1===t ? "" : "s" }`,
80
+ stroke: "Stroke",
81
+ svgObject: "SVG Object",
82
+ text: t=>`Text object: ${t}`,
83
+ pathNodeCount: t=>`There are ${t} visible path objects.`,
84
+ textNodeCount: t=>`There are ${t} visible text nodes.`,
85
+ textNode: t=>`Text: ${t}`,
86
+ rerenderAsText: "Re-render as text",
87
+ accessibilityInputInstructions: "Press \"t\" to read the contents of the viewport as text. Use the arrow keys to move the viewport, click and drag to draw strokes. Press \"w\" to zoom in and \"s\" to zoom out.",
88
+ loading: t=>`Loading ${t}%...`,
89
+ imageEditor: "Image Editor",
90
+ doneLoading: "Done loading",
91
+ undoAnnouncement: t=>`Undid ${t}`,
92
+ redoAnnouncement: t=>`Redid ${t}`,
93
+
94
+ <!--
95
+ If you have development expierence and are comfortable creating a pull request, please consider doing so — the language can be added to ./src/localizations/.
96
+ -->
@@ -0,0 +1,25 @@
1
+ # This file was auto-generated by the Firebase CLI
2
+ # https://github.com/firebase/firebase-tools
3
+
4
+ name: Deploy to Firebase Hosting on merge
5
+ 'on':
6
+ push:
7
+ branches:
8
+ - 'main'
9
+ jobs:
10
+ build_and_deploy:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ - name: Install dependencies
15
+ run: yarn install
16
+ - name: Run tests
17
+ run: yarn test
18
+ - name: Build
19
+ run: cd docs/example && yarn install && yarn build
20
+ - uses: FirebaseExtended/action-hosting-deploy@v0
21
+ with:
22
+ repoToken: '${{ secrets.GITHUB_TOKEN }}'
23
+ firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_JS_DRAW }}'
24
+ channelId: live
25
+ projectId: js-draw
@@ -0,0 +1,22 @@
1
+ # This file was auto-generated by the Firebase CLI
2
+ # https://github.com/firebase/firebase-tools
3
+
4
+ name: Deploy to Firebase Hosting on PR
5
+ 'on': pull_request
6
+ jobs:
7
+ build_and_preview:
8
+ if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+ - name: Install dependencies
13
+ run: yarn install
14
+ - name: Run tests
15
+ run: yarn test
16
+ - name: Build
17
+ run: cd docs/example && yarn install && yarn build
18
+ - uses: FirebaseExtended/action-hosting-deploy@v0
19
+ with:
20
+ repoToken: '${{ secrets.GITHUB_TOKEN }}'
21
+ firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_JS_DRAW }}'
22
+ projectId: js-draw
@@ -0,0 +1,52 @@
1
+ # Created on GitHub
2
+
3
+ # Simple workflow for deploying static content to GitHub Pages
4
+ name: Deploy static content to Pages
5
+
6
+ on:
7
+ # Runs on pushes targeting the default branch
8
+ push:
9
+ branches: ["main"]
10
+
11
+ # Allows you to run this workflow manually from the Actions tab
12
+ workflow_dispatch:
13
+
14
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15
+ permissions:
16
+ contents: read
17
+ pages: write
18
+ id-token: write
19
+
20
+ # Allow one concurrent deployment
21
+ concurrency:
22
+ group: "pages"
23
+ cancel-in-progress: true
24
+
25
+ jobs:
26
+ # Single deploy job since we're just deploying
27
+ deploy:
28
+ environment:
29
+ name: github-pages
30
+ url: ${{ steps.deployment.outputs.page_url }}
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - name: Checkout
34
+ uses: actions/checkout@v3
35
+ - name: Install dependencies
36
+ run: yarn install
37
+ - name: Run tests
38
+ run: yarn test
39
+ - name: Build documentation
40
+ run: yarn doc
41
+ - name: Build
42
+ run: cd docs/example && yarn install && yarn build
43
+ - name: Setup Pages
44
+ uses: actions/configure-pages@v2
45
+ - name: Upload artifact
46
+ uses: actions/upload-pages-artifact@v1
47
+ with:
48
+ # Upload just the docs folder
49
+ path: './docs/'
50
+ - name: Deploy to GitHub Pages
51
+ id: deployment
52
+ uses: actions/deploy-pages@v1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.2.1
2
+ * German localization.
3
+
4
+ # 0.2.0
5
+ * Export `Mat33`, `Vec3`, `Vec2`, and `Color4`.
6
+ * [Documentation](https://personalizedrefrigerator.github.io/js-draw/typedoc/index.html)
7
+ * Bug fixes:
8
+ * After using up all blocks in the rendering cache, a single block was repeatedly re-allocated, leading to slow performance.
9
+
1
10
  # 0.1.12
2
11
  * Add icons to the selection menu.
3
12
  * Screen-reader-related bug fixes.
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # js-draw
2
2
 
3
- [NPM package](https://www.npmjs.com/package/js-draw) | [GitHub](https://github.com/personalizedrefrigerator/js-draw) | [Try it!](https://personalizedrefrigerator.github.io/js-draw/example/example.html)
3
+ [NPM package](https://www.npmjs.com/package/js-draw) | [GitHub](https://github.com/personalizedrefrigerator/js-draw) | [Documentation](https://personalizedrefrigerator.github.io/js-draw/typedoc/) | [Try it!](https://personalizedrefrigerator.github.io/js-draw/example/example.html)
4
4
 
5
5
  ![](docs/img/js-draw.jpg)
6
6
 
7
- For example usage, see [docs/example/example.ts](docs/example/example.ts).
7
+ For example usage, see [docs/example/example.ts](docs/example/example.ts) or read [the (work-in-progress) documentation](https://personalizedrefrigerator.github.io/js-draw/typedoc/modules/lib.html).
8
+
9
+ At present, not all documented modules are `import`-able.
8
10
 
9
11
  # API
10
12
 
@@ -13,6 +15,7 @@ To use `js-draw`,
13
15
  ## Creating an `Editor`
14
16
 
15
17
  ### With a bundler that supports importing `.css` files
18
+
16
19
  To create a new `Editor` and add it as a child of `document.body`,
17
20
  ```ts
18
21
  import Editor from 'js-draw';
@@ -24,6 +27,7 @@ const editor = new Editor(document.body);
24
27
  The `import js-draw/styles` step requires a bundler that can import `.css` files. For example, [`webpack` with `css-loader`.](https://webpack.js.org/loaders/css-loader/)
25
28
 
26
29
  ### With a bundler that doesn't support importing `.css` files
30
+
27
31
  Import the pre-bundled version of the editor to apply CSS after loading the page.
28
32
  ```ts
29
33
  import Editor from 'js-draw';
@@ -34,10 +38,11 @@ const editor = new Editor(document.body);
34
38
  `js-draw/bundle` is a version of the editor pre-processed by `Webpack`. As such, `import`ing it applies editor-specific CSS to the document.
35
39
 
36
40
  ### Without a bundler
41
+
37
42
  If you're not using a bundler, consider using the pre-bundled editor:
38
43
  ```html
39
- <!-- Replace 0.1.7 with the latest version of js-draw -->
40
- <script src="https://cdn.jsdelivr.net/npm/js-draw@0.1.7/dist/bundle.js"></script>
44
+ <!-- Replace 0.2.0 with the latest version of js-draw -->
45
+ <script src="https://cdn.jsdelivr.net/npm/js-draw@0.2.0/dist/bundle.js"></script>
41
46
  <script>
42
47
  const editor = new jsdraw.Editor(document.body);
43
48
  editor.addToolbar();
@@ -79,7 +84,7 @@ editor.loadFromSVG(`
79
84
  **Note**: While `js-draw` supports a small subset of the SVG markup language, it tries to preserve unrecognised SVG elements.
80
85
 
81
86
  For example, although `js-draw` doesn't support `<circle/>` elements,
82
- ```svg
87
+ ```xml
83
88
  <svg
84
89
  viewBox="156 74 200 150"
85
90
  width="200" height="150"
@@ -93,7 +98,7 @@ renders as
93
98
  ![screenshot of the image editor, displaying a green checkmark. The circle is invisible](docs/img/unsupported-elements--in-editor.png)
94
99
 
95
100
  but exports to
96
- ```svg
101
+ ```xml
97
102
  <svg viewBox="156 74 200 150" width="200" height="150" version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg"><g><path d="M156,150M156,150Q190,190 209,217L213,215Q193,187 160,148M209,217M209,217Q212,218 236,178L232,176Q210,215 213,215M236,178M236,178Q240,171 307,95L305,93Q237,168 232,176M307,95M307,95Q312,90 329,78L327,74Q309,87 305,93" fill="#07a837"></path></g><circle cx="200" cy="100" r="40" fill="red"></circle></svg>
98
103
  ```
99
104