@lvl99dotcom/paintcanvas 0.5.0 → 0.6.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 (97) hide show
  1. package/dist/lib/brushes/configRanges/index.d.ts +17 -0
  2. package/dist/lib/brushes/configRanges/index.js +31 -1
  3. package/dist/lib/brushes/params/index.d.ts +2 -1
  4. package/dist/lib/brushes/params/index.js +7 -4
  5. package/dist/lib/brushes/types/index.d.ts +8 -0
  6. package/dist/lib/classes/Layer/index.d.ts +10 -0
  7. package/dist/lib/classes/Layer/index.js +15 -1
  8. package/dist/lib/classes/LayerAutosave/index.d.ts +9 -15
  9. package/dist/lib/classes/LayerAutosave/index.js +30 -43
  10. package/dist/lib/classes/LayerStack/index.d.ts +15 -0
  11. package/dist/lib/classes/LayerStack/index.js +26 -2
  12. package/dist/lib/classes/PaintCanvas/index.d.ts +26 -3
  13. package/dist/lib/classes/PaintCanvas/index.js +39 -12
  14. package/dist/lib/classes/PngEncoder/index.d.ts +41 -0
  15. package/dist/lib/classes/PngEncoder/index.js +104 -0
  16. package/dist/lib/classes/ProfileGraphs/index.d.ts +87 -0
  17. package/dist/lib/classes/ProfileGraphs/index.js +148 -0
  18. package/dist/lib/classes/SettingsAutosave/index.d.ts +1 -1
  19. package/dist/lib/classes/SettingsAutosave/index.js +2 -1
  20. package/dist/lib/messages/schema.d.ts +720 -0
  21. package/dist/lib/presets/schema.d.ts +360 -0
  22. package/dist/lib/presets/schema.js +8 -1
  23. package/dist/lib/profiles/index.d.ts +61 -0
  24. package/dist/lib/profiles/index.js +131 -0
  25. package/dist/lib/profiles/schema.d.ts +73 -0
  26. package/dist/lib/profiles/schema.js +53 -0
  27. package/dist/lib/rendering/sample/index.d.ts +11 -0
  28. package/dist/lib/rendering/sample/index.js +36 -5
  29. package/dist/lib/settings/index.d.ts +2 -1
  30. package/dist/lib/settings/index.js +4 -1
  31. package/dist/lib/settings/schema.d.ts +49 -0
  32. package/dist/lib/settings/schema.js +6 -0
  33. package/dist/lib/validation/validators.generated.js +13064 -3696
  34. package/dist/locales/en-GB.js +30 -0
  35. package/dist/locales/en-US.js +30 -0
  36. package/dist/locales/fr.js +30 -0
  37. package/dist/locales/ja.js +30 -0
  38. package/dist/locales/ko.js +30 -0
  39. package/dist/locales/zh-Hans.js +30 -0
  40. package/dist/locales/zh-Hant.js +30 -0
  41. package/dist/package.js +1 -1
  42. package/dist/ui/ask/index.d.ts +48 -0
  43. package/dist/ui/ask/index.js +67 -0
  44. package/dist/ui/base/index.d.ts +8 -1
  45. package/dist/ui/base/index.js +19 -4
  46. package/dist/ui/elements/PaintCanvas/index.js +3 -1
  47. package/dist/ui/elements/PaintCanvas/style.js +1 -1
  48. package/dist/ui/elements/PcAppSettings/index.d.ts +6 -6
  49. package/dist/ui/elements/PcAppSettings/index.js +21 -65
  50. package/dist/ui/elements/PcBrushConfig/index.d.ts +25 -14
  51. package/dist/ui/elements/PcBrushConfig/index.js +216 -146
  52. package/dist/ui/elements/PcBrushConfig/style.js +1 -1
  53. package/dist/ui/elements/PcBrushTest/index.js +7 -2
  54. package/dist/ui/elements/PcBrushTest/style.js +1 -1
  55. package/dist/ui/elements/PcButton/index.d.ts +12 -3
  56. package/dist/ui/elements/PcButton/index.js +18 -10
  57. package/dist/ui/elements/PcCanvas/index.d.ts +6 -1
  58. package/dist/ui/elements/PcCanvas/index.js +10 -3
  59. package/dist/ui/elements/PcCanvas/style.js +1 -1
  60. package/dist/ui/elements/PcClipboardTools/index.d.ts +5 -4
  61. package/dist/ui/elements/PcClipboardTools/index.js +12 -5
  62. package/dist/ui/elements/PcDialog/index.d.ts +46 -10
  63. package/dist/ui/elements/PcDialog/index.js +102 -51
  64. package/dist/ui/elements/PcDialogWindow/index.d.ts +141 -0
  65. package/dist/ui/elements/PcDialogWindow/index.js +385 -0
  66. package/dist/ui/elements/PcPanelBrushes/index.d.ts +3 -2
  67. package/dist/ui/elements/PcPanelBrushes/index.js +7 -5
  68. package/dist/ui/elements/PcPanelBrushes/style.js +1 -1
  69. package/dist/ui/elements/PcPanelColours/index.js +2 -2
  70. package/dist/ui/elements/PcPanelColours/style.js +1 -1
  71. package/dist/ui/elements/PcPanelLayers/index.js +1 -1
  72. package/dist/ui/elements/PcPanelLayers/style.js +1 -1
  73. package/dist/ui/elements/PcProfileEditor/index.d.ts +103 -0
  74. package/dist/ui/elements/PcProfileEditor/index.js +259 -0
  75. package/dist/ui/elements/PcProfileGraph/index.d.ts +84 -0
  76. package/dist/ui/elements/PcProfileGraph/index.js +317 -0
  77. package/dist/ui/elements/PcShortcutSettings/index.js +9 -13
  78. package/dist/ui/elements/PcSliderRange/index.d.ts +147 -0
  79. package/dist/ui/elements/PcSliderRange/index.js +307 -0
  80. package/dist/ui/elements/PcStats/index.d.ts +19 -4
  81. package/dist/ui/elements/PcStats/index.js +29 -13
  82. package/dist/ui/elements/PcToolSettings/index.js +6 -6
  83. package/dist/ui/icons/images/icon-profile-graph@2x.js +3 -0
  84. package/dist/ui/icons/index.d.ts +1 -1
  85. package/dist/ui/icons/index.js +2 -0
  86. package/dist/ui/index.d.ts +6 -1
  87. package/dist/ui/index.js +6 -1
  88. package/dist/ui/styles/index.d.ts +21 -1
  89. package/dist/ui/styles/index.js +73 -14
  90. package/locales/en-GB.json +30 -0
  91. package/locales/en-US.json +30 -0
  92. package/locales/fr.json +30 -0
  93. package/locales/ja.json +30 -0
  94. package/locales/ko.json +30 -0
  95. package/locales/zh-Hans.json +30 -0
  96. package/locales/zh-Hant.json +30 -0
  97. package/package.json +25 -23
