open-ultrahdr 0.1.1 → 0.1.2

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/dist/index.d.mts CHANGED
@@ -167,6 +167,23 @@ declare const smallSizeEncodeOptions: UltraHdrEncodeOptions;
167
167
  * ```
168
168
  */
169
169
  declare function setLocation(newLocation: string): void;
170
+ /**
171
+ * Sets a direct URL (including data URLs) for the WASM module.
172
+ *
173
+ * Use this when the WASM binary is inlined as a base64 data URL
174
+ * at build time. Unlike `setLocation`, this passes the URL directly
175
+ * to the WASM init function without appending a filename.
176
+ *
177
+ * @param url - Direct URL or data URL for the WASM binary.
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * // With a build tool that inlines WASM as base64 data URLs:
182
+ * import wasmDataUrl from 'open-ultrahdr-wasm/pkg/open_ultrahdr_bg.wasm';
183
+ * setWasmUrl(wasmDataUrl);
184
+ * ```
185
+ */
186
+ declare function setWasmUrl(url: string): void;
170
187
  /**
171
188
  * Checks if a buffer contains an UltraHDR image.
172
189
  *
@@ -322,4 +339,4 @@ declare function estimateHdrHeadroom(metadata: GainMapMetadata): Promise<number>
322
339
  */
323
340
  declare function isMeaningfulHdr(metadata: GainMapMetadata): Promise<boolean>;
324
341
 
325
- export { ColorGamut, type GainMapMetadata, type ItemId, TransferFunction, type UltraHdrDecodeResult, type UltraHdrEncodeOptions, type UltraHdrProbeResult, decodeUltraHdr, defaultEncodeOptions, encodeUltraHdr, estimateHdrHeadroom, extractSdrBase, getMetadata, highQualityEncodeOptions, isMeaningfulHdr, isUltraHdr, probeUltraHdr, setLocation, smallSizeEncodeOptions, validateMetadata };
342
+ export { ColorGamut, type GainMapMetadata, type ItemId, TransferFunction, type UltraHdrDecodeResult, type UltraHdrEncodeOptions, type UltraHdrProbeResult, decodeUltraHdr, defaultEncodeOptions, encodeUltraHdr, estimateHdrHeadroom, extractSdrBase, getMetadata, highQualityEncodeOptions, isMeaningfulHdr, isUltraHdr, probeUltraHdr, setLocation, setWasmUrl, smallSizeEncodeOptions, validateMetadata };
package/dist/index.d.ts CHANGED
@@ -167,6 +167,23 @@ declare const smallSizeEncodeOptions: UltraHdrEncodeOptions;
167
167
  * ```
168
168
  */
169
169
  declare function setLocation(newLocation: string): void;
170
+ /**
171
+ * Sets a direct URL (including data URLs) for the WASM module.
172
+ *
173
+ * Use this when the WASM binary is inlined as a base64 data URL
174
+ * at build time. Unlike `setLocation`, this passes the URL directly
175
+ * to the WASM init function without appending a filename.
176
+ *
177
+ * @param url - Direct URL or data URL for the WASM binary.
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * // With a build tool that inlines WASM as base64 data URLs:
182
+ * import wasmDataUrl from 'open-ultrahdr-wasm/pkg/open_ultrahdr_bg.wasm';
183
+ * setWasmUrl(wasmDataUrl);
184
+ * ```
185
+ */
186
+ declare function setWasmUrl(url: string): void;
170
187
  /**
171
188
  * Checks if a buffer contains an UltraHDR image.
172
189
  *
@@ -322,4 +339,4 @@ declare function estimateHdrHeadroom(metadata: GainMapMetadata): Promise<number>
322
339
  */
323
340
  declare function isMeaningfulHdr(metadata: GainMapMetadata): Promise<boolean>;
324
341
 
325
- export { ColorGamut, type GainMapMetadata, type ItemId, TransferFunction, type UltraHdrDecodeResult, type UltraHdrEncodeOptions, type UltraHdrProbeResult, decodeUltraHdr, defaultEncodeOptions, encodeUltraHdr, estimateHdrHeadroom, extractSdrBase, getMetadata, highQualityEncodeOptions, isMeaningfulHdr, isUltraHdr, probeUltraHdr, setLocation, smallSizeEncodeOptions, validateMetadata };
342
+ export { ColorGamut, type GainMapMetadata, type ItemId, TransferFunction, type UltraHdrDecodeResult, type UltraHdrEncodeOptions, type UltraHdrProbeResult, decodeUltraHdr, defaultEncodeOptions, encodeUltraHdr, estimateHdrHeadroom, extractSdrBase, getMetadata, highQualityEncodeOptions, isMeaningfulHdr, isUltraHdr, probeUltraHdr, setLocation, setWasmUrl, smallSizeEncodeOptions, validateMetadata };
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ __export(index_exports, {
43
43
  isUltraHdr: () => isUltraHdr,
44
44
  probeUltraHdr: () => probeUltraHdr,
45
45
  setLocation: () => setLocation,
46
+ setWasmUrl: () => setWasmUrl,
46
47
  smallSizeEncodeOptions: () => smallSizeEncodeOptions,
47
48
  validateMetadata: () => validateMetadata
48
49
  });
