@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.
Files changed (159) hide show
  1. package/README.md +3 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +11 -3
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +5 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extension-points/trigger-source.md +19 -0
  14. package/agent-docs/extensions.md +98 -4
  15. package/agent-docs/plugin-format.md +45 -10
  16. package/agent-docs/setup.md +54 -0
  17. package/api/plugin-sdk.api.md +5983 -0
  18. package/dist/agent-template.d.ts +15 -6
  19. package/dist/agent-template.js +32 -13
  20. package/dist/agents-ctx.d.ts +116 -0
  21. package/dist/agents-ctx.js +22 -0
  22. package/dist/avatar-presets.d.ts +8 -0
  23. package/dist/avatar-presets.js +17 -0
  24. package/dist/bootstrap.d.ts +109 -1
  25. package/dist/bootstrap.js +185 -2
  26. package/dist/cards.d.ts +121 -13
  27. package/dist/cards.js +161 -19
  28. package/dist/channel.d.ts +133 -47
  29. package/dist/channel.js +10 -5
  30. package/dist/client-css.d.ts +36 -0
  31. package/dist/client-css.js +326 -0
  32. package/dist/client-section.d.ts +35 -0
  33. package/dist/client-section.js +133 -0
  34. package/dist/config-ui.d.ts +28 -6
  35. package/dist/config-ui.js +88 -25
  36. package/dist/config-url-fetch.d.ts +19 -0
  37. package/dist/config-url-fetch.js +43 -0
  38. package/dist/connector-auth.d.ts +13 -2
  39. package/dist/connector-auth.js +82 -8
  40. package/dist/connector.d.ts +74 -32
  41. package/dist/context.d.ts +40 -0
  42. package/dist/context.js +2 -0
  43. package/dist/ctx.d.ts +344 -31
  44. package/dist/ctx.js +9 -1
  45. package/dist/define-extension.d.ts +18 -12
  46. package/dist/define-extension.js +18 -5
  47. package/dist/device-denied-paths.d.ts +20 -0
  48. package/dist/device-denied-paths.js +118 -0
  49. package/dist/device-operation.d.ts +348 -0
  50. package/dist/device-operation.js +312 -0
  51. package/dist/device-protocol.d.ts +286 -49
  52. package/dist/device-protocol.js +766 -89
  53. package/dist/device-provider.d.ts +820 -0
  54. package/dist/device-provider.js +432 -0
  55. package/dist/device-service.d.ts +204 -0
  56. package/dist/device-service.js +291 -0
  57. package/dist/dial-in.d.ts +286 -0
  58. package/dist/dial-in.js +213 -0
  59. package/dist/directory.d.ts +15 -12
  60. package/dist/extension-point.d.ts +2 -0
  61. package/dist/extension-point.js +8 -3
  62. package/dist/field-meta.d.ts +19 -0
  63. package/dist/field-meta.js +54 -0
  64. package/dist/file-preview.d.ts +46 -9
  65. package/dist/git-hosts.d.ts +53 -0
  66. package/dist/git-hosts.js +98 -0
  67. package/dist/hooks.d.ts +185 -22
  68. package/dist/hooks.js +6 -0
  69. package/dist/http-access.d.ts +71 -0
  70. package/dist/http-access.js +12 -0
  71. package/dist/identity.d.ts +70 -9
  72. package/dist/identity.js +46 -1
  73. package/dist/inbox.d.ts +103 -0
  74. package/dist/inbox.js +173 -0
  75. package/dist/index.d.ts +30 -4
  76. package/dist/index.js +30 -4
  77. package/dist/model-params.d.ts +41 -22
  78. package/dist/model-params.js +28 -15
  79. package/dist/model.d.ts +295 -77
  80. package/dist/model.js +249 -21
  81. package/dist/native-failure.d.ts +13 -0
  82. package/dist/native-failure.js +31 -0
  83. package/dist/net.d.ts +52 -0
  84. package/dist/net.js +34 -0
  85. package/dist/network-classes.d.ts +98 -0
  86. package/dist/network-classes.js +291 -0
  87. package/dist/permissions.d.ts +95 -25
  88. package/dist/permissions.js +175 -54
  89. package/dist/platform-only.d.ts +27 -0
  90. package/dist/platform-only.js +35 -0
  91. package/dist/plugin-manifest.d.ts +30 -6
  92. package/dist/plugin-manifest.js +147 -55
  93. package/dist/plugin-package.d.ts +82 -39
  94. package/dist/plugin-package.js +68 -41
  95. package/dist/push.d.ts +75 -0
  96. package/dist/push.js +87 -0
  97. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  98. package/dist/sandbox-linux-runtime-source.js +2343 -0
  99. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  100. package/dist/sandbox-native-runtime-source.js +480 -0
  101. package/dist/sandbox-runtime-source.d.ts +47 -0
  102. package/dist/sandbox-runtime-source.js +73 -0
  103. package/dist/sandbox-write-denies.d.ts +139 -0
  104. package/dist/sandbox-write-denies.js +869 -0
  105. package/dist/secret.d.ts +8 -2
  106. package/dist/secret.js +11 -4
  107. package/dist/setup-check.d.ts +128 -0
  108. package/dist/setup-check.js +142 -0
  109. package/dist/setup-guide-parse.d.ts +121 -0
  110. package/dist/setup-guide-parse.js +356 -0
  111. package/dist/setup-guide-render.d.ts +45 -0
  112. package/dist/setup-guide-render.js +351 -0
  113. package/dist/setup-guide.d.ts +86 -72
  114. package/dist/setup-guide.js +340 -108
  115. package/dist/shell-capabilities.d.ts +216 -0
  116. package/dist/shell-capabilities.js +44 -0
  117. package/dist/shell-environment.d.ts +57 -0
  118. package/dist/shell-environment.js +21 -0
  119. package/dist/skill-invocation.d.ts +5 -0
  120. package/dist/skill-invocation.js +4 -3
  121. package/dist/skill.d.ts +27 -17
  122. package/dist/skill.js +40 -26
  123. package/dist/storage.d.ts +52 -25
  124. package/dist/svg-viewbox.d.ts +10 -0
  125. package/dist/svg-viewbox.js +24 -0
  126. package/dist/theme-assets.d.ts +25 -9
  127. package/dist/theme-assets.js +87 -47
  128. package/dist/theme-tokens.generated.d.ts +40 -12
  129. package/dist/theme-tokens.generated.js +36 -8
  130. package/dist/theme.d.ts +56 -10
  131. package/dist/theme.js +117 -23
  132. package/dist/tool.d.ts +242 -28
  133. package/dist/tool.js +135 -13
  134. package/dist/trigger-source.d.ts +35 -0
  135. package/dist/trigger-source.js +2 -0
  136. package/dist/triggers.d.ts +88 -0
  137. package/dist/triggers.js +71 -0
  138. package/dist/ui-parts.d.ts +23 -0
  139. package/dist/ui-parts.js +374 -0
  140. package/dist/ui-resolve.d.ts +2 -7
  141. package/dist/ui-resolve.js +7 -19
  142. package/dist/ui-slots.d.ts +27 -5
  143. package/dist/ui-slots.js +112 -19
  144. package/dist/ui.d.ts +203 -64
  145. package/dist/ui.js +117 -23
  146. package/dist/url.d.ts +4 -1
  147. package/dist/url.js +4 -1
  148. package/dist/web.d.ts +26 -20
  149. package/package.json +13 -1
  150. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  151. package/schemas/bootstrap.v1.schema.json +20 -0
  152. package/schemas/connector-template.v1.schema.json +62 -4
  153. package/schemas/plugin.v1.schema.json +74 -143
  154. package/schemas/theme.v1.schema.json +77 -0
  155. package/agent-docs/extension-points/sandbox.md +0 -15
  156. package/dist/org-access.d.ts +0 -27
  157. package/dist/org-access.js +0 -35
  158. package/dist/sandbox.d.ts +0 -254
  159. package/dist/sandbox.js +0 -153
