@solidtv/solid 1.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 (237) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +95 -0
  4. package/dist/jsx-runtime.d.ts +14 -0
  5. package/dist/src/activeElement.d.ts +2 -0
  6. package/dist/src/activeElement.js +3 -0
  7. package/dist/src/activeElement.js.map +1 -0
  8. package/dist/src/core/config.d.ts +51 -0
  9. package/dist/src/core/config.js +37 -0
  10. package/dist/src/core/config.js.map +1 -0
  11. package/dist/src/core/dom-renderer/domRenderer.d.ts +138 -0
  12. package/dist/src/core/dom-renderer/domRenderer.js +1844 -0
  13. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -0
  14. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +110 -0
  15. package/dist/src/core/dom-renderer/domRendererTypes.js +2 -0
  16. package/dist/src/core/dom-renderer/domRendererTypes.js.map +1 -0
  17. package/dist/src/core/dom-renderer/domRendererUtils.d.ts +23 -0
  18. package/dist/src/core/dom-renderer/domRendererUtils.js +232 -0
  19. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -0
  20. package/dist/src/core/elementNode.d.ts +508 -0
  21. package/dist/src/core/elementNode.js +928 -0
  22. package/dist/src/core/elementNode.js.map +1 -0
  23. package/dist/src/core/flex.d.ts +2 -0
  24. package/dist/src/core/flex.js +284 -0
  25. package/dist/src/core/flex.js.map +1 -0
  26. package/dist/src/core/flexLayout.d.ts +2 -0
  27. package/dist/src/core/flexLayout.js +360 -0
  28. package/dist/src/core/flexLayout.js.map +1 -0
  29. package/dist/src/core/focusKeyTypes.d.ts +42 -0
  30. package/dist/src/core/focusKeyTypes.js +2 -0
  31. package/dist/src/core/focusKeyTypes.js.map +1 -0
  32. package/dist/src/core/focusManager.d.ts +13 -0
  33. package/dist/src/core/focusManager.js +270 -0
  34. package/dist/src/core/focusManager.js.map +1 -0
  35. package/dist/src/core/index.d.ts +14 -0
  36. package/dist/src/core/index.js +11 -0
  37. package/dist/src/core/index.js.map +1 -0
  38. package/dist/src/core/intrinsicTypes.d.ts +106 -0
  39. package/dist/src/core/intrinsicTypes.js +2 -0
  40. package/dist/src/core/intrinsicTypes.js.map +1 -0
  41. package/dist/src/core/lightningInit.d.ts +9 -0
  42. package/dist/src/core/lightningInit.js +34 -0
  43. package/dist/src/core/lightningInit.js.map +1 -0
  44. package/dist/src/core/nodeTypes.d.ts +6 -0
  45. package/dist/src/core/nodeTypes.js +6 -0
  46. package/dist/src/core/nodeTypes.js.map +1 -0
  47. package/dist/src/core/shaders.d.ts +52 -0
  48. package/dist/src/core/shaders.js +86 -0
  49. package/dist/src/core/shaders.js.map +1 -0
  50. package/dist/src/core/states.d.ts +12 -0
  51. package/dist/src/core/states.js +84 -0
  52. package/dist/src/core/states.js.map +1 -0
  53. package/dist/src/core/utils.d.ts +39 -0
  54. package/dist/src/core/utils.js +164 -0
  55. package/dist/src/core/utils.js.map +1 -0
  56. package/dist/src/devtools/index.d.ts +6 -0
  57. package/dist/src/devtools/index.js +65 -0
  58. package/dist/src/devtools/index.js.map +1 -0
  59. package/dist/src/index.d.ts +9 -0
  60. package/dist/src/index.js +7 -0
  61. package/dist/src/index.js.map +1 -0
  62. package/dist/src/primitives/Column.d.ts +3 -0
  63. package/dist/src/primitives/Column.jsx +25 -0
  64. package/dist/src/primitives/Column.jsx.map +1 -0
  65. package/dist/src/primitives/FPSCounter.d.ts +4 -0
  66. package/dist/src/primitives/FPSCounter.jsx +188 -0
  67. package/dist/src/primitives/FPSCounter.jsx.map +1 -0
  68. package/dist/src/primitives/FadeInOut.d.ts +18 -0
  69. package/dist/src/primitives/FadeInOut.jsx +39 -0
  70. package/dist/src/primitives/FadeInOut.jsx.map +1 -0
  71. package/dist/src/primitives/Grid.d.ts +23 -0
  72. package/dist/src/primitives/Grid.jsx +100 -0
  73. package/dist/src/primitives/Grid.jsx.map +1 -0
  74. package/dist/src/primitives/Image.d.ts +8 -0
  75. package/dist/src/primitives/Image.jsx +42 -0
  76. package/dist/src/primitives/Image.jsx.map +1 -0
  77. package/dist/src/primitives/KeepAlive.d.ts +42 -0
  78. package/dist/src/primitives/KeepAlive.jsx +160 -0
  79. package/dist/src/primitives/KeepAlive.jsx.map +1 -0
  80. package/dist/src/primitives/Lazy.d.ts +15 -0
  81. package/dist/src/primitives/Lazy.jsx +95 -0
  82. package/dist/src/primitives/Lazy.jsx.map +1 -0
  83. package/dist/src/primitives/LazyImport.d.ts +8 -0
  84. package/dist/src/primitives/LazyImport.js +40 -0
  85. package/dist/src/primitives/LazyImport.js.map +1 -0
  86. package/dist/src/primitives/Marquee.d.ts +64 -0
  87. package/dist/src/primitives/Marquee.jsx +86 -0
  88. package/dist/src/primitives/Marquee.jsx.map +1 -0
  89. package/dist/src/primitives/Preserve.d.ts +4 -0
  90. package/dist/src/primitives/Preserve.jsx +11 -0
  91. package/dist/src/primitives/Preserve.jsx.map +1 -0
  92. package/dist/src/primitives/Row.d.ts +3 -0
  93. package/dist/src/primitives/Row.jsx +24 -0
  94. package/dist/src/primitives/Row.jsx.map +1 -0
  95. package/dist/src/primitives/Suspense.d.ts +22 -0
  96. package/dist/src/primitives/Suspense.jsx +33 -0
  97. package/dist/src/primitives/Suspense.jsx.map +1 -0
  98. package/dist/src/primitives/Virtual.d.ts +18 -0
  99. package/dist/src/primitives/Virtual.jsx +495 -0
  100. package/dist/src/primitives/Virtual.jsx.map +1 -0
  101. package/dist/src/primitives/VirtualGrid.d.ts +13 -0
  102. package/dist/src/primitives/VirtualGrid.jsx +160 -0
  103. package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
  104. package/dist/src/primitives/Visible.d.ts +6 -0
  105. package/dist/src/primitives/Visible.jsx +37 -0
  106. package/dist/src/primitives/Visible.jsx.map +1 -0
  107. package/dist/src/primitives/announcer/announcer.d.ts +40 -0
  108. package/dist/src/primitives/announcer/announcer.js +125 -0
  109. package/dist/src/primitives/announcer/announcer.js.map +1 -0
  110. package/dist/src/primitives/announcer/index.d.ts +6 -0
  111. package/dist/src/primitives/announcer/index.js +15 -0
  112. package/dist/src/primitives/announcer/index.js.map +1 -0
  113. package/dist/src/primitives/announcer/speech.d.ts +10 -0
  114. package/dist/src/primitives/announcer/speech.js +281 -0
  115. package/dist/src/primitives/announcer/speech.js.map +1 -0
  116. package/dist/src/primitives/borderBox.d.ts +8 -0
  117. package/dist/src/primitives/borderBox.jsx +47 -0
  118. package/dist/src/primitives/borderBox.jsx.map +1 -0
  119. package/dist/src/primitives/createFocusStack.d.ts +31 -0
  120. package/dist/src/primitives/createFocusStack.jsx +62 -0
  121. package/dist/src/primitives/createFocusStack.jsx.map +1 -0
  122. package/dist/src/primitives/createInfiniteItems.d.ts +27 -0
  123. package/dist/src/primitives/createInfiniteItems.js +46 -0
  124. package/dist/src/primitives/createInfiniteItems.js.map +1 -0
  125. package/dist/src/primitives/createTag.d.ts +8 -0
  126. package/dist/src/primitives/createTag.jsx +20 -0
  127. package/dist/src/primitives/createTag.jsx.map +1 -0
  128. package/dist/src/primitives/index.d.ts +32 -0
  129. package/dist/src/primitives/index.js +31 -0
  130. package/dist/src/primitives/index.js.map +1 -0
  131. package/dist/src/primitives/portal.d.ts +5 -0
  132. package/dist/src/primitives/portal.jsx +21 -0
  133. package/dist/src/primitives/portal.jsx.map +1 -0
  134. package/dist/src/primitives/router.d.ts +20 -0
  135. package/dist/src/primitives/router.js +90 -0
  136. package/dist/src/primitives/router.js.map +1 -0
  137. package/dist/src/primitives/types.d.ts +79 -0
  138. package/dist/src/primitives/types.js +2 -0
  139. package/dist/src/primitives/types.js.map +1 -0
  140. package/dist/src/primitives/useFocusManager.d.ts +5 -0
  141. package/dist/src/primitives/useFocusManager.js +21 -0
  142. package/dist/src/primitives/useFocusManager.js.map +1 -0
  143. package/dist/src/primitives/useHold.d.ts +27 -0
  144. package/dist/src/primitives/useHold.js +54 -0
  145. package/dist/src/primitives/useHold.js.map +1 -0
  146. package/dist/src/primitives/useMouse.d.ts +18 -0
  147. package/dist/src/primitives/useMouse.js +240 -0
  148. package/dist/src/primitives/useMouse.js.map +1 -0
  149. package/dist/src/primitives/utils/chainFunctions.d.ts +30 -0
  150. package/dist/src/primitives/utils/chainFunctions.js +32 -0
  151. package/dist/src/primitives/utils/chainFunctions.js.map +1 -0
  152. package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
  153. package/dist/src/primitives/utils/createBlurredImage.js +223 -0
  154. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
  155. package/dist/src/primitives/utils/createSpriteMap.d.ts +9 -0
  156. package/dist/src/primitives/utils/createSpriteMap.js +18 -0
  157. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -0
  158. package/dist/src/primitives/utils/handleNavigation.d.ts +103 -0
  159. package/dist/src/primitives/utils/handleNavigation.js +300 -0
  160. package/dist/src/primitives/utils/handleNavigation.js.map +1 -0
  161. package/dist/src/primitives/utils/withScrolling.d.ts +22 -0
  162. package/dist/src/primitives/utils/withScrolling.js +186 -0
  163. package/dist/src/primitives/utils/withScrolling.js.map +1 -0
  164. package/dist/src/render.d.ts +28 -0
  165. package/dist/src/render.js +107 -0
  166. package/dist/src/render.js.map +1 -0
  167. package/dist/src/solidOpts.d.ts +15 -0
  168. package/dist/src/solidOpts.js +93 -0
  169. package/dist/src/solidOpts.js.map +1 -0
  170. package/dist/src/types.d.ts +11 -0
  171. package/dist/src/types.js +2 -0
  172. package/dist/src/types.js.map +1 -0
  173. package/dist/src/utils.d.ts +19 -0
  174. package/dist/src/utils.js +94 -0
  175. package/dist/src/utils.js.map +1 -0
  176. package/dist/tsconfig.tsbuildinfo +1 -0
  177. package/docs/AI_CODING_GUIDELINES.md +108 -0
  178. package/docs/README.md +35 -0
  179. package/jsx-runtime.d.ts +14 -0
  180. package/package.json +125 -0
  181. package/src/activeElement.ts +5 -0
  182. package/src/core/config.ts +101 -0
  183. package/src/core/dom-renderer/domRenderer.ts +2066 -0
  184. package/src/core/dom-renderer/domRendererTypes.ts +148 -0
  185. package/src/core/dom-renderer/domRendererUtils.ts +292 -0
  186. package/src/core/elementNode.ts +1623 -0
  187. package/src/core/flex.ts +331 -0
  188. package/src/core/flexLayout.ts +414 -0
  189. package/src/core/focusKeyTypes.ts +90 -0
  190. package/src/core/focusManager.ts +374 -0
  191. package/src/core/index.ts +15 -0
  192. package/src/core/intrinsicTypes.ts +216 -0
  193. package/src/core/lightningInit.ts +45 -0
  194. package/src/core/nodeTypes.ts +6 -0
  195. package/src/core/shaders.ts +187 -0
  196. package/src/core/states.ts +91 -0
  197. package/src/core/utils.ts +222 -0
  198. package/src/devtools/index.ts +77 -0
  199. package/src/index.ts +18 -0
  200. package/src/primitives/Column.tsx +59 -0
  201. package/src/primitives/FPSCounter.tsx +209 -0
  202. package/src/primitives/FadeInOut.tsx +58 -0
  203. package/src/primitives/Grid.tsx +151 -0
  204. package/src/primitives/Image.tsx +56 -0
  205. package/src/primitives/KeepAlive.tsx +268 -0
  206. package/src/primitives/Lazy.tsx +128 -0
  207. package/src/primitives/LazyImport.ts +53 -0
  208. package/src/primitives/Marquee.tsx +149 -0
  209. package/src/primitives/Preserve.tsx +18 -0
  210. package/src/primitives/Row.tsx +58 -0
  211. package/src/primitives/Suspense.tsx +39 -0
  212. package/src/primitives/Virtual.tsx +602 -0
  213. package/src/primitives/VirtualGrid.tsx +220 -0
  214. package/src/primitives/Visible.tsx +59 -0
  215. package/src/primitives/announcer/announcer.ts +198 -0
  216. package/src/primitives/announcer/index.ts +20 -0
  217. package/src/primitives/announcer/speech.ts +334 -0
  218. package/src/primitives/borderBox.tsx +69 -0
  219. package/src/primitives/createFocusStack.tsx +79 -0
  220. package/src/primitives/createInfiniteItems.ts +66 -0
  221. package/src/primitives/createTag.tsx +33 -0
  222. package/src/primitives/index.ts +37 -0
  223. package/src/primitives/portal.tsx +25 -0
  224. package/src/primitives/router.ts +147 -0
  225. package/src/primitives/types.ts +109 -0
  226. package/src/primitives/useFocusManager.ts +47 -0
  227. package/src/primitives/useHold.ts +69 -0
  228. package/src/primitives/useMouse.ts +417 -0
  229. package/src/primitives/utils/chainFunctions.ts +60 -0
  230. package/src/primitives/utils/createBlurredImage.ts +366 -0
  231. package/src/primitives/utils/createSpriteMap.ts +32 -0
  232. package/src/primitives/utils/handleNavigation.ts +373 -0
  233. package/src/primitives/utils/withScrolling.ts +238 -0
  234. package/src/render.ts +164 -0
  235. package/src/solidOpts.ts +107 -0
  236. package/src/types.ts +22 -0
  237. package/src/utils.ts +129 -0
