@kayjs/kay 1.105.0 → 1.106.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 (310) hide show
  1. package/dist/eslint.js +435 -120
  2. package/editors/zed/extension.toml +2 -2
  3. package/llms/action-protection.md +1 -1
  4. package/llms/actions-from-islands.md +2 -2
  5. package/llms/actions.md +22 -19
  6. package/llms/analytics.md +1 -1
  7. package/llms/api-from-islands.md +1 -1
  8. package/llms/api-routes.md +6 -6
  9. package/llms/check-and-tools.md +1 -1
  10. package/llms/code-lints.md +2 -2
  11. package/llms/compiler-api.md +1 -1
  12. package/llms/component-libraries.md +1 -0
  13. package/llms/content-cms.md +1 -1
  14. package/llms/content-markdown-to-caching.md +1 -1
  15. package/llms/content-preview.md +2 -2
  16. package/llms/content.md +21 -21
  17. package/llms/deprecated-lints-1-105-libraries.md +2 -0
  18. package/llms/deprecated-lints-1-105.md +3 -3
  19. package/llms/deprecated-lints.md +3 -2
  20. package/llms/dev-tool.md +2 -2
  21. package/llms/environment.md +22 -22
  22. package/llms/files.md +5 -5
  23. package/llms/islands-state-to-ids.md +2 -1
  24. package/llms/local-collections.md +2 -2
  25. package/llms/mcp.md +2 -1
  26. package/llms/navigation-from-code.md +1 -1
  27. package/llms/notifications.md +4 -2
  28. package/llms/project.md +1 -1
  29. package/llms/rate-limits.md +1 -1
  30. package/llms/recipes.md +16 -16
  31. package/llms/rooms.md +4 -4
  32. package/llms/routing-endpoints-and-base.md +1 -1
  33. package/llms/routing.md +5 -5
  34. package/llms/schemas.md +10 -5
  35. package/llms/server.md +7 -7
  36. package/llms/site.md +9 -9
  37. package/llms/sitemap-search-fonts.md +2 -0
  38. package/llms/styles-and-assets.md +2 -1
  39. package/llms/templates-elements-slots-snippets.md +2 -2
  40. package/llms/testing-browser.md +20 -0
  41. package/llms/testing.md +1 -1
  42. package/llms/upgrading-1-105-config.md +2 -2
  43. package/llms/upgrading.md +18 -3
  44. package/llms/whats-new-archive.md +35 -66
  45. package/llms/whats-new.md +34 -28
  46. package/llms.txt +1 -1
  47. package/package.json +15 -11
  48. package/src/add.ts +1 -1
  49. package/src/build/class-table.ts +2 -2
  50. package/src/build/client.ts +7 -6
  51. package/src/build/plugin.ts +14 -11
  52. package/src/build/styles.ts +3 -3
  53. package/src/build/transform.ts +3 -1
  54. package/src/build/ui-layers.ts +30 -0
  55. package/src/build/ui.ts +108 -11
  56. package/src/build/variants.ts +119 -43
  57. package/src/build/worker-bundle.ts +6 -0
  58. package/src/check/boot.ts +22 -1
  59. package/src/check/call-result.ts +242 -0
  60. package/src/check/config-objects.ts +17 -2
  61. package/src/check/diagnose.ts +22 -0
  62. package/src/check/handler-events.ts +149 -0
  63. package/src/check/index.ts +6 -2
  64. package/src/check/link-flag-tests.ts +130 -0
  65. package/src/check/project.ts +4 -3
  66. package/src/check/refusal-calls.ts +2 -2
  67. package/src/check/regroup.ts +5 -3
  68. package/src/check/renamed-packages.ts +58 -14
  69. package/src/check/schema-builders.ts +256 -0
  70. package/src/check/secret-keys.ts +15 -2
  71. package/src/check/shadow-types.ts +2 -0
  72. package/src/check/template-hints.ts +1 -1
  73. package/src/check/tool-labels.ts +11 -9
  74. package/src/check/ui-types.ts +4 -3
  75. package/src/check/ui.ts +14 -11
  76. package/src/commands/env-declare.ts +18 -6
  77. package/src/commands/routes.ts +1 -1
  78. package/src/compiler/a11y.ts +8 -1
  79. package/src/compiler/ast.ts +1 -1
  80. package/src/compiler/bound-props.ts +1 -1
  81. package/src/compiler/codegen.ts +6 -6
  82. package/src/compiler/deprecated-lints-1-106.ts +14 -0
  83. package/src/compiler/deprecated-lints.ts +10 -5
  84. package/src/compiler/deprecated-typed-lints.ts +23 -0
  85. package/src/compiler/dom-here.ts +72 -0
  86. package/src/compiler/dom.ts +23 -23
  87. package/src/compiler/fence-checks.ts +12 -11
  88. package/src/compiler/field-described.ts +2 -2
  89. package/src/compiler/helper-imports.ts +1 -1
  90. package/src/compiler/html-fields.ts +92 -0
  91. package/src/compiler/html-initial.ts +5 -3
  92. package/src/compiler/html.ts +14 -31
  93. package/src/compiler/index.ts +3 -1
  94. package/src/compiler/items.ts +5 -5
  95. package/src/compiler/link-flags.ts +6 -5
  96. package/src/compiler/lints.ts +12 -12
  97. package/src/compiler/rest-omits.ts +15 -0
  98. package/src/config-loader.ts +10 -2
  99. package/src/config-resolve.ts +3 -1
  100. package/src/config-shape.ts +2 -2
  101. package/src/config.ts +20 -4
  102. package/src/content/markdown.ts +2 -3
  103. package/src/generate-resource.ts +9 -9
  104. package/src/generate.ts +1 -1
  105. package/src/mcp/guards.ts +1 -1
  106. package/src/mcp/tools.ts +1 -1
  107. package/src/migrate/content.ts +61 -55
  108. package/src/runtime/action-shared.ts +2 -2
  109. package/src/runtime/action.ts +6 -2
  110. package/src/runtime/form-types.ts +99 -0
  111. package/src/runtime/form.ts +22 -7
  112. package/src/runtime/html.ts +36 -5
  113. package/src/runtime/markdown-autolink.ts +69 -0
  114. package/src/runtime/markdown-render.client.ts +39 -3
  115. package/src/runtime/markdown.client.ts +6 -3
  116. package/src/runtime/markdown.server.ts +6 -3
  117. package/src/runtime/markdown.ts +125 -1
  118. package/src/runtime/navigate-api.ts +10 -5
  119. package/src/runtime/persist.ts +7 -7
  120. package/src/runtime/query-param.ts +1 -1
  121. package/src/runtime/reactive.ts +14 -0
  122. package/src/runtime/sanitize.ts +3 -1
  123. package/src/runtime/schema-record.ts +31 -0
  124. package/src/runtime/schema.client.ts +1 -4
  125. package/src/runtime/schema.ts +321 -26
  126. package/src/runtime/swap-focus.ts +59 -11
  127. package/src/server/action-module.ts +16 -0
  128. package/src/server/actions.ts +6 -14
  129. package/src/server/api-modules.ts +1 -1
  130. package/src/server/api.ts +13 -1
  131. package/src/server/app-stages.ts +23 -18
  132. package/src/server/dev-ui.ts +2 -2
  133. package/src/server/env-state.ts +1 -1
  134. package/src/server/env.ts +11 -3
  135. package/src/server/favicon.ts +47 -1
  136. package/src/server/image-metadata-bmff.ts +1 -1
  137. package/src/server/kept-pages.ts +3 -3
  138. package/src/server/library.ts +2 -0
  139. package/src/server/mcp.ts +13 -12
  140. package/src/server/notifications.ts +4 -2
  141. package/src/server/offline.ts +24 -7
  142. package/src/server/push-settings.ts +16 -2
  143. package/src/server/push.ts +12 -4
  144. package/src/server/query.ts +13 -6
  145. package/src/server/render.ts +1 -1
  146. package/src/server/scope.ts +20 -13
  147. package/src/server/signals.ts +4 -4
  148. package/src/template-ws.ts +1 -1
  149. package/src/test/a11y-dom.ts +70 -0
  150. package/src/test/html-snapshot.ts +103 -0
  151. package/src/test/index.ts +2 -1
  152. package/src/test/mount.ts +8 -1
  153. package/src/test/page-checks.ts +12 -0
  154. package/src/test/screenshot-match.ts +2 -2
  155. package/src/test/shared-modules.ts +27 -5
  156. package/src/test/site-types.ts +5 -1
  157. package/types/build/class-table.d.ts +1 -1
  158. package/types/build/class-table.d.ts.map +1 -1
  159. package/types/build/client.d.ts.map +1 -1
  160. package/types/build/plugin.d.ts.map +1 -1
  161. package/types/build/transform.d.ts +1 -0
  162. package/types/build/transform.d.ts.map +1 -1
  163. package/types/build/ui-layers.d.ts +5 -0
  164. package/types/build/ui-layers.d.ts.map +1 -0
  165. package/types/build/ui.d.ts +7 -0
  166. package/types/build/ui.d.ts.map +1 -1
  167. package/types/build/variants.d.ts +1 -1
  168. package/types/build/variants.d.ts.map +1 -1
  169. package/types/build/worker-bundle.d.ts +1 -0
  170. package/types/build/worker-bundle.d.ts.map +1 -1
  171. package/types/check/boot.d.ts.map +1 -1
  172. package/types/check/call-result.d.ts +7 -0
  173. package/types/check/call-result.d.ts.map +1 -0
  174. package/types/check/config-objects.d.ts.map +1 -1
  175. package/types/check/diagnose.d.ts.map +1 -1
  176. package/types/check/handler-events.d.ts +9 -0
  177. package/types/check/handler-events.d.ts.map +1 -0
  178. package/types/check/index.d.ts +1 -0
  179. package/types/check/index.d.ts.map +1 -1
  180. package/types/check/link-flag-tests.d.ts +4 -0
  181. package/types/check/link-flag-tests.d.ts.map +1 -0
  182. package/types/check/project.d.ts.map +1 -1
  183. package/types/check/regroup.d.ts +1 -1
  184. package/types/check/regroup.d.ts.map +1 -1
  185. package/types/check/renamed-packages.d.ts +1 -0
  186. package/types/check/renamed-packages.d.ts.map +1 -1
  187. package/types/check/schema-builders.d.ts +3 -0
  188. package/types/check/schema-builders.d.ts.map +1 -0
  189. package/types/check/secret-keys.d.ts.map +1 -1
  190. package/types/check/shadow-types.d.ts.map +1 -1
  191. package/types/check/template-hints.d.ts +1 -0
  192. package/types/check/template-hints.d.ts.map +1 -1
  193. package/types/check/tool-labels.d.ts.map +1 -1
  194. package/types/check/ui-types.d.ts.map +1 -1
  195. package/types/check/ui.d.ts.map +1 -1
  196. package/types/commands/env-declare.d.ts.map +1 -1
  197. package/types/compiler/a11y.d.ts.map +1 -1
  198. package/types/compiler/bound-props.d.ts +1 -0
  199. package/types/compiler/bound-props.d.ts.map +1 -1
  200. package/types/compiler/codegen.d.ts +1 -0
  201. package/types/compiler/codegen.d.ts.map +1 -1
  202. package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
  203. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
  204. package/types/compiler/deprecated-lints.d.ts +32 -5
  205. package/types/compiler/deprecated-lints.d.ts.map +1 -1
  206. package/types/compiler/deprecated-typed-lints.d.ts +21 -0
  207. package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
  208. package/types/compiler/dom-here.d.ts +14 -0
  209. package/types/compiler/dom-here.d.ts.map +1 -0
  210. package/types/compiler/dom.d.ts +1 -0
  211. package/types/compiler/dom.d.ts.map +1 -1
  212. package/types/compiler/fence-checks.d.ts.map +1 -1
  213. package/types/compiler/field-described.d.ts +1 -1
  214. package/types/compiler/field-described.d.ts.map +1 -1
  215. package/types/compiler/html-fields.d.ts +19 -0
  216. package/types/compiler/html-fields.d.ts.map +1 -0
  217. package/types/compiler/html-initial.d.ts +3 -2
  218. package/types/compiler/html-initial.d.ts.map +1 -1
  219. package/types/compiler/html.d.ts.map +1 -1
  220. package/types/compiler/index.d.ts +1 -0
  221. package/types/compiler/index.d.ts.map +1 -1
  222. package/types/compiler/items.d.ts +4 -1
  223. package/types/compiler/items.d.ts.map +1 -1
  224. package/types/compiler/link-flags.d.ts +6 -0
  225. package/types/compiler/link-flags.d.ts.map +1 -1
  226. package/types/compiler/lints.d.ts +44 -17
  227. package/types/compiler/lints.d.ts.map +1 -1
  228. package/types/compiler/rest-omits.d.ts +4 -0
  229. package/types/compiler/rest-omits.d.ts.map +1 -0
  230. package/types/config-loader.d.ts.map +1 -1
  231. package/types/config-resolve.d.ts.map +1 -1
  232. package/types/config.d.ts +15 -2
  233. package/types/config.d.ts.map +1 -1
  234. package/types/content/markdown.d.ts.map +1 -1
  235. package/types/migrate/content.d.ts.map +1 -1
  236. package/types/runtime/action-shared.d.ts +1 -1
  237. package/types/runtime/action-shared.d.ts.map +1 -1
  238. package/types/runtime/action.d.ts +3 -0
  239. package/types/runtime/action.d.ts.map +1 -1
  240. package/types/runtime/form-types.d.ts +6 -0
  241. package/types/runtime/form-types.d.ts.map +1 -0
  242. package/types/runtime/form.d.ts +3 -1
  243. package/types/runtime/form.d.ts.map +1 -1
  244. package/types/runtime/html.d.ts +3 -0
  245. package/types/runtime/html.d.ts.map +1 -1
  246. package/types/runtime/markdown-autolink.d.ts +11 -0
  247. package/types/runtime/markdown-autolink.d.ts.map +1 -0
  248. package/types/runtime/markdown-render.client.d.ts +2 -1
  249. package/types/runtime/markdown-render.client.d.ts.map +1 -1
  250. package/types/runtime/markdown.client.d.ts +3 -1
  251. package/types/runtime/markdown.client.d.ts.map +1 -1
  252. package/types/runtime/markdown.d.ts +11 -0
  253. package/types/runtime/markdown.d.ts.map +1 -1
  254. package/types/runtime/markdown.server.d.ts +3 -1
  255. package/types/runtime/markdown.server.d.ts.map +1 -1
  256. package/types/runtime/navigate-api.d.ts +1 -1
  257. package/types/runtime/navigate-api.d.ts.map +1 -1
  258. package/types/runtime/persist.d.ts +2 -2
  259. package/types/runtime/persist.d.ts.map +1 -1
  260. package/types/runtime/reactive.d.ts +3 -0
  261. package/types/runtime/reactive.d.ts.map +1 -1
  262. package/types/runtime/sanitize.d.ts.map +1 -1
  263. package/types/runtime/schema-record.d.ts +9 -0
  264. package/types/runtime/schema-record.d.ts.map +1 -0
  265. package/types/runtime/schema.client.d.ts.map +1 -1
  266. package/types/runtime/schema.d.ts +94 -10
  267. package/types/runtime/schema.d.ts.map +1 -1
  268. package/types/runtime/swap-focus.d.ts.map +1 -1
  269. package/types/server/action-module.d.ts +2 -0
  270. package/types/server/action-module.d.ts.map +1 -0
  271. package/types/server/actions.d.ts +1 -0
  272. package/types/server/actions.d.ts.map +1 -1
  273. package/types/server/api.d.ts.map +1 -1
  274. package/types/server/app-stages.d.ts +3 -2
  275. package/types/server/app-stages.d.ts.map +1 -1
  276. package/types/server/env-state.d.ts.map +1 -1
  277. package/types/server/env.d.ts +5 -1
  278. package/types/server/env.d.ts.map +1 -1
  279. package/types/server/favicon.d.ts +3 -1
  280. package/types/server/favicon.d.ts.map +1 -1
  281. package/types/server/kept-pages.d.ts +1 -1
  282. package/types/server/kept-pages.d.ts.map +1 -1
  283. package/types/server/library.d.ts +2 -0
  284. package/types/server/library.d.ts.map +1 -1
  285. package/types/server/mcp.d.ts +1 -1
  286. package/types/server/mcp.d.ts.map +1 -1
  287. package/types/server/notifications.d.ts +2 -1
  288. package/types/server/notifications.d.ts.map +1 -1
  289. package/types/server/offline.d.ts.map +1 -1
  290. package/types/server/push-settings.d.ts +1 -1
  291. package/types/server/push-settings.d.ts.map +1 -1
  292. package/types/server/push.d.ts +1 -0
  293. package/types/server/push.d.ts.map +1 -1
  294. package/types/server/query.d.ts.map +1 -1
  295. package/types/server/scope.d.ts +1 -1
  296. package/types/server/scope.d.ts.map +1 -1
  297. package/types/test/a11y-dom.d.ts +20 -0
  298. package/types/test/a11y-dom.d.ts.map +1 -0
  299. package/types/test/html-snapshot.d.ts +4 -0
  300. package/types/test/html-snapshot.d.ts.map +1 -0
  301. package/types/test/index.d.ts.map +1 -1
  302. package/types/test/mount.d.ts +3 -0
  303. package/types/test/mount.d.ts.map +1 -1
  304. package/types/test/page-checks.d.ts +6 -0
  305. package/types/test/page-checks.d.ts.map +1 -0
  306. package/types/test/screenshot-match.d.ts +1 -1
  307. package/types/test/screenshot-match.d.ts.map +1 -1
  308. package/types/test/shared-modules.d.ts.map +1 -1
  309. package/types/test/site-types.d.ts +3 -1
  310. package/types/test/site-types.d.ts.map +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayjs/kay",
