@plitzi/sdk-server 0.38.4 → 0.38.5

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 (116) hide show
  1. package/CHANGELOG.md +333 -0
  2. package/README.md +126 -17
  3. package/dist/actions.d.ts +8 -5
  4. package/dist/actions.js +3 -1
  5. package/dist/adapters/jsonAdapters.d.ts +1 -1
  6. package/dist/adapters/jsonAdapters.js +16 -3
  7. package/dist/core/configSeam.js +20 -4
  8. package/dist/core/createServer.js +3 -2
  9. package/dist/core/handlers/socialRouteHandlers.js +6 -1
  10. package/dist/core/http/stages/devReload.d.ts +11 -0
  11. package/dist/core/http/stages/devReload.js +17 -0
  12. package/dist/core/server/baseServer.d.ts +2 -0
  13. package/dist/core/server/baseServer.js +3 -0
  14. package/dist/core/server/pageServer.js +18 -0
  15. package/dist/core/services/registry.js +2 -0
  16. package/dist/core/services/rsc.js +1 -1
  17. package/dist/core/services/spaceDocument.d.ts +2 -0
  18. package/dist/core/services/spaceDocument.js +11 -0
  19. package/dist/functions-api.d.ts +6 -1
  20. package/dist/functionsRunner.d.ts +5 -0
  21. package/dist/functionsRunner.js +2 -1
  22. package/dist/helpers/hydrationPayload.d.ts +25 -4
  23. package/dist/helpers/hydrationPayload.js +36 -30
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +2 -2
  26. package/dist/modules/actions/index.d.ts +11 -2
  27. package/dist/modules/actions/index.js +29 -7
  28. package/dist/modules/actions/runtime/fileKv.d.ts +28 -0
  29. package/dist/modules/actions/runtime/fileKv.js +95 -0
  30. package/dist/modules/actions/runtime/fileKv.test.d.ts +1 -0
  31. package/dist/modules/actions/runtime/memoryKv.d.ts +23 -0
  32. package/dist/modules/actions/runtime/memoryKv.js +39 -24
  33. package/dist/modules/actions/runtime/namespaceKv.d.ts +2 -0
  34. package/dist/modules/actions/runtime/namespaceKv.js +5 -3
  35. package/dist/modules/actions/runtime/renderResolver.d.ts +3 -2
  36. package/dist/modules/actions/runtime/renderResolver.js +13 -9
  37. package/dist/modules/actions/runtime/renderShare.d.ts +7 -24
  38. package/dist/modules/actions/runtime/renderShare.js +47 -13
  39. package/dist/modules/actions/runtime/runAction.js +15 -1
  40. package/dist/modules/actions/runtime/scope.js +16 -1
  41. package/dist/modules/actions/runtime/signing.js +4 -1
  42. package/dist/modules/actions/runtime/taskContext.d.ts +7 -1
  43. package/dist/modules/actions/runtime/taskContext.js +6 -2
  44. package/dist/modules/actions/tasks/registry.d.ts +3 -1
  45. package/dist/modules/actions/tasks/registry.js +15 -1
  46. package/dist/modules/actions/types.d.ts +15 -2
  47. package/dist/modules/functions/config.d.ts +6 -0
  48. package/dist/modules/functions/context.d.ts +4 -2
  49. package/dist/modules/functions/context.js +43 -21
  50. package/dist/modules/functions/load.d.ts +8 -1
  51. package/dist/modules/functions/load.js +8 -4
  52. package/dist/modules/functions/manifest.d.ts +4 -1
  53. package/dist/modules/functions/manifest.js +14 -2
  54. package/dist/modules/functions/native.d.ts +2 -1
  55. package/dist/modules/functions/native.js +2 -2
  56. package/dist/modules/functions/plugins.test.d.ts +1 -0
  57. package/dist/modules/functions/routes.d.ts +8 -3
  58. package/dist/modules/functions/routes.js +41 -21
  59. package/dist/modules/functions/scope.d.ts +30 -0
  60. package/dist/modules/functions/scope.js +28 -0
  61. package/dist/modules/functions/space.d.ts +10 -5
  62. package/dist/modules/functions/space.js +37 -15
  63. package/dist/modules/rsc/connectorRscData.d.ts +3 -1
  64. package/dist/modules/rsc/connectorRscData.js +8 -4
  65. package/dist/modules/rsc/handler.d.ts +3 -16
  66. package/dist/modules/rsc/handler.js +10 -4
  67. package/dist/modules/rsc/publicFileResolver.d.ts +15 -12
  68. package/dist/modules/rsc/publicFileResolver.js +56 -24
  69. package/dist/modules/rsc/resolveRscData.d.ts +3 -1
  70. package/dist/modules/rsc/resolveRscData.js +8 -5
  71. package/dist/modules/runtime/bundle.d.ts +5 -0
  72. package/dist/modules/runtime/bundle.js +20 -5
  73. package/dist/modules/sqlite/kv.d.ts +34 -0
  74. package/dist/modules/sqlite/kv.js +99 -0
  75. package/dist/modules/sqlite/kv.test.d.ts +1 -0
  76. package/dist/modules/ssr/prepareRender.js +45 -6
  77. package/dist/modules/ssr/spaceDocument.d.ts +25 -0
  78. package/dist/modules/ssr/spaceDocument.js +72 -0
  79. package/dist/modules/ssr/spaceDocument.test.d.ts +1 -0
  80. package/dist/modules/ssr/testing/offlineData.d.ts +5 -0
  81. package/dist/modules/ssr/views/template.ejs +122 -20
  82. package/dist/plugins/compile.js +6 -21
  83. package/dist/plugins/compile.test.d.ts +1 -0
  84. package/dist/plugins/copy.d.ts +5 -0
  85. package/dist/plugins/copy.js +16 -1
  86. package/dist/plugins/copy.test.d.ts +1 -0
  87. package/dist/plugins/manager.d.ts +13 -0
  88. package/dist/plugins/manager.js +40 -11
  89. package/dist/plugins/watch.d.ts +12 -0
  90. package/dist/plugins/watch.js +79 -0
  91. package/dist/runtime.d.ts +1 -1
  92. package/dist/runtime.js +2 -2
  93. package/dist/sqlite.d.ts +17 -0
  94. package/dist/sqlite.js +2 -0
  95. package/package.json +8 -3
  96. package/skills/plitzi-authoring/CHEATSHEET.md +4 -2
  97. package/skills/plitzi-authoring/SKILL.md +20 -19
  98. package/skills/plitzi-authoring/recipes/plugin.ts +1 -1
  99. package/skills/plitzi-authoring/recipes/server-data.ts +3 -3
  100. package/skills/plitzi-authoring/recipes/show-data.ts +3 -2
  101. package/skills/plitzi-authoring/recipes/typed-data.ts +1 -1
  102. package/skills/plitzi-authoring/reference/authoring-errors.md +8 -2
  103. package/skills/plitzi-authoring/reference/colours-and-motion.md +3 -1
  104. package/skills/plitzi-authoring/reference/data-and-visibility.md +24 -22
  105. package/skills/plitzi-authoring/reference/drawing.md +24 -0
  106. package/skills/plitzi-authoring/reference/efficiency.md +19 -2
  107. package/skills/plitzi-authoring/reference/flows.md +3 -0
  108. package/skills/plitzi-authoring/reference/layouts.md +8 -23
  109. package/skills/plitzi-authoring/reference/performance.md +2 -2
  110. package/skills/plitzi-authoring/reference/plugins.md +51 -38
  111. package/skills/plitzi-authoring/reference/review-checklist.md +2 -0
  112. package/skills/plitzi-authoring/reference/structure.md +32 -1
  113. package/skills/plitzi-authoring/reference/templates.md +5 -2
  114. package/skills/plitzi-authoring/reference/testing.md +9 -2
  115. package/skills/plitzi-authoring/reference/typed-sources.md +3 -1
  116. package/skills/plitzi-authoring/reference/validation.md +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-server",
