@lvl99dotcom/paintcanvas 0.5.0 → 0.7.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/README.md +2 -2
- package/dist/lib/brushes/configRanges/index.d.ts +17 -0
- package/dist/lib/brushes/configRanges/index.js +31 -1
- package/dist/lib/brushes/params/index.d.ts +2 -1
- package/dist/lib/brushes/params/index.js +7 -4
- package/dist/lib/brushes/types/index.d.ts +8 -0
- package/dist/lib/classes/Layer/index.d.ts +10 -0
- package/dist/lib/classes/Layer/index.js +15 -1
- package/dist/lib/classes/LayerAutosave/index.d.ts +9 -15
- package/dist/lib/classes/LayerAutosave/index.js +30 -43
- package/dist/lib/classes/LayerStack/index.d.ts +15 -0
- package/dist/lib/classes/LayerStack/index.js +26 -2
- package/dist/lib/classes/PaintCanvas/index.d.ts +36 -5
- package/dist/lib/classes/PaintCanvas/index.js +45 -14
- package/dist/lib/classes/PngEncoder/index.d.ts +41 -0
- package/dist/lib/classes/PngEncoder/index.js +104 -0
- package/dist/lib/classes/ProfileGraphs/index.d.ts +87 -0
- package/dist/lib/classes/ProfileGraphs/index.js +148 -0
- package/dist/lib/classes/SettingsAutosave/index.d.ts +1 -1
- package/dist/lib/classes/SettingsAutosave/index.js +2 -1
- package/dist/lib/classes/UiSettings/index.d.ts +24 -2
- package/dist/lib/classes/UiSettings/index.js +32 -7
- package/dist/lib/messages/schema.d.ts +720 -0
- package/dist/lib/presets/schema.d.ts +360 -0
- package/dist/lib/presets/schema.js +8 -1
- package/dist/lib/profiles/index.d.ts +61 -0
- package/dist/lib/profiles/index.js +131 -0
- package/dist/lib/profiles/schema.d.ts +73 -0
- package/dist/lib/profiles/schema.js +53 -0
- package/dist/lib/rendering/sample/index.d.ts +11 -0
- package/dist/lib/rendering/sample/index.js +36 -5
- package/dist/lib/settings/index.d.ts +2 -1
- package/dist/lib/settings/index.js +4 -1
- package/dist/lib/settings/schema.d.ts +53 -1
- package/dist/lib/settings/schema.js +9 -2
- package/dist/lib/storage/index.d.ts +26 -0
- package/dist/lib/storage/index.js +38 -1
- package/dist/lib/validation/validators.generated.js +13061 -3675
- package/dist/lib/version/index.d.ts +25 -0
- package/dist/lib/version/index.js +35 -0
- package/dist/locales/en-GB.js +35 -0
- package/dist/locales/en-US.js +35 -0
- package/dist/locales/fr.js +35 -0
- package/dist/locales/ja.js +35 -0
- package/dist/locales/ko.js +35 -0
- package/dist/locales/zh-Hans.js +35 -0
- package/dist/locales/zh-Hant.js +35 -0
- package/dist/package.js +1 -1
- package/dist/ui/ask/index.d.ts +48 -0
- package/dist/ui/ask/index.js +67 -0
- package/dist/ui/base/index.d.ts +8 -1
- package/dist/ui/base/index.js +19 -4
- package/dist/ui/elements/PaintCanvas/index.d.ts +13 -3
- package/dist/ui/elements/PaintCanvas/index.js +25 -6
- package/dist/ui/elements/PaintCanvas/style.js +1 -1
- package/dist/ui/elements/PcAppSettings/index.d.ts +15 -7
- package/dist/ui/elements/PcAppSettings/index.js +53 -62
- package/dist/ui/elements/PcBrushConfig/index.d.ts +26 -14
- package/dist/ui/elements/PcBrushConfig/index.js +214 -145
- package/dist/ui/elements/PcBrushConfig/style.js +1 -1
- package/dist/ui/elements/PcBrushTest/index.d.ts +1 -0
- package/dist/ui/elements/PcBrushTest/index.js +15 -9
- package/dist/ui/elements/PcBrushTest/style.js +1 -1
- package/dist/ui/elements/PcButton/index.d.ts +12 -3
- package/dist/ui/elements/PcButton/index.js +18 -10
- package/dist/ui/elements/PcButtonMenu/index.d.ts +88 -0
- package/dist/ui/elements/PcButtonMenu/index.js +125 -0
- package/dist/ui/elements/PcCanvas/index.d.ts +15 -1
- package/dist/ui/elements/PcCanvas/index.js +42 -19
- package/dist/ui/elements/PcCanvas/style.js +1 -1
- package/dist/ui/elements/PcClipboardTools/index.d.ts +11 -7
- package/dist/ui/elements/PcClipboardTools/index.js +30 -29
- package/dist/ui/elements/PcDialog/index.d.ts +46 -10
- package/dist/ui/elements/PcDialog/index.js +102 -51
- package/dist/ui/elements/PcDialogWindow/index.d.ts +141 -0
- package/dist/ui/elements/PcDialogWindow/index.js +385 -0
- package/dist/ui/elements/PcInputSettings/index.d.ts +2 -1
- package/dist/ui/elements/PcInputSettings/index.js +9 -15
- package/dist/ui/elements/PcLayerItem/index.d.ts +21 -6
- package/dist/ui/elements/PcLayerItem/index.js +53 -26
- package/dist/ui/elements/PcLayerItem/style.js +1 -1
- package/dist/ui/elements/PcPanelBrushes/index.d.ts +3 -2
- package/dist/ui/elements/PcPanelBrushes/index.js +7 -5
- package/dist/ui/elements/PcPanelBrushes/style.js +1 -1
- package/dist/ui/elements/PcPanelColours/index.js +2 -2
- package/dist/ui/elements/PcPanelColours/style.js +1 -1
- package/dist/ui/elements/PcPanelLayers/index.js +1 -1
- package/dist/ui/elements/PcPanelLayers/style.js +1 -1
- package/dist/ui/elements/PcProfileEditor/index.d.ts +103 -0
- package/dist/ui/elements/PcProfileEditor/index.js +259 -0
- package/dist/ui/elements/PcProfileGraph/index.d.ts +84 -0
- package/dist/ui/elements/PcProfileGraph/index.js +317 -0
- package/dist/ui/elements/PcShortcutSettings/index.js +9 -13
- package/dist/ui/elements/PcSliderRange/index.d.ts +147 -0
- package/dist/ui/elements/PcSliderRange/index.js +308 -0
- package/dist/ui/elements/PcStats/index.d.ts +19 -4
- package/dist/ui/elements/PcStats/index.js +29 -13
- package/dist/ui/elements/PcToggleCheckbox/index.d.ts +13 -2
- package/dist/ui/elements/PcToggleCheckbox/index.js +27 -8
- package/dist/ui/elements/PcToolSettings/index.d.ts +1 -0
- package/dist/ui/elements/PcToolSettings/index.js +14 -14
- package/dist/ui/elements/PcVersion/index.d.ts +12 -0
- package/dist/ui/elements/PcVersion/index.js +43 -0
- package/dist/ui/icons/images/icon-profile-graph@2x.js +3 -0
- package/dist/ui/icons/index.d.ts +1 -1
- package/dist/ui/icons/index.js +2 -0
- package/dist/ui/index.d.ts +9 -2
- package/dist/ui/index.js +9 -2
- package/dist/ui/layout/index.d.ts +2 -2
- package/dist/ui/layout/index.js +2 -2
- package/dist/ui/styles/index.d.ts +21 -1
- package/dist/ui/styles/index.js +73 -14
- package/locales/en-GB.json +35 -0
- package/locales/en-US.json +35 -0
- package/locales/fr.json +35 -0
- package/locales/ja.json +35 -0
- package/locales/ko.json +35 -0
- package/locales/zh-Hans.json +35 -0
- package/locales/zh-Hant.json +35 -0
- 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
|
|
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 =
|
|
95
|
+
ctx.imageSmoothingEnabled = scaled;
|
|
75
96
|
ctx.fillStyle = CANVAS_BACKGROUND;
|
|
76
|
-
ctx.fillRect(
|
|
77
|
-
|
|
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,
|
|
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,
|
|
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,7 +25,9 @@ export interface AppSettings {
|
|
|
24
25
|
foreground: string;
|
|
25
26
|
background: string;
|
|
26
27
|
};
|
|
27
|
-
/** The
|
|
28
|
+
/** The user's own profile graphs */
|
|
29
|
+
profiles?: ProfileGraph[];
|
|
30
|
+
/** The theme, language and where canvases draw */
|
|
28
31
|
ui?: Partial<UiSettingsData>;
|
|
29
32
|
}
|
|
30
33
|
/** A settings file: what users export and import */
|
|
@@ -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;
|
|
@@ -142,6 +191,9 @@ export declare const settingsSchema: {
|
|
|
142
191
|
readonly maxLength: 35;
|
|
143
192
|
readonly pattern: "^[A-Za-z0-9-]+$";
|
|
144
193
|
};
|
|
194
|
+
readonly rendering: {
|
|
195
|
+
readonly enum: readonly ["cpu", "gpu"];
|
|
196
|
+
};
|
|
145
197
|
};
|
|
146
198
|
};
|
|
147
199
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { LOCALE_PATTERN, THEMES } from "../classes/UiSettings/index.js";
|
|
1
|
+
import { LOCALE_PATTERN, RENDERINGS, 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,
|
|
@@ -88,7 +94,8 @@ var settingsSchema = {
|
|
|
88
94
|
minLength: 1,
|
|
89
95
|
maxLength: 35,
|
|
90
96
|
pattern: LOCALE_PATTERN
|
|
91
|
-
}
|
|
97
|
+
},
|
|
98
|
+
rendering: { enum: RENDERINGS }
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LayerConfig } from "../classes/Layer";
|
|
2
2
|
import type { AppSettings } from "../settings/schema";
|
|
3
|
+
import { type Rendering } from "../classes/UiSettings";
|
|
3
4
|
/** Version of a saved drawing's shape, so drawings saved by other versions can be recognised */
|
|
4
5
|
export declare const SAVED_DRAWING_VERSION = 1;
|
|
5
6
|
/** Name of the IndexedDB database `IndexedDbLayerStore` keeps drawings in, and `IndexedDbSettingsStore` settings */
|
|
@@ -92,3 +93,28 @@ export declare class IndexedDbSettingsStore implements SettingsStoreLike {
|
|
|
92
93
|
load(): Promise<unknown>;
|
|
93
94
|
save(settings: AppSettings): Promise<void>;
|
|
94
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The browser storage key that keeps the rendering chosen with the app settings of a name (see
|
|
98
|
+
* `loadRenderingChoice`).
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* renderingChoiceKey("demo"); // "paintcanvas-rendering:demo"
|
|
102
|
+
*/
|
|
103
|
+
export declare const renderingChoiceKey: (name: string) => string;
|
|
104
|
+
/**
|
|
105
|
+
* The rendering (`cpu` or `gpu`) last chosen with the app settings of a name, kept in `localStorage` so it can be read
|
|
106
|
+
* before the canvas is made (the app settings themselves load later, from IndexedDB). Undefined when none was kept, it
|
|
107
|
+
* isn't valid, or the storage can't be read (e.g. blocked by the browser).
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* new PaintCanvas({ rendering: loadRenderingChoice("demo") });
|
|
111
|
+
*/
|
|
112
|
+
export declare const loadRenderingChoice: (name?: string, storage?: Pick<Storage, "getItem"> | undefined) => Rendering | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Keep the rendering chosen with the app settings of a name, to be read with `loadRenderingChoice` when the canvas is
|
|
115
|
+
* next made. Does nothing if the storage can't be written.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* canvas.ui.addEventListener("change", () => saveRenderingChoice("demo", canvas.ui.data.rendering));
|
|
119
|
+
*/
|
|
120
|
+
export declare const saveRenderingChoice: (name: string, rendering: Rendering, storage?: Pick<Storage, "setItem"> | undefined) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRendering } from "../classes/UiSettings/index.js";
|
|
1
2
|
// src/lib/storage/index.ts
|
|
2
3
|
/** Version of a saved drawing's shape, so drawings saved by other versions can be recognised */
|
|
3
4
|
var SAVED_DRAWING_VERSION = 1;
|
|
@@ -169,4 +170,40 @@ var IndexedDbSettingsStore = class {
|
|
|
169
170
|
await done;
|
|
170
171
|
}
|
|
171
172
|
};
|
|
172
|
-
|
|
173
|
+
/**
|
|
174
|
+
* The browser storage key that keeps the rendering chosen with the app settings of a name (see
|
|
175
|
+
* `loadRenderingChoice`).
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* renderingChoiceKey("demo"); // "paintcanvas-rendering:demo"
|
|
179
|
+
*/
|
|
180
|
+
var renderingChoiceKey = (name) => `${DATABASE_NAME}-rendering:${name}`;
|
|
181
|
+
/**
|
|
182
|
+
* The rendering (`cpu` or `gpu`) last chosen with the app settings of a name, kept in `localStorage` so it can be read
|
|
183
|
+
* before the canvas is made (the app settings themselves load later, from IndexedDB). Undefined when none was kept, it
|
|
184
|
+
* isn't valid, or the storage can't be read (e.g. blocked by the browser).
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* new PaintCanvas({ rendering: loadRenderingChoice("demo") });
|
|
188
|
+
*/
|
|
189
|
+
var loadRenderingChoice = (name = DEFAULT_SETTINGS_NAME, storage = globalThis.localStorage) => {
|
|
190
|
+
try {
|
|
191
|
+
const value = storage?.getItem(renderingChoiceKey(name));
|
|
192
|
+
return isRendering(value) ? value : void 0;
|
|
193
|
+
} catch {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Keep the rendering chosen with the app settings of a name, to be read with `loadRenderingChoice` when the canvas is
|
|
199
|
+
* next made. Does nothing if the storage can't be written.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* canvas.ui.addEventListener("change", () => saveRenderingChoice("demo", canvas.ui.data.rendering));
|
|
203
|
+
*/
|
|
204
|
+
var saveRenderingChoice = (name, rendering, storage = globalThis.localStorage) => {
|
|
205
|
+
try {
|
|
206
|
+
storage?.setItem(renderingChoiceKey(name), rendering);
|
|
207
|
+
} catch {}
|
|
208
|
+
};
|
|
209
|
+
export { DATABASE_NAME, DATABASE_VERSION, DEFAULT_SETTINGS_NAME, IndexedDbSettingsStore, SAVED_DRAWING_VERSION, IndexedDbLayerStore as default, loadRenderingChoice, renderingChoiceKey, saveRenderingChoice };
|