@needle-tools/gltf-build-pipeline 2.13.0 → 2.13.1

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +520 -517
  2. package/README.md +38 -38
  3. package/dist/cache/cache.d.ts +55 -55
  4. package/dist/cache/cache.js +326 -326
  5. package/dist/cache/index.d.ts +1 -1
  6. package/dist/cache/index.js +1 -1
  7. package/dist/cli/index.d.ts +2 -2
  8. package/dist/cli/index.js +198 -198
  9. package/dist/config/index.d.ts +53 -53
  10. package/dist/config/index.js +152 -152
  11. package/dist/constants.d.ts +7 -7
  12. package/dist/constants.js +7 -7
  13. package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.d.ts +24 -24
  14. package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.js +54 -54
  15. package/dist/extensions/NEEDLE_compression_texture/index.d.ts +1 -1
  16. package/dist/extensions/NEEDLE_compression_texture/index.js +1 -1
  17. package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.d.ts +27 -27
  18. package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.js +88 -88
  19. package/dist/extensions/NEEDLE_mesh_compression/index.d.ts +1 -1
  20. package/dist/extensions/NEEDLE_mesh_compression/index.js +1 -1
  21. package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.d.ts +27 -27
  22. package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.js +980 -980
  23. package/dist/extensions/NEEDLE_opaque/index.d.ts +3 -3
  24. package/dist/extensions/NEEDLE_opaque/index.js +30 -30
  25. package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.d.ts +48 -48
  26. package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.js +69 -69
  27. package/dist/extensions/NEEDLE_progressive/index.d.ts +1 -1
  28. package/dist/extensions/NEEDLE_progressive/index.js +1 -1
  29. package/dist/extensions/NEEDLE_progressive_mesh_settings/index.d.ts +23 -23
  30. package/dist/extensions/NEEDLE_progressive_mesh_settings/index.js +41 -41
  31. package/dist/extensions/NEEDLE_progressive_texture_settings/index.d.ts +25 -25
  32. package/dist/extensions/NEEDLE_progressive_texture_settings/index.js +38 -38
  33. package/dist/extensions/index.d.ts +7 -7
  34. package/dist/extensions/index.js +17 -17
  35. package/dist/extensions/utils.d.ts +6 -6
  36. package/dist/extensions/utils.js +72 -72
  37. package/dist/functions/weld.3.d.ts +76 -76
  38. package/dist/functions/weld.3.js +414 -414
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.js +8 -8
  41. package/dist/scripts/index.d.ts +2 -2
  42. package/dist/scripts/index.js +2 -2
  43. package/dist/scripts/pack-gltf.d.ts +15 -15
  44. package/dist/scripts/pack-gltf.js +135 -133
  45. package/dist/scripts/stats.d.ts +2 -2
  46. package/dist/scripts/stats.js +19 -19
  47. package/dist/transforms/index.d.ts +9 -9
  48. package/dist/transforms/index.js +9 -9
  49. package/dist/transforms/needle_animation_transform.d.ts +2 -2
  50. package/dist/transforms/needle_animation_transform.js +5 -5
  51. package/dist/transforms/needle_asset.d.ts +3 -3
  52. package/dist/transforms/needle_asset.js +50 -50
  53. package/dist/transforms/needle_common.d.ts +17 -17
  54. package/dist/transforms/needle_common.js +1 -1
  55. package/dist/transforms/needle_mesh_transform.d.ts +15 -15
  56. package/dist/transforms/needle_mesh_transform.js +223 -223
  57. package/dist/transforms/needle_progressive.d.ts +45 -45
  58. package/dist/transforms/needle_progressive.js +1043 -1043
  59. package/dist/transforms/needle_texture_transform.d.ts +13 -13
  60. package/dist/transforms/needle_texture_transform.js +257 -257
  61. package/dist/transforms/needle_toktx.d.ts +26 -26
  62. package/dist/transforms/needle_toktx.js +243 -243
  63. package/dist/transforms/needle_webp.d.ts +15 -15
  64. package/dist/transforms/needle_webp.js +53 -53
  65. package/dist/transforms/toktx.d.ts +52 -52
  66. package/dist/transforms/toktx.js +221 -221
  67. package/dist/transforms/toktx_types.d.ts +78 -78
  68. package/dist/transforms/toktx_types.js +62 -62
  69. package/dist/transforms/util.d.ts +21 -21
  70. package/dist/transforms/util.js +90 -90
  71. package/dist/utils/compression_utils.d.ts +2 -2
  72. package/dist/utils/compression_utils.js +6 -6
  73. package/dist/utils/fileutils.d.ts +19 -19
  74. package/dist/utils/fileutils.js +177 -177
  75. package/dist/utils/guid.d.ts +1 -1
  76. package/dist/utils/guid.js +5 -5
  77. package/dist/utils/index.d.ts +10 -10
  78. package/dist/utils/index.js +10 -10
  79. package/dist/utils/merge.d.ts +12 -12
  80. package/dist/utils/merge.js +31 -31
  81. package/dist/utils/mesh.d.ts +13 -13
  82. package/dist/utils/mesh.js +124 -124
  83. package/dist/utils/nodeio.d.ts +6 -6
  84. package/dist/utils/nodeio.js +86 -86
  85. package/dist/utils/stats.d.ts +70 -70
  86. package/dist/utils/stats.js +258 -258
  87. package/dist/utils/texture.d.ts +5 -5
  88. package/dist/utils/texture.js +14 -14
  89. package/dist/utils/validate.d.ts +5 -5
  90. package/dist/utils/validate.js +17 -17
  91. package/dist/utils/version.d.ts +1 -1
  92. package/dist/utils/version.gen.d.ts +1 -1
  93. package/dist/utils/version.gen.js +1 -1
  94. package/dist/utils/version.js +4 -4
  95. package/package.json +79 -79
  96. package/scripts/clear-caches.mjs +3 -3
  97. package/scripts/defaults.mjs +11 -11
  98. package/scripts/fileutils.mjs +5 -5
  99. package/scripts/index.mjs +41 -41
  100. package/scripts/limit-caches.mjs +3 -3
  101. package/scripts/make-progressive.mjs +16 -16
  102. package/scripts/pack-gltf.mjs +106 -106
  103. package/tsconfig.json +19 -19
