react-native-model-viewer-webview 0.1.0 → 0.2.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/CHANGELOG.md +22 -0
- package/README.md +18 -8
- package/THIRD_PARTY_NOTICES.md +24 -0
- package/agent-skills/react-native-model-viewer-webview/SKILL.md +3 -1
- package/agent-skills/react-native-model-viewer-webview/references/api.md +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/model-viewer-html.d.ts +2 -0
- package/dist/model-viewer-html.js +14 -3
- package/docs/COMPATIBILITY.md +4 -3
- package/docs/HOW_IT_WORKS.md +12 -4
- package/package.json +5 -1
- package/scripts/generate-model-viewer-runtime.js +150 -0
- package/src/index.ts +2 -0
- package/src/model-viewer-html.ts +13 -3
- package/vendor/model-viewer/LICENSE +202 -0
- package/vendor/model-viewer/SOURCE.md +28 -0
- package/vendor/model-viewer/VERSION +1 -0
- package/vendor/model-viewer/runtime.d.ts +2 -0
- package/vendor/model-viewer/runtime.js +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,28 @@ All notable changes to this package should be documented here.
|
|
|
5
5
|
This project uses semantic versioning. Versions below `1.0.0` may still change
|
|
6
6
|
minor APIs when the release notes call it out clearly.
|
|
7
7
|
|
|
8
|
+
## 0.2.0 - 2026-06-02
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Bundle `@google/model-viewer` 4.2.0 inside the package so the default WebView
|
|
13
|
+
runtime no longer needs a CDN request.
|
|
14
|
+
- Add third-party notice and Apache-2.0 license metadata for the vendored
|
|
15
|
+
`@google/model-viewer` runtime.
|
|
16
|
+
- Export `BUNDLED_MODEL_VIEWER_VERSION` so consumers can inspect the embedded
|
|
17
|
+
runtime version.
|
|
18
|
+
- Export `MODEL_VIEWER_CDN_SCRIPT_URL` for apps that explicitly opt back into
|
|
19
|
+
the Google CDN runtime.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Make generated model-viewer HTML offline-first by inlining the bundled
|
|
24
|
+
runtime by default.
|
|
25
|
+
- Keep `modelViewerScriptUrl` and `modelViewerScript` as explicit overrides for
|
|
26
|
+
custom CDN, local file, or app-bundled script loading.
|
|
27
|
+
- Keep `DEFAULT_MODEL_VIEWER_SCRIPT_URL` as a compatibility alias for
|
|
28
|
+
`MODEL_VIEWER_CDN_SCRIPT_URL`.
|
|
29
|
+
|
|
8
30
|
## 0.1.0 - 2026-05-31
|
|
9
31
|
|
|
10
32
|
Initial public release of `react-native-model-viewer-webview`.
|
package/README.md
CHANGED
|
@@ -160,17 +160,27 @@ from Metro's file map.
|
|
|
160
160
|
|
|
161
161
|
## Offline Script Loading
|
|
162
162
|
|
|
163
|
-
By default, the generated WebView HTML
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
By default, the generated WebView HTML inlines a vendored copy of
|
|
164
|
+
`@google/model-viewer` 4.2.0. That means the viewer runtime does not need a CDN
|
|
165
|
+
request, and local `.glb` previews can work offline when the model asset is also
|
|
166
|
+
available locally.
|
|
166
167
|
|
|
167
|
-
|
|
168
|
+
This makes the npm package larger, but keeps runtime behavior deterministic and
|
|
169
|
+
offline-friendly. The Apache-2.0 license for the bundled runtime is included in
|
|
170
|
+
[`vendor/model-viewer/LICENSE`](./vendor/model-viewer/LICENSE), with a summary in
|
|
171
|
+
[`THIRD_PARTY_NOTICES.md`](./THIRD_PARTY_NOTICES.md). The exact source package,
|
|
172
|
+
file hash, and generated runtime details are recorded in
|
|
173
|
+
[`vendor/model-viewer/SOURCE.md`](./vendor/model-viewer/SOURCE.md).
|
|
174
|
+
|
|
175
|
+
If you prefer a custom or CDN-hosted runtime, pass your own script URL:
|
|
168
176
|
|
|
169
177
|
```tsx
|
|
178
|
+
import { MODEL_VIEWER_CDN_SCRIPT_URL } from "react-native-model-viewer-webview";
|
|
179
|
+
|
|
170
180
|
<ModelViewerWebView
|
|
171
|
-
modelSource=
|
|
181
|
+
modelSource="https://example.com/car.glb"
|
|
172
182
|
htmlOptions={{
|
|
173
|
-
modelViewerScriptUrl:
|
|
183
|
+
modelViewerScriptUrl: MODEL_VIEWER_CDN_SCRIPT_URL,
|
|
174
184
|
}}
|
|
175
185
|
/>
|
|
176
186
|
```
|
|
@@ -215,8 +225,8 @@ Useful `htmlOptions`:
|
|
|
215
225
|
| `exposure` / `shadowIntensity` | Basic visual tuning. |
|
|
216
226
|
| `backgroundColor` / `posterColor` | Controls the WebView and poster background. |
|
|
217
227
|
| `additionalAttributes` | Adds extra `<model-viewer>` attributes. |
|
|
218
|
-
| `modelViewerScriptUrl` |
|
|
219
|
-
| `modelViewerScript` |
|
|
228
|
+
| `modelViewerScriptUrl` | Overrides the bundled runtime with a custom `<model-viewer>` script URL. |
|
|
229
|
+
| `modelViewerScript` | Overrides the bundled runtime with a custom inline module script. |
|
|
220
230
|
|
|
221
231
|
## Example
|
|
222
232
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Third-Party Notices
|
|
2
|
+
|
|
3
|
+
This package includes a vendored copy of `@google/model-viewer` so the default
|
|
4
|
+
viewer runtime can load offline inside React Native WebView.
|
|
5
|
+
|
|
6
|
+
## @google/model-viewer
|
|
7
|
+
|
|
8
|
+
- Version: `4.2.0`
|
|
9
|
+
- Source: <https://www.npmjs.com/package/@google/model-viewer/v/4.2.0>
|
|
10
|
+
- Repository: <https://github.com/google/model-viewer>
|
|
11
|
+
- License: Apache-2.0
|
|
12
|
+
|
|
13
|
+
The Apache-2.0 license text is included at:
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
vendor/model-viewer/LICENSE
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The generated runtime and source verification details are included at:
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
vendor/model-viewer/runtime.js
|
|
23
|
+
vendor/model-viewer/SOURCE.md
|
|
24
|
+
```
|
|
@@ -96,7 +96,9 @@ await model.downloadAsync();
|
|
|
96
96
|
|
|
97
97
|
## Offline Apps
|
|
98
98
|
|
|
99
|
-
By default,
|
|
99
|
+
By default, the package inlines its bundled `@google/model-viewer` runtime, so
|
|
100
|
+
local model assets can render without a CDN request. If the user wants to provide
|
|
101
|
+
a custom runtime, use:
|
|
100
102
|
|
|
101
103
|
```tsx
|
|
102
104
|
<ModelViewerWebView
|
|
@@ -64,10 +64,14 @@ type ModelViewerHtmlOptions = {
|
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
Consumers pass `htmlOptions` without `modelUri`; the component injects it.
|
|
67
|
+
The package inlines bundled `@google/model-viewer` 4.2.0 by default.
|
|
68
|
+
`modelViewerScriptUrl` and `modelViewerScript` override that bundled runtime.
|
|
67
69
|
|
|
68
70
|
## Utility Functions
|
|
69
71
|
|
|
70
72
|
```ts
|
|
73
|
+
BUNDLED_MODEL_VIEWER_VERSION
|
|
74
|
+
MODEL_VIEWER_CDN_SCRIPT_URL
|
|
71
75
|
buildModelViewerHtml(options)
|
|
72
76
|
parseModelViewerMessage(data)
|
|
73
77
|
isModelViewerErrorStatus(status)
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ export {
|
|
|
3
3
|
type ModelViewerWebViewProps,
|
|
4
4
|
} from "./ModelViewerWebView";
|
|
5
5
|
export {
|
|
6
|
+
BUNDLED_MODEL_VIEWER_VERSION,
|
|
6
7
|
buildModelViewerHtml,
|
|
7
8
|
DEFAULT_MODEL_VIEWER_SCRIPT_URL,
|
|
8
9
|
isModelViewerErrorStatus,
|
|
10
|
+
MODEL_VIEWER_CDN_SCRIPT_URL,
|
|
9
11
|
MODEL_VIEWER_DOM_READY_EVENT,
|
|
10
12
|
MODEL_VIEWER_LOADED_EVENT,
|
|
11
13
|
MODEL_VIEWER_MODEL_ERROR_EVENT,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export declare const MODEL_VIEWER_CDN_SCRIPT_URL = "https://ajax.googleapis.com/ajax/libs/model-viewer/4.2.0/model-viewer.min.js";
|
|
1
2
|
export declare const DEFAULT_MODEL_VIEWER_SCRIPT_URL = "https://ajax.googleapis.com/ajax/libs/model-viewer/4.2.0/model-viewer.min.js";
|
|
3
|
+
export { BUNDLED_MODEL_VIEWER_VERSION } from "../vendor/model-viewer/runtime";
|
|
2
4
|
export declare const MODEL_VIEWER_DOM_READY_EVENT = "dom-ready";
|
|
3
5
|
export declare const MODEL_VIEWER_LOADED_EVENT = "model-loaded";
|
|
4
6
|
export declare const MODEL_VIEWER_MODEL_ERROR_EVENT = "model-error";
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const {
|
|
2
|
+
BUNDLED_MODEL_VIEWER_SCRIPT,
|
|
3
|
+
BUNDLED_MODEL_VIEWER_VERSION,
|
|
4
|
+
} = require("../vendor/model-viewer/runtime");
|
|
5
|
+
|
|
6
|
+
const MODEL_VIEWER_CDN_SCRIPT_URL =
|
|
2
7
|
"https://ajax.googleapis.com/ajax/libs/model-viewer/4.2.0/model-viewer.min.js";
|
|
8
|
+
const DEFAULT_MODEL_VIEWER_SCRIPT_URL = MODEL_VIEWER_CDN_SCRIPT_URL;
|
|
3
9
|
|
|
4
10
|
const MODEL_VIEWER_DOM_READY_EVENT = "dom-ready";
|
|
5
11
|
const MODEL_VIEWER_LOADED_EVENT = "model-loaded";
|
|
@@ -133,8 +139,11 @@ function getModelViewerScriptTag(options) {
|
|
|
133
139
|
return `<script type="module">${escapeScriptContent(options.modelViewerScript)}</script>`;
|
|
134
140
|
}
|
|
135
141
|
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
if (options.modelViewerScriptUrl) {
|
|
143
|
+
return `<script type="module" src="${escapeHtmlAttribute(options.modelViewerScriptUrl)}"></script>`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return `<script type="module">/* @google/model-viewer ${BUNDLED_MODEL_VIEWER_VERSION} bundled runtime */\n${escapeScriptContent(BUNDLED_MODEL_VIEWER_SCRIPT)}</script>`;
|
|
138
147
|
}
|
|
139
148
|
|
|
140
149
|
function htmlAttribute(name, value) {
|
|
@@ -178,6 +187,8 @@ function sanitizeCssColor(value) {
|
|
|
178
187
|
}
|
|
179
188
|
|
|
180
189
|
exports.DEFAULT_MODEL_VIEWER_SCRIPT_URL = DEFAULT_MODEL_VIEWER_SCRIPT_URL;
|
|
190
|
+
exports.MODEL_VIEWER_CDN_SCRIPT_URL = MODEL_VIEWER_CDN_SCRIPT_URL;
|
|
191
|
+
exports.BUNDLED_MODEL_VIEWER_VERSION = BUNDLED_MODEL_VIEWER_VERSION;
|
|
181
192
|
exports.MODEL_VIEWER_DOM_READY_EVENT = MODEL_VIEWER_DOM_READY_EVENT;
|
|
182
193
|
exports.MODEL_VIEWER_LOADED_EVENT = MODEL_VIEWER_LOADED_EVENT;
|
|
183
194
|
exports.MODEL_VIEWER_MODEL_ERROR_EVENT = MODEL_VIEWER_MODEL_ERROR_EVENT;
|
package/docs/COMPATIBILITY.md
CHANGED
|
@@ -6,7 +6,7 @@ This package is a WebView bridge. Compatibility depends on:
|
|
|
6
6
|
- React Native
|
|
7
7
|
- `react-native-webview`
|
|
8
8
|
- the Android System WebView or iOS WKWebView
|
|
9
|
-
-
|
|
9
|
+
- the bundled `@google/model-viewer` runtime
|
|
10
10
|
- how the consuming app bundles `.glb` and `.gltf` files
|
|
11
11
|
|
|
12
12
|
## Supported Peer Ranges
|
|
@@ -30,6 +30,7 @@ Current local integration target:
|
|
|
30
30
|
- React 19.1
|
|
31
31
|
- React Native 0.81
|
|
32
32
|
- `react-native-webview` 13.15
|
|
33
|
+
- `@google/model-viewer` 4.2.0
|
|
33
34
|
- TypeScript 5.9
|
|
34
35
|
|
|
35
36
|
Automated checks validate:
|
|
@@ -108,5 +109,5 @@ For local development, configure the consuming app's Metro setup to:
|
|
|
108
109
|
found.
|
|
109
110
|
- Keep dev dependencies pinned to one known-good React Native stack.
|
|
110
111
|
- Use CI and device smoke tests before raising support claims.
|
|
111
|
-
- If `<model-viewer>` changes behavior, update README examples
|
|
112
|
-
changing the
|
|
112
|
+
- If `<model-viewer>` changes behavior, update README examples, vendor metadata,
|
|
113
|
+
third-party notices, and tests before changing the bundled runtime version.
|
package/docs/HOW_IT_WORKS.md
CHANGED
|
@@ -77,15 +77,23 @@ to avoid injecting arbitrary CSS into generated HTML.
|
|
|
77
77
|
|
|
78
78
|
## Script Loading
|
|
79
79
|
|
|
80
|
-
By default, the HTML
|
|
80
|
+
By default, the HTML inlines the vendored runtime:
|
|
81
81
|
|
|
82
82
|
```text
|
|
83
|
-
|
|
83
|
+
@google/model-viewer 4.2.0
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
This avoids a CDN request at runtime, so a bundled/local model asset can render
|
|
87
|
+
without network access. It also makes each package version deterministic: the
|
|
88
|
+
same npm package version always embeds the same `<model-viewer>` runtime.
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
The vendored runtime is generated into `vendor/model-viewer/runtime.js` from
|
|
91
|
+
`@google/model-viewer`'s `dist/model-viewer.min.js`. Source hashes and license
|
|
92
|
+
metadata are recorded in `vendor/model-viewer/SOURCE.md`.
|
|
93
|
+
|
|
94
|
+
Apps that want to use a different runtime can provide either:
|
|
95
|
+
|
|
96
|
+
- `modelViewerScriptUrl`, such as a CDN URL or `file:` URL to another script
|
|
89
97
|
- `modelViewerScript`, an inline module script string
|
|
90
98
|
|
|
91
99
|
Inline script content escapes closing `</script>` sequences to avoid breaking
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-model-viewer-webview",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A WebView-backed GLB and glTF model viewer for React Native and Expo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,18 +31,22 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"example",
|
|
33
33
|
"src",
|
|
34
|
+
"vendor",
|
|
35
|
+
"scripts",
|
|
34
36
|
"CHANGELOG.md",
|
|
35
37
|
"CONTRIBUTING.md",
|
|
36
38
|
"LICENSE",
|
|
37
39
|
"llms.txt",
|
|
38
40
|
"README.md",
|
|
39
41
|
"SECURITY.md",
|
|
42
|
+
"THIRD_PARTY_NOTICES.md",
|
|
40
43
|
"docs",
|
|
41
44
|
"tsconfig.json"
|
|
42
45
|
],
|
|
43
46
|
"sideEffects": false,
|
|
44
47
|
"scripts": {
|
|
45
48
|
"check": "npm test && npm run typecheck && npm run pack:dry-run",
|
|
49
|
+
"generate:model-viewer-runtime": "node scripts/generate-model-viewer-runtime.js",
|
|
46
50
|
"test": "node --test test/*.test.js",
|
|
47
51
|
"pack:dry-run": "npm pack --dry-run",
|
|
48
52
|
"typecheck": "tsc --noEmit"
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const childProcess = require("node:child_process");
|
|
4
|
+
const crypto = require("node:crypto");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const os = require("node:os");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
|
|
9
|
+
const MODEL_VIEWER_PACKAGE = "@google/model-viewer";
|
|
10
|
+
const MODEL_VIEWER_VERSION = "4.2.0";
|
|
11
|
+
const packageRoot = path.resolve(__dirname, "..");
|
|
12
|
+
const vendorRoot = path.join(packageRoot, "vendor", "model-viewer");
|
|
13
|
+
|
|
14
|
+
function main() {
|
|
15
|
+
const packageDir =
|
|
16
|
+
process.env.MODEL_VIEWER_PACKAGE_DIR || downloadModelViewerPackage();
|
|
17
|
+
const runtimeSourcePath = path.join(packageDir, "dist", "model-viewer.min.js");
|
|
18
|
+
const licensePath = path.join(packageDir, "LICENSE");
|
|
19
|
+
|
|
20
|
+
const runtimeSource = fs.readFileSync(runtimeSourcePath, "utf8");
|
|
21
|
+
const license = fs.readFileSync(licensePath, "utf8");
|
|
22
|
+
const runtimeHash = sha256(runtimeSource);
|
|
23
|
+
const packageHash = findPackageHash(packageDir);
|
|
24
|
+
|
|
25
|
+
fs.mkdirSync(vendorRoot, { recursive: true });
|
|
26
|
+
fs.writeFileSync(
|
|
27
|
+
path.join(vendorRoot, "runtime.js"),
|
|
28
|
+
[
|
|
29
|
+
`"use strict";`,
|
|
30
|
+
"",
|
|
31
|
+
`const BUNDLED_MODEL_VIEWER_VERSION = ${JSON.stringify(MODEL_VIEWER_VERSION)};`,
|
|
32
|
+
`const BUNDLED_MODEL_VIEWER_SCRIPT = ${JSON.stringify(runtimeSource)};`,
|
|
33
|
+
"",
|
|
34
|
+
"exports.BUNDLED_MODEL_VIEWER_VERSION = BUNDLED_MODEL_VIEWER_VERSION;",
|
|
35
|
+
"exports.BUNDLED_MODEL_VIEWER_SCRIPT = BUNDLED_MODEL_VIEWER_SCRIPT;",
|
|
36
|
+
"",
|
|
37
|
+
].join("\n"),
|
|
38
|
+
);
|
|
39
|
+
fs.writeFileSync(
|
|
40
|
+
path.join(vendorRoot, "runtime.d.ts"),
|
|
41
|
+
[
|
|
42
|
+
`export declare const BUNDLED_MODEL_VIEWER_VERSION = ${JSON.stringify(MODEL_VIEWER_VERSION)};`,
|
|
43
|
+
"export declare const BUNDLED_MODEL_VIEWER_SCRIPT: string;",
|
|
44
|
+
"",
|
|
45
|
+
].join("\n"),
|
|
46
|
+
);
|
|
47
|
+
fs.writeFileSync(path.join(vendorRoot, "LICENSE"), license);
|
|
48
|
+
fs.writeFileSync(
|
|
49
|
+
path.join(vendorRoot, "VERSION"),
|
|
50
|
+
`${MODEL_VIEWER_PACKAGE} ${MODEL_VIEWER_VERSION}\n`,
|
|
51
|
+
);
|
|
52
|
+
fs.writeFileSync(
|
|
53
|
+
path.join(vendorRoot, "SOURCE.md"),
|
|
54
|
+
buildSourceNotice({ packageHash, runtimeHash, runtimeSource }),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function downloadModelViewerPackage() {
|
|
59
|
+
const tempDir = fs.mkdtempSync(
|
|
60
|
+
path.join(os.tmpdir(), "react-native-model-viewer-webview-"),
|
|
61
|
+
);
|
|
62
|
+
const packResult = childProcess.spawnSync(
|
|
63
|
+
"npm",
|
|
64
|
+
["pack", `${MODEL_VIEWER_PACKAGE}@${MODEL_VIEWER_VERSION}`, "--pack-destination", tempDir],
|
|
65
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] },
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (packResult.status !== 0) {
|
|
69
|
+
throw new Error(packResult.stderr || packResult.stdout || "npm pack failed");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const tarballPath = fs
|
|
73
|
+
.readdirSync(tempDir)
|
|
74
|
+
.filter((fileName) => fileName.endsWith(".tgz"))
|
|
75
|
+
.map((fileName) => path.join(tempDir, fileName))[0];
|
|
76
|
+
|
|
77
|
+
if (!tarballPath) {
|
|
78
|
+
throw new Error("npm pack did not produce a .tgz file");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const tarResult = childProcess.spawnSync(
|
|
82
|
+
"tar",
|
|
83
|
+
["-xzf", tarballPath, "-C", tempDir],
|
|
84
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] },
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (tarResult.status !== 0) {
|
|
88
|
+
throw new Error(tarResult.stderr || tarResult.stdout || "tar extraction failed");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return path.join(tempDir, "package");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function findPackageHash(packageDir) {
|
|
95
|
+
const parentDir = path.dirname(packageDir);
|
|
96
|
+
const tarballPath = fs
|
|
97
|
+
.readdirSync(parentDir)
|
|
98
|
+
.filter((fileName) => fileName.endsWith(".tgz"))
|
|
99
|
+
.map((fileName) => path.join(parentDir, fileName))[0];
|
|
100
|
+
|
|
101
|
+
if (!tarballPath) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return sha256(fs.readFileSync(tarballPath));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function sha256(value) {
|
|
109
|
+
return crypto.createHash("sha256").update(value).digest("hex");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function buildSourceNotice({ packageHash, runtimeHash, runtimeSource }) {
|
|
113
|
+
const packageHashLine = packageHash
|
|
114
|
+
? `- Package tarball SHA-256: \`${packageHash}\``
|
|
115
|
+
: "- Package tarball SHA-256: not recorded; regenerate from an npm tarball to update this value.";
|
|
116
|
+
|
|
117
|
+
return [
|
|
118
|
+
"# Vendored model-viewer Runtime",
|
|
119
|
+
"",
|
|
120
|
+
`This directory vendors ${MODEL_VIEWER_PACKAGE}@${MODEL_VIEWER_VERSION} so the default`,
|
|
121
|
+
"`ModelViewerWebView` runtime can load inside a React Native WebView without",
|
|
122
|
+
"fetching Google's CDN script at render time.",
|
|
123
|
+
"",
|
|
124
|
+
"## Source",
|
|
125
|
+
"",
|
|
126
|
+
`- Package: \`${MODEL_VIEWER_PACKAGE}@${MODEL_VIEWER_VERSION}\``,
|
|
127
|
+
`- npm: <https://www.npmjs.com/package/${MODEL_VIEWER_PACKAGE}/v/${MODEL_VIEWER_VERSION}>`,
|
|
128
|
+
"- Repository: <https://github.com/google/model-viewer>",
|
|
129
|
+
"- Source file: `dist/model-viewer.min.js`",
|
|
130
|
+
packageHashLine,
|
|
131
|
+
`- Source file SHA-256: \`${runtimeHash}\``,
|
|
132
|
+
`- Source file bytes: \`${Buffer.byteLength(runtimeSource, "utf8")}\``,
|
|
133
|
+
"",
|
|
134
|
+
"## Generated Files",
|
|
135
|
+
"",
|
|
136
|
+
"- `runtime.js` embeds `dist/model-viewer.min.js` as a CommonJS string export.",
|
|
137
|
+
"- `runtime.d.ts` exposes the generated runtime constants to TypeScript.",
|
|
138
|
+
"- `LICENSE` contains the upstream Apache-2.0 license text.",
|
|
139
|
+
"- `VERSION` records the exact upstream package version.",
|
|
140
|
+
"",
|
|
141
|
+
"Regenerate these files with:",
|
|
142
|
+
"",
|
|
143
|
+
"```bash",
|
|
144
|
+
"npm run generate:model-viewer-runtime",
|
|
145
|
+
"```",
|
|
146
|
+
"",
|
|
147
|
+
].join("\n");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
main();
|
package/src/index.ts
CHANGED
|
@@ -3,9 +3,11 @@ export {
|
|
|
3
3
|
type ModelViewerWebViewProps,
|
|
4
4
|
} from "./ModelViewerWebView";
|
|
5
5
|
export {
|
|
6
|
+
BUNDLED_MODEL_VIEWER_VERSION,
|
|
6
7
|
buildModelViewerHtml,
|
|
7
8
|
DEFAULT_MODEL_VIEWER_SCRIPT_URL,
|
|
8
9
|
isModelViewerErrorStatus,
|
|
10
|
+
MODEL_VIEWER_CDN_SCRIPT_URL,
|
|
9
11
|
MODEL_VIEWER_DOM_READY_EVENT,
|
|
10
12
|
MODEL_VIEWER_LOADED_EVENT,
|
|
11
13
|
MODEL_VIEWER_MODEL_ERROR_EVENT,
|
package/src/model-viewer-html.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
BUNDLED_MODEL_VIEWER_SCRIPT,
|
|
3
|
+
BUNDLED_MODEL_VIEWER_VERSION,
|
|
4
|
+
} from "../vendor/model-viewer/runtime";
|
|
5
|
+
|
|
6
|
+
export const MODEL_VIEWER_CDN_SCRIPT_URL =
|
|
2
7
|
"https://ajax.googleapis.com/ajax/libs/model-viewer/4.2.0/model-viewer.min.js";
|
|
8
|
+
export const DEFAULT_MODEL_VIEWER_SCRIPT_URL = MODEL_VIEWER_CDN_SCRIPT_URL;
|
|
9
|
+
export { BUNDLED_MODEL_VIEWER_VERSION };
|
|
3
10
|
|
|
4
11
|
export const MODEL_VIEWER_DOM_READY_EVENT = "dom-ready";
|
|
5
12
|
export const MODEL_VIEWER_LOADED_EVENT = "model-loaded";
|
|
@@ -159,8 +166,11 @@ function getModelViewerScriptTag(options: ModelViewerHtmlOptions) {
|
|
|
159
166
|
return `<script type="module">${escapeScriptContent(options.modelViewerScript)}</script>`;
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
if (options.modelViewerScriptUrl) {
|
|
170
|
+
return `<script type="module" src="${escapeHtmlAttribute(options.modelViewerScriptUrl)}"></script>`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return `<script type="module">/* @google/model-viewer ${BUNDLED_MODEL_VIEWER_VERSION} bundled runtime */\n${escapeScriptContent(BUNDLED_MODEL_VIEWER_SCRIPT)}</script>`;
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
function htmlAttribute(
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|