package/dist/storage.d.ts CHANGED
@@ -7,27 +7,34 @@
7
7
  */
8
8
  /** Object storage extension point ref. */
9
9
  export declare const OBJECT_STORE_EXTENSION_POINT = "object-store@1";
10
- /** 对象的元数据。 */
10
+ /** Metadata of an object. */
11
11
  export interface ObjectHead {
12
12
  key: string;
13
- /** 字节数。 */
13
+ /** Size in bytes. */
14
14
  size: number;
15
15
  contentType: string;
16
16
  etag?: string;
17
- /** ISO 8601 时间。 */
17
+ /** ISO 8601 time. */
18
18
  lastModified?: string;
19
19
  }
20
- /** `object-store@1` 的实现(由对象存储插件提供,如 S3 兼容存储)。 */
20
+ /**
21
+ * The `object-store@1` implementation (provided by an object-store plugin, e.g. S3-compatible
22
+ * storage).
23
+ */
21
24
  export interface ObjectStore {
22
- /** 写入(覆盖同名键);`body` 是流时最好给出 `size`。 */
25
+ /**
26
+ * Writes (overwriting a key of the same name); give `size` when `body` is a stream if possible.
27
+ */
23
28
  put(key: string, body: Uint8Array | ReadableStream<Uint8Array>, opts: {
24
29
  contentType: string;
25
30
  size?: number;
26
31
  signal?: AbortSignal;
27
32
  }): Promise<ObjectHead>;
28
33
  /**
29
- * 读取;不存在返回 null。`range` 为闭区间字节范围,缺省 `end` 表示读到末尾。
30
- * 带 `range` 时 `head.size` 仍是整个对象的大小;存储忽略 Range 时 body 可能是整个对象。
34
+ * Reads; returns null when missing. `range` is a closed byte range; an omitted `end` means read
35
+ * to the end.
36
+ * With `range`, `head.size` is still the size of the whole object; when the store ignores Range,
37
+ * body may be the whole object.
31
38
  */
32
39
  get(key: string, opts?: {
33
40
  signal?: AbortSignal;
@@ -39,15 +46,18 @@ export interface ObjectStore {
39
46
  head: ObjectHead;
40
47
  body: ReadableStream<Uint8Array>;
41
48
  } | null>;
42
- /** 不存在返回 null。 */
49
+ /** Returns null when missing. */
43
50
  head(key: string): Promise<ObjectHead | null>;
44
- /** 删除;不存在也算成功。 */
51
+ /** Deletes; a missing key also counts as success. */
45
52
  delete(key: string): Promise<void>;
46
- /** 删除前缀下的全部对象,返回删除数(用于组织数据删除)。 */
53
+ /**
54
+ * Deletes all objects under a prefix and returns the number deleted (used for org data deletion).
55
+ */
47
56
  deletePrefix(prefix: string): Promise<number>;
48
57
  /**
49
- * 分页列举前缀下的对象;返回的 `cursor` 缺省表示没有下一页。列举结果不带类型时 `contentType` 为空串
50
- * (需要时用 `head` 取)。
58
+ * Lists objects under a prefix with pagination; an omitted `cursor` in the result means there is
59
+ * no next page. When the listing carries no type, `contentType` is an empty string
60
+ * (use `head` to get it when needed).
51
61
  */
52
62
  list(prefix: string, opts?: {
53
63
  cursor?: string;
@@ -56,41 +66,58 @@ export interface ObjectStore {
56
66
  items: ObjectHead[];
57
67
  cursor?: string;
58
68
  }>;
59
- /** 预签名下载 URL(选项见 {@link PresignGetOptions})。 */
69
+ /** Presigned download URL (options in {@link PresignGetOptions}). */
60
70
  presignGet(key: string, opts: PresignGetOptions): Promise<string>;
61
71
  /**
62
- * 预签名上传:浏览器按返回的 {@link PresignedUpload} 直传存储。超过 `maxSize` 的上传必须由**存储端**拒绝
63
- * (预签名 PUT 无法限制大小,所以 S3 兼容实现用带 `content-length-range` 条件的 POST 策略)。
72
+ * Presigned upload: the browser uploads straight to storage following the returned {@link
73
+ * PresignedUpload}. An upload over `maxSize` must be rejected by the **store side**
74
+ * (a presigned PUT cannot limit the size, so S3-compatible implementations use a POST policy with
75
+ * a `content-length-range` condition).
64
76
  */
65
77
  presignPut(key: string, opts: {
66
78
  contentType: string;
67
79
  maxSize: number;
68
80
  ttlSeconds: number;
69
81
  }): Promise<PresignedUpload>;
82
+ /**
83
+ * The canonical URI of a key in this store: unsigned, stable, no credentials
84
+ * (`s3://bucket/key`). This is an identifier, never a presigned URL: it may be recorded in an
85
+ * event log and shown to a model, so it must stay valid and carry no secret. Optional: a store
86
+ * with no notion of URIs leaves it out and the kernel falls back to its own reference.
87
+ */
88
+ uri?(key: string): string;
70
89
  }
71
- /** 预签名下载的选项。 */
90
+ /** Options of a presigned download. */
72
91
  export interface PresignGetOptions {
73
92
  ttlSeconds: number;
74
- /** 下载文件名,进 `Content-Disposition`(RFC 6266,非 ASCII 用 `filename*=UTF-8''…`)。 */
93
+ /**
94
+ * Download file name, goes into `Content-Disposition` (RFC 6266; non-ASCII uses
95
+ * `filename*=UTF-8''…`).
96
+ */
75
97
  downloadName?: string;
76
98
  /**
77
- * 浏览器打开方式:`attachment`(缺省,下载)或 `inline`(在页面里显示)。用户上传的内容只应对
78
- * 不会执行脚本的类型(图片、PDF)用 `inline`。
99
+ * How the browser opens it: `attachment` (default, download) or `inline` (display in the page).
100
+ * User-uploaded content should use `inline` only for types
101
+ * that do not execute scripts (images, PDF).
79
102
  */
80
103
  disposition?: "attachment" | "inline";
81
- /** 覆盖响应的 `Content-Type`(如按核对过的类型返回,而不是存储里记的类型)。 */
104
+ /**
105
+ * Overrides the response `Content-Type` (e.g. return the verified type rather than the type
106
+ * recorded in storage).
107
+ */
82
108
  responseContentType?: string;
83
109
  }
84
110
  /**
85
- * 预签名上传的请求方式:
86
- * - `PUT`:请求体就是文件字节,请求头带上 `headers`;
87
- * - `POST`:`multipart/form-data` 表单,先按原样放入 `fields` 的每一项,**最后**放文件字段 `file`;
88
- * 请求头带上 `headers`(通常为空)。
111
+ * The request method of a presigned upload:
112
+ * - `PUT`: the request body is the file bytes, and the request carries `headers`;
113
+ * - `POST`: a `multipart/form-data` form; first put every item of `fields` in as is, and put the
114
+ * file field `file` **last**;
115
+ * the request carries `headers` (usually empty).
89
116
  */
90
117
  export interface PresignedUpload {
91
118
  method: "PUT" | "POST";
92
119
  url: string;
93
120
  headers: Record<string, string>;
94
- /** `POST` 时必有:表单字段(含策略与签名)。 */
121
+ /** Always present for `POST`: the form fields (including policy and signature). */
95
122
  fields?: Record<string, string>;
96
123
  }
@@ -0,0 +1,10 @@
1
+ /** Characters of a viewBox value; longer values are refused before any regex sees them. */
2
+ export declare const VIEWBOX_MAX_CHARS = 128;
3
+ /**
4
+ * The only regexes the viewBox parser runs. Each is one character class under one quantifier,
5
+ * so matching is linear in the (already capped) input: there is nothing to backtrack into.
6
+ */
7
+ export declare const VIEWBOX_SEPARATOR_RE: RegExp;
8
+ export declare const VIEWBOX_NUMBER_RE: RegExp;
9
+ /** `min-x min-y width height`, width and height > 0; undefined when malformed. */
10
+ export declare function parseViewBox(v: string): [number, number, number, number] | undefined;
@@ -0,0 +1,24 @@
1
+ // Internal to the SDK: not re-exported from index.ts, so not part of the public API.
2
+ /** Characters of a viewBox value; longer values are refused before any regex sees them. */
3
+ export const VIEWBOX_MAX_CHARS = 128;
4
+ /**
5
+ * The only regexes the viewBox parser runs. Each is one character class under one quantifier,
6
+ * so matching is linear in the (already capped) input: there is nothing to backtrack into.
7
+ */
8
+ export const VIEWBOX_SEPARATOR_RE = /[\s,]+/;
9
+ export const VIEWBOX_NUMBER_RE = /^[-+.0-9eE]+$/;
10
+ /** `min-x min-y width height`, width and height > 0; undefined when malformed. */
11
+ export function parseViewBox(v) {
12
+ if (v.length > VIEWBOX_MAX_CHARS)
13
+ return undefined;
14
+ const parts = v
15
+ .trim()
16
+ .split(VIEWBOX_SEPARATOR_RE)
17
+ .filter((p) => p !== "");
18
+ if (parts.length !== 4 || !parts.every((p) => VIEWBOX_NUMBER_RE.test(p)))
19
+ return undefined;
20
+ const n = parts.map(Number);
21
+ if (!n.every(Number.isFinite) || n[2] <= 0 || n[3] <= 0)
22
+ return undefined;
23
+ return n;
24
+ }
@@ -21,17 +21,33 @@ export declare function sanitizeThemeSvg(bytes: Uint8Array): {
21
21
  export declare function checkWoff2(bytes: Uint8Array): string | undefined;
22
22
  /**
23
23
  * A PNG logo: the PNG signature, an `IHDR` first chunk with a height of at least
24
- * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most {@link THEME_LIMITS}`.pngBytes`.
24
+ * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most `maxBytes` (default
25
+ * {@link THEME_LIMITS}`.pngBytes`; an app icon allows {@link THEME_LIMITS}`.appIconBytes`).
25
26
  */
26
- export declare function checkPng(bytes: Uint8Array): string | undefined;
27
+ export declare function checkPng(bytes: Uint8Array, maxBytes?: number): string | undefined;
27
28
  /**
28
- * Resolves and checks the asset files of a parsed theme: each `fonts[].file` ({@link checkWoff2})
29
- * and `logo.mark` / `logo.favicon` (`.svg` through {@link sanitizeThemeSvg}, `.png` through
30
- * {@link checkPng}); the favicon must be square (SVG viewBox or PNG width = height). `files` holds the plugin's files keyed by their path without a leading
31
- * `./`; the returned `assets` (the sanitized SVG bytes, the other files unchanged) use the same
32
- * keys. Errors are `<field>: <reason>`, English; the total input size of the theme's distinct
33
- * assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is per plugin, so a
34
- * caller reading several themes also checks the sum over all of them (distinct paths).
29
+ * Every asset a parsed theme names, in order: `fonts.<i>.file`, `logo.mark`, `logo.favicon`,
30
+ * `logo.illustration`, `logo.appIcon`, `logo.appIconMaskable`, `avatars.<i>.file`. `ref` is the
31
+ * path as written (an optional leading `./`). The one list every reader of theme assets uses (the
32
+ * checks, packing, the catalog and delivery), so a file the theme does not name is never read or
33
+ * served.
34
+ */
35
+ export declare function themeAssetRefs(theme: ParsedTheme): {
36
+ field: string;
37
+ ref: string;
38
+ }[];
39
+ /**
40
+ * Resolves and checks the asset files of a parsed theme ({@link themeAssetRefs}), each by its
41
+ * kind: `fonts[].file` ({@link checkWoff2}); `logo.mark` and `logo.illustration` (`.svg` through
42
+ * {@link sanitizeThemeSvg}, `.png` through {@link checkPng}); `logo.favicon` and `avatars[].file`
43
+ * likewise and square (SVG viewBox or PNG width = height); `logo.appIcon` and
44
+ * `logo.appIconMaskable` PNG only, square, at least {@link THEME_LIMITS}`.appIconMinSize` px and at
45
+ * most {@link THEME_LIMITS}`.appIconBytes`. `files` holds the plugin's files keyed by their path
46
+ * without a leading `./`; the returned `assets` (the sanitized SVG bytes, the other files
47
+ * unchanged) use the same keys. Errors are `<field>: <reason>`, English; the total input size of
48
+ * the theme's distinct assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is
49
+ * per plugin, so a caller reading several themes also checks the sum over all of them (distinct
50
+ * paths).
35
51
  */
36
52
  export declare function validateThemeAssets(theme: ParsedTheme, files: Map<string, Uint8Array>): {
37
53
  assets: Map<string, Uint8Array>;
@@ -1,11 +1,13 @@
1
1
  import { SaxesParser } from "saxes";
2
2
  import { isSafePackagePath } from "./plugin-package.js";
3
+ import { parseViewBox } from "./svg-viewbox.js";
3
4
  import { THEME_LIMITS } from "./theme.js";
4
5
  /**
5
- * Checks of a theme's asset files (themes spec §4.2-§4.4): woff2 fonts, PNG logos and the SVG
6
- * sanitizer. The sanitized SVG is served to every browser, so {@link sanitizeThemeSvg} is a trust
7
- * boundary: the output is re-serialized from the parsed tree (never the input bytes), elements are
8
- * allowlisted, every attribute value and text node is escaped on output.
6
+ * Checks of a theme's asset files (themes spec §4.2-§4.4, theme brand coverage spec §1): woff2
7
+ * fonts, PNG logos, app icons and avatars, and the SVG sanitizer. The sanitized SVG is served to
8
+ * every browser, so {@link sanitizeThemeSvg} is a trust boundary: the output is re-serialized from
9
+ * the parsed tree (never the input bytes), elements are allowlisted, every attribute value and text
10
+ * node is escaped on output.
9
11
  */
10
12
  const SVG_NS = "http://www.w3.org/2000/svg";
11
13
  const XLINK_NS = "http://www.w3.org/1999/xlink";
@@ -79,10 +81,6 @@ const SVG_ELEMENTS = new Set([
79
81
  const XML_ATTRS = new Set(["space", "lang"]);
80
82
  /** Root attributes dropped: the design system sizes the logo to its slot. */
81
83
  const ROOT_DROPPED = new Set(["width", "height", "class"]);
82
- /** Characters of a viewBox value; longer values are refused before they are split. */
83
- const VIEWBOX_MAX_CHARS = 128;
84
- /** Characters a viewBox number may use (checked per character class, no backtracking). */
85
- const VIEWBOX_NUMBER_RE = /^[-+.0-9eE]+$/;
86
84
  /**
87
85
  * The only functions an attribute value may call: colors and transforms. `url` is allowed only as
88
86
  * `url(#id)` (checked separately); everything else (`image-set`, `cross-fade`, `element`,
@@ -150,21 +148,6 @@ function checkValue(el, attr, value) {
150
148
  }
151
149
  }
152
150
  }
153
- /** `min-x min-y width height`, width and height > 0; undefined when malformed. */
154
- function parseViewBox(v) {
155
- if (v.length > VIEWBOX_MAX_CHARS)
156
- return undefined;
157
- const parts = v
158
- .trim()
159
- .split(/[\s,]+/)
160
- .filter((p) => p !== "");
161
- if (parts.length !== 4 || !parts.every((p) => VIEWBOX_NUMBER_RE.test(p)))
162
- return undefined;
163
- const n = parts.map(Number);
164
- if (!n.every(Number.isFinite) || n[2] <= 0 || n[3] <= 0)
165
- return undefined;
166
- return n;
167
- }
168
151
  /** The serialized attributes of an allowed SVG element; rejects the forbidden ones. */
169
152
  function attributesOf(tag, isRoot, usesXlink) {
170
153
  const el = tag.local;
@@ -356,16 +339,17 @@ export function checkWoff2(bytes) {
356
339
  }
357
340
  /**
358
341
  * A PNG logo: the PNG signature, an `IHDR` first chunk with a height of at least
359
- * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most {@link THEME_LIMITS}`.pngBytes`.
342
+ * {@link THEME_LIMITS}`.pngMinHeight` pixels, and at most `maxBytes` (default
343
+ * {@link THEME_LIMITS}`.pngBytes`; an app icon allows {@link THEME_LIMITS}`.appIconBytes`).
360
344
  */
361
- export function checkPng(bytes) {
362
- const r = readPng(bytes);
345
+ export function checkPng(bytes, maxBytes = THEME_LIMITS.pngBytes) {
346
+ const r = readPng(bytes, maxBytes);
363
347
  return typeof r === "string" ? r : undefined;
364
348
  }
365
349
  /** {@link checkPng}, returning the IHDR size when the PNG passes. */
366
- function readPng(bytes) {
367
- if (bytes.length > THEME_LIMITS.pngBytes) {
368
- return `PNG is larger than ${THEME_LIMITS.pngBytes} bytes`;
350
+ function readPng(bytes, maxBytes) {
351
+ if (bytes.length > maxBytes) {
352
+ return `PNG is larger than ${maxBytes} bytes`;
369
353
  }
370
354
  if (!startsWith(bytes, PNG_SIG))
371
355
  return "image is not a PNG file (no PNG signature)";
@@ -383,13 +367,51 @@ function readPng(bytes) {
383
367
  return { width, height };
384
368
  }
385
369
  /**
386
- * Resolves and checks the asset files of a parsed theme: each `fonts[].file` ({@link checkWoff2})
387
- * and `logo.mark` / `logo.favicon` (`.svg` through {@link sanitizeThemeSvg}, `.png` through
388
- * {@link checkPng}); the favicon must be square (SVG viewBox or PNG width = height). `files` holds the plugin's files keyed by their path without a leading
389
- * `./`; the returned `assets` (the sanitized SVG bytes, the other files unchanged) use the same
390
- * keys. Errors are `<field>: <reason>`, English; the total input size of the theme's distinct
391
- * assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is per plugin, so a
392
- * caller reading several themes also checks the sum over all of them (distinct paths).
370
+ * Every asset a parsed theme names, in order: `fonts.<i>.file`, `logo.mark`, `logo.favicon`,
371
+ * `logo.illustration`, `logo.appIcon`, `logo.appIconMaskable`, `avatars.<i>.file`. `ref` is the
372
+ * path as written (an optional leading `./`). The one list every reader of theme assets uses (the
373
+ * checks, packing, the catalog and delivery), so a file the theme does not name is never read or
374
+ * served.
375
+ */
376
+ export function themeAssetRefs(theme) {
377
+ return refsWithKind(theme).map(({ field, ref }) => ({ field, ref }));
378
+ }
379
+ /** The kind each logo field is checked as, in {@link themeAssetRefs} order. */
380
+ const LOGO_ASSETS = [
381
+ ["mark", "image"],
382
+ ["favicon", "favicon"],
383
+ ["illustration", "image"],
384
+ ["appIcon", "appIcon"],
385
+ ["appIconMaskable", "appIcon"],
386
+ ];
387
+ /** {@link themeAssetRefs} with the kind each file is checked as. */
388
+ function refsWithKind(theme) {
389
+ const refs = [];
390
+ theme.fonts?.forEach((f, i) => {
391
+ refs.push({ field: `fonts.${i}.file`, ref: f.file, kind: "font" });
392
+ });
393
+ for (const [key, kind] of LOGO_ASSETS) {
394
+ const ref = theme.logo?.[key];
395
+ if (ref !== undefined)
396
+ refs.push({ field: `logo.${key}`, ref, kind });
397
+ }
398
+ theme.avatars?.forEach((a, i) => {
399
+ refs.push({ field: `avatars.${i}.file`, ref: a.file, kind: "avatar" });
400
+ });
401
+ return refs;
402
+ }
403
+ /**
404
+ * Resolves and checks the asset files of a parsed theme ({@link themeAssetRefs}), each by its
405
+ * kind: `fonts[].file` ({@link checkWoff2}); `logo.mark` and `logo.illustration` (`.svg` through
406
+ * {@link sanitizeThemeSvg}, `.png` through {@link checkPng}); `logo.favicon` and `avatars[].file`
407
+ * likewise and square (SVG viewBox or PNG width = height); `logo.appIcon` and
408
+ * `logo.appIconMaskable` PNG only, square, at least {@link THEME_LIMITS}`.appIconMinSize` px and at
409
+ * most {@link THEME_LIMITS}`.appIconBytes`. `files` holds the plugin's files keyed by their path
410
+ * without a leading `./`; the returned `assets` (the sanitized SVG bytes, the other files
411
+ * unchanged) use the same keys. Errors are `<field>: <reason>`, English; the total input size of
412
+ * the theme's distinct assets must stay within {@link THEME_LIMITS}`.assetsBytes`. That limit is
413
+ * per plugin, so a caller reading several themes also checks the sum over all of them (distinct
414
+ * paths).
393
415
  */
394
416
  export function validateThemeAssets(theme, files) {
395
417
  const assets = new Map();
@@ -415,13 +437,16 @@ export function validateThemeAssets(theme, files) {
415
437
  assets.set(path, r);
416
438
  };
417
439
  const font = (b) => checkWoff2(b) ?? b;
440
+ const notSquare = (what, w, h) => `${what} must be square, not ${w} x ${h}`;
441
+ /** A logo image (`mark` rules); `square` names what must be square, or is undefined. */
418
442
  const image = (ref, square) => (b) => {
419
- const notSquare = (w, h) => `favicon must be square, not ${w} x ${h}`;
420
443
  if (/\.png$/i.test(ref)) {
421
- const r = readPng(b);
444
+ const r = readPng(b, THEME_LIMITS.pngBytes);
422
445
  if (typeof r === "string")
423
446
  return r;
424
- return square && r.width !== r.height ? notSquare(r.width, r.height) : b;
447
+ return square !== undefined && r.width !== r.height
448
+ ? notSquare(square, r.width, r.height)
449
+ : b;
425
450
  }
426
451
  if (!/\.svg$/i.test(ref))
427
452
  return "must be a .svg or .png file";
@@ -429,15 +454,30 @@ export function validateThemeAssets(theme, files) {
429
454
  if ("error" in r)
430
455
  return r.error;
431
456
  const [, , w, h] = r.viewBox;
432
- return square && w !== h ? notSquare(w, h) : new TextEncoder().encode(r.svg);
457
+ return square !== undefined && w !== h
458
+ ? notSquare(square, w, h)
459
+ : new TextEncoder().encode(r.svg);
433
460
  };
434
- theme.fonts?.forEach((f, i) => {
435
- resolve(`fonts.${i}.file`, f.file, font);
436
- });
437
- for (const key of ["mark", "favicon"]) {
438
- const ref = theme.logo?.[key];
439
- if (ref !== undefined)
440
- resolve(`logo.${key}`, ref, image(ref, key === "favicon"));
461
+ const appIcon = (ref) => (b) => {
462
+ if (!/\.png$/i.test(ref))
463
+ return "must be a .png file";
464
+ const r = readPng(b, THEME_LIMITS.appIconBytes);
465
+ if (typeof r === "string")
466
+ return r;
467
+ if (r.width !== r.height)
468
+ return notSquare("app icon", r.width, r.height);
469
+ if (r.width < THEME_LIMITS.appIconMinSize) {
470
+ return `app icon must be at least ${THEME_LIMITS.appIconMinSize} px, not ${r.width}`;
471
+ }
472
+ return b;
473
+ };
474
+ for (const { field, ref, kind } of refsWithKind(theme)) {
475
+ const check = kind === "font"
476
+ ? font
477
+ : kind === "appIcon"
478
+ ? appIcon(ref)
479
+ : image(ref, kind === "favicon" ? "favicon" : kind === "avatar" ? "avatar" : undefined);
480
+ resolve(field, ref, check);
441
481
  }
442
482
  let total = 0;
443
483
  for (const n of sizes.values())
@@ -3,35 +3,39 @@ export declare const THEME_TOKENS: {
3
3
  readonly color: {
4
4
  readonly bg: {
5
5
  readonly dark: "#0A0A0A";
6
- readonly light: "#FAF9F6";
6
+ readonly light: "#FDFDFC";
7
7
  };
8
8
  readonly panel: {
9
9
  readonly dark: "#111110";
10
- readonly light: "#FFFFFF";
10
+ readonly light: "#F9F8F5";
11
11
  };
12
12
  readonly "panel-2": {
13
13
  readonly dark: "#0E0E0D";
14
- readonly light: "#FCFBF9";
14
+ readonly light: "#FBFAF8";
15
15
  };
16
16
  readonly sidebar: {
17
- readonly dark: "#111110";
18
- readonly light: "#F3F2EE";
17
+ readonly dark: "#171716";
18
+ readonly light: "#EDECE7";
19
19
  };
20
20
  readonly "sidebar-active": {
21
- readonly dark: "#1A1A18";
21
+ readonly dark: "rgba(255,255,255,0.07)";
22
22
  readonly light: "rgba(26,26,24,0.09)";
23
23
  };
24
24
  readonly raised: {
25
25
  readonly dark: "#141413";
26
26
  readonly light: "#FFFFFF";
27
27
  };
28
+ readonly field: {
29
+ readonly dark: "rgba(0,0,0,0)";
30
+ readonly light: "#FFFFFF";
31
+ };
28
32
  readonly selected: {
29
- readonly dark: "#1F1F1D";
33
+ readonly dark: "#21211F";
30
34
  readonly light: "rgba(26,26,24,0.07)";
31
35
  };
32
36
  readonly hover: {
33
- readonly dark: "#171716";
34
- readonly light: "rgba(26,26,24,0.04)";
37
+ readonly dark: "rgba(255,255,255,0.04)";
38
+ readonly light: "rgba(26,26,24,0.045)";
35
39
  };
36
40
  readonly "line-soft": {
37
41
  readonly dark: "#1C1C1A";
@@ -99,7 +103,7 @@ export declare const THEME_TOKENS: {
99
103
  };
100
104
  readonly fail: {
101
105
  readonly dark: "#FF5C52";
102
- readonly light: "#C8302A";
106
+ readonly light: "#C42E28";
103
107
  };
104
108
  readonly warn: {
105
109
  readonly dark: "#F2C14B";
@@ -109,6 +113,26 @@ export declare const THEME_TOKENS: {
109
113
  readonly dark: "rgba(0,0,0,.60)";
110
114
  readonly light: "rgba(10,10,10,.25)";
111
115
  };
116
+ readonly "preview-light": {
117
+ readonly dark: "#FAF9F6";
118
+ readonly light: "#FAF9F6";
119
+ };
120
+ readonly "preview-dark": {
121
+ readonly dark: "#0A0A0A";
122
+ readonly light: "#0A0A0A";
123
+ };
124
+ readonly lightbox: {
125
+ readonly dark: "rgba(0,0,0,.88)";
126
+ readonly light: "rgba(10,10,10,.80)";
127
+ };
128
+ readonly "float-ground": {
129
+ readonly dark: "rgba(28,28,26,0.85)";
130
+ readonly light: "rgba(255,255,255,0.85)";
131
+ };
132
+ readonly "float-line": {
133
+ readonly dark: "rgba(255,255,255,0.08)";
134
+ readonly light: "rgba(26,26,24,0.08)";
135
+ };
112
136
  readonly "diff-add": {
113
137
  readonly dark: "rgba(63,212,131,.08)";
114
138
  readonly light: "rgba(22,128,63,.10)";
@@ -251,6 +275,10 @@ export declare const THEME_TOKENS: {
251
275
  readonly dark: "0 8px 24px rgba(0,0,0,.45)";
252
276
  readonly light: "0 8px 24px rgba(26,26,24,.08)";
253
277
  };
278
+ readonly "shadow-float-touch": {
279
+ readonly dark: "0 6px 20px rgba(0,0,0,.35)";
280
+ readonly light: "0 6px 20px rgba(26,26,24,.10)";
281
+ };
254
282
  };
255
283
  readonly radius: {
256
284
  readonly sm: 4;
@@ -265,8 +293,8 @@ export declare const THEME_FONTS: {
265
293
  };
266
294
  /** The tokens a theme may override: no avatar colors, no color-mix values (they derive). */
267
295
  export declare const THEME_OVERRIDABLE: {
268
- readonly color: readonly ["bg", "panel", "panel-2", "sidebar", "sidebar-active", "raised", "selected", "hover", "line-soft", "line", "line-strong", "line-card", "scroll-thumb", "ink", "muted", "faint", "disabled", "accent", "accent-hover", "accent-press", "on-accent", "focus-ring", "ok", "fail", "warn", "scrim", "diff-add", "diff-del"];
269
- readonly shadow: readonly ["shadow-1", "shadow-2", "shadow-sheet", "shadow-float"];
296
+ readonly color: readonly ["bg", "panel", "panel-2", "sidebar", "sidebar-active", "raised", "field", "selected", "hover", "line-soft", "line", "line-strong", "line-card", "scroll-thumb", "ink", "muted", "faint", "disabled", "accent", "accent-hover", "accent-press", "on-accent", "focus-ring", "ok", "fail", "warn", "scrim", "lightbox", "float-ground", "float-line", "diff-add", "diff-del"];
297
+ readonly shadow: readonly ["shadow-1", "shadow-2", "shadow-sheet", "shadow-float", "shadow-float-touch"];
270
298
  readonly radius: readonly ["sm", "md", "bubble"];
271
299
  };
272
300
  /** [foreground, background, floor] or, with a fourth element, the surface it sits on. */
@@ -3,14 +3,15 @@
3
3
  /** The built-in token values a theme overrides (design spec §2). */
4
4
  export const THEME_TOKENS = {
5
5
  color: {
6
- "bg": { dark: "#0A0A0A", light: "#FAF9F6" },
7
- "panel": { dark: "#111110", light: "#FFFFFF" },
8
- "panel-2": { dark: "#0E0E0D", light: "#FCFBF9" },
9
- "sidebar": { dark: "#111110", light: "#F3F2EE" },
10
- "sidebar-active": { dark: "#1A1A18", light: "rgba(26,26,24,0.09)" },
6
+ "bg": { dark: "#0A0A0A", light: "#FDFDFC" },
7
+ "panel": { dark: "#111110", light: "#F9F8F5" },
8
+ "panel-2": { dark: "#0E0E0D", light: "#FBFAF8" },
9
+ "sidebar": { dark: "#171716", light: "#EDECE7" },
10
+ "sidebar-active": { dark: "rgba(255,255,255,0.07)", light: "rgba(26,26,24,0.09)" },
11
11
  "raised": { dark: "#141413", light: "#FFFFFF" },
12
- "selected": { dark: "#1F1F1D", light: "rgba(26,26,24,0.07)" },
13
- "hover": { dark: "#171716", light: "rgba(26,26,24,0.04)" },
12
+ "field": { dark: "rgba(0,0,0,0)", light: "#FFFFFF" },
13
+ "selected": { dark: "#21211F", light: "rgba(26,26,24,0.07)" },
14
+ "hover": { dark: "rgba(255,255,255,0.04)", light: "rgba(26,26,24,0.045)" },
14
15
  "line-soft": { dark: "#1C1C1A", light: "#E8E7E2" },
15
16
  "line": { dark: "#2A2A28", light: "#D9D8D2" },
16
17
  "line-strong": { dark: "#3A3A37", light: "#B5B5AE" },
@@ -27,9 +28,14 @@ export const THEME_TOKENS = {
27
28
  "accent-tint": { dark: "color-mix(in srgb, var(--cb-accent) 12%, transparent)", light: "color-mix(in srgb, var(--cb-accent) 12%, transparent)" },
28
29
  "focus-ring": { dark: "rgba(255,106,19,.25)", light: "rgba(204,70,9,.18)" },
29
30
  "ok": { dark: "#3FD483", light: "#16803F" },
30
- "fail": { dark: "#FF5C52", light: "#C8302A" },
31
+ "fail": { dark: "#FF5C52", light: "#C42E28" },
31
32
  "warn": { dark: "#F2C14B", light: "#8F6500" },
32
33
  "scrim": { dark: "rgba(0,0,0,.60)", light: "rgba(10,10,10,.25)" },
34
+ "preview-light": { dark: "#FAF9F6", light: "#FAF9F6" },
35
+ "preview-dark": { dark: "#0A0A0A", light: "#0A0A0A" },
36
+ "lightbox": { dark: "rgba(0,0,0,.88)", light: "rgba(10,10,10,.80)" },
37
+ "float-ground": { dark: "rgba(28,28,26,0.85)", light: "rgba(255,255,255,0.85)" },
38
+ "float-line": { dark: "rgba(255,255,255,0.08)", light: "rgba(26,26,24,0.08)" },
33
39
  "diff-add": { dark: "rgba(63,212,131,.08)", light: "rgba(22,128,63,.10)" },
34
40
  "diff-del": { dark: "rgba(255,92,82,.08)", light: "rgba(207,34,46,.08)" },
35
41
  "avatar-black": { dark: "#1C1C1A", light: "#1C1C1A" },
@@ -67,6 +73,7 @@ export const THEME_TOKENS = {
67
73
  "shadow-2": { dark: "0 16px 48px rgba(0,0,0,.50)", light: "0 8px 24px rgba(10,10,10,.12)" },
68
74
  "shadow-sheet": { dark: "-16px 0 40px rgba(0,0,0,.40)", light: "-4px 0 16px rgba(10,10,10,.08)" },
69
75
  "shadow-float": { dark: "0 8px 24px rgba(0,0,0,.45)", light: "0 8px 24px rgba(26,26,24,.08)" },
76
+ "shadow-float-touch": { dark: "0 6px 20px rgba(0,0,0,.35)", light: "0 6px 20px rgba(26,26,24,.10)" },
70
77
  },
71
78
  radius: { sm: 4, md: 8, bubble: 10 },
72
79
  };
@@ -84,6 +91,7 @@ export const THEME_OVERRIDABLE = {
84
91
  "sidebar",
85
92
  "sidebar-active",
86
93
  "raised",
94
+ "field",
87
95
  "selected",
88
96
  "hover",
89
97
  "line-soft",
@@ -104,6 +112,9 @@ export const THEME_OVERRIDABLE = {
104
112
  "fail",
105
113
  "warn",
106
114
  "scrim",
115
+ "lightbox",
116
+ "float-ground",
117
+ "float-line",
107
118
  "diff-add",
108
119
  "diff-del",
109
120
  ],
@@ -112,6 +123,7 @@ export const THEME_OVERRIDABLE = {
112
123
  "shadow-2",
113
124
  "shadow-sheet",
114
125
  "shadow-float",
126
+ "shadow-float-touch",
115
127
  ],
116
128
  radius: ["sm", "md", "bubble"],
117
129
  };
@@ -123,8 +135,22 @@ export const THEME_CONTRAST = [
123
135
  ["muted", "sidebar", 4.5],
124
136
  ["muted", "panel-2", 4.5],
125
137
  ["muted", "raised", 4.5],
138
+ ["ink", "float-ground", 4.5, "bg"],
139
+ ["muted", "float-ground", 4.5, "bg"],
126
140
  ["muted", "selected", 4.5],
127
141
  ["muted", "hover", 4.5],
142
+ ["ink", "hover", 4.5, "panel"],
143
+ ["ink", "selected", 4.5, "panel"],
144
+ ["muted", "hover", 4.5, "panel"],
145
+ ["ink", "field", 4.5, "panel"],
146
+ ["muted", "field", 4.5, "panel"],
147
+ ["disabled", "field", 3, "panel"],
148
+ ["ink", "hover", 4.5, "raised"],
149
+ ["ink", "selected", 4.5, "raised"],
150
+ ["fail", "raised", 4.5],
151
+ ["disabled", "raised", 3],
152
+ ["fail", "selected", 4.5, "panel"],
153
+ ["accent", "selected", 3, "panel"],
128
154
  ["disabled", "bg", 3],
129
155
  ["disabled", "panel", 3],
130
156
  ["disabled", "hover", 3],
@@ -164,4 +190,6 @@ export const THEME_SEPARATION = [
164
190
  ["selected", "panel", 2.5],
165
191
  ["selected", "sidebar", 2.5],
166
192
  ["sidebar-active", "sidebar", 2.5],
193
+ ["hover", "raised", 2.5],
194
+ ["selected", "raised", 2.5],
167
195
  ];