@solidtv/solid 1.7.3 → 1.8.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/MIGRATION-1.8.md +270 -0
  2. package/dist/src/core/dom-renderer/dashedBorderStyle.d.ts +20 -0
  3. package/dist/src/core/dom-renderer/dashedBorderStyle.js +104 -0
  4. package/dist/src/core/dom-renderer/dashedBorderStyle.js.map +1 -0
  5. package/dist/src/core/dom-renderer/domRenderer.d.ts +14 -0
  6. package/dist/src/core/dom-renderer/domRenderer.js +194 -12
  7. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  8. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +12 -2
  9. package/dist/src/core/elementNode.d.ts +176 -9
  10. package/dist/src/core/elementNode.js +1906 -411
  11. package/dist/src/core/elementNode.js.map +1 -1
  12. package/dist/src/core/flexLayout.d.ts +6 -0
  13. package/dist/src/core/flexLayout.js +535 -218
  14. package/dist/src/core/flexLayout.js.map +1 -1
  15. package/dist/src/core/focusManager.js +70 -23
  16. package/dist/src/core/focusManager.js.map +1 -1
  17. package/dist/src/core/fontLoaded.d.ts +10 -0
  18. package/dist/src/core/fontLoaded.js +26 -0
  19. package/dist/src/core/fontLoaded.js.map +1 -0
  20. package/dist/src/core/intrinsicTypes.d.ts +2 -1
  21. package/dist/src/core/lightningInit.js +8 -1
  22. package/dist/src/core/lightningInit.js.map +1 -1
  23. package/dist/src/core/shaders.d.ts +5 -2
  24. package/dist/src/core/shaders.js +6 -0
  25. package/dist/src/core/shaders.js.map +1 -1
  26. package/dist/src/core/states.d.ts +2 -0
  27. package/dist/src/core/states.js +26 -7
  28. package/dist/src/core/states.js.map +1 -1
  29. package/dist/src/core/stylePlan.d.ts +39 -0
  30. package/dist/src/core/stylePlan.js +159 -0
  31. package/dist/src/core/stylePlan.js.map +1 -0
  32. package/dist/src/core/utils.js +2 -2
  33. package/dist/src/primitives/Grid.d.ts +7 -1
  34. package/dist/src/primitives/Grid.jsx +48 -4
  35. package/dist/src/primitives/Grid.jsx.map +1 -1
  36. package/dist/src/primitives/Virtual.jsx +16 -6
  37. package/dist/src/primitives/Virtual.jsx.map +1 -1
  38. package/dist/src/primitives/useMouse.d.ts +10 -5
  39. package/dist/src/primitives/useMouse.js +42 -10
  40. package/dist/src/primitives/useMouse.js.map +1 -1
  41. package/dist/src/primitives/utils/handleNavigation.js +29 -6
  42. package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
  43. package/dist/src/primitives/utils/withScrolling.js +2 -1
  44. package/dist/src/primitives/utils/withScrolling.js.map +1 -1
  45. package/dist/src/solidOpts.js +22 -8
  46. package/dist/src/solidOpts.js.map +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/docs/AI_CODING_GUIDELINES.md +7 -6
  49. package/docs/AI_UPGRADE_1.8.md +290 -0
  50. package/package.json +5 -3
  51. package/src/core/dom-renderer/dashedBorderStyle.ts +128 -0
  52. package/src/core/dom-renderer/domRenderer.ts +201 -10
  53. package/src/core/dom-renderer/domRendererTypes.ts +12 -0
  54. package/src/core/elementNode.ts +2124 -459
  55. package/src/core/flexLayout.ts +583 -231
  56. package/src/core/focusManager.ts +86 -27
  57. package/src/core/fontLoaded.ts +29 -0
  58. package/src/core/intrinsicTypes.ts +2 -0
  59. package/src/core/lightningInit.ts +8 -1
  60. package/src/core/shaders.ts +12 -0
  61. package/src/core/states.ts +29 -9
  62. package/src/core/stylePlan.ts +195 -0
  63. package/src/core/utils.ts +2 -2
  64. package/src/primitives/Grid.tsx +66 -14
  65. package/src/primitives/Virtual.tsx +20 -6
  66. package/src/primitives/useMouse.ts +73 -6
  67. package/src/primitives/utils/handleNavigation.ts +40 -6
  68. package/src/primitives/utils/withScrolling.ts +3 -2
  69. package/src/solidOpts.ts +23 -8
  70. package/dist/src/core/flex.d.ts +0 -2
  71. package/dist/src/core/flex.js +0 -285
  72. package/dist/src/core/flex.js.map +0 -1
  73. package/src/core/flex.ts +0 -332