3
- "version": "0.38.4",
3
+ "version": "0.38.5",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist",
@@ -40,6 +40,11 @@
40
40
  "import": "./dist/mongo.js",
41
41
  "default": "./dist/mongo.js"
42
42
  },
43
+ "./sqlite": {
44
+ "types": "./dist/sqlite.d.ts",
45
+ "import": "./dist/sqlite.js",
46
+ "default": "./dist/sqlite.js"
47
+ },
43
48
  "./handlers": {
44
49
  "types": "./dist/handlers.d.ts",
45
50
  "import": "./dist/handlers.js",
@@ -79,8 +84,8 @@
79
84
  "type": "module",
80
85
  "sideEffects": false,
81
86
  "dependencies": {
82
- "@plitzi/plitzi-sdk": "0.38.4",
83
- "@plitzi/sdk-shared": "0.38.4",
87
+ "@plitzi/plitzi-sdk": "0.38.5",
88
+ "@plitzi/sdk-shared": "0.38.5",
84
89
  "ejs": "^6.0.1",
85
90
  "esbuild": "^0.28.2",
86
91
  "jsonwebtoken": "^9.0.3",
@@ -18,7 +18,8 @@ const space: SpaceSpec = {
18
18
  components: [{ id, props, slots, root }], // a block placed many times with different content
19
19
  pages: [{ id, name, slug: '', layout: { id: 'shell', slot: 'main' }, body: [] }] // slot: where the body goes
20
20
  }; // slug '' is home; 'products/:slug' takes a param
21
- const { schema, style, warnings } = authorSpace(space, { plugins: [declaration] });
21
+ pageFamily({ folder, layout, seoTitle, body: entry => [...] }, ENTRIES) // pages of one shape, from data; ids scoped per page
22
+ const { schema, style, warnings, suggestions } = authorSpace(space, { plugins: [declaration] });
22
23
  ```
23
24
 
24
25
  ## Elements
@@ -46,6 +47,7 @@ carousel({ id: 'hero', items: 'p.data.slides', autoplay: 5000, row: 'slide-card'
46
47
  // rows follow their item's `id`, or `itemKey: 'slug'`
47
48
  apiContainer({ id: 'p', query: '/data/x.json', cache: true, children }) // publishes p.data; no box of its own
48
49
  apiContainer({ id: 'p', query: '/data/x.json', runtime: 'server', children }) // read by the page server: still p.data
50
+ apiContainer({ id: 'p', action: 'report', runtime: 'server', children }) // the action's output at p's root: p.rows
49
51
  // loadingSlot: 'p-skeleton' — a child shown until it answers
50
52
  form({ id, managedByInteractions: true, flows, children })
51
53
  formControl({ name: 'email', label: 'Email', subType: 'email' }) // select: options: [{ label, value }]
@@ -109,7 +111,7 @@ A flow is `[trigger, …steps]`, in an element's `flows`.
109
111
  [onClick(), navigate({ urlType: 'page', url: 'about' })]
110
112
  [onClick(), runServerAction({ actionId: 'checkout', input: { id: '{{ list_rows.item.id }}' } })]
111
113
  [onClick(), when({ field: 'state.step', operator: '=', value: '2' }, setState({ … }))]
112
- [whileRunning('queue', onClick()), delay(1000), …]
114
+ [whileRunning('queue', onClick()), delay(1000), …] // 'latest': a new firing stops the running one
113
115
  [named('picked', declaredTrigger(declaration, 'onPick')), …]; declaredCallback(declaration, 'reset', { on: 'seats' })
114
116
  ```
115
117
 
@@ -38,21 +38,21 @@ second into the first. If the MCP asks for a sign-in nobody can give, a project
38
38
 
39
39
  ## How to work
40
40
 
41
- 1. **Read before you write.** Open `src/space.ts` (and whatever it imports) and find the layout, the classes and the
41
+ 1. **Read before you write.** Open `src/space/index.ts` (and whatever it imports) and find the layout, the classes and the
42
42
  helpers already there. Extend them; do not add a second way of doing something the space already does.
43
- 2. **Change the declaration, then author it.** `npm run author` (or restart the server) runs `authorSpace`. It checks
44
- everything — every field, value, template, name, param and page link — and a refusal says what to write instead:
45
- do exactly that. Never work around a check, cast past it, or move the logic into a plugin to escape it. The first
46
- refusals come one at a time; the linter's come as ONE list — fix every line of it before running again. How it
47
- checks, a one-file author script for any project, and what it cannot see: [validation](reference/validation.md).
43
+ 2. **Change the declaration, then author it.** `npm run author` (or a restart) runs `authorSpace` — not `doctor`, which
44
+ is the project's. It checks every field, value, template, name, param and page link, and a refusal says what to
45
+ write instead: do exactly that. Never work around a check, cast past it, or move the logic into a plugin to escape
46
+ it. The linter's problems come as ONE list — fix every line before running again. How it checks, and what it
47
+ cannot see: [validation](reference/validation.md).
48
48
  3. **Read every warning, then every suggestion.** A warning names something written that will not do what it says —
49
- zero warnings is the bar. A suggestion (`[suggest]`, `suggestions` in `authorSpace`'s result) names a shorter way to
50
- the same page: a layout for chrome on every page, a component or a `list` for copies, a button's own `content`. Take
51
- them, the ones that save the most first. See [efficiency](reference/efficiency.md).
49
+ zero warnings is the bar. A suggestion (`[suggest]`) names a shorter way to the same page — a layout, a component,
50
+ a `list`, a button's own `content` — or what nothing uses. Take them, the ones that save the most first
51
+ ([efficiency](reference/efficiency.md)). Then `npm run lint:space`: how the source is written — long files, rows of
52
+ data inline, colours that are not tokens — at file:line. Leave both clean.
52
53
  4. **Look at it.** `npm run check -- /about --width 1440,390` says in text whether the page is whole — every element on
53
- screen, nothing overflowing, a clean console; `npm run shot -- /about --width 390 --scheme dark` is the picture, for
54
- when it says something is wrong (`--frames 4` shows what moves); `npm run visual`
55
- runs the checks. Look at desktop, tablet and mobile, light and dark, and the page while its data is still loading.
54
+ screen, nothing overflowing, a clean console; `npm run shot -- /about --width 390 --scheme dark` is the picture
55
+ (`--frames 4` shows what moves); `npm run visual` runs the checks. Look at desktop, tablet and mobile, light and dark, and the page while its data is still loading.
56
56
  5. **Go through the [review checklist](reference/review-checklist.md) before saying it is done.** It is the feedback a
57
57
  reviewer gives on every change, written down so you do not need to hear it.
58
58
 
@@ -66,10 +66,11 @@ second into the first. If the MCP asks for a sign-in nobody can give, a project
66
66
  Chrome shown on several pages — a header, a sidebar, a footer — is a **layout** the pages name, written once. A block
67
67
  placed many times with different content — a product card, a testimonial — is a **component** placed with
68
68
  `component(id, { props })`. A menu, a card grid, a list of steps is DATA, never a block pasted per item: a short
69
- menu mapped in code (`entries.map(entry => link({ href, content: entry.title }))`) is fine; rows — cards, dishes,
70
- tiles — are one `list` over them (`items: [ … ]`) whose row is written once. A link or a button says its words as
71
- its own `content`, not through a `text` inside it. See [layouts and duplication](reference/layouts.md),
72
- [components](reference/components.md) and [efficiency](reference/efficiency.md).
69
+ menu mapped in code is fine; rows — cards, dishes, tiles — are one `list` (`items: [ … ]`) whose row is written
70
+ once. A link or a button says its words as
71
+ its own `content`, not through a `text` inside it. Pages of one shape are one `pageFamily` over data. See
72
+ [layouts](reference/layouts.md), [components](reference/components.md), [structure](reference/structure.md) and
73
+ [efficiency](reference/efficiency.md).
73
74
  3. **One element, one base selector.** An element takes a shared `class` OR its own `css`, never both — authoring
74
75
  refuses the pair. "This class plus one thing" is the class with rules on top, last in the list:
75
76
  `class: [cover, { opacity: '0.25' }]` (needs the element's `id`; it becomes the class `<id>--own`). A look that
@@ -94,9 +95,9 @@ second into the first. If the MCP asks for a sign-in nobody can give, a project
94
95
  8. **Breakpoints are ranges.** `tablet` (48–64rem) and `mobile` (up to 48rem) each inherit only from `desktop`; a rule
95
96
  meant for both is written under `compact`.
96
97
  9. **Never invent data.** Numbers, names and states on screen come from a source. A panel with nothing true to say is
97
- an empty state, not a placeholder figure. With no backend, the data is JSON the project serves
98
- (`public/data/*.json`) read by an `apiContainer` — see [data and visibility](reference/data-and-visibility.md).
99
- `public/` is public: never a secret there.
98
+ an empty state, not a placeholder figure. With no backend, the data is JSON read by an `apiContainer`: a server
99
+ project's `src/data/*.json`, read on the server and never served; with no server, `public/data/*.json`, which is
100
+ public — see [data and visibility](reference/data-and-visibility.md).
100
101
  10. **Never hand-write** `flat`, derived ids, `styleSelectors`, `beforeNode`/`afterNode`/`flowId`, or a
101
102
  `styleVariant` binding's key — use the factories, `variantFrom` and `activeOn`.
102
103
  11. **A switch is named for how it leaves its default.** `toggleState` turns a key nobody has set yet ON, so a key
@@ -24,7 +24,7 @@ const declaration = {
24
24
 
25
25
  const seatPicker = defineElement<{ rows?: number }>(declaration);
26
26
 
27
- // `authorSpace(recipe, { plugins })` — in a project, `src/plugins/declarations.ts` lists them all.
27
+ // `authorSpace(recipe, { plugins })` — in a project, every `src/plugins/<Name>/declaration.ts`, found by folder.
28
28
  export const plugins: PluginDeclarationData[] = [declaration];
29
29
 
30
30
  export const recipe: SpaceSpec = {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Data in a server project (`create --mode server`): a JSON file the project serves (`public/data/plans.json`), read
3
- * by the page server before it answers — so the page arrives with the plans in its HTML, their anchors in place, and
4
- * nothing to fetch once the browser has it.
2
+ * Data in a server project (`create --mode server`): a JSON file of the project's own (`src/data/plans.json`, answering
3
+ * `/data/plans.json`), read by the page server before it answers and never served — so the page arrives with the plans
4
+ * in its HTML, their anchors in place, and nothing to fetch once the browser has it.
5
5
  *
6
6
  * - `runtime: 'server'` on the provider is the whole switch: server data is on unless a space turns it off.
7
7
  * - The answer is read exactly as in the browser — `plans.data.…` — so moving a provider between runtimes changes no
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable quotes -- templates quote their own strings, and read best in the other quotes */
2
2
  /**
3
- * Show data with no backend: a JSON file the project serves (`public/data/products.json`), read by a provider — one
4
- * card per product, a skeleton while it loads, a count, a computed value, and an empty state that never flashes.
3
+ * Show data with no backend, in a project with no server: a JSON file the browser fetches (`public/data/products.json`,
4
+ * public), read by a provider — one card per product, a skeleton while it loads, a count, a computed value, and an
5
+ * empty state that never flashes. A server project reads its `src/data/` on the server instead (`server-data.ts`).
5
6
  */
6
7
  import { apiContainer, container, heading, list, styles, text, listItem } from '@plitzi/sdk-authoring';
7
8
 
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Data typed by a sample of it: `source()` turns the JSON the page reads into names the editor completes and checks —
4
4
  * `site.data.hero.titel` is a type error, not an empty heading. In a project the sample is the file itself:
5
- * `import home from '../../public/data/home.json' with { type: 'json' }`.
5
+ * `import home from '../data/home.json' with { type: 'json' }` — `src/data/`, or `public/data/` with no server.
6
6
  */
7
7
  import { apiContainer, heading, list, source, styles, text, twig, listItem } from '@plitzi/sdk-authoring';
8
8
 
@@ -6,7 +6,7 @@ Search this page for the code in brackets — `[class-and-css]` — rather than
6
6
  `npx @plitzi/cli explain class-and-css`.
7
7
 
8
8
  `authorSpace` reports everything it cannot write in one run, as a `SpaceRefusedError` whose `refusals` each carry
9
- a `code`, the line of your code that wrote the element (`src/site/home.ts:417`) and the nearest named element
9
+ a `code`, the line of your code that wrote the element (`src/space/pages/home.ts:417`) and the nearest named element
10
10
  (`"store-footer" › container[1]`). **Do what the message says.** Never cast past a check, silence it, or move the
11
11
  logic into a plugin to avoid it — the check exists because that declaration renders something other than what it says.
12
12
 
@@ -119,6 +119,7 @@ The space is not written until these are fixed.
119
119
  | `rule-set-mixed` | a style that writes its rules beside `states`, `variants` or `ancestors` instead of under `css` | `{ css: { desktop: { … } }, states: { hover: { … } } }` — the rules under `css`, each of the others beside it |
120
120
  | `selector-invalid` | a `selector` that is not a CSS class name | letters, digits, `-` and `_` |
121
121
  | `selector-taken` | a `selector` that is a declared class, or another element's | `class` to share rules; a selector of an element's own is its alone |
122
+ | `server-data-in-browser` | a provider asking for the project's own data (`/data/…`, read by its server from `src/data/` and never served) from the browser | `runtime: 'server'` on the provider: the page arrives with the data in it |
122
123
  | `server-provider-in-component` | a `runtime: 'server'` element inside a component: the page server resolves a page's and its layouts', never a component's | put the provider on the page, around the instance, and hand the component its rows as a prop |
123
124
  | `setting-misplaced` | `settings.computed` or `settings.channels` written inside `settings` | `computed` and `channels` at the top of the space |
124
125
  | `slot-children` | children handed to an instance outside its slots | `children: { slotName: [ … ] }`; a component with no slots takes no children |
@@ -151,7 +152,7 @@ The space is not written until these are fixed.
151
152
  | `utility-module` | a utility sent to a module — a utility takes none | drop the `on` |
152
153
  | `visibility-as-attribute` | `visibility` bound as an attribute, which no element reads | `visible: { source, template }` |
153
154
  | `visitor-roles` | `settings.visitorRoles` written in a shape the runtime does not read | the shape the message gives |
154
- | `while-running` | `whileRunning` on a step that is not the trigger, or a mode other than `skip`, `parallel`, `queue` | `[whileRunning('queue', onClick()), …]` |
155
+ | `while-running` | `whileRunning` on a step that is not the trigger, or a mode other than `skip`, `parallel`, `queue`, `latest` | `[whileRunning('queue', onClick()), …]` |
155
156
 
156
157
  ## Warned
157
158
 
@@ -159,6 +160,7 @@ The space renders, and renders something you probably did not mean. Fix every on
159
160
 
160
161
  | Code | What was wrong | Write instead |
161
162
  | --- | --- | --- |
163
+ | `action-output-path` | a read of `.data` on a provider fed by a server action — it publishes the action’s output at its root, and `.data` is a `query` provider’s answer | the output’s own field — `apiContainer_feed.stories`, not `apiContainer_feed.data.stories` |
162
164
  | `click-on-static-element` | a click flow on a container, text, heading, image or list item — no keyboard reaches it | the flow on a `button` (it holds children) or a `link` |
163
165
  | `colour-without-dark` | a colour token with no dark value | `{ light, dark, default }` |
164
166
  | `condition-starts-visible` | a computed visibility that shows until its data answers | `visible: { source, template }` |
@@ -211,8 +213,12 @@ Nothing is wrong: the page renders as written. Each is a shorter way to the same
211
213
  | `custom-css-notifications` | the toasts dressed with `.Toastify__toast` rules in `customCss` | `notifications: { font, fontSize, border, shadow, padding, background, text, radius }` |
212
214
  | `custom-css-sdk-default` | `customCss` repeating what the SDK already does for every space — less motion when asked, the theme toggle showing one icon | nothing: remove it |
213
215
  | `heavy-animation` | keyframes animating what the browser repaints or lays out again on every frame — a size, a position, a blur, a shadow, or a colour in a loop — which stutters whenever the page is busy, most of all while it loads | `opacity` and `transform`: a size or a position is `translate`/`scale`, a blur or a shadow is the `opacity` of a layer carrying it; a loop that must animate anything else starts `paused` and runs under `[data-hydrated]` |
216
+ | `literal-colour` | a colour written out in a class where the space has a token of that value — it stays put in the dark scheme | `var(--token)` when it should follow the scheme; a token of one value of its own when it must stay the same in both |
214
217
  | `repeated-on-pages` | the same block — a header, a footer, a side panel — written into several pages | a layout holding it once (`layouts`, and `layout: { id, slot }` on each page) — a component when only some pages of a layout carry it; a link marks its own page with the `current` state |
215
218
  | `repeated-shape` | the same structure written again and again with different words — cards, rows, tiles | a component with props (`components`, `component(id, { props })`), or one `list` when they are rows of data side by side — a few cards a person rewords on the canvas can stay cards |
219
+ | `unused-class` | a class declared in `classes` that no element, binding, flow or other class names | remove it from `classes` — or wear it where it was meant to go |
220
+ | `unused-component` | a component no page, layout or other component places | remove it from `components`, or place it where it was meant to go |
221
+ | `unused-token` | a token of `variables` no `var(--…)` reads — not a class, an element, `customCss` nor another token | remove it, or write it where its colour is written out |
216
222
 
217
223
  ## UPPER_CASE codes
218
224
 
@@ -62,7 +62,9 @@ variables: {
62
62
  - **`tokens(variables)`** names them for a rule: declare the variables once (`satisfies SpaceSpec['variables']`), hand
63
63
  the same object to the space, and `const t = tokens(variables)` gives `t.primary === 'var(--primary)'` — a name the
64
64
  space does not declare is a type error. A `var(--x)` written by hand that nothing declares is warned
65
- `unknown-variable`; one that may be missing on purpose takes a fallback, `var(--x, 8px)`.
65
+ `unknown-variable`; one that may be missing on purpose takes a fallback, `var(--x, 8px)`. The other way round, a token
66
+ nothing reads is suggested `unused-token`, and a class painted from the palette that types one of its colours out
67
+ `literal-colour` — see [efficiency](efficiency.md#what-it-declares-and-never-uses).
66
68
  - Choose each value against its own background: a colour picked on white is not the same colour on near-black.
67
69
  - Fixed colours are only for surfaces that are fixed in both themes (a brand panel that is always dark) — and then
68
70
  the text on them is fixed too. Theme-following text on a fixed background is the bug.
@@ -13,8 +13,8 @@ text({ bind: [{ to: 'content', source: 'posts.title', when: { … } }] })
13
13
 
14
14
  `from` binds what the type shows — a text's, heading's, paragraph's or button's `content`, an image's `src`, a link's
15
15
  `href`, a list's `items` — and leaves it empty until the data answers. `as` shows it through a template (`source` is
16
- the value), or a format the space names once in `formats: { price: "{{ source|currency('USD') }}" }` (filters
17
- `currency` and `percent` are there for exactly this). `bind` is for every other attribute;
16
+ the value), or a format the space names once in `formats: { price: "{{ source|currency('USD') }}" }` (the
17
+ `currency` and `percent` filters). `bind` is for every other attribute;
18
18
  `bindTemplate(to, source, template, { category?, returns? })` is the computed attribute — a template over the value
19
19
  at `source`. `returns: 'value'` hands over what a single `{{ expression }}` evaluates to instead of its text: a list's
20
20
  `items`, a number, a flag (see [lists](lists.md)).
@@ -27,7 +27,8 @@ completed from what the element publishes (`apiContainer_posts`, `list_postList`
27
27
  The binding's `source` is completed for you; its template is read as written, so the short name there is refused.
28
28
 
29
29
  An element re-renders when anything it reads changes: the first part of each binding's `source` and every source its
30
- templates name. The globals are `variables`, `navigation` (`routeParams`, `queryParams`, `origin`, `currentPageId`),
30
+ templates name. The globals are `variables`, `navigation` (`routeParams`, `queryParams`, `origin`, `currentPageId`,
31
+ `pending` / `pendingLocation` while a link waits for its page's server data),
31
32
  `auth` (who is signed in, `status` while that is being found out), `state` (what flows wrote), `theme`
32
33
  (`mode`, `resolved`), `host` (the `hostData` an application embedding the space hands the SDK) and `computed` (below).
33
34
 
@@ -60,14 +61,19 @@ apiContainer({ id: 'board', runtime: 'server', action: 'queue-board' })
60
61
  ```
61
62
 
62
63
  - A provider's source is readable by its **descendants** only. Wrap what reads it; a sibling cannot see it.
63
- - It publishes `data` plus `isLoading`, `isEmpty`, `hasError`, `errorMessage` — bind a state to those, not to guesses.
64
- A `query`'s body is `data` in **either runtime** (`p.data.plans`), so moving a provider to the server changes no
65
- binding. A connector publishes `records` (or `record`), an action its output.
64
+ - It publishes its answer plus `isLoading`, `isEmpty`, `hasError`, `errorMessage` — bind a state to those, not to
65
+ guesses. A `query`'s body is `data` in **either runtime** (`p.data.plans`), so moving a provider to the server
66
+ changes no binding. A connector publishes `records` (or `record`). **An action publishes its output at the root**:
67
+ `apiContainer_board.columns`, never `.data.columns` (warned `action-output-path`).
66
68
  `isEmpty` reads what arrived: a `query`'s body when it is missing, `null`, `''`, `[]` or `{}`; a connector list by
67
69
  its `records`; a `singleRecord` provider by its `record`. It is also true before the first answer, so pair it with
68
70
  `not isLoading` for an empty state.
69
71
  - A query that depends on state is a binding on `query`; it answers `''` (and fetches nothing) until the state exists:
70
- `"{{ source ? apiUrl ~ '/workspaces/' ~ source ~ '/stats' : '' }}"` with `source: 'state.workspace.id'`.
72
+ `"{{ source ? apiUrl ~ '/workspaces/' ~ source ~ '/stats' : '' }}"` with `source: 'state.workspace.id'`. A server
73
+ provider's bound `input` (`bindTemplate('input', 'state.c', '{{ { country: source } }}', { returns: 'value' })`)
74
+ asks again on every change; `reloadApi('p', { … })` asks once.
75
+ - `isLoading` is true while it is asked again, in either runtime. A newer ask drops the older one; `cancelApi('p')` is a
76
+ STOP: what is shown stays.
71
77
  - `runtime: 'server'` is resolved by the page server — server data is on unless a space says `rsc: { enabled: false }`.
72
78
  Only a page and its layouts are resolved — never inside a component: keep the provider on the page and hand the
73
79
  component its rows as a prop ([recipes/server-data.ts](../recipes/server-data.ts)).
@@ -79,21 +85,17 @@ see [typed-sources.md](typed-sources.md).
79
85
 
80
86
  ### Data in a project with no backend
81
87
 
82
- An offline project (`offlineMode`) still never invents data: the content lives in JSON files the project serves
83
- (`public/data/games.json`, served in either mode) and a provider reads them like any API — `apiContainer({ id: 'catalog', query:
84
- '/data/games.json', cache: true, children: [ … ] })`. The page binds to `catalog.data.…` exactly as it would to a live
85
- backend, so swapping the file for a real endpoint later changes one `query`. `mockData` is what the BUILDER shows while
86
- editing; it is not a data source for the running page. Say on the page that demo content is demo content.
87
-
88
- **`public/` is on the internet.** Every file in it is served to anyone who asks, as it is, once the project is deployed —
89
- and so is everything the space's documents hold (pages, variables, attributes, `mockData`): they reach every visitor's
90
- browser. Never put a secret, a key, a private document or data only some visitors may read in either. A secret is a
91
- credential that an action or a connector names; data for some visitors only comes from a server action whose `access`
92
- checks who is asking, or a `runtime: 'server'` provider behind one.
93
-
94
- **In a server project (`create --mode server`), put the provider on the server** — `runtime: 'server'` — and the page
95
- server reads the file from `public/` itself: the page arrives with those sections (and their anchors) in it. A `query`
96
- with `{{tokens}}` is still read in the browser, against the visitor's route and state.
88
+ Content lives in JSON files read like any API — `apiContainer({ id: 'catalog', query: '/data/games.json', children:
89
+ [ … ] })` — so a real endpoint later changes one `query`. `mockData` is only what the BUILDER shows. Say demo is demo.
90
+
91
+ - **Server project:** `src/data/games.json` answers `/data/games.json`, read by the server, never served. The provider
92
+ is `runtime: 'server'` (the page arrives with it); a browser one is refused (`server-data-in-browser`).
93
+ - **No server:** `public/data/`, fetched — public.
94
+
95
+ **`public/` is on the internet**, and so is everything the space's documents hold (pages, variables, attributes,
96
+ `mockData`) and what a provider reads into a page: never a secret, a key or data only some visitors may read. A secret
97
+ is a credential an action or a connector names; data for some visitors, or fields a page must not carry, comes from a
98
+ server action answering only what is shown, its `access` checking who asks.
97
99
 
98
100
  ### Live, cached, refreshed
99
101
 
@@ -20,3 +20,27 @@ compile — GLSL ES 1.0 wants `196.0`, not `196` — throws a `ShaderError` with
20
20
  `[plugin <type> "<id>"] fragment shader failed: …` (`plitzi check` lists it under the console) and `error` says it;
21
21
  show the still image meanwhile, as above. `useAnimationFrame(onFrame, { target })` is the same loop for motion that
22
22
  is not a canvas.
23
+
24
+ ## Drawing a lot
25
+
26
+ A canvas with thousands of shapes on it — a whiteboard, a diagram, a map of points — is judged on a slower machine than
27
+ yours: sixty frames a second here says nothing about a four-year-old laptop. What keeps one fast is doing work in
28
+ proportion to what CHANGED, not to what is there:
29
+
30
+ - **Two layers.** Paint what stands still on one canvas and leave it; clear and draw the one over it every frame, with
31
+ only what moves: the cursor, the selection, what is being dragged.
32
+ - **Repaint the part that changed.** Something added, edited or removed repaints the area it was and is in, clipped,
33
+ with whatever reaches into it — not the whole board. A pan moves the picture already painted by whole device pixels
34
+ and paints the edges it uncovers.
35
+ - **Draw a dragged group once.** Everything picked up moves by the same amount at every step: draw it to a canvas of its
36
+ own when the drag begins and copy that into place after.
37
+ - **Cache per object, not per frame.** Treat elements as immutable and key what is derived from one — its bounds, its
38
+ shape, a resolved connector — on the object itself (a `WeakMap`), so nothing is worked out twice for the same thing.
39
+ - **Hand the space outcomes, not motion.** A stroke finished, a selection changed: a trigger each. Firing one at every
40
+ pointer move runs a flow and renders the page at every pointer move.
41
+ - **Measure with a bench, throttled.** A script that drives the real thing in a browser with the CPU slowed
42
+ (`Emulation.setCPUThrottlingRate`) and reports script time per frame, not only frames per second — and a test that
43
+ counts WORK (full repaints, strokes drawn during a drag), which holds on any machine where a timing does not.
44
+
45
+ Pizarra, the collaborative whiteboard on the platform (`pizarra.plitzi.app`), does all of it on a board of thousands
46
+ of elements.
@@ -19,8 +19,9 @@ const { warnings, suggestions } = authorSpace(space);
19
19
  is a bug to fix; a suggestion is a shorter way to the same page — take it unless you have a reason not to, and the
20
20
  reason is usually that the copies are about to diverge. `npx @plitzi/cli explain repeated-on-pages` explains any code.
21
21
 
22
- Left on purpose, say so where it is written — `quiet` on an element it is about, and it is not offered again, in the
23
- builder or over MCP either (it is kept in the document):
22
+ Left on purpose, say so where it is written — `quiet` on an element it is about (a component's instance too:
23
+ `component(id, { quiet })`), and it is not offered again, in the builder or over MCP either (it is kept in the
24
+ document):
24
25
 
25
26
  ```ts
26
27
  const includes = (words: string) => container({ class: row, quiet: ['repeated-shape'], children: [tick, text(words)] });
@@ -42,6 +43,22 @@ Only a suggestion's code: a problem is never quieted (`quiet-unknown`).
42
43
  | `.Toastify__toast { font-family: …; border: … }` in `customCss` | `notifications: { font, fontSize, border, shadow, padding, … }` | `custom-css-notifications` |
43
44
  | Keyframes animating `width`, `top`, `filter: blur()`, `box-shadow`, a colour in a loop | `opacity` and `transform`; decoration held until `[data-hydrated]` — [motion](colours-and-motion.md) | `heavy-animation` |
44
45
 
46
+ ## What it declares and never uses
47
+
48
+ A big space gathers what nothing reads any more: the class kept after the last element wearing it went, the token
49
+ nobody points at, the component no page places — and the colour typed out where its token was meant. Each is one more
50
+ thing the next reader has to check is safe to change. `authorSpace` names them too:
51
+
52
+ | What it found | What to do | Suggestion |
53
+ | --- | --- | --- |
54
+ | A class in `classes` that no element, binding, flow or other class's `ancestors` names | Remove it — or wear it where it was meant to go | `unused-class` |
55
+ | A token in `variables` that no `var(--…)` reads — not a class, an element, `customCss` nor another token | Remove it, or write it where its colour is typed out | `unused-token` |
56
+ | A component that no page, layout or other component places | Remove it, or place it where it was meant to go | `unused-component` |
57
+ | A colour typed out in a class painted from the palette, equal to a token's light value | `var(--token)` when it should follow the scheme; a token of one value of its own when it must stay the same in both (dark words on a light chip) | `literal-colour` |
58
+
59
+ They are read generously, so they are never wrong: a name counts as used wherever it appears as a word, and a class
60
+ written all in literals — a sticker's paper and ink, a swatch — is a palette of its own and not named.
61
+
45
62
  And a few the suggestions do not count, because they cost styles rather than elements:
46
63
 
47
64
  - **A look used twice is a class**, written once with `styles()`; every element of a TYPE dressed the same way is the
@@ -31,6 +31,9 @@ same flags, decided on the server. Use the step builders — they fill in where
31
31
  key for hiding it (`sidebarCollapsed`).
32
32
  - **A trigger fired again while its flow runs is IGNORED** (`skip`, the default — no double submit). For a stream of
33
33
  events that must each run, wrap the trigger: `whileRunning('queue', on('onArrival'))` (in order) or `'parallel'`.
34
+ Where only the newest firing matters — a search as you type — `whileRunning('latest', …)`: the run in progress
35
+ stops (no further step; its server action or request is cancelled) and the new one runs. With a `delay(450)` first
36
+ it is a debounce: each firing stops the one still waiting, and only the last gets past the wait.
34
37
  - **Each step reads the page as it is when it runs.** A `when` or a `{{ state.x }}` after a `setState` sees the new
35
38
  value, and one after a `delay` or a server action sees whatever changed meanwhile. To act on the value from BEFORE
36
39
  a write, put the step that reads it first.
@@ -113,31 +113,16 @@ this replaces.
113
113
 
114
114
  ## Pages from a factory
115
115
 
116
- When pages share a shape — a heading, a lede, content, a footer — the shape is a function and each page is its data:
116
+ When pages share a shape — a heading, a lede, content, a footer — the shape is written once and each page is its data,
117
+ with `pageFamily`: it gives every page its id, slug, titles, folder and this layout, and prefixes the ids each body
118
+ gives (see [structure](structure.md#pages-of-one-shape-are-a-family)):
117
119
 
118
120
  ```ts
119
- export const docsPage = (id: string, markdownSource: string): PageSpec => {
120
- const entry = docsEntry(id); // title, slug, lede from nav.ts
121
-
122
- return {
123
- id,
124
- name: entry.title,
125
- slug: entry.slug,
126
- seoTitle: `${entry.title} — Docs`,
127
- seoDescription: entry.lede,
128
- folder: 'docs',
129
- layout: { id: 'docs-layout', slot: 'docs-slot' },
130
- body: [
131
- container({
132
- id: `${id}-main`, // prefixed: this function runs once per page
133
- class: main,
134
- children: [heading(entry.title, { id: `${id}-title`, class: title }), markdown(markdownSource, { id: `${id}-md` }), ...footer(id)]
135
- })
136
- ]
137
- };
138
- };
139
-
140
- export const quickstart = docsPage('docs-quickstart', `## One command …`);
121
+ pages: pageFamily(
122
+ { folder: 'docs', layout: { id: 'docs-layout', slot: 'docs-slot' }, seoTitle: entry => `${entry.title} — Docs`,
123
+ body: entry => [container({ id: 'main', class: main, children: [heading({ id: 'title', content: entry.title, class: title }), markdown(entry.source, { id: 'md' })] })] },
124
+ DOCS // [{ id: 'docs-quickstart', title, slug, description, source }] — the same list the sidebar reads
125
+ )
141
126
  ```
142
127
 
143
128
  Every page is now its content and nothing else, and every page is guaranteed the same structure.
@@ -28,8 +28,8 @@ An element renders again when something it READS changes, and only then:
28
28
  moment-to-moment state inside a plugin and hand the space the outcome (`onCommit`, `onSelectionChange`), not every
29
29
  step of it.
30
30
  - **`whileRunning`** decides what a trigger fired again does while its flow runs: `skip` (the default) drops it,
31
- `queue` runs it after, `parallel` alongside. A burst of events queued behind a slow request is a burst of renders
32
- later.
31
+ `queue` runs it after, `parallel` alongside, `latest` stops the one running. A burst of events queued behind a slow
32
+ request is a burst of renders later — for a search, `latest`.
33
33
 
34
34
  ## What mounts
35
35
 
@@ -9,13 +9,8 @@ custom({ id: 'arcade', renderType: 'nebulaRun', shipColor: 'amber', bind: { best
9
9
 
10
10
  ## Creating one
11
11
 
12
- The CLI writes it, in the shape Plitzi's own elements are written in:
13
-
14
- ```bash
15
- npx @plitzi/cli add plugin seat-picker legend # elements of this project (src/plugins/<Name> in a CLI project)
16
- npx @plitzi/cli create seat-picker --plugin # a package of its own, with a preview
17
- npx @plitzi/cli pack plugin # built, with its manifest and the zip the builder takes
18
- ```
12
+ The CLI writes it, in the shape Plitzi's own elements are written in: `npx @plitzi/cli add plugin seat-picker` (a
13
+ package of its own and packing it: the CLI skill).
19
14
 
20
15
  One folder, four files: `SeatPicker.tsx` (the component), `declaration.ts` (its `type`, the `triggers` it fires, the
21
16
  `callbacks` it answers to, and the element the builder adds — data only), `Settings.tsx` (its panel in the builder), and
@@ -38,8 +33,7 @@ by the same name, and so does whatever a binding writes — which is what makes
38
33
  panel edits for a plugin it has no controls for; from code, write attributes. A `settings` that is not JSON renders
39
34
  "Settings Malformed" in the page.
40
35
 
41
- Every prop is optional and has a default: an attribute not authored yet, or a binding whose source has not answered,
42
- is `undefined`, and a plugin that renders nothing then is a hole in the page.
36
+ Every prop is optional with a default: an attribute not authored yet, or a binding not answered yet, is `undefined`.
43
37
 
44
38
  ## The component
45
39
 
@@ -73,7 +67,36 @@ const stop = state.subscribe(next => save(next)); // called after every cha
73
67
  ```
74
68
 
75
69
  `state` is the current value, `setState` replaces it (or takes an updater), `setStateByKey` writes one key,
76
- `clearState` empties it, `subscribe` listens. Bindings on `state.*` re-render at once.
70
+ `clearState` empties it, `subscribe` listens. Bindings on `state.*` re-render at once. With the space's `keepState`
71
+ on ([kept state](kept-state.md)), what a plugin writes there — its layout, a choice — is back after a reload too.
72
+
73
+ ## Laying out the space's elements
74
+
75
+ A plugin that arranges elements — a dock, tabs, a masonry — HOLDS them: they are its children in the space
76
+ (`custom({ renderType: 'dock', children: [feed, tools] })`, or dropped into it in the builder), and the component
77
+ places each in a box of its own, by the id it was authored under:
78
+
79
+ ```tsx
80
+ import { elementChildren } from '@plitzi/plitzi-sdk';
81
+
82
+ {elementChildren(children).map(({ id, node }) => <section key={id} style={placed[id]}>{node}</section>)}
83
+ ```
84
+
85
+ Never write `style` onto an element the plugin does not render: nothing promises to keep it. Its boxes share one
86
+ stacking context, the plugin's. `useDisplayMode()` names the breakpoint showing — `desktop`, `tablet` or `mobile` — at
87
+ the widths the space's styles use, instead of a width of the plugin's own.
88
+
89
+ ## Its own server code
90
+
91
+ `plitzi add plugin board --server` writes `functions/index.ts` in its folder (the CLI skill). Its routes answer
92
+ under `/fn/plugins/board/`; the component names them, with nothing for the space to wire:
93
+
94
+ ```tsx
95
+ const route = usePluginRoute('board'); // from '@plitzi/plitzi-sdk'
96
+ const url = route('/layout'); // undefined where no server runs code (the canvas)
97
+ ```
98
+
99
+ Its `ctx.kv` is the plugin's own; the space's credentials and channels are not.
77
100
 
78
101
  ## Talking to other pages
79
102
 
@@ -104,13 +127,12 @@ import { useFlag } from '@plitzi/plitzi-sdk';
104
127
  const newChart = useFlag('newChart'); // false for a flag the space does not declare
105
128
  ```
106
129
 
107
- Gating the whole plugin needs no code: give its element `flag: 'newChart'`. `useFlag` is for a plugin that changes
108
- inside — a new mode, an extra panel.
130
+ Gating the whole plugin needs no code: give its element `flag: 'newChart'`.
109
131
 
110
132
  ## Drawing and animating
111
133
 
112
- A canvas, WebGL or a loop of its own: `useCanvas2d`, `useWebGL`, `useWebGL2` and `useAnimationFrame` — see
113
- [drawing](drawing.md).
134
+ A canvas, WebGL or a loop of its own: `useCanvas2d`, `useWebGL`, `useWebGL2` and `useAnimationFrame` — and keeping one
135
+ with thousands of shapes fast — see [drawing](drawing.md).
114
136
 
115
137
  ## Registering
116
138
 
@@ -154,6 +176,10 @@ A plugin says what HAPPENED through its events (`onPick`, with the seat in the p
154
176
  decide what that means — write `state`, open a modal, call a server action. Prefer that to writing `state` from inside
155
177
  the component: the flow is visible in the space, the builder shows it, and the same act can come from a button too.
156
178
 
179
+ - A param declared `number` or `boolean` arrives as one, written or bound; any other arrives as written.
180
+ - To act when another element appears, `useElementVisible('tools')` (`@plitzi/plitzi-sdk`) — never watch classes.
181
+ - A name for screen readers is a prop of its own: declare `label`, write it as the root's `aria-label`.
182
+
157
183
  ## Behaving in the builder
158
184
 
159
185
  The builder draws the element on its canvas while somebody edits the page: a click selects it, a drag moves it, a key
@@ -162,10 +188,21 @@ belongs to the editor.
162
188
  - **Outside preview, do nothing on your own.** `usePlitziServiceContext().settings.previewMode` is `false` while the
163
189
  page is edited. Declared interactions are already held back then; your own click handlers, timers, global listeners,
164
190
  permission prompts and map gestures are not — gate them on `previewMode`, and still render something to select.
191
+ - **A drag lives in state, not in refs read while rendering** (the project's lint refuses that): keep the gesture
192
+ in `useState`, mirror the latest props into a ref inside an effect, and attach `pointermove` on `pointerdown`.
165
193
  - **Never the global `window` or `document`.** The canvas is a frame of its own and the code runs in the builder's
166
194
  window: listen, measure and go full screen through the node's own page (`ref.current.ownerDocument`, its
167
195
  `defaultView`) or `usePlitziServiceContext().utils.getWindow()`. An `instanceof` check takes its class from there too.
168
196
 
197
+ ## The plugin's stylesheet and the space's CSS
198
+
199
+ A plugin's stylesheet ships in a layer below the space's (`plitzi-sdk-plugin`, written by the build): the space's
200
+ classes and `customCss` win over it whatever their specificity, as over a built-in element's defaults.
201
+
202
+ A file a library needs whole is imported as Vite imports it, and travels inside the bundle: `worker.js?raw` is its
203
+ text (a worker, started from `URL.createObjectURL(new Blob([source]))`), `engine.wasm?inline` a data URI. Images and
204
+ fonts a stylesheet names are carried the same way.
205
+
169
206
  ## Components that draw into DOM they do not render
170
207
 
171
208
  A map, a chart library, anything that positions its own markers or popups: its roots are the library's to place. Never
@@ -173,27 +210,3 @@ give them a class that sets `position` — the element falls into the page's flo
173
210
  the look in the plugin's own stylesheet (imported CSS ships beside the bundle) and take colours from custom properties
174
211
  the space sets (`--seat-accent: var(--accent)` in `customCss`); a canvas or WebGL layer resolves them through a probe
175
212
  element with `getComputedStyle(probe).color`, again whenever `theme.resolved` changes (bind it as a prop).
176
-
177
- ## Components that draw a lot
178
-
179
- A canvas with thousands of shapes on it — a whiteboard, a diagram, a map of points — is judged on a slower machine than
180
- yours: sixty frames a second here says nothing about a four-year-old laptop. What keeps one fast is doing work in
181
- proportion to what CHANGED, not to what is there:
182
-
183
- - **Two layers.** Paint what stands still on one canvas and leave it; clear and draw the one over it every frame, with
184
- only what moves: the cursor, the selection, what is being dragged.
185
- - **Repaint the part that changed.** Something added, edited or removed repaints the area it was and is in, clipped,
186
- with whatever reaches into it — not the whole board. A pan moves the picture already painted by whole device pixels
187
- and paints the edges it uncovers.
188
- - **Draw a dragged group once.** Everything picked up moves by the same amount at every step: draw it to a canvas of its
189
- own when the drag begins and copy that into place after.
190
- - **Cache per object, not per frame.** Treat elements as immutable and key what is derived from one — its bounds, its
191
- shape, a resolved connector — on the object itself (a `WeakMap`), so nothing is worked out twice for the same thing.
192
- - **Hand the space outcomes, not motion.** A stroke finished, a selection changed: a trigger each. Firing one at every
193
- pointer move runs a flow and renders the page at every pointer move.
194
- - **Measure with a bench, throttled.** A script that drives the real thing in a browser with the CPU slowed
195
- (`Emulation.setCPUThrottlingRate`) and reports script time per frame, not only frames per second — and a test that
196
- counts WORK (full repaints, strokes drawn during a drag), which holds on any machine where a timing does not.
197
-
198
- Pizarra, the collaborative whiteboard on the platform (`pizarra.plitzi.app`), does all of it on a board of thousands
199
- of elements.
@@ -9,6 +9,8 @@ of it; each line is something that has shipped broken before.
9
9
  - [ ] Every **suggestion** is taken, or left for a reason you can say (the copies are about to diverge; three cards a
10
10
  person rewords on the canvas) — and then quieted where it is written, `quiet: ['repeated-shape']`, so it stops
11
11
  burying the ones that matter. The ones your change opened up first — [efficiency.md](efficiency.md).
12
+ - [ ] `npm run lint:space` is clean — no file past 400 lines, no rows of data inline, no colour that is not a token —
13
+ or each departure says why where it is ([structure.md](structure.md#checked-for-you)).
12
14
  - [ ] No console errors on any page you touched.
13
15
 
14
16
  ## Nothing flashes, nothing jumps