@lvl99dotcom/paintcanvas 0.6.0 → 0.8.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 (119) hide show
  1. package/README.md +3 -2
  2. package/dist/lib/assets/index.d.ts +92 -0
  3. package/dist/lib/assets/index.js +106 -0
  4. package/dist/lib/assets/schema.d.ts +151 -0
  5. package/dist/lib/assets/schema.js +76 -0
  6. package/dist/lib/brushes/presetFile/index.d.ts +6 -27
  7. package/dist/lib/brushes/presetFile/index.js +34 -47
  8. package/dist/lib/brushes/types/index.d.ts +2 -11
  9. package/dist/lib/classes/AssetSync/index.d.ts +45 -0
  10. package/dist/lib/classes/AssetSync/index.js +80 -0
  11. package/dist/lib/classes/ColourPalettes/index.d.ts +83 -0
  12. package/dist/lib/classes/ColourPalettes/index.js +165 -0
  13. package/dist/lib/classes/CustomPresets/index.d.ts +14 -15
  14. package/dist/lib/classes/CustomPresets/index.js +25 -10
  15. package/dist/lib/classes/LayerAutosave/index.d.ts +9 -2
  16. package/dist/lib/classes/LayerAutosave/index.js +16 -6
  17. package/dist/lib/classes/PaintCanvas/index.d.ts +124 -28
  18. package/dist/lib/classes/PaintCanvas/index.js +228 -63
  19. package/dist/lib/classes/Palette/index.d.ts +3 -2
  20. package/dist/lib/classes/Palette/index.js +3 -2
  21. package/dist/lib/classes/ProfileGraphs/index.d.ts +13 -2
  22. package/dist/lib/classes/ProfileGraphs/index.js +22 -2
  23. package/dist/lib/classes/RemoteDocumentAutosave/index.d.ts +73 -0
  24. package/dist/lib/classes/RemoteDocumentAutosave/index.js +119 -0
  25. package/dist/lib/classes/SettingsAutosave/index.d.ts +7 -3
  26. package/dist/lib/classes/SettingsAutosave/index.js +28 -7
  27. package/dist/lib/classes/SettingsExtensions/index.d.ts +67 -0
  28. package/dist/lib/classes/SettingsExtensions/index.js +88 -0
  29. package/dist/lib/classes/UiSettings/index.d.ts +24 -2
  30. package/dist/lib/classes/UiSettings/index.js +32 -7
  31. package/dist/lib/document/index.d.ts +61 -4
  32. package/dist/lib/document/index.js +173 -4
  33. package/dist/lib/document/schema.d.ts +154 -39
  34. package/dist/lib/document/schema.js +91 -25
  35. package/dist/lib/messages/schema.d.ts +176 -74
  36. package/dist/lib/messages/schema.js +2 -1
  37. package/dist/lib/palette/index.d.ts +8 -42
  38. package/dist/lib/palette/index.js +26 -59
  39. package/dist/lib/palette/schema.d.ts +111 -22
  40. package/dist/lib/palette/schema.js +51 -26
  41. package/dist/lib/presets/index.d.ts +1 -9
  42. package/dist/lib/presets/index.js +4 -10
  43. package/dist/lib/presets/schema.d.ts +118 -73
  44. package/dist/lib/presets/schema.js +28 -60
  45. package/dist/lib/profiles/profileFile/index.d.ts +10 -0
  46. package/dist/lib/profiles/profileFile/index.js +19 -0
  47. package/dist/lib/profiles/schema.d.ts +96 -3
  48. package/dist/lib/profiles/schema.js +31 -7
  49. package/dist/lib/schemas/index.d.ts +42 -0
  50. package/dist/lib/schemas/index.js +60 -0
  51. package/dist/lib/settings/index.d.ts +37 -22
  52. package/dist/lib/settings/index.js +78 -37
  53. package/dist/lib/settings/schema.d.ts +202 -77
  54. package/dist/lib/settings/schema.js +93 -86
  55. package/dist/lib/storage/index.d.ts +108 -3
  56. package/dist/lib/storage/index.js +119 -5
  57. package/dist/lib/validation/validators.generated.d.ts +19 -8
  58. package/dist/lib/validation/validators.generated.js +44723 -18889
  59. package/dist/lib/version/index.d.ts +25 -0
  60. package/dist/lib/version/index.js +35 -0
  61. package/dist/locales/en-GB.js +28 -5
  62. package/dist/locales/en-US.js +28 -5
  63. package/dist/locales/fr.js +28 -5
  64. package/dist/locales/ja.js +28 -5
  65. package/dist/locales/ko.js +28 -5
  66. package/dist/locales/zh-Hans.js +28 -5
  67. package/dist/locales/zh-Hant.js +28 -5
  68. package/dist/package.js +1 -1
  69. package/dist/testing/app.d.ts +6 -2
  70. package/dist/testing/app.js +7 -2
  71. package/dist/testing/documentStore.d.ts +26 -0
  72. package/dist/testing/documentStore.js +31 -0
  73. package/dist/ui/elements/PaintCanvas/index.d.ts +19 -5
  74. package/dist/ui/elements/PaintCanvas/index.js +41 -10
  75. package/dist/ui/elements/PcAppSettings/index.d.ts +14 -7
  76. package/dist/ui/elements/PcAppSettings/index.js +58 -33
  77. package/dist/ui/elements/PcBrushConfig/index.d.ts +1 -0
  78. package/dist/ui/elements/PcBrushConfig/index.js +8 -9
  79. package/dist/ui/elements/PcBrushTest/index.d.ts +1 -0
  80. package/dist/ui/elements/PcBrushTest/index.js +8 -7
  81. package/dist/ui/elements/PcBrushTest/style.js +1 -1
  82. package/dist/ui/elements/PcButtonMenu/index.d.ts +88 -0
  83. package/dist/ui/elements/PcButtonMenu/index.js +125 -0
  84. package/dist/ui/elements/PcCanvas/index.d.ts +9 -0
  85. package/dist/ui/elements/PcCanvas/index.js +33 -17
  86. package/dist/ui/elements/PcClipboardTools/index.d.ts +7 -4
  87. package/dist/ui/elements/PcClipboardTools/index.js +20 -26
  88. package/dist/ui/elements/PcInputSettings/index.d.ts +2 -1
  89. package/dist/ui/elements/PcInputSettings/index.js +9 -15
  90. package/dist/ui/elements/PcLayerItem/index.d.ts +21 -6
  91. package/dist/ui/elements/PcLayerItem/index.js +53 -26
  92. package/dist/ui/elements/PcLayerItem/style.js +1 -1
  93. package/dist/ui/elements/PcPanelBrushes/index.d.ts +1 -1
  94. package/dist/ui/elements/PcPanelBrushes/index.js +22 -28
  95. package/dist/ui/elements/PcPanelBrushes/style.js +1 -1
  96. package/dist/ui/elements/PcPanelColours/index.d.ts +56 -19
  97. package/dist/ui/elements/PcPanelColours/index.js +251 -104
  98. package/dist/ui/elements/PcPanelColours/style.js +1 -1
  99. package/dist/ui/elements/PcSliderRange/index.js +3 -2
  100. package/dist/ui/elements/PcStats/index.d.ts +8 -4
  101. package/dist/ui/elements/PcStats/index.js +39 -5
  102. package/dist/ui/elements/PcToggleCheckbox/index.d.ts +13 -2
  103. package/dist/ui/elements/PcToggleCheckbox/index.js +27 -8
  104. package/dist/ui/elements/PcToolSettings/index.d.ts +1 -0
  105. package/dist/ui/elements/PcToolSettings/index.js +8 -8
  106. package/dist/ui/elements/PcVersion/index.d.ts +12 -0
  107. package/dist/ui/elements/PcVersion/index.js +43 -0
  108. package/dist/ui/index.d.ts +3 -1
  109. package/dist/ui/index.js +4 -2
  110. package/dist/ui/layout/index.d.ts +2 -2
  111. package/dist/ui/layout/index.js +2 -2
  112. package/locales/en-GB.json +28 -5
  113. package/locales/en-US.json +28 -5
  114. package/locales/fr.json +28 -5
  115. package/locales/ja.json +28 -5
  116. package/locales/ko.json +28 -5
  117. package/locales/zh-Hans.json +28 -5
  118. package/locales/zh-Hant.json +28 -5
  119. package/package.json +3 -2