@@ -2,6 +2,8 @@
2
2
 
3
3
  **System Role:** You are an expert frontend engineer working with a custom TV-UI framework called **Lightning**, built on **SolidTV**.
4
4
 
5
+ **Upgrading an app from 1.7 to 1.8?** Follow [`docs/AI_UPGRADE_1.8.md`](./AI_UPGRADE_1.8.md), shipped in the package as `node_modules/@solidtv/solid/docs/AI_UPGRADE_1.8.md`.
6
+
5
7
  ## 1. Core Architecture & Runtime
6
8
 
7
9
  - **Environment:** TV app development over WebGL (not the DOM). No pointer input; interaction is directional (Up/Down/Left/Right).
@@ -21,8 +23,8 @@
21
23
  ## 3. Flexbox Engine
22
24
 
23
25
  - **Activation:** Set `display: "flex"` on containers to enable flex layout.
24
- - **Padding:** Supports ONLY a single overall `padding` number. (NO `paddingLeft`, `paddingTop`, etc.).
25
- - **Margins:** Supported on items (`marginTop`, `marginBottom`, `marginLeft`, `marginRight`).
26
+ - **Padding:** On the container: a number for all sides, a CSS-style array (`[vertical, horizontal]`, `[top, horizontal, bottom]` or `[top, right, bottom, left]`), or per side with `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`. A per-side prop overrides that side of `padding`.
27
+ - **Margins:** On items: `margin` (a number or the same array forms) and `marginTop`, `marginRight`, `marginBottom`, `marginLeft`.
26
28
  - **Gap:** `gap`, `rowGap`, and `columnGap` are supported.
27
29
  - **Alignment:** Strictly typed properties: `flexDirection` ('row'|'column'), `justifyContent`, `alignItems`, `alignSelf`.
28
30
 
@@ -51,11 +53,11 @@
51
53
 
52
54
  ### Container Flexbox
53
55
 
54
- `display: "flex"`, `flexDirection`, `flexWrap`, `justifyContent`, `alignItems`, `gap`, `rowGap`, `columnGap`, `padding`
56
+ `display: "flex"`, `flexDirection`, `flexWrap`, `justifyContent`, `alignItems`, `gap`, `rowGap`, `columnGap`, `padding`, `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`
55
57
 
56
58
  ### Item Flexbox
57
59
 
58
- `flexGrow`, `flexItem`, `alignSelf`, `marginTop`, `marginBottom`, `marginLeft`, `marginRight`
60
+ `flexGrow`, `flexShrink`, `flexBasis`, `flexOrder`, `flexItem`, `alignSelf`, `margin`, `marginTop`, `marginBottom`, `marginLeft`, `marginRight`
59
61
 
60
62
  ### Visual & Text
61
63
 
@@ -68,14 +70,13 @@
68
70
  - The `style={{}}` Prop (Use native node props instead)
69
71
  - `display: 'grid'`
70
72
  - String literal colors without hex (e.g. `'red'`, `'#F00'`) - Use full hex codes like `'#ff0000ff'`
71
- - Directional paddings (e.g., `paddingLeft`)
72
73
 
73
74
  ## 8. Code Examples
74
75
 
75
76
  **❌ Incorrect:**
76
77
 
