@solidrt/components 0.0.14 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/components",
3
- "version": "0.0.14",
3
+ "version": "0.0.17",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "type": "module",
@@ -14,6 +14,6 @@
14
14
  ],
15
15
  "peerDependencies": {
16
16
  "@solidjs/signals": "2.0.0-beta.15",
17
- "@solidrt/core": "0.0.0"
17
+ "@solidrt/core": "0.0.17"
18
18
  }
19
19
  }
package/src/image.tsx CHANGED
@@ -1,6 +1,4 @@
1
- import { createSignal, createEffect, onCleanup } from "@solidjs/signals"
2
- import { createTexture, destroyTexture } from "@solidrt/core/gpu"
3
- import { decodeImage } from "@solidrt/core/image"
1
+ import { createImage, Loading } from "@solidrt/core"
4
2
  import type { LayoutProps, PointerProps } from "@solidrt/core"
5
3
  import type { StyleProps } from "./types"
6
4
 
@@ -12,41 +10,11 @@ export interface ImageProps extends PointerProps {
12
10
 
13
11
  //TODO onLoad, onError
14
12
  export function Image(props: ImageProps) {
15
- let [res, setRes] = createSignal<{ id: number; width: number; height: number }>()
16
-
17
- // Load (and decode) whenever src changes. A url is fetched; bytes are used
18
- // directly. The async result is pushed into the signal so the texture shows
19
- // once ready; a stale flag drops results from a superseded src. The old
20
- // texture is destroyed before installing the new one; on unmount the current
21
- // texture is destroyed by onCleanup below.
22
- createEffect(
23
- () => props.src,
24
- (source) => {
25
- let stale = false
26
-
27
- ;(async () => {
28
- let bytes: Uint8Array
29
- if (typeof source === "string") {
30
- let response = await fetch(source)
31
- bytes = await response.bytes()
32
- } else {
33
- bytes = source
34
- }
35
- if (stale) return
36
- let { data, width, height } = decodeImage(bytes)
37
- let id = createTexture(data, width, height)
38
- let old = res()
39
- setRes({ id, width, height })
40
- if (old !== undefined) destroyTexture(old.id)
41
- })()
42
-
43
- return () => {
44
- stale = true
45
- }
46
- },
47
- )
48
-
49
- let src = () => res()?.id
13
+ // createImage fetches/decodes/uploads, swaps the texture when src changes, and
14
+ // frees it on cleanup, returning the texture id. Pass an accessor so a reactive
15
+ // src reloads. Reading src() suspends until ready (a SolidJS 2.0 async value),
16
+ // so the <texture> below sits in a <Loading> boundary.
17
+ let src = createImage(() => props.src)
50
18
  let hasBorder = () => (props.style?.borderWidth ?? 0) > 0
51
19
 
52
20
  // A texture sizes from its own width/height (not the box around it), so the
@@ -55,11 +23,6 @@ export function Image(props: ImageProps) {
55
23
  let texW = () => (typeof props.layout?.width === "number" ? props.layout.width : undefined)
56
24
  let texH = () => (typeof props.layout?.height === "number" ? props.layout.height : undefined)
57
25
 
58
- onCleanup(() => {
59
- let r = res()
60
- if (r !== undefined) destroyTexture(r.id)
61
- })
62
-
63
26
  return (
64
27
  <view
65
28
  {...props.layout}
@@ -85,7 +48,9 @@ export function Image(props: ImageProps) {
85
48
  {props.style?.backgroundColor != null ? (
86
49
  <d-rect color={props.style?.backgroundColor} radius={props.style?.borderRadius} />
87
50
  ) : null}
88
- <texture src={src()} width={texW()} height={texH()} />
51
+ <Loading fallback={null}>
52
+ <texture src={src()} width={texW()} height={texH()} />
53
+ </Loading>
89
54
  {hasBorder() ? (
90
55
  <d-rect
91
56
  drawStyle="stroke"
package/src/modal.tsx CHANGED
@@ -53,6 +53,6 @@ export function Modal(props: ModalProps) {
53
53
  <d-rect color={props.backdropColor ?? theme.color.scrim} />
54
54
  </view>
55
55
  {props.children}
56
- </view> as any,
56
+ </view>
57
57
  )
58
58
  }