@preference-sl/prefconfigurator-wasm 0.1.3 → 0.1.6
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/README.md +4 -4
- package/js/gltf-storage.js +26 -17
- package/package.json +1 -1
- package/scripts/postinstall.js +7 -17
- package/index.js +0 -3
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Upon install, postinstall copies into the consumer project:
|
|
4
4
|
|
|
5
|
-
- public
|
|
6
|
-
- public
|
|
7
|
-
- public
|
|
8
|
-
- public
|
|
5
|
+
- public/preference-sl/prefconfigurator-wasm/_framework
|
|
6
|
+
- public/preference-sl/prefconfigurator-wasm/main.js (if not present)
|
|
7
|
+
- public/preference-sl/prefconfigurator-wasm/index.demo.html (if not present; example to try it)
|
|
8
|
+
- public/preference-sl/prefconfigurator-wasm/ extra JS found under wwwroot (without overwriting existing files)
|
|
9
9
|
|
|
10
10
|
Env vars:
|
|
11
11
|
- PUBLIC_DIR — destination root (auto-detects public, wwwroot, or src/assets if not set)
|
package/js/gltf-storage.js
CHANGED
|
@@ -51,36 +51,28 @@ export async function saveModel(modelDataStr, storeName) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Cargar modelo
|
|
54
|
-
|
|
54
|
+
export function loadModel(modelId, storeName) {
|
|
55
55
|
return new Promise((resolve, reject) => {
|
|
56
|
-
if (!
|
|
56
|
+
if (!globalThis.gltfDB) {
|
|
57
57
|
reject(new Error('Database not initialized'));
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
request.onerror = () => reject(request.error);
|
|
66
|
-
request.onsuccess = () => {
|
|
67
|
-
if (request.result) {
|
|
68
|
-
resolve(request.result);
|
|
69
|
-
} else {
|
|
70
|
-
resolve(null);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
60
|
+
const tx = globalThis.gltfDB.transaction([storeName], 'readonly');
|
|
61
|
+
const store = tx.objectStore(storeName);
|
|
62
|
+
const req = store.get(modelId);
|
|
63
|
+
req.onerror = () => reject(req.error);
|
|
64
|
+
req.onsuccess = () => resolve(req.result ?? null);
|
|
73
65
|
});
|
|
74
66
|
}
|
|
75
67
|
|
|
76
|
-
|
|
68
|
+
export function downloadFileFromBytes(fileName, bytesBase64, mimeType) {
|
|
77
69
|
const link = document.createElement('a');
|
|
78
70
|
link.download = fileName;
|
|
79
71
|
link.href = `data:${mimeType};base64,${bytesBase64}`;
|
|
80
72
|
document.body.appendChild(link);
|
|
81
73
|
link.click();
|
|
82
74
|
document.body.removeChild(link);
|
|
83
|
-
}
|
|
75
|
+
}
|
|
84
76
|
|
|
85
77
|
// Obtener todos los modelos (solo metadata)
|
|
86
78
|
export async function getAllModels(storeName) {
|
|
@@ -143,6 +135,23 @@ export async function clearAll(storeName) {
|
|
|
143
135
|
});
|
|
144
136
|
}
|
|
145
137
|
|
|
138
|
+
(function attachPublicAPI(global) {
|
|
139
|
+
const root = (global.PrefConfigurator ??= {});
|
|
140
|
+
const storage = {
|
|
141
|
+
initDb,
|
|
142
|
+
saveModel,
|
|
143
|
+
loadModel,
|
|
144
|
+
getAllModels,
|
|
145
|
+
deleteModel,
|
|
146
|
+
clearAll,
|
|
147
|
+
downloadFileFromBytes,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// versionado del módulo público
|
|
151
|
+
root.version = root.version ?? '1.0.0';
|
|
152
|
+
root.storage = Object.freeze(storage);
|
|
153
|
+
})(globalThis);
|
|
154
|
+
|
|
146
155
|
// Utilidades
|
|
147
156
|
//_arrayBufferToBase64: function (buffer) {
|
|
148
157
|
// let binary = '';
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"postinstall": "node scripts/postinstall.js"
|
|
4
4
|
},
|
|
5
5
|
"description": ".NET WebAssembly runtime package that centralizes logic for building product configurators, exposing a simple API for integration into ecommerce platforms.",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.6",
|
|
7
7
|
"files": [
|
|
8
8
|
"_framework/**",
|
|
9
9
|
"scripts/**",
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
2
3
|
const fs = require("fs");
|
|
3
4
|
const path = require("path");
|
|
4
5
|
|
|
@@ -25,19 +26,6 @@ function copyFileIfAbsent(src, dest) {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
function getAppFolder(frameworkDir) {
|
|
29
|
-
try {
|
|
30
|
-
const bootPath = path.join(frameworkDir, "blazor.boot.json");
|
|
31
|
-
if (fs.existsSync(bootPath)) {
|
|
32
|
-
const boot = JSON.parse(fs.readFileSync(bootPath, "utf8"));
|
|
33
|
-
if (boot && typeof boot.mainAssemblyName === "string" && boot.mainAssemblyName) {
|
|
34
|
-
return boot.mainAssemblyName;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} catch {}
|
|
38
|
-
return "wasm-app";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
29
|
try {
|
|
42
30
|
const pkgRoot = __dirname ? path.resolve(__dirname, "..") : process.cwd();
|
|
43
31
|
const srcFramework = path.join(pkgRoot, "_framework");
|
|
@@ -54,9 +42,12 @@ try {
|
|
|
54
42
|
}
|
|
55
43
|
if (!targetPublic) targetPublic = path.resolve(consumerRoot, "public");
|
|
56
44
|
|
|
45
|
+
// Siempre bajo public/preference-sl/<nombrepaquete>, y <nombrepaquete> en minúsculas
|
|
46
|
+
const packageName = "prefconfigurator-wasm".toLowerCase();
|
|
47
|
+
const preferenceNamespace = "preference-sl";
|
|
48
|
+
const destRoot = path.join(targetPublic, preferenceNamespace, packageName);
|
|
49
|
+
|
|
57
50
|
const wasmSubdir = process.env.WASM_SUBDIR || "_framework";
|
|
58
|
-
const appFolderName = getAppFolder(srcFramework);
|
|
59
|
-
const destRoot = path.join(targetPublic, appFolderName);
|
|
60
51
|
const destFramework = path.join(destRoot, wasmSubdir);
|
|
61
52
|
|
|
62
53
|
// 1) Copiar runtime
|
|
@@ -89,7 +80,6 @@ try {
|
|
|
89
80
|
}
|
|
90
81
|
|
|
91
82
|
// 4) Copiar TODOS los .js fuera de _framework y sin sobreescribir, preservando estructura.
|
|
92
|
-
// Excluye: main.js (raÃz del paquete), index.html, scripts/postinstall.js
|
|
93
83
|
console.log(`[${path.basename(pkgRoot)}] Copying extra JS -> ${destRoot}`);
|
|
94
84
|
const excludeAbs = new Set([
|
|
95
85
|
path.join(pkgRoot, "main.js"),
|
package/index.js
DELETED