@kayjs/kay 1.109.0 → 1.111.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 (199) hide show
  1. package/dist/eslint.js +488 -75
  2. package/editors/zed/extension.toml +2 -2
  3. package/llms/actions-from-islands.md +1 -1
  4. package/llms/build-and-start.md +1 -1
  5. package/llms/checks.md +1 -0
  6. package/llms/component-libraries.md +1 -1
  7. package/llms/components.md +1 -1
  8. package/llms/deprecated-lints.md +1 -1
  9. package/llms/dev-tool.md +1 -1
  10. package/llms/effects.md +1 -0
  11. package/llms/head.md +1 -1
  12. package/llms/images.md +2 -0
  13. package/llms/island-and-form-lints.md +2 -1
  14. package/llms/islands-lazy-components.md +23 -0
  15. package/llms/islands.md +4 -14
  16. package/llms/lints.md +1 -1
  17. package/llms/live-values.md +1 -1
  18. package/llms/navigation-from-code.md +1 -1
  19. package/llms/navigation.md +5 -3
  20. package/llms/performance-lints.md +1 -0
  21. package/llms/prerendering.md +1 -1
  22. package/llms/project-new-and-add.md +1 -1
  23. package/llms/project.md +1 -1
  24. package/llms/templates-elements-slots-snippets.md +4 -4
  25. package/llms/upgrading-archive.md +121 -42
  26. package/llms/upgrading.md +17 -133
  27. package/llms/whats-new-archive.md +31 -31
  28. package/llms/whats-new.md +45 -30
  29. package/llms.txt +3 -2
  30. package/package.json +11 -11
  31. package/src/build/client.ts +10 -8
  32. package/src/build/island-images.ts +277 -0
  33. package/src/build/pipeline.ts +10 -4
  34. package/src/build/static.ts +99 -24
  35. package/src/build/variants.ts +132 -18
  36. package/src/check/env-types.ts +1 -1
  37. package/src/check/project.ts +4 -0
  38. package/src/check/schema-builders.ts +230 -26
  39. package/src/check/shadow-types.ts +3 -3
  40. package/src/commands/upgrade.ts +2 -1
  41. package/src/compiler/allow-comments.ts +38 -2
  42. package/src/compiler/ast.ts +4 -4
  43. package/src/compiler/codegen.ts +4 -4
  44. package/src/compiler/deprecated-lints-1-106.ts +2 -2
  45. package/src/compiler/dom.ts +4 -3
  46. package/src/compiler/hand-parts.ts +36 -8
  47. package/src/compiler/handed-data.ts +15 -0
  48. package/src/compiler/helper-imports.ts +2 -2
  49. package/src/compiler/html.ts +3 -7
  50. package/src/compiler/index.ts +7 -4
  51. package/src/compiler/island-arguments.ts +9 -0
  52. package/src/compiler/island-lints.ts +7 -0
  53. package/src/compiler/items.ts +174 -0
  54. package/src/compiler/jsx.ts +10 -11
  55. package/src/compiler/kay-exports.ts +1 -0
  56. package/src/compiler/lints.ts +6 -7
  57. package/src/compiler/markup.ts +26 -24
  58. package/src/compiler/names.ts +1 -1
  59. package/src/compiler/removed-lints.ts +90 -0
  60. package/src/compiler/rewrite-types.ts +2 -0
  61. package/src/compiler/rewrite.ts +4 -2
  62. package/src/compiler/route-lints.ts +8 -0
  63. package/src/compiler/signal-from-prop.ts +141 -0
  64. package/src/compiler/template-reads.ts +16 -0
  65. package/src/compiler/template-walk.ts +2 -1
  66. package/src/config-shape.ts +4 -1
  67. package/src/config.ts +2 -2
  68. package/src/new.ts +16 -4
  69. package/src/project.ts +3 -3
  70. package/src/runtime/await.server.ts +4 -2
  71. package/src/runtime/checks.ts +14 -2
  72. package/src/runtime/client.ts +5 -9
  73. package/src/runtime/dev-tab-env.ts +28 -3
  74. package/src/runtime/dom-loop.ts +2 -4
  75. package/src/runtime/dom.ts +2 -2
  76. package/src/runtime/html.ts +53 -7
  77. package/src/runtime/image.ts +24 -23
  78. package/src/runtime/index.ts +2 -2
  79. package/src/runtime/island.server.ts +41 -11
  80. package/src/runtime/navigate.ts +14 -0
  81. package/src/runtime/navigation.ts +9 -1
  82. package/src/runtime/page-swap.ts +6 -3
  83. package/src/runtime/reactive.ts +72 -0
  84. package/src/runtime/row-key.ts +4 -0
  85. package/src/runtime/swap-flight.ts +10 -10
  86. package/src/runtime/swap-focus.ts +56 -9
  87. package/src/runtime/swap-kept.ts +97 -29
  88. package/src/runtime/swap-morph.ts +49 -9
  89. package/src/runtime/text-hash.ts +17 -0
  90. package/src/runtime/uid.server.ts +6 -4
  91. package/src/runtime/values.ts +12 -0
  92. package/src/server/client.ts +3 -0
  93. package/src/server/dev.ts +2 -0
  94. package/src/server/image.ts +1 -1
  95. package/src/server/kept-exports.ts +1 -0
  96. package/src/server/render-document.ts +11 -8
  97. package/src/server/render.ts +3 -3
  98. package/types/build/client.d.ts +6 -0
  99. package/types/build/client.d.ts.map +1 -1
  100. package/types/build/island-images.d.ts +45 -0
  101. package/types/build/island-images.d.ts.map +1 -0
  102. package/types/build/pipeline.d.ts.map +1 -1
  103. package/types/build/static.d.ts.map +1 -1
  104. package/types/build/variants.d.ts +9 -1
  105. package/types/build/variants.d.ts.map +1 -1
  106. package/types/check/project.d.ts.map +1 -1
  107. package/types/check/schema-builders.d.ts.map +1 -1
  108. package/types/commands/upgrade.d.ts.map +1 -1
  109. package/types/compiler/allow-comments.d.ts +2 -0
  110. package/types/compiler/allow-comments.d.ts.map +1 -1
  111. package/types/compiler/ast.d.ts +1 -1
  112. package/types/compiler/ast.d.ts.map +1 -1
  113. package/types/compiler/deprecated-lints-1-106.d.ts +2 -2
  114. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
  115. package/types/compiler/deprecated-lints.d.ts +2 -2
  116. package/types/compiler/dom.d.ts.map +1 -1
  117. package/types/compiler/hand-parts.d.ts +6 -3
  118. package/types/compiler/hand-parts.d.ts.map +1 -1
  119. package/types/compiler/handed-data.d.ts +5 -0
  120. package/types/compiler/handed-data.d.ts.map +1 -0
  121. package/types/compiler/html.d.ts.map +1 -1
  122. package/types/compiler/index.d.ts.map +1 -1
  123. package/types/compiler/island-arguments.d.ts +5 -0
  124. package/types/compiler/island-arguments.d.ts.map +1 -1
  125. package/types/compiler/island-lints.d.ts +7 -0
  126. package/types/compiler/island-lints.d.ts.map +1 -1
  127. package/types/compiler/items.d.ts +14 -0
  128. package/types/compiler/items.d.ts.map +1 -1
  129. package/types/compiler/jsx.d.ts.map +1 -1
  130. package/types/compiler/kay-exports.d.ts.map +1 -1
  131. package/types/compiler/lints.d.ts +20 -5
  132. package/types/compiler/lints.d.ts.map +1 -1
  133. package/types/compiler/markup.d.ts +3 -1
  134. package/types/compiler/markup.d.ts.map +1 -1
  135. package/types/compiler/names.d.ts.map +1 -1
  136. package/types/compiler/removed-lints.d.ts +3 -0
  137. package/types/compiler/removed-lints.d.ts.map +1 -0
  138. package/types/compiler/rewrite-types.d.ts +1 -0
  139. package/types/compiler/rewrite-types.d.ts.map +1 -1
  140. package/types/compiler/route-lints.d.ts +8 -0
  141. package/types/compiler/route-lints.d.ts.map +1 -1
  142. package/types/compiler/signal-from-prop.d.ts +4 -0
  143. package/types/compiler/signal-from-prop.d.ts.map +1 -0
  144. package/types/compiler/template-reads.d.ts +1 -0
  145. package/types/compiler/template-reads.d.ts.map +1 -1
  146. package/types/compiler/template-walk.d.ts.map +1 -1
  147. package/types/config-shape.d.ts.map +1 -1
  148. package/types/config.d.ts +3 -1
  149. package/types/config.d.ts.map +1 -1
  150. package/types/new.d.ts.map +1 -1
  151. package/types/project.d.ts +2 -2
  152. package/types/project.d.ts.map +1 -1
  153. package/types/runtime/await.server.d.ts.map +1 -1
  154. package/types/runtime/checks.d.ts +8 -2
  155. package/types/runtime/checks.d.ts.map +1 -1
  156. package/types/runtime/client.d.ts.map +1 -1
  157. package/types/runtime/dev-tab-env.d.ts.map +1 -1
  158. package/types/runtime/dom-loop.d.ts +2 -1
  159. package/types/runtime/dom-loop.d.ts.map +1 -1
  160. package/types/runtime/dom.d.ts +2 -2
  161. package/types/runtime/dom.d.ts.map +1 -1
  162. package/types/runtime/html.d.ts +6 -3
  163. package/types/runtime/html.d.ts.map +1 -1
  164. package/types/runtime/image.d.ts.map +1 -1
  165. package/types/runtime/index.d.ts +2 -2
  166. package/types/runtime/index.d.ts.map +1 -1
  167. package/types/runtime/island.server.d.ts +1 -0
  168. package/types/runtime/island.server.d.ts.map +1 -1
  169. package/types/runtime/navigate.d.ts.map +1 -1
  170. package/types/runtime/navigation.d.ts +4 -0
  171. package/types/runtime/navigation.d.ts.map +1 -1
  172. package/types/runtime/reactive.d.ts +5 -0
  173. package/types/runtime/reactive.d.ts.map +1 -1
  174. package/types/runtime/row-key.d.ts +2 -0
  175. package/types/runtime/row-key.d.ts.map +1 -0
  176. package/types/runtime/swap-flight.d.ts +1 -1
  177. package/types/runtime/swap-flight.d.ts.map +1 -1
  178. package/types/runtime/swap-focus.d.ts +2 -0
  179. package/types/runtime/swap-focus.d.ts.map +1 -1
  180. package/types/runtime/swap-kept.d.ts.map +1 -1
  181. package/types/runtime/swap-morph.d.ts.map +1 -1
  182. package/types/runtime/text-hash.d.ts +2 -0
  183. package/types/runtime/text-hash.d.ts.map +1 -0
  184. package/types/runtime/uid.server.d.ts.map +1 -1
  185. package/types/runtime/values.d.ts +4 -0
  186. package/types/runtime/values.d.ts.map +1 -1
  187. package/types/server/app-stages.d.ts +3 -1
  188. package/types/server/app-stages.d.ts.map +1 -1
  189. package/types/server/app.d.ts +3 -1
  190. package/types/server/app.d.ts.map +1 -1
  191. package/types/server/client.d.ts +2 -0
  192. package/types/server/client.d.ts.map +1 -1
  193. package/types/server/dev.d.ts +1 -0
  194. package/types/server/dev.d.ts.map +1 -1
  195. package/types/server/kept-exports.d.ts.map +1 -1
  196. package/types/server/render-document.d.ts +1 -1
  197. package/types/server/render-document.d.ts.map +1 -1
  198. package/types/server/render.d.ts +2 -2
  199. package/types/server/render.d.ts.map +1 -1
