@lvl99dotcom/paintcanvas 0.0.0-stage → 0.2.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 (284) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +131 -2
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +5 -0
  5. package/dist/lib/brushes/BrushTipCache/index.d.ts +32 -0
  6. package/dist/lib/brushes/BrushTipCache/index.js +60 -0
  7. package/dist/lib/brushes/StrokeEngine/index.d.ts +171 -0
  8. package/dist/lib/brushes/StrokeEngine/index.js +324 -0
  9. package/dist/lib/brushes/StrokePath/index.d.ts +53 -0
  10. package/dist/lib/brushes/StrokePath/index.js +161 -0
  11. package/dist/lib/brushes/StrokeSampler/index.d.ts +55 -0
  12. package/dist/lib/brushes/StrokeSampler/index.js +75 -0
  13. package/dist/lib/brushes/authors/index.d.ts +55 -0
  14. package/dist/lib/brushes/authors/index.js +60 -0
  15. package/dist/lib/brushes/configRanges/index.d.ts +52 -0
  16. package/dist/lib/brushes/configRanges/index.js +206 -0
  17. package/dist/lib/brushes/index.d.ts +5 -0
  18. package/dist/lib/brushes/index.js +19 -0
  19. package/dist/lib/brushes/params/index.d.ts +108 -0
  20. package/dist/lib/brushes/params/index.js +139 -0
  21. package/dist/lib/brushes/presetFile/index.d.ts +32 -0
  22. package/dist/lib/brushes/presetFile/index.js +55 -0
  23. package/dist/lib/brushes/presets/drawing/brush-pen.js +3 -0
  24. package/dist/lib/brushes/presets/drawing/felt-pen.js +3 -0
  25. package/dist/lib/brushes/presets/drawing/index.d.ts +13 -0
  26. package/dist/lib/brushes/presets/drawing/index.js +88 -0
  27. package/dist/lib/brushes/presets/drawing/pencil-2b.js +3 -0
  28. package/dist/lib/brushes/presets/drawing/pencil-hb.js +3 -0
  29. package/dist/lib/brushes/presets/painting/grass.js +3 -0
  30. package/dist/lib/brushes/presets/painting/hair.js +3 -0
  31. package/dist/lib/brushes/presets/painting/index.d.ts +18 -0
  32. package/dist/lib/brushes/presets/painting/index.js +118 -0
  33. package/dist/lib/brushes/presets/painting/splatter.js +3 -0
  34. package/dist/lib/brushes/presets/painting/textured-paint.js +3 -0
  35. package/dist/lib/brushes/presets/painting/watery-paint.js +3 -0
  36. package/dist/lib/brushes/presets/round/index.d.ts +9 -0
  37. package/dist/lib/brushes/presets/round/index.js +44 -0
  38. package/dist/lib/brushes/presets/round/round.js +3 -0
  39. package/dist/lib/brushes/presets/round/soft-round.js +3 -0
  40. package/dist/lib/brushes/presets/sized/index.d.ts +20 -0
  41. package/dist/lib/brushes/presets/sized/index.js +30 -0
  42. package/dist/lib/brushes/presets/sketching/index.d.ts +14 -0
  43. package/dist/lib/brushes/presets/sketching/index.js +107 -0
  44. package/dist/lib/brushes/presets/square/index.d.ts +7 -0
  45. package/dist/lib/brushes/presets/square/index.js +22 -0
  46. package/dist/lib/brushes/presets/square/square.js +3 -0
  47. package/dist/lib/brushes/shapeImage/index.d.ts +40 -0
  48. package/dist/lib/brushes/shapeImage/index.js +61 -0
  49. package/dist/lib/brushes/types/index.d.ts +243 -0
  50. package/dist/lib/brushes/types/index.js +20 -0
  51. package/dist/lib/classes/BackgroundWork/index.d.ts +55 -0
  52. package/dist/lib/classes/BackgroundWork/index.js +97 -0
  53. package/dist/lib/classes/BrushSettings/index.d.ts +91 -0
  54. package/dist/lib/classes/BrushSettings/index.js +152 -0
  55. package/dist/lib/classes/CustomPresets/index.d.ts +53 -0
  56. package/dist/lib/classes/CustomPresets/index.js +71 -0
  57. package/dist/lib/classes/ExternalSheets/index.d.ts +64 -0
  58. package/dist/lib/classes/ExternalSheets/index.js +112 -0
  59. package/dist/lib/classes/GestureTracker/index.d.ts +62 -0
  60. package/dist/lib/classes/GestureTracker/index.js +122 -0
  61. package/dist/lib/classes/History/index.d.ts +83 -0
  62. package/dist/lib/classes/History/index.js +126 -0
  63. package/dist/lib/classes/HistoryGuard/index.d.ts +58 -0
  64. package/dist/lib/classes/HistoryGuard/index.js +97 -0
  65. package/dist/lib/classes/InputSettings/index.d.ts +74 -0
  66. package/dist/lib/classes/InputSettings/index.js +101 -0
  67. package/dist/lib/classes/KeyboardShortcuts/index.d.ts +48 -0
  68. package/dist/lib/classes/KeyboardShortcuts/index.js +137 -0
  69. package/dist/lib/classes/Layer/index.d.ts +86 -0
  70. package/dist/lib/classes/Layer/index.js +111 -0
  71. package/dist/lib/classes/LayerAutosave/index.d.ts +180 -0
  72. package/dist/lib/classes/LayerAutosave/index.js +346 -0
  73. package/dist/lib/classes/LayerStack/index.d.ts +177 -0
  74. package/dist/lib/classes/LayerStack/index.js +394 -0
  75. package/dist/lib/classes/PaintCanvas/index.d.ts +537 -0
  76. package/dist/lib/classes/PaintCanvas/index.js +965 -0
  77. package/dist/lib/classes/StrokeLog/index.d.ts +149 -0
  78. package/dist/lib/classes/StrokeLog/index.js +257 -0
  79. package/dist/lib/classes/Viewport/index.d.ts +108 -0
  80. package/dist/lib/classes/Viewport/index.js +194 -0
  81. package/dist/lib/document/index.d.ts +17 -0
  82. package/dist/lib/document/index.js +25 -0
  83. package/dist/lib/document/schema.d.ts +132 -0
  84. package/dist/lib/document/schema.js +110 -0
  85. package/dist/lib/i18n/index.d.ts +94 -0
  86. package/dist/lib/i18n/index.js +182 -0
  87. package/dist/lib/image/index.d.ts +90 -0
  88. package/dist/lib/image/index.js +147 -0
  89. package/dist/lib/messages/PatchSender/index.d.ts +75 -0
  90. package/dist/lib/messages/PatchSender/index.js +125 -0
  91. package/dist/lib/messages/index.d.ts +26 -0
  92. package/dist/lib/messages/index.js +59 -0
  93. package/dist/lib/messages/schema.d.ts +1775 -0
  94. package/dist/lib/messages/schema.js +192 -0
  95. package/dist/lib/presets/index.d.ts +32 -0
  96. package/dist/lib/presets/index.js +35 -0
  97. package/dist/lib/presets/schema.d.ts +753 -0
  98. package/dist/lib/presets/schema.js +181 -0
  99. package/dist/lib/rendering/BrushTip/index.d.ts +63 -0
  100. package/dist/lib/rendering/BrushTip/index.js +112 -0
  101. package/dist/lib/rendering/checkerboard/index.d.ts +22 -0
  102. package/dist/lib/rendering/checkerboard/index.js +31 -0
  103. package/dist/lib/rendering/compositing/index.d.ts +64 -0
  104. package/dist/lib/rendering/compositing/index.js +124 -0
  105. package/dist/lib/rendering/cursor/index.d.ts +14 -0
  106. package/dist/lib/rendering/cursor/index.js +39 -0
  107. package/dist/lib/rendering/cursors/index.d.ts +18 -0
  108. package/dist/lib/rendering/cursors/index.js +23 -0
  109. package/dist/lib/rendering/maskOutline/index.d.ts +22 -0
  110. package/dist/lib/rendering/maskOutline/index.js +78 -0
  111. package/dist/lib/rendering/outline/index.d.ts +36 -0
  112. package/dist/lib/rendering/outline/index.js +120 -0
  113. package/dist/lib/rendering/sample/index.d.ts +55 -0
  114. package/dist/lib/rendering/sample/index.js +83 -0
  115. package/dist/lib/rendering/screenshot/index.d.ts +67 -0
  116. package/dist/lib/rendering/screenshot/index.js +96 -0
  117. package/dist/lib/rendering/transformBox/index.d.ts +10 -0
  118. package/dist/lib/rendering/transformBox/index.js +57 -0
  119. package/dist/lib/selection/Lasso/index.d.ts +70 -0
  120. package/dist/lib/selection/Lasso/index.js +156 -0
  121. package/dist/lib/selection/Selection/index.d.ts +86 -0
  122. package/dist/lib/selection/Selection/index.js +228 -0
  123. package/dist/lib/selection/geometry/index.d.ts +37 -0
  124. package/dist/lib/selection/geometry/index.js +57 -0
  125. package/dist/lib/storage/index.d.ts +63 -0
  126. package/dist/lib/storage/index.js +114 -0
  127. package/dist/lib/transform/Transformer/index.d.ts +124 -0
  128. package/dist/lib/transform/Transformer/index.js +286 -0
  129. package/dist/lib/transform/geometry/index.d.ts +95 -0
  130. package/dist/lib/transform/geometry/index.js +258 -0
  131. package/dist/lib/utils/array/index.d.ts +10 -0
  132. package/dist/lib/utils/array/index.js +21 -0
  133. package/dist/lib/utils/gestures/index.d.ts +35 -0
  134. package/dist/lib/utils/gestures/index.js +81 -0
  135. package/dist/lib/utils/navigation/index.d.ts +51 -0
  136. package/dist/lib/utils/navigation/index.js +59 -0
  137. package/dist/lib/utils/random/index.d.ts +18 -0
  138. package/dist/lib/utils/random/index.js +27 -0
  139. package/dist/lib/utils/shortcuts/index.d.ts +74 -0
  140. package/dist/lib/utils/shortcuts/index.js +189 -0
  141. package/dist/lib/validation/validators.generated.d.ts +27 -0
  142. package/dist/lib/validation/validators.generated.js +19826 -0
  143. package/dist/locales/en-GB.js +188 -0
  144. package/dist/locales/en-US.js +188 -0
  145. package/dist/locales/fr.js +188 -0
  146. package/dist/locales/ja.js +188 -0
  147. package/dist/locales/ko.js +188 -0
  148. package/dist/locales/zh-Hans.js +188 -0
  149. package/dist/locales/zh-Hant.js +188 -0
  150. package/dist/package.js +3 -0
  151. package/dist/testing/app.d.ts +7 -0
  152. package/dist/testing/app.js +16 -0
  153. package/dist/testing/elements.d.ts +42 -0
  154. package/dist/testing/elements.js +58 -0
  155. package/dist/testing/fakeCanvas.d.ts +21 -0
  156. package/dist/testing/fakeCanvas.js +26 -0
  157. package/dist/testing/layerStore.d.ts +26 -0
  158. package/dist/testing/layerStore.js +43 -0
  159. package/dist/testing/locks.d.ts +15 -0
  160. package/dist/testing/locks.js +41 -0
  161. package/dist/testing/recordingCanvas.d.ts +14 -0
  162. package/dist/testing/recordingCanvas.js +28 -0
  163. package/dist/testing/recordingContext.d.ts +10 -0
  164. package/dist/testing/recordingContext.js +19 -0
  165. package/dist/ui/ChangeController/index.d.ts +40 -0
  166. package/dist/ui/ChangeController/index.js +62 -0
  167. package/dist/ui/base/index.d.ts +69 -0
  168. package/dist/ui/base/index.js +94 -0
  169. package/dist/ui/elements/PaintCanvas/index.d.ts +249 -0
  170. package/dist/ui/elements/PaintCanvas/index.js +584 -0
  171. package/dist/ui/elements/PaintCanvas/style.js +3 -0
  172. package/dist/ui/elements/PcBrushConfig/index.d.ts +130 -0
  173. package/dist/ui/elements/PcBrushConfig/index.js +463 -0
  174. package/dist/ui/elements/PcBrushConfig/style.js +3 -0
  175. package/dist/ui/elements/PcBrushMenu/index.d.ts +121 -0
  176. package/dist/ui/elements/PcBrushMenu/index.js +362 -0
  177. package/dist/ui/elements/PcBrushMenu/style.js +3 -0
  178. package/dist/ui/elements/PcBrushTest/index.d.ts +71 -0
  179. package/dist/ui/elements/PcBrushTest/index.js +136 -0
  180. package/dist/ui/elements/PcBrushTest/style.js +3 -0
  181. package/dist/ui/elements/PcButton/index.d.ts +57 -0
  182. package/dist/ui/elements/PcButton/index.js +124 -0
  183. package/dist/ui/elements/PcButtonGroup/index.d.ts +44 -0
  184. package/dist/ui/elements/PcButtonGroup/index.js +93 -0
  185. package/dist/ui/elements/PcCanvas/index.d.ts +356 -0
  186. package/dist/ui/elements/PcCanvas/index.js +1004 -0
  187. package/dist/ui/elements/PcCanvas/style.js +3 -0
  188. package/dist/ui/elements/PcCanvasMap/index.d.ts +96 -0
  189. package/dist/ui/elements/PcCanvasMap/index.js +187 -0
  190. package/dist/ui/elements/PcCanvasMap/style.js +3 -0
  191. package/dist/ui/elements/PcContextMenu/index.d.ts +72 -0
  192. package/dist/ui/elements/PcContextMenu/index.js +148 -0
  193. package/dist/ui/elements/PcDialog/index.d.ts +63 -0
  194. package/dist/ui/elements/PcDialog/index.js +114 -0
  195. package/dist/ui/elements/PcIcon/index.d.ts +36 -0
  196. package/dist/ui/elements/PcIcon/index.js +43 -0
  197. package/dist/ui/elements/PcIconToggle/index.d.ts +46 -0
  198. package/dist/ui/elements/PcIconToggle/index.js +87 -0
  199. package/dist/ui/elements/PcInfoTip/index.d.ts +40 -0
  200. package/dist/ui/elements/PcInfoTip/index.js +95 -0
  201. package/dist/ui/elements/PcInputSettings/index.d.ts +69 -0
  202. package/dist/ui/elements/PcInputSettings/index.js +150 -0
  203. package/dist/ui/elements/PcLayerItem/index.d.ts +221 -0
  204. package/dist/ui/elements/PcLayerItem/index.js +561 -0
  205. package/dist/ui/elements/PcLayerItem/style.js +3 -0
  206. package/dist/ui/elements/PcLayersMenu/index.d.ts +108 -0
  207. package/dist/ui/elements/PcLayersMenu/index.js +208 -0
  208. package/dist/ui/elements/PcLayersMenu/style.js +3 -0
  209. package/dist/ui/elements/PcMatch/index.d.ts +31 -0
  210. package/dist/ui/elements/PcMatch/index.js +58 -0
  211. package/dist/ui/elements/PcPanel/index.d.ts +43 -0
  212. package/dist/ui/elements/PcPanel/index.js +51 -0
  213. package/dist/ui/elements/PcPopover/index.d.ts +48 -0
  214. package/dist/ui/elements/PcPopover/index.js +86 -0
  215. package/dist/ui/elements/PcSlider/index.d.ts +57 -0
  216. package/dist/ui/elements/PcSlider/index.js +88 -0
  217. package/dist/ui/elements/PcStats/index.d.ts +54 -0
  218. package/dist/ui/elements/PcStats/index.js +141 -0
  219. package/dist/ui/elements/PcThemePicker/index.d.ts +56 -0
  220. package/dist/ui/elements/PcThemePicker/index.js +134 -0
  221. package/dist/ui/elements/PcToast/index.d.ts +58 -0
  222. package/dist/ui/elements/PcToast/index.js +110 -0
  223. package/dist/ui/elements/PcToggleCheckbox/index.d.ts +37 -0
  224. package/dist/ui/elements/PcToggleCheckbox/index.js +105 -0
  225. package/dist/ui/elements/PcToolSettings/index.d.ts +128 -0
  226. package/dist/ui/elements/PcToolSettings/index.js +543 -0
  227. package/dist/ui/elements/PcToolSettings/style.js +3 -0
  228. package/dist/ui/elements/PcToolbar/index.d.ts +71 -0
  229. package/dist/ui/elements/PcToolbar/index.js +190 -0
  230. package/dist/ui/elements/PcToolbar/style.js +3 -0
  231. package/dist/ui/icons/images/brush.js +3 -0
  232. package/dist/ui/icons/images/circle-mask.js +3 -0
  233. package/dist/ui/icons/images/clipboard.js +3 -0
  234. package/dist/ui/icons/images/cursor.js +3 -0
  235. package/dist/ui/icons/images/eraser.js +3 -0
  236. package/dist/ui/icons/images/eyedropper.js +3 -0
  237. package/dist/ui/icons/images/flip-horizontal.js +3 -0
  238. package/dist/ui/icons/images/flip-vertical.js +3 -0
  239. package/dist/ui/icons/images/focus-pen.js +3 -0
  240. package/dist/ui/icons/images/freehand-mask.js +3 -0
  241. package/dist/ui/icons/images/hidden.js +3 -0
  242. package/dist/ui/icons/images/layers.js +3 -0
  243. package/dist/ui/icons/images/linked.js +3 -0
  244. package/dist/ui/icons/images/locked.js +3 -0
  245. package/dist/ui/icons/images/moon.js +3 -0
  246. package/dist/ui/icons/images/pan.js +3 -0
  247. package/dist/ui/icons/images/polygon-mask.js +3 -0
  248. package/dist/ui/icons/images/pressure.js +3 -0
  249. package/dist/ui/icons/images/randomise.js +3 -0
  250. package/dist/ui/icons/images/rectangle-mask.js +3 -0
  251. package/dist/ui/icons/images/redo.js +3 -0
  252. package/dist/ui/icons/images/rotate-90-left.js +3 -0
  253. package/dist/ui/icons/images/rotate-90-right.js +3 -0
  254. package/dist/ui/icons/images/smoothing-bezier-cubic.js +3 -0
  255. package/dist/ui/icons/images/smoothing-bezier-quad.js +3 -0
  256. package/dist/ui/icons/images/smoothing-linear.js +3 -0
  257. package/dist/ui/icons/images/star.js +3 -0
  258. package/dist/ui/icons/images/sun.js +3 -0
  259. package/dist/ui/icons/images/tilt.js +3 -0
  260. package/dist/ui/icons/images/undo.js +3 -0
  261. package/dist/ui/icons/images/unlinked.js +3 -0
  262. package/dist/ui/icons/images/unlocked.js +3 -0
  263. package/dist/ui/icons/images/visible.js +3 -0
  264. package/dist/ui/icons/images/zoom-in.js +3 -0
  265. package/dist/ui/icons/images/zoom-out.js +3 -0
  266. package/dist/ui/icons/images/zoom.js +3 -0
  267. package/dist/ui/icons/index.d.ts +42 -0
  268. package/dist/ui/icons/index.js +130 -0
  269. package/dist/ui/index.d.ts +21 -0
  270. package/dist/ui/index.js +22 -0
  271. package/dist/ui/layout/index.d.ts +88 -0
  272. package/dist/ui/layout/index.js +96 -0
  273. package/dist/ui/styles/index.d.ts +13 -0
  274. package/dist/ui/styles/index.js +195 -0
  275. package/dist/ui/tokens/index.d.ts +29 -0
  276. package/dist/ui/tokens/index.js +114 -0
  277. package/locales/en-GB.json +186 -0
  278. package/locales/en-US.json +186 -0
  279. package/locales/fr.json +186 -0
  280. package/locales/ja.json +186 -0
  281. package/locales/ko.json +186 -0
  282. package/locales/zh-Hans.json +186 -0
  283. package/locales/zh-Hant.json +186 -0
  284. package/package.json +97 -3