@@ -1,78 +1,78 @@
1
- import { vec2 } from "@gltf-transform/core";
2
- import { TextureResizeFilter } from "@gltf-transform/functions";
3
- /**********************************************************************************************
4
- * Interfaces.
5
- */
6
- export declare const Mode: {
7
- ETC1S: string;
8
- UASTC: string;
9
- };
10
- export declare const Filter: {
11
- BOX: string;
12
- TENT: string;
13
- BELL: string;
14
- BSPLINE: string;
15
- MITCHELL: string;
16
- LANCZOS3: string;
17
- LANCZOS4: string;
18
- LANCZOS6: string;
19
- LANCZOS12: string;
20
- BLACKMAN: string;
21
- KAISER: string;
22
- GAUSSIAN: string;
23
- CATMULLROM: string;
24
- QUADRATIC_INTERP: string;
25
- QUADRATIC_APPROX: string;
26
- QUADRATIC_MIX: string;
27
- };
28
- interface GlobalOptions {
29
- /** Instance of the Sharp encoder, required if resizing textures. */
30
- encoder: unknown;
31
- mode: string;
32
- /** Pattern identifying textures to compress, matched to name or URI. */
33
- pattern?: RegExp | null;
34
- /**
35
- * Pattern matching the material texture slot(s) to be compressed or converted.
36
- * Passing a string (glob) is deprecated; use a RegExp instead.
37
- */
38
- slots?: RegExp | null;
39
- /** Interpolation used for generating mipmaps. Default: 'lanczos4'. */
40
- filter?: string;
41
- filterScale?: number;
42
- resize?: vec2 | 'nearest-pot' | 'ceil-pot' | 'floor-pot';
43
- /** Interpolation used if resizing. Default: TextureResizeFilter.LANCZOS3. */
44
- resizeFilter?: TextureResizeFilter;
45
- jobs?: number;
46
- /**
47
- * Whether to clean up temporary files created during texture compression. See
48
- * verbose log output for temporary file paths. Default: true.
49
- */
50
- cleanup?: boolean;
51
- /**
52
- * Attempts to avoid processing images that could exceed memory or other other
53
- * limits, throwing an error instead. Default: true.
54
- * @experimental
55
- */
56
- limitInputPixels?: boolean;
57
- }
58
- export interface ETC1SOptions extends GlobalOptions {
59
- quality?: number;
60
- compression?: number;
61
- maxEndpoints?: number;
62
- maxSelectors?: number;
63
- rdo?: boolean;
64
- rdoThreshold?: number;
65
- }
66
- export interface UASTCOptions extends GlobalOptions {
67
- level?: number;
68
- rdo?: boolean;
69
- rdoLambda?: number;
70
- rdoDictionarySize?: number;
71
- rdoBlockScale?: number;
72
- rdoStdDev?: number;
73
- rdoMultithreading?: boolean;
74
- zstd?: number;
75
- }
76
- export declare const ETC1S_DEFAULTS: Omit<ETC1SOptions, 'encoder' | 'mode'>;
77
- export declare const UASTC_DEFAULTS: Omit<UASTCOptions, 'encoder' | 'mode'>;
78
- export {};
1
+ import { vec2 } from "@gltf-transform/core";
2
+ import { TextureResizeFilter } from "@gltf-transform/functions";
3
+ /**********************************************************************************************
4
+ * Interfaces.
5
+ */
6
+ export declare const Mode: {
7
+ ETC1S: string;
8
+ UASTC: string;
9
+ };
10
+ export declare const Filter: {
11
+ BOX: string;
12
+ TENT: string;
13
+ BELL: string;
14
+ BSPLINE: string;
15
+ MITCHELL: string;
16
+ LANCZOS3: string;
17
+ LANCZOS4: string;
18
+ LANCZOS6: string;
19
+ LANCZOS12: string;
20
+ BLACKMAN: string;
21
+ KAISER: string;
22
+ GAUSSIAN: string;
23
+ CATMULLROM: string;
24
+ QUADRATIC_INTERP: string;
25
+ QUADRATIC_APPROX: string;
26
+ QUADRATIC_MIX: string;
27
+ };
28
+ interface GlobalOptions {
29
+ /** Instance of the Sharp encoder, required if resizing textures. */
30
+ encoder: unknown;
31
+ mode: string;
32
+ /** Pattern identifying textures to compress, matched to name or URI. */
33
+ pattern?: RegExp | null;
34
+ /**
35
+ * Pattern matching the material texture slot(s) to be compressed or converted.
36
+ * Passing a string (glob) is deprecated; use a RegExp instead.
37
+ */
38
+ slots?: RegExp | null;
39
+ /** Interpolation used for generating mipmaps. Default: 'lanczos4'. */
40
+ filter?: string;
41
+ filterScale?: number;
42
+ resize?: vec2 | 'nearest-pot' | 'ceil-pot' | 'floor-pot';
43
+ /** Interpolation used if resizing. Default: TextureResizeFilter.LANCZOS3. */
44
+ resizeFilter?: TextureResizeFilter;
45
+ jobs?: number;
46
+ /**
47
+ * Whether to clean up temporary files created during texture compression. See
48
+ * verbose log output for temporary file paths. Default: true.
49
+ */
50
+ cleanup?: boolean;
51
+ /**
52
+ * Attempts to avoid processing images that could exceed memory or other other
53
+ * limits, throwing an error instead. Default: true.
54
+ * @experimental
55
+ */
56
+ limitInputPixels?: boolean;
57
+ }
58
+ export interface ETC1SOptions extends GlobalOptions {
59
+ quality?: number;
60
+ compression?: number;
61
+ maxEndpoints?: number;
62
+ maxSelectors?: number;
63
+ rdo?: boolean;
64
+ rdoThreshold?: number;
65
+ }
66
+ export interface UASTCOptions extends GlobalOptions {
67
+ level?: number;
68
+ rdo?: boolean;
69
+ rdoLambda?: number;
70
+ rdoDictionarySize?: number;
71
+ rdoBlockScale?: number;
72
+ rdoStdDev?: number;
73
+ rdoMultithreading?: boolean;
74
+ zstd?: number;
75
+ }
76
+ export declare const ETC1S_DEFAULTS: Omit<ETC1SOptions, 'encoder' | 'mode'>;
77
+ export declare const UASTC_DEFAULTS: Omit<UASTCOptions, 'encoder' | 'mode'>;
78
+ export {};
@@ -1,62 +1,62 @@
1
- import os from 'os';
2
- import { TextureChannel } from "@gltf-transform/core";
3
- import { TextureResizeFilter } from "@gltf-transform/functions";
4
- const NUM_CPUS = os.cpus().length || 1; // microsoft/vscode#112122
5
- const KTX_SOFTWARE_VERSION_MIN = '4.3.0';
6
- const { R, G, A } = TextureChannel;
7
- /**********************************************************************************************
8
- * Interfaces.
9
- */
10
- export const Mode = {
11
- ETC1S: 'etc1s',
12
- UASTC: 'uastc',
13
- };
14
- export const Filter = {
15
- BOX: 'box',
16
- TENT: 'tent',
17
- BELL: 'bell',
18
- BSPLINE: 'b-spline',
19
- MITCHELL: 'mitchell',
20
- LANCZOS3: 'lanczos3',
21
- LANCZOS4: 'lanczos4',
22
- LANCZOS6: 'lanczos6',
23
- LANCZOS12: 'lanczos12',
24
- BLACKMAN: 'blackman',
25
- KAISER: 'kaiser',
26
- GAUSSIAN: 'gaussian',
27
- CATMULLROM: 'catmullrom',
28
- QUADRATIC_INTERP: 'quadratic_interp',
29
- QUADRATIC_APPROX: 'quadratic_approx',
30
- QUADRATIC_MIX: 'quadratic_mix',
31
- };
32
- const GLOBAL_DEFAULTS = {
33
- resizeFilter: TextureResizeFilter.LANCZOS3,
34
- filter: Filter.LANCZOS4,
35
- filterScale: 1,
36
- pattern: null,
37
- slots: null,
38
- // See: https://github.com/donmccurdy/glTF-Transform/pull/389#issuecomment-1089842185
39
- jobs: 2 * NUM_CPUS,
40
- cleanup: true,
41
- limitInputPixels: true,
42
- };
43
- export const ETC1S_DEFAULTS = {
44
- quality: 128,
45
- compression: 1,
46
- rdo: true,
47
- rdoThreshold: 1.25,
48
- maxSelectors: 0,
49
- maxEndpoints: 0,
50
- ...GLOBAL_DEFAULTS,
51
- };
52
- export const UASTC_DEFAULTS = {
53
- level: 2,
54
- rdo: false,
55
- rdoLambda: 1.0,
56
- rdoDictionarySize: 32768,
57
- rdoBlockScale: 10.0,
58
- rdoStdDev: 18.0,
59
- rdoMultithreading: true,
60
- zstd: 18,
61
- ...GLOBAL_DEFAULTS,
62
- };
1
+ import os from 'os';
2
+ import { TextureChannel } from "@gltf-transform/core";
3
+ import { TextureResizeFilter } from "@gltf-transform/functions";
4
+ const NUM_CPUS = os.cpus().length || 1; // microsoft/vscode#112122
5
+ const KTX_SOFTWARE_VERSION_MIN = '4.3.0';
6
+ const { R, G, A } = TextureChannel;
7
+ /**********************************************************************************************
8
+ * Interfaces.
9
+ */
10
+ export const Mode = {
11
+ ETC1S: 'etc1s',
12
+ UASTC: 'uastc',
13
+ };
14
+ export const Filter = {
15
+ BOX: 'box',
16
+ TENT: 'tent',
17
+ BELL: 'bell',
18
+ BSPLINE: 'b-spline',
19
+ MITCHELL: 'mitchell',
20
+ LANCZOS3: 'lanczos3',
21
+ LANCZOS4: 'lanczos4',
22
+ LANCZOS6: 'lanczos6',
23
+ LANCZOS12: 'lanczos12',
24
+ BLACKMAN: 'blackman',
25
+ KAISER: 'kaiser',
26
+ GAUSSIAN: 'gaussian',
27
+ CATMULLROM: 'catmullrom',
28
+ QUADRATIC_INTERP: 'quadratic_interp',
29
+ QUADRATIC_APPROX: 'quadratic_approx',
30
+ QUADRATIC_MIX: 'quadratic_mix',
31
+ };
32
+ const GLOBAL_DEFAULTS = {
33
+ resizeFilter: TextureResizeFilter.LANCZOS3,
34
+ filter: Filter.LANCZOS4,
35
+ filterScale: 1,
36
+ pattern: null,
37
+ slots: null,
38
+ // See: https://github.com/donmccurdy/glTF-Transform/pull/389#issuecomment-1089842185
39
+ jobs: 2 * NUM_CPUS,
40
+ cleanup: true,
41
+ limitInputPixels: true,
42
+ };
43
+ export const ETC1S_DEFAULTS = {
44
+ quality: 128,
45
+ compression: 1,
46
+ rdo: true,
47
+ rdoThreshold: 1.25,
48
+ maxSelectors: 0,
49
+ maxEndpoints: 0,
50
+ ...GLOBAL_DEFAULTS,
51
+ };
52
+ export const UASTC_DEFAULTS = {
53
+ level: 2,
54
+ rdo: false,
55
+ rdoLambda: 1.0,
56
+ rdoDictionarySize: 32768,
57
+ rdoBlockScale: 10.0,
58
+ rdoStdDev: 18.0,
59
+ rdoMultithreading: true,
60
+ zstd: 18,
61
+ ...GLOBAL_DEFAULTS,
62
+ };
@@ -1,21 +1,21 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { spawn as _spawn } from 'child_process';
3
- import type { ChildProcess } from 'child_process';
4
- export declare const XMPContext: Record<string, string>;
5
- export declare const MICROMATCH_OPTIONS: {
6
- nocase: boolean;
7
- contains: boolean;
8
- };
9
- export declare let spawn: typeof _spawn;
10
- export declare let commandExists: (cmd: string) => any;
11
- export declare let waitExit: typeof _waitExit;
12
- export declare function mockSpawn(_spawn: unknown): void;
13
- export declare function mockCommandExists(_commandExists: (n: string) => Promise<boolean>): void;
14
- export declare function mockWaitExit(_waitExit: (process: ChildProcess) => Promise<[unknown, string, string]>): void;
15
- export declare function _waitExit(process: ChildProcess): Promise<[unknown, string, string]>;
16
- export declare function formatLong(x: number): string;
17
- export declare function formatBytes(bytes: number, decimals?: number): string;
18
- export declare function formatParagraph(str: string): string;
19
- export declare function formatHeader(title: string): string;
20
- export declare function formatXMP(value: string | number | boolean | Record<string, unknown> | null): string;
21
- export declare function underline(str: string): string;
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { spawn as _spawn } from 'child_process';
3
+ import type { ChildProcess } from 'child_process';
4
+ export declare const XMPContext: Record<string, string>;
5
+ export declare const MICROMATCH_OPTIONS: {
6
+ nocase: boolean;
7
+ contains: boolean;
8
+ };
9
+ export declare let spawn: typeof _spawn;
10
+ export declare let commandExists: (cmd: string) => any;
11
+ export declare let waitExit: typeof _waitExit;
12
+ export declare function mockSpawn(_spawn: unknown): void;
13
+ export declare function mockCommandExists(_commandExists: (n: string) => Promise<boolean>): void;
14
+ export declare function mockWaitExit(_waitExit: (process: ChildProcess) => Promise<[unknown, string, string]>): void;
15
+ export declare function _waitExit(process: ChildProcess): Promise<[unknown, string, string]>;
16
+ export declare function formatLong(x: number): string;
17
+ export declare function formatBytes(bytes: number, decimals?: number): string;
18
+ export declare function formatParagraph(str: string): string;
19
+ export declare function formatHeader(title: string): string;
20
+ export declare function formatXMP(value: string | number | boolean | Record<string, unknown> | null): string;
21
+ export declare function underline(str: string): string;
@@ -1,90 +1,90 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
- import { spawn as _spawn } from 'child_process';
3
- import _commandExists from 'command-exists';
4
- // Constants.
5
- export const XMPContext = {
6
- dc: 'http://purl.org/dc/elements/1.1/',
7
- model3d: 'https://schema.khronos.org/model3d/xsd/1.0/',
8
- rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
9
- xmp: 'http://ns.adobe.com/xap/1.0/',
10
- xmpRights: 'http://ns.adobe.com/xap/1.0/rights/',
11
- };
12
- // Using 'micromatch' because 'contains: true' did not work as expected with
13
- // minimatch. Need to ensure that '*' matches patterns like 'image/png'.
14
- export const MICROMATCH_OPTIONS = { nocase: true, contains: true };
15
- // Mocks for tests.
16
- export let spawn = _spawn;
17
- // See https://github.com/mathisonian/command-exists/issues/22
18
- export let commandExists = (cmd) => _commandExists(cmd)?.catch(() => false) ?? false;
19
- export let waitExit = _waitExit;
20
- export function mockSpawn(_spawn) {
21
- //@ts-ignore
22
- spawn = _spawn;
23
- }
24
- export function mockCommandExists(_commandExists) {
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- commandExists = _commandExists;
27
- }
28
- export function mockWaitExit(_waitExit) {
29
- waitExit = _waitExit;
30
- }
31
- export async function _waitExit(process) {
32
- let stdout = '';
33
- if (process.stdout) {
34
- for await (const chunk of process.stdout) {
35
- stdout += chunk;
36
- }
37
- }
38
- let stderr = '';
39
- if (process.stderr) {
40
- for await (const chunk of process.stderr) {
41
- stderr += chunk;
42
- }
43
- }
44
- const status = await new Promise((resolve, _) => {
45
- process.on('close', resolve);
46
- });
47
- return [status, stdout, stderr];
48
- }
49
- // Formatting.
50
- export function formatLong(x) {
51
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
52
- }
53
- export function formatBytes(bytes, decimals = 2) {
54
- if (bytes === 0)
55
- return '0 Bytes';
56
- const k = 1000;
57
- const dm = decimals < 0 ? 0 : decimals;
58
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
59
- const i = Math.floor(Math.log(bytes) / Math.log(k));
60
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
61
- }
62
- export function formatParagraph(str) {
63
- return str
64
- .match(/.{1,80}(\s|$)/g)
65
- .map((line) => line.trim())
66
- .join('\n');
67
- }
68
- export function formatHeader(title) {
69
- return '' + '\n ' + title.toUpperCase() + '\n ────────────────────────────────────────────';
70
- }
71
- export function formatXMP(value) {
72
- if (!value) {
73
- return '';
74
- }
75
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
76
- return value.toString();
77
- }
78
- if (value['@list']) {
79
- const list = value['@list'];
80
- const hasCommas = list.some((value) => value.indexOf(',') > 0);
81
- return list.join(hasCommas ? '; ' : ', ');
82
- }
83
- if (value['@type'] === 'rdf:Alt') {
84
- return value['rdf:_1']['@value'];
85
- }
86
- return JSON.stringify(value);
87
- }
88
- export function underline(str) {
89
- return `\x1b[4m${str}\x1b[0m`;
90
- }
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ import { spawn as _spawn } from 'child_process';
3
+ import _commandExists from 'command-exists';
4
+ // Constants.
5
+ export const XMPContext = {
6
+ dc: 'http://purl.org/dc/elements/1.1/',
7
+ model3d: 'https://schema.khronos.org/model3d/xsd/1.0/',
8
+ rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
9
+ xmp: 'http://ns.adobe.com/xap/1.0/',
10
+ xmpRights: 'http://ns.adobe.com/xap/1.0/rights/',
11
+ };
12
+ // Using 'micromatch' because 'contains: true' did not work as expected with
13
+ // minimatch. Need to ensure that '*' matches patterns like 'image/png'.
14
+ export const MICROMATCH_OPTIONS = { nocase: true, contains: true };
15
+ // Mocks for tests.
16
+ export let spawn = _spawn;
17
+ // See https://github.com/mathisonian/command-exists/issues/22
18
+ export let commandExists = (cmd) => _commandExists(cmd)?.catch(() => false) ?? false;
19
+ export let waitExit = _waitExit;
20
+ export function mockSpawn(_spawn) {
21
+ //@ts-ignore
22
+ spawn = _spawn;
23
+ }
24
+ export function mockCommandExists(_commandExists) {
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ commandExists = _commandExists;
27
+ }
28
+ export function mockWaitExit(_waitExit) {
29
+ waitExit = _waitExit;
30
+ }
31
+ export async function _waitExit(process) {
32
+ let stdout = '';
33
+ if (process.stdout) {
34
+ for await (const chunk of process.stdout) {
35
+ stdout += chunk;
36
+ }
37
+ }
38
+ let stderr = '';
39
+ if (process.stderr) {
40
+ for await (const chunk of process.stderr) {
41
+ stderr += chunk;
42
+ }
43
+ }
44
+ const status = await new Promise((resolve, _) => {
45
+ process.on('close', resolve);
46
+ });
47
+ return [status, stdout, stderr];
48
+ }
49
+ // Formatting.
50
+ export function formatLong(x) {
51
+ return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
52
+ }
53
+ export function formatBytes(bytes, decimals = 2) {
54
+ if (bytes === 0)
55
+ return '0 Bytes';
56
+ const k = 1000;
57
+ const dm = decimals < 0 ? 0 : decimals;
58
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
59
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
60
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
61
+ }
62
+ export function formatParagraph(str) {
63
+ return str
64
+ .match(/.{1,80}(\s|$)/g)
65
+ .map((line) => line.trim())
66
+ .join('\n');
67
+ }
68
+ export function formatHeader(title) {
69
+ return '' + '\n ' + title.toUpperCase() + '\n ────────────────────────────────────────────';
70
+ }
71
+ export function formatXMP(value) {
72
+ if (!value) {
73
+ return '';
74
+ }
75
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
76
+ return value.toString();
77
+ }
78
+ if (value['@list']) {
79
+ const list = value['@list'];
80
+ const hasCommas = list.some((value) => value.indexOf(',') > 0);
81
+ return list.join(hasCommas ? '; ' : ', ');
82
+ }
83
+ if (value['@type'] === 'rdf:Alt') {
84
+ return value['rdf:_1']['@value'];
85
+ }
86
+ return JSON.stringify(value);
87
+ }
88
+ export function underline(str) {
89
+ return `\x1b[4m${str}\x1b[0m`;
90
+ }
@@ -1,2 +1,2 @@
1
- export declare type TextureCompressionMode = "webp" | "ETC1S" | "UASTC";
2
- export declare function detectTextureCompressionMode(slots: string[]): "UASTC" | "ETC1S";
1
+ export declare type TextureCompressionMode = "webp" | "ETC1S" | "UASTC";
2
+ export declare function detectTextureCompressionMode(slots: string[]): "UASTC" | "ETC1S";
@@ -1,6 +1,6 @@
1
- export function detectTextureCompressionMode(slots) {
2
- if (slots.includes("normalTexture") || slots.includes("metallicRoughnessTexture")) {
3
- return "UASTC";
4
- }
5
- return "ETC1S";
6
- }
1
+ export function detectTextureCompressionMode(slots) {
2
+ if (slots.includes("normalTexture") || slots.includes("metallicRoughnessTexture")) {
3
+ return "UASTC";
4
+ }
5
+ return "ETC1S";
6
+ }
@@ -1,19 +1,19 @@
1
- /**
2
- * Get the output path for a file based on the output directory or file.
3
- * If outDirOrFile is a filepath, it will be returned as is.
4
- * If outDirOrFile is a directory, the file will be placed in that directory.
5
- */
6
- export declare function getOutputPath(filepath: string, outDirOrFile: string | undefined | null, opts?: {
7
- create?: boolean;
8
- }): string;
9
- export declare function getFileName(filepath: string): string;
10
- export declare function getDirName(filepath: string): string;
11
- export declare type GLTFFileCallback = (file: string) => void | Promise<void>;
12
- export declare function foreachGLTF(args: string | string[], callback: GLTFFileCallback): Promise<void>;
13
- export declare function replaceExtension(filepath: string, newExtension: string): string;
14
- export declare function isDirectory(path: string): boolean;
15
- /**
16
- * Ensure that a path is a directory.
17
- * If the directory does not exist, it will be created.
18
- */
19
- export declare function ensureIsDirectory(path: string): string;
1
+ /**
2
+ * Get the output path for a file based on the output directory or file.
3
+ * If outDirOrFile is a filepath, it will be returned as is.
4
+ * If outDirOrFile is a directory, the file will be placed in that directory.
5
+ */
6
+ export declare function getOutputPath(filepath: string, outDirOrFile: string | undefined | null, opts?: {
7
+ create?: boolean;
8
+ }): string;
9
+ export declare function getFileName(filepath: string): string;
10
+ export declare function getDirName(filepath: string): string;
11
+ export declare type GLTFFileCallback = (file: string) => void | Promise<void>;
12
+ export declare function foreachGLTF(args: string | string[], callback: GLTFFileCallback): Promise<void>;
13
+ export declare function replaceExtension(filepath: string, newExtension: string): string;
14
+ export declare function isDirectory(path: string): boolean;
15
+ /**
16
+ * Ensure that a path is a directory.
17
+ * If the directory does not exist, it will be created.
18
+ */
19
+ export declare function ensureIsDirectory(path: string): string;