@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.
- package/dist/eslint.js +488 -75
- package/editors/zed/extension.toml +2 -2
- package/llms/actions-from-islands.md +1 -1
- package/llms/build-and-start.md +1 -1
- package/llms/checks.md +1 -0
- package/llms/component-libraries.md +1 -1
- package/llms/components.md +1 -1
- package/llms/deprecated-lints.md +1 -1
- package/llms/dev-tool.md +1 -1
- package/llms/effects.md +1 -0
- package/llms/head.md +1 -1
- package/llms/images.md +2 -0
- package/llms/island-and-form-lints.md +2 -1
- package/llms/islands-lazy-components.md +23 -0
- package/llms/islands.md +4 -14
- package/llms/lints.md +1 -1
- package/llms/live-values.md +1 -1
- package/llms/navigation-from-code.md +1 -1
- package/llms/navigation.md +5 -3
- package/llms/performance-lints.md +1 -0
- package/llms/prerendering.md +1 -1
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +1 -1
- package/llms/templates-elements-slots-snippets.md +4 -4
- package/llms/upgrading-archive.md +121 -42
- package/llms/upgrading.md +17 -133
- package/llms/whats-new-archive.md +31 -31
- package/llms/whats-new.md +45 -30
- package/llms.txt +3 -2
- package/package.json +11 -11
- package/src/build/client.ts +10 -8
- package/src/build/island-images.ts +277 -0
- package/src/build/pipeline.ts +10 -4
- package/src/build/static.ts +99 -24
- package/src/build/variants.ts +132 -18
- package/src/check/env-types.ts +1 -1
- package/src/check/project.ts +4 -0
- package/src/check/schema-builders.ts +230 -26
- package/src/check/shadow-types.ts +3 -3
- package/src/commands/upgrade.ts +2 -1
- package/src/compiler/allow-comments.ts +38 -2
- package/src/compiler/ast.ts +4 -4
- package/src/compiler/codegen.ts +4 -4
- package/src/compiler/deprecated-lints-1-106.ts +2 -2
- package/src/compiler/dom.ts +4 -3
- package/src/compiler/hand-parts.ts +36 -8
- package/src/compiler/handed-data.ts +15 -0
- package/src/compiler/helper-imports.ts +2 -2
- package/src/compiler/html.ts +3 -7
- package/src/compiler/index.ts +7 -4
- package/src/compiler/island-arguments.ts +9 -0
- package/src/compiler/island-lints.ts +7 -0
- package/src/compiler/items.ts +174 -0
- package/src/compiler/jsx.ts +10 -11
- package/src/compiler/kay-exports.ts +1 -0
- package/src/compiler/lints.ts +6 -7
- package/src/compiler/markup.ts +26 -24
- package/src/compiler/names.ts +1 -1
- package/src/compiler/removed-lints.ts +90 -0
- package/src/compiler/rewrite-types.ts +2 -0
- package/src/compiler/rewrite.ts +4 -2
- package/src/compiler/route-lints.ts +8 -0
- package/src/compiler/signal-from-prop.ts +141 -0
- package/src/compiler/template-reads.ts +16 -0
- package/src/compiler/template-walk.ts +2 -1
- package/src/config-shape.ts +4 -1
- package/src/config.ts +2 -2
- package/src/new.ts +16 -4
- package/src/project.ts +3 -3
- package/src/runtime/await.server.ts +4 -2
- package/src/runtime/checks.ts +14 -2
- package/src/runtime/client.ts +5 -9
- package/src/runtime/dev-tab-env.ts +28 -3
- package/src/runtime/dom-loop.ts +2 -4
- package/src/runtime/dom.ts +2 -2
- package/src/runtime/html.ts +53 -7
- package/src/runtime/image.ts +24 -23
- package/src/runtime/index.ts +2 -2
- package/src/runtime/island.server.ts +41 -11
- package/src/runtime/navigate.ts +14 -0
- package/src/runtime/navigation.ts +9 -1
- package/src/runtime/page-swap.ts +6 -3
- package/src/runtime/reactive.ts +72 -0
- package/src/runtime/row-key.ts +4 -0
- package/src/runtime/swap-flight.ts +10 -10
- package/src/runtime/swap-focus.ts +56 -9
- package/src/runtime/swap-kept.ts +97 -29
- package/src/runtime/swap-morph.ts +49 -9
- package/src/runtime/text-hash.ts +17 -0
- package/src/runtime/uid.server.ts +6 -4
- package/src/runtime/values.ts +12 -0
- package/src/server/client.ts +3 -0
- package/src/server/dev.ts +2 -0
- package/src/server/image.ts +1 -1
- package/src/server/kept-exports.ts +1 -0
- package/src/server/render-document.ts +11 -8
- package/src/server/render.ts +3 -3
- package/types/build/client.d.ts +6 -0
- package/types/build/client.d.ts.map +1 -1
- package/types/build/island-images.d.ts +45 -0
- package/types/build/island-images.d.ts.map +1 -0
- package/types/build/pipeline.d.ts.map +1 -1
- package/types/build/static.d.ts.map +1 -1
- package/types/build/variants.d.ts +9 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/project.d.ts.map +1 -1
- package/types/check/schema-builders.d.ts.map +1 -1
- package/types/commands/upgrade.d.ts.map +1 -1
- package/types/compiler/allow-comments.d.ts +2 -0
- package/types/compiler/allow-comments.d.ts.map +1 -1
- package/types/compiler/ast.d.ts +1 -1
- package/types/compiler/ast.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-106.d.ts +2 -2
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
- package/types/compiler/deprecated-lints.d.ts +2 -2
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/hand-parts.d.ts +6 -3
- package/types/compiler/hand-parts.d.ts.map +1 -1
- package/types/compiler/handed-data.d.ts +5 -0
- package/types/compiler/handed-data.d.ts.map +1 -0
- package/types/compiler/html.d.ts.map +1 -1
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-arguments.d.ts +5 -0
- package/types/compiler/island-arguments.d.ts.map +1 -1
- package/types/compiler/island-lints.d.ts +7 -0
- package/types/compiler/island-lints.d.ts.map +1 -1
- package/types/compiler/items.d.ts +14 -0
- package/types/compiler/items.d.ts.map +1 -1
- package/types/compiler/jsx.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +20 -5
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/markup.d.ts +3 -1
- package/types/compiler/markup.d.ts.map +1 -1
- package/types/compiler/names.d.ts.map +1 -1
- package/types/compiler/removed-lints.d.ts +3 -0
- package/types/compiler/removed-lints.d.ts.map +1 -0
- package/types/compiler/rewrite-types.d.ts +1 -0
- package/types/compiler/rewrite-types.d.ts.map +1 -1
- package/types/compiler/route-lints.d.ts +8 -0
- package/types/compiler/route-lints.d.ts.map +1 -1
- package/types/compiler/signal-from-prop.d.ts +4 -0
- package/types/compiler/signal-from-prop.d.ts.map +1 -0
- package/types/compiler/template-reads.d.ts +1 -0
- package/types/compiler/template-reads.d.ts.map +1 -1
- package/types/compiler/template-walk.d.ts.map +1 -1
- package/types/config-shape.d.ts.map +1 -1
- package/types/config.d.ts +3 -1
- package/types/config.d.ts.map +1 -1
- package/types/new.d.ts.map +1 -1
- package/types/project.d.ts +2 -2
- package/types/project.d.ts.map +1 -1
- package/types/runtime/await.server.d.ts.map +1 -1
- package/types/runtime/checks.d.ts +8 -2
- package/types/runtime/checks.d.ts.map +1 -1
- package/types/runtime/client.d.ts.map +1 -1
- package/types/runtime/dev-tab-env.d.ts.map +1 -1
- package/types/runtime/dom-loop.d.ts +2 -1
- package/types/runtime/dom-loop.d.ts.map +1 -1
- package/types/runtime/dom.d.ts +2 -2
- package/types/runtime/dom.d.ts.map +1 -1
- package/types/runtime/html.d.ts +6 -3
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/image.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -2
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +1 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/navigate.d.ts.map +1 -1
- package/types/runtime/navigation.d.ts +4 -0
- package/types/runtime/navigation.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +5 -0
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/row-key.d.ts +2 -0
- package/types/runtime/row-key.d.ts.map +1 -0
- package/types/runtime/swap-flight.d.ts +1 -1
- package/types/runtime/swap-flight.d.ts.map +1 -1
- package/types/runtime/swap-focus.d.ts +2 -0
- package/types/runtime/swap-focus.d.ts.map +1 -1
- package/types/runtime/swap-kept.d.ts.map +1 -1
- package/types/runtime/swap-morph.d.ts.map +1 -1
- package/types/runtime/text-hash.d.ts +2 -0
- package/types/runtime/text-hash.d.ts.map +1 -0
- package/types/runtime/uid.server.d.ts.map +1 -1
- package/types/runtime/values.d.ts +4 -0
- package/types/runtime/values.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +3 -1
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +3 -1
- package/types/server/app.d.ts.map +1 -1
- package/types/server/client.d.ts +2 -0
- package/types/server/client.d.ts.map +1 -1
- package/types/server/dev.d.ts +1 -0
- package/types/server/dev.d.ts.map +1 -1
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/render-document.d.ts +1 -1
- package/types/server/render-document.d.ts.map +1 -1
- package/types/server/render.d.ts +2 -2
- 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.
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- `
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- kayjs-ui's
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
- `kay
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
- `
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
291
|
-
"@kaynooo/utils": "^3.
|
|
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.
|
|
308
|
-
"@kayjs/auth": "1.
|
|
309
|
-
"@kayjs/cms": "1.
|
|
310
|
-
"@kayjs/mail": "1.
|
|
311
|
-
"@kayjs/ui": "1.
|
|
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": "^
|
|
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",
|
package/src/build/client.ts
CHANGED
|
@@ -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
|
|
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
|
+
}
|
package/src/build/pipeline.ts
CHANGED
|
@@ -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
|
|
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'),
|
|
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' })
|