@@ -0,0 +1,73 @@
1
+ /** Longest profile graph ID or name (characters) */
2
+ export declare const MAX_PROFILE_TEXT_LENGTH = 100;
3
+ /** Most profile graphs a user can keep */
4
+ export declare const MAX_SAVED_PROFILES = 100;
5
+ /** Schema of a profile graph's points, from left to right */
6
+ export declare const profilePointsSchema: {
7
+ readonly type: "array";
8
+ readonly minItems: 2;
9
+ readonly maxItems: 32;
10
+ readonly items: {
11
+ readonly type: "object";
12
+ readonly additionalProperties: false;
13
+ readonly required: readonly ["x", "y", "i"];
14
+ readonly properties: {
15
+ readonly x: {
16
+ readonly type: "number";
17
+ readonly minimum: 0;
18
+ readonly maximum: 10;
19
+ };
20
+ readonly y: {
21
+ readonly type: "number";
22
+ readonly minimum: number;
23
+ readonly maximum: 0;
24
+ };
25
+ readonly i: {
26
+ readonly enum: ("linear" | "bezier-cubic")[];
27
+ };
28
+ };
29
+ };
30
+ };
31
+ /** Schema of a named profile graph */
32
+ export declare const profileGraphSchema: {
33
+ readonly type: "object";
34
+ readonly additionalProperties: false;
35
+ readonly required: readonly ["id", "name", "points"];
36
+ readonly properties: {
37
+ readonly id: {
38
+ readonly type: "string";
39
+ readonly minLength: 1;
40
+ readonly maxLength: 100;
41
+ };
42
+ readonly name: {
43
+ readonly type: "string";
44
+ readonly minLength: 1;
45
+ readonly maxLength: 100;
46
+ };
47
+ readonly points: {
48
+ readonly type: "array";
49
+ readonly minItems: 2;
50
+ readonly maxItems: 32;
51
+ readonly items: {
52
+ readonly type: "object";
53
+ readonly additionalProperties: false;
54
+ readonly required: readonly ["x", "y", "i"];
55
+ readonly properties: {
56
+ readonly x: {
57
+ readonly type: "number";
58
+ readonly minimum: 0;
59
+ readonly maximum: 10;
60
+ };
61
+ readonly y: {
62
+ readonly type: "number";
63
+ readonly minimum: number;
64
+ readonly maximum: 0;
65
+ };
66
+ readonly i: {
67
+ readonly enum: ("linear" | "bezier-cubic")[];
68
+ };
69
+ };
70
+ };
71
+ };
72
+ };
73
+ };
@@ -0,0 +1,53 @@
1
+ import { Interpolation } from "./index.js";
2
+ /** Schema of a profile graph's points, from left to right */
3
+ var profilePointsSchema = {
4
+ type: "array",
5
+ minItems: 2,
6
+ maxItems: 32,
7
+ items: {
8
+ type: "object",
9
+ additionalProperties: false,
10
+ required: [
11
+ "x",
12
+ "y",
13
+ "i"
14
+ ],
15
+ properties: {
16
+ x: {
17
+ type: "number",
18
+ minimum: 0,
19
+ maximum: 10
20
+ },
21
+ y: {
22
+ type: "number",
23
+ minimum: -10,
24
+ maximum: 0
25
+ },
26
+ i: { enum: Object.values(Interpolation) }
27
+ }
28
+ }
29
+ };
30
+ /** Schema of a named profile graph */
31
+ var profileGraphSchema = {
32
+ type: "object",
33
+ additionalProperties: false,
34
+ required: [
35
+ "id",
36
+ "name",
37
+ "points"
38
+ ],
39
+ properties: {
40
+ id: {
41
+ type: "string",
42
+ minLength: 1,
43
+ maxLength: 100
44
+ },
45
+ name: {
46
+ type: "string",
47
+ minLength: 1,
48
+ maxLength: 100
49
+ },
50
+ points: profilePointsSchema
51
+ }
52
+ };
53
+ export { profileGraphSchema, profilePointsSchema };
@@ -41,10 +41,21 @@ export declare const pixelRect: (a: {
41
41
  x: number;
42
42
  y: number;
43
43
  }, canvasWidth: number, canvasHeight: number) => PixelRect | undefined;