@@ -0,0 +1,62 @@
1
+ // src/ui/ChangeController/index.ts
2
+ /**
3
+ * Re-renders a Lit component whenever any of the given state objects dispatch a `change` event, first telling
4
+ * `onChange` (if given) which one changed.
5
+ *
6
+ * The targets are re-read before every update, so replaced state objects (e.g. new layers after a canvas resize) are picked up.
7
+ *
8
+ * @example
9
+ * class MyElement extends LitElement {
10
+ * private changes = new ChangeController(this, () => [this.app, this.app?.layers]);
11
+ * }
12
+ */
13
+ var ChangeController = class {
14
+ host;
15
+ getTargets;
16
+ subscribed = [];
17
+ notify;
18
+ onChange = (event) => {
19
+ this.notify?.(event.currentTarget);
20
+ this.host.requestUpdate();
21
+ };
22
+ constructor(host, getTargets, onChange) {
23
+ this.host = host;
24
+ this.getTargets = getTargets;
25
+ this.notify = onChange;
26
+ host.addController(this);
27
+ }
28
+ /**
29
+ * Subscribe to the current targets, replacing any previous subscriptions.
30
+ */
31
+ refresh() {
32
+ this.unsubscribe();
33
+ this.subscribed = this.getTargets().filter((t) => t !== void 0);
34
+ for (const target of this.subscribed) target.addEventListener("change", this.onChange);
35
+ }
36
+ /**
37
+ * Subscribe when the component connects.
38
+ */
39
+ hostConnected() {
40
+ this.refresh();
41
+ }
42
+ /**
43
+ * Re-subscribe before each update in case targets were replaced.
44
+ */
45
+ hostUpdate() {
46
+ this.refresh();
47
+ }
48
+ /**
49
+ * Unsubscribe when the component disconnects.
50
+ */
51
+ hostDisconnected() {
52
+ this.unsubscribe();
53
+ }
54
+ /**
55
+ * Remove all subscriptions.
56
+ */
57
+ unsubscribe() {
58
+ for (const target of this.subscribed) target.removeEventListener("change", this.onChange);
59
+ this.subscribed = [];
60
+ }
61
+ };
62
+ export { ChangeController as default };
@@ -0,0 +1,69 @@
1
+ import { LitElement, type CSSResultGroup } from "lit";
2
+ import { type IconRegistry } from "../icons";
3
+ import Translations from "../../lib/i18n";
4
+ /**
5
+ * Register a custom element unless the name is already registered (e.g. by another copy of PaintCanvas, or after hot
6
+ * module reload).
7
+ *
8
+ * @example
9
+ * defineElement("pc-button", PcButton);
10
+ */
11
+ export declare const defineElement: (name: string, constructor: CustomElementConstructor) => void;
12
+ /**
13
+ * Dispatch a custom event that crosses shadow DOM boundaries, so the implementer can listen anywhere above.
14
+ *
15
+ * @example
16
+ * emit(this, "pc-select", { value: "duplicate" });
17
+ */
18
+ export declare const emit: <T>(target: EventTarget, type: string, detail?: T) => boolean;
19
+ /**
20
+ * The base of PaintCanvas's elements: the design tokens, the translations and icons they use (shared ones unless
21
+ * given others), and re-rendering when either changes.
22
+ *
23
+ * @example
24
+ * class PcThing extends PcElement {
25
+ * override render() {
26
+ * return html`<button>${this.t("common.close")}</button>`;
27
+ * }
28
+ * }
29
+ */
30
+ export declare class PcElement extends LitElement {
31
+ static styles: CSSResultGroup;
32
+ static properties: {
33
+ translations: {
34
+ attribute: boolean;
35
+ };
36
+ icons: {
37
+ attribute: boolean;
38
+ };
39
+ theme: {
40
+ type: StringConstructor;
41
+ reflect: boolean;
42
+ };
43
+ };
44
+ /** The text the element shows, in the chosen language */
45
+ translations: Translations;
46
+ /** The icons the element shows */
47
+ icons: IconRegistry;
48
+ /** "light" (default), "dark", or "auto" to follow the device (see the design tokens) */
49
+ theme?: "light" | "dark" | "auto";
50
+ /** The translations and icons being listened to */
51
+ private watched;
52
+ private readonly onSourceChange;
53
+ constructor();
54
+ /**
55
+ * An icon's URL from the element's icons, or "" if there's none by that name.
56
+ */
57
+ protected iconUrl(name: string): string;
58
+ /**
59
+ * Translate a key with the element's translations.
60
+ */
61
+ protected t(key: string, values?: Record<string, string | number>): string;
62
+ connectedCallback(): void;
63
+ disconnectedCallback(): void;
64
+ protected willUpdate(changed: Map<PropertyKey, unknown>): void;
65
+ /** Listen to the current translations and icons */
66
+ private watch;
67
+ /** Stop listening */
68
+ private unwatch;
69
+ }
@@ -0,0 +1,94 @@
1
+ import { installTokens, tokens } from "../tokens/index.js";
2
+ import { icons } from "../icons/index.js";
3
+ import { translations } from "../../lib/i18n/index.js";
4
+ import { LitElement } from "lit";
5
+ // src/ui/base/index.ts
6
+ /**
7
+ * Register a custom element unless the name is already registered (e.g. by another copy of PaintCanvas, or after hot
8
+ * module reload).
9
+ *
10
+ * @example
11
+ * defineElement("pc-button", PcButton);
12
+ */
13
+ var defineElement = (name, constructor) => {
14
+ if (!customElements.get(name)) customElements.define(name, constructor);
15
+ };
16
+ /**
17
+ * Dispatch a custom event that crosses shadow DOM boundaries, so the implementer can listen anywhere above.
18
+ *
19
+ * @example
20
+ * emit(this, "pc-select", { value: "duplicate" });
21
+ */
22
+ var emit = (target, type, detail) => target.dispatchEvent(new CustomEvent(type, {
23
+ detail,
24
+ bubbles: true,
25
+ composed: true,
26
+ cancelable: true
27
+ }));
28
+ /**
29
+ * The base of PaintCanvas's elements: the design tokens, the translations and icons they use (shared ones unless
30
+ * given others), and re-rendering when either changes.
31
+ *
32
+ * @example
33
+ * class PcThing extends PcElement {
34
+ * override render() {
35
+ * return html`<button>${this.t("common.close")}</button>`;
36
+ * }
37
+ * }
38
+ */
39
+ var PcElement = class extends LitElement {
40
+ static styles = [tokens];
41
+ static properties = {
42
+ translations: { attribute: false },
43
+ icons: { attribute: false },
44
+ theme: {
45
+ type: String,
46
+ reflect: true
47
+ }
48
+ };
49
+ /** The translations and icons being listened to */
50
+ watched = [];
51
+ onSourceChange = () => this.requestUpdate();
52
+ constructor() {
53
+ super();
54
+ this.translations = translations;
55
+ this.icons = icons;
56
+ }
57
+ /**
58
+ * An icon's URL from the element's icons, or "" if there's none by that name.
59
+ */
60
+ iconUrl(name) {
61
+ return this.icons.get(name) ?? "";
62
+ }
63
+ /**
64
+ * Translate a key with the element's translations.
65
+ */
66
+ t(key, values) {
67
+ return this.translations.t(key, values);
68
+ }
69
+ connectedCallback() {
70
+ super.connectedCallback();
71
+ installTokens(this.ownerDocument);
72
+ this.watch();
73
+ }
74
+ disconnectedCallback() {
75
+ super.disconnectedCallback();
76
+ this.unwatch();
77
+ }
78
+ willUpdate(changed) {
79
+ super.willUpdate(changed);
80
+ if (this.isConnected && (changed.has("translations") || changed.has("icons"))) this.watch();
81
+ }
82
+ /** Listen to the current translations and icons */
83
+ watch() {
84
+ this.unwatch();
85
+ this.watched = [this.translations, this.icons];
86
+ for (const source of this.watched) source.addEventListener("change", this.onSourceChange);
87
+ }
88
+ /** Stop listening */
89
+ unwatch() {
90
+ for (const source of this.watched) source.removeEventListener("change", this.onSourceChange);
91
+ this.watched = [];
92
+ }
93
+ };
94
+ export { PcElement, defineElement, emit };
@@ -0,0 +1,249 @@
1
+ import { PcElement } from "../../base";
2
+ import PaintCanvas from "../../../lib/classes/PaintCanvas";
3
+ import type { BrushConfig } from "../../../lib/brushes/types";
4
+ import { type SaveMethod } from "../../../lib/rendering/screenshot";
5
+ import { type InputKind, type LayoutState } from "../../layout";
6
+ import type { PcPanel } from "../PcPanel";
7
+ import "../PcPanel";
8
+ import "../PcToolbar";
9
+ import "../PcToolSettings";
10
+ import "../PcCanvas";
11
+ import "../PcCanvasMap";
12
+ import "../PcBrushMenu";
13
+ import "../PcLayersMenu";
14
+ import "../PcBrushConfig";
15
+ import "../PcStats";
16
+ import "../PcDialog";
17
+ /** A side of the layout */
18
+ type Side = "left" | "right";
19
+ /**
20
+ * A ready-made painting app: the drawing elements arranged around the canvas, sized to its container (not the
21
+ * window), with slots to add or replace content:
22
+ *
23
+ * - `header`: across the top (empty by default)
24
+ * - `left`: `<pc-toolbar>` by default
25
+ * - `top`: `<pc-tool-settings>` (for tools that have settings) by default
26
+ * - `right`: empty by default (e.g. a `<pc-panel>` with a layers menu or chat)
27
+ * - `center`: `<pc-canvas>` by default
28
+ * - `overlay`: drawn over the canvas; `<pc-canvas-map>` by default
29
+ * - `bottom`: under the canvas (empty by default)
30
+ * - `footer`: across the bottom; `<pc-stats>` by default
31
+ * - `menu`: the app menu the toolbar's menu button opens (the button shows only with a menu)
32
+ *
33
+ * Content given for a slot replaces its default; an empty element clears it. Empty slots take no space. Hiding the
34
+ * interface (Tab key) leaves only the canvas and overlay. A `<pc-layers-menu>` given in a side (e.g. in a `<pc-panel>`)
35
+ * replaces the toolbar's layers menu button.
36
+ *
37
+ * Each side has a mode, chosen by the layout's width from `left-modes` and `right-modes` (default `"docked,
38
+ * rail@600"`): `docked` beside the canvas; `rail`, a column of buttons (one per `<pc-panel>`) that open each panel over
39
+ * the canvas; or `floating`, the side over the canvas as a palette that collapses to a button.
40
+ *
41
+ * Reports its state for styling as attributes (`narrow`, `input="pen|touch|mouse"`, `ui-hidden`, `left-mode`,
42
+ * `right-mode`) and as `pc-state-change` events (see `LayoutState`). Creates its own canvas unless given one, and
43
+ * handles keyboard shortcuts unless `shortcuts` is false.
44
+ *
45
+ * With a `store` name, the user's layers are kept in the browser (IndexedDB) under that name, so the drawing survives
46
+ * reloading the page (see `LayerAutosave`). While another window is drawing on it, the layout is blocked by a message
47
+ * that offers to draw here instead. Fires `pc-toast` when the drawing can't be loaded or saved.
48
+ *
49
+ * @example
50
+ * html`<paint-canvas style="height: 600px"></paint-canvas>`
51
+ * html`<paint-canvas .app=${canvas} right-modes="docked, rail@800">
52
+ * <pc-panel slot="right" icon="layers" label="Layers"><pc-layers-menu .app=${canvas}></pc-layers-menu></pc-panel>
53
+ * </paint-canvas>`
54
+ */
55
+ export declare class PaintCanvasElement extends PcElement {
56
+ static properties: {
57
+ app: {
58
+ attribute: boolean;
59
+ };
60
+ leftModes: {
61
+ type: StringConstructor;
62
+ attribute: string;
63
+ };
64
+ rightModes: {
65
+ type: StringConstructor;
66
+ attribute: string;
67
+ };
68
+ narrowWidth: {
69
+ type: NumberConstructor;
70
+ attribute: string;
71
+ };
72
+ menuText: {
73
+ type: StringConstructor;
74
+ attribute: string;
75
+ };
76
+ menuLabel: {
77
+ type: StringConstructor;
78
+ attribute: string;
79
+ };
80
+ shortcuts: {
81
+ type: BooleanConstructor;
82
+ };
83
+ store: {
84
+ type: StringConstructor;
85
+ };
86
+ width: {
87
+ state: boolean;
88
+ };
89
+ input: {
90
+ state: boolean;
91
+ };
92
+ configuring: {
93
+ state: boolean;
94
+ };
95
+ collapsed: {
96
+ state: boolean;
97
+ };
98
+ openPanel: {
99
+ state: boolean;
100
+ };
101
+ translations: {
102
+ attribute: boolean;
103
+ };
104
+ icons: {
105
+ attribute: boolean;
106
+ };
107
+ theme: {
108
+ type: StringConstructor;
109
+ reflect: boolean;
110
+ };
111
+ };
112
+ static styles: import("lit").CSSResultGroup[];
113
+ /** The canvas (one is created if none is given) */
114
+ app?: PaintCanvas;
115
+ /** The left side's modes (see `parseSideModes`) */
116
+ leftModes: string;
117
+ /** The right side's modes (see `parseSideModes`) */
118
+ rightModes: string;
119
+ /** Width (CSS pixels) below which the layout is narrow */
120
+ narrowWidth: number;
121
+ /** What the toolbar's menu button shows */
122
+ menuText: string;
123
+ /** The toolbar's menu button's name for screen readers */
124
+ menuLabel?: string;
125
+ /** Whether the layout handles keyboard shortcuts (default true) */
126
+ shortcuts: boolean;
127
+ /** Name to keep the user's layers under in the browser, so the drawing survives reloading the page (none by default) */
128
+ store?: string;
129
+ /** The layout's width in CSS pixels */
130
+ width: number;
131
+ /** The input being used now */
132
+ input: InputKind;
133
+ /** The brush or eraser configuration window, while open */
134
+ configuring?: {
135
+ kind: "brush" | "eraser";
136
+ config: BrushConfig;
137
+ editingId?: string;
138
+ };
139
+ /** Which floating sides are collapsed to a button */
140
+ collapsed: Record<Side, boolean>;
141
+ /** The panel open from a rail, if any */
142
+ openPanel?: PcPanel;
143
+ /** Saves files (replaceable for tests) */
144
+ saveFile: (blob: Blob, name: string) => Promise<SaveMethod | undefined>;
145
+ private changes;
146
+ /** The autosave the layout started for `store`, if any */
147
+ private ownAutosave?;
148
+ /** The autosave whose errors are shown */
149
+ private watchedAutosave?;
150
+ /** Whether drawing was blocked when shortcuts were last watched */
151
+ private blockedShortcuts;
152
+ /** The panels in each side's slot */
153
+ private panels;
154
+ /** Whether each side's slot has a layers menu (the toolbar's isn't needed then) */
155
+ private sideLayers;
156
+ /** Whether the implementer gave a menu */
157
+ private hasMenu;
158
+ /** Slots the implementer gave content for (their defaults aren't created) */
159
+ private filled;
160
+ /** Keyboard shortcuts, while handled */
161
+ private keys?;
162
+ /** The state last reported, to report only changes */
163
+ private reported?;
164
+ /** Space the floating sides cover over the canvas */
165
+ private floatingInsets;
166
+ /** The rail button that opened the open panel, to return focus to */
167
+ private opener?;
168
+ private readonly resizeObserver?;
169
+ private readonly panelObserver;
170
+ private readonly onPointerDown;
171
+ private readonly onAutosaveError;
172
+ private readonly onShortcut;
173
+ private readonly onDocumentPointerDown;
174
+ private readonly onKeyDown;
175
+ constructor();
176
+ /** Whether another window is drawing on the stored drawing, so this one is blocked */
177
+ get blocked(): boolean;
178
+ /** The layout's state now (see `LayoutState`) */
179
+ get state(): LayoutState;
180
+ /** A side's mode for the layout's width */
181
+ private modeOf;
182
+ connectedCallback(): void;
183
+ disconnectedCallback(): void;
184
+ protected willUpdate(changed: Map<PropertyKey, unknown>): void;
185
+ protected updated(): void;
186
+ /** Keep the canvas clear of floating sides when fitting it */
187
+ private measureFloatingSides;
188
+ /**
189
+ * Keep the canvas's layers under the `store` name, replacing an autosave the layout started earlier (also on the
190
+ * previous canvas). An autosave the implementer started is left alone when there's no name.
191
+ */
192
+ private useStore;
193
+ /** Show errors from the canvas's current autosave */
194
+ private watchAutosaveErrors;
195
+ /** Handle keyboard shortcuts for the current canvas, if asked to (not while blocked) */
196
+ private watchShortcuts;
197
+ /** Stop handling keyboard shortcuts */
198
+ private unwatchShortcuts;
199
+ /**
200
+ * Save the whole canvas as a PNG on white, at full size, including a stroke or transform in progress. Returns how it
201
+ * was saved, or undefined if cancelled.
202
+ */
203
+ saveScreenshot(): Promise<SaveMethod | undefined>;
204
+ /** The brush or eraser settings */
205
+ private toolSettings;
206
+ /**
207
+ * Open the configuration window for the current brush or eraser settings. When the selected preset is one of the
208
+ * user's own, the window can delete it.
209
+ */
210
+ configure(kind: "brush" | "eraser"): void;
211
+ /**
212
+ * Open the configuration window to make a new preset, starting from the current brush or eraser settings.
213
+ */
214
+ newPreset(kind: "brush" | "eraser"): void;
215
+ /** Which side a panel is in */
216
+ private sideOf;
217
+ /**
218
+ * Open a panel from its rail button (closing any other), or close it if it's open. Focus moves into the panel.
219
+ */
220
+ togglePanel(panel: PcPanel, opener?: HTMLElement): void;
221
+ /**
222
+ * Close the panel open from a rail, moving focus back to its rail button if asked.
223
+ */
224
+ closePanel(returnFocus: boolean): void;
225
+ /** Follow which slots have content given (their defaults aren't needed) */
226
+ private onSlotChange;
227
+ /** A slot, with its default content unless content was given for it */
228
+ private slotWithDefault;
229
+ /** Follow the panels given for a side, and whether it has a layers menu */
230
+ private onSideSlotChange;
231
+ /** Follow whether a menu was given */
232
+ private onMenuSlotChange;
233
+ /** Whether a side has a layers menu, replacing the toolbar's */
234
+ private get layersInSide();
235
+ /** The toolbar shown on the left unless the implementer gives other content */
236
+ private renderToolbar;
237
+ /** A side's rail buttons, one per panel */
238
+ private renderRail;
239
+ /** A side, in its mode */
240
+ private renderSide;
241
+ /** The menus the toolbar opens, floating over the canvas beside it */
242
+ private renderPanels;
243
+ /** The brush configuration window, while open */
244
+ private renderConfig;
245
+ /** The message blocking the layout while another window is drawing on the stored drawing */
246
+ private renderBlocked;
247
+ render(): import("lit").TemplateResult<1>;
248
+ }
249
+ export {};