@webxr-jp/texture-compression 0.1.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/README.md +158 -0
- package/dist/index.cjs +200 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +147 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +157 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
- package/wasm/LICENSE +201 -0
- package/wasm/basis_encoder.js +6201 -0
- package/wasm/basis_encoder.wasm +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var UastcQuality = /* @__PURE__ */ ((UastcQuality2) => {
|
|
3
|
+
UastcQuality2[UastcQuality2["Fastest"] = 0] = "Fastest";
|
|
4
|
+
UastcQuality2[UastcQuality2["Faster"] = 1] = "Faster";
|
|
5
|
+
UastcQuality2[UastcQuality2["Default"] = 2] = "Default";
|
|
6
|
+
UastcQuality2[UastcQuality2["Slower"] = 3] = "Slower";
|
|
7
|
+
UastcQuality2[UastcQuality2["VerySlow"] = 4] = "VerySlow";
|
|
8
|
+
return UastcQuality2;
|
|
9
|
+
})(UastcQuality || {});
|
|
10
|
+
|
|
11
|
+
// src/compress.ts
|
|
12
|
+
import { errAsync, ResultAsync as ResultAsync2 } from "neverthrow";
|
|
13
|
+
|
|
14
|
+
// src/encoder.ts
|
|
15
|
+
import { ResultAsync } from "neverthrow";
|
|
16
|
+
import BASIS from "../wasm/basis_encoder.js";
|
|
17
|
+
import wasmUrl from "../wasm/basis_encoder.wasm?url";
|
|
18
|
+
var cachedModule = null;
|
|
19
|
+
function initBasisEncoder() {
|
|
20
|
+
if (cachedModule) {
|
|
21
|
+
return ResultAsync.fromSafePromise(Promise.resolve(cachedModule));
|
|
22
|
+
}
|
|
23
|
+
return ResultAsync.fromPromise(loadBasisModule(), (error) => ({
|
|
24
|
+
type: "WASM_LOAD_ERROR",
|
|
25
|
+
message: `Basis WASM \u30E2\u30B8\u30E5\u30FC\u30EB\u306E\u8AAD\u307F\u8FBC\u307F\u306B\u5931\u6557: ${error instanceof Error ? error.message : String(error)}`
|
|
26
|
+
})).map((module) => {
|
|
27
|
+
cachedModule = module;
|
|
28
|
+
return module;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function disposeBasisEncoder() {
|
|
32
|
+
cachedModule = null;
|
|
33
|
+
}
|
|
34
|
+
function getCachedBasisEncoder() {
|
|
35
|
+
return cachedModule;
|
|
36
|
+
}
|
|
37
|
+
function isBasisEncoderReady() {
|
|
38
|
+
return cachedModule !== null;
|
|
39
|
+
}
|
|
40
|
+
async function loadBasisModule() {
|
|
41
|
+
const moduleObj = await BASIS({
|
|
42
|
+
locateFile: () => wasmUrl
|
|
43
|
+
});
|
|
44
|
+
if (moduleObj.initializeBasis) {
|
|
45
|
+
moduleObj.initializeBasis();
|
|
46
|
+
}
|
|
47
|
+
if (!moduleObj.BasisEncoder) {
|
|
48
|
+
throw new Error("BasisEncoder class not found in module after init");
|
|
49
|
+
}
|
|
50
|
+
return moduleObj;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/compress.ts
|
|
54
|
+
var DEFAULT_OPTIONS = {
|
|
55
|
+
quality: 2 /* Default */,
|
|
56
|
+
compressionLevel: 3,
|
|
57
|
+
generateMipmaps: true,
|
|
58
|
+
supercompression: true
|
|
59
|
+
};
|
|
60
|
+
var MAX_OUTPUT_SIZE = 1024 * 1024 * 24;
|
|
61
|
+
function compressToKtx2(imageData, width, height, options) {
|
|
62
|
+
const validationError = validateInput(imageData, width, height);
|
|
63
|
+
if (validationError) {
|
|
64
|
+
return errAsync(validationError);
|
|
65
|
+
}
|
|
66
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
67
|
+
return initBasisEncoder().andThen(
|
|
68
|
+
(module) => ResultAsync2.fromPromise(
|
|
69
|
+
encodeWithBasis(module, imageData, width, height, opts),
|
|
70
|
+
(error) => ({
|
|
71
|
+
type: "COMPRESSION_ERROR",
|
|
72
|
+
message: `KTX2\u30A8\u30F3\u30B3\u30FC\u30C9\u306B\u5931\u6557: ${error instanceof Error ? error.message : String(error)}`
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function validateInput(imageData, width, height) {
|
|
78
|
+
if (width <= 0 || height <= 0) {
|
|
79
|
+
return {
|
|
80
|
+
type: "INVALID_INPUT",
|
|
81
|
+
message: `\u5E45\u3068\u9AD8\u3055\u306F\u6B63\u306E\u5024\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059: width=${width}, height=${height}`
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const expectedSize = width * height * 4;
|
|
85
|
+
if (imageData.length !== expectedSize) {
|
|
86
|
+
return {
|
|
87
|
+
type: "INVALID_INPUT",
|
|
88
|
+
message: `\u753B\u50CF\u30C7\u30FC\u30BF\u30B5\u30A4\u30BA\u304C\u4E0D\u6B63\u3067\u3059: expected=${expectedSize}, actual=${imageData.length}`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (!isPowerOfTwo(width) || !isPowerOfTwo(height)) {
|
|
92
|
+
console.warn(
|
|
93
|
+
`[texture-compression] \u5E45\u30FB\u9AD8\u3055\u304C2\u306E\u3079\u304D\u4E57\u3067\u306A\u3044\u5834\u5408\u3001\u4E00\u90E8\u306EGPU\u3067\u554F\u984C\u304C\u767A\u751F\u3059\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059: ${width}x${height}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
function isPowerOfTwo(n) {
|
|
99
|
+
return n > 0 && (n & n - 1) === 0;
|
|
100
|
+
}
|
|
101
|
+
async function encodeWithBasis(module, imageData, width, height, options) {
|
|
102
|
+
const encoder = new module.BasisEncoder();
|
|
103
|
+
try {
|
|
104
|
+
encoder.setCreateKTX2File(true);
|
|
105
|
+
encoder.setUASTC(true);
|
|
106
|
+
encoder.setKTX2UASTCSupercompression(options.supercompression);
|
|
107
|
+
encoder.setPackUASTCFlags(options.quality);
|
|
108
|
+
encoder.setCompressionLevel(options.compressionLevel);
|
|
109
|
+
encoder.setMipGen(options.generateMipmaps);
|
|
110
|
+
const success = encoder.setSliceSourceImage(
|
|
111
|
+
0,
|
|
112
|
+
imageData,
|
|
113
|
+
width,
|
|
114
|
+
height,
|
|
115
|
+
module.ldr_image_type.cRGBA32.value
|
|
116
|
+
);
|
|
117
|
+
if (!success) {
|
|
118
|
+
throw new Error("\u30BD\u30FC\u30B9\u753B\u50CF\u306E\u8A2D\u5B9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
|
|
119
|
+
}
|
|
120
|
+
const outputBuffer = new Uint8Array(MAX_OUTPUT_SIZE);
|
|
121
|
+
const outputSize = encoder.encode(outputBuffer);
|
|
122
|
+
if (outputSize === 0) {
|
|
123
|
+
throw new Error("\u30A8\u30F3\u30B3\u30FC\u30C9\u7D50\u679C\u304C\u7A7A\u3067\u3059");
|
|
124
|
+
}
|
|
125
|
+
const ktx2Data = new Uint8Array(outputBuffer.buffer, 0, outputSize);
|
|
126
|
+
return {
|
|
127
|
+
data: ktx2Data.slice(),
|
|
128
|
+
// コピーを返す
|
|
129
|
+
originalSize: imageData.length,
|
|
130
|
+
compressedSize: outputSize,
|
|
131
|
+
width,
|
|
132
|
+
height
|
|
133
|
+
};
|
|
134
|
+
} finally {
|
|
135
|
+
encoder.delete();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function flipImageY(imageData, width, height) {
|
|
139
|
+
const rowSize = width * 4;
|
|
140
|
+
const flipped = new Uint8Array(imageData.length);
|
|
141
|
+
for (let y = 0; y < height; y++) {
|
|
142
|
+
const srcOffset = y * rowSize;
|
|
143
|
+
const dstOffset = (height - 1 - y) * rowSize;
|
|
144
|
+
flipped.set(imageData.subarray(srcOffset, srcOffset + rowSize), dstOffset);
|
|
145
|
+
}
|
|
146
|
+
return flipped;
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
UastcQuality,
|
|
150
|
+
compressToKtx2,
|
|
151
|
+
disposeBasisEncoder,
|
|
152
|
+
flipImageY,
|
|
153
|
+
getCachedBasisEncoder,
|
|
154
|
+
initBasisEncoder,
|
|
155
|
+
isBasisEncoderReady
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/compress.ts","../src/encoder.ts"],"sourcesContent":["/**\n * テクスチャ圧縮関連の型定義\n */\n\n/** UASTC品質レベル */\nexport enum UastcQuality {\n /** 最速、最低品質 */\n Fastest = 0,\n /** 高速 */\n Faster = 1,\n /** デフォルト */\n Default = 2,\n /** 低速、高品質 */\n Slower = 3,\n /** 最高品質 */\n VerySlow = 4,\n}\n\n/** KTX2圧縮オプション */\nexport interface Ktx2CompressionOptions {\n /** UASTC品質レベル (0-4, デフォルト: 2) */\n quality?: UastcQuality\n /** 圧縮レベル (0-5, デフォルト: 3) */\n compressionLevel?: number\n /** ミップマップ生成 (デフォルト: false) */\n generateMipmaps?: boolean\n /** Zstandard超圧縮を使用 (デフォルト: true) */\n supercompression?: boolean\n}\n\n/** KTX2圧縮結果 */\nexport interface Ktx2CompressionResult {\n /** 圧縮後のKTX2バイナリデータ */\n data: Uint8Array\n /** 元のサイズ (bytes) */\n originalSize: number\n /** 圧縮後のサイズ (bytes) */\n compressedSize: number\n /** 画像の幅 */\n width: number\n /** 画像の高さ */\n height: number\n}\n\n/** エラー型 */\nexport type CompressionError =\n | { type: 'WASM_LOAD_ERROR'; message: string }\n | { type: 'COMPRESSION_ERROR'; message: string }\n | { type: 'INVALID_INPUT'; message: string }\n\n/**\n * BasisEncoderモジュールの型定義\n * Emscriptenでビルドされたbasis_encoder.jsが公開するAPI\n */\nexport interface BasisEncoderModule {\n /** BasisEncoderクラス */\n BasisEncoder: new () => BasisEncoder\n /** LDR画像タイプ列挙(生ピクセルデータにはcRGBA32を使用) */\n ldr_image_type: {\n cRGBA32: { value: number }\n cPNGImage: { value: number }\n cJPGImage: { value: number }\n }\n}\n\n/**\n * BasisEncoderインスタンスの型定義\n */\nexport interface BasisEncoder {\n /** KTX2ファイル生成を設定 */\n setCreateKTX2File(create: boolean): void\n /** UASTC超圧縮(Zstandard)を設定 */\n setKTX2UASTCSupercompression(enable: boolean): void\n /** UASTCモードを有効化 */\n setUASTC(enable: boolean): void\n /** スライスソース画像を設定(LDR) */\n setSliceSourceImage(\n sliceIndex: number,\n imageData: Uint8Array,\n width: number,\n height: number,\n imageType: number,\n ): boolean\n /** UASTC品質フラグを設定 */\n setPackUASTCFlags(flags: number): void\n /** 圧縮レベルを設定 */\n setCompressionLevel(level: number): void\n /** ミップマップ生成を設定 */\n setMipGen(generate: boolean): void\n /** エンコードを実行 */\n encode(outputBuffer: Uint8Array): number\n /** リソースを解放 */\n delete(): void\n}\n\n/** BASIS WASM ファクトリ関数の型 */\nexport type BasisModuleFactory = (\n moduleOverrides?: Record<string, unknown>,\n) => Promise<BasisEncoderModule>\n","/**\n * KTX2テクスチャ圧縮ロジック\n */\n\nimport { errAsync, ResultAsync } from 'neverthrow'\nimport { initBasisEncoder } from './encoder'\nimport {\n BasisEncoderModule,\n CompressionError,\n Ktx2CompressionOptions,\n Ktx2CompressionResult,\n UastcQuality,\n} from './types'\n\n/** デフォルトの圧縮オプション */\nconst DEFAULT_OPTIONS: Required<Ktx2CompressionOptions> = {\n quality: UastcQuality.Default,\n compressionLevel: 3,\n generateMipmaps: true,\n supercompression: true,\n}\n\n/** 出力バッファの最大サイズ(24MB) */\nconst MAX_OUTPUT_SIZE = 1024 * 1024 * 24\n\n/**\n * RGBAピクセルデータをKTX2形式に圧縮\n *\n * @param imageData - RGBAピクセルデータ(width * height * 4 bytes)\n * @param width - 画像の幅\n * @param height - 画像の高さ\n * @param options - 圧縮オプション\n * @returns 圧縮結果\n */\nexport function compressToKtx2(\n imageData: Uint8Array,\n width: number,\n height: number,\n options?: Ktx2CompressionOptions,\n): ResultAsync<Ktx2CompressionResult, CompressionError> {\n // 入力検証\n const validationError = validateInput(imageData, width, height)\n if (validationError) {\n return errAsync(validationError)\n }\n\n const opts = { ...DEFAULT_OPTIONS, ...options }\n\n return initBasisEncoder().andThen((module) =>\n ResultAsync.fromPromise(\n encodeWithBasis(module, imageData, width, height, opts),\n (error) => ({\n type: 'COMPRESSION_ERROR' as const,\n message: `KTX2エンコードに失敗: ${error instanceof Error ? error.message : String(error)}`,\n }),\n ),\n )\n}\n\n/**\n * 入力データを検証\n * @returns エラーがあればCompressionError、なければnull\n */\nfunction validateInput(\n imageData: Uint8Array,\n width: number,\n height: number,\n): CompressionError | null {\n if (width <= 0 || height <= 0) {\n return {\n type: 'INVALID_INPUT',\n message: `幅と高さは正の値である必要があります: width=${width}, height=${height}`,\n }\n }\n\n const expectedSize = width * height * 4\n if (imageData.length !== expectedSize) {\n return {\n type: 'INVALID_INPUT',\n message: `画像データサイズが不正です: expected=${expectedSize}, actual=${imageData.length}`,\n }\n }\n\n // 2のべき乗チェック(推奨だが必須ではない)\n if (!isPowerOfTwo(width) || !isPowerOfTwo(height)) {\n console.warn(\n `[texture-compression] 幅・高さが2のべき乗でない場合、一部のGPUで問題が発生する可能性があります: ${width}x${height}`,\n )\n }\n\n return null\n}\n\n/**\n * 2のべき乗かチェック\n */\nfunction isPowerOfTwo(n: number): boolean {\n return n > 0 && (n & (n - 1)) === 0\n}\n\n/**\n * BasisEncoderを使用してエンコード\n */\nasync function encodeWithBasis(\n module: BasisEncoderModule,\n imageData: Uint8Array,\n width: number,\n height: number,\n options: Required<Ktx2CompressionOptions>,\n): Promise<Ktx2CompressionResult> {\n const encoder = new module.BasisEncoder()\n\n try {\n // KTX2出力を有効化\n encoder.setCreateKTX2File(true)\n\n // UASTCモードを有効化\n encoder.setUASTC(true)\n\n // 超圧縮(Zstandard)を設定\n encoder.setKTX2UASTCSupercompression(options.supercompression)\n\n // 品質設定\n encoder.setPackUASTCFlags(options.quality)\n\n // 圧縮レベル\n encoder.setCompressionLevel(options.compressionLevel)\n\n // ミップマップ生成\n encoder.setMipGen(options.generateMipmaps)\n\n // ソース画像を設定(RGBA32生データ)\n const success = encoder.setSliceSourceImage(\n 0,\n imageData,\n width,\n height,\n module.ldr_image_type.cRGBA32.value,\n )\n\n if (!success) {\n throw new Error('ソース画像の設定に失敗しました')\n }\n\n // 出力バッファを確保\n const outputBuffer = new Uint8Array(MAX_OUTPUT_SIZE)\n\n // エンコード実行\n const outputSize = encoder.encode(outputBuffer)\n\n if (outputSize === 0) {\n throw new Error('エンコード結果が空です')\n }\n\n // 結果を切り出し\n const ktx2Data = new Uint8Array(outputBuffer.buffer, 0, outputSize)\n\n return {\n data: ktx2Data.slice(), // コピーを返す\n originalSize: imageData.length,\n compressedSize: outputSize,\n width,\n height,\n }\n } finally {\n // リソース解放\n encoder.delete()\n }\n}\n\n/**\n * Y軸を反転したピクセルデータを生成\n * WebGLテクスチャ座標系(左下原点)からKTX2座標系(左上原点)への変換\n *\n * @param imageData - 元のRGBAピクセルデータ\n * @param width - 画像の幅\n * @param height - 画像の高さ\n * @returns Y軸反転されたピクセルデータ\n */\nexport function flipImageY(\n imageData: Uint8Array,\n width: number,\n height: number,\n): Uint8Array {\n const rowSize = width * 4\n const flipped = new Uint8Array(imageData.length)\n\n for (let y = 0; y < height; y++) {\n const srcOffset = y * rowSize\n const dstOffset = (height - 1 - y) * rowSize\n flipped.set(imageData.subarray(srcOffset, srcOffset + rowSize), dstOffset)\n }\n\n return flipped\n}\n","/**\n * BasisEncoder WASM モジュールのロードと管理\n * ブラウザ環境専用\n */\n\nimport { ResultAsync } from 'neverthrow'\n// @ts-expect-error - Emscripten module\nimport BASIS from '../wasm/basis_encoder.js'\n// @ts-expect-error - Vite ?url import\nimport wasmUrl from '../wasm/basis_encoder.wasm?url'\nimport { BasisEncoderModule, CompressionError } from './types'\n\n/** モジュールキャッシュ */\nlet cachedModule: BasisEncoderModule | null = null\n\n/**\n * BasisEncoder WASMモジュールを初期化(ブラウザ環境専用)\n *\n * @returns 初期化されたBasisEncoderModule\n */\nexport function initBasisEncoder(): ResultAsync<\n BasisEncoderModule,\n CompressionError\n> {\n // キャッシュがあれば返す\n if (cachedModule) {\n return ResultAsync.fromSafePromise(Promise.resolve(cachedModule))\n }\n\n return ResultAsync.fromPromise(loadBasisModule(), (error) => ({\n type: 'WASM_LOAD_ERROR' as const,\n message: `Basis WASM モジュールの読み込みに失敗: ${error instanceof Error ? error.message : String(error)}`,\n })).map((module) => {\n cachedModule = module\n return module\n })\n}\n\n/**\n * BasisEncoderモジュールを解放\n */\nexport function disposeBasisEncoder(): void {\n cachedModule = null\n}\n\n/**\n * キャッシュされたモジュールを取得(初期化済みの場合のみ)\n */\nexport function getCachedBasisEncoder(): BasisEncoderModule | null {\n return cachedModule\n}\n\n/**\n * WASMがすでにロード済みかチェック\n */\nexport function isBasisEncoderReady(): boolean {\n return cachedModule !== null\n}\n\n/** 拡張されたモジュール型(initializeBasisを含む) */\ninterface BasisEncoderModuleWithInit extends BasisEncoderModule {\n initializeBasis?: () => void\n}\n\n/**\n * BASISモジュールをロード\n * locateFileでWASMのURLを指定\n */\nasync function loadBasisModule(): Promise<BasisEncoderModule> {\n const moduleObj = (await BASIS({\n locateFile: () => wasmUrl,\n })) as BasisEncoderModuleWithInit\n\n // Basisエンコーダーの初期化(必須)\n if (moduleObj.initializeBasis) {\n moduleObj.initializeBasis()\n }\n\n // BasisEncoderクラスが存在するか確認\n if (!moduleObj.BasisEncoder) {\n throw new Error('BasisEncoder class not found in module after init')\n }\n\n return moduleObj as BasisEncoderModule\n}\n"],"mappings":";AAKO,IAAK,eAAL,kBAAKA,kBAAL;AAEL,EAAAA,4BAAA,aAAU,KAAV;AAEA,EAAAA,4BAAA,YAAS,KAAT;AAEA,EAAAA,4BAAA,aAAU,KAAV;AAEA,EAAAA,4BA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,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,4FAAiB;AAAA,IACnC;AAGA,UAAM,eAAe,IAAI,WAAW,eAAe;AAGnD,UAAM,aAAa,QAAQ,OAAO,YAAY;AAE9C,QAAI,eAAe,GAAG;AACpB,YAAM,IAAI,MAAM,oEAAa;AAAA,IAC/B;AAGA,UAAM,WAAW,IAAI,WAAW,aAAa,QAAQ,GAAG,UAAU;AAElE,WAAO;AAAA,MACL,MAAM,SAAS,MAAM;AAAA;AAAA,MACrB,cAAc,UAAU;AAAA,MACxB,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,EACF,UAAE;AAEA,YAAQ,OAAO;AAAA,EACjB;AACF;AAWO,SAAS,WACd,WACA,OACA,QACY;AACZ,QAAM,UAAU,QAAQ;AACxB,QAAM,UAAU,IAAI,WAAW,UAAU,MAAM;AAE/C,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,UAAM,YAAY,IAAI;AACtB,UAAM,aAAa,SAAS,IAAI,KAAK;AACrC,YAAQ,IAAI,UAAU,SAAS,WAAW,YAAY,OAAO,GAAG,SAAS;AAAA,EAC3E;AAEA,SAAO;AACT;","names":["UastcQuality","ResultAsync","ResultAsync"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webxr-jp/texture-compression",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Texture compression utilities for avatar-optimizer using WebAssembly",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./wasm/*": "./wasm/*"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"wasm"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"texture",
|
|
21
|
+
"compression",
|
|
22
|
+
"wasm",
|
|
23
|
+
"webassembly",
|
|
24
|
+
"ktx2",
|
|
25
|
+
"basis",
|
|
26
|
+
"uastc"
|
|
27
|
+
],
|
|
28
|
+
"author": "HALBY",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@eslint/js": "^9.32.0",
|
|
35
|
+
"@types/node": "^24.10.0",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
37
|
+
"@typescript-eslint/parser": "^8.39.0",
|
|
38
|
+
"@vitest/browser-playwright": "^4.0.16",
|
|
39
|
+
"@vitest/coverage-istanbul": "^4.0.16",
|
|
40
|
+
"eslint": "^9.32.0",
|
|
41
|
+
"eslint-plugin-import": "^2.32.0",
|
|
42
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
43
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
44
|
+
"playwright": "^1.57.0",
|
|
45
|
+
"prettier": "^3.3.0",
|
|
46
|
+
"tsup": "^8.0.0",
|
|
47
|
+
"typescript": "^5.0.0",
|
|
48
|
+
"typescript-eslint": "^8.38.0",
|
|
49
|
+
"vite-plugin-top-level-await": "^1.6.0",
|
|
50
|
+
"vite-plugin-wasm": "^3.5.0",
|
|
51
|
+
"vitest": "^4.0.16"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"neverthrow": "^8.2.0"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "pnpm lint:fix && pnpm typecheck && tsup",
|
|
58
|
+
"dev": "tsup --watch",
|
|
59
|
+
"lint": "eslint .",
|
|
60
|
+
"lint:fix": "eslint . --fix && prettier --write .",
|
|
61
|
+
"format": "prettier --write .",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"typecheck": "tsc --noEmit"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/wasm/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2019-2025 Binomial LLC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|