@capybara-hq/plugin-sdk 0.1.0-rc.9 → 0.1.0-rc.90
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 +3 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +11 -3
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/identity-source.md +2 -0
- package/agent-docs/extension-points/model-provider.md +5 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extension-points/trigger-source.md +19 -0
- package/agent-docs/extensions.md +98 -4
- package/agent-docs/plugin-format.md +45 -10
- package/agent-docs/setup.md +54 -0
- package/api/plugin-sdk.api.md +5983 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/agents-ctx.d.ts +116 -0
- package/dist/agents-ctx.js +22 -0
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +121 -13
- package/dist/cards.js +161 -19
- package/dist/channel.d.ts +133 -47
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +28 -6
- package/dist/config-ui.js +88 -25
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/connector-auth.d.ts +13 -2
- package/dist/connector-auth.js +82 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +344 -31
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +18 -12
- package/dist/define-extension.js +18 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +348 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +286 -49
- package/dist/device-protocol.js +766 -89
- package/dist/device-provider.d.ts +820 -0
- package/dist/device-provider.js +432 -0
- package/dist/device-service.d.ts +204 -0
- package/dist/device-service.js +291 -0
- package/dist/dial-in.d.ts +286 -0
- package/dist/dial-in.js +213 -0
- package/dist/directory.d.ts +15 -12
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +8 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +46 -9
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +185 -22
- package/dist/hooks.js +6 -0
- package/dist/http-access.d.ts +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +70 -9
- package/dist/identity.js +46 -1
- package/dist/inbox.d.ts +103 -0
- package/dist/inbox.js +173 -0
- package/dist/index.d.ts +30 -4
- package/dist/index.js +30 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +295 -77
- package/dist/model.js +249 -21
- package/dist/native-failure.d.ts +13 -0
- package/dist/native-failure.js +31 -0
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +95 -25
- package/dist/permissions.js +175 -54
- package/dist/platform-only.d.ts +27 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +30 -6
- package/dist/plugin-manifest.js +147 -55
- package/dist/plugin-package.d.ts +82 -39
- package/dist/plugin-package.js +68 -41
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2343 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +480 -0
- package/dist/sandbox-runtime-source.d.ts +47 -0
- package/dist/sandbox-runtime-source.js +73 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +8 -2
- package/dist/secret.js +11 -4
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +86 -72
- package/dist/setup-guide.js +340 -108
- package/dist/shell-capabilities.d.ts +216 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill-invocation.d.ts +5 -0
- package/dist/skill-invocation.js +4 -3
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +25 -9
- package/dist/theme-assets.js +87 -47
- package/dist/theme-tokens.generated.d.ts +40 -12
- package/dist/theme-tokens.generated.js +36 -8
- package/dist/theme.d.ts +56 -10
- package/dist/theme.js +117 -23
- package/dist/tool.d.ts +242 -28
- package/dist/tool.js +135 -13
- package/dist/trigger-source.d.ts +35 -0
- package/dist/trigger-source.js +2 -0
- package/dist/triggers.d.ts +88 -0
- package/dist/triggers.js +71 -0
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +374 -0
- package/dist/ui-resolve.d.ts +2 -7
- package/dist/ui-resolve.js +7 -19
- package/dist/ui-slots.d.ts +27 -5
- package/dist/ui-slots.js +112 -19
- package/dist/ui.d.ts +203 -64
- package/dist/ui.js +117 -23
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +62 -4
- package/schemas/plugin.v1.schema.json +74 -143
- package/schemas/theme.v1.schema.json +77 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
package/dist/theme.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type BuiltinAvatarPresetId } from "./avatar-presets.js";
|
|
2
3
|
import { type LocalizedName } from "./plugin-package.js";
|
|
3
4
|
import { type MergedScheme, type ThemeScheme } from "./theme-readability.js";
|
|
4
5
|
/**
|
|
5
6
|
* A theme file `themes/<id>.json` (themes spec §4): a partial override of the design tokens per
|
|
6
|
-
* scheme, optional fonts
|
|
7
|
+
* scheme, optional fonts, an optional logo and the brand fields (theme brand coverage spec §1:
|
|
8
|
+
* illustration, app icons, decoration, avatar presets). The id is the file's base name
|
|
7
9
|
* ({@link themeIdOf}, `CATALOG_ITEM_NAME_RE`).
|
|
8
10
|
*
|
|
9
11
|
* {@link parseThemeFile} is the CSS-injection boundary: every token value is parsed against the
|
|
10
12
|
* grammar `tokens.json` uses (`#RRGGBB`, `rgba(r,g,b,a)`, shadows `<x> <y> <blur> [<spread>]
|
|
11
13
|
* <color>`) and re-rendered from its parts in canonical form. Asset paths (`fonts[].file`,
|
|
12
|
-
* `logo
|
|
13
|
-
* to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
|
|
14
|
-
* letters, digits, spaces and `-`. Free text (`name`, `description`,
|
|
15
|
-
* control, format, line / paragraph separator or
|
|
16
|
-
* never CSS. Whether the files exist and their
|
|
17
|
-
* the reader of the package, with {@link THEME_LIMITS}.
|
|
14
|
+
* `logo.*`, `avatars[].file`) are relative to the plugin root (an optional leading `./`) and every
|
|
15
|
+
* segment is limited to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
|
|
16
|
+
* families are limited to letters, digits, spaces and `-`. Free text (`name`, `description`,
|
|
17
|
+
* `logo.wordmark`, `avatars[].name`) carries no control, format, line / paragraph separator or
|
|
18
|
+
* lone surrogate characters; it is text for the UI, never CSS. Whether the files exist and their
|
|
19
|
+
* size / signature / SVG rules are checked by the reader of the package, with {@link THEME_LIMITS}.
|
|
18
20
|
*
|
|
19
21
|
* The committed JSON Schema (`schemas/theme.v1.schema.json`) is generated from
|
|
20
22
|
* {@link ThemeFileSchema} (the shape only) by `pnpm gen:package-schemas`; token names, value
|
|
@@ -26,7 +28,7 @@ export declare const THEME_LIMITS: {
|
|
|
26
28
|
readonly fileBytes: number;
|
|
27
29
|
/** Themes per plugin. */
|
|
28
30
|
readonly perPlugin: 10;
|
|
29
|
-
/** Total bytes of a plugin's theme assets (fonts and
|
|
31
|
+
/** Total bytes of a plugin's theme assets (fonts, logos, app icons and avatars). */
|
|
30
32
|
readonly assetsBytes: number;
|
|
31
33
|
/** Fonts per theme. */
|
|
32
34
|
readonly fonts: 8;
|
|
@@ -38,9 +40,21 @@ export declare const THEME_LIMITS: {
|
|
|
38
40
|
readonly pngBytes: number;
|
|
39
41
|
/** Minimum pixel height of a logo PNG. */
|
|
40
42
|
readonly pngMinHeight: 64;
|
|
41
|
-
/** Characters of the wordmark. */
|
|
43
|
+
/** Characters of the wordmark (and of each avatar preset name). */
|
|
42
44
|
readonly wordmark: 24;
|
|
45
|
+
/** Avatar presets per theme. */
|
|
46
|
+
readonly avatars: 12;
|
|
47
|
+
/** Bytes of an app icon PNG. */
|
|
48
|
+
readonly appIconBytes: 1048576;
|
|
49
|
+
/** Minimum pixel size of an app icon PNG (square). */
|
|
50
|
+
readonly appIconMinSize: 512;
|
|
43
51
|
};
|
|
52
|
+
/** The id of a theme's avatar preset (`avatars[].id`); never a built-in preset id. */
|
|
53
|
+
export declare const THEME_AVATAR_ID_RE: RegExp;
|
|
54
|
+
/** The sign-in page background decoration (the dither columns) a theme asks for; omitted means
|
|
55
|
+
* `dither`. */
|
|
56
|
+
export declare const THEME_DECORATIONS: readonly ["dither", "none"];
|
|
57
|
+
export type ThemeDecoration = (typeof THEME_DECORATIONS)[number];
|
|
44
58
|
/** A theme of the plugin: a `./…/<id>.json` file ({@link ThemeFile}). */
|
|
45
59
|
export interface PluginThemeRef {
|
|
46
60
|
path: string;
|
|
@@ -74,6 +88,24 @@ export interface ThemeLogo {
|
|
|
74
88
|
wordmark?: string;
|
|
75
89
|
/** `.svg` or `.png` path inside the plugin. */
|
|
76
90
|
favicon?: string;
|
|
91
|
+
/** The empty-state art: `.svg` or `.png` path inside the plugin, the `mark` rules. */
|
|
92
|
+
illustration?: string;
|
|
93
|
+
/** Apple touch and manifest `any` icon: a square `.png` path, ≥ 512 px, ≤ 1 MiB. */
|
|
94
|
+
appIcon?: string;
|
|
95
|
+
/** Manifest `maskable` icon: a square `.png` path, ≥ 512 px, ≤ 1 MiB; requires `appIcon`. */
|
|
96
|
+
appIconMaskable?: string;
|
|
97
|
+
}
|
|
98
|
+
/** An agent avatar preset the theme adds to the picker. */
|
|
99
|
+
export interface ThemeAvatarPreset {
|
|
100
|
+
/** {@link THEME_AVATAR_ID_RE}, unique in the theme, not a built-in preset id. */
|
|
101
|
+
id: string;
|
|
102
|
+
/** Each ≤ 24 characters, the wordmark's character rules. */
|
|
103
|
+
name: {
|
|
104
|
+
en: string;
|
|
105
|
+
zh?: string;
|
|
106
|
+
};
|
|
107
|
+
/** A square `.svg` or `.png` path inside the plugin (PNG ≥ 64 px, the `mark` size limits). */
|
|
108
|
+
file: string;
|
|
77
109
|
}
|
|
78
110
|
/** `themes/<id>.json`. */
|
|
79
111
|
export interface ThemeFile {
|
|
@@ -86,6 +118,12 @@ export interface ThemeFile {
|
|
|
86
118
|
schemes: Partial<Record<ThemeScheme, ThemeSchemeOverride>>;
|
|
87
119
|
fonts?: ThemeFont[];
|
|
88
120
|
logo?: ThemeLogo;
|
|
121
|
+
/** Omitted means `dither`; readers apply the default. */
|
|
122
|
+
decoration?: ThemeDecoration;
|
|
123
|
+
/** At most {@link THEME_LIMITS}`.avatars`. */
|
|
124
|
+
avatars?: ThemeAvatarPreset[];
|
|
125
|
+
/** Built-in presets not offered; hiding all of them requires at least one `avatars` entry. */
|
|
126
|
+
hideAvatarPresets?: BuiltinAvatarPresetId[];
|
|
89
127
|
}
|
|
90
128
|
/**
|
|
91
129
|
* A theme file after {@link parseThemeFile}: values canonical. It holds only the file's own
|
|
@@ -108,7 +146,7 @@ export interface ParseThemeOptions {
|
|
|
108
146
|
*/
|
|
109
147
|
readability?: boolean;
|
|
110
148
|
}
|
|
111
|
-
/** `themes/
|
|
149
|
+
/** `themes/neon-grid.json` → `neon-grid`. */
|
|
112
150
|
export declare function themeIdOf(path: string): string;
|
|
113
151
|
/**
|
|
114
152
|
* The zod schema of a theme file's shape (strict objects). Token names and values are only
|
|
@@ -130,6 +168,14 @@ export declare function isThemeFontFamily(v: unknown): v is string;
|
|
|
130
168
|
* every segment of `[A-Za-z0-9._-]`, no `.` / `..` segments (the extension is not checked).
|
|
131
169
|
*/
|
|
132
170
|
export declare function isThemeAssetPath(v: unknown): v is string;
|
|
171
|
+
/**
|
|
172
|
+
* Values a theme scheme takes for tokens it leaves out but whose built-in value only suits the
|
|
173
|
+
* built-in palette. `field` (the ground of a form control) is white in the built-in light scheme
|
|
174
|
+
* because the built-in cards are grey: a scheme that recolours `panel` without naming `field`
|
|
175
|
+
* keeps clear fields, so its controls show its own card through, as they did before `field`
|
|
176
|
+
* existed. A theme that wants filled fields names `field` itself.
|
|
177
|
+
*/
|
|
178
|
+
export declare function themeSchemeFallbacks(overridden: ReadonlySet<string>): Record<string, string>;
|
|
133
179
|
/**
|
|
134
180
|
* Each scheme the theme defines, merged onto the current built-in values (for swatches, the
|
|
135
181
|
* readability check and anything else that needs full values). A stored theme is read leniently:
|
package/dist/theme.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { BUILTIN_AVATAR_PRESET_IDS } from "./avatar-presets.js";
|
|
2
3
|
import { CATALOG_ITEM_NAME_RE, isSafePackagePath } from "./plugin-package.js";
|
|
3
4
|
import { checkThemeReadability } from "./theme-readability.js";
|
|
4
5
|
import { THEME_OVERRIDABLE, THEME_TOKENS } from "./theme-tokens.generated.js";
|
|
5
6
|
/**
|
|
6
7
|
* A theme file `themes/<id>.json` (themes spec §4): a partial override of the design tokens per
|
|
7
|
-
* scheme, optional fonts
|
|
8
|
+
* scheme, optional fonts, an optional logo and the brand fields (theme brand coverage spec §1:
|
|
9
|
+
* illustration, app icons, decoration, avatar presets). The id is the file's base name
|
|
8
10
|
* ({@link themeIdOf}, `CATALOG_ITEM_NAME_RE`).
|
|
9
11
|
*
|
|
10
12
|
* {@link parseThemeFile} is the CSS-injection boundary: every token value is parsed against the
|
|
11
13
|
* grammar `tokens.json` uses (`#RRGGBB`, `rgba(r,g,b,a)`, shadows `<x> <y> <blur> [<spread>]
|
|
12
14
|
* <color>`) and re-rendered from its parts in canonical form. Asset paths (`fonts[].file`,
|
|
13
|
-
* `logo
|
|
14
|
-
* to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
|
|
15
|
-
* letters, digits, spaces and `-`. Free text (`name`, `description`,
|
|
16
|
-
* control, format, line / paragraph separator or
|
|
17
|
-
* never CSS. Whether the files exist and their
|
|
18
|
-
* the reader of the package, with {@link THEME_LIMITS}.
|
|
15
|
+
* `logo.*`, `avatars[].file`) are relative to the plugin root (an optional leading `./`) and every
|
|
16
|
+
* segment is limited to `[A-Za-z0-9._-]`, so they need no escaping inside `url(...)`. Font
|
|
17
|
+
* families are limited to letters, digits, spaces and `-`. Free text (`name`, `description`,
|
|
18
|
+
* `logo.wordmark`, `avatars[].name`) carries no control, format, line / paragraph separator or
|
|
19
|
+
* lone surrogate characters; it is text for the UI, never CSS. Whether the files exist and their
|
|
20
|
+
* size / signature / SVG rules are checked by the reader of the package, with {@link THEME_LIMITS}.
|
|
19
21
|
*
|
|
20
22
|
* The committed JSON Schema (`schemas/theme.v1.schema.json`) is generated from
|
|
21
23
|
* {@link ThemeFileSchema} (the shape only) by `pnpm gen:package-schemas`; token names, value
|
|
@@ -27,7 +29,7 @@ export const THEME_LIMITS = {
|
|
|
27
29
|
fileBytes: 64 * 1024,
|
|
28
30
|
/** Themes per plugin. */
|
|
29
31
|
perPlugin: 10,
|
|
30
|
-
/** Total bytes of a plugin's theme assets (fonts and
|
|
32
|
+
/** Total bytes of a plugin's theme assets (fonts, logos, app icons and avatars). */
|
|
31
33
|
assetsBytes: 16 * 1024 * 1024,
|
|
32
34
|
/** Fonts per theme. */
|
|
33
35
|
fonts: 8,
|
|
@@ -39,10 +41,21 @@ export const THEME_LIMITS = {
|
|
|
39
41
|
pngBytes: 256 * 1024,
|
|
40
42
|
/** Minimum pixel height of a logo PNG. */
|
|
41
43
|
pngMinHeight: 64,
|
|
42
|
-
/** Characters of the wordmark. */
|
|
44
|
+
/** Characters of the wordmark (and of each avatar preset name). */
|
|
43
45
|
wordmark: 24,
|
|
46
|
+
/** Avatar presets per theme. */
|
|
47
|
+
avatars: 12,
|
|
48
|
+
/** Bytes of an app icon PNG. */
|
|
49
|
+
appIconBytes: 1_048_576,
|
|
50
|
+
/** Minimum pixel size of an app icon PNG (square). */
|
|
51
|
+
appIconMinSize: 512,
|
|
44
52
|
};
|
|
45
|
-
/** `
|
|
53
|
+
/** The id of a theme's avatar preset (`avatars[].id`); never a built-in preset id. */
|
|
54
|
+
export const THEME_AVATAR_ID_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
55
|
+
/** The sign-in page background decoration (the dither columns) a theme asks for; omitted means
|
|
56
|
+
* `dither`. */
|
|
57
|
+
export const THEME_DECORATIONS = ["dither", "none"];
|
|
58
|
+
/** `themes/neon-grid.json` → `neon-grid`. */
|
|
46
59
|
export function themeIdOf(path) {
|
|
47
60
|
return (path.split("/").pop() ?? "").replace(/\.json$/, "");
|
|
48
61
|
}
|
|
@@ -53,6 +66,8 @@ const FORBIDDEN_CHARS_RE = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/u;
|
|
|
53
66
|
const PATH_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
|
|
54
67
|
const FORBIDDEN_CHARS_MESSAGE = "must not contain control, format, line / paragraph separator or lone surrogate characters";
|
|
55
68
|
const IMAGE_RE = /\.(?:svg|png)$/i;
|
|
69
|
+
const PNG_RE = /\.png$/i;
|
|
70
|
+
const BUILTIN_AVATARS = new Set(BUILTIN_AVATAR_PRESET_IDS);
|
|
56
71
|
const MAX_VALUE_CHARS = 256;
|
|
57
72
|
const text = (max, what) => z
|
|
58
73
|
.string()
|
|
@@ -60,6 +75,14 @@ const text = (max, what) => z
|
|
|
60
75
|
.max(max)
|
|
61
76
|
.regex(/\S/, { message: `${what} must not be blank` })
|
|
62
77
|
.refine((t) => !FORBIDDEN_CHARS_RE.test(t), { message: `${what} ${FORBIDDEN_CHARS_MESSAGE}` });
|
|
78
|
+
/** Short free text (the wordmark, avatar names): not blank, ≤ 24 characters, no forbidden ones. */
|
|
79
|
+
const shortText = (what) => z
|
|
80
|
+
.string()
|
|
81
|
+
.regex(/\S/, { message: `${what} must not be blank` })
|
|
82
|
+
.refine((w) => [...w].length <= THEME_LIMITS.wordmark, {
|
|
83
|
+
message: `${what} must be at most ${THEME_LIMITS.wordmark} characters`,
|
|
84
|
+
})
|
|
85
|
+
.refine((w) => !FORBIDDEN_CHARS_RE.test(w), { message: `${what} ${FORBIDDEN_CHARS_MESSAGE}` });
|
|
63
86
|
/** A plugin-root relative path (optional `./`), each segment `[A-Za-z0-9._-]`, no `.` / `..`. */
|
|
64
87
|
const isPlainAssetPath = (p) => {
|
|
65
88
|
const rest = p.replace(/^\.\//, "");
|
|
@@ -81,7 +104,15 @@ const schemeOverride = z.strictObject({
|
|
|
81
104
|
.strictObject({ sm: radius.optional(), md: radius.optional(), bubble: radius.optional() })
|
|
82
105
|
.optional(),
|
|
83
106
|
});
|
|
84
|
-
const
|
|
107
|
+
const avatarPreset = z.strictObject({
|
|
108
|
+
id: z.string().regex(THEME_AVATAR_ID_RE, {
|
|
109
|
+
message: "id must match ^[a-z0-9][a-z0-9-]{0,31}$",
|
|
110
|
+
}),
|
|
111
|
+
name: z.strictObject({ en: shortText("name.en"), zh: shortText("name.zh").optional() }),
|
|
112
|
+
file: assetPath("file", IMAGE_RE, ".svg or .png"),
|
|
113
|
+
});
|
|
114
|
+
const shape = z
|
|
115
|
+
.strictObject({
|
|
85
116
|
$schema: z.string().max(512).optional(),
|
|
86
117
|
name: z.strictObject({ zh: text(100, "name.zh"), en: text(100, "name.en") }),
|
|
87
118
|
description: z
|
|
@@ -110,19 +141,67 @@ const shape = z.strictObject({
|
|
|
110
141
|
logo: z
|
|
111
142
|
.strictObject({
|
|
112
143
|
mark: assetPath("mark", IMAGE_RE, ".svg or .png").optional(),
|
|
113
|
-
wordmark:
|
|
114
|
-
.string()
|
|
115
|
-
.regex(/\S/, { message: "wordmark must not be blank" })
|
|
116
|
-
.refine((w) => [...w].length <= THEME_LIMITS.wordmark, {
|
|
117
|
-
message: `wordmark must be at most ${THEME_LIMITS.wordmark} characters`,
|
|
118
|
-
})
|
|
119
|
-
.refine((w) => !FORBIDDEN_CHARS_RE.test(w), {
|
|
120
|
-
message: `wordmark ${FORBIDDEN_CHARS_MESSAGE}`,
|
|
121
|
-
})
|
|
122
|
-
.optional(),
|
|
144
|
+
wordmark: shortText("wordmark").optional(),
|
|
123
145
|
favicon: assetPath("favicon", IMAGE_RE, ".svg or .png").optional(),
|
|
146
|
+
illustration: assetPath("illustration", IMAGE_RE, ".svg or .png").optional(),
|
|
147
|
+
appIcon: assetPath("appIcon", PNG_RE, ".png").optional(),
|
|
148
|
+
appIconMaskable: assetPath("appIconMaskable", PNG_RE, ".png").optional(),
|
|
149
|
+
})
|
|
150
|
+
.superRefine((l, ctx) => {
|
|
151
|
+
if (l.appIconMaskable !== undefined && l.appIcon === undefined) {
|
|
152
|
+
ctx.addIssue({
|
|
153
|
+
code: "custom",
|
|
154
|
+
path: ["appIconMaskable"],
|
|
155
|
+
message: "appIconMaskable requires appIcon",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
.optional(),
|
|
160
|
+
decoration: z.enum(THEME_DECORATIONS).optional(),
|
|
161
|
+
avatars: z
|
|
162
|
+
.array(avatarPreset)
|
|
163
|
+
.max(THEME_LIMITS.avatars)
|
|
164
|
+
.superRefine((list, ctx) => {
|
|
165
|
+
const seen = new Set();
|
|
166
|
+
list.forEach((a, i) => {
|
|
167
|
+
if (BUILTIN_AVATARS.has(a.id)) {
|
|
168
|
+
ctx.addIssue({
|
|
169
|
+
code: "custom",
|
|
170
|
+
path: [i, "id"],
|
|
171
|
+
message: `id must not be a built-in avatar preset id (${a.id})`,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else if (seen.has(a.id)) {
|
|
175
|
+
ctx.addIssue({
|
|
176
|
+
code: "custom",
|
|
177
|
+
path: [i, "id"],
|
|
178
|
+
message: `duplicate avatar id ${a.id}`,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
seen.add(a.id);
|
|
182
|
+
});
|
|
124
183
|
})
|
|
125
184
|
.optional(),
|
|
185
|
+
hideAvatarPresets: z
|
|
186
|
+
.array(z.enum(BUILTIN_AVATAR_PRESET_IDS))
|
|
187
|
+
.superRefine((list, ctx) => {
|
|
188
|
+
list.forEach((id, i) => {
|
|
189
|
+
if (list.indexOf(id) !== i) {
|
|
190
|
+
ctx.addIssue({ code: "custom", path: [i], message: `duplicate hidden preset ${id}` });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
})
|
|
194
|
+
.optional(),
|
|
195
|
+
})
|
|
196
|
+
.superRefine((t, ctx) => {
|
|
197
|
+
const hidden = new Set(t.hideAvatarPresets ?? []);
|
|
198
|
+
if (hidden.size === BUILTIN_AVATAR_PRESET_IDS.length && (t.avatars?.length ?? 0) === 0) {
|
|
199
|
+
ctx.addIssue({
|
|
200
|
+
code: "custom",
|
|
201
|
+
path: ["hideAvatarPresets"],
|
|
202
|
+
message: "hiding every built-in avatar preset requires at least one entry in avatars",
|
|
203
|
+
});
|
|
204
|
+
}
|
|
126
205
|
});
|
|
127
206
|
/**
|
|
128
207
|
* The zod schema of a theme file's shape (strict objects). Token names and values are only
|
|
@@ -210,6 +289,16 @@ export function isThemeFontFamily(v) {
|
|
|
210
289
|
export function isThemeAssetPath(v) {
|
|
211
290
|
return typeof v === "string" && v.length <= 512 && isPlainAssetPath(v);
|
|
212
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Values a theme scheme takes for tokens it leaves out but whose built-in value only suits the
|
|
294
|
+
* built-in palette. `field` (the ground of a form control) is white in the built-in light scheme
|
|
295
|
+
* because the built-in cards are grey: a scheme that recolours `panel` without naming `field`
|
|
296
|
+
* keeps clear fields, so its controls show its own card through, as they did before `field`
|
|
297
|
+
* existed. A theme that wants filled fields names `field` itself.
|
|
298
|
+
*/
|
|
299
|
+
export function themeSchemeFallbacks(overridden) {
|
|
300
|
+
return overridden.has("panel") && !overridden.has("field") ? { field: "rgba(0,0,0,0)" } : {};
|
|
301
|
+
}
|
|
213
302
|
/**
|
|
214
303
|
* Each scheme the theme defines, merged onto the current built-in values (for swatches, the
|
|
215
304
|
* readability check and anything else that needs full values). A stored theme is read leniently:
|
|
@@ -226,6 +315,7 @@ export function mergeThemeSchemes(theme) {
|
|
|
226
315
|
if (over === null || typeof over !== "object")
|
|
227
316
|
continue;
|
|
228
317
|
const m = builtIn(scheme);
|
|
318
|
+
const colors = new Set();
|
|
229
319
|
for (const group of ["color", "shadow"]) {
|
|
230
320
|
const values = over[group];
|
|
231
321
|
if (values === null || typeof values !== "object")
|
|
@@ -234,10 +324,14 @@ export function mergeThemeSchemes(theme) {
|
|
|
234
324
|
if (!OVERRIDABLE[group].has(name))
|
|
235
325
|
continue;
|
|
236
326
|
const v = canonicalThemeValue(group, raw);
|
|
237
|
-
if (v
|
|
238
|
-
|
|
327
|
+
if (v === undefined)
|
|
328
|
+
continue;
|
|
329
|
+
m[group][name] = v;
|
|
330
|
+
if (group === "color")
|
|
331
|
+
colors.add(name);
|
|
239
332
|
}
|
|
240
333
|
}
|
|
334
|
+
Object.assign(m.color, themeSchemeFallbacks(colors));
|
|
241
335
|
const radii = over.radius;
|
|
242
336
|
if (radii !== null && typeof radii === "object") {
|
|
243
337
|
for (const key of ["sm", "md", "bubble"]) {
|