77
78
  ```tsx
78
- // Missing dimensions, invalid colors, using styles, directional padding
79
+ // Missing dimensions, invalid colors, CSS properties in a style prop
79
80
  <view
80
81
  style={{
81
82
  backgroundColor: 'red',
@@ -0,0 +1,290 @@
1
+ # Upgrading an app from @solidtv/solid 1.7 to 1.8: checklist for AI agents
2
+
3
+ **System role:** You are upgrading a TV app built on `@solidtv/solid` from 1.7.x
4
+ to 1.8. Work through the steps below in order. Each step names what to search
5
+ the app for, what a match means, and what to change. Most apps need only a few
6
+ of them. Do not change code a step does not point to. When a match is unclear,
7
+ leave the code as it is and list it for the developer.
8
+
9
+ The full description of every change is `MIGRATION-1.8.md`, at the package root
10
+ (`node_modules/@solidtv/solid/MIGRATION-1.8.md`) and in the repository. Read it
11
+ when a step needs more detail.
12
+
13
+ Search commands use `rg` (ripgrep). Run them from the app's root, on its own
14
+ sources only (not `node_modules` or build output). `grep -rnE` takes the same
15
+ patterns.
16
+
17
+ ## 1. Dependencies
18
+
19
+ - Set `@solidtv/solid` to `^1.8.0`.
20
+ - Set `@solidtv/renderer` to `^2.0.11` or later. 1.7.3 accepted `^2.0.7`.
21
+ 1.8 sizes text with the renderer's `TextNode.measure()`, orders siblings
22
+ with `Node.insertBefore`, registers the renderer's `DashedBorder` shader
23
+ (2.0.9), and reads `truncated` from a text's `loaded` (2.0.11). Check the
24
+ peer range with `npm view @solidtv/solid@1.8 peerDependencies`.
25
+ - Reinstall, then confirm the app builds before going on.
26
+
27
+ ## 2. Flex: one engine
28
+
29
+ 1.8 has one flex engine, the one 1.7 used only when `VITE_USE_NEW_FLEX` was set.
30
+
31
+ ```sh
32
+ rg -n "VITE_USE_NEW_FLEX" --hidden -g '!node_modules'
33
+ ```
34
+
35
+ - **Found:** delete it from `.env` files and the Vite config; it is ignored.
36
+ The app already ran on this engine, so its layouts do not change from the
37
+ engine switch. Skip to step 3.
38
+ - **Not found:** the app ran on the old engine. Its flex layouts can move.
39
+ Check each flex container for the cases below.
40
+
41
+ ```sh
42
+ rg -n "display[=:]\s*[\"'{]*flex" src
43
+ ```
44
+
45
+ For each flex container, look for:
46
+
47
+ - **A number `padding` together with `alignItems`, `alignSelf` or
48
+ `flexWrap`.** The padding now also offsets the cross axis: rows start at
49
+ `paddingTop`, and wrapped lines start at the cross padding. If the app added
50
+ its own offset to make up for the missing cross padding, remove that offset.
51
+ - **`flexShrink` on items.** It now shrinks overflowing items (the old engine
52
+ ignored it). A container whose items only have `flexShrink` no longer sizes
53
+ itself to its items; give it an explicit size if it needs one.
54
+ - **`flexBasis` on items.** It now replaces the item's width or height for
55
+ positioning (it was ignored).
56
+ - **Padding arrays, `paddingLeft`/`paddingTop`/`paddingRight`/`paddingBottom`,
57
+ or a `margin` array.** These now work. The old engine produced NaN for them,
58
+ so if the app avoided them with workarounds, the workarounds can stay or be
59
+ simplified. Do not simplify without being asked.
60
+ - **Code that reads flex positions and expects float32 rounding** (such as
61
+ `109.70999908`). Positions are float64 now.
62
+
63
+ ## 3. Flex bug fixes that move layouts
64
+
65
+ These apply to every app, whichever engine it used.
66
+
67
+ | Search for | What changed | What to change |
68
+ | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
69
+ | `justifyContent` `"center"` on a container with `padding` | Items are centred inside the padding (they were shifted by the start padding). | Remove offsets the app added to re-centre them. |
70
+ | `alignItems` or `alignSelf` `"center"` or `"flexEnd"` on a container with cross-axis `padding` | Items stay inside the cross padding (center was offset by `paddingTop`; flexEnd overflowed by it). | Remove compensating offsets. |
71
+ | `flexGrow` or `flexShrink` items | An item is sized from its own size on every layout: a grown item shrinks back when a sibling grows, a shrunk item grows back when the overflow goes away. A grown item used to keep its largest grown size; a shrunk item shrank again on every layout. | Usually nothing. A size the app writes to a grown or shrunk item becomes its own size, which the next layout grows or shrinks from; list such writes for the developer. |
72
+ | `flexGrow` or `flexShrink` items in a container with `padding` | Items share the space inside the padding (grown items overflowed the end padding). | Remove offsets or widths the app adjusted to make up for the overflow. |
73
+ | A row with no `height`, `padding`, and `alignItems` or `alignSelf` | The row's height adds the cross padding to its tallest item (items overflowed the row). | Remove extra height the app added to make up for it. |
74
+ | `flexWrap` on a container with no cross size (no `height` in a row, no `width` in a column) | Wrapped items are placed on their own lines (they overlapped the first line). | Nothing, unless the app worked around the overlap. |
75
+ | `flexWrap="wrap-reverse"` | It wraps now, first line at the end. | Nothing, unless the app worked around it. |
76
+ | `maxLines={1}` with a `lineHeight` of 3 or less | `lineHeight` is read as a multiplier: `maxHeight = lineHeight * fontSize`. | Nothing, unless the app set `maxHeight` to make up for a 1.2 px tall text. |
77
+ | `contain` text with no size, and `marginRight`/`marginBottom` or a `margin` array | The computed `maxWidth`/`maxHeight` subtracts those margins. | Nothing. |
78
+ | `<text flexItem={false}>` with no size | It no longer blocks its container's layout. | Nothing. |
79
+ | `onLayout` on a container that has `flexGrow` children | `onLayout` runs once per layout, with the final layout. It used to run twice. | Remove code that counts calls or skips the first one. |
80
+
81
+ ## 4. Text in flex containers
82
+
83
+ A `<text>` inside a `display="flex"` container, or one with an `onLayout`, is
84
+ now measured by Solid right after the change, before the frame.
85
+
86
+ 1. **Text props written or animated on the renderer node.** Solid is not told
87
+ about these, so the container keeps the old size.
88
+
89
+ ```sh
90
+ rg -n "\.lng\.(text|fontSize|fontFamily|fontStyle|fontWeight|lineHeight|letterSpacing|maxWidth|maxHeight|maxLines|contain|wordWrap|wordBreak|overflowSuffix)\s*=" src
91
+ rg -n "\.lng\.animate\(" src
92
+ ```
93
+
94
+ Change each match to write or animate on the element instead:
95
+ `el.fontSize = 40`, a `transition`, or `el.animate({ fontSize: 40 })`.
96
+ Development builds log this warning when it happens, so run the app and
97
+ check the console:
98
+
99
+ ```text
100
+ [solid] A text in a flex container was laid out at a size Solid did not measure
101
+ ```
102
+
103
+ 2. **Workarounds for layout that arrived late.** Before 1.8, a flex container
104
+ with text was laid out after the text's `loaded` event, a frame later. Code
105
+ that reads a flex-derived `x`, `y`, `width` or `height` at mount (in an
106
+ `onFocus` that fires at mount, an effect, or a `ref` callback) now gets the
107
+ laid-out value instead of 0. Look for code that waited for layout before
108
+ reading it:
109
+
110
+ ```sh
111
+ rg -n "onEvent=\{\{[^}]*loaded|loaded:\s*\(" src
112
+ rg -n "(setTimeout|requestAnimationFrame|queueMicrotask)\(" src
113
+ ```
114
+
115
+ - A `loaded` handler on a text, or on an autosize node, that reads its
116
+ parent's layout: it now runs before the parent's relayout. Read the
117
+ layout in the parent's `onLayout` instead.
118
+ - A `setTimeout` or `requestAnimationFrame` that only waits for flex before
119
+ reading positions: it still works. List it for the developer as
120
+ removable; do not remove it unasked.
121
+ - Code that positions something from a value read at mount, and was tuned
122
+ for that value being 0, can now place the element in a different spot.
123
+ Check such screens in the running app.
124
+
125
+ 3. **Text under hidden or culled ancestors** (alpha 0, outside the bounds
126
+ margin, kept-alive pages) is now measured eagerly. No code change. A page
127
+ with more measured texts than the renderer's `textLayoutCacheSize` (250 by
128
+ default) thrashes the cache; if such a page is slow, raise
129
+ `textLayoutCacheSize` in `Config.rendererOptions`.
130
+
131
+ ## 5. States and style objects
132
+
133
+ 1. **Style objects changed in place.** A `$state` block (`$focus`, `$active`,
134
+ …), and a `border` or `shadow` object, is read once and cached by object
135
+ identity. Changing it later is not seen.
136
+
137
+ ```sh
138
+ rg -n "\.\\\$[a-zA-Z]+\.[a-zA-Z]+\s*=" src
139
+ rg -n "\.(border|borderTop|borderRight|borderBottom|borderLeft|shadow)\.[a-zA-Z]+\s*=" src
140
+ ```
141
+
142
+ For each match that changes an object the app later assigns again (or that
143
+ a style already holds), assign a new object instead:
144
+ `node.border = { ...node.border, width: 4 }`. A getter in a `$state` block
145
+ (`get color() { … }`) is still read every time, so a match inside a getter
146
+ is fine. A `$state` block from a Solid store (`createStore`) is not cached
147
+ either: changes made with the store's setter are seen, keys it adds or
148
+ removes included.
149
+
150
+ 2. **Row and Column `transition` changed in place.** After a key press, a
151
+ Row's or Column's `transition` is a merged object cached per direction. An
152
+ in-place edit of the base `transition` is not seen.
153
+
154
+ ```sh
155
+ rg -n "\.transition\.[a-zA-Z]+\s*=" src
156
+ ```
157
+
158
+ Assign a new `transition` object instead.
159
+
160
+ 3. **`States` methods on a copy.** `states.slice()`, `filter()`, `map()`,
161
+ `splice()` and other `Array` methods now return a plain `Array`, without
162
+ `has`, `add` or `toggle`.
163
+
164
+ ```sh
165
+ rg -n "states\.(slice|filter|map|concat|splice|reduce|flat)\(" src
166
+ ```
167
+
168
+ If the result is used as a `States` (`.has(`, `.add(`, `.toggle(`,
169
+ `.remove(`), call those methods on `node.states` instead.
170
+
171
+ 4. **`remove` or `toggle` with a bare name.** `states.remove('focus')` and
172
+ `states.toggle('focus')` now act on `'$focus'` when only `'$focus'` is in
173
+ the list. Before, they did nothing.
174
+
175
+ ```sh
176
+ rg -n "states\.(remove|toggle)\(\s*[\"'][a-zA-Z]" src
177
+ ```
178
+
179
+ Check each match: if the node can carry the `$`-prefixed state, the call
180
+ now changes it. That is usually what the code meant.
181
+
182
+ 5. **A state change writes only the keys whose value changed.**
183
+ - Adding a second state no longer restarts the first state's transition.
184
+ - A value the app writes to a key that a state also sets survives a later
185
+ state change that leaves that key's value unchanged. Before, the next
186
+ state change overwrote it.
187
+ - Search for imperative writes to keys a `$state` block sets on the same
188
+ node (`color`, `alpha`, `scale`, `border`, `shadow`, …). If the code
189
+ relied on a later state change to put the state's value back, write the
190
+ value again itself. The border keys (`border`, `borderTop`, …) are still
191
+ rewritten together when a state change writes one of them.
192
+
193
+ 6. **Re-assigning an unchanged `states` list does nothing.**
194
+
195
+ ```sh
196
+ rg -n "states\s*=\s*[a-zA-Z_.]*states\b" src
197
+ ```
198
+
199
+ `node.states = node.states` used to empty the list and re-apply the
200
+ styles; it is now a no-op. With `forwardStates`, assigning the parent an
201
+ unchanged list no longer resets the children's own states. If the code used
202
+ either to re-apply styles, set the states it wants explicitly.
203
+
204
+ 7. **Shared gradient shaders.** Setting `linearGradient` or `radialGradient`
205
+ again now updates the node's shader in place. If the app assigned one
206
+ node's `lng.shader` to another node and then set the gradient again, both
207
+ nodes change. Give each node its own gradient.
208
+
209
+ 8. **A gradient set to `undefined` is removed.** Setting `linearGradient` or
210
+ `radialGradient` to `undefined` (or `null`) now removes the gradient the
211
+ prop made, and leaves any other shader on the node alone. Before, it drew
212
+ the shader's default gradient in place of the node's shader (a
213
+ `borderRadius`, say).
214
+
215
+ ```sh
216
+ rg -n "(linearGradient|radialGradient)[=:]" src
217
+ ```
218
+
219
+ Check matches whose value can be `undefined`, such as
220
+ `linearGradient={focused() ? gradient : undefined}`. If the screen relied
221
+ on the default gradient showing, pass that gradient explicitly.
222
+
223
+ ## 6. Focus callbacks
224
+
225
+ The whole focus change (`onFocus`, `onBlur`, `onFocusChanged`, `focusPath`,
226
+ `activeElement`) runs in one Solid `batch`. Effects triggered by signals the
227
+ callbacks write run once, after the last callback.
228
+
229
+ ```sh
230
+ rg -n "on(Focus|Blur|FocusChanged)=" src
231
+ ```
232
+
233
+ Look inside each handler for a signal write followed by a read of a node prop
234
+ that an effect sets from that signal. That read now sees the old value. Read
235
+ the signal itself, or move the read into the effect. Handlers that only write
236
+ signals, or only read props, need no change.
237
+
238
+ ## 7. Draw order
239
+
240
+ Overlapping siblings with equal `zIndex` now draw in their `children` order
241
+ after every update, as on first render. Before, a node added later (a `<Show>`
242
+ that appears, a `<For>` item added or moved, a Virtual window shift) was drawn
243
+ after all its siblings.
244
+
245
+ - An overlay, badge or popup shown with `<Show>` or added by `<For>`, that
246
+ must draw over later siblings, needs a higher `zIndex`.
247
+ - A focused tile with a `$focus` `scale` is now covered by its later siblings,
248
+ as on first render. Give the focused state a `zIndex` if it should draw on
249
+ top.
250
+
251
+ ## 8. Removed and ignored writes
252
+
253
+ ```sh
254
+ rg -n "\.(absX|absY|destroyed)\s*=" src
255
+ ```
256
+
257
+ Writes to `absX`, `absY` and `destroyed` are ignored (they threw on renderer
258
+ 2.0). Remove them. Text props written to a `<view>` (`fontSize`, `text`, …)
259
+ stay on the element and no longer reach `view.lng`; read them from the
260
+ element.
261
+
262
+ `src` now accepts a `Blob` (from `fetch().blob()`, say) and shows it on both
263
+ renderers. Before, a `Blob` `src` drew nothing. If the app made its own object
264
+ URL for a `Blob` (`URL.createObjectURL`), that still works; list it for the
265
+ developer as removable, and do not remove it unasked.
266
+
267
+ ## 9. Build setting
268
+
269
+ Find the bundler config (`vite.config.*`, `webpack.config.*`). With terser's
270
+ default `reduce_funcs`, renderer 2.0's scene walk allocates on every node it
271
+ visits. Set:
272
+
273
+ ```js
274
+ build: {
275
+ minify: 'terser',
276
+ terserOptions: { compress: { reduce_funcs: false } },
277
+ },
278
+ ```
279
+
280
+ Install terser if it is missing (`npm i -D terser`). For webpack:
281
+ `new TerserPlugin({ terserOptions: { compress: { reduce_funcs: false } } })`.
282
+
283
+ ## 10. Verify
284
+
285
+ 1. Build the app and run its tests.
286
+ 2. Run it in development mode and check the console for `[solid]` warnings.
287
+ 3. Open the screens with flex layouts, focus styles and overlays changed or
288
+ listed in steps 2 to 7, and compare them with the 1.7 build.
289
+ 4. Report what you changed, and list every match you left alone with the
290
+ reason.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidtv/solid",
3
- "version": "1.7.3",
3
+ "version": "1.8.0-0",
4
4
  "description": "SolidTV",
5
5
  "type": "module",
6
6
  "exports": {
@@ -115,7 +115,7 @@
115
115
  },
116
116
  "peerDependencies": {
117
117
  "@solidjs/router": "^0.16.1",
118
- "@solidtv/renderer": "^2.0.7",
118
+ "@solidtv/renderer": "^2.0.11",
119
119
  "solid-js": "*"
120
120
  },
121
121
  "peerDependenciesMeta": {},
@@ -130,7 +130,9 @@
130
130
  "LICENSE",
131
131
  "NOTICE",
132
132
  "README.md",
133
- "docs/AI_CODING_GUIDELINES.md"
133
+ "MIGRATION-1.8.md",
134
+ "docs/AI_CODING_GUIDELINES.md",
135
+ "docs/AI_UPGRADE_1.8.md"
134
136
  ],
135
137
  "packageManager": "pnpm@10.33.4",
136
138
  "publishConfig": {
@@ -0,0 +1,128 @@
1
+ import type { DashedBorderProps } from '@solidtv/renderer';
2
+
3
+ /**
4
+ * The DOM renderer's `dashedBorder`, in CSS only, so that `dash`, `gap`,
5
+ * `width`, `color` and `radius` draw as the WebGL shader draws them:
6
+ *
7
+ * - each straight side is a repeating linear gradient strip, `width` thick;
8
+ * - with a radius, each corner is a quarter ring (a radial gradient), drawn
9
+ * as one dash, and the straight sides run gap, dash, ..., dash, gap
10
+ * between them; without one, each side starts and ends with a dash, and
11
+ * the corners' dashes meet.
12
+ *
13
+ * On each side the dash and gap are stretched so that a whole number of
14
+ * them fits. A `gap` of 0 or less draws a solid border. Returns '' when
15
+ * nothing is drawn: a `dash`, `width` or colour alpha of 0 or less, or a
16
+ * node without size.
17
+ *
18
+ * Each gradient is written twice, the `-webkit-` syntax first, for older
19
+ * WebKit (e.g. PS4); a browser keeps the last declaration it can read.
20
+ */
21
+ export function dashedBorderStyle(
22
+ w: number,
23
+ h: number,
24
+ props: Partial<DashedBorderProps>,
25
+ ): string {
26
+ const width = props.width ?? 2;
27
+ const color = props.color ?? 0xffffffff;
28
+ const dash = props.dash ?? 10;
29
+ const gap = props.gap ?? 10;
30
+ if (w <= 0 || h <= 0 || width <= 0 || dash <= 0 || (color & 0xff) === 0) {
31
+ return '';
32
+ }
33
+ const rgba = `rgba(${(color >>> 24) & 0xff},${(color >>> 16) & 0xff},${(color >>> 8) & 0xff},${round((color & 0xff) / 255)})`;
34
+ const r = round(Math.max(0, Math.min(props.radius ?? 0, w / 2, h / 2)));
35
+ const px = `${width}px`;
36
+
37
+ // [-webkit- image, image, size, position]
38
+ const layers: [string, string, string, string][] = [];
39
+ const side = (
40
+ length: number,
41
+ dirs: [string, string],
42
+ size: string,
43
+ position: string,
44
+ ) => {
45
+ const stops = strip(length, dash, gap, rgba, r > 0);
46
+ if (stops !== '') {
47
+ layers.push([
48
+ `-webkit-repeating-linear-gradient(${dirs[0]}, ${stops})`,
49
+ `repeating-linear-gradient(${dirs[1]}, ${stops})`,
50
+ size,
51
+ position,
52
+ ]);
53
+ }
54
+ };
55
+ const straightX = round(w - 2 * r);
56
+ const straightY = round(h - 2 * r);
57
+ side(straightX, ['left', 'to right'], `${straightX}px ${px}`, `${r}px 0`);
58
+ side(straightX, ['left', 'to right'], `${straightX}px ${px}`, `${r}px 100%`);
59
+ side(straightY, ['top', 'to bottom'], `${px} ${straightY}px`, `0 ${r}px`);
60
+ side(straightY, ['top', 'to bottom'], `${px} ${straightY}px`, `100% ${r}px`);
61
+
62
+ if (r > 0) {
63
+ // A quarter ring around the corner's centre; the layer's border-radius
64
+ // clips (and smooths) its outer edge.
65
+ const inner = round(r - width);
66
+ const ring =
67
+ inner > 0
68
+ ? `transparent ${round(inner - 0.5)}px, ${rgba} ${round(inner + 0.5)}px, ${rgba} ${r}px, transparent ${r}px`
69
+ : `${rgba} 0, ${rgba} ${r}px, transparent ${r}px`;
70
+ // The corner box's position, and the ring's centre in that box
71
+ const corners: [string, string][] = [
72
+ ['0 0', '100% 100%'],
73
+ ['100% 0', '0 100%'],
74
+ ['0 100%', '100% 0'],
75
+ ['100% 100%', '0 0'],
76
+ ];
77
+ for (const [position, centre] of corners) {
78
+ layers.push([
79
+ `-webkit-radial-gradient(${centre}, circle, ${ring})`,
80
+ `radial-gradient(circle at ${centre}, ${ring})`,
81
+ `${r}px ${r}px`,
82
+ position,
83
+ ]);
84
+ }
85
+ }
86
+
87
+ const list = (i: number) => layers.map((layer) => layer[i]).join(', ');
88
+ return (
89
+ `background-image: ${list(0)};` +
90
+ `background-image: ${list(1)};` +
91
+ `background-size: ${list(2)};` +
92
+ `background-position: ${list(3)};` +
93
+ 'background-repeat: no-repeat;'
94
+ );
95
+ }
96
+
97
+ /**
98
+ * The colour stops of a straight side `length` long. Between rounded
99
+ * corners (which are dashes) it starts and ends with a gap: count dashes,
100
+ * count + 1 gaps. Without corners it starts and ends with a dash: count
101
+ * dashes, count - 1 gaps. '' when the side holds no dash.
102
+ */
103
+ function strip(
104
+ length: number,
105
+ dash: number,
106
+ gap: number,
107
+ rgba: string,
108
+ betweenCorners: boolean,
109
+ ): string {
110
+ if (length <= 0) return '';
111
+ if (gap <= 0) return `${rgba} 0, ${rgba} ${length}px`;
112
+ const pair = dash + gap;
113
+ const gaps = betweenCorners ? 1 : -1;
114
+ const count = Math.max(
115
+ betweenCorners ? 0 : 1,
116
+ Math.round((length - gaps * gap) / pair),
117
+ );
118
+ if (count === 0) return '';
119
+ const scale = length / (count * dash + (count + gaps) * gap);
120
+ const d = round(dash * scale);
121
+ const g = round(gap * scale);
122
+ const p = round(d + g);
123
+ return betweenCorners
124
+ ? `transparent 0, transparent ${g}px, ${rgba} ${g}px, ${rgba} ${p}px`
125
+ : `${rgba} 0, ${rgba} ${d}px, transparent ${d}px, transparent ${p}px`;
126
+ }
127
+
128
+ const round = (n: number) => Math.round(n * 1000) / 1000;