@caelo-cms/shared 0.10.21 → 0.10.23

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 (241) hide show
  1. package/dist/ai-tools.d.ts +291 -231
  2. package/dist/ai-tools.d.ts.map +1 -1
  3. package/dist/ai-tools.js +349 -281
  4. package/dist/ai-tools.js.map +1 -1
  5. package/dist/auth-forms.d.ts.map +1 -1
  6. package/dist/auth-forms.js +4 -1
  7. package/dist/auth-forms.js.map +1 -1
  8. package/dist/base-css.d.ts +24 -0
  9. package/dist/base-css.d.ts.map +1 -0
  10. package/dist/base-css.js +28 -0
  11. package/dist/base-css.js.map +1 -0
  12. package/dist/build-page.d.ts +330 -0
  13. package/dist/build-page.d.ts.map +1 -0
  14. package/dist/build-page.js +282 -0
  15. package/dist/build-page.js.map +1 -0
  16. package/dist/content.d.ts +322 -9
  17. package/dist/content.d.ts.map +1 -1
  18. package/dist/content.js +354 -11
  19. package/dist/content.js.map +1 -1
  20. package/dist/css-gradient-scan.d.ts +14 -0
  21. package/dist/css-gradient-scan.d.ts.map +1 -0
  22. package/dist/css-gradient-scan.js +81 -0
  23. package/dist/css-gradient-scan.js.map +1 -0
  24. package/dist/css-var-scan.d.ts +56 -0
  25. package/dist/css-var-scan.d.ts.map +1 -0
  26. package/dist/css-var-scan.js +97 -0
  27. package/dist/css-var-scan.js.map +1 -0
  28. package/dist/design-manifest.d.ts +36 -0
  29. package/dist/design-manifest.d.ts.map +1 -0
  30. package/dist/design-manifest.js +90 -0
  31. package/dist/design-manifest.js.map +1 -0
  32. package/dist/fonts.d.ts +89 -0
  33. package/dist/fonts.d.ts.map +1 -0
  34. package/dist/fonts.js +241 -0
  35. package/dist/fonts.js.map +1 -0
  36. package/dist/genesis-inventory.d.ts +32 -0
  37. package/dist/genesis-inventory.d.ts.map +1 -0
  38. package/dist/genesis-inventory.js +186 -0
  39. package/dist/genesis-inventory.js.map +1 -0
  40. package/dist/genesis.d.ts +62 -0
  41. package/dist/genesis.d.ts.map +1 -0
  42. package/dist/genesis.js +78 -0
  43. package/dist/genesis.js.map +1 -0
  44. package/dist/i18n.d.ts +44 -1
  45. package/dist/i18n.d.ts.map +1 -1
  46. package/dist/i18n.js +72 -6
  47. package/dist/i18n.js.map +1 -1
  48. package/dist/index.d.ts +27 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +27 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/interactions.d.ts +23 -0
  53. package/dist/interactions.d.ts.map +1 -0
  54. package/dist/interactions.js +44 -0
  55. package/dist/interactions.js.map +1 -0
  56. package/dist/media.d.ts +101 -16
  57. package/dist/media.d.ts.map +1 -1
  58. package/dist/media.js +126 -15
  59. package/dist/media.js.map +1 -1
  60. package/dist/page-log.d.ts +94 -0
  61. package/dist/page-log.d.ts.map +1 -0
  62. package/dist/page-log.js +111 -0
  63. package/dist/page-log.js.map +1 -0
  64. package/dist/preview-compose.d.ts +79 -0
  65. package/dist/preview-compose.d.ts.map +1 -1
  66. package/dist/preview-compose.js +155 -25
  67. package/dist/preview-compose.js.map +1 -1
  68. package/dist/proposal-status.d.ts +40 -0
  69. package/dist/proposal-status.d.ts.map +1 -0
  70. package/dist/proposal-status.js +34 -0
  71. package/dist/proposal-status.js.map +1 -0
  72. package/dist/responsive-images.d.ts +64 -0
  73. package/dist/responsive-images.d.ts.map +1 -0
  74. package/dist/responsive-images.js +98 -0
  75. package/dist/responsive-images.js.map +1 -0
  76. package/dist/safe-keys.d.ts +9 -0
  77. package/dist/safe-keys.d.ts.map +1 -0
  78. package/dist/safe-keys.js +20 -0
  79. package/dist/safe-keys.js.map +1 -0
  80. package/dist/seo.d.ts +8 -0
  81. package/dist/seo.d.ts.map +1 -1
  82. package/dist/seo.js +3 -1
  83. package/dist/seo.js.map +1 -1
  84. package/dist/skills.d.ts +14 -68
  85. package/dist/skills.d.ts.map +1 -1
  86. package/dist/skills.js +19 -113
  87. package/dist/skills.js.map +1 -1
  88. package/dist/strip-cdata.d.ts +7 -0
  89. package/dist/strip-cdata.d.ts.map +1 -0
  90. package/dist/strip-cdata.js +48 -0
  91. package/dist/strip-cdata.js.map +1 -0
  92. package/dist/structured-sets.d.ts +6 -16
  93. package/dist/structured-sets.d.ts.map +1 -1
  94. package/dist/structured-sets.js +5 -16
  95. package/dist/structured-sets.js.map +1 -1
  96. package/dist/subagents.d.ts +105 -3
  97. package/dist/subagents.d.ts.map +1 -1
  98. package/dist/subagents.js +224 -41
  99. package/dist/subagents.js.map +1 -1
  100. package/dist/template-engine.d.ts +85 -0
  101. package/dist/template-engine.d.ts.map +1 -0
  102. package/dist/template-engine.js +403 -0
  103. package/dist/template-engine.js.map +1 -0
  104. package/dist/theme-importers/auto-detect.d.ts +26 -0
  105. package/dist/theme-importers/auto-detect.d.ts.map +1 -0
  106. package/dist/theme-importers/auto-detect.js +42 -0
  107. package/dist/theme-importers/auto-detect.js.map +1 -0
  108. package/dist/theme-importers/css-comments.d.ts +12 -0
  109. package/dist/theme-importers/css-comments.d.ts.map +1 -0
  110. package/dist/theme-importers/css-comments.js +15 -0
  111. package/dist/theme-importers/css-comments.js.map +1 -0
  112. package/dist/theme-importers/dtcg.d.ts +46 -0
  113. package/dist/theme-importers/dtcg.d.ts.map +1 -0
  114. package/dist/theme-importers/dtcg.js +111 -0
  115. package/dist/theme-importers/dtcg.js.map +1 -0
  116. package/dist/theme-importers/loose.d.ts +3 -0
  117. package/dist/theme-importers/loose.d.ts.map +1 -0
  118. package/dist/theme-importers/loose.js +76 -0
  119. package/dist/theme-importers/loose.js.map +1 -0
  120. package/dist/theme-importers/shadcn.d.ts +24 -0
  121. package/dist/theme-importers/shadcn.d.ts.map +1 -0
  122. package/dist/theme-importers/shadcn.js +135 -0
  123. package/dist/theme-importers/shadcn.js.map +1 -0
  124. package/dist/theme-importers/style-dictionary.d.ts +17 -0
  125. package/dist/theme-importers/style-dictionary.d.ts.map +1 -0
  126. package/dist/theme-importers/style-dictionary.js +125 -0
  127. package/dist/theme-importers/style-dictionary.js.map +1 -0
  128. package/dist/theme-importers/tailwind.d.ts +3 -0
  129. package/dist/theme-importers/tailwind.d.ts.map +1 -0
  130. package/dist/theme-importers/tailwind.js +218 -0
  131. package/dist/theme-importers/tailwind.js.map +1 -0
  132. package/dist/theme-literal-binding.d.ts +37 -0
  133. package/dist/theme-literal-binding.d.ts.map +1 -0
  134. package/dist/theme-literal-binding.js +138 -0
  135. package/dist/theme-literal-binding.js.map +1 -0
  136. package/dist/theme-normalize.d.ts +31 -0
  137. package/dist/theme-normalize.d.ts.map +1 -0
  138. package/dist/theme-normalize.js +587 -0
  139. package/dist/theme-normalize.js.map +1 -0
  140. package/dist/theme-ramp.d.ts +55 -0
  141. package/dist/theme-ramp.d.ts.map +1 -0
  142. package/dist/theme-ramp.js +149 -0
  143. package/dist/theme-ramp.js.map +1 -0
  144. package/dist/theme-render.d.ts +105 -0
  145. package/dist/theme-render.d.ts.map +1 -0
  146. package/dist/theme-render.js +441 -0
  147. package/dist/theme-render.js.map +1 -0
  148. package/dist/themes-errors.d.ts +109 -0
  149. package/dist/themes-errors.d.ts.map +1 -0
  150. package/dist/themes-errors.js +170 -0
  151. package/dist/themes-errors.js.map +1 -0
  152. package/dist/themes.d.ts +343 -0
  153. package/dist/themes.d.ts.map +1 -0
  154. package/dist/themes.js +697 -0
  155. package/dist/themes.js.map +1 -0
  156. package/dist/version.d.ts +7 -4
  157. package/dist/version.d.ts.map +1 -1
  158. package/dist/version.js +6 -3
  159. package/dist/version.js.map +1 -1
  160. package/package.json +10 -2
  161. package/src/__tests__/redos-hardening.test.ts +160 -0
  162. package/src/ai-tools-add-module-modes.test.ts +106 -0
  163. package/src/ai-tools-position.test.ts +134 -0
  164. package/src/ai-tools.test.ts +81 -0
  165. package/src/ai-tools.ts +1179 -0
  166. package/src/auth-forms.ts +36 -0
  167. package/src/base-css.ts +30 -0
  168. package/src/build-page.test.ts +228 -0
  169. package/src/build-page.ts +319 -0
  170. package/src/cap-failures.ts +67 -0
  171. package/src/content.test.ts +170 -0
  172. package/src/content.ts +620 -0
  173. package/src/context.ts +43 -0
  174. package/src/css-gradient-scan.ts +88 -0
  175. package/src/css-var-scan.test.ts +96 -0
  176. package/src/css-var-scan.ts +144 -0
  177. package/src/derive-module-type.test.ts +80 -0
  178. package/src/design-manifest.ts +93 -0
  179. package/src/fonts.test.ts +157 -0
  180. package/src/fonts.ts +296 -0
  181. package/src/genesis-inventory.test.ts +86 -0
  182. package/src/genesis-inventory.ts +215 -0
  183. package/src/genesis-sanitize.test.ts +35 -0
  184. package/src/genesis.ts +87 -0
  185. package/src/i18n.test.ts +274 -0
  186. package/src/i18n.ts +269 -0
  187. package/src/index.test.ts +10 -0
  188. package/src/index.ts +59 -0
  189. package/src/interactions.ts +48 -0
  190. package/src/logger.ts +147 -0
  191. package/src/media.test.ts +160 -0
  192. package/src/media.ts +355 -0
  193. package/src/page-log.test.ts +163 -0
  194. package/src/page-log.ts +124 -0
  195. package/src/preview-compose.test.ts +602 -0
  196. package/src/preview-compose.ts +709 -0
  197. package/src/preview-scanner.test.ts +96 -0
  198. package/src/preview-scanner.ts +214 -0
  199. package/src/proposal-status.test.ts +69 -0
  200. package/src/proposal-status.ts +40 -0
  201. package/src/responsive-images.test.ts +104 -0
  202. package/src/responsive-images.ts +151 -0
  203. package/src/result.ts +29 -0
  204. package/src/safe-keys.ts +21 -0
  205. package/src/seo.test.ts +234 -0
  206. package/src/seo.ts +261 -0
  207. package/src/skills.ts +48 -0
  208. package/src/snapshots.test.ts +80 -0
  209. package/src/snapshots.ts +81 -0
  210. package/src/strip-cdata.test.ts +41 -0
  211. package/src/strip-cdata.ts +50 -0
  212. package/src/structured-sets.ts +180 -0
  213. package/src/subagents.test.ts +262 -0
  214. package/src/subagents.ts +432 -0
  215. package/src/template-engine.test.ts +379 -0
  216. package/src/template-engine.ts +520 -0
  217. package/src/theme-gradient.test.ts +92 -0
  218. package/src/theme-importers/__tests__/proto-pollution.test.ts +54 -0
  219. package/src/theme-importers/auto-detect.ts +84 -0
  220. package/src/theme-importers/css-comments.ts +15 -0
  221. package/src/theme-importers/dtcg.ts +106 -0
  222. package/src/theme-importers/loose.ts +76 -0
  223. package/src/theme-importers/shadcn.ts +133 -0
  224. package/src/theme-importers/style-dictionary.ts +125 -0
  225. package/src/theme-importers/tailwind.ts +217 -0
  226. package/src/theme-literal-binding.test.ts +71 -0
  227. package/src/theme-literal-binding.ts +159 -0
  228. package/src/theme-motion.test.ts +115 -0
  229. package/src/theme-normalize-envelope.test.ts +43 -0
  230. package/src/theme-normalize-gradient.test.ts +135 -0
  231. package/src/theme-normalize.ts +661 -0
  232. package/src/theme-ramp.ts +187 -0
  233. package/src/theme-render-sanitize.test.ts +45 -0
  234. package/src/theme-render.test.ts +119 -0
  235. package/src/theme-render.ts +487 -0
  236. package/src/theme-shadow.test.ts +56 -0
  237. package/src/themes-errors.ts +199 -0
  238. package/src/themes.ts +842 -0
  239. package/src/translation.test.ts +160 -0
  240. package/src/translation.ts +295 -0
  241. package/src/version.ts +66 -0
