@solidrt/components 0.0.14 → 0.0.16
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 +1 -1
- package/src/image.tsx +9 -44
- package/src/modal.tsx +1 -1
package/package.json
CHANGED
package/src/image.tsx
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
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
|
-
<
|
|
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"
|