package/llms/whats-new.md CHANGED
@@ -2,33 +2,48 @@
2
2
 
3
3
  What each release of kay and its libraries adds, newest first, each feature with where it is documented. kay and its libraries share one version, so one section covers them all; what a release breaks is in [Upgrading](upgrading.md).
4
4
 
5
- ## 1.109.0
6
-
7
- - An endpoint file (`src/routes/a.txt.ts`) no longer stops an app with a root `_guard.ts` and an extension layout that reaches files, as kayjs-auth's, from starting or passing `kay check` (`the layouts of the extensions are placed before what the pages reach was opened`): the endpoints are scanned after what the pages reach is open, as the pages are.
8
- - `kay env` and `kay check` list the variables of a `defineEnv` module that kay.config.ts imports, as for any other module, so a variable required in production and missing from `.env.example` is reported ([environment](environment.md)).
9
- - kayjs-ui's centred modal `Dialog` is as tall as its content again, capped at the viewport less 2rem (`size="full"` still fills it), and the opened dialog box no longer draws a browser focus ring round itself (a regression of the 1.105 placement change).
10
- - An island reading a `queryParam` follows a swap that changes only the query, a link `?x=1` or a component's `param=` navigation, and Back and Forward, whatever its render mode: a signal made outside a component and shared by islands reads the address again after each swap and traversal, as one in a component does ([islands](islands.md#keep-a-filter-in-the-url)).
11
- - On a static build or a `prerender` page, an island reading a `queryParam` is drawn again from the address when the page is opened with a query, instead of reporting `did not match its server markup`; the build warns naming each page holding one ([prerendering](prerendering.md#static-export)).
12
- - `site.call(action.with(fields), input)` and `site.submit(action.with(fields), fields, { from: '/path' })` send the fields `with` fixes, as an island's call and a form's post do, instead of answering 422 for a missing field ([testing](testing.md)).
13
-
14
- ## 1.108.0
15
-
16
- - kayjs-ui's `BarChart` leaves `goals` out of an island that never writes them, a `ConfirmDelete` leaves out the inline pair (`ask`), the trigger looks and `details` it is never given, and the confirm words no longer carry the questions' queue: a plain `ConfirmDelete` island holds 3.1 KB less of kayjs-ui, a `BarChart` 1.6 KB, and a `Dialog`'s discard question loads when first asked, 1.2 KB less ([kayjs-ui](../../ui/llms/table.md))
17
- - An island ships only the kayjs-ui icons it can draw: with kayjs-ui in the app's dependencies the default registry is cut to the slots the project writes as strings, about 8 KB minified off an island drawing a Dialog, and a slot named from a variable in the app keeps it whole; the app's own icon settings stay whole ([kayjs-ui setup](../../ui/llms/setup.md))
18
- - The code that runs an action call (queue, timeout, retries, the post and what follows its answer) loads with the first call instead of with the first island holding an action: a page of hubble's with a table of rows and dialogs loads 1.8 KB gzip less ([islands](islands.md#the-action-caller))
19
- - A component of an island that leaves a feature out (kayjs-ui's `Table` with no filter, selection, paging or detail rows) no longer ships the markers and the effects of the blocks it never draws, and an `aria-` or `data-` attribute of such a feature is not bound: a plain `Table` island carries 1.7 KB less of kayjs-ui's code, 9.9 KB in all, as any component declaring `uses()` features carries less.
20
- - An extension's own islands, as kayjs-ui's toaster, tooltip host and confirm host, hydrate when the library resolves outside the project root (a workspace link, or a folder above it) and the app lists no dependency on it ([component libraries](component-libraries.md)).
21
-
22
- ## 1.107.0
23
-
24
- - `--- script` as a file's first fence is a compile error naming `---`, and the `deprecated-script-fence` lint is gone ([components](components.md)).
25
- - `kay new` pins kay with `~` through 1.x and with `^` from 2.0.0, when a breaking change becomes a major ([Upgrading](upgrading.md))
26
- - A component an island draws only where it may not render at first paint (inside an `if`, a `match` case, `@failed`, or the body of a closed `Dialog` or `FormDialog`) loads when that branch first draws, with nothing to declare: the page preloads what the server drew, a visitor reaching for the island loads the rest ahead, and a failed chunk is retried and reported; the code that posts an action call loads with its first call, retried after 1 s and 3 s when the load fails ([islands](islands.md#components-that-load-when-they-first-draw)).
27
- - An island whose closed forms and dialogs hold words that are also component names loads less: a name in a string or a comment no longer keeps a component eager, and `Form`, `FormDialog` and `SaveForm` load their sending code on the first send. An island with a table, a closed form dialog and a select in it sheds 4.6 KB gzip of eager JS ([islands](islands.md))
28
- - `action({ input, ...options }, handler)`: an action takes its options first with its input in them, as an API route does; the old argument order works until 2.0 and `kay upgrade` rewrites it ([actions](actions.md))
29
- - One `validate(schema, value, { source })` reads every input of an app, an action's, an API route's, a socket's and `defineEnv`'s, and refuses with `{ errors: [{ path, key, params, message }], status: 422 }` worded in the request's locale; a JSON body is never coerced, and a Standard Schema validator (Zod, ArkType) is accepted where a schema is ([schemas](schemas.md))
30
- - An island validates with the same schema: `validate(schema, value, { source })` from `kay` is the server's `validate` in the browser (JSON Schema built by the browser's `s`, a Standard Schema validator called as it is), its code a chunk the first call loads ([Schemas](schemas.md#schemas)).
31
- - `kay check` names a Standard Schema validator with no `~standard.jsonSchema` (`schema-without-json-schema`) where an action's `input` or an API route's `body`, `query`, `params`, `headers` or `cookie` takes it, in `.ts` modules and `.kay` fences ([Schemas](schemas.md#schemas)).
32
- - kayjs-ui's `Table` draws its failure row's retry as a plain button with a `retry` part, so an island holding a plain Table ships 6 KB less (the `Button`, its busy state and the icon set stay out unless the page uses them) ([restyle](https://git.kaynooo.fr/kaynooo/kayjs/src/branch/main/packages/ui/llms/restyle.md)).
33
-
34
- Releases before 1.107 are in [What's new, older releases](whats-new-archive.md).
5
+ ## 1.111.0
6
+
7
+ - kay and its libraries need Bun 1.4.5, a security release for HTTP/3, HTTP/1.1, TLS, DNS and Zstandard, and refuse 1.4.4 with the command that updates it ([project](project.md), [upgrading](upgrading.md)).
8
+ - A refresh in place no longer jumps the window to the end of the page in Chrome when it drops or moves rows around the one in view (an action posted from a long list of row forms): the swap turns scroll anchoring off while it morphs and keeps the scroll, and a focused field the refresh removed gives the focus to the field of that name now at its place rather than the first of the page, without the text typed into it meanwhile, which goes nowhere (a row is told by its form's `id`, or its action and hidden fields, else its nearest ancestor's `id`), and an island's field a refresh renders afresh gets its typed text back at its own place, not the first field of its name. See [navigation](navigation.md).
9
+ - A page that is an island (a closure passed to an interactive component) sends only the `--- server` values its script or template read as props, so a list the fence only reduces no longer weighs the page down ([Props to an island](islands.md#props-to-an-island)).
10
+ - The dev tool no longer requests `/_kay/env.js` on an app with no `s.Public` field, which logged a 404 in the browser console on every page: the page's request block says whether the route exists, so the Env tab asks for nothing and still says the app sends no public env ([dev tool](dev-tool.md)).
11
+ - A form in a file with a loop over a pattern (`for [key, value] of entries`, `for { id } of rows`) reads its own action again: its `error` and `pending` lines, field values, constraints and messages no longer fall back to the form of the function, where a bare `error` threw `KayFormHere is not defined` and the page answered 500.
12
+ - kay's `@kaynooo/pg-orm` peer range takes 9.x beside 7 and 8, and kayjs-ui, kayjs-cms, kayjs-mail, kayjs-ai and kayjs-auth ask for `@kaynooo/utils` `^3.2.0`, which the `kay check` of a lockfile on an older 3.x could not resolve ([component libraries](component-libraries.md)).
13
+ - kayjs-mail's confirmation and unsubscribe pages are set in the font and colours of the app's mails with a flat button, in place of a bare `system-ui` column, and the "confirmed" and "unsubscribed" answers state their title alone, so `mail.list.page.confirmed` and `mail.list.page.unsubscribed` are no longer read; a mail's field labels are sentence case and the dev outbox names a real font ([mailing lists](../../mail/llms/mailing-list.md)).
14
+ - kayjs-ai's Chat is flat (no shadow on the panel or the launcher unless `--kai-chat-shadow` sets one), waits behind a still `Thinking…` line, wraps its suggestions in a squared button, builds its controls from kayjs-ui's `Button` and `ConfirmDelete`, and shows a held tool call by its label and one line of its input, with calls counted `×2` ([chat](../../ai/llms/chat.md)).
15
+ - kayjs-mail's confirmation and unsubscribe pages follow the `settings` of the app's mails (font stack, colours, radius, so a site that sets them gets its own look) with a flat button, in place of a centred `system-ui` column, and the "confirmed" and "unsubscribed" answers state their title alone, so `mail.list.page.confirmed` and `mail.list.page.unsubscribed` are no longer read; a mail's field labels are sentence case and the dev outbox names a real font ([mailing lists](../../mail/llms/mailing-list.md)).
16
+ - kayjs-ui's fields draw their text at 16px on a coarse pointer or in a window under 40rem, so iOS no longer zooms the page in on one; a wide window with a mouse keeps the compact sizes ([TextInput](/ui/text-input)).
17
+ - kayjs-ui's `TabNav`, `Tabs` and `Segmented` fade out at the edge of a strip that scrolls, so a clipped tab reads as one to scroll to, and `Tabs` opens with its shown tab centred as `TabNav` does ([TabNav](/ui/tab-nav)).
18
+ - A kayjs-ui `Table` stacked as cards on a phone names its row of sort buttons with the words `Sort by` (`ui.table.sortBy`) instead of showing bare column names, and draws no per-card label when it has one column ([Table](/ui/table)).
19
+ - `kay new .` scaffolds in a fresh clone holding only `.git` and what a new forge repo carries (`README.md`, a licence, `.gitignore`, `.gitattributes`), keeping them and the `origin`, and a folder with anything else is refused naming the entries in the way ([kay new](project-new-and-add.md)).
20
+ - `kay build --static` writes the site to a folder beside the output and renames it over `dist` once complete, so a server pointed at `dist` never answers 404 during a rebuild and a failed export leaves the last one untouched (a folder git does not ignore is still removed first, as Tailwind would scan it) ([static export](prerendering.md#static-export)).
21
+ - A block drawn per item keeps its nodes and focus across a same-key replacement in kayjs-ui's `TreeView` (`@row`, `@actions`), `Steps` (`@step`), `VirtualList` (`@item`) and `Toaster` (`@toast`), `RelationGraph` (`@middle`) and `MapView` (`@popup`), in a `slot x(item)` inside a form, and in a block whose other arguments, a carousel's index for one, change; an island in an `await` block of a keyed row keeps the row's key as its identity ([slots](templates-elements-slots-snippets.md), [effects](effects.md)).
22
+ - On a static export the build reads the `img` and `image()` calls of the islands, so a crop, a quality or a small width only a browser-rendered island draws has its files, and a remote image an island names as a literal URL is downloaded and linked as files; any other remote image keeps its own address in the browser, and `kay build --static` warns of it with `static-remote-image` ([images](images.md)).
23
+ - On a static export an island that draws an imported image in the browser links the variant files the build wrote, as the server HTML does, instead of the image route, which a static host answers with a 404 ([images](images.md)).
24
+ - `kay check` resolves the imports of a library's own components from where Bun's isolated linker put the library's dependencies, so an app listing `@kayjs/ui` alone no longer lists `@kaynooo/utils` for the check to pass ([component libraries](component-libraries.md)).
25
+ - `kay check` reports an `auth()` whose users go through `@kaynooo/pg-orm`, a SQLite file by default, when the app has not installed it, with `bun add @kaynooo/pg-orm`, where the server stopped only at start ([checks](checks.md#peer-packages)).
26
+ - `kay check --fix` of `deprecated-schema-builders` keeps an unbounded `s.String()` unbounded, writing `max: Number.MAX_SAFE_INTEGER`, except in an action's input and an API route's `body`, which capped it at 10,000 characters already ([deprecated lints](deprecated-lints.md)).
27
+ - A `head` entry in `kay.config.ts` with `children` beside `props` is refused at load and by `kay check`, naming `props.children`, where it used to render an empty tag; the config type refuses it too ([Head](head.md)).
28
+ - kayjs-ui's `SiteNav`, `SideNav` and `TabNav` no longer mark every `/#section` link as the current page on that page: a link with a hash is current only when `current` carries the same hash ([TabNav](/ui/tab-nav)).
29
+ - The count badge of kayjs-ui's `TabNav`, `Tabs`, `SideNav` and `SiteNav` has the vertical padding of a `Badge`, so its number no longer touches the pill's top and bottom ([TabNav](/ui/tab-nav)).
30
+ - A block's item stays the real item when it follows a replacement under the same key: the `row` of a Table's `@cell` and `@detail` is the object in `rows`, so `rows.indexOf(row)` and `row === selected` hold in it and a class instance with private fields works, while its nodes and a field's focus still stay (the 1.110 view of the row, compared by key, is gone). A block or a snippet reads its plain parameters where they are used, `followed(read, draw)` from `kay` draws a call once for the item under its key, and `slot name(item, index)` called with names or paths does it for its first argument, so Tabs, TabNav, Breadcrumb, SiteNav, SideNav and Carousel keep the nodes of the entry blocks across a refresh as the other item blocks do ([templates](templates-elements-slots-snippets.md), [effects](effects.md), [Table](../../ui/llms/table.md)).
31
+
32
+ - An island drawn in a keyed `for` is paired by the loop's key across a refresh, with no `id` or `persist` on it, so deleting the first row leaves each other island its own state; the server writes the key as the island's `data-key`. A `details` of the first load takes the server's value as its baseline, as one a swap brings does ([Navigation](navigation.md#islands-kept-across-pages)).
33
+
34
+ ## 1.110.0
35
+
36
+ - kayjs-ui's `Checkbox`, `RadioGroup` choices and `Toggle` rows are at least 24px tall, the tap target of WCAG 2.5.8, whatever the label's line height.
37
+ - kayjs-ui's `Segmented` keeps each option's label on one line and scrolls sideways inside its container when the options do not fit, and a `Badge` wraps its text between words inside its parent, instead of overflowing it.
38
+ - kayjs-ui's `BarChart` draws each shown x-axis label in a box as wide as its text, centred on its column, and no box for a column with no label, so a chart of many columns no longer has labels running past their own box.
39
+ - A task list item (`- [ ] a`) inside `.kui-prose`, such as a MarkdownEditor preview, shows no bullet and a drawn box in the accent hanging where the bullet was, not the browser's dimmed checkbox; the space skin draws it too.
40
+ - A component listing `island({ interactive })` takes a function or a block with parameters from a use turning none of those props on, so a page's `Table` with an `@cell(row, column)` block is plain markup with the block rendered by the server, and no longer an `island-prop` error ([islands](islands.md#make-a-component-interactive)).
41
+ - A Table whose `rows` is replaced by copies under the same `rowKey` keeps the nodes its `@cell` and `@detail` blocks drew, so a field in a cell keeps the focus while it is edited; the block's `row` is a view of the current row, read by its fields where it is used, so compare rows by their key, not by identity (`rows.indexOf(row)` is `-1`); Masonry, AvatarGroup, BellInbox, ChipGroup, Segmented, RadioGroup, MultiSelect, Combobox, DescriptionList, AppSwitcher and AudioPlayer draw their item blocks the same way ([Table](../../ui/llms/table.md)).
42
+ - A swap keeps what the visitor changed and applies what the server changed: an island stays on a refresh and takes its new props in place, its state kept, as do the islands a layout renders across a visit to a page with the same layout; a static `details` the visitor opened and a field they typed in keep their state through a refresh, in production as in `kay dev`, unless the server changed that value ([Navigation](navigation.md#islands-kept-across-pages), [Actions from islands](actions-from-islands.md)).
43
+ - `signal-from-prop` (a warning in the `islands` group) flags a `signal(light)` seeded from a prop and never written, which keeps the first value now that an island stays through a refresh, and `kay check --fix` writes `linked(() => light)` ([lints](island-and-form-lints.md)).
44
+ - kayjs-ui's `Dialog` closes with a plain button with a `close` part, so an island holding a Dialog no longer ships `IconButton` and the icon set for it (a plain Dialog island is 7 KB smaller in an app that has no other icon button), and it leaves out `level`, `header`, `handle`, `trigger` and `closeHref` when no call site of the project writes them; the close draws kayjs-ui's `x` icon, and a `close` block replaces it ([restyle](https://git.kaynooo.fr/kaynooo/kayjs/src/branch/main/packages/ui/llms/restyle.md)).
45
+ - A kayjs-ui component handing its `...rest` props, or a prop it takes by name, on to a component with optional features (`FormDialog`, `SidePanel` and `ConfirmHost` into `Dialog`) counts by what its own callers write, no longer as every prop, so an island leaves out the features no call site uses.
46
+ - A part handed on to a component (`Icon(part="spinner")`) writes its `class` and `parts` as one source, about 45 bytes less in each island per hand-off.
47
+ - A `lints` entry in kay.config.ts naming a lint kay has removed (`'deprecated-package-names': 'allow'`) is accepted by the config type and warned about by `kay check`, instead of refused; `kay check --fix` writes `s.Union(Object.keys(R).map(key => s.Literal(key)))` as `s.enum(R)` and leaves any other mapped `s.Union` to the app, see [Upgrading](upgrading.md). The same fix writes `max: Number.MAX_SAFE_INTEGER` on an `s.Array` and `extra: 'strip'` on an `s.Object`, so a rewritten list or object keeps the old behaviour; an app rewritten before has lists capped at 1,000 and objects that refuse extra keys, [how to check](upgrading-archive.md).
48
+
49
+ Releases before 1.110 are in [What's new, older releases](whats-new-archive.md).
package/llms.txt CHANGED
@@ -46,6 +46,7 @@ To build a site, read [Build a site](llms/site.md) first, then the topics below;
46
46
  - [Images and icons](llms/images.md): imported and responsive images, share cards, icons
47
47
  - [Runtime and remote images](llms/images-runtime-and-remote.md): uploaded and remote images
48
48
  - [Islands](llms/islands.md): props, hydration
49
+ - [Islands: lazy components](llms/islands-lazy-components.md): components an island loads when first drawn
49
50
  - [Islands: state to ids](llms/islands-state-to-ids.md): shared state, transitions, context
50
51
  - [Browser-only code](llms/browser-only.md): browser globals on the server, server globals in the browser
51
52
  - [Navigation](llms/navigation.md): in-place navigation, islands kept across pages
@@ -117,9 +118,9 @@ To build a site, read [Build a site](llms/site.md) first, then the topics below;
117
118
  - [Proxies and security headers](llms/proxy-and-security.md): headers, CSP, compression
118
119
  - [Upgrading](llms/upgrading.md): what each recent minor breaks, what an app changes
119
120
  - [Upgrading to 1.105, config](llms/upgrading-1-105-config.md): config and hooks
120
- - [Upgrading, older](llms/upgrading-archive.md): the minors before 1.106
121
+ - [Upgrading, older](llms/upgrading-archive.md): the minors before 1.110
121
122
  - [What's new](llms/whats-new.md): what each recent release adds
122
- - [What's new, older](llms/whats-new-archive.md): the releases before 1.107
123
+ - [What's new, older](llms/whats-new-archive.md): the releases before 1.110
123
124
  - [Privacy and personal data](llms/privacy.md): what kay keeps, erasing a person
124
125
  - [Events and names](llms/events.md): DOM events, cookie and key rules
125
126
  - [Notifications](llms/notifications.md): `notify()`, the Bell
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayjs/kay",
3
3
  "type": "module",
4
- "version": "1.109.0",
4
+ "version": "1.111.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",
@@ -233,7 +233,7 @@
233
233
  "types"
234
234
  ],
235
235
  "engines": {
236
- "bun": ">=1.4.4"
236
+ "bun": ">=1.4.5"
237
237
  },
238
238
  "scripts": {
239
239
  "check": "$npm_execpath check && $npm_execpath src/tsgo.ts --noEmit -p tsconfig.consumer.json",
@@ -262,7 +262,7 @@
262
262
  },
263
263
  "peerDependencies": {
264
264
  "@happy-dom/global-registrator": "^20.14.6 || ^21.0.3",
265
- "@kaynooo/pg-orm": "^7.0.0 || ^8.0.0",
265
+ "@kaynooo/pg-orm": "^7.0.0 || ^8.0.0 || ^9.0.0",
266
266
  "@types/bun": "^1.4.4",
267
267
  "axe-core": "^4.14.0",
268
268
  "happy-dom": "^20.14.6 || ^21.0.3",
@@ -287,8 +287,8 @@
287
287
  },
288
288
  "dependencies": {
289
289
  "@jsquash/avif": "2.1.1",
290
- "@kaynooo/cli-kit": "0.46.2",
291
- "@kaynooo/utils": "^3.1.0",
290
+ "@kaynooo/cli-kit": "0.47.0",
291
+ "@kaynooo/utils": "^3.2.0",
292
292
  "@resvg/resvg-js": "^2.6.2",
293
293
  "devalue": "^6.0.3",
294
294
  "elysia": "^1.4.31",
@@ -304,13 +304,13 @@
304
304
  "@fontsource/inter": "^5.3.0",
305
305
  "@happy-dom/global-registrator": "^21.0.4",
306
306
  "@iconify-json/tabler": "^1.2.42",
307
- "@kayjs/ai": "1.109.0",
308
- "@kayjs/auth": "1.109.0",
309
- "@kayjs/cms": "1.109.0",
310
- "@kayjs/mail": "1.109.0",
311
- "@kayjs/ui": "1.109.0",
307
+ "@kayjs/ai": "1.111.0",
308
+ "@kayjs/auth": "1.111.0",
309
+ "@kayjs/cms": "1.111.0",
310
+ "@kayjs/mail": "1.111.0",
311
+ "@kayjs/ui": "1.111.0",
312
312
  "@kaynooo/eslint": "^8.0.3",
313
- "@kaynooo/pg-orm": "^8.1.4",
313
+ "@kaynooo/pg-orm": "^9.0.0",
314
314
  "@oxc-parser/binding-wasm32-wasip1": "0.155.0",
315
315
  "@types/babel__traverse": "^7.28.0",
316
316
  "@types/bun": "^1.4.4",
@@ -34,6 +34,7 @@ import { entryFile, KAY_OUTPUT, lazyEntryKey } from './entry-files'
34
34
  import { CSS_FILE, findKayFiles, findProjectFiles, forgetSources, inWalkScope, keepSources, liftSources, readSource, readSourcePaths, readText, writeIfChanged } from './files'
35
35
  import { iconSlotsOf, slotsKey } from './icon-slots'
36
36
  import { Increments, realPaths, sameEntries } from './increments'
37
+ import { exportedImages, staticRemoteDefine } from './island-images'
37
38
  import { keepBundleMapCached, pruneKeptMaps } from './kept-maps'
38
39
  import { hoistLayerOrder } from './layer-order'
39
40
  import { eagerKeys, lazyKey } from './lazy-components'
@@ -80,6 +81,7 @@ export interface ClientOptions extends Pick<KayConfig, ClientBuildKey> {
80
81
  publicEnv?: boolean | undefined
81
82
  // `kay build --static`: no server takes the errors the browser meets, so none are sent.
82
83
  exported?: boolean | undefined
84
+ staticImages?: { allowed: (src: string) => boolean, remote?: string[] } | undefined
83
85
  // Measures what the browser loads for islands, `modules` breaking each chunk down by the modules it holds.
84
86
  report?: 'sizes' | 'modules' | undefined
85
87
  }
@@ -132,10 +134,8 @@ const builtGraph: ImportGraph = new Map()
132
134
  // Bundles what the browser needs: one entry hydrating the islands, each island in its own chunk, and a stylesheet per page and layout.
133
135
  // Every component is compiled first, so all of the project's syntax errors come out together instead of one per bundler run. `stamps` takes what the build read, for the caller to tell later whether it is still current.
134
136
  export async function buildClient(root: string, options: ClientOptions = {}, stamps?: BuildStamps): Promise<ClientBuild> {
135
- const { sources, manifest, scripts, styles } = await clientSession(root, options, { graph: builtGraph, stamps }).build(null)
136
- const built = fromManifest(root, manifest)
137
-
138
- built.unresolved = styles!.server
137
+ const { sources, manifest, scripts, styles, images } = await clientSession(root, options, { graph: builtGraph, stamps }).build(null)
138
+ const built = Object.assign(fromManifest(root, manifest), { islandImages: images, unresolved: styles!.server })
139
139
  const bundled = Object.values(scripts!.inputs).flatMap(inputs => Object.entries(inputs).filter(([, input]) => (input.bytesInOutput ?? 0) > 0).map(([input]) => variantFile(input)))
140
140
 
141
141
  built.packages = packagesOf([...bundled, ...styles!.inputs])
@@ -162,6 +162,7 @@ export interface SessionBuild {
162
162
  manifest: ClientManifest
163
163
  scripts?: Awaited<ReturnType<typeof bundleIslands>> | undefined
164
164
  styles?: Awaited<ReturnType<typeof bundleStyles>> | undefined
165
+ images?: Awaited<ReturnType<typeof exportedImages>>['images']
165
166
  }
166
167
 
167
168
  export interface ClientSession {
@@ -227,7 +228,8 @@ export function clientSession(root: string, options: ClientOptions, settings: Se
227
228
  if (previous && islandsAgain)
228
229
  await increments!.stopMaps(false)
229
230
 
230
- const [scripts, styles] = await bothBundles(islandsAgain ? bundleIslands(root, sources.islands, sources.files, sources.actionForms, sources.actionProps, options, classTable, islandTable, await iconSlotsOf(root, [...sources.files, ...sources.islands.values()], sources.libraries, graph)) : undefined, stylesAgain ? bundleStyles(root, sources, options) : undefined)
231
+ const { images, bundled } = await exportedImages(root, sources, graph, options)
232
+ const [scripts, styles] = await bothBundles(islandsAgain ? bundleIslands(root, sources.islands, sources.files, sources.actionForms, sources.actionProps, bundled, classTable, islandTable, await iconSlotsOf(root, [...sources.files, ...sources.islands.values()], sources.libraries, graph)) : undefined, stylesAgain ? bundleStyles(root, sources, options) : undefined)
231
233
  const styleUses = styles ? styles.uses : previous!.styleUses
232
234
  const manifest: ClientManifest = { ...scripts?.manifest ?? previous!.islands, styles: styles?.styles ?? previous!.styles, ...classTable && { classTable }, ...styleUses && { styleUses }, ...options.hot && { problems: sources.problems }, ...key !== undefined && { options: key } }
233
235
 
@@ -253,7 +255,7 @@ export function clientSession(root: string, options: ClientOptions, settings: Se
253
255
  }
254
256
  }
255
257
 
256
- return { sources, manifest, scripts, styles }
258
+ return { sources, manifest, scripts, styles, images }
257
259
  }
258
260
 
259
261
  return {
@@ -566,7 +568,7 @@ async function bundleRound(root: string, islands: Map<string, string>, files: st
566
568
  ].join('\n'))
567
569
 
568
570
  // Bun resolves packages' `development` export condition unless NODE_ENV is defined as production, which would ship a package's dev build; a build for development, not NODE_ENV, asks for theirs.
569
- const define: Record<string, string> = { 'KAY_BROWSER': 'true', 'process.env.NODE_ENV': JSON.stringify(options.hot === true ? 'development' : 'production'), 'KAY_STATIC_EXPORT': options.exported === true ? 'true' : 'undefined', 'KAY_NAV_ENTRY': 'undefined', 'KAY_FRENCH': options.french === true ? 'true' : 'undefined', 'KAY_I18N': options.i18n === true ? 'true' : 'undefined', 'KAY_NO_ACTION_PROPS': options.hot !== true && !actionProps ? 'true' : 'undefined', 'KAY_VISIBLE_MARGIN': JSON.stringify(rootMargin(options.client?.hydration?.visible, '200px', 'visible')), 'KAY_NEAR_MARGIN': JSON.stringify(rootMargin(options.client?.hydration?.serverIslands, '100% 0px', 'serverIslands')) }
571
+ const define: Record<string, string> = { 'KAY_BROWSER': 'true', 'process.env.NODE_ENV': JSON.stringify(options.hot === true ? 'development' : 'production'), 'KAY_STATIC_EXPORT': options.exported === true ? 'true' : 'undefined', 'KAY_STATIC_REMOTE': staticRemoteDefine(options), 'KAY_NAV_ENTRY': 'undefined', 'KAY_FRENCH': options.french === true ? 'true' : 'undefined', 'KAY_I18N': options.i18n === true ? 'true' : 'undefined', 'KAY_NO_ACTION_PROPS': options.hot !== true && !actionProps ? 'true' : 'undefined', 'KAY_VISIBLE_MARGIN': JSON.stringify(rootMargin(options.client?.hydration?.visible, '200px', 'visible')), 'KAY_NEAR_MARGIN': JSON.stringify(rootMargin(options.client?.hydration?.serverIslands, '100% 0px', 'serverIslands')) }
570
572
  const external = publicEnv !== undefined ? [publicEnv] : []
571
573
  const plugins = (anchor?: string, anchored?: ReadonlySet<string>, direct?: boolean) => [withoutStyles(), api, kay({ target: 'dom', root, variants, localeLinks: options.i18n === true, cacheDir: projectPaths(root).cache, settings: options.librarySettings, iconSlots, anchor, anchored, direct, inspect: options.inspect, api: trees, external, classTable }), ...options.plugins ?? []]
572
574
 
@@ -574,7 +576,7 @@ async function bundleRound(root: string, islands: Map<string, string>, files: st
574
576
 
575
577
  // Without the registry in the boot, each island is an entry point of its own.
576
578
  const islandFiles = options.hot ? [] : [...entries.values()]
577
- const chunk = await runtimeChunk(entryFile, { plugins: plugins(), define, external, islands: islandFiles, cache: { file: join(projectPaths(root).cache, `runtime-search-${options.hot ? 'dev' : 'build'}.json`), key: `${JSON.stringify([options.librarySettings, slotsKey(iconSlots), options.inspect, options.client?.navigation, trees, islandFiles, eagerKeys()])}\0${await Bun.file(bootFile).text()}` } })
579
+ const chunk = await runtimeChunk(entryFile, { plugins: plugins(), define, external, islands: islandFiles, cache: { file: join(projectPaths(root).cache, `runtime-search-${options.hot ? 'dev' : 'build'}.json`), key: `${JSON.stringify([options.librarySettings, slotsKey(iconSlots), options.inspect, options.client?.navigation, trees, islandFiles, eagerKeys(), staticRemoteDefine(options)])}\0${await Bun.file(bootFile).text()}` } })
578
580
 
579
581
  // In development the entry keeps its own code, the islands it imports by their hashed names included: the runtime's chunk then stays as it was through an edit of an island, which swaps in alone.
580
582
  // A second entry point importing the runtime alone has Bun give it that chunk of its own, which it would otherwise merge into the entry's.
@@ -0,0 +1,277 @@
1
+ import type { CheckDiagnostic } from '../check'
2
+ import type { NamedAttribute } from '../compiler/ast'
3
+ import type { LintLevels } from '../compiler/lints'
4
+ import type { ImageOptions } from '../runtime/image'
5
+ import type { ClientOptions } from './client'
6
+ import type { ImportGraph, KayLibrary } from './libraries'
7
+ import { existsSync, readFileSync } from 'node:fs'
8
+ import { basename, dirname, extname, join, resolve } from 'node:path'
9
+ import { walkNodes } from '../compiler/ast'
10
+ import { lintLevel } from '../compiler/lints'
11
+ import { positionAt } from '../compiler/mapping'
12
+ import { parseKay } from '../compiler/parser'
13
+ import { image, registerImage } from '../runtime/image'
14
+ import { imageHeader } from '../server/image-format'
15
+ import { ASSET_PREFIX, ASSETS_DIR } from './assets'
16
+ import { importEdges, reachedFrom } from './libraries'
17
+
18
+ // What the browser of a static export draws that no page rendered: an island's `img` or `image()` of an image the build cannot see otherwise, so no file would be written for its crop, its quality or its small width.
19
+ // Read from the sources of the components an island reaches, as `iconSlotsOf` reads icon slots; a value that is no literal is not known here.
20
+ export interface IslandImage {
21
+ // The imported file, which the build names its asset after.
22
+ file: string
23
+ options: ImageOptions
24
+ }
25
+
26
+ // An `image(url, { width, height, ... })` of an image on another host, its URL a literal.
27
+ export interface RemoteIslandImage extends Position {
28
+ src: string
29
+ options: ImageOptions
30
+ }
31
+
32
+ interface Position {
33
+ file: string
34
+ line: number
35
+ column: number
36
+ }
37
+
38
+ // An image of an island that a static export cannot write files for, and why: its source is neither an import nor a literal (a remote image the build cannot fetch), its size is no number literal, or its crop, quality or sizes is no literal.
39
+ export interface DynamicIslandImage extends Position {
40
+ reason: 'source' | 'size' | 'option'
41
+ }
42
+
43
+ export interface IslandImages {
44
+ imported: IslandImage[]
45
+ remote: RemoteIslandImage[]
46
+ dynamic: DynamicIslandImage[]
47
+ }
48
+
49
+ const IMAGE_IMPORT = /^import\s+(\w+)\s+from\s+(["'])(\.[^"'\n]*\.(?:png|jpe?g|webp|gif|avif))\2/gm
50
+ const KAY_IMAGE_IMPORT = /import\s*\{[^}]*\bimage\b[^}]*\}\s*from\s*["']kay\/image["']/
51
+ const IMAGE_CALL = /(?<![\w$])(?<!(?<!\.\.)\.)image\(\s*(?:(["'])(https?:\/\/[^"'\n]+)\1|([\w$.]+)\s*(?=[,)]))\s*(?:,\s*\{((?:[^{}]|\$\{[^}]*\})*)\})?/g
52
+ const NUMBER = /^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i
53
+ const STRING = /^(["'`])(.*)\1$/s
54
+ const SCANNED = /\.(?:kay|[cm]?[jt]sx?)$/
55
+ const REMOTE = /^https?:\/\//i
56
+
57
+ // A literal as written, a number or a string; undefined for anything computed.
58
+ function literal(text: string): string | number | undefined {
59
+ const written = text.trim()
60
+
61
+ if (NUMBER.test(written))
62
+ return Number(written)
63
+
64
+ const inner = STRING.exec(written)?.[2]
65
+
66
+ // A template literal is read when nothing is interpolated.
67
+ return written.startsWith('`') && inner?.includes('${') === true ? undefined : inner
68
+ }
69
+
70
+ function optionsOf(read: (name: string) => string | undefined): ImageOptions {
71
+ const sizes = literal(read('sizes') ?? '')
72
+ const aspect = literal(read('aspect') ?? '')
73
+ const quality = literal(read('quality') ?? '')
74
+ const width = literal(read('width') ?? '')
75
+ const height = literal(read('height') ?? '')
76
+
77
+ return {
78
+ ...typeof sizes === 'string' && { sizes },
79
+ ...typeof aspect === 'string' && { aspect },
80
+ ...typeof quality === 'number' && { quality },
81
+ ...typeof width === 'number' && { width },
82
+ ...typeof height === 'number' && { height },
83
+ }
84
+ }
85
+
86
+ // The options `read` finds written but `optionsOf` could not take, as a value computed.
87
+ function unreadOptions(read: (name: string) => string | undefined): boolean {
88
+ const options = optionsOf(read)
89
+
90
+ return (['sizes', 'aspect', 'quality'] as const).some(name => read(name) !== undefined && options[name] === undefined)
91
+ }
92
+
93
+ function fieldOf(text: string, name: string): string | undefined {
94
+ const found = new RegExp(`(?:^|[,{\\s])${name}(?:\\s*:\\s*("[^"]*"|'[^']*'|\x60[^\x60]*\x60|[^,}\\s]+)|(?=\\s*(?:[,}]|$)))`).exec(text)
95
+
96
+ // A shorthand property holds a variable, written by its name.
97
+ return found === null ? undefined : found[1] ?? name
98
+ }
99
+
100
+ // The files the sources import by identifier, as absolute paths.
101
+ function importedImages(source: string, file: string): Map<string, string> {
102
+ const found = new Map<string, string>()
103
+
104
+ for (const [, name, , path] of source.matchAll(IMAGE_IMPORT))
105
+ found.set(name!, resolve(dirname(file), path!))
106
+
107
+ return found
108
+ }
109
+
110
+ // What the `.kay` and script files hand the browser to draw, an image option written: a bare `img` of an imported image gives nothing new unless it asks for a crop, a quality or a width.
111
+ export function scanIslandImages(files: Iterable<string>): IslandImages {
112
+ const found: IslandImages = { imported: [], remote: [], dynamic: [] }
113
+
114
+ for (const file of files) {
115
+ if (!SCANNED.test(file))
116
+ continue
117
+
118
+ let source: string
119
+
120
+ try {
121
+ source = readFileSync(file, 'utf8')
122
+ }
123
+ catch {
124
+ continue
125
+ }
126
+
127
+ if (!source.includes('img') && !source.includes('image('))
128
+ continue
129
+
130
+ const imports = importedImages(source, file)
131
+
132
+ if (file.endsWith('.kay')) {
133
+ walkNodes(parseKay(source).template, undefined, (node) => {
134
+ if (node.kind !== 'element' || node.component || node.name !== 'img')
135
+ return undefined
136
+
137
+ const named = (name: string) => node.attributes.find((attribute): attribute is NamedAttribute => attribute.kind !== 'spread' && attribute.kind !== 'boolean' && source.slice(attribute.name.start, attribute.name.end) === name)
138
+ const value = (name: string) => {
139
+ const attribute = named(name)
140
+
141
+ if (attribute?.kind === 'static')
142
+ return JSON.stringify(attribute.text)
143
+
144
+ return attribute?.kind === 'expression' ? source.slice(attribute.expression.start, attribute.expression.end) : undefined
145
+ }
146
+ const src = value('src')?.trim()
147
+ const options = optionsOf(value)
148
+ const imported = src === undefined ? undefined : imports.get(src)
149
+
150
+ if (imported !== undefined && (options.aspect !== undefined || options.quality !== undefined || options.sizes !== undefined))
151
+ found.imported.push({ file: imported, options })
152
+
153
+ if (imported !== undefined && unreadOptions(value))
154
+ found.dynamic.push({ file, ...positionAt(source, node.start), reason: 'option' })
155
+
156
+ return undefined
157
+ })
158
+ }
159
+
160
+ if (!KAY_IMAGE_IMPORT.test(source))
161
+ continue
162
+
163
+ for (const match of source.matchAll(IMAGE_CALL)) {
164
+ const [, , url, name, written] = match
165
+ const options = optionsOf(field => written === undefined ? undefined : fieldOf(written, field))
166
+
167
+ const at = { file, ...positionAt(source, match.index) }
168
+ const read = (field: string) => written === undefined ? undefined : fieldOf(written, field)
169
+ const sized = options.width !== undefined && options.height !== undefined
170
+
171
+ if (url !== undefined && sized)
172
+ found.remote.push({ src: url, options, ...at })
173
+ else if (url !== undefined)
174
+ found.dynamic.push({ ...at, reason: 'size' })
175
+ else if (imports.has(name!))
176
+ found.imported.push({ file: imports.get(name!)!, options })
177
+ else if (url === undefined && read('width') !== undefined && read('height') !== undefined)
178
+ found.dynamic.push({ ...at, reason: 'source' })
179
+
180
+ if ((url !== undefined || imports.has(name!)) && unreadOptions(read))
181
+ found.dynamic.push({ ...at, reason: 'option' })
182
+ }
183
+ }
184
+
185
+ return found
186
+ }
187
+
188
+ // The name the build gives an imported file in `assets`: its content's hash after its own name.
189
+ export function assetNameOf(file: string): string | undefined {
190
+ try {
191
+ const extension = extname(file)
192
+
193
+ return `${basename(file, extension)}-${Bun.hash(readFileSync(file)).toString(36)}${extension}`
194
+ }
195
+ catch {
196
+ return undefined
197
+ }
198
+ }
199
+
200
+ // The URL `registerImage` knows an imported file by.
201
+ export function assetUrlOf(file: string): string | undefined {
202
+ const name = assetNameOf(file)
203
+
204
+ return name === undefined ? undefined : `${ASSET_PREFIX}${ASSETS_DIR}/${encodeURIComponent(name)}`
205
+ }
206
+
207
+ // What the islands of a static export draw that no page renders, and the options its browser bundle is built with: it links a remote image as a file only when the build fetches it, a literal URL given its size on a host `images.remote` lists.
208
+ // `ClientOptions.staticImages` is the hosts `images.remote` lists, and what this adds: the remote URLs the build fetches.
209
+ export async function exportedImages(root: string, sources: { islands: Map<string, string>, libraries: KayLibrary[] }, graph: ImportGraph, options: ClientOptions): Promise<{ images: IslandImages | undefined, bundled: ClientOptions }> {
210
+ if (options.exported !== true)
211
+ return { images: undefined, bundled: options }
212
+
213
+ const images = scanIslandImages(await reachedFrom([...sources.islands.values()], importEdges(root, sources.libraries, graph)))
214
+
215
+ const { staticImages } = options
216
+
217
+ return { images, bundled: staticImages ? { ...options, staticImages: { ...staticImages, remote: linkedRemote(images, staticImages.allowed).map(({ src }) => src) } } : options }
218
+ }
219
+
220
+ // The value of `KAY_STATIC_REMOTE` in the browser bundle.
221
+ export function staticRemoteDefine({ staticImages }: ClientOptions): string {
222
+ return staticImages?.remote === undefined ? 'undefined' : JSON.stringify(staticImages.remote)
223
+ }
224
+
225
+ // The remote images a static export writes files for: a literal URL given its size, on a host `images.remote` lists.
226
+ export function linkedRemote(images: IslandImages, allowed: (src: string) => boolean): RemoteIslandImage[] {
227
+ return images.remote.filter(({ src }) => REMOTE.test(src) && allowed(src))
228
+ }
229
+
230
+ // Asks the image runtime for the variants the islands draw, which records the ones beyond the ladder for the build to write: the images are registered first, as a server that never loaded the island's module has not.
231
+ // Returns what `kay check` says of the ones it cannot read, when `checking`.
232
+ export async function recordIslandImages(clientDir: string, images: IslandImages | undefined, allowed: (src: string) => boolean, { checking, lints }: { checking: boolean, lints: LintLevels | undefined }): Promise<CheckDiagnostic[]> {
233
+ if (images === undefined)
234
+ return []
235
+
236
+ for (const { file, options } of images.imported) {
237
+ const name = assetNameOf(file)
238
+ const path = name === undefined ? undefined : join(clientDir, ASSETS_DIR, name)
239
+
240
+ if (path === undefined || !existsSync(path))
241
+ continue
242
+
243
+ // An image kay cannot decode is served as it is, with no variants.
244
+ let header: Awaited<ReturnType<typeof imageHeader>>
245
+
246
+ try {
247
+ header = await imageHeader(Bun.file(path))
248
+ }
249
+ catch {
250
+ continue
251
+ }
252
+
253
+ if (!header.animated)
254
+ image(registerImage(assetUrlOf(file)!, header.width, header.height), options)
255
+ }
256
+
257
+ for (const { src, options } of linkedRemote(images, allowed))
258
+ image(src, options)
259
+
260
+ const level = lintLevel('static-remote-image', lints)
261
+
262
+ return checking && level !== 'allow' ? dynamicImageLints(images, level, allowed) : []
263
+ }
264
+
265
+ const UNREAD = {
266
+ source: { message: 'This `image()` of an island takes a source the build cannot read, so a static export, which has no image route, links the original image instead of resized files', help: 'give `image()` the image\'s URL as a literal in the island, on a host `images.remote` lists, so the build fetches and resizes it, or draw the image where the server renders it' },
267
+ size: { message: 'This `image()` of an island takes a width or a height that is no number literal, so the build cannot fetch and resize the image and a static export links the original', help: 'write the width and the height as numbers' },
268
+ option: { message: 'This island image takes a crop, a quality or sizes that is no literal, so a static export, which writes the files it reads from the source, has none for it and the browser asks for a file that does not exist', help: 'write `aspect`, `quality` and `sizes` as literals in the island' },
269
+ host: { message: 'This `image()` URL is on a host `images.remote` does not list, so a static export links the original image instead of resized files', help: 'list the host in `images.remote`, so the build fetches and resizes it' },
270
+ } as const
271
+
272
+ // What `kay check` says of the island images a static export cannot write files for: they keep their own URL, or ask the browser for a file that is not there.
273
+ export function dynamicImageLints(images: IslandImages, level: 'warn' | 'deny', allowed: (src: string) => boolean = () => true): CheckDiagnostic[] {
274
+ const unlisted = images.remote.filter(({ src }) => !allowed(src)).map(({ file, line, column }) => ({ file, line, column, reason: 'host' as const }))
275
+
276
+ return [...images.dynamic, ...unlisted].map(({ file, line, column, reason }) => ({ file, line, column, code: 'static-remote-image', severity: level === 'warn' ? 'warning' : 'error', ...UNREAD[reason] }))
277
+ }
@@ -38,7 +38,7 @@ import { avifQuality, webpQuality, writeImageVariants, writeRemoteVariants } fro
38
38
  import { setImageColors } from '../server/image-color'
39
39
  import { assetFiles, hookPrerendered } from '../server/page-hook'
40
40
  import { prerenderPages } from '../server/prerender'
41
- import { remoteImages, remotePatterns } from '../server/remote'
41
+ import { remoteAllowed, remoteImages, remotePatterns } from '../server/remote'
42
42
  import { contextReadsOf, routeMounts, slashedPath } from '../server/routes'
43
43
  import { configuredFiles, linkStoredFiles } from '../server/storage'
44
44
  import { budgetLints, checkBudget, footprintLints } from './budget'
@@ -49,6 +49,7 @@ import { cachedCopies, cachedDictionaryCopies, pruneCopies, pruneDictionaryCopie
49
49
  import { writeCachedFavicons } from './favicons'
50
50
  import { inWalkScope } from './files'
51
51
  import { routeFootprints } from './footprint'
52
+ import { recordIslandImages } from './island-images'
52
53
  import { restoreKept, setAsideKept } from './kept'
53
54
  import { codecWarnings, iconSetPackages, iconSetWarnings, NOTICES_FILE, packagesOf, thirdPartyNotices } from './licenses'
54
55
  import { readStoredReport, storedReport, writeStoredReport } from './report'
@@ -403,7 +404,8 @@ async function bundleStage(project: Project, exported: boolean, analyze: boolean
403
404
  if (exported)
404
405
  refuseStaticConfig(config)
405
406
 
406
- const client = await buildClient(root, clientOptionsOf(config, project.mode, { exported, report: analyze || (project.config.budget?.js !== undefined && lintLevel('over-budget', project.config.lints) !== 'allow') ? 'modules' : 'sizes' }))
407
+ const patterns = exported ? await remotePatterns(config.assets?.images?.remote?.hosts) : []
408
+ const client = await buildClient(root, clientOptionsOf(config, project.mode, { exported, ...exported && { staticImages: { allowed: (src: string) => remoteAllowed(src, patterns) } }, report: analyze || (project.config.budget?.js !== undefined && lintLevel('over-budget', project.config.lints) !== 'allow') ? 'modules' : 'sizes' }))
407
409
 
408
410
  // A static host cannot pick a format by `Accept`, so an export links WebP alone.
409
411
  const avif = exported ? undefined : avifQuality(config.assets?.images)
@@ -475,11 +477,15 @@ async function outputStage(project: Project, exported: boolean, client: ClientBu
475
477
  // Read to point a redirect's lint at its line, only when there is one to point at.
476
478
  const configSource = checking && config.redirects !== undefined && await Bun.file(configFile).exists() ? await Bun.file(configFile).text() : undefined
477
479
 
480
+ const imagePatterns = await remotePatterns(config.assets?.images?.remote?.hosts)
481
+ // The pages recorded the variants they link, and the islands' own, which no page rendered, go in beside them.
482
+ const islandImageLints = await recordIslandImages(client.dir, client.islandImages, src => remoteAllowed(src, imagePatterns), { checking, lints: config.lints })
483
+
478
484
  // The heads are the check's to read, so a build without checking skips them with it.
479
- const linted = [...checking ? [...pageSeoLints(config, rendered, exported), ...siteSeoLints(config, rendered, others, { configFile, configSource, exported, unseen: hasUnseenPages(routes, rendered, others, exported, paths.routes), skipConfigChains: true }), ...unkeptPageLints(config, [...stops.values()]), ...pageStructureLints(config, rendered)] : [], ...budgetLints(config.budget, config.lints, sizes, routes, client.report)]
485
+ const linted = [...checking ? [...pageSeoLints(config, rendered, exported), ...siteSeoLints(config, rendered, others, { configFile, configSource, exported, unseen: hasUnseenPages(routes, rendered, others, exported, paths.routes), skipConfigChains: true }), ...unkeptPageLints(config, [...stops.values()]), ...pageStructureLints(config, rendered)] : [], ...islandImageLints, ...budgetLints(config.budget, config.lints, sizes, routes, client.report)]
480
486
 
481
487
  // Remote originals are kept between builds, revalidated as the image route does.
482
- const remote = remoteImages(cacheDir(root, 'remote'), await remotePatterns(config.assets?.images?.remote?.hosts), undefined, undefined, remoteLimits(config.assets?.images))
488
+ const remote = remoteImages(cacheDir(root, 'remote'), imagePatterns, undefined, undefined, remoteLimits(config.assets?.images))
483
489
 
484
490
  await writeImageVariants(client.dir, webpQuality(config.assets?.images), cacheDir(root, 'variants'), { avif: exported ? undefined : avifQuality(config.assets?.images), onImage: imageProgress(report) })
485
491
  report({ step: 'writing images, cards and favicons' })