44
+ /**
45
+ * Copy an area of a canvas onto a new canvas the size of the area, by reading its pixels. Reading only the area keeps
46
+ * this quick for GPU-backed canvases: drawing one onto another canvas can copy all of its pixels back from the GPU.
47
+ *
48
+ * @example
49
+ * copyPixels(layer.canvas, { x: 10, y: 10, width: 1, height: 1 }, createOffscreenCanvas); // a 1 × 1 canvas
50
+ */
51
+ export declare const copyPixels: (source: OffscreenCanvas, area: PixelRect, createCanvas: CanvasFactory) => OffscreenCanvas;
44
52
  /**
45
53
  * Draw an area of the canvas as it's shown (the white background, then every layer mixed as shown) onto a new canvas,
46
54
  * scaled to fit `width` × `height`. Parts outside the canvas stay transparent.
47
55
  *
56
+ * Only the area of each layer is used: at full size, its pixels are read (see `copyPixels`); scaled down (e.g. a
57
+ * preview of a large area), that part of each layer is drawn scaled.
58
+ *
48
59
  * @example
49
60
  * flattenArea(app.drawables, app.createCanvas, app.width, app.height, { x: 10, y: 10, width: 10, height: 10 });
50
61
  */
@@ -1,4 +1,5 @@
1
1
  import { rgbToHex } from "../../utils/colour/index.js";
2
+ import { clipRect } from "../../brushes/StrokeEngine/index.js";
2
3
  import { CANVAS_BACKGROUND, drawLayers } from "../compositing/index.js";
3
4
  // src/lib/rendering/sample/index.ts
4
5
  /** How many canvas pixels across the sampling window enlarges */
@@ -59,26 +60,56 @@ var pixelRect = (a, b, canvasWidth, canvasHeight) => {
59
60
  };
60
61
  };
