@symbiote-native/image 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/build/angular/image/index.d.ts +20 -0
- package/build/angular/image/index.js +113 -0
- package/build/angular/image-background/index.d.ts +14 -0
- package/build/angular/image-background/index.js +107 -0
- package/build/angular/index.d.ts +4 -0
- package/build/angular/index.js +6 -0
- package/build/angular/inject-image.d.ts +8 -0
- package/build/angular/inject-image.js +20 -0
- package/build/core/constants.d.ts +3 -0
- package/build/core/constants.js +4 -0
- package/build/core/hash-strings.d.ts +5 -0
- package/build/core/hash-strings.js +20 -0
- package/build/core/image-api.d.ts +18 -0
- package/build/core/image-api.js +30 -0
- package/build/core/image-background.d.ts +11 -0
- package/build/core/image-background.js +26 -0
- package/build/core/image-loader.d.ts +20 -0
- package/build/core/image-loader.js +42 -0
- package/build/core/image-ref-loader.d.ts +4 -0
- package/build/core/image-ref-loader.js +10 -0
- package/build/core/image-view-events.d.ts +9 -0
- package/build/core/image-view-events.js +32 -0
- package/build/core/image-view.d.ts +14 -0
- package/build/core/image-view.js +111 -0
- package/build/core/index.d.ts +10 -0
- package/build/core/index.js +7 -0
- package/build/core/native-module.d.ts +27 -0
- package/build/core/native-module.js +3 -0
- package/build/core/native-style.d.ts +19 -0
- package/build/core/native-style.js +62 -0
- package/build/core/props.d.ts +11 -0
- package/build/core/props.js +87 -0
- package/build/core/sources.d.ts +8 -0
- package/build/core/sources.js +59 -0
- package/build/core/types.d.ts +186 -0
- package/build/core/types.js +1 -0
- package/build/react/image-background.d.ts +7 -0
- package/build/react/image-background.js +7 -0
- package/build/react/image.d.ts +8 -0
- package/build/react/image.js +6 -0
- package/build/react/index.d.ts +6 -0
- package/build/react/index.js +5 -0
- package/build/react/use-image.d.ts +8 -0
- package/build/react/use-image.js +20 -0
- package/build/solid/image-background.d.ts +7 -0
- package/build/solid/image-background.js +4 -0
- package/build/solid/image.d.ts +45 -0
- package/build/solid/image.js +4 -0
- package/build/solid/index.d.ts +5 -0
- package/build/solid/index.js +5 -0
- package/build/solid/use-image.d.ts +8 -0
- package/build/solid/use-image.js +16 -0
- package/build/svelte/image-background-props.d.ts +5 -0
- package/build/svelte/image-background-props.js +1 -0
- package/build/svelte/image-background.svelte +10 -0
- package/build/svelte/image-background.svelte.d.ts +4 -0
- package/build/svelte/image.svelte +26 -0
- package/build/svelte/image.svelte.d.ts +10 -0
- package/build/svelte/index.d.ts +6 -0
- package/build/svelte/index.js +5 -0
- package/build/svelte/use-image.svelte.d.ts +10 -0
- package/build/svelte/use-image.svelte.js +26 -0
- package/build/vue/image-background.d.ts +3 -0
- package/build/vue/image-background.js +12 -0
- package/build/vue/image.d.ts +2 -0
- package/build/vue/image.js +4 -0
- package/build/vue/index.d.ts +4 -0
- package/build/vue/index.js +5 -0
- package/build/vue/use-image.d.ts +8 -0
- package/build/vue/use-image.js +18 -0
- package/build-ngc/angular/image/index.d.ts +23 -0
- package/build-ngc/angular/image/index.js +72 -0
- package/build-ngc/angular/image/index.js.map +1 -0
- package/build-ngc/angular/image-background/index.d.ts +17 -0
- package/build-ngc/angular/image-background/index.js +66 -0
- package/build-ngc/angular/image-background/index.js.map +1 -0
- package/build-ngc/angular/index.d.ts +4 -0
- package/build-ngc/angular/index.js +7 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/angular/inject-image.d.ts +8 -0
- package/build-ngc/angular/inject-image.js +23 -0
- package/build-ngc/angular/inject-image.js.map +1 -0
- package/build-ngc/core/constants.d.ts +3 -0
- package/build-ngc/core/constants.js +5 -0
- package/build-ngc/core/constants.js.map +1 -0
- package/build-ngc/core/hash-strings.d.ts +5 -0
- package/build-ngc/core/hash-strings.js +21 -0
- package/build-ngc/core/hash-strings.js.map +1 -0
- package/build-ngc/core/image-api.d.ts +18 -0
- package/build-ngc/core/image-api.js +31 -0
- package/build-ngc/core/image-api.js.map +1 -0
- package/build-ngc/core/image-background.d.ts +11 -0
- package/build-ngc/core/image-background.js +27 -0
- package/build-ngc/core/image-background.js.map +1 -0
- package/build-ngc/core/image-loader.d.ts +20 -0
- package/build-ngc/core/image-loader.js +43 -0
- package/build-ngc/core/image-loader.js.map +1 -0
- package/build-ngc/core/image-ref-loader.d.ts +4 -0
- package/build-ngc/core/image-ref-loader.js +11 -0
- package/build-ngc/core/image-ref-loader.js.map +1 -0
- package/build-ngc/core/image-view-events.d.ts +9 -0
- package/build-ngc/core/image-view-events.js +33 -0
- package/build-ngc/core/image-view-events.js.map +1 -0
- package/build-ngc/core/image-view.d.ts +14 -0
- package/build-ngc/core/image-view.js +112 -0
- package/build-ngc/core/image-view.js.map +1 -0
- package/build-ngc/core/index.d.ts +10 -0
- package/build-ngc/core/index.js +8 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/native-module.d.ts +27 -0
- package/build-ngc/core/native-module.js +4 -0
- package/build-ngc/core/native-module.js.map +1 -0
- package/build-ngc/core/native-style.d.ts +19 -0
- package/build-ngc/core/native-style.js +63 -0
- package/build-ngc/core/native-style.js.map +1 -0
- package/build-ngc/core/props.d.ts +11 -0
- package/build-ngc/core/props.js +88 -0
- package/build-ngc/core/props.js.map +1 -0
- package/build-ngc/core/sources.d.ts +8 -0
- package/build-ngc/core/sources.js +60 -0
- package/build-ngc/core/sources.js.map +1 -0
- package/build-ngc/core/types.d.ts +186 -0
- package/build-ngc/core/types.js +2 -0
- package/build-ngc/core/types.js.map +1 -0
- package/native-link.json +13 -0
- package/package.json +145 -3
- package/src/angular/image/index.ts +78 -0
- package/src/angular/image-background/index.ts +69 -0
- package/src/angular/index.ts +7 -0
- package/src/angular/inject-image.ts +29 -0
- package/src/core/constants.ts +6 -0
- package/src/core/hash-strings.ts +27 -0
- package/src/core/image-api.ts +67 -0
- package/src/core/image-background.ts +42 -0
- package/src/core/image-loader.ts +65 -0
- package/src/core/image-ref-loader.ts +16 -0
- package/src/core/image-view-events.ts +41 -0
- package/src/core/image-view.ts +156 -0
- package/src/core/index.ts +50 -0
- package/src/core/native-module.ts +45 -0
- package/src/core/native-style.ts +89 -0
- package/src/core/props.ts +118 -0
- package/src/core/sources.ts +70 -0
- package/src/core/types.ts +278 -0
- package/src/react/image-background.ts +14 -0
- package/src/react/image.ts +14 -0
- package/src/react/index.ts +8 -0
- package/src/react/use-image.ts +29 -0
- package/src/solid/image-background.ts +13 -0
- package/src/solid/image.ts +8 -0
- package/src/solid/index.ts +7 -0
- package/src/solid/use-image.ts +30 -0
- package/src/svelte/image-background-props.ts +6 -0
- package/src/svelte/image-background.svelte +10 -0
- package/src/svelte/image.svelte +26 -0
- package/src/svelte/index.ts +8 -0
- package/src/svelte/svelte-ambient.d.ts +3 -0
- package/src/svelte/svelte-compile.test-helper.ts +6 -0
- package/src/svelte/use-image.svelte.ts +38 -0
- package/src/vue/image-background.ts +17 -0
- package/src/vue/image.ts +5 -0
- package/src/vue/index.ts +6 -0
- package/src/vue/use-image.ts +34 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import DescriptorHost from '@symbiote-native/svelte/descriptor-host';
|
|
3
|
+
import { renderImageBackground } from '../core';
|
|
4
|
+
import type { IImageBackgroundSvelteProps } from './image-background-props';
|
|
5
|
+
|
|
6
|
+
const { children, ...rest }: IImageBackgroundSvelteProps = $props();
|
|
7
|
+
const descriptor = $derived(renderImageBackground({ ...rest }));
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<DescriptorHost {descriptor} {children} />
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// The native view name is mixed-case, which a literal tag would parse as a component reference,
|
|
3
|
+
// so the tag is dynamic
|
|
4
|
+
import { hostProps } from '@symbiote-native/svelte/native-view-bridge';
|
|
5
|
+
import { useNativeViewController } from '@symbiote-native/svelte/runes/use-native-view-controller';
|
|
6
|
+
import { createImageView } from '../core';
|
|
7
|
+
import type { IImageViewProps } from '../core';
|
|
8
|
+
|
|
9
|
+
const props: IImageViewProps = $props();
|
|
10
|
+
const view = useNativeViewController(createImageView, () => ({ ...props }));
|
|
11
|
+
|
|
12
|
+
// The functions of the view are instance members, `bind:this` reaches them
|
|
13
|
+
export const startAnimating = view.handle.startAnimating;
|
|
14
|
+
export const stopAnimating = view.handle.stopAnimating;
|
|
15
|
+
export const lockResourceAsync = view.handle.lockResourceAsync;
|
|
16
|
+
export const unlockResourceAsync = view.handle.unlockResourceAsync;
|
|
17
|
+
export const reloadAsync = view.handle.reloadAsync;
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
{#if view.descriptor}
|
|
21
|
+
<svelte:element
|
|
22
|
+
this={view.descriptor.type}
|
|
23
|
+
{@attach view.attachHost}
|
|
24
|
+
{@attach hostProps(view.descriptor.props)}
|
|
25
|
+
/>
|
|
26
|
+
{/if}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @symbiote-native/image/svelte: the image view, its cache and hash functions on a shared core
|
|
2
|
+
|
|
3
|
+
export { default as Image } from './image.svelte';
|
|
4
|
+
export { default as ImageBackground } from './image-background.svelte';
|
|
5
|
+
export type { IImageBackgroundSvelteProps } from './image-background-props';
|
|
6
|
+
export { useImage } from './use-image.svelte';
|
|
7
|
+
export type { IUseImageResult } from './use-image.svelte';
|
|
8
|
+
export * from '../core';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { untrack } from 'svelte';
|
|
2
|
+
import { createImageRefLoader, resolveSource } from '../core';
|
|
3
|
+
import type { IImageLoadOptions, IImageSource, ImageRef } from '../core';
|
|
4
|
+
|
|
5
|
+
export type IUseImageResult = {
|
|
6
|
+
readonly current: ImageRef | null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Svelte twin of `expo-image`'s `useImage`, boxed getter shape of the other hooks
|
|
11
|
+
*
|
|
12
|
+
* It loads again when the uri of the source or a value read by `getDependencies` changes
|
|
13
|
+
*/
|
|
14
|
+
export function useImage(
|
|
15
|
+
getSource: () => IImageSource | string | number,
|
|
16
|
+
getOptions: () => IImageLoadOptions = () => ({}),
|
|
17
|
+
getDependencies: () => unknown[] = () => [],
|
|
18
|
+
): IUseImageResult {
|
|
19
|
+
let image = $state.raw<ImageRef | null>(null);
|
|
20
|
+
const key = $derived(resolveSource(getSource())?.uri);
|
|
21
|
+
|
|
22
|
+
$effect(() => {
|
|
23
|
+
// Read so the effect tracks them, the source itself is not a trigger
|
|
24
|
+
key;
|
|
25
|
+
getDependencies();
|
|
26
|
+
const loader = createImageRefLoader(loaded => {
|
|
27
|
+
image = loaded;
|
|
28
|
+
}, getOptions);
|
|
29
|
+
untrack(() => loader.load(getSource()));
|
|
30
|
+
return loader.cancel;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
get current(): ImageRef | null {
|
|
35
|
+
return image;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineComponent, type VNode } from '@vue/runtime-core';
|
|
2
|
+
import { descriptorToVue, normalizeVueAttrs } from '@symbiote-native/vue';
|
|
3
|
+
import { renderImageBackground } from '../core';
|
|
4
|
+
|
|
5
|
+
/** Vue twin of `expo-image`'s `ImageBackground`, the default slot paints over the image */
|
|
6
|
+
export const ImageBackground = defineComponent({
|
|
7
|
+
name: 'ImageBackground',
|
|
8
|
+
// Every attribute is a prop of the image or the view, nothing leaks onto the wrapper
|
|
9
|
+
inheritAttrs: false,
|
|
10
|
+
setup(_props, { attrs, slots }) {
|
|
11
|
+
return (): VNode =>
|
|
12
|
+
descriptorToVue(
|
|
13
|
+
renderImageBackground(normalizeVueAttrs(attrs)),
|
|
14
|
+
slots.default?.() ?? [],
|
|
15
|
+
);
|
|
16
|
+
},
|
|
17
|
+
});
|
package/src/vue/image.ts
ADDED
package/src/vue/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { shallowRef, toValue, watch } from '@vue/runtime-core';
|
|
2
|
+
import type { MaybeRefOrGetter, ShallowRef, WatchSource } from '@vue/runtime-core';
|
|
3
|
+
import { createImageRefLoader, resolveSource } from '../core';
|
|
4
|
+
import type { IImageLoadOptions, IImageSource, ImageRef } from '../core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Vue twin of `expo-image`'s `useImage`, `null` until the first image has loaded
|
|
8
|
+
*
|
|
9
|
+
* It loads again when the uri of the source or a watched `dependencies` source changes
|
|
10
|
+
*/
|
|
11
|
+
export function useImage(
|
|
12
|
+
source: MaybeRefOrGetter<IImageSource | string | number>,
|
|
13
|
+
options: MaybeRefOrGetter<IImageLoadOptions> = {},
|
|
14
|
+
dependencies: WatchSource[] = [],
|
|
15
|
+
): Readonly<ShallowRef<ImageRef | null>> {
|
|
16
|
+
const image = shallowRef<ImageRef | null>(null);
|
|
17
|
+
|
|
18
|
+
watch(
|
|
19
|
+
[() => resolveSource(toValue(source))?.uri, ...dependencies],
|
|
20
|
+
(_next, _previous, onCleanup) => {
|
|
21
|
+
const loader = createImageRefLoader(
|
|
22
|
+
loaded => {
|
|
23
|
+
image.value = loaded;
|
|
24
|
+
},
|
|
25
|
+
() => toValue(options),
|
|
26
|
+
);
|
|
27
|
+
loader.load(toValue(source));
|
|
28
|
+
onCleanup(loader.cancel);
|
|
29
|
+
},
|
|
30
|
+
{ immediate: true },
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return image;
|
|
34
|
+
}
|