@tenphi/cookbook 0.25.3 → 0.26.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.
@@ -130,6 +130,30 @@ import { Preview } from "@tenphi/cookbook/components";
130
130
  css={"button { padding: 0.75rem; }"}
131
131
  />
132
132
 
133
+ To demonstrate your own library, build it into the site's public directory
134
+ (`public/` by default) and list the files in `scripts` by their public path,
135
+ without the Astro `base`. Cookbook inlines each file, in order, before
136
+ `javascript`, so the authored code can use what they define. Each file runs as
137
+ a classic script, so use a self-contained IIFE or UMD build without `import` or
138
+ `export`:
139
+
140
+ ```mdx
141
+ <Preview
142
+ title="Library button"
143
+ html={"<acme-button>Save</acme-button>"}
144
+ scripts={["/demo/button.js"]}
145
+ javascript={"document.querySelector('acme-button').loading = true;"}
146
+ />
147
+ ```
148
+
149
+ Inlining keeps the preview isolated and needs no request, so the demo works in
150
+ `astro dev`, `astro preview`, and offline as well as on the deployed site. A
151
+ `<script src>` in `html` is a cross-site request from the sandboxed frame:
152
+ `astro dev` rejects it, and Chrome blocks it from local servers. View source
153
+ shows each inlined file as a `<script src>` tag. Every preview embeds its own
154
+ copy, so keep demo bundles small. A missing file or a path outside the public
155
+ directory fails the build.
156
+
133
157
  ## Cookbook logo
134
158
 
135
159
  `Logo` renders the Cookbook mark. Use `label` when it carries meaning or
@@ -149,12 +173,12 @@ markers remain visible independently of their theme-aware backgrounds:
149
173
 
150
174
  ## Component props
151
175
 
152
- | Component | Props and behavior |
153
- | --------- | --------------------------------------------------------------------------------------------------- |
154
- | `Card` | Optional `title` and `href`; renders an article or link with slot content |
155
- | `Steps` | Ordered list container; supply `li` elements |
156
- | `Logo` | Optional `label`, `decorative`, and root `class`; renders the Cookbook mark |
157
- | `Preview` | Required `title`; optional `html`, `css`, and `javascript`; isolates examples in a sandboxed iframe |
176
+ | Component | Props and behavior |
177
+ | --------- | -------------------------------------------------------------------------------------------------------------------------- |
178
+ | `Card` | Optional `title` and `href`; renders an article or link with slot content |
179
+ | `Steps` | Ordered list container; supply `li` elements |
180
+ | `Logo` | Optional `label`, `decorative`, and root `class`; renders the Cookbook mark |
181
+ | `Preview` | Required `title`; optional `html`, `css`, `javascript`, and public-file `scripts`; isolates examples in a sandboxed iframe |
158
182
 
159
183
  The public package exports each component's props type, such as `TabProps`,
160
184
  `CalloutProps`, and `CodeGroupProps`. Styles and all named sub-elements are
package/docs/migration.md CHANGED
@@ -230,8 +230,8 @@ Tasty-generated style hashes and library-owned Pagefind sub-element classes rema
230
230
 
231
231
  Hero buttons stay stationary on hover. Minimal actions share secondary outline
232
232
  padding, background, and border width, with a transparent border (`border: "#clear"`).
233
- Pagination links also reserve a transparent border before hover; hover changes
234
- only its color, preserving `theme.styles.Pagination.Link` border width and style.
233
+ Pagination links keep their border at rest; hover changes only colors,
234
+ preserving `theme.styles.Pagination.Link` border width and style.
235
235
 
236
236
  ## Smaller shared state set
237
237
 
@@ -382,6 +382,38 @@ Adopt Cookbook's Tasty validation preset and register your additional names.
382
382
  See [Linting custom styles](./custom-components.md#linting-custom-styles) for
383
383
  ESLint and oxlint examples.
384
384
 
385
+ ## Reader appearance
386
+
387
+ The Appearance menu stores each reader's color scheme and contrast in one
388
+ `localStorage` entry. Its key and format are a stable contract, so another app
389
+ on the same origin can share the preference with the documentation. A typical
390
+ example is a product site that serves Cookbook under `/docs/`.
391
+
392
+ ```ts
393
+ // localStorage["cookbook-appearance"], stored as JSON
394
+ type CookbookAppearance = {
395
+ theme?: "light" | "dark" | "system";
396
+ contrast?: "normal" | "more" | "system";
397
+ };
398
+ ```
399
+
400
+ A missing or unrecognized field means `"system"`, which follows the reader's
401
+ operating system. Keep any other fields when you write the object:
402
+
403
+ ```ts
404
+ const key = "cookbook-appearance";
405
+ const appearance = JSON.parse(localStorage.getItem(key) ?? "{}") ?? {};
406
+
407
+ localStorage.setItem(key, JSON.stringify({ ...appearance, theme: "dark" }));
408
+ ```
409
+
410
+ Cookbook applies the stored choice before the first paint, as `data-theme` and
411
+ `data-contrast` on `<html>`. Open pages follow changes made in other tabs through
412
+ the `storage` event. Your app can map the same values onto its own attributes.
413
+
414
+ Browsers keep `localStorage` per origin: the scheme, host, and port must all
415
+ match, so a docs subdomain does not share the preference.
416
+
385
417
  ## Static behavior
386
418
 
387
419
  The page content remains readable without client JavaScript. Search, menus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/cookbook",
3
- "version": "0.25.3",
3
+ "version": "0.26.0",
4
4
  "description": "Repository-native static documentation for Astro",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -68,8 +68,8 @@
68
68
  "author": "Andrey Yamanov",
69
69
  "license": "MIT",
70
70
  "dependencies": {
71
- "@tenphi/docs": "0.25.3",
72
- "@tenphi/renderer": "0.25.3"
71
+ "@tenphi/docs": "0.26.0",
72
+ "@tenphi/renderer": "0.26.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "astro": "^7.3.2"