@@ -1,18 +1,18 @@
1
- import { profilePointsSchema } from "../profiles/schema.js";
1
+ import { profileIdSchema, profilePointsSchema } from "../profiles/schema.js";
2
+ import { UUID_PATTERN, authorSchema, collectionSchema, fileSchemaUrlSchema } from "../assets/schema.js";
3
+ import { SCHEMA_DIALECT, schemaUrl } from "../schemas/index.js";
2
4
  // src/lib/presets/schema.ts
3
- /** Matches a lowercase UUID */
4
- var UUID_PATTERN = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
5
- /** The `format` of a brush preset file, unless the implementer names their own (see `PaintCanvasNames`) */
6
- var BRUSH_PRESET_FILE_FORMAT = "paintcanvas-brush-presets";
7
- /** Formats of brush preset files that are imported by default */
8
- var BRUSH_PRESET_FILE_FORMATS = [BRUSH_PRESET_FILE_FORMAT];
9
- /** Longest brush preset file format name (characters) */
10
- var MAX_PRESET_FILE_FORMAT_LENGTH = 100;
11
- /** The version of the brush preset file format */
12
- var BRUSH_PRESET_FILE_VERSION = 1;
5
+ /** Version of the brush preset schema */
6
+ var BRUSH_PRESET_SCHEMA_VERSION = "1.0.0";
7
+ /** `@type` of a brush preset */
8
+ var BRUSH_PRESET_TYPE = "PaintCanvas/BrushConfig";
9
+ /** Version of the brush preset collection schema */
10
+ var BRUSH_PRESET_COLLECTION_SCHEMA_VERSION = "1.0.0";
11
+ /** `@type` of a brush preset collection file */
12
+ var BRUSH_PRESET_COLLECTION_TYPE = "PaintCanvas/BrushConfigCollection";
13
13
  /** Most presets in one file */