@@ -0,0 +1,30 @@
1
+ import * as s from 'solid-js';
2
+ export type AnyFunction = (this: any, ...args: any[]) => any;
3
+ /**
4
+ * take an array of functions and if you return `true` from a function, it will stop the chain
5
+ * @param fns list of functions to chain together, can be `undefined`, `null`, or `false` to skip them
6
+ * @returns a function that will call each function in the list until one returns `true` or all functions are called.
7
+ * If no functions are provided, it will return `undefined`.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * function Button (props: NodeProps) {
12
+ * function onEnter (el: ElementNode) {...}
13
+ * return <view onEnter={chainFunctions(props.onEnter, onEnter)} />
14
+ * }
15
+ * ```
16
+ */
17
+ export declare function chainFunctions<T extends AnyFunction>(...fns: T[]): T;
18
+ export declare function chainFunctions<T extends AnyFunction>(...fns: (T | undefined | null | false)[]): T | undefined;
19
+ /**
20
+ * Utility for chaining multiple `ref` assignments with `props.ref` forwarding.
21
+ * @param refs list of ref setters. Can be a `props.ref` prop for ref forwarding or a setter to a local variable (`el => ref = el`).
22
+ * @example
23
+ * ```tsx
24
+ * function Button (props: NodeProps) {
25
+ * let localRef: ElementNode | undefined
26
+ * return <view ref={chainRefs(props.ref, el => localRef = el)} />
27
+ * }
28
+ * ```
29
+ */
30
+ export declare const chainRefs: <T>(...refs: (s.Ref<T> | undefined)[]) => (el: T) => void;
@@ -0,0 +1,32 @@
1
+ export function chainFunctions(...fns) {
2
+ const onlyFunctions = fns.filter((func) => typeof func === 'function');
3
+ if (onlyFunctions.length === 0) {
4
+ return undefined;
5
+ }
6
+ if (onlyFunctions.length === 1) {
7
+ return onlyFunctions[0];
8
+ }
9
+ return function (...innerArgs) {
10
+ let result;
11
+ for (const func of onlyFunctions) {
12
+ result = func.apply(this, innerArgs);
13
+ if (result === true) {
14
+ return result;
15
+ }
16
+ }
17
+ return result;
18
+ };
19
+ }
20
+ /**
21
+ * Utility for chaining multiple `ref` assignments with `props.ref` forwarding.
22
+ * @param refs list of ref setters. Can be a `props.ref` prop for ref forwarding or a setter to a local variable (`el => ref = el`).
23
+ * @example
24
+ * ```tsx
25
+ * function Button (props: NodeProps) {
26
+ * let localRef: ElementNode | undefined
27
+ * return <view ref={chainRefs(props.ref, el => localRef = el)} />
28
+ * }
29
+ * ```
30
+ */
31
+ export const chainRefs = chainFunctions;
32
+ //# sourceMappingURL=chainFunctions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chainFunctions.js","sourceRoot":"","sources":["../../../../src/primitives/utils/chainFunctions.ts"],"names":[],"mappings":"AAsBA,MAAM,UAAU,cAAc,CAC5B,GAAG,GAA+C;IAElD,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC;IACvE,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,UAAU,GAAG,SAAS;QAC3B,IAAI,MAAM,CAAC;QACX,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;YACjC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACrC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,cAEL,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { type Accessor, type Resource } from 'solid-js';
2
+ /**
3
+ * Represents a valid image source that can be used for blurring
4
+ */
5
+ type ImageSource = string | URL;
6
+ /**
7
+ * Represents a valid image source or null/undefined
8
+ */
9
+ type NullableImageSource = ImageSource | null | undefined;
10
+ /**
11
+ * Configuration options for Gaussian blur operation
12
+ */
13
+ interface BlurOptions {
14
+ /**
15
+ * The blur radius in pixels
16
+ * @default 10
17
+ */
18
+ readonly radius?: number;
19
+ /**
20
+ * CORS setting for image loading
21
+ * @default 'anonymous'
22
+ */
23
+ readonly crossOrigin?: 'anonymous' | 'use-credentials' | '';
24
+ /**
25
+ * The resolution of the output image in pixels
26
+ * @default 1
27
+ */
28
+ readonly resolution?: number;
29
+ }
30
+ /**
31
+ * Type for the resource return value from createBlurredImage
32
+ */
33
+ type BlurredImageResource<T extends NullableImageSource> = Resource<T extends null | undefined ? null : string>;
34
+ /**
35
+ * Applies Gaussian blur to an image URL
36
+ * @param imageUrl - Image source (string or URL)
37
+ * @param options - Blur configuration options
38
+ * @returns Promise resolving to data URL of blurred image
39
+ * @throws {Error} If image fails to load or blur operation fails
40
+ */
41
+ export declare function applyGaussianBlur<TSource extends ImageSource>(imageUrl: TSource, options?: Readonly<BlurOptions>): Promise<string>;
42
+ /**
43
+ * Hook to create a blurred image resource
44
+ * @param imageUrl - Accessor function returning image source or null/undefined
45
+ * @param options - Blur configuration options
46
+ * @returns Resource containing blurred image data URL or null
47
+ * @template TSource - Type of image source (string, URL, or null/undefined)
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const imageUrl = () => 'https://example.com/image.jpg';
52
+ * const blurred = createBlurredImage(imageUrl, { radius: 15 });
53
+ * ```
54
+ */
55
+ export declare function createBlurredImage<TSource extends NullableImageSource>(imageUrl: Accessor<TSource>, options?: Readonly<BlurOptions>): BlurredImageResource<TSource>;
56
+ export {};
@@ -0,0 +1,223 @@
1
+ import { createResource } from 'solid-js';
2
+ /**
3
+ * Default blur options
4
+ */
5
+ const DEFAULT_BLUR_OPTIONS = {
6
+ radius: 10,
7
+ crossOrigin: 'anonymous',
8
+ resolution: 1,
9
+ };
10
+ /**
11
+ * Validates that radius is a positive number
12
+ */
13
+ function isValidRadius(radius) {
14
+ return radius > 0 && Number.isFinite(radius);
15
+ }
16
+ /**
17
+ * Ensures a resolution is a positive number
18
+ */
19
+ function isValidResolution(resolution) {
20
+ return resolution > 0 && resolution <= 1 && Number.isFinite(resolution);
21
+ }
22
+ /**
23
+ * Applies vertical Gaussian blur to image data
24
+ * @param input - Input pixel data
25
+ * @param output - Output pixel data buffer
26
+ * @param width - Image width
27
+ * @param height - Image height
28
+ * @param kernel - Gaussian kernel weights
29
+ * @param half - Half of kernel size
30
+ */
31
+ function applyVerticalBlur(input, output, width, height, kernel, half) {
32
+ for (let y = 0; y < height; y++) {
33
+ for (let x = 0; x < width; x++) {
34
+ let r = 0, g = 0, b = 0, a = 0;
35
+ let weightSum = 0;
36
+ for (let ky = -half; ky <= half; ky++) {
37
+ const py = y + ky;
38
+ if (py >= 0 && py < height) {
39
+ const pixelIndex = (py * width + x) * 4;
40
+ const weight = kernel[ky + half];
41
+ r += input[pixelIndex] * weight;
42
+ g += input[pixelIndex + 1] * weight;
43
+ b += input[pixelIndex + 2] * weight;
44
+ a += input[pixelIndex + 3] * weight;
45
+ weightSum += weight;
46
+ }
47
+ }
48
+ const outputIndex = (y * width + x) * 4;
49
+ output[outputIndex] = r / weightSum;
50
+ output[outputIndex + 1] = g / weightSum;
51
+ output[outputIndex + 2] = b / weightSum;
52
+ output[outputIndex + 3] = a / weightSum;
53
+ }
54
+ }
55
+ }
56
+ /**
57
+ * Applies horizontal Gaussian blur to image data
58
+ * @param input - Input pixel data
59
+ * @param output - Output pixel data buffer
60
+ * @param width - Image width
61
+ * @param height - Image height
62
+ * @param kernel - Gaussian kernel weights
63
+ * @param half - Half of kernel size
64
+ */
65
+ function applyHorizontalBlur(input, output, width, height, kernel, half) {
66
+ for (let y = 0; y < height; y++) {
67
+ for (let x = 0; x < width; x++) {
68
+ let r = 0, g = 0, b = 0, a = 0;
69
+ let weightSum = 0;
70
+ for (let kx = -half; kx <= half; kx++) {
71
+ const px = x + kx;
72
+ if (px >= 0 && px < width) {
73
+ const pixelIndex = (y * width + px) * 4;
74
+ const weight = kernel[kx + half];
75
+ r += input[pixelIndex] * weight;
76
+ g += input[pixelIndex + 1] * weight;
77
+ b += input[pixelIndex + 2] * weight;
78
+ a += input[pixelIndex + 3] * weight;
79
+ weightSum += weight;
80
+ }
81
+ }
82
+ const outputIndex = (y * width + x) * 4;
83
+ output[outputIndex] = r / weightSum;
84
+ output[outputIndex + 1] = g / weightSum;
85
+ output[outputIndex + 2] = b / weightSum;
86
+ output[outputIndex + 3] = a / weightSum;
87
+ }
88
+ }
89
+ }
90
+ /**
91
+ * Generates a normalized Gaussian kernel
92
+ * @param size - Kernel size (must be odd)
93
+ * @param sigma - Standard deviation
94
+ * @returns Normalized Gaussian kernel
95
+ */
96
+ function generateGaussianKernel(size, sigma) {
97
+ const kernel = [];
98
+ const half = Math.floor(size / 2);
99
+ let sum = 0;
100
+ for (let i = -half; i <= half; i++) {
101
+ const value = Math.exp(-(i * i) / (2 * sigma * sigma));
102
+ kernel.push(value);
103
+ sum += value;
104
+ }
105
+ return Object.freeze(kernel.map((value) => value / sum));
106
+ }
107
+ /**
108
+ * Applies Gaussian blur convolution to image data
109
+ * @param imageData - Source image data
110
+ * @param dimensions - Image dimensions
111
+ * @param radius - Blur radius
112
+ * @returns Blurred image data
113
+ */
114
+ function gaussianBlurConvolution(imageData, dimensions, radius) {
115
+ const { data } = imageData;
116
+ const { width, height } = dimensions;
117
+ const output = new Uint8ClampedArray(data.length);
118
+ const kernelSize = Math.ceil(radius * 2) * 2 + 1;
119
+ const kernel = generateGaussianKernel(kernelSize, radius);
120
+ const half = Math.floor(kernelSize / 2);
121
+ applyHorizontalBlur(data, output, width, height, kernel, half);
122
+ const tempData = new Uint8ClampedArray(output);
123
+ applyVerticalBlur(tempData, output, width, height, kernel, half);
124
+ return new ImageData(output, width, height);
125
+ }
126
+ /**
127
+ * Applies Gaussian blur to an image URL
128
+ * @param imageUrl - Image source (string or URL)
129
+ * @param options - Blur configuration options
130
+ * @returns Promise resolving to data URL of blurred image
131
+ * @throws {Error} If image fails to load or blur operation fails
132
+ */
133
+ export async function applyGaussianBlur(imageUrl, options) {
134
+ const opts = { ...DEFAULT_BLUR_OPTIONS, ...options };
135
+ const radius = opts.radius;
136
+ const resolution = opts.resolution;
137
+ if (!isValidRadius(radius)) {
138
+ throw new Error(`Invalid blur radius: ${radius}. Must be a positive number.`);
139
+ }
140
+ if (!isValidResolution(resolution)) {
141
+ throw new Error(`Invalid resolution: ${resolution}. Must be a number between 0 and 1.`);
142
+ }
143
+ return new Promise((resolve, reject) => {
144
+ const img = new Image();
145
+ img.crossOrigin = opts.crossOrigin;
146
+ img.onload = () => {
147
+ try {
148
+ const canvas = document.createElement('canvas');
149
+ const ctx = canvas.getContext('2d', {
150
+ willReadFrequently: true,
151
+ });
152
+ if (ctx === null) {
153
+ reject(new Error('Failed to get canvas context'));
154
+ return;
155
+ }
156
+ const scaledWidth = Math.max(1, Math.round(img.width * resolution));
157
+ const scaledHeight = Math.max(1, Math.round(img.height * resolution));
158
+ const dimensions = {
159
+ width: scaledWidth,
160
+ height: scaledHeight,
161
+ };
162
+ canvas.width = dimensions.width;
163
+ canvas.height = dimensions.height;
164
+ const hasFilterSupport = ctx.filter !== undefined;
165
+ if (hasFilterSupport) {
166
+ ctx.filter = `blur(${radius}px)`;
167
+ ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);
168
+ ctx.filter = 'none';
169
+ }
170
+ else {
171
+ ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);
172
+ const imageData = ctx.getImageData(0, 0, dimensions.width, dimensions.height);
173
+ const blurredData = gaussianBlurConvolution(imageData, dimensions, radius);
174
+ ctx.putImageData(blurredData, 0, 0);
175
+ }
176
+ const dataUrl = canvas.toDataURL();
177
+ if (dataUrl) {
178
+ resolve(dataUrl);
179
+ }
180
+ else {
181
+ reject(new Error('Failed to create image data URL'));
182
+ }
183
+ }
184
+ catch (error) {
185
+ reject(error instanceof Error
186
+ ? error
187
+ : new Error('Unknown error during blur operation'));
188
+ }
189
+ };
190
+ img.onerror = () => {
191
+ reject(new Error('Failed to load image'));
192
+ };
193
+ const srcString = typeof imageUrl === 'string' ? imageUrl : imageUrl.toString();
194
+ img.src = srcString;
195
+ });
196
+ }
197
+ /**
198
+ * Hook to create a blurred image resource
199
+ * @param imageUrl - Accessor function returning image source or null/undefined
200
+ * @param options - Blur configuration options
201
+ * @returns Resource containing blurred image data URL or null
202
+ * @template TSource - Type of image source (string, URL, or null/undefined)
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const imageUrl = () => 'https://example.com/image.jpg';
207
+ * const blurred = createBlurredImage(imageUrl, { radius: 15 });
208
+ * ```
209
+ */
210
+ export function createBlurredImage(imageUrl, options) {
211
+ const imageUrlString = () => {
212
+ const url = imageUrl();
213
+ if (url === null || url === undefined) {
214
+ return url;
215
+ }
216
+ return typeof url === 'string' ? url : url.toString();
217
+ };
218
+ const [blurredImage] = createResource(imageUrlString, async (url) => {
219
+ return await applyGaussianBlur(url, options);
220
+ });
221
+ return blurredImage;
222
+ }
223
+ //# sourceMappingURL=createBlurredImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBlurredImage.js","sourceRoot":"","sources":["../../../../src/primitives/utils/createBlurredImage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,cAAc,EAAE,MAAM,UAAU,CAAC;AAiCxE;;GAEG;AACH,MAAM,oBAAoB,GAEtB;IACF,MAAM,EAAE,EAAE;IACV,WAAW,EAAE,WAAW;IACxB,UAAU,E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H,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CACJ,KAAK,YAAY,KAAK;oBACpB,CAAC,CAAC,KAAK;oBACP,CAAC,CAAC,IAAI,KAAK,CAAC,qCAAqC,CAAC,CACrD,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,GAAG,CAAC,OAAO,GAAG,GAAS,EAAE;YACvB,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC;QAEF,MAAM,SAAS,GACb,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAChE,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA2B,EAC3B,OAA+B;IAE/B,MAAM,cAAc,GAAwC,GAAG,EAAE;QAC/D,MAAM,GAAG,GAAG,QAAQ,EAAE,CAAC;QACvB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,GAAG,CAAC;QACb,CAAC;QACD,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxD,CAAC,CAAC;IAEF,MAAM,CAAC,YAAY,CAAC,GAAG,cAAc,CACnC,cAAc,EACd,KAAK,EAAE,GAAW,EAAmB,EAAE;QACrC,OAAO,MAAM,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC,CACF,CAAC;IAEF,OAAO,YAA6C,CAAC;AACvD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type TextureMap } from '../../core/index.js';
2
+ export interface SpriteDef {
3
+ name: string | number;
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export declare function createSpriteMap(src: string, subTextures: SpriteDef[]): Record<string, InstanceType<TextureMap['SubTexture']>>;
@@ -0,0 +1,18 @@
1
+ import { renderer } from '../../core/index.js';
2
+ export function createSpriteMap(src, subTextures) {
3
+ const spriteMapTexture = renderer.createTexture('ImageTexture', {
4
+ src,
5
+ });
6
+ return subTextures.reduce((acc, t) => {
7
+ const { x, y, width, height } = t;
8
+ acc[t.name] = renderer.createTexture('SubTexture', {
9
+ texture: spriteMapTexture,
10
+ x,
11
+ y,
12
+ w: width,
13
+ h: height,
14
+ });
15
+ return acc;
16
+ }, {});
17
+ }
18
+ //# sourceMappingURL=createSpriteMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSpriteMap.js","sourceRoot":"","sources":["../../../../src/primitives/utils/createSpriteMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAUhE,MAAM,UAAU,eAAe,CAC7B,GAAW,EACX,WAAwB;IAExB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,EAAE;QAC9D,GAAG;KACJ,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC,MAAM,CAEvB,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACX,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAClC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,YAAY,EAAE;YACjD,OAAO,EAAE,gBAAgB;YACzB,CAAC;YACD,CAAC;YACD,CAAC,EAAE,KAAK;YACR,CAAC,EAAE,MAAM;SACV,CAA2C,CAAC;QAC7C,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
@@ -0,0 +1,103 @@
1
+ import * as lng from '../../index.js';
2
+ import * as lngp from '../index.js';
3
+ export declare const defaultTransitionBack: {
4
+ x: {
5
+ duration: number;
6
+ easing: string;
7
+ };
8
+ };
9
+ export declare const defaultTransitionForward: {
10
+ x: {
11
+ duration: number;
12
+ easing: string;
13
+ };
14
+ };
15
+ export declare const defaultTransitionDown: {
16
+ y: {
17
+ duration: number;
18
+ easing: string;
19
+ };
20
+ };
21
+ export declare const defaultTransitionUp: {
22
+ y: {
23
+ duration: number;
24
+ easing: string;
25
+ };
26
+ };
27
+ /** @deprecated Use {@link navigableForwardFocus} instead */
28
+ export declare function onGridFocus(_?: lngp.OnSelectedChanged): lng.ForwardFocusHandler;
29
+ /**
30
+ * Forwards focus to the first focusable child of a {@link lngp.NavigableElement} and
31
+ * selects it.
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * <view
36
+ * selected={0}
37
+ * forwardFocus={navigableForwardFocus}
38
+ * onSelectedChanged={(idx, el, child, lastIdx) => {...}}
39
+ * >
40
+ * ```
41
+ */
42
+ export declare const navigableForwardFocus: lng.ForwardFocusHandler;
43
+ export declare function handleNavigation(direction: 'up' | 'right' | 'down' | 'left'): lng.KeyHandler;
44
+ /**
45
+ * Handles navigation key events for navigable elements, \
46
+ * such as {@link lngp.Row} and {@link lngp.Column}.
47
+ *
48
+ * Uses {@link moveSelection} to select the next or previous child based on the key pressed.
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * <view
53
+ * selected={0}
54
+ * onUp={navigableHandleNavigation}
55
+ * onDown={navigableHandleNavigation}
56
+ * onSelectedChanged={(idx, el, child, lastIdx) => {...}}
57
+ * >
58
+ * ```
59
+ */
60
+ export declare const navigableHandleNavigation: lng.KeyHandler;
61
+ /**
62
+ * Moves the selection within a {@link lngp.NavigableElement}.
63
+ */
64
+ export declare function moveSelection(el: lngp.NavigableElement, delta: number): boolean;
65
+ /**
66
+ * Forwards focus to the closest or first focusable child of a {@link lngp.NavigableElement} and
67
+ * selects it.
68
+ *
69
+ * To determine the closest child, it uses the distance between the center of the previous focused element
70
+ * and the center of each child element.
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * <view
75
+ * selected={0}
76
+ * forwardFocus={spatialForwardFocus}
77
+ * onSelectedChanged={(idx, el, child, lastIdx) => {...}}
78
+ * >
79
+ * ```
80
+ */
81
+ export declare const spatialForwardFocus: lng.ForwardFocusHandler;
82
+ /**
83
+ * Handles spatial navigation within a {@link lngp.NavigableElement} by moving focus
84
+ * based on the arrow keys pressed.
85
+ *
86
+ * This function allows for navigation in a grid-like manner for flex-wrap containers, \
87
+ * where pressing the arrow keys will either:
88
+ * - move focus to the next/prev child in the same row/column
89
+ * - or find the closest child in the next/prev row/column.
90
+ *
91
+ * @example
92
+ * ```tsx
93
+ * <view
94
+ * selected={0}
95
+ * display="flex"
96
+ * flexWrap="wrap"
97
+ * onUp={spatialHandleNavigation}
98
+ * onDown={spatialHandleNavigation}
99
+ * onSelectedChanged={(idx, el, child, lastIdx) => {...}}
100
+ * >
101
+ * ```
102
+ */
103
+ export declare const spatialHandleNavigation: lng.KeyHandler;