3
3
  "type": "module",
4
- "version": "1.105.0",
4
+ "version": "1.106.0",
5
5
  "description": "A Bun web framework: one .kay file per component, pages rendered to plain HTML on the server, interactive islands in the browser",
6
6
  "author": "Kaynooo <https://github.com/Kayno0o>",
7
7
  "license": "MIT",
@@ -260,6 +260,7 @@
260
260
  "@kaynooo/pg-orm": "^7.0.0 || ^8.0.0",
261
261
  "@types/bun": "^1.4.4",
262
262
  "axe-core": "^4.14.0",
263
+ "happy-dom": "^20.14.6 || ^21.0.3",
263
264
  "typescript7": "npm:typescript@^7.0.2"
264
265
  },
265
266
  "peerDependenciesMeta": {
@@ -272,6 +273,9 @@
272
273
  "axe-core": {
273
274
  "optional": true
274
275
  },
276
+ "happy-dom": {
277
+ "optional": true
278
+ },
275
279
  "typescript7": {
276
280
  "optional": true
277
281
  }
@@ -287,20 +291,20 @@
287
291
  "oxc-parser": "^0.155.0"
288
292
  },
289
293
  "devDependencies": {
290
- "@babel/parser": "^7.29.7",
291
- "@babel/traverse": "^7.29.10",
292
- "@babel/types": "^7.29.11",
294
+ "@babel/parser": "^8.1.0",
295
+ "@babel/traverse": "^8.1.0",
296
+ "@babel/types": "^8.1.0",
293
297
  "@fontsource-variable/jetbrains-mono": "5.3.0",
294
298
  "@fontsource-variable/space-grotesk": "5.3.0",
295
299
  "@fontsource/inter": "^5.3.0",
296
300
  "@happy-dom/global-registrator": "^21.0.4",
297
301
  "@iconify-json/tabler": "^1.2.42",
298
- "@kayjs/ai": "1.105.0",
299
- "@kayjs/auth": "1.105.0",
300
- "@kayjs/cms": "1.105.0",
301
- "@kayjs/mail": "1.105.0",
302
- "@kayjs/ui": "1.105.0",
303
- "@kaynooo/eslint": "^7.1.6",
302
+ "@kayjs/ai": "1.106.0",
303
+ "@kayjs/auth": "1.106.0",
304
+ "@kayjs/cms": "1.106.0",
305
+ "@kayjs/mail": "1.106.0",
306
+ "@kayjs/ui": "1.106.0",
307
+ "@kaynooo/eslint": "^8.0.3",
304
308
  "@kaynooo/pg-orm": "^8.1.4",
305
309
  "@oxc-parser/binding-wasm32-wasip1": "0.155.0",
306
310
  "@types/babel__traverse": "^7.28.0",
@@ -310,7 +314,7 @@
310
314
  "kay": "link:.",
311
315
  "mitata": "1.0.34",
312
316
  "playwright-core": "1.64.1",
313
- "shiki": "^4.5.0",
317
+ "shiki": "^4.6.0",
314
318
  "tailwindcss": "^4.3.3",
315
319
  "typescript": "^6.0.3",
316
320
  "typescript7": "npm:typescript@^7.0.2"
package/src/add.ts CHANGED
@@ -498,7 +498,7 @@ async function loadLibrary(dir: string, name: string, project: LibraryProject, f
498
498
  const feature = typeof module.default === 'function' ? module.default(project) : module.default
499
499
 
500
500
  if (typeof feature?.description !== 'string')
501
- throw new Error(`kay add: ${LIBRARIES[name]![0]!}/add does not export a feature as its default`)
501
+ throw new TypeError(`kay add: ${LIBRARIES[name]![0]!}/add does not export a feature as its default`)
502
502
 
503
503
  return feature
504
504
  }
@@ -326,6 +326,6 @@ export function isUtility(design: Design, word: string): boolean {
326
326
  const RUNTIME_MERGE = /\bclass\s*=\s*(?!["'])|\.\.\.[\w$({[]|\bparts?\b|\brecipe\b/
327
327
 
328
328
  // Whether a module may hand the browser classes to merge: a `.kay` file with a class expression, a spread, a part or a recipe, or `src/ui.ts`, which writes parts.
329
- export function mergesAtRuntime(file: string): boolean {
330
- return (file.endsWith('.kay') || file.endsWith(UI_FILE)) && RUNTIME_MERGE.test(readSource(file).text)
329
+ export function mergesAtRuntime(file: string, uiFiles: readonly string[] = []): boolean {
330
+ return (file.endsWith('.kay') || file.endsWith(UI_FILE) || uiFiles.includes(file)) && RUNTIME_MERGE.test(readSource(file).text)
331
331
  }
@@ -54,7 +54,7 @@ import { styleImports, withoutStyles, writeComponentStylesheets } from './styles
54
54
  import { mergingSupports } from './supports'
55
55
  import { warnBuiltThemeVariables } from './theme-vars'
56
56
  import { analyzeKayCached, KayCompileError, keepAnalyses } from './transform'
57
- import { UI_FILE } from './ui'
57
+ import { uiFilesOf, uiLayerClasses, uiPathsOf } from './ui'
58
58
  import { kayFiles, variantFile, VariantIndex } from './variants'
59
59
 
60
60
  export interface ClientOptions extends Pick<KayConfig, ClientBuildKey> {
@@ -215,7 +215,8 @@ export function clientSession(root: string, options: ClientOptions, settings: Se
215
215
 
216
216
  const classTableText = JSON.stringify([classTable, islandTable])
217
217
  // `src/ui.ts` is written into the components it restyles, none of which imports it, so no chunk lists it among its inputs.
218
- const islandsAgain = !previous || !sameEntries(previous.sources.islands, sources.islands) || files.some(file => previous.islandInputs.has(file) || file === join(realRoot, UI_FILE) || file === join(realRoot, AWAIT_ALERT_FILE)) || previous.classTable !== classTableText || (!options.hot && (previous.sources.actionForms !== sources.actionForms || previous.sources.actionProps !== sources.actionProps))
218
+
219
+ const islandsAgain = !previous || !sameEntries(previous.sources.islands, sources.islands) || files.some(file => previous.islandInputs.has(file) || uiPathsOf(realRoot).includes(file) || file === join(realRoot, AWAIT_ALERT_FILE)) || previous.classTable !== classTableText || (!options.hot && (previous.sources.actionForms !== sources.actionForms || previous.sources.actionProps !== sources.actionProps))
219
220
  const stylesAgain = !previous || await increments!.stylesChanged(previous, sources, texts)
220
221
 
221
222
  if (previous && islandsAgain)
@@ -428,7 +429,7 @@ async function writeClasses(root: string, classes: Set<string>): Promise<void> {
428
429
  const file = projectPaths(root).classes
429
430
 
430
431
  await writeIfChanged(join(dirname(file), '.gitignore'), '*\n!/scratch/\n!/scratch/**\n')
431
- await writeIfChanged(file, [...classes].sort().join('\n'))
432
+ await writeIfChanged(file, [...new Set([...classes, ...uiLayerClasses(root)])].sort().join('\n'))
432
433
  }
433
434
 
434
435
  // The table of Tailwind classes a later one overrides, from every word of the components and of the other files an app writes markup in; none when the app has no Tailwind.
@@ -483,15 +484,15 @@ export async function islandClassTableOf(root: string, sources: Pick<ClientSourc
483
484
  const bundled = await reachedFrom([...entries], edges)
484
485
  const renderers = new Set([...shorthand.keys(), ...(await markupFiles(root, sources)).filter(file => RENDERING_FILE.test(file))])
485
486
  const outside = [...renderers].filter(file => !bundled.has(realpathSync(file)))
486
- const ui = join(root, UI_FILE)
487
487
  // `src/ui.ts` is written into the components it restyles, none of which imports it.
488
488
  const reaching = await reachingAny(outside.map(file => realpathSync(file)), entries, edges)
489
489
  const reachingOutside = outside.filter(file => reaching.has(realpathSync(file)))
490
490
  const alert = join(root, AWAIT_ALERT_FILE)
491
- const written = [...bundled, ...existsSync(ui) ? [ui] : [], ...existsSync(alert) ? [alert] : [], ...reachingOutside]
491
+ const uiFiles = uiFilesOf(root)
492
+ const written = [...bundled, ...uiFiles, ...existsSync(alert) ? [alert] : [], ...reachingOutside]
492
493
 
493
494
  // The browser merges classes only where a component writes a class that is not a literal, a spread or a part; two literals side by side were resolved while compiling.
494
- if (!written.some(file => mergesAtRuntime(file)))
495
+ if (!written.some(file => mergesAtRuntime(file, uiFiles)))
495
496
  return undefined
496
497
 
497
498
  const words = new Set(written.flatMap(file => fileWords(file)))
@@ -22,6 +22,7 @@ import { liveIds } from './live-ids'
22
22
  import { withLocaleLinks } from './navigation-locale'
23
23
  import { embeddedMapTail } from './sourcemap'
24
24
  import { embeddedMapCached, transformKayCached } from './transform'
25
+ import { uiLayerPathsOf } from './ui'
25
26
  import { specializedSource, USES_QUERY, VariantIndex } from './variants'
26
27
 
27
28
  export interface KayPluginOptions {
@@ -85,13 +86,13 @@ const WORKER_BUNDLE = join(import.meta.dir, 'worker-bundle.ts')
85
86
  const bundledWorkers = new Map<string, { result: WorkerResult, stamp: string }>()
86
87
 
87
88
  // Serves a component as the variant its `?uses=` names: resolved from the importer, loaded specialized to its features.
88
- function variantHooks(build: Bun.PluginBuilder, load: (file: string, twin: boolean, features: ReadonlySet<string>) => Promise<Bun.OnLoadResult>): void {
89
+ function variantHooks(build: Bun.PluginBuilder, load: (file: string, twin: boolean, features: ReadonlySet<string>, written?: ReadonlySet<string>) => Promise<Bun.OnLoadResult>): void {
89
90
  build.onResolve({ filter: USES_QUERY }, ({ path, importer }) => {
90
- const features = USES_QUERY.exec(path)![1]!
91
- const base = path.slice(0, path.length - features.length - '?uses='.length)
91
+ const query = USES_SUFFIX.exec(path)![0]
92
+ const base = path.slice(0, path.length - query.length)
92
93
 
93
94
  try {
94
- return { path: `${Bun.resolveSync(base, dirname(withoutTwin(importer.replace(USES_SUFFIX, ''))))}?uses=${features}`, namespace: VARIANT_NAMESPACE }
95
+ return { path: `${Bun.resolveSync(base, dirname(withoutTwin(importer.replace(USES_SUFFIX, ''))))}${query}`, namespace: VARIANT_NAMESPACE }
95
96
  }
96
97
  catch {
97
98
  // The normal resolver names what is wrong with the specifier.
@@ -99,9 +100,10 @@ function variantHooks(build: Bun.PluginBuilder, load: (file: string, twin: boole
99
100
  }
100
101
  })
101
102
  build.onLoad({ filter: USES_QUERY, namespace: VARIANT_NAMESPACE }, async ({ path }) => {
102
- const features = USES_QUERY.exec(path)![1]!
103
+ const [, features, written] = USES_QUERY.exec(path)!
104
+ const query = USES_SUFFIX.exec(path)![0]
103
105
 
104
- return load(path.slice(0, path.length - features.length - '?uses='.length), false, new Set(features.split('-').filter(Boolean)))
106
+ return load(path.slice(0, path.length - query.length), false, new Set(features!.split('-').filter(Boolean)), written === undefined ? undefined : new Set(written.split('-').filter(Boolean)))
105
107
  })
106
108
  }
107
109
 
@@ -163,11 +165,12 @@ export function kayPlugin(options: KayPluginOptions, workers: string[]): BunPlug
163
165
  const dist = clientDir(root)
164
166
 
165
167
  const bundleWorker = async (path: string): Promise<string> => {
166
- const bundle: WorkerBundle = { entry: path, outdir: join(dist, 'assets'), minify: config.minify ?? false, define: config.define ?? {}, options: { ...options, root, anchor: undefined, anchored: undefined }, workers: [...workers, path] }
168
+ const layers = uiLayerPathsOf(root)
169
+ const bundle: WorkerBundle = { entry: path, outdir: join(dist, 'assets'), minify: config.minify ?? false, define: config.define ?? {}, options: { ...options, root, anchor: undefined, anchored: undefined, variants: undefined }, workers: [...workers, path], uiLayers: layers }
167
170
  const key = JSON.stringify(bundle)
168
171
  const kept = bundledWorkers.get(key)
169
172
 
170
- if (kept !== undefined && kept.result.outputs.every(output => existsSync(output)) && stampOf(kept.result.inputs) === kept.stamp)
173
+ if (kept !== undefined && kept.result.outputs.every(output => existsSync(output)) && stampOf([...kept.result.inputs, ...layers]) === kept.stamp)
171
174
  return kept.result.name
172
175
 
173
176
  const started = Date.now()
@@ -193,7 +196,7 @@ export function kayPlugin(options: KayPluginOptions, workers: string[]): BunPlug
193
196
 
194
197
  // A file written while the bundle ran may not be the one it read.
195
198
  if (!result.ships && result.inputs.every(input => (statSync(input, { throwIfNoEntry: false })?.mtimeMs ?? 0) < started))
196
- bundledWorkers.set(key, { result, stamp: stampOf(result.inputs) })
199
+ bundledWorkers.set(key, { result, stamp: stampOf([...result.inputs, ...layers]) })
197
200
 
198
201
  return result.name
199
202
  }
@@ -256,11 +259,11 @@ export function kayPlugin(options: KayPluginOptions, workers: string[]): BunPlug
256
259
  const pointed = async (contents: string, loader: Bun.JavaScriptLoader = 'ts') => options.direct === true ? directImports(contents, loader) : contents
257
260
 
258
261
  // A twin's frames show its namespace and the whole path, where a file's show its path from where the build ran.
259
- const load = async (file: string, twin = false, features?: ReadonlySet<string>) => {
262
+ const load = async (file: string, twin = false, features?: ReadonlySet<string>, written?: ReadonlySet<string>) => {
260
263
  const original = await Bun.file(withoutTwin(file)).text()
261
264
  const source = features === undefined ? original : specializedSource(original, features, withoutTwin(file))
262
265
 
263
- const compiled = await transformKayCached(source, file, { target, hydratable: options.hydratable ?? true, root: options.root, pages: options.pages, cacheDir: options.cacheDir, inspect: options.inspect, classTable: options.classTable, variant: features === undefined ? undefined : [...features].sort().join('.') })
266
+ const compiled = await transformKayCached(source, file, { target, hydratable: options.hydratable ?? true, root: options.root, pages: options.pages, cacheDir: options.cacheDir, inspect: options.inspect, classTable: options.classTable, variant: features === undefined ? undefined : `${[...features].sort().join('.')}${written === undefined ? '' : `~${[...written].sort().join('.')}`}`, writtenProps: written })
264
267
  const code = target === 'dom' ? await variantIndex.variantImports(compiled, withoutTwin(file), original) : compiled
265
268
  const contents = await pointed(await shippingFiles(expandGlobs(code, withoutTwin(file), root, 'ts'), withoutTwin(file), 'ts'))
266
269
 
@@ -18,7 +18,7 @@ import { globbedFiles } from './glob'
18
18
  import { importsOf, libraryOf } from './libraries'
19
19
  import { outOfStore, throughLinks } from './links'
20
20
  import { recipeLifter } from './recipe-classes'
21
- import { UI_FILE, uiEntryOf } from './ui'
21
+ import { uiEntryOf, uiFilesOf } from './ui'
22
22
 
23
23
  const ABSOLUTE_URL = /^\//
24
24
  const FONT_FILE = /\.(?:woff2?|ttf|otf)(?:[?#].*)?$/i
@@ -273,8 +273,8 @@ export function styleImports(root: string, libraries: KayLibrary[] = [], loaded?
273
273
  server ? serverAssets(source.slice(server.start, server.end), path, 'ts') : undefined,
274
274
  ])
275
275
 
276
- // A component `src/ui.ts` restyles has the classes written there, which the page using it keeps the rules of.
277
- const restyled = uiEntryOf(root, path) === undefined ? '' : importing(note(path, [join(root, UI_FILE)]))
276
+ // A component `src/ui.ts` or an extension's `ui` file restyles has the classes written there, which the page using it keeps the rules of.
277
+ const restyled = uiEntryOf(root, path) === undefined ? '' : importing(note(path, uiFilesOf(root)))
278
278
 
279
279
  // A component with an `await` may draw the app's `await-failed.kay`, which the compiler imports, so its styles go to the page too.
280
280
  const alert = AWAIT_LINE.test(source) ? awaitAlertOf(root, path) : undefined
@@ -61,6 +61,8 @@ export interface TransformOptions {
61
61
  classTable?: ClassTable | undefined
62
62
  // The features of a component its importer's call sites use, as `variants.ts` reads them: part of the cache key, as the source it was specialized from is the same file's.
63
63
  variant?: string | undefined
64
+ // The props the call sites of a variant write, when it knows them all: the component leaves the others out of the rest it forwards.
65
+ writtenProps?: ReadonlySet<string> | undefined
64
66
  // The server's build of an app with Tailwind, which merges a shorthand beside a static `class` while rendering; set by `transformKayCached` from the app's stylesheets.
65
67
  classMerge?: boolean | undefined
66
68
  }
@@ -254,7 +256,7 @@ function compile(source: string, filename: string, options: TransformOptions, si
254
256
  const root = options.root ?? process.cwd()
255
257
  // A page of the routes directory, whose root `@failed` fills a layout outlet rather than being a component's own block.
256
258
  const page = isPageFile(file, options.pages ?? [projectPaths(root).routes]) ? true : undefined
257
- const { tsx, map, diagnostics } = compileKay(source, throughLinks(root, file), { root: options.root, page, includeServer: server, output: server ? 'html' : 'dom', hydratable, twinBuild: isTwin, clientOnly: options.clientOnly, inspect: options.inspect, classTable: options.target === 'dom' ? options.classTable : undefined, classMerge: server ? options.classMerge : undefined, awaitAlert: awaitAlertOf(root, file), importedSignals: signals, namedRefresh: server && namedRefresh(file, root), ui: uiEntryOf(options.root ?? process.cwd(), file) })
259
+ const { tsx, map, diagnostics } = compileKay(source, throughLinks(root, file), { root: options.root, page, includeServer: server, output: server ? 'html' : 'dom', hydratable, twinBuild: isTwin, clientOnly: options.clientOnly, inspect: options.inspect, classTable: options.target === 'dom' ? options.classTable : undefined, classMerge: server ? options.classMerge : undefined, awaitAlert: awaitAlertOf(root, file), importedSignals: signals, namedRefresh: server && namedRefresh(file, root), ui: uiEntryOf(options.root ?? process.cwd(), file), writtenProps: options.writtenProps })
258
260
 
259
261
  if (diagnostics.length > 0)
260
262
  throw new KayCompileError(diagnostics.map(diagnostic => ({ ...diagnostic, file, source })))
@@ -0,0 +1,30 @@
1
+ import { realpathSync } from 'node:fs'
2
+ import { resolve } from 'node:path'
3
+
4
+ // The files extensions contribute `defineUi` entries from, by project root, in the order of the config; set as the config loads. Kept apart from `ui.ts`, which reads them with the compiler, so the config loader a compiled server runs stays free of it.
5
+ const layerFiles = new Map<string, string[]>()
6
+
7
+ // A project's root as the layers are filed under it: through a symlink or not, it is one project.
8
+ function rootKey(root: string): string {
9
+ try {
10
+ return realpathSync(root)
11
+ }
12
+ catch {
13
+ return resolve(root)
14
+ }
15
+ }
16
+
17
+ // The files of the layers of a project, in config order.
18
+ export function layerFilesOf(root: string): string[] {
19
+ return layerFiles.get(rootKey(root)) ?? []
20
+ }
21
+
22
+ // Records the `ui` files of the extensions for a project: absolute, or relative to its root.
23
+ export function setUiLayers(root: string, extensions: readonly { ui?: string | undefined }[] | undefined): void {
24
+ const files = (extensions ?? []).flatMap(({ ui }) => ui === undefined ? [] : [resolve(root, ui)])
25
+
26
+ if (files.length === 0)
27
+ layerFiles.delete(rootKey(root))
28
+ else
29
+ layerFiles.set(rootKey(root), files)
30
+ }
package/src/build/ui.ts CHANGED
@@ -4,11 +4,12 @@ import type { Span } from '../compiler/ast'
4
4
  import type { Node, Program } from '../compiler/estree'
5
5
  import type { UiEntry } from '../runtime/ui'
6
6
  import { readdirSync, readFileSync, realpathSync, statSync } from 'node:fs'
7
- import { basename, dirname, join } from 'node:path'
7
+ import { basename, dirname, join, resolve } from 'node:path'
8
8
  import { componentName, ROUTE_FILES } from '../compiler'
9
9
  import { parseProgram } from '../compiler/estree'
10
10
  import { constBindings, exportedObject, propertiesOf, unwrapped } from '../compiler/object-literal'
11
11
  import { parseKay } from '../compiler/parser'
12
+ import { layerFilesOf } from './ui-layers'
12
13
 
13
14
  // Where an app sets the parts and variants of its components and its libraries'.
14
15
  export const UI_FILE = 'src/ui.ts'
@@ -42,12 +43,15 @@ export interface UiSource {
42
43
  problems: UiProblem[]
43
44
  // The app's components by name and what each name stood for, as of `at`.
44
45
  index?: NameIndex | undefined
46
+ // Where names and relative specifiers resolve from when it is not the folder of `file`: the app's `src/` for an extension's file.
47
+ base?: string | undefined
45
48
  }
46
49
 
47
50
  export const KAY_EXTENSION = /\.kay$/
48
51
  // A key written as a component's name, `Card`, rather than as a specifier.
49
52
  const COMPONENT_NAME = /^[A-Z_$][\w$]*$/i
50
53
  const WORD_BOUNDARY = /(?<=[a-z0-9])(?=[A-Z])/g
54
+ const WHITESPACE = /\s+/
51
55
  // The package whose components a bare name reaches besides the app's own.
52
56
  const UI_LIBRARY = '@kayjs/ui'
53
57
  // What `src/ui.ts` was last read as, by file: it is read for every component the build compiles.
@@ -276,13 +280,17 @@ export function forgetNames(ui: UiSource): void {
276
280
  ui.index = undefined
277
281
  }
278
282
 
283
+ export function baseOf(ui: UiSource): string {
284
+ return ui.base ?? dirname(ui.file)
285
+ }
286
+
279
287
  function nameIndex(ui: UiSource): NameIndex {
280
288
  if (ui.index !== undefined && Date.now() - ui.index.at < INDEX_LIFETIME)
281
289
  return ui.index
282
290
 
283
291
  const app = new Map<string, string[]>()
284
292
 
285
- appComponents(dirname(ui.file), app)
293
+ appComponents(baseOf(ui), app)
286
294
  ui.index = { at: Date.now(), app, matches: new Map() }
287
295
 
288
296
  return ui.index
@@ -299,7 +307,7 @@ export function componentsNamed(ui: UiSource, name: string): string[] {
299
307
  const found = (index.app.get(name) ?? []).map(realOf)
300
308
 
301
309
  try {
302
- const library = realpathSync(Bun.resolveSync(`${UI_LIBRARY}/${name.replace(WORD_BOUNDARY, '-').toLowerCase()}.kay`, dirname(ui.file)))
310
+ const library = realpathSync(Bun.resolveSync(`${UI_LIBRARY}/${name.replace(WORD_BOUNDARY, '-').toLowerCase()}.kay`, baseOf(ui)))
303
311
 
304
312
  if (componentName(library) === name && !found.includes(library))
305
313
  found.push(library)
@@ -337,14 +345,14 @@ export function componentFile(ui: UiSource, component: UiComponent): string | un
337
345
  return component.file
338
346
 
339
347
  try {
340
- component.file = realpathSync(Bun.resolveSync(component.specifier, dirname(ui.file)))
348
+ component.file = realpathSync(Bun.resolveSync(component.specifier, baseOf(ui)))
341
349
  }
342
350
  catch {}
343
351
 
344
352
  return component.file
345
353
  }
346
354
 
347
- function readUi(file: string): UiSource | undefined {
355
+ function readUi(file: string, base?: string): UiSource | undefined {
348
356
  let source: string
349
357
 
350
358
  try {
@@ -361,7 +369,7 @@ function readUi(file: string): UiSource | undefined {
361
369
  program = parseProgram(source).program
362
370
  }
363
371
  catch (error) {
364
- return { file, source, components: [], problems: [{ start: 0, end: 0, message: `src/ui.ts does not parse: ${error instanceof Error ? error.message : String(error)}` }] }
372
+ return { file, source, base, components: [], problems: [{ start: 0, end: 0, message: `src/ui.ts does not parse: ${error instanceof Error ? error.message : String(error)}` }] }
365
373
  }
366
374
 
367
375
  const config = exported(program)
@@ -379,7 +387,7 @@ function readUi(file: string): UiSource | undefined {
379
387
  })
380
388
  }
381
389
 
382
- return { file, source, components, problems }
390
+ return { file, source, base, components, problems }
383
391
  }
384
392
 
385
393
  // The project's `src/ui.ts` as it is written, read again only when the file changed; none when the project has none.
@@ -406,11 +414,91 @@ export function uiOf(root: string): UiSource | undefined {
406
414
  return ui
407
415
  }
408
416
 
409
- // What `src/ui.ts` sets for a component file, as Bun loads it; none for a component it does not name.
417
+ const layerReads = new Map<string, { stamp: string, ui: UiSource | undefined }>()
418
+
419
+ // What the extensions' `ui` files say, in config order, each read as `src/ui.ts` is and resolving names against the app; a file that does not exist is skipped.
420
+ export function uiLayersOf(root: string): UiSource[] {
421
+ const base = join(resolve(root), 'src')
422
+ const found: UiSource[] = []
423
+
424
+ for (const file of layerFilesOf(root)) {
425
+ const stat = statSync(file, { throwIfNoEntry: false })
426
+ const key = `${base}\0${file}`
427
+
428
+ if (stat === undefined) {
429
+ layerReads.delete(key)
430
+
431
+ continue
432
+ }
433
+
434
+ const stamp = `${stat.mtimeMs}:${stat.size}`
435
+ let kept = layerReads.get(key)
436
+
437
+ if (kept?.stamp !== stamp)
438
+ layerReads.set(key, kept = { stamp, ui: readUi(file, base) })
439
+
440
+ if (kept.ui !== undefined)
441
+ found.push(kept.ui)
442
+ }
443
+
444
+ return found
445
+ }
446
+
447
+ // The classes the extensions' `ui` files write, for Tailwind to make rules of: a file outside the project, in `node_modules`, is not one it scans on its own.
448
+ export function uiLayerClasses(root: string): string[] {
449
+ const words = (classes: string | Record<string, string>): string[] => Object.values(typeof classes === 'string' ? { root: classes } : classes).flatMap(text => text.split(WHITESPACE))
450
+ const entries = uiLayersOf(root).flatMap(({ components }) => components.map(({ entry }) => entry))
451
+ const variants = entries.flatMap(({ variants }) => Object.values(variants ?? {}).flatMap(values => Object.values(values).flatMap(words)))
452
+
453
+ return [...entries.flatMap(({ parts }) => parts === undefined ? [] : words(parts)), ...variants].filter(word => word !== '')
454
+ }
455
+
456
+ // Where classes of components may be set from: the extensions' `ui` files and the app's `src/ui.ts`, whether they exist now or not, for a rebuild when one is written or removed.
457
+ export function uiPathsOf(root: string): string[] {
458
+ return [...layerFilesOf(root), join(root, UI_FILE)]
459
+ }
460
+
461
+ // The `ui` files of the project's extensions, as the config listed them.
462
+ export function uiLayerPathsOf(root: string): string[] {
463
+ return layerFilesOf(root)
464
+ }
465
+
466
+ // Every file that sets a component's classes now: the extensions' `ui` files, then the app's `src/ui.ts` when there is one.
467
+ export function uiFilesOf(root: string): string[] {
468
+ return uiPathsOf(root).filter(file => statSync(file, { throwIfNoEntry: false }) !== undefined)
469
+ }
470
+
471
+ function partsOf(parts: UiEntry['parts']): Record<string, string> {
472
+ return typeof parts === 'string' ? { root: parts } : { ...parts }
473
+ }
474
+
475
+ // `over` laid on `under`: a part or a variant value it sets replaces the one under it whole, so the app's classes never fight an extension's.
476
+ function mergeEntries(under: UiEntry, over: UiEntry): UiEntry {
477
+ const merged: UiEntry = {}
478
+
479
+ if (under.parts !== undefined || over.parts !== undefined)
480
+ merged.parts = { ...partsOf(under.parts), ...partsOf(over.parts) }
481
+
482
+ if (under.variants !== undefined || over.variants !== undefined) {
483
+ const variants = record<Record<string, string | Record<string, string>>>()
484
+
485
+ for (const source of [under.variants ?? {}, over.variants ?? {}]) {
486
+ for (const [name, values] of Object.entries(source))
487
+ variants[name] = Object.assign(record<string | Record<string, string>>(), variants[name], values)
488
+ }
489
+
490
+ merged.variants = variants
491
+ }
492
+
493
+ return merged
494
+ }
495
+
496
+ // What `src/ui.ts` and the extensions' `ui` files set for a component file, as Bun loads it, the app's over the extensions' and a later extension's over an earlier one's; none for a component none of them names.
410
497
  export function uiEntryOf(root: string, file: string): UiEntry | undefined {
411
- const ui = uiOf(root)
498
+ const app = uiOf(root)
499
+ const sources = [...uiLayersOf(root), ...app === undefined ? [] : [app]]
412
500
 
413
- if (ui === undefined || ui.components.length === 0)
501
+ if (sources.every(({ components }) => components.length === 0))
414
502
  return undefined
415
503
 
416
504
  let real = file
@@ -420,7 +508,16 @@ export function uiEntryOf(root: string, file: string): UiEntry | undefined {
420
508
  }
421
509
  catch {}
422
510
 
423
- return ui.components.findLast(component => componentFile(ui, component) === real)?.entry
511
+ let entry: UiEntry | undefined
512
+
513
+ for (const ui of sources) {
514
+ const found = ui.components.findLast(component => componentFile(ui, component) === real)?.entry
515
+
516
+ if (found !== undefined)
517
+ entry = entry === undefined ? found : mergeEntries(entry, found)
518
+ }
519
+
520
+ return entry
424
521
  }
425
522
 
426
523
  // Whatever `src/ui.ts` changes in a component's compiled output, as text for a cache key.