61
62
  /**
63
+ * Copy an area of a canvas onto a new canvas the size of the area, by reading its pixels. Reading only the area keeps
64
+ * this quick for GPU-backed canvases: drawing one onto another canvas can copy all of its pixels back from the GPU.
65
+ *
66
+ * @example
67
+ * copyPixels(layer.canvas, { x: 10, y: 10, width: 1, height: 1 }, createOffscreenCanvas); // a 1 × 1 canvas
68
+ */
69
+ var copyPixels = (source, area, createCanvas) => {
70
+ const { x, y, width, height } = area;
71
+ const piece = createCanvas(width, height);
72
+ const pixels = source.getContext("2d").getImageData(x, y, width, height);
73
+ piece.getContext("2d").putImageData(pixels, 0, 0);
74
+ return piece;
75
+ };
76
+ /**
62
77
  * Draw an area of the canvas as it's shown (the white background, then every layer mixed as shown) onto a new canvas,
63
78
  * scaled to fit `width` × `height`. Parts outside the canvas stay transparent.
64
79
  *
80
+ * Only the area of each layer is used: at full size, its pixels are read (see `copyPixels`); scaled down (e.g. a
81
+ * preview of a large area), that part of each layer is drawn scaled.
82
+ *
65
83
  * @example
66
84
  * flattenArea(app.drawables, app.createCanvas, app.width, app.height, { x: 10, y: 10, width: 10, height: 10 });
67
85
  */
68
86
  var flattenArea = (layers, createCanvas, canvasWidth, canvasHeight, area, width = area.width, height = area.height) => {
69
87
  const canvas = createCanvas(width, height);
70
- const ctx = canvas.getContext("2d", { willReadFrequently: true });
88
+ const source = clipRect(area, canvasWidth, canvasHeight);
89
+ if (!source) return canvas;
90
+ const ctx = canvas.getContext("2d");
71
91
  const scaleX = width / area.width;
72
92
  const scaleY = height / area.height;
93
+ const scaled = scaleX < 1 || scaleY < 1;
73
94
  ctx.setTransform(scaleX, 0, 0, scaleY, -area.x * scaleX, -area.y * scaleY);
74
- ctx.imageSmoothingEnabled = scaleX < 1 || scaleY < 1;
95
+ ctx.imageSmoothingEnabled = scaled;
75
96
  ctx.fillStyle = CANVAS_BACKGROUND;
76
- ctx.fillRect(0, 0, canvasWidth, canvasHeight);
77
- drawLayers(ctx, layers);
97
+ ctx.fillRect(source.x, source.y, source.width, source.height);
98
+ if (scaled) {
99
+ drawLayers(ctx, layers, void 0, source);
100
+ return canvas;
101
+ }
102
+ ctx.translate(source.x, source.y);
103
+ drawLayers(ctx, layers.filter((layer) => layer.visible && layer.opacity > 0).map(({ visible, opacity, blendMode, canvas: image }) => ({
104
+ visible,
105
+ opacity,
106
+ blendMode,
107
+ canvas: copyPixels(image, source, createCanvas)
108
+ })));
78
109
  return canvas;
79
110
  };
80
111
  /**
81
112
  * Read all of a canvas's pixels as RGBA.
82
113
  */
83
114
  var readPixels = (canvas) => canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height).data;