@@ -0,0 +1,199 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * Typed errors emitted by the theme primitive (#45, v0.11.0).
5
+ *
6
+ * Per CLAUDE.md §11 ("Failure surfaces are AI-actionable") every error
7
+ * includes the next step the AI should try inside `.message`. The ops
8
+ * layer wraps these as `err({kind:"HandlerError", message})`; the AI
9
+ * tool layer returns them in `content`. Inline classes (vs ad-hoc
10
+ * strings) so callers can `instanceof` to surface structured fields
11
+ * (suggestions, supported formats) to the UI / system-prompt later.
12
+ */
13
+
14
+ /**
15
+ * Loose token name could not be normalized to a canonical DTCG path.
16
+ * Carries the closest-match suggestions so the AI's next attempt has
17
+ * a concrete target.
18
+ */
19
+ export class UnknownTokenName extends Error {
20
+ readonly input: string;
21
+ readonly suggestions: readonly string[];
22
+ constructor(input: string, suggestions: readonly string[]) {
23
+ const tail =
24
+ suggestions.length > 0
25
+ ? ` — did you mean ${suggestions.map((s) => `'${s}'`).join(" or ")}?`
26
+ : " — pass a canonical DTCG path like 'color.primary' or 'typography.heading.fontFamily'";
27
+ super(`UnknownTokenName: cannot infer canonical path for '${input}'${tail}`);
28
+ this.name = "UnknownTokenName";
29
+ this.input = input;
30
+ this.suggestions = suggestions;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Value supplied for a color token isn't in a supported CSS color
36
+ * format. The message names every format we accept so the AI's retry
37
+ * lands.
38
+ */
39
+ export class InvalidColorValue extends Error {
40
+ readonly input: string;
41
+ readonly supportedFormats: readonly string[] = [
42
+ "#rrggbb",
43
+ "#rgb",
44
+ "oklch(L C H)",
45
+ "oklch(L C H / A)",
46
+ "rgb(R G B)",
47
+ "rgb(R G B / A)",
48
+ ];
49
+ constructor(input: string) {
50
+ super(
51
+ `InvalidColorValue: '${input}' is not a recognised CSS color — supported formats: ${[
52
+ "#rrggbb",
53
+ "#rgb",
54
+ "oklch(L C H)",
55
+ "rgb(R G B)",
56
+ ].join(", ")}. Try a hex like '#3b82f6' or 'oklch(0.6 0.2 250)'.`,
57
+ );
58
+ this.name = "InvalidColorValue";
59
+ this.input = input;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * v0.11.0 (#45 opt §2) — `themes.import_dtcg` was handed a JSON body
65
+ * whose shape doesn't look like DTCG (no `$value` anywhere in the
66
+ * tree). v0.11.1 (issue #76) — auto-detect chain uses this as a
67
+ * "fall through to next importer" signal; only surfaces verbatim when
68
+ * the caller explicitly picked the DTCG importer.
69
+ */
70
+ export class NotDtcgShape extends Error {
71
+ constructor(message?: string) {
72
+ super(
73
+ message ??
74
+ "NotDtcgShape: the JSON body parsed cleanly but doesn't look like a DTCG document " +
75
+ "(no `$value` keys anywhere in the tree). Send a DTCG-shaped document — see " +
76
+ "https://www.designtokens.org/tr/drafts/format/ for the spec.",
77
+ );
78
+ this.name = "NotDtcgShape";
79
+ }
80
+ }
81
+
82
+ /**
83
+ * v0.11.1 (issue #76) — Style Dictionary importer rejected input.
84
+ * Used as a fall-through signal by the auto-detect chain.
85
+ */
86
+ export class NotStyleDictionaryShape extends Error {
87
+ constructor(message?: string) {
88
+ super(
89
+ message ??
90
+ "NotStyleDictionaryShape: input has no nested `{ value: … }` leaves typical of " +
91
+ "Style Dictionary v3/v4. Looks like another format — try DTCG ($value leaves), " +
92
+ "Tailwind 4 (@theme block), or shadcn (:root CSS variables).",
93
+ );
94
+ this.name = "NotStyleDictionaryShape";
95
+ }
96
+ }
97
+
98
+ /**
99
+ * v0.11.1 (issue #76) — Tailwind 4 `@theme { … }` importer rejected
100
+ * input. Either no `@theme` block found, or the body contained a
101
+ * construct the line-by-line parser can't handle (calc(), nested
102
+ * at-rules). Auto-detect chain catches it and falls through.
103
+ */
104
+ export class NotTailwindShape extends Error {
105
+ constructor(message?: string) {
106
+ super(
107
+ message ??
108
+ "NotTailwindShape: input has no `@theme { … }` block. Send the contents of your " +
109
+ "Tailwind 4 theme file or use a different importer.",
110
+ );
111
+ this.name = "NotTailwindShape";
112
+ }
113
+ }
114
+
115
+ /**
116
+ * v0.11.1 (issue #76) — Tailwind 4 importer hit a construct it can't
117
+ * parse (e.g. `calc(…)` values, nested at-rules). Surfaced verbatim
118
+ * by the auto-detect chain since the input WAS Tailwind-shaped — the
119
+ * caller should simplify or pre-resolve.
120
+ */
121
+ export class TailwindImportError extends Error {
122
+ readonly construct: string;
123
+ constructor(construct: string, line: string) {
124
+ super(
125
+ `TailwindImportError: the @theme block contains '${construct}' which the importer can't parse: '${line.trim()}'. ` +
126
+ "Pre-resolve calc()/var() to literal values, or split nested at-rules into a separate file.",
127
+ );
128
+ this.name = "TailwindImportError";
129
+ this.construct = construct;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * v0.11.1 (issue #76) — shadcn `:root { … }` importer rejected input
135
+ * (no `:root` selector found, or values were wrapped in `{value: …}`
136
+ * style-dictionary shape). Auto-detect chain falls through.
137
+ */
138
+ export class NotShadcnShape extends Error {
139
+ constructor(message?: string) {
140
+ super(
141
+ message ??
142
+ "NotShadcnShape: input has no `:root { … }` CSS block with `--<name>: <value>;` pairs. " +
143
+ "Send a shadcn-style CSS variable list (with optional `.dark { … }` for dark mode).",
144
+ );
145
+ this.name = "NotShadcnShape";
146
+ }
147
+ }
148
+
149
+ /**
150
+ * v0.11.1 (issue #76) — loose JSON-object importer rejected input
151
+ * (not a JSON object, or contains `$value` / `value` leaves that
152
+ * belong to a different format). Auto-detect chain falls through.
153
+ */
154
+ export class NotLooseShape extends Error {
155
+ constructor(message?: string) {
156
+ super(
157
+ message ?? "NotLooseShape: input is not a flat JSON object of `{looseName: value}` pairs.",
158
+ );
159
+ this.name = "NotLooseShape";
160
+ }
161
+ }
162
+
163
+ /**
164
+ * v0.11.1 (issue #76) — auto-detect chain ran every importer and none
165
+ * accepted the input. Carries per-format rejection reasons so the AI's
166
+ * next turn can fix the input or fall back to `set_theme_tokens`.
167
+ */
168
+ export class NoImporterMatched extends Error {
169
+ readonly attempts: ReadonlyArray<{ format: string; reason: string }>;
170
+ constructor(attempts: ReadonlyArray<{ format: string; reason: string }>) {
171
+ const summary = attempts.map((a) => `${a.format}: ${a.reason}`).join("; ");
172
+ super(
173
+ `NoImporterMatched: none of the supported formats accepted the input. ${summary}. ` +
174
+ "Fix the input or fall back to `set_theme_tokens` with a normalized object.",
175
+ );
176
+ this.name = "NoImporterMatched";
177
+ this.attempts = attempts;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Loose-name input resolved to a canonical path but the value's
183
+ * inferred category doesn't match the category for that path
184
+ * (e.g. caller put a `0.5rem` value at `color.primary`).
185
+ */
186
+ export class TokenCategoryMismatch extends Error {
187
+ readonly canonicalPath: string;
188
+ readonly expected: string;
189
+ readonly got: string;
190
+ constructor(canonicalPath: string, expected: string, got: string) {
191
+ super(
192
+ `TokenCategoryMismatch: '${canonicalPath}' expects a ${expected} value, got a ${got} — re-send with a value matching ${expected}.`,
193
+ );
194
+ this.name = "TokenCategoryMismatch";
195
+ this.canonicalPath = canonicalPath;
196
+ this.expected = expected;
197
+ this.got = got;
198
+ }
199
+ }