@symbiote-native/asset 0.1.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 +198 -0
- package/build/angular/index.d.ts +2 -0
- package/build/angular/index.js +4 -0
- package/build/angular/services/assets.service/index.d.ts +8 -0
- package/build/angular/services/assets.service/index.js +64 -0
- package/build/core/asset-fx.d.ts +1 -0
- package/build/core/asset-fx.js +24 -0
- package/build/core/asset-sources.d.ts +13 -0
- package/build/core/asset-sources.js +50 -0
- package/build/core/asset-uris.d.ts +3 -0
- package/build/core/asset-uris.js +33 -0
- package/build/core/asset.d.ts +35 -0
- package/build/core/asset.js +158 -0
- package/build/core/index.d.ts +3 -0
- package/build/core/index.js +2 -0
- package/build/core/local-assets.d.ts +1 -0
- package/build/core/local-assets.js +16 -0
- package/build/core/native-module.d.ts +4 -0
- package/build/core/native-module.js +2 -0
- package/build/core/platform-utils.d.ts +5 -0
- package/build/core/platform-utils.js +28 -0
- package/build/react/hooks/use-assets/index.d.ts +2 -0
- package/build/react/hooks/use-assets/index.js +14 -0
- package/build/react/index.d.ts +2 -0
- package/build/react/index.js +3 -0
- package/build/solid/index.d.ts +2 -0
- package/build/solid/index.js +5 -0
- package/build/solid/primitives/create-assets.d.ts +6 -0
- package/build/solid/primitives/create-assets.js +10 -0
- package/build/svelte/index.d.ts +2 -0
- package/build/svelte/index.js +5 -0
- package/build/svelte/runes/use-assets.svelte.d.ts +5 -0
- package/build/svelte/runes/use-assets.svelte.js +24 -0
- package/build/vue/composables/use-assets/index.d.ts +6 -0
- package/build/vue/composables/use-assets/index.js +18 -0
- package/build/vue/index.d.ts +2 -0
- package/build/vue/index.js +3 -0
- package/build-ngc/angular/index.d.ts +2 -0
- package/build-ngc/angular/index.js +5 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/angular/services/assets.service/index.d.ts +11 -0
- package/build-ngc/angular/services/assets.service/index.js +24 -0
- package/build-ngc/angular/services/assets.service/index.js.map +1 -0
- package/build-ngc/core/asset-fx.d.ts +1 -0
- package/build-ngc/core/asset-fx.js +25 -0
- package/build-ngc/core/asset-fx.js.map +1 -0
- package/build-ngc/core/asset-sources.d.ts +13 -0
- package/build-ngc/core/asset-sources.js +51 -0
- package/build-ngc/core/asset-sources.js.map +1 -0
- package/build-ngc/core/asset-uris.d.ts +3 -0
- package/build-ngc/core/asset-uris.js +34 -0
- package/build-ngc/core/asset-uris.js.map +1 -0
- package/build-ngc/core/asset.d.ts +35 -0
- package/build-ngc/core/asset.js +159 -0
- package/build-ngc/core/asset.js.map +1 -0
- package/build-ngc/core/index.d.ts +3 -0
- package/build-ngc/core/index.js +3 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/local-assets.d.ts +1 -0
- package/build-ngc/core/local-assets.js +17 -0
- package/build-ngc/core/local-assets.js.map +1 -0
- package/build-ngc/core/native-module.d.ts +4 -0
- package/build-ngc/core/native-module.js +3 -0
- package/build-ngc/core/native-module.js.map +1 -0
- package/build-ngc/core/platform-utils.d.ts +5 -0
- package/build-ngc/core/platform-utils.js +29 -0
- package/build-ngc/core/platform-utils.js.map +1 -0
- package/native-link.json +12 -0
- package/package.json +151 -0
- package/src/angular/index.ts +4 -0
- package/src/angular/services/assets.service/index.ts +21 -0
- package/src/core/asset-fx.ts +30 -0
- package/src/core/asset-sources.ts +80 -0
- package/src/core/asset-uris.ts +51 -0
- package/src/core/asset.ts +212 -0
- package/src/core/index.ts +8 -0
- package/src/core/local-assets.ts +22 -0
- package/src/core/native-module.ts +11 -0
- package/src/core/platform-utils.ts +47 -0
- package/src/core/ts-declarations/react-native-assets.d.ts +75 -0
- package/src/react/hooks/use-assets/index.ts +19 -0
- package/src/react/index.ts +4 -0
- package/src/solid/index.ts +6 -0
- package/src/solid/primitives/create-assets.ts +16 -0
- package/src/svelte/index.ts +6 -0
- package/src/svelte/runes/use-assets.svelte.ts +30 -0
- package/src/svelte/svelte-ambient.d.ts +3 -0
- package/src/vue/composables/use-assets/index.ts +30 -0
- package/src/vue/index.ts +4 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
|
|
3
|
+
export type INativeAssetModule = {
|
|
4
|
+
downloadAsync(
|
|
5
|
+
url: string,
|
|
6
|
+
md5Hash: string | null,
|
|
7
|
+
type: string,
|
|
8
|
+
): Promise<string>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const expoAsset = requireNativeModule<INativeAssetModule>('ExpoAsset');
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Ported from expo-asset/src/PlatformUtils.ts (sdk-57) — real logic, not a stub. Every check
|
|
2
|
+
// here (ExpoGo/expo-updates native modules, the classic-updates manifest) naturally resolves to
|
|
3
|
+
// "absent" in a bare app that ships neither, matching upstream's own designed fallback.
|
|
4
|
+
import Constants from 'expo-constants';
|
|
5
|
+
import {
|
|
6
|
+
requireNativeModule,
|
|
7
|
+
requireOptionalNativeModule,
|
|
8
|
+
} from 'expo-modules-core';
|
|
9
|
+
|
|
10
|
+
import { getManifestBaseUrl } from './asset-uris';
|
|
11
|
+
|
|
12
|
+
type IExpoUpdatesModule = {
|
|
13
|
+
isEnabled?: boolean;
|
|
14
|
+
isUsingEmbeddedAssets?: boolean;
|
|
15
|
+
localAssets?: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ExpoUpdates =
|
|
19
|
+
requireOptionalNativeModule<IExpoUpdatesModule>('ExpoUpdates');
|
|
20
|
+
|
|
21
|
+
function isRunningInExpoGo(): boolean {
|
|
22
|
+
try {
|
|
23
|
+
return requireNativeModule('ExpoGo') != null;
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const expoUpdatesIsInstalledAndEnabled = !!ExpoUpdates?.isEnabled;
|
|
30
|
+
const expoUpdatesIsUsingEmbeddedAssets = ExpoUpdates?.isUsingEmbeddedAssets;
|
|
31
|
+
const shouldUseUpdatesAssetResolution =
|
|
32
|
+
expoUpdatesIsInstalledAndEnabled && !expoUpdatesIsUsingEmbeddedAssets;
|
|
33
|
+
|
|
34
|
+
export const IS_ENV_WITH_LOCAL_ASSETS =
|
|
35
|
+
isRunningInExpoGo() || shouldUseUpdatesAssetResolution;
|
|
36
|
+
|
|
37
|
+
export function getLocalAssets(): Record<string, string> {
|
|
38
|
+
return ExpoUpdates?.localAssets ?? {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getManifest2(): typeof Constants.__unsafeNoWarnManifest2 {
|
|
42
|
+
return Constants.__unsafeNoWarnManifest2;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const manifestBaseUrl = Constants.experienceUrl
|
|
46
|
+
? getManifestBaseUrl(Constants.experienceUrl)
|
|
47
|
+
: null;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// RN ships no types for these Flow-only internal modules; upstream expo-asset hand-writes the
|
|
2
|
+
// same ambient declarations (src/ts-declarations/react-native-assets.d.ts, sdk-57).
|
|
3
|
+
declare module 'react-native/Libraries/Image/AssetSourceResolver' {
|
|
4
|
+
import type { PackagerAsset } from '@react-native/assets-registry/registry';
|
|
5
|
+
|
|
6
|
+
export type ResolvedAssetSource = {
|
|
7
|
+
__packager_asset: boolean;
|
|
8
|
+
width?: number | null;
|
|
9
|
+
height?: number | null;
|
|
10
|
+
uri: string;
|
|
11
|
+
scale: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default class AssetSourceResolver {
|
|
15
|
+
serverUrl: string | null;
|
|
16
|
+
jsbundleUrl: string | null;
|
|
17
|
+
asset: PackagerAsset & { fileHashes?: string[] };
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
serverUrl: string | null,
|
|
21
|
+
jsbundleUrl: string | null,
|
|
22
|
+
asset: PackagerAsset,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
isLoadedFromServer(): boolean;
|
|
26
|
+
isLoadedFromFileSystem(): boolean;
|
|
27
|
+
defaultAsset(): ResolvedAssetSource;
|
|
28
|
+
assetServerURL(): ResolvedAssetSource;
|
|
29
|
+
scaledAssetPath(): ResolvedAssetSource;
|
|
30
|
+
scaledAssetURLNearBundle(): ResolvedAssetSource;
|
|
31
|
+
resourceIdentifierWithoutScale(): ResolvedAssetSource;
|
|
32
|
+
drawableFolderInBundle(): ResolvedAssetSource;
|
|
33
|
+
fromSource(source: string): ResolvedAssetSource;
|
|
34
|
+
|
|
35
|
+
static pickScale(scales: number[], deviceScale: number): number;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module 'react-native/Libraries/Image/resolveAssetSource' {
|
|
40
|
+
import type AssetSourceResolver from 'react-native/Libraries/Image/AssetSourceResolver';
|
|
41
|
+
import type { ResolvedAssetSource } from 'react-native/Libraries/Image/AssetSourceResolver';
|
|
42
|
+
|
|
43
|
+
export type ICustomSourceTransformer = (
|
|
44
|
+
resolver: AssetSourceResolver,
|
|
45
|
+
) => ResolvedAssetSource | null | undefined;
|
|
46
|
+
|
|
47
|
+
interface IResolveAssetSource {
|
|
48
|
+
(source: unknown): ResolvedAssetSource | null;
|
|
49
|
+
setCustomSourceTransformer?(transformer: ICustomSourceTransformer): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const resolveAssetSource: IResolveAssetSource;
|
|
53
|
+
export default resolveAssetSource;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module '@react-native/assets-registry/registry' {
|
|
57
|
+
export type PackagerAsset = {
|
|
58
|
+
readonly __packager_asset: boolean;
|
|
59
|
+
readonly fileSystemLocation: string;
|
|
60
|
+
readonly httpServerLocation: string;
|
|
61
|
+
readonly width?: number | null;
|
|
62
|
+
readonly height?: number | null;
|
|
63
|
+
readonly scales: number[];
|
|
64
|
+
readonly hash: string;
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly type: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export function registerAsset(asset: PackagerAsset): number;
|
|
70
|
+
// Widened to match upstream's own override — Asset.fromModule's object branch always
|
|
71
|
+
// returns before reaching this call; the extra type only closes a narrowing gap tsc leaves.
|
|
72
|
+
export function getAssetByID(
|
|
73
|
+
assetId: number | { uri: string; width: number; height: number },
|
|
74
|
+
): PackagerAsset | undefined;
|
|
75
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// React lifecycle wiring over the framework-agnostic core (core/asset.ts). Loads once on mount;
|
|
2
|
+
// upstream's own contract ("the assets are not reloaded when you dynamically change the asset
|
|
3
|
+
// list") is preserved by the empty dependency array.
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { Asset } from '../../../core';
|
|
6
|
+
|
|
7
|
+
export function useAssets(
|
|
8
|
+
moduleIds: number | number[],
|
|
9
|
+
): [Asset[] | undefined, Error | undefined] {
|
|
10
|
+
const [assets, setAssets] = useState<Asset[]>();
|
|
11
|
+
const [error, setError] = useState<Error>();
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
Asset.loadAsync(moduleIds).then(setAssets).catch(setError);
|
|
15
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
return [assets, error];
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @symbiote-native/asset/solid: the Solid entry over the framework-agnostic core — mirrors the
|
|
2
|
+
// lifecycle-bucket naming convention of adapters/solid/src/primitives (never `hooks`/
|
|
3
|
+
// `composables`/`runes`, those are React's, Vue's and Svelte's terms).
|
|
4
|
+
|
|
5
|
+
export { createAssets } from './primitives/create-assets';
|
|
6
|
+
export * from '../core';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// createAssets — the Solid twin of React's useAssets hook, over the framework-agnostic core
|
|
2
|
+
// (core/asset.ts). Loads once from the primitive body, matching upstream's own contract.
|
|
3
|
+
import { createSignal, type Accessor } from 'solid-js';
|
|
4
|
+
import { Asset } from '../../core';
|
|
5
|
+
|
|
6
|
+
export function createAssets(moduleIds: number | number[]): {
|
|
7
|
+
assets: Accessor<Asset[] | undefined>;
|
|
8
|
+
error: Accessor<Error | undefined>;
|
|
9
|
+
} {
|
|
10
|
+
const [assets, setAssets] = createSignal<Asset[] | undefined>(undefined);
|
|
11
|
+
const [error, setError] = createSignal<Error | undefined>(undefined);
|
|
12
|
+
|
|
13
|
+
Asset.loadAsync(moduleIds).then(setAssets).catch(setError);
|
|
14
|
+
|
|
15
|
+
return { assets, error };
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @symbiote-native/asset/svelte: the Svelte entry over the framework-agnostic core — mirrors the
|
|
2
|
+
// lifecycle-bucket naming convention of adapters/svelte/src/runes (never `hooks`/`composables`,
|
|
3
|
+
// those are React's and Vue's terms).
|
|
4
|
+
|
|
5
|
+
export { useAssets } from './runes/use-assets.svelte';
|
|
6
|
+
export * from '../core';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic core (core/asset.ts). Loads once per
|
|
2
|
+
// mount ($effect with no read of its own state), matching upstream's useAssets contract.
|
|
3
|
+
import { Asset } from '../../core';
|
|
4
|
+
|
|
5
|
+
export function useAssets(moduleIds: number | number[]): {
|
|
6
|
+
readonly assets: Asset[] | undefined;
|
|
7
|
+
readonly error: Error | undefined;
|
|
8
|
+
} {
|
|
9
|
+
let assets = $state<Asset[] | undefined>(undefined);
|
|
10
|
+
let error = $state<Error | undefined>(undefined);
|
|
11
|
+
|
|
12
|
+
$effect(() => {
|
|
13
|
+
Asset.loadAsync(moduleIds)
|
|
14
|
+
.then(loaded => {
|
|
15
|
+
assets = loaded;
|
|
16
|
+
})
|
|
17
|
+
.catch((err: Error) => {
|
|
18
|
+
error = err;
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
get assets(): Asset[] | undefined {
|
|
24
|
+
return assets;
|
|
25
|
+
},
|
|
26
|
+
get error(): Error | undefined {
|
|
27
|
+
return error;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Vue lifecycle wiring over the framework-agnostic core (core/asset.ts). Loads once on mount,
|
|
2
|
+
// matching upstream's own useAssets contract (a changed moduleIds prop is not reloaded).
|
|
3
|
+
import {
|
|
4
|
+
onMounted,
|
|
5
|
+
ref,
|
|
6
|
+
shallowRef,
|
|
7
|
+
type Ref,
|
|
8
|
+
type ShallowRef,
|
|
9
|
+
} from '@vue/runtime-core';
|
|
10
|
+
import { Asset } from '../../../core';
|
|
11
|
+
|
|
12
|
+
export function useAssets(moduleIds: number | number[]): {
|
|
13
|
+
assets: ShallowRef<Asset[] | undefined>;
|
|
14
|
+
error: Ref<Error | undefined>;
|
|
15
|
+
} {
|
|
16
|
+
const assets = shallowRef<Asset[]>();
|
|
17
|
+
const error = ref<Error>();
|
|
18
|
+
|
|
19
|
+
onMounted(() => {
|
|
20
|
+
Asset.loadAsync(moduleIds)
|
|
21
|
+
.then(loaded => {
|
|
22
|
+
assets.value = loaded;
|
|
23
|
+
})
|
|
24
|
+
.catch((err: Error) => {
|
|
25
|
+
error.value = err;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return { assets, error };
|
|
30
|
+
}
|
package/src/vue/index.ts
ADDED