14
14
  var MAX_PRESETS_PER_FILE = 1e3;
15
- /** Longest preset name, author name or handle (characters) */
15
+ /** Longest preset name (characters) */
16
16
  var MAX_PRESET_TEXT_LENGTH = 100;
17
17
  /** Longest brush shape data URL (characters): a 2 MB PNG as base64 */
18
18
  var MAX_SHAPE_DATA_URL_LENGTH = Math.ceil(2097152 / 3) * 4 + 22;
@@ -39,11 +39,7 @@ var paramConfig = {
39
39
  minTilt: factor,
40
40
  maxTilt: factor,
41
41
  profile: profilePointsSchema,
42
- profileId: {
43
- type: "string",
44
- minLength: 1,
45
- maxLength: 100
46
- }
42
+ profileId: profileIdSchema
47
43
  }
48
44
  };
49
45
  /** A colour value: a number, or a number as text */
@@ -59,11 +55,15 @@ var text = {
59
55
  };
60
56
  /** JSON schema for a brush preset a user made or imported (see `BrushConfig` in the app) */
61
57
  var brushPresetSchema = {
62
- $id: "paintcanvas/brush-preset",
58
+ $schema: SCHEMA_DIALECT,
59
+ $id: schemaUrl("brush-preset", BRUSH_PRESET_SCHEMA_VERSION),
60
+ "@type": BRUSH_PRESET_TYPE,
63
61
  type: "object",
64
62
  additionalProperties: false,
65
63
  required: ["id"],
66
64
  properties: {
65
+ $schema: fileSchemaUrlSchema,
66
+ "@type": { const: BRUSH_PRESET_TYPE },
67
67
  id: {
68
68
  type: "string",
69
69
  pattern: UUID_PATTERN
@@ -74,23 +74,7 @@ var brushPresetSchema = {
74
74
  type: "string",
75
75
  maxLength: 20
76
76
  },
77
- author: { anyOf: [text, {
78
- type: "object",
79
- additionalProperties: false,
80
- required: ["name"],
81
- properties: {
82
- name: text,
83
- handle: text,
84
- email: {
85
- type: "string",
86
- maxLength: 254
87
- },
88
- website: {
89
- type: "string",
90
- maxLength: 2048
91
- }
92
- }
93
- }] },
77
+ author: authorSchema,
94
78
  image: {
95
79
  type: "string",
96
80
  pattern: PNG_DATA_URL_PATTERN,
@@ -161,28 +145,12 @@ var brushPresetSchema = {
161
145
  snapToPixelGrid: { type: "boolean" }
162
146
  }
163
147
  };
164
- /** JSON schema for a brush preset file */
165
- var brushPresetFileSchema = {
166
- $id: "paintcanvas/brush-preset-file",
167
- type: "object",
168
- additionalProperties: false,
169
- required: [
170
- "format",
171
- "version",
172
- "presets"
173
- ],
174
- properties: {
175
- format: {
176
- type: "string",
177
- minLength: 1,
178
- maxLength: 100
179
- },
180
- version: { const: 1 },
181
- presets: {
182
- type: "array",
183
- maxItems: MAX_PRESETS_PER_FILE,
184
- items: { $ref: "brush-preset" }
185
- }
186
- }
187
- };
188
- export { BRUSH_PRESET_FILE_FORMAT, BRUSH_PRESET_FILE_FORMATS, BRUSH_PRESET_FILE_VERSION, MAX_PRESETS_PER_FILE, MAX_PRESET_FILE_FORMAT_LENGTH, MAX_PRESET_TEXT_LENGTH, MAX_SHAPE_DATA_URL_LENGTH, PNG_DATA_URL_PATTERN, UUID_PATTERN, brushPresetFileSchema, brushPresetSchema };
148
+ /** JSON schema for a brush preset collection file */
149
+ var brushPresetCollectionSchema = collectionSchema({
150
+ name: "brush-preset-collection",
151
+ version: BRUSH_PRESET_COLLECTION_SCHEMA_VERSION,
152
+ type: BRUSH_PRESET_COLLECTION_TYPE,
153
+ item: brushPresetSchema.$id,
154
+ maxItems: MAX_PRESETS_PER_FILE
155
+ });
156
+ export { BRUSH_PRESET_COLLECTION_SCHEMA_VERSION, BRUSH_PRESET_COLLECTION_TYPE, BRUSH_PRESET_SCHEMA_VERSION, BRUSH_PRESET_TYPE, MAX_PRESETS_PER_FILE, MAX_PRESET_TEXT_LENGTH, MAX_SHAPE_DATA_URL_LENGTH, PNG_DATA_URL_PATTERN, UUID_PATTERN, brushPresetCollectionSchema, brushPresetSchema };
@@ -0,0 +1,10 @@
1
+ import AssetFile from "../../assets";
2
+ import type { ProfileGraph } from "..";
3
+ /**
4
+ * Reads and writes profile graph collection files.
5
+ *
6
+ * @example
7
+ * const graphs = profileGraphFile.parse(await file.text()); // throws AssetFileError
8
+ * const json = profileGraphFile.write(app.profiles.graphs);
9
+ */
10
+ export declare const profileGraphFile: AssetFile<ProfileGraph>;
@@ -0,0 +1,19 @@
1
+ import AssetFile from "../../assets/index.js";
2
+ import { validateProfileGraphCollection } from "../../validation/validators.generated.js";
3
+ import { PROFILE_GRAPH_COLLECTION_SCHEMA_VERSION, PROFILE_GRAPH_COLLECTION_TYPE } from "../schema.js";
4
+ // src/lib/profiles/profileFile/index.ts
5
+ /**
6
+ * Reads and writes profile graph collection files.
7
+ *
8
+ * @example
9
+ * const graphs = profileGraphFile.parse(await file.text()); // throws AssetFileError
10
+ * const json = profileGraphFile.write(app.profiles.graphs);
11
+ */
12
+ var profileGraphFile = new AssetFile({
13
+ schema: "profile-graph-collection",
14
+ version: PROFILE_GRAPH_COLLECTION_SCHEMA_VERSION,
15
+ type: PROFILE_GRAPH_COLLECTION_TYPE,
16
+ validate: validateProfileGraphCollection,
17
+ fileName: "profile-graphs"
18
+ });
19
+ export { profileGraphFile };
@@ -1,7 +1,24 @@
1
1
  /** Longest profile graph ID or name (characters) */
2
2
  export declare const MAX_PROFILE_TEXT_LENGTH = 100;
3
- /** Most profile graphs a user can keep */
3
+ /** Most profile graphs a user can keep (and in one file) */
4
4
  export declare const MAX_SAVED_PROFILES = 100;
5
+ /** Version of the profile graph schema */
6
+ export declare const PROFILE_GRAPH_SCHEMA_VERSION = "1.0.0";
7
+ /** `@type` of a profile graph */
8
+ export declare const PROFILE_GRAPH_TYPE = "PaintCanvas/ProfileGraph";
9
+ /** Version of the profile graph collection schema */
10
+ export declare const PROFILE_GRAPH_COLLECTION_SCHEMA_VERSION = "1.0.0";
11
+ /** `@type` of a profile graph collection file */
12
+ export declare const PROFILE_GRAPH_COLLECTION_TYPE = "PaintCanvas/ProfileGraphCollection";
13
+ /** Schema of a profile graph's ID: a UUID for the user's own, or a built-in graph's ID */
14
+ export declare const profileIdSchema: {
15
+ readonly anyOf: readonly [{
16
+ readonly type: "string";
17
+ readonly pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
18
+ }, {
19
+ readonly enum: string[];
20
+ }];
21
+ };
5
22
  /** Schema of a profile graph's points, from left to right */
6
23
  export declare const profilePointsSchema: {
7
24
  readonly type: "array";
@@ -30,20 +47,70 @@ export declare const profilePointsSchema: {
30
47
  };
31
48
  /** Schema of a named profile graph */
32
49
  export declare const profileGraphSchema: {
50
+ readonly $schema: "https://json-schema.org/draft/2020-12/schema";
51
+ readonly $id: string;
52
+ readonly "@type": "PaintCanvas/ProfileGraph";
33
53
  readonly type: "object";
34
54
  readonly additionalProperties: false;
35
55
  readonly required: readonly ["id", "name", "points"];
36
56
  readonly properties: {
37
- readonly id: {
57
+ readonly $schema: {
38
58
  readonly type: "string";
39
59
  readonly minLength: 1;
40
- readonly maxLength: 100;
60
+ readonly maxLength: 2048;
61
+ };
62
+ readonly "@type": {
63
+ readonly const: "PaintCanvas/ProfileGraph";
64
+ };
65
+ readonly id: {
66
+ readonly anyOf: readonly [{
67
+ readonly type: "string";
68
+ readonly pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
69
+ }, {
70
+ readonly enum: string[];
71
+ }];
41
72
  };
42
73
  readonly name: {
43
74
  readonly type: "string";
44
75
  readonly minLength: 1;
45
76
  readonly maxLength: 100;
46
77
  };
78
+ readonly author: {
79
+ readonly anyOf: readonly [{
80
+ readonly type: "string";
81
+ readonly minLength: 1;
82
+ readonly maxLength: 100;
83
+ }, {
84
+ readonly type: "object";
85
+ readonly additionalProperties: false;
86
+ readonly required: readonly ["name"];
87
+ readonly properties: {
88
+ readonly did: {
89
+ readonly type: "string";
90
+ readonly maxLength: 2048;
91
+ readonly pattern: "^did:[a-z]+:[a-zA-Z0-9._:%-]+$";
92
+ };
93
+ readonly name: {
94
+ readonly type: "string";
95
+ readonly minLength: 1;
96
+ readonly maxLength: 100;
97
+ };
98
+ readonly handle: {
99
+ readonly type: "string";
100
+ readonly minLength: 1;
101
+ readonly maxLength: 100;
102
+ };
103
+ readonly email: {
104
+ readonly type: "string";
105
+ readonly maxLength: 254;
106
+ };
107
+ readonly homepage: {
108
+ readonly type: "string";
109
+ readonly maxLength: 2048;
110
+ };
111
+ };
112
+ }];
113
+ };
47
114
  readonly points: {
48
115
  readonly type: "array";
49
116
  readonly minItems: 2;
@@ -71,3 +138,29 @@ export declare const profileGraphSchema: {
71
138
  };
72
139
  };
73
140
  };
141
+ /** Schema of a profile graph collection file */
142
+ export declare const profileGraphCollectionSchema: {
143
+ $schema: string;
144
+ $id: string;
145
+ "@type": string;
146
+ type: string;
147
+ additionalProperties: boolean;
148
+ required: string[];
149
+ properties: {
150
+ $schema: {
151
+ readonly type: "string";
152
+ readonly minLength: 1;
153
+ readonly maxLength: 2048;
154
+ };
155
+ "@type": {
156
+ const: string;
157
+ };
158
+ items: {
159
+ type: string;
160
+ maxItems: number;
161
+ items: {
162
+ $ref: string;
163
+ };
164
+ };
165
+ };
166
+ };
@@ -1,4 +1,19 @@
1
- import { Interpolation } from "./index.js";
1
+ import { Interpolation, PROFILE_PRESETS } from "./index.js";
2
+ import { UUID_PATTERN, authorSchema, collectionSchema, fileSchemaUrlSchema } from "../assets/schema.js";
3
+ import { SCHEMA_DIALECT, schemaUrl } from "../schemas/index.js";
4
+ /** Version of the profile graph schema */
5
+ var PROFILE_GRAPH_SCHEMA_VERSION = "1.0.0";
6
+ /** `@type` of a profile graph */
7
+ var PROFILE_GRAPH_TYPE = "PaintCanvas/ProfileGraph";
8
+ /** Version of the profile graph collection schema */
9
+ var PROFILE_GRAPH_COLLECTION_SCHEMA_VERSION = "1.0.0";
10
+ /** `@type` of a profile graph collection file */
11
+ var PROFILE_GRAPH_COLLECTION_TYPE = "PaintCanvas/ProfileGraphCollection";
12
+ /** Schema of a profile graph's ID: a UUID for the user's own, or a built-in graph's ID */
13
+ var profileIdSchema = { anyOf: [{
14
+ type: "string",
15
+ pattern: UUID_PATTERN
16
+ }, { enum: PROFILE_PRESETS.map((preset) => preset.id) }] };
2
17
  /** Schema of a profile graph's points, from left to right */
3
18
  var profilePointsSchema = {
4
19
  type: "array",
@@ -29,6 +44,9 @@ var profilePointsSchema = {
29
44
  };
30
45
  /** Schema of a named profile graph */
31
46
  var profileGraphSchema = {
47
+ $schema: SCHEMA_DIALECT,
48
+ $id: schemaUrl("profile-graph", PROFILE_GRAPH_SCHEMA_VERSION),
49
+ "@type": PROFILE_GRAPH_TYPE,
32
50
  type: "object",
33
51
  additionalProperties: false,
34
52
  required: [
@@ -37,17 +55,23 @@ var profileGraphSchema = {
37
55
  "points"
38
56
  ],
39
57
  properties: {
40
- id: {
41
- type: "string",
42
- minLength: 1,
43
- maxLength: 100
44
- },
58
+ $schema: fileSchemaUrlSchema,
59
+ "@type": { const: PROFILE_GRAPH_TYPE },
60
+ id: profileIdSchema,
45
61
  name: {
46
62
  type: "string",
47
63
  minLength: 1,
48
64
  maxLength: 100
49
65
  },
66
+ author: authorSchema,
50
67
  points: profilePointsSchema
51
68
  }
52
69
  };
53
- export { profileGraphSchema, profilePointsSchema };
70
+ collectionSchema({
71
+ name: "profile-graph-collection",
72
+ version: PROFILE_GRAPH_COLLECTION_SCHEMA_VERSION,
73
+ type: PROFILE_GRAPH_COLLECTION_TYPE,
74
+ item: profileGraphSchema.$id,
75
+ maxItems: 100
76
+ });
77
+ export { PROFILE_GRAPH_COLLECTION_SCHEMA_VERSION, PROFILE_GRAPH_COLLECTION_TYPE, PROFILE_GRAPH_SCHEMA_VERSION, PROFILE_GRAPH_TYPE, profileGraphSchema, profileIdSchema, profilePointsSchema };
@@ -0,0 +1,42 @@
1
+ /** Where PaintCanvas's JSON schemas are published */
2
+ export declare const SCHEMA_BASE_URL = "https://lvl99.github.io/paintcanvas/schemas/";
3
+ /** The JSON Schema dialect PaintCanvas's schemas are written in */
4
+ export declare const SCHEMA_DIALECT = "https://json-schema.org/draft/2020-12/schema";
5
+ /** A schema's name and version, read from its URL */
6
+ export interface SchemaName {
7
+ /** e.g. `brush-preset` */
8
+ name: string;
9
+ /** e.g. `1.0.0` */
10
+ version: string;
11
+ }
12
+ /**
13
+ * The URL a schema is published at: its `$id`.
14
+ *
15
+ * @example
16
+ * schemaUrl("brush-preset", "1.0.0"); // "https://lvl99.github.io/paintcanvas/schemas/brush-preset-1.0.0.json"
17
+ */
18
+ export declare const schemaUrl: (name: string, version: string) => string;
19
+ /**
20
+ * The name and version of a schema from its URL, or undefined if it isn't one of PaintCanvas's published schemas.
21
+ *
22
+ * @example
23
+ * parseSchemaUrl("https://lvl99.github.io/paintcanvas/schemas/brush-preset-1.0.0.json"); // { name: "brush-preset", version: "1.0.0" }
24
+ * parseSchemaUrl("https://example.com/other.json"); // undefined
25
+ */
26
+ export declare const parseSchemaUrl: (url: unknown) => SchemaName | undefined;
27
+ /**
28
+ * Compare two `major.minor.patch` versions: negative when `a` is older, positive when newer, 0 when the same. Versions
29
+ * that can't be read sort first.
30
+ *
31
+ * @example
32
+ * compareVersions("1.2.0", "1.10.0"); // negative
33
+ */
34
+ export declare const compareVersions: (a: string, b: string) => number;
35
+ /**
36
+ * The major part of a `major.minor.patch` version. Files whose schema has the same major version as the app's are
37
+ * read without migrating (later minor versions only add optional properties).
38
+ *
39
+ * @example
40
+ * majorVersion("1.2.3"); // 1
41
+ */
42
+ export declare const majorVersion: (version: string) => number;
@@ -0,0 +1,60 @@
1
+ // src/lib/schemas/index.ts
2
+ /** Where PaintCanvas's JSON schemas are published */
3
+ var SCHEMA_BASE_URL = "https://lvl99.github.io/paintcanvas/schemas/";
4
+ /** The JSON Schema dialect PaintCanvas's schemas are written in */
5
+ var SCHEMA_DIALECT = "https://json-schema.org/draft/2020-12/schema";
6
+ /** Matches a semver version without pre-release or build parts, e.g. `1.0.0` */
7
+ var VERSION_PATTERN = /^(\d+)\.(\d+)\.(\d+)$/;
8
+ /** Matches a published schema URL, capturing its name and version */
9
+ var SCHEMA_URL_PATTERN = /^(.+)-(\d+\.\d+\.\d+)\.json$/;
10
+ /**
11
+ * The URL a schema is published at: its `$id`.
12
+ *
13
+ * @example
14
+ * schemaUrl("brush-preset", "1.0.0"); // "https://lvl99.github.io/paintcanvas/schemas/brush-preset-1.0.0.json"
15
+ */
16
+ var schemaUrl = (name, version) => `${SCHEMA_BASE_URL}${name}-${version}.json`;
17
+ /**
18
+ * The name and version of a schema from its URL, or undefined if it isn't one of PaintCanvas's published schemas.
19
+ *
20
+ * @example
21
+ * parseSchemaUrl("https://lvl99.github.io/paintcanvas/schemas/brush-preset-1.0.0.json"); // { name: "brush-preset", version: "1.0.0" }
22
+ * parseSchemaUrl("https://example.com/other.json"); // undefined
23
+ */
24
+ var parseSchemaUrl = (url) => {
25
+ if (typeof url !== "string" || !url.startsWith("https://lvl99.github.io/paintcanvas/schemas/")) return void 0;
26
+ const match = SCHEMA_URL_PATTERN.exec(url.slice(44));
27
+ return match ? {
28
+ name: match[1],
29
+ version: match[2]
30
+ } : void 0;
31
+ };
32
+ /**
33
+ * Compare two `major.minor.patch` versions: negative when `a` is older, positive when newer, 0 when the same. Versions
34
+ * that can't be read sort first.
35
+ *
36
+ * @example
37
+ * compareVersions("1.2.0", "1.10.0"); // negative
38
+ */
39
+ var compareVersions = (a, b) => {
40
+ const parts = (version) => (VERSION_PATTERN.exec(version)?.slice(1) ?? [
41
+ "-1",
42
+ "0",
43
+ "0"
44
+ ]).map(Number);
45
+ const [x, y] = [parts(a), parts(b)];
46
+ for (let i = 0; i < 3; i++) {
47
+ const difference = x[i] - y[i];
48
+ if (difference !== 0) return difference;
49
+ }
50
+ return 0;
51
+ };
52
+ /**
53
+ * The major part of a `major.minor.patch` version. Files whose schema has the same major version as the app's are
54
+ * read without migrating (later minor versions only add optional properties).
55
+ *
56
+ * @example
57
+ * majorVersion("1.2.3"); // 1
58
+ */
59
+ var majorVersion = (version) => Number(VERSION_PATTERN.exec(version)?.[1] ?? NaN);
60
+ export { SCHEMA_BASE_URL, SCHEMA_DIALECT, compareVersions, majorVersion, parseSchemaUrl, schemaUrl };
@@ -1,14 +1,6 @@
1
1
  import type PaintCanvas from "../classes/PaintCanvas";
2
2
  import { type AppSettings } from "./schema";
3
3
  export * from "./schema";
4
- /** Messages shown when importing settings fails */
5
- export declare const SETTINGS_FILE_ERRORS: {
6
- readonly incompatible: "Settings JSON file not compatible";
7
- readonly read: "Failed to read settings JSON file";
8
- };
9
- /** Importing settings failed, with a message for the user */
10
- export declare class SettingsFileError extends Error {
11
- }
12
4
  /** Result of checking settings */
13
5
  export type SettingsValidationResult = {
14
6
  valid: true;
@@ -24,22 +16,44 @@ export type SettingsValidationResult = {
24
16
  * isValidSettings({ palette: ["#ff0000"] }).valid; // true
25
17
  */
26
18
  export declare const isValidSettings: (input: unknown) => SettingsValidationResult;
19
+ /** Assets that app settings can hold */
20
+ export type SettingsAsset = "brushes" | "palettes" | "profiles";
21
+ /** What `collectSettings` leaves out */
22
+ export interface CollectSettingsOptions {
23
+ /** Assets to leave out, e.g. ones kept in stores of their own */
24
+ without?: readonly SettingsAsset[];
25
+ }
26
+ /**
27
+ * The app settings of a canvas: its input settings, keyboard shortcuts, colours, the user's colour palettes, profile
28
+ * graphs and brush presets, theme and language, and settings wrapper apps added (see `SettingsExtension`).
29
+ *
30
+ * @example
31
+ * collectSettings(canvas).palettes; // the user's own palettes
32
+ * collectSettings(canvas, { without: ["profiles"] }).profiles; // undefined
33
+ */
34
+ export declare const collectSettings: (app: PaintCanvas, { without }?: CollectSettingsOptions) => AppSettings;
35
+ /** Name of the palette that colours saved in PaintCanvas's palette by older versions are moved to */
36
+ export declare const OLDER_PALETTE_NAME = "My colours";
27
37
  /**
28
- * The app settings of a canvas: its input settings, keyboard shortcuts, colour palette, colours, profile graphs, theme
29
- * and language.
38
+ * Keep colours that older versions saved in PaintCanvas's palette (which can no longer be changed) in a palette of the
39
+ * user's own, named `OLDER_PALETTE_NAME`: unless they're PaintCanvas's colours, or one of the user's palettes already has
40
+ * them.
30
41
  *
31
42
  * @example
32
- * collectSettings(canvas).palette; // ["#2c6bff", ...]
43
+ * keepOlderPalette(canvas, ["#123456"]); // the user now has a "My colours" palette with #123456
33
44
  */
34
- export declare const collectSettings: (app: PaintCanvas) => AppSettings;
45
+ export declare const keepOlderPalette: (app: PaintCanvas, colours: readonly string[]) => void;
35
46
  /**
36
47
  * Use app settings on a canvas, e.g. ones kept in the browser or imported. Parts left out stay as they are; invalid
37
- * values within a part are left out (see each part's sanitising).
48
+ * values within a part are left out (see each part's sanitising). Colour palettes, profile graphs and brush presets are
49
+ * added to the user's own, replacing those with the same IDs. Colours older versions saved in PaintCanvas's palette are
50
+ * moved to one of the user's own (see `keepOlderPalette`). Other parts go to the settings extensions (see
51
+ * `SettingsExtensions.apply`).
38
52
  *
39
53
  * @example
40
- * applySettings(canvas, { colours: { foreground: "#ff0000", background: "#ffffff" } });
54
+ * await applySettings(canvas, { colours: { foreground: "#ff0000", background: "#ffffff" } });
41
55
  */
42
- export declare const applySettings: (app: PaintCanvas, settings: AppSettings) => void;
56
+ export declare const applySettings: (app: PaintCanvas, settings: AppSettings) => Promise<void>;
43
57
  /**
44
58
  * The file name settings are exported to on a day, starting with a prefix (see `PaintCanvasNames.filePrefix`).
45
59
  *
@@ -48,17 +62,18 @@ export declare const applySettings: (app: PaintCanvas, settings: AppSettings) =>
48
62
  */
49
63
  export declare const settingsFileName: (date?: Date, prefix?: string) => string;
50
64
  /**
51
- * Write app settings to a settings file (JSON) of a format (see `PaintCanvasNames.settingsFileFormat`).
65
+ * Write app settings to an app settings file (JSON). Colours older versions saved in PaintCanvas's palette are left out.
52
66
  *
53
67
  * @example
54
- * exportSettingsFile(collectSettings(canvas)); // '{ "format": "paintcanvas-settings", "version": 1, "settings": {...} }'
68
+ * exportSettingsFile(collectSettings(canvas)); // '{ "$schema": ".../app-settings-1.0.0.json", "@type": "PaintCanvas/AppSettings", ... }'
55
69
  */
56
- export declare const exportSettingsFile: (settings: AppSettings, format?: string) => string;
70
+ export declare const exportSettingsFile: (settings: AppSettings) => string;
57
71
  /**
58
- * Read the app settings in a settings file of one of the given formats (PaintCanvas's by default). Throws a
59
- * `SettingsFileError` if it isn't valid JSON or a compatible file.
72
+ * Read the app settings in an app settings file. Settings files from before versioned schemas (`format`, `version: 1`
73
+ * and `settings`, of any format name) are read too. Throws an `AssetFileError`: `read` if it isn't JSON, `invalid` if it
74
+ * isn't a settings file or doesn't match its schema, `unsupported` if it's a version the app can't read.
60
75
  *
61
76
  * @example
62
- * applySettings(canvas, parseSettingsFile(text));
77
+ * await applySettings(canvas, parseSettingsFile(text));
63
78
  */
64
- export declare const parseSettingsFile: (text: string, formats?: readonly string[]) => AppSettings;
79
+ export declare const parseSettingsFile: (text: string) => AppSettings;