@aethervtt/shard-texture 0.2.0 → 0.2.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/basis.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { ShardError } from "@aethervtt/shard-core";
2
+ import { commonJsContext, readCodecAsset } from "@aethervtt/shard-platform-node/codecs";
2
3
  const modules = /* @__PURE__ */ new Map();
4
+ const vendorUrls = {
5
+ "basis_encoder.js": new URL("../vendor/basis/basis_encoder.js", import.meta.url),
6
+ "basis_encoder.wasm": new URL("../vendor/basis/basis_encoder.wasm", import.meta.url),
7
+ "basis_transcoder.js": new URL("../vendor/basis/basis_transcoder.js", import.meta.url),
8
+ "basis_transcoder.wasm": new URL("../vendor/basis/basis_transcoder.wasm", import.meta.url)
9
+ };
3
10
  async function readVendor(file) {
4
- const url = new URL(`../vendor/basis/${file}`, import.meta.url);
5
- if (url.protocol === "file:") {
6
- const { readFile } = await import("node:fs/promises");
7
- const data = await readFile(url);
8
- return file.endsWith(".js") ? { text: data.toString("utf8") } : { bytes: new Uint8Array(data) };
9
- }
10
- const res = await fetch(url);
11
- if (!res.ok) throw new ShardError("texture/transcoder-unavailable", `Couldn't fetch ${url}`);
12
- return file.endsWith(".js") ? { text: await res.text() } : { bytes: new Uint8Array(await res.arrayBuffer()) };
11
+ const data = await readCodecAsset(vendorUrls[file]);
12
+ return file.endsWith(".js") ? { text: new TextDecoder().decode(data) } : { bytes: data };
13
13
  }
14
14
  function load(name) {
15
15
  let pending = modules.get(name);
@@ -20,14 +20,7 @@ function load(name) {
20
20
  readVendor(`${name}.js`),
21
21
  readVendor(`${name}.wasm`)
22
22
  ]);
23
- let require2;
24
- let dirname = "";
25
- if (typeof process !== "undefined" && process.versions?.node) {
26
- const { createRequire } = await import("node:module");
27
- const { fileURLToPath } = await import("node:url");
28
- require2 = createRequire(import.meta.url);
29
- dirname = fileURLToPath(new URL("../vendor/basis/", import.meta.url));
30
- }
23
+ const { require: require2, dirname, filename } = commonJsContext(vendorUrls[`${name}.js`]);
31
24
  const factory = new Function(
32
25
  "module",
33
26
  "exports",
@@ -36,7 +29,7 @@ function load(name) {
36
29
  "__filename",
37
30
  `${text}
38
31
  return BASIS`
39
- )(void 0, void 0, require2, dirname, `${dirname}${name}.js`);
32
+ )(void 0, void 0, require2, dirname, filename);
40
33
  const quiet = () => {
41
34
  };
42
35
  const mod = await factory({ wasmBinary: bytes, print: quiet, printErr: quiet });
@@ -63,7 +56,7 @@ async function encodeBasis(rgba, width, height, usage, mode, mipmaps) {
63
56
  try {
64
57
  enc.setCreateKTX2File(true);
65
58
  const format = mode === "uastc" ? basis.basis_tex_format.cUASTC_LDR_4x4 : basis.basis_tex_format.cETC1S;
66
- enc.setFormatModeAndQualityEffort(format.value, -1, -1, true);
59
+ enc.setFormatModeAndQualityEffort(format.value, mode === "etc1s" ? 128 : -1, -1, true);
67
60
  enc.setKTX2UASTCSupercompression(mode === "uastc");
68
61
  const color = usage === "color";
69
62
  enc.setPerceptual(color);
@@ -1,15 +1,16 @@
1
1
  import { ShardError } from "@aethervtt/shard-core";
2
+ import { nodeCodecs, readCodecDependency } from "@aethervtt/shard-platform-node/codecs";
2
3
  let ready;
3
4
  function decoder() {
4
5
  ready ??= (async () => {
5
- const mod = await import("@jsquash/webp/decode");
6
- if (typeof process !== "undefined" && process.versions?.node) {
7
- const wasmUrl = new URL(
6
+ const mod = await import("@jsquash/webp/decode.js");
7
+ if (nodeCodecs) {
8
+ const bytes = await readCodecDependency(
9
+ "@jsquash/webp/decode.js",
8
10
  "./codec/dec/webp_dec.wasm",
9
- import.meta.resolve("@jsquash/webp/decode")
11
+ import.meta.url
10
12
  );
11
- const { readFile } = await import("node:fs/promises");
12
- await mod.init(await WebAssembly.compile(await readFile(wasmUrl)));
13
+ await mod.init(await WebAssembly.compile(bytes));
13
14
  }
14
15
  return mod.default;
15
16
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aethervtt/shard-texture",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -18,11 +18,12 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@jsquash/webp": "^1.5.0",
21
- "@aethervtt/shard-assets": "0.2.0",
22
- "@aethervtt/shard-core": "0.2.0",
21
+ "@aethervtt/shard-assets": "0.2.2",
22
+ "@aethervtt/shard-core": "0.2.2",
23
23
  "fzstd": "^0.1.1",
24
24
  "jpeg-js": "^0.4.4",
25
- "ktx-parse": "^2.0.0"
25
+ "ktx-parse": "^2.0.0",
26
+ "@aethervtt/shard-platform-node": "0.2.2"
26
27
  },
27
28
  "repository": {
28
29
  "type": "git",
@@ -34,6 +35,6 @@
34
35
  "provenance": true
35
36
  },
36
37
  "shard": {
37
- "buildSha": "32c22a3944ed23f5d1baa90bf7cc9fae724f5fd8"
38
+ "buildSha": "c92ccf813334ab40ce73d5f4ad98680bf1dcf9e4"
38
39
  }
39
40
  }