@@ -89,11 +90,15 @@ var smallSizeEncodeOptions = {
89
90
 
90
91
  // src/index.ts
91
92
  var location = "";
93
+ var wasmUrl = "";
92
94
  var wasmInstance = null;
93
95
  var initPromise = null;
94
96
  function setLocation(newLocation) {
95
97
  location = newLocation;
96
98
  }
99
+ function setWasmUrl(url) {
100
+ wasmUrl = url;
101
+ }
97
102
  function isWasmMetadataInstance(metadata) {
98
103
  return typeof metadata === "object" && metadata !== null && "__wbg_ptr" in metadata;
99
104
  }
@@ -124,7 +129,9 @@ async function getWasm() {
124
129
  initPromise = (async () => {
125
130
  try {
126
131
  const UltraHdrWasm = await import("open-ultrahdr-wasm");
127
- if (location) {
132
+ if (wasmUrl) {
133
+ await UltraHdrWasm.default(wasmUrl);
134
+ } else if (location) {
128
135
  const base = location.endsWith("/") ? location : `${location}/`;
129
136
  const wasmPath = base + "open_ultrahdr_bg.wasm";
130
137
  if (typeof process !== "undefined" && process.versions && process.versions.node) {
@@ -220,6 +227,7 @@ async function isMeaningfulHdr(metadata) {
220
227
  isUltraHdr,
221
228
  probeUltraHdr,
222
229
  setLocation,
230
+ setWasmUrl,
223
231
  smallSizeEncodeOptions,
224
232
  validateMetadata
225
233
  });
package/dist/index.mjs CHANGED
@@ -39,11 +39,15 @@ var smallSizeEncodeOptions = {
39
39
 
40
40
  // src/index.ts
41
41
  var location = "";
42
+ var wasmUrl = "";
42
43
  var wasmInstance = null;
43
44
  var initPromise = null;
44
45
  function setLocation(newLocation) {
45
46
  location = newLocation;
46
47
  }
48
+ function setWasmUrl(url) {
49
+ wasmUrl = url;
50
+ }
47
51
  function isWasmMetadataInstance(metadata) {
48
52
  return typeof metadata === "object" && metadata !== null && "__wbg_ptr" in metadata;
49
53
  }
@@ -74,7 +78,9 @@ async function getWasm() {
74
78
  initPromise = (async () => {
75
79
  try {
76
80
  const UltraHdrWasm = await import("open-ultrahdr-wasm");
77
- if (location) {
81
+ if (wasmUrl) {
82
+ await UltraHdrWasm.default(wasmUrl);
83
+ } else if (location) {
78
84
  const base = location.endsWith("/") ? location : `${location}/`;
79
85
  const wasmPath = base + "open_ultrahdr_bg.wasm";
80
86
  if (typeof process !== "undefined" && process.versions && process.versions.node) {
@@ -169,6 +175,7 @@ export {
169
175
  isUltraHdr,
170
176
  probeUltraHdr,
171
177
  setLocation,
178
+ setWasmUrl,
172
179
  smallSizeEncodeOptions,
173
180
  validateMetadata
174
181
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-ultrahdr",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "UltraHDR (ISO 21496-1) gain map support for JavaScript/TypeScript",
5
5
  "author": "Adam Silverstein",
6
6
  "license": "GPL-2.0-or-later",
package/src/index.ts CHANGED
@@ -98,6 +98,13 @@ interface UltraHdrWasmModule {
98
98
  */
99
99
  let location = '';
100
100
 
101
+ /**
102
+ * Direct URL or data URL for the WASM module.
103
+ * When set, this is passed directly to the WASM init function,
104
+ * bypassing the location prefix + filename construction.
105
+ */
106
+ let wasmUrl = '';
107
+
101
108
  /**
102
109
  * Cached WASM module instance.
103
110
  */
@@ -126,6 +133,26 @@ export function setLocation(newLocation: string): void {
126
133
  location = newLocation;
127
134
  }
128
135
 
136
+ /**
137
+ * Sets a direct URL (including data URLs) for the WASM module.
138
+ *
139
+ * Use this when the WASM binary is inlined as a base64 data URL
140
+ * at build time. Unlike `setLocation`, this passes the URL directly
141
+ * to the WASM init function without appending a filename.
142
+ *
143
+ * @param url - Direct URL or data URL for the WASM binary.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // With a build tool that inlines WASM as base64 data URLs:
148
+ * import wasmDataUrl from 'open-ultrahdr-wasm/pkg/open_ultrahdr_bg.wasm';
149
+ * setWasmUrl(wasmDataUrl);
150
+ * ```
151
+ */
152
+ export function setWasmUrl(url: string): void {
153
+ wasmUrl = url;
154
+ }
155
+
129
156
  /**
130
157
  * Checks if metadata is a WASM class instance (has __wbg_ptr property).
131
158
  */
@@ -176,9 +203,12 @@ async function getWasm(): Promise<UltraHdrWasmModule> {
176
203
  // Dynamic import of the WASM package
177
204
  const UltraHdrWasm = (await import('open-ultrahdr-wasm')) as unknown as UltraHdrWasmModule;
178
205
 
179
- // Initialize WASM with the location prefix for the .wasm file
180
- // If location is set, construct the full URL to the WASM file
181
- if (location) {
206
+ // Initialize WASM module.
207
+ // Priority: wasmUrl (direct URL/data URL) > location (path prefix) > default
208
+ if (wasmUrl) {
209
+ // Direct URL (e.g. inlined base64 data URL from build tool)
210
+ await UltraHdrWasm.default(wasmUrl);
211
+ } else if (location) {
182
212
  const base = location.endsWith('/') ? location : `${location}/`;
183
213
  const wasmPath = base + 'open_ultrahdr_bg.wasm';
184
214