@preference-sl/prefconfigurator-wasm 0.1.3 → 0.1.4
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/js/gltf-storage.js +26 -17
- package/package.json +1 -1
- package/index.js +0 -3
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.4",
|
|
7
7
|
"files": [
|
|
8
8
|
"_framework/**",
|
|
9
9
|
"scripts/**",
|
package/index.js
DELETED