84
- export { PREVIEW_MAX_PIXELS, SAMPLE_PIXELS, SAMPLE_SCALE, averageColour, flattenArea, pixelRect, readPixels, toHex };
115
+ export { PREVIEW_MAX_PIXELS, SAMPLE_PIXELS, SAMPLE_SCALE, averageColour, copyPixels, flattenArea, pixelRect, readPixels, toHex };
@@ -25,7 +25,8 @@ export type SettingsValidationResult = {
25
25
  */
26
26
  export declare const isValidSettings: (input: unknown) => SettingsValidationResult;
27
27
  /**
28
- * The app settings of a canvas: its input settings, keyboard shortcuts, colour palette, colours, theme and language.
28
+ * The app settings of a canvas: its input settings, keyboard shortcuts, colour palette, colours, profile graphs, theme
29
+ * and language.
29
30
  *
30
31
  * @example
31
32
  * collectSettings(canvas).palette; // ["#2c6bff", ...]
@@ -23,7 +23,8 @@ var isValidSettings = (input) => validateSettings(input) ? {
23
23
  errors: formatErrors(validateSettings.errors)
24
24
  };
25
25
  /**
26
- * The app settings of a canvas: its input settings, keyboard shortcuts, colour palette, colours, theme and language.
26
+ * The app settings of a canvas: its input settings, keyboard shortcuts, colour palette, colours, profile graphs, theme
27
+ * and language.
27
28
  *
28
29
  * @example
29
30
  * collectSettings(canvas).palette; // ["#2c6bff", ...]
@@ -33,6 +34,7 @@ var collectSettings = (app) => ({
33
34
  shortcuts: structuredClone(app.shortcuts.bindings),
34
35
  palette: [...app.palette.colours],
35
36
  colours: { ...app.colours },
37
+ profiles: structuredClone([...app.profiles.graphs]),
36
38
  ui: { ...app.ui.data }
37
39
  });
38
40
  /**
@@ -50,6 +52,7 @@ var applySettings = (app, settings) => {
50
52
  app.setColour(settings.colours.foreground, "foreground");
51
53
  app.setColour(settings.colours.background, "background");
52
54
  }
55
+ if (settings.profiles) app.profiles.set(settings.profiles);
53
56
  if (settings.ui) app.ui.update(settings.ui);
54
57
  };
55
58
  /**
@@ -1,6 +1,7 @@
1
1
  import type { InputSettingsData } from "../classes/InputSettings";
2
2
  import { type UiSettingsData } from "../classes/UiSettings/index.ts";
3
3
  import type { KeyCombo } from "../utils/shortcuts";
4
+ import type { ProfileGraph } from "../profiles/index.ts";
4
5
  /** The `format` of a settings file, unless the implementer names their own (see `PaintCanvasNames`) */
5
6
  export declare const SETTINGS_FILE_FORMAT = "paintcanvas-settings";
6
7
  /** Formats of settings files that are imported by default */
@@ -24,6 +25,8 @@ export interface AppSettings {
24
25
  foreground: string;
25
26
  background: string;
26
27
  };
28
+ /** The user's own profile graphs */
29
+ profiles?: ProfileGraph[];
27
30
  /** The theme and language */
28
31
  ui?: Partial<UiSettingsData>;
29
32
  }
@@ -129,6 +132,52 @@ export declare const settingsSchema: {
129
132
  };
130
133
  };
131
134
  };
135
+ readonly profiles: {
136
+ readonly type: "array";
137
+ readonly maxItems: 100;
138
+ readonly items: {
139
+ readonly type: "object";
140
+ readonly additionalProperties: false;
141
+ readonly required: readonly ["id", "name", "points"];
142
+ readonly properties: {
143
+ readonly id: {
144
+ readonly type: "string";
145
+ readonly minLength: 1;
146
+ readonly maxLength: 100;
147
+ };
148
+ readonly name: {
149
+ readonly type: "string";
150
+ readonly minLength: 1;
151
+ readonly maxLength: 100;
152
+ };
153
+ readonly points: {
154
+ readonly type: "array";
155
+ readonly minItems: 2;
156
+ readonly maxItems: 32;
157
+ readonly items: {
158
+ readonly type: "object";
159
+ readonly additionalProperties: false;
160
+ readonly required: readonly ["x", "y", "i"];
161
+ readonly properties: {
162
+ readonly x: {
163
+ readonly type: "number";
164
+ readonly minimum: 0;
165
+ readonly maximum: 10;
166
+ };
167
+ readonly y: {
168
+ readonly type: "number";
169
+ readonly minimum: number;
170
+ readonly maximum: 0;
171
+ };
172
+ readonly i: {
173
+ readonly enum: ("linear" | "bezier-cubic")[];
174
+ };
175
+ };
176
+ };
177
+ };
178
+ };
179
+ };
180
+ };
132
181
  readonly ui: {
133
182
  readonly type: "object";
134
183
  readonly additionalProperties: false;
@@ -1,5 +1,6 @@
1
1
  import { LOCALE_PATTERN, THEMES } from "../classes/UiSettings/index.js";
2
2
  import { HEX_COLOUR_PATTERN, MAX_PALETTE_COLOURS, paletteFileSchema } from "../palette/schema.js";
3
+ import { profileGraphSchema } from "../profiles/schema.js";
3
4
  // src/lib/settings/schema.ts
4
5
  /** The `format` of a settings file, unless the implementer names their own (see `PaintCanvasNames`) */
5
6
  var SETTINGS_FILE_FORMAT = "paintcanvas-settings";
@@ -78,6 +79,11 @@ var settingsSchema = {
78
79
  background: hexColour
79
80
  }
80
81
  },
82
+ profiles: {
83
+ type: "array",
84
+ maxItems: 100,
85
+ items: profileGraphSchema
86
+ },
81
87
  ui: {
82
88
  type: "object",
83
89
  additionalProperties: false,