@lvl99dotcom/paintcanvas 0.0.0-stage → 0.3.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.
- package/LICENSE +201 -0
- package/README.md +131 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/lib/brushes/BrushTipCache/index.d.ts +32 -0
- package/dist/lib/brushes/BrushTipCache/index.js +60 -0
- package/dist/lib/brushes/StrokeEngine/index.d.ts +171 -0
- package/dist/lib/brushes/StrokeEngine/index.js +324 -0
- package/dist/lib/brushes/StrokePath/index.d.ts +53 -0
- package/dist/lib/brushes/StrokePath/index.js +161 -0
- package/dist/lib/brushes/StrokeSampler/index.d.ts +55 -0
- package/dist/lib/brushes/StrokeSampler/index.js +75 -0
- package/dist/lib/brushes/authors/index.d.ts +55 -0
- package/dist/lib/brushes/authors/index.js +60 -0
- package/dist/lib/brushes/configRanges/index.d.ts +52 -0
- package/dist/lib/brushes/configRanges/index.js +206 -0
- package/dist/lib/brushes/index.d.ts +5 -0
- package/dist/lib/brushes/index.js +19 -0
- package/dist/lib/brushes/params/index.d.ts +108 -0
- package/dist/lib/brushes/params/index.js +139 -0
- package/dist/lib/brushes/presetFile/index.d.ts +32 -0
- package/dist/lib/brushes/presetFile/index.js +55 -0
- package/dist/lib/brushes/presets/drawing/brush-pen.js +3 -0
- package/dist/lib/brushes/presets/drawing/felt-pen.js +3 -0
- package/dist/lib/brushes/presets/drawing/index.d.ts +13 -0
- package/dist/lib/brushes/presets/drawing/index.js +88 -0
- package/dist/lib/brushes/presets/drawing/pencil-2b.js +3 -0
- package/dist/lib/brushes/presets/drawing/pencil-hb.js +3 -0
- package/dist/lib/brushes/presets/painting/grass.js +3 -0
- package/dist/lib/brushes/presets/painting/hair.js +3 -0
- package/dist/lib/brushes/presets/painting/index.d.ts +18 -0
- package/dist/lib/brushes/presets/painting/index.js +118 -0
- package/dist/lib/brushes/presets/painting/splatter.js +3 -0
- package/dist/lib/brushes/presets/painting/textured-paint.js +3 -0
- package/dist/lib/brushes/presets/painting/watery-paint.js +3 -0
- package/dist/lib/brushes/presets/round/index.d.ts +9 -0
- package/dist/lib/brushes/presets/round/index.js +44 -0
- package/dist/lib/brushes/presets/round/round.js +3 -0
- package/dist/lib/brushes/presets/round/soft-round.js +3 -0
- package/dist/lib/brushes/presets/sized/index.d.ts +20 -0
- package/dist/lib/brushes/presets/sized/index.js +30 -0
- package/dist/lib/brushes/presets/sketching/index.d.ts +14 -0
- package/dist/lib/brushes/presets/sketching/index.js +107 -0
- package/dist/lib/brushes/presets/square/index.d.ts +7 -0
- package/dist/lib/brushes/presets/square/index.js +22 -0
- package/dist/lib/brushes/presets/square/square.js +3 -0
- package/dist/lib/brushes/shapeImage/index.d.ts +40 -0
- package/dist/lib/brushes/shapeImage/index.js +61 -0
- package/dist/lib/brushes/types/index.d.ts +243 -0
- package/dist/lib/brushes/types/index.js +20 -0
- package/dist/lib/classes/BackgroundWork/index.d.ts +55 -0
- package/dist/lib/classes/BackgroundWork/index.js +97 -0
- package/dist/lib/classes/BrushSettings/index.d.ts +91 -0
- package/dist/lib/classes/BrushSettings/index.js +152 -0
- package/dist/lib/classes/CustomPresets/index.d.ts +53 -0
- package/dist/lib/classes/CustomPresets/index.js +71 -0
- package/dist/lib/classes/ExternalSheets/index.d.ts +64 -0
- package/dist/lib/classes/ExternalSheets/index.js +112 -0
- package/dist/lib/classes/GestureTracker/index.d.ts +62 -0
- package/dist/lib/classes/GestureTracker/index.js +122 -0
- package/dist/lib/classes/History/index.d.ts +83 -0
- package/dist/lib/classes/History/index.js +126 -0
- package/dist/lib/classes/HistoryGuard/index.d.ts +58 -0
- package/dist/lib/classes/HistoryGuard/index.js +97 -0
- package/dist/lib/classes/InputSettings/index.d.ts +74 -0
- package/dist/lib/classes/InputSettings/index.js +101 -0
- package/dist/lib/classes/KeyboardShortcuts/index.d.ts +48 -0
- package/dist/lib/classes/KeyboardShortcuts/index.js +137 -0
- package/dist/lib/classes/Layer/index.d.ts +86 -0
- package/dist/lib/classes/Layer/index.js +111 -0
- package/dist/lib/classes/LayerAutosave/index.d.ts +180 -0
- package/dist/lib/classes/LayerAutosave/index.js +346 -0
- package/dist/lib/classes/LayerStack/index.d.ts +177 -0
- package/dist/lib/classes/LayerStack/index.js +394 -0
- package/dist/lib/classes/PaintCanvas/index.d.ts +537 -0
- package/dist/lib/classes/PaintCanvas/index.js +965 -0
- package/dist/lib/classes/StrokeLog/index.d.ts +149 -0
- package/dist/lib/classes/StrokeLog/index.js +257 -0
- package/dist/lib/classes/Viewport/index.d.ts +108 -0
- package/dist/lib/classes/Viewport/index.js +194 -0
- package/dist/lib/document/index.d.ts +17 -0
- package/dist/lib/document/index.js +25 -0
- package/dist/lib/document/schema.d.ts +132 -0
- package/dist/lib/document/schema.js +110 -0
- package/dist/lib/i18n/index.d.ts +131 -0
- package/dist/lib/i18n/index.js +277 -0
- package/dist/lib/image/index.d.ts +90 -0
- package/dist/lib/image/index.js +147 -0
- package/dist/lib/messages/PatchSender/index.d.ts +75 -0
- package/dist/lib/messages/PatchSender/index.js +125 -0
- package/dist/lib/messages/index.d.ts +26 -0
- package/dist/lib/messages/index.js +59 -0
- package/dist/lib/messages/schema.d.ts +1775 -0
- package/dist/lib/messages/schema.js +192 -0
- package/dist/lib/presets/index.d.ts +32 -0
- package/dist/lib/presets/index.js +35 -0
- package/dist/lib/presets/schema.d.ts +753 -0
- package/dist/lib/presets/schema.js +181 -0
- package/dist/lib/rendering/BrushTip/index.d.ts +63 -0
- package/dist/lib/rendering/BrushTip/index.js +112 -0
- package/dist/lib/rendering/checkerboard/index.d.ts +22 -0
- package/dist/lib/rendering/checkerboard/index.js +31 -0
- package/dist/lib/rendering/compositing/index.d.ts +64 -0
- package/dist/lib/rendering/compositing/index.js +124 -0
- package/dist/lib/rendering/cursor/index.d.ts +14 -0
- package/dist/lib/rendering/cursor/index.js +39 -0
- package/dist/lib/rendering/cursors/index.d.ts +18 -0
- package/dist/lib/rendering/cursors/index.js +23 -0
- package/dist/lib/rendering/maskOutline/index.d.ts +22 -0
- package/dist/lib/rendering/maskOutline/index.js +78 -0
- package/dist/lib/rendering/outline/index.d.ts +36 -0
- package/dist/lib/rendering/outline/index.js +120 -0
- package/dist/lib/rendering/sample/index.d.ts +55 -0
- package/dist/lib/rendering/sample/index.js +83 -0
- package/dist/lib/rendering/screenshot/index.d.ts +67 -0
- package/dist/lib/rendering/screenshot/index.js +96 -0
- package/dist/lib/rendering/transformBox/index.d.ts +10 -0
- package/dist/lib/rendering/transformBox/index.js +57 -0
- package/dist/lib/selection/Lasso/index.d.ts +70 -0
- package/dist/lib/selection/Lasso/index.js +156 -0
- package/dist/lib/selection/Selection/index.d.ts +86 -0
- package/dist/lib/selection/Selection/index.js +228 -0
- package/dist/lib/selection/geometry/index.d.ts +37 -0
- package/dist/lib/selection/geometry/index.js +57 -0
- package/dist/lib/storage/index.d.ts +63 -0
- package/dist/lib/storage/index.js +114 -0
- package/dist/lib/transform/Transformer/index.d.ts +124 -0
- package/dist/lib/transform/Transformer/index.js +286 -0
- package/dist/lib/transform/geometry/index.d.ts +95 -0
- package/dist/lib/transform/geometry/index.js +258 -0
- package/dist/lib/utils/array/index.d.ts +10 -0
- package/dist/lib/utils/array/index.js +21 -0
- package/dist/lib/utils/gestures/index.d.ts +35 -0
- package/dist/lib/utils/gestures/index.js +81 -0
- package/dist/lib/utils/navigation/index.d.ts +51 -0
- package/dist/lib/utils/navigation/index.js +59 -0
- package/dist/lib/utils/random/index.d.ts +18 -0
- package/dist/lib/utils/random/index.js +27 -0
- package/dist/lib/utils/shortcuts/index.d.ts +74 -0
- package/dist/lib/utils/shortcuts/index.js +189 -0
- package/dist/lib/validation/validators.generated.d.ts +27 -0
- package/dist/lib/validation/validators.generated.js +19826 -0
- package/dist/locales/en-GB.js +181 -0
- package/dist/locales/en-US.js +181 -0
- package/dist/locales/fr.js +181 -0
- package/dist/locales/ja.js +181 -0
- package/dist/locales/ko.js +181 -0
- package/dist/locales/zh-Hans.js +181 -0
- package/dist/locales/zh-Hant.js +181 -0
- package/dist/package.js +3 -0
- package/dist/testing/app.d.ts +7 -0
- package/dist/testing/app.js +16 -0
- package/dist/testing/elements.d.ts +42 -0
- package/dist/testing/elements.js +58 -0
- package/dist/testing/fakeCanvas.d.ts +21 -0
- package/dist/testing/fakeCanvas.js +26 -0
- package/dist/testing/layerStore.d.ts +26 -0
- package/dist/testing/layerStore.js +43 -0
- package/dist/testing/locks.d.ts +15 -0
- package/dist/testing/locks.js +41 -0
- package/dist/testing/recordingCanvas.d.ts +14 -0
- package/dist/testing/recordingCanvas.js +28 -0
- package/dist/testing/recordingContext.d.ts +10 -0
- package/dist/testing/recordingContext.js +19 -0
- package/dist/ui/ChangeController/index.d.ts +40 -0
- package/dist/ui/ChangeController/index.js +62 -0
- package/dist/ui/base/index.d.ts +69 -0
- package/dist/ui/base/index.js +94 -0
- package/dist/ui/elements/PaintCanvas/index.d.ts +249 -0
- package/dist/ui/elements/PaintCanvas/index.js +584 -0
- package/dist/ui/elements/PaintCanvas/style.js +3 -0
- package/dist/ui/elements/PcBrushConfig/index.d.ts +130 -0
- package/dist/ui/elements/PcBrushConfig/index.js +465 -0
- package/dist/ui/elements/PcBrushConfig/style.js +3 -0
- package/dist/ui/elements/PcBrushMenu/index.d.ts +121 -0
- package/dist/ui/elements/PcBrushMenu/index.js +362 -0
- package/dist/ui/elements/PcBrushMenu/style.js +3 -0
- package/dist/ui/elements/PcBrushTest/index.d.ts +71 -0
- package/dist/ui/elements/PcBrushTest/index.js +136 -0
- package/dist/ui/elements/PcBrushTest/style.js +3 -0
- package/dist/ui/elements/PcButton/index.d.ts +57 -0
- package/dist/ui/elements/PcButton/index.js +124 -0
- package/dist/ui/elements/PcButtonGroup/index.d.ts +44 -0
- package/dist/ui/elements/PcButtonGroup/index.js +93 -0
- package/dist/ui/elements/PcCanvas/index.d.ts +356 -0
- package/dist/ui/elements/PcCanvas/index.js +1004 -0
- package/dist/ui/elements/PcCanvas/style.js +3 -0
- package/dist/ui/elements/PcCanvasMap/index.d.ts +96 -0
- package/dist/ui/elements/PcCanvasMap/index.js +187 -0
- package/dist/ui/elements/PcCanvasMap/style.js +3 -0
- package/dist/ui/elements/PcContextMenu/index.d.ts +72 -0
- package/dist/ui/elements/PcContextMenu/index.js +148 -0
- package/dist/ui/elements/PcDialog/index.d.ts +63 -0
- package/dist/ui/elements/PcDialog/index.js +114 -0
- package/dist/ui/elements/PcIcon/index.d.ts +36 -0
- package/dist/ui/elements/PcIcon/index.js +43 -0
- package/dist/ui/elements/PcIconToggle/index.d.ts +46 -0
- package/dist/ui/elements/PcIconToggle/index.js +87 -0
- package/dist/ui/elements/PcInfoTip/index.d.ts +40 -0
- package/dist/ui/elements/PcInfoTip/index.js +95 -0
- package/dist/ui/elements/PcInputSettings/index.d.ts +69 -0
- package/dist/ui/elements/PcInputSettings/index.js +154 -0
- package/dist/ui/elements/PcLayerItem/index.d.ts +221 -0
- package/dist/ui/elements/PcLayerItem/index.js +561 -0
- package/dist/ui/elements/PcLayerItem/style.js +3 -0
- package/dist/ui/elements/PcLayersMenu/index.d.ts +108 -0
- package/dist/ui/elements/PcLayersMenu/index.js +208 -0
- package/dist/ui/elements/PcLayersMenu/style.js +3 -0
- package/dist/ui/elements/PcMatch/index.d.ts +31 -0
- package/dist/ui/elements/PcMatch/index.js +58 -0
- package/dist/ui/elements/PcPanel/index.d.ts +43 -0
- package/dist/ui/elements/PcPanel/index.js +51 -0
- package/dist/ui/elements/PcPopover/index.d.ts +48 -0
- package/dist/ui/elements/PcPopover/index.js +86 -0
- package/dist/ui/elements/PcSlider/index.d.ts +57 -0
- package/dist/ui/elements/PcSlider/index.js +88 -0
- package/dist/ui/elements/PcStats/index.d.ts +54 -0
- package/dist/ui/elements/PcStats/index.js +144 -0
- package/dist/ui/elements/PcThemePicker/index.d.ts +56 -0
- package/dist/ui/elements/PcThemePicker/index.js +134 -0
- package/dist/ui/elements/PcToast/index.d.ts +58 -0
- package/dist/ui/elements/PcToast/index.js +110 -0
- package/dist/ui/elements/PcToggleCheckbox/index.d.ts +37 -0
- package/dist/ui/elements/PcToggleCheckbox/index.js +105 -0
- package/dist/ui/elements/PcToolSettings/index.d.ts +128 -0
- package/dist/ui/elements/PcToolSettings/index.js +549 -0
- package/dist/ui/elements/PcToolSettings/style.js +3 -0
- package/dist/ui/elements/PcToolbar/index.d.ts +71 -0
- package/dist/ui/elements/PcToolbar/index.js +190 -0
- package/dist/ui/elements/PcToolbar/style.js +3 -0
- package/dist/ui/icons/images/brush.js +3 -0
- package/dist/ui/icons/images/circle-mask.js +3 -0
- package/dist/ui/icons/images/clipboard.js +3 -0
- package/dist/ui/icons/images/cursor.js +3 -0
- package/dist/ui/icons/images/eraser.js +3 -0
- package/dist/ui/icons/images/eyedropper.js +3 -0
- package/dist/ui/icons/images/flip-horizontal.js +3 -0
- package/dist/ui/icons/images/flip-vertical.js +3 -0
- package/dist/ui/icons/images/focus-pen.js +3 -0
- package/dist/ui/icons/images/freehand-mask.js +3 -0
- package/dist/ui/icons/images/hidden.js +3 -0
- package/dist/ui/icons/images/layers.js +3 -0
- package/dist/ui/icons/images/linked.js +3 -0
- package/dist/ui/icons/images/locked.js +3 -0
- package/dist/ui/icons/images/moon.js +3 -0
- package/dist/ui/icons/images/pan.js +3 -0
- package/dist/ui/icons/images/polygon-mask.js +3 -0
- package/dist/ui/icons/images/pressure.js +3 -0
- package/dist/ui/icons/images/randomise.js +3 -0
- package/dist/ui/icons/images/rectangle-mask.js +3 -0
- package/dist/ui/icons/images/redo.js +3 -0
- package/dist/ui/icons/images/rotate-90-left.js +3 -0
- package/dist/ui/icons/images/rotate-90-right.js +3 -0
- package/dist/ui/icons/images/smoothing-bezier-cubic.js +3 -0
- package/dist/ui/icons/images/smoothing-bezier-quad.js +3 -0
- package/dist/ui/icons/images/smoothing-linear.js +3 -0
- package/dist/ui/icons/images/star.js +3 -0
- package/dist/ui/icons/images/sun.js +3 -0
- package/dist/ui/icons/images/tilt.js +3 -0
- package/dist/ui/icons/images/undo.js +3 -0
- package/dist/ui/icons/images/unlinked.js +3 -0
- package/dist/ui/icons/images/unlocked.js +3 -0
- package/dist/ui/icons/images/visible.js +3 -0
- package/dist/ui/icons/images/zoom-in.js +3 -0
- package/dist/ui/icons/images/zoom-out.js +3 -0
- package/dist/ui/icons/images/zoom.js +3 -0
- package/dist/ui/icons/index.d.ts +42 -0
- package/dist/ui/icons/index.js +130 -0
- package/dist/ui/index.d.ts +21 -0
- package/dist/ui/index.js +22 -0
- package/dist/ui/layout/index.d.ts +88 -0
- package/dist/ui/layout/index.js +96 -0
- package/dist/ui/styles/index.d.ts +13 -0
- package/dist/ui/styles/index.js +195 -0
- package/dist/ui/tokens/index.d.ts +29 -0
- package/dist/ui/tokens/index.js +114 -0
- package/locales/en-GB.json +179 -0
- package/locales/en-US.json +179 -0
- package/locales/fr.json +179 -0
- package/locales/ja.json +179 -0
- package/locales/ko.json +179 -0
- package/locales/zh-Hans.json +179 -0
- package/locales/zh-Hant.json +179 -0
- package/package.json +97 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,132 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PaintCanvas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Open-source painting engine and renderer for the browser, with optional UI.
|
|
4
|
+
|
|
5
|
+
- **Engine** (`@lvl99dotcom/paintcanvas/lib/*`): layers, brushes and erasers, custom brush presets, selection, transforms, clipboard, undo/redo, viewport, pen/touch/mouse input and rendering. No UI, and nothing is stored unless you ask (e.g. keeping the drawing in the browser).
|
|
6
|
+
- **Messages**: the engine sends and receives small drawing messages (patches of pixels, strokes, undo and redo), so you can share a drawing over any transport you choose.
|
|
7
|
+
- **UI** (`@lvl99dotcom/paintcanvas/ui`), optional: Lit web components, from buttons and sliders up to a full `<paint-canvas>` layout with slots for your own parts.
|
|
8
|
+
|
|
9
|
+
Licensed under the [Apache License 2.0](LICENSE). See [CONTRIBUTING.md](CONTRIBUTING.md) to help.
|
|
10
|
+
|
|
11
|
+
## Contents
|
|
12
|
+
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Quick start](#quick-start)
|
|
15
|
+
- [Documentation](#documentation)
|
|
16
|
+
- [Demo](#demo)
|
|
17
|
+
- [Development](#development)
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install @lvl99dotcom/paintcanvas lit
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
[Lit](https://lit.dev) is a peer dependency, used by the UI only.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
A full-page drawing app:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<!doctype html>
|
|
33
|
+
<html lang="en">
|
|
34
|
+
<head>
|
|
35
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
36
|
+
<style>
|
|
37
|
+
html,
|
|
38
|
+
body,
|
|
39
|
+
paint-canvas {
|
|
40
|
+
height: 100%;
|
|
41
|
+
margin: 0;
|
|
42
|
+
}
|
|
43
|
+
</style>
|
|
44
|
+
</head>
|
|
45
|
+
<body>
|
|
46
|
+
<paint-canvas></paint-canvas>
|
|
47
|
+
<script type="module">
|
|
48
|
+
import "@lvl99dotcom/paintcanvas/ui";
|
|
49
|
+
import { translations } from "@lvl99dotcom/paintcanvas/lib/i18n";
|
|
50
|
+
|
|
51
|
+
await translations.useDeviceLocale();
|
|
52
|
+
</script>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
To keep the drawing through page reloads, give it a name to store it under in the browser: `<paint-canvas store="my-drawing">`.
|
|
58
|
+
|
|
59
|
+
`<paint-canvas>` creates its own engine (a 2000 × 2000 pixel canvas). To choose the size or other options, give it one:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import PaintCanvas from "@lvl99dotcom/paintcanvas/lib/classes/PaintCanvas";
|
|
63
|
+
|
|
64
|
+
const layout = document.querySelector("paint-canvas");
|
|
65
|
+
layout.app = new PaintCanvas({ width: 1200, height: 800, maxLayers: 10 });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Importing `@lvl99dotcom/paintcanvas/ui` registers every element. To load less, import single elements, e.g. `@lvl99dotcom/paintcanvas/ui/elements/PaintCanvas`.
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
Guides and API pages are in [docs/](docs/), a [Docusaurus](https://docusaurus.io) site (`pnpm docs`). The guides:
|
|
73
|
+
|
|
74
|
+
- [The layout and its slots](docs/docs/layout.md)
|
|
75
|
+
- [Building your own UI on the engine](docs/docs/engine.md)
|
|
76
|
+
- [Messages and events](docs/docs/messages.md)
|
|
77
|
+
- [Saving and opening drawings](docs/docs/documents.md)
|
|
78
|
+
- [Translations, and adding your app's own](docs/docs/translations.md)
|
|
79
|
+
- [Icons](docs/docs/icons.md)
|
|
80
|
+
- [Theming](docs/docs/theming.md)
|
|
81
|
+
|
|
82
|
+
## Demo
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
pnpm dev
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Starts a development server and opens the demo in your browser. It uses the source directly, so saving a change to `src/`, `demo/` or `locales/` reloads the page with the change straight away. (The whole page reloads because custom elements can't be redefined in a running page, so the drawing starts again.)
|
|
89
|
+
|
|
90
|
+
- http://localhost:5190/: a full-page PaintCanvas with a layers panel, a menu with input settings, a dark theme switch and a "New drawing" button. The drawing is kept in the browser, so it survives reloads.
|
|
91
|
+
- http://localhost:5190/elements.html: the base elements.
|
|
92
|
+
|
|
93
|
+
To try it with a pen or touch on another device (e.g. a tablet) on the same network, run `pnpm dev --host` and open the network address it prints. This makes the server reachable by anyone on that network.
|
|
94
|
+
|
|
95
|
+
The UI text follows your device's languages: on an English (UK) device, edit `locales/en-GB.json` to see text changes. The demo's own text (e.g. the "New drawing" button) is in `demo/locales/`, added the way an app adds its translations.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
You need [Node.js](https://nodejs.org) 22.18 or later (scripts run TypeScript directly) and [pnpm](https://pnpm.io) (`corepack enable` installs the version in `package.json`).
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
pnpm install
|
|
103
|
+
pnpm exec playwright install chromium # once, for the browser tests
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Source layout:
|
|
107
|
+
|
|
108
|
+
- `src/lib/`: engine code (brushes, rendering, selection, transform, classes, messages, document, i18n, image, presets, validation, utils). No UI.
|
|
109
|
+
- `src/ui/`: tokens, icons, base elements, drawing elements and the layout.
|
|
110
|
+
- `src/testing/`: test helpers (fake and recording canvases), published as `@lvl99dotcom/paintcanvas/testing/*`. Some use Vitest.
|
|
111
|
+
- `locales/`: UI text per locale.
|
|
112
|
+
- `scripts/`: build scripts, e.g. the validator generator.
|
|
113
|
+
- `demo/`: the demo pages.
|
|
114
|
+
- `docs/`: the documentation site (its own pnpm package): guides in `docs/docs/`, and API pages TypeDoc generates from the source's comments.
|
|
115
|
+
|
|
116
|
+
Tests sit in a `tests` folder beside the code. Unit tests (`*.test.ts`) run in jsdom; pixel tests (`*.browser.test.ts`) run in headless Chromium.
|
|
117
|
+
|
|
118
|
+
| Command | Does |
|
|
119
|
+
| ----------------------- | --------------------------------------------------------------------------------- |
|
|
120
|
+
| `pnpm typecheck` | Checks types in the source, tests, scripts and demo |
|
|
121
|
+
| `pnpm lint` | Checks the code with ESLint |
|
|
122
|
+
| `pnpm format` | Formats files with Prettier (`pnpm format:check` only checks) |
|
|
123
|
+
| `pnpm test` | Runs the unit tests |
|
|
124
|
+
| `pnpm test:browser` | Runs the pixel tests in a real browser |
|
|
125
|
+
| `pnpm test:all` | Runs both |
|
|
126
|
+
| `pnpm coverage` | Runs both, with a coverage report in `coverage/` |
|
|
127
|
+
| `pnpm build` | Builds the package into `dist/`: ES modules matching `src/`, with types |
|
|
128
|
+
| `pnpm build:validators` | Regenerates the validators after changing the preset, message or document schemas |
|
|
129
|
+
| `pnpm dev` | Starts the demo, reloading it when files change (`pnpm demo` does the same) |
|
|
130
|
+
| `pnpm docs` | Starts the documentation site (`pnpm docs:build` builds it into `docs/build/`) |
|
|
131
|
+
|
|
132
|
+
Each folder in `src/lib` and `src/ui` is published as its own import path (e.g. `src/lib/classes/PaintCanvas` as `@lvl99dotcom/paintcanvas/lib/classes/PaintCanvas`). `sideEffects` in `package.json` lists the UI modules that register elements when loaded (`src/ui/index.ts` and each `src/ui/elements/*/index.ts`), so bundlers keep them; add any other module that registers elements there.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BrushConfig, BrushesConfig } from "../types";
|
|
2
|
+
import BrushTip, { type ImageDecoder } from "../../rendering/BrushTip";
|
|
3
|
+
import { type CanvasFactory } from "../../classes/Layer";
|
|
4
|
+
/**
|
|
5
|
+
* Loads and keeps each shape's brush tip. Until a shape's image has loaded, the round tip is used.
|
|
6
|
+
*
|
|
7
|
+
* Dispatches a `change` event when a tip finishes loading.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const tips = new BrushTipCache();
|
|
11
|
+
* const tip = tips.get(preset); // round until the image loads
|
|
12
|
+
*/
|
|
13
|
+
export default class BrushTipCache extends EventTarget {
|
|
14
|
+
private readonly tips;
|
|
15
|
+
private readonly loading;
|
|
16
|
+
private readonly round;
|
|
17
|
+
private readonly decode;
|
|
18
|
+
private readonly createCanvas;
|
|
19
|
+
constructor(decode?: ImageDecoder, createCanvas?: CanvasFactory);
|
|
20
|
+
/**
|
|
21
|
+
* Get a preset's tip, starting to load it if needed. Returns the round tip while loading or if loading fails.
|
|
22
|
+
*/
|
|
23
|
+
get(preset: BrushConfig): BrushTip;
|
|
24
|
+
/**
|
|
25
|
+
* Start loading every preset's tip, so the first stroke with each preset already uses its shape.
|
|
26
|
+
*/
|
|
27
|
+
preload(presets: BrushesConfig): void;
|
|
28
|
+
/**
|
|
29
|
+
* Load a preset's tip and remember it under its key.
|
|
30
|
+
*/
|
|
31
|
+
private load;
|
|
32
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import BrushTip, { decodeImage } from "../../rendering/BrushTip/index.js";
|
|
2
|
+
import { createOffscreenCanvas } from "../../classes/Layer/index.js";
|
|
3
|
+
// src/lib/brushes/BrushTipCache/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* The key a preset's tip is kept under: its shape image (so presets and edited settings with the same shape share a
|
|
6
|
+
* tip, and a changed shape loads anew), or its ID for shapes given as bytes.
|
|
7
|
+
*/
|
|
8
|
+
var tipKey = (preset) => typeof preset.image === "string" ? preset.image : preset.id;
|
|
9
|
+
/**
|
|
10
|
+
* Loads and keeps each shape's brush tip. Until a shape's image has loaded, the round tip is used.
|
|
11
|
+
*
|
|
12
|
+
* Dispatches a `change` event when a tip finishes loading.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const tips = new BrushTipCache();
|
|
16
|
+
* const tip = tips.get(preset); // round until the image loads
|
|
17
|
+
*/
|
|
18
|
+
var BrushTipCache = class extends EventTarget {
|
|
19
|
+
tips = /* @__PURE__ */ new Map();
|
|
20
|
+
loading = /* @__PURE__ */ new Set();
|
|
21
|
+
round;
|
|
22
|
+
decode;
|
|
23
|
+
createCanvas;
|
|
24
|
+
constructor(decode = decodeImage, createCanvas = createOffscreenCanvas) {
|
|
25
|
+
super();
|
|
26
|
+
this.decode = decode;
|
|
27
|
+
this.createCanvas = createCanvas;
|
|
28
|
+
this.round = new BrushTip(void 0, void 0, createCanvas);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get a preset's tip, starting to load it if needed. Returns the round tip while loading or if loading fails.
|
|
32
|
+
*/
|
|
33
|
+
get(preset) {
|
|
34
|
+
if (!preset.image) return this.round;
|
|
35
|
+
const key = tipKey(preset);
|
|
36
|
+
const tip = this.tips.get(key);
|
|
37
|
+
if (tip) return tip;
|
|
38
|
+
if (!this.loading.has(key)) this.load(preset, key);
|
|
39
|
+
return this.round;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Start loading every preset's tip, so the first stroke with each preset already uses its shape.
|
|
43
|
+
*/
|
|
44
|
+
preload(presets) {
|
|
45
|
+
for (const preset of Object.values(presets)) this.get(preset);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Load a preset's tip and remember it under its key.
|
|
49
|
+
*/
|
|
50
|
+
async load(preset, key) {
|
|
51
|
+
this.loading.add(key);
|
|
52
|
+
try {
|
|
53
|
+
this.tips.set(key, await BrushTip.load(preset, this.decode, this.createCanvas));
|
|
54
|
+
this.dispatchEvent(new Event("change"));
|
|
55
|
+
} catch {
|
|
56
|
+
this.tips.set(key, this.round);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export { BrushTipCache as default };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type RandomFn } from "../../utils/random";
|
|
2
|
+
import type { TimedStrokePoint } from "../../messages/schema";
|
|
3
|
+
import type { BrushConfig, BrushStrokePoint } from "../types";
|
|
4
|
+
import type Layer from "../../classes/Layer";
|
|
5
|
+
import type { Rect } from "../../classes/Viewport";
|
|
6
|
+
import { type CanvasFactory } from "../../classes/Layer";
|
|
7
|
+
import type BrushTip from "../../rendering/BrushTip";
|
|
8
|
+
import type { LayerOverride } from "../../rendering/compositing";
|
|
9
|
+
/** Whether a stroke adds paint or erases */
|
|
10
|
+
export type StrokeMode = "paint" | "erase";
|
|
11
|
+
/** Everything needed to draw one stroke */
|
|
12
|
+
export interface StrokeOptions {
|
|
13
|
+
/** Layer the stroke is drawn on */
|
|
14
|
+
layer: Layer;
|
|
15
|
+
mode: StrokeMode;
|
|
16
|
+
preset: BrushConfig;
|
|
17
|
+
/** Size chosen by the user */
|
|
18
|
+
size: {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
};
|
|
22
|
+
/** Paint colour as a hex string */
|
|
23
|
+
colour: string;
|
|
24
|
+
tip: BrushTip;
|
|
25
|
+
/** Whether input comes from a pen (enables pressure and tilt) */
|
|
26
|
+
isPen: boolean;
|
|
27
|
+
/** Mask limiting where the stroke applies (its alpha scales the stroke), if a selection is active */
|
|
28
|
+
mask?: OffscreenCanvas;
|
|
29
|
+
/** Seed for the stroke's random variation, to draw a recorded stroke the same way again (a new one by default) */
|
|
30
|
+
seed?: number;
|
|
31
|
+
/** Random source for parameter variation, instead of one from `seed` (replaceable for tests) */
|
|
32
|
+
random?: RandomFn;
|
|
33
|
+
}
|
|
34
|
+
/** What a finished stroke was drawn from, so it can be sent and drawn again */
|
|
35
|
+
export interface RecordedStroke {
|
|
36
|
+
mode: StrokeMode;
|
|
37
|
+
preset: BrushConfig;
|
|
38
|
+
size: {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
};
|
|
42
|
+
colour: string;
|
|
43
|
+
isPen: boolean;
|
|
44
|
+
/** Seed of the stroke's random variation */
|
|
45
|
+
seed: number;
|
|
46
|
+
/** Input points as they arrived, before sampling and smoothing */
|
|
47
|
+
points: TimedStrokePoint[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Grow a rectangle to include another (the first may be empty).
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* unionRect({ x: 0, y: 0, width: 10, height: 10 }, { x: 20, y: 5, width: 5, height: 5 });
|
|
54
|
+
* // { x: 0, y: 0, width: 25, height: 10 }
|
|
55
|
+
*/
|
|
56
|
+
export declare const unionRect: (a: Rect | undefined, b: Rect) => Rect;
|
|
57
|
+
/**
|
|
58
|
+
* Snap a rectangle outwards to whole pixels and clip it to the canvas. Returns undefined if nothing is left.
|
|
59
|
+
*/
|
|
60
|
+
export declare const clipRect: (rect: Rect, width: number, height: number) => Rect | undefined;
|
|
61
|
+
/** Event dispatched just before a finished stroke is written into its layer */
|
|
62
|
+
export declare const BEFORE_COMMIT_EVENT = "beforecommit";
|
|
63
|
+
/** Event dispatched when a stroke starts */
|
|
64
|
+
export declare const STROKE_BEGIN_EVENT = "strokebegin";
|
|
65
|
+
/** Event dispatched when a stroke ends: written into its layer, or cancelled */
|
|
66
|
+
export declare const STROKE_END_EVENT = "strokeend";
|
|
67
|
+
/** Details of a `beforecommit` event: the layer, the area of it the stroke will change, and the stroke itself */
|
|
68
|
+
export interface StrokeCommitDetail {
|
|
69
|
+
layer: Layer;
|
|
70
|
+
area: Rect;
|
|
71
|
+
stroke: RecordedStroke;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Draws brush and eraser strokes.
|
|
75
|
+
*
|
|
76
|
+
* Stamps are drawn at full strength into a stroke buffer, so overlapping stamps within one stroke do not build up opacity.
|
|
77
|
+
* The buffer is merged into the layer with the stroke's opacity (the preset's `alpha`):
|
|
78
|
+
* - Brush: painted over the layer (or only onto existing pixels when the layer's alpha lock is on).
|
|
79
|
+
* - Eraser: removes the buffer's shape from the layer (does nothing when alpha lock is on).
|
|
80
|
+
* - With a mask, the buffer is first cut to the mask, so the stroke only applies inside it.
|
|
81
|
+
*
|
|
82
|
+
* While drawing, `preview` provides the layer with the stroke merged in, to draw instead of the layer. The stroke is written into the layer when it ends.
|
|
83
|
+
*
|
|
84
|
+
* Dispatches a `change` event whenever the preview changes, and when a stroke is committed or cancelled. Dispatches a
|
|
85
|
+
* `beforecommit` event (with `StrokeCommitDetail`) just before a stroke that changes its layer is written into it, so
|
|
86
|
+
* the area can be recorded for undo. Dispatches `strokebegin` when a stroke starts and `strokeend` when it's committed or
|
|
87
|
+
* cancelled.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* engine.begin(options, { x: 10, y: 10, pressure: 0.5 }, event.timeStamp);
|
|
91
|
+
* engine.move({ x: 20, y: 12 }, event.timeStamp);
|
|
92
|
+
* engine.end({ x: 25, y: 15 }, event.timeStamp);
|
|
93
|
+
*/
|
|
94
|
+
export default class StrokeEngine extends EventTarget {
|
|
95
|
+
/** Canvas width in pixels */
|
|
96
|
+
readonly width: number;
|
|
97
|
+
/** Canvas height in pixels */
|
|
98
|
+
readonly height: number;
|
|
99
|
+
private readonly createCanvas;
|
|
100
|
+
private bufferCanvas?;
|
|
101
|
+
private workingCanvas?;
|
|
102
|
+
private maskedCanvas?;
|
|
103
|
+
private active?;
|
|
104
|
+
/** Area of the preview changed since `takeChangedArea` was last called */
|
|
105
|
+
private changedArea?;
|
|
106
|
+
/** Whether strokes record their points and stamps for the debug overlay */
|
|
107
|
+
debugEnabled: boolean;
|
|
108
|
+
/** Points recorded and stamps placed by the current or last stroke (only while `debugEnabled`) */
|
|
109
|
+
readonly debugTrace: {
|
|
110
|
+
points: BrushStrokePoint[];
|
|
111
|
+
stamps: BrushStrokePoint[];
|
|
112
|
+
};
|
|
113
|
+
constructor(width: number, height: number, createCanvas?: CanvasFactory);
|
|
114
|
+
/**
|
|
115
|
+
* The area of the canvas whose preview changed since this was last called (stamps placed, or a stroke cancelled or
|
|
116
|
+
* written into its layer), to redraw only that area; undefined if nothing changed.
|
|
117
|
+
*/
|
|
118
|
+
takeChangedArea(): Rect | undefined;
|
|
119
|
+
/** Whether a stroke is in progress */
|
|
120
|
+
get drawing(): boolean;
|
|
121
|
+
/** The layer with the stroke in progress merged in, to draw in its place; undefined when not drawing */
|
|
122
|
+
get preview(): LayerOverride | undefined;
|
|
123
|
+
/** The stroke buffer (created on first use) */
|
|
124
|
+
private get buffer();
|
|
125
|
+
/** The preview canvas (created on first use) */
|
|
126
|
+
private get working();
|
|
127
|
+
/**
|
|
128
|
+
* Turn recording of stroke points and stamps (for the debug overlay) on or off.
|
|
129
|
+
*/
|
|
130
|
+
setDebug(enabled: boolean): void;
|
|
131
|
+
/**
|
|
132
|
+
* Record a sampled point for the debug overlay.
|
|
133
|
+
*/
|
|
134
|
+
private trace;
|
|
135
|
+
/**
|
|
136
|
+
* Start a stroke at the pointer-down point. Cancels any stroke already in progress.
|
|
137
|
+
*/
|
|
138
|
+
begin(options: StrokeOptions, point: BrushStrokePoint, time: number): void;
|
|
139
|
+
/**
|
|
140
|
+
* Continue the stroke as the pointer moves. Points are recorded at the preset's sample rate.
|
|
141
|
+
*/
|
|
142
|
+
move(point: BrushStrokePoint, time: number): void;
|
|
143
|
+
/**
|
|
144
|
+
* Finish the stroke at the pointer-up point and write it into the layer.
|
|
145
|
+
*/
|
|
146
|
+
end(point: BrushStrokePoint, time: number): void;
|
|
147
|
+
/**
|
|
148
|
+
* Abandon the stroke in progress without changing the layer.
|
|
149
|
+
*/
|
|
150
|
+
cancel(): void;
|
|
151
|
+
/**
|
|
152
|
+
* Stamp the shape at each point into the buffer, then refresh the preview where it changed.
|
|
153
|
+
*/
|
|
154
|
+
private place;
|
|
155
|
+
/**
|
|
156
|
+
* Merge the buffer into a target canvas within an area. For the preview, the area is first reset to the layer's pixels.
|
|
157
|
+
*/
|
|
158
|
+
private mergeInto;
|
|
159
|
+
/**
|
|
160
|
+
* The stroke buffer, cut to the mask within an area when a mask is active (partially masked areas let partial paint through).
|
|
161
|
+
*/
|
|
162
|
+
private strokeImage;
|
|
163
|
+
/**
|
|
164
|
+
* Write the finished stroke into its layer and reset for the next stroke.
|
|
165
|
+
*/
|
|
166
|
+
private commit;
|
|
167
|
+
/**
|
|
168
|
+
* Clear an area of the stroke buffer.
|
|
169
|
+
*/
|
|
170
|
+
private clearBuffer;
|
|
171
|
+
}
|