distark-render 1.2.1 → 1.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/cli/fix.d.ts.map +1 -1
- package/dist/cli/fix.js +40 -10
- package/dist/cli/fix.js.map +1 -1
- package/dist/cli/validate.d.ts.map +1 -1
- package/dist/cli/validate.js +40 -1
- package/dist/cli/validate.js.map +1 -1
- package/dist/modules/characterValidator.d.ts +9 -2
- package/dist/modules/characterValidator.d.ts.map +1 -1
- package/dist/modules/characterValidator.js +53 -5
- package/dist/modules/characterValidator.js.map +1 -1
- package/dist/modules/imageLoad.d.ts.map +1 -1
- package/dist/modules/imageLoad.js +22 -4
- package/dist/modules/imageLoad.js.map +1 -1
- package/dist/modules/rigAssetFix.d.ts +2 -2
- package/dist/modules/rigAssetFix.d.ts.map +1 -1
- package/dist/modules/rigAssetFix.js +32 -4
- package/dist/modules/rigAssetFix.js.map +1 -1
- package/dist/modules/svgAssetAnalysis.d.ts +26 -1
- package/dist/modules/svgAssetAnalysis.d.ts.map +1 -1
- package/dist/modules/svgAssetAnalysis.js +126 -5
- package/dist/modules/svgAssetAnalysis.js.map +1 -1
- package/dist/modules/svgAssetFix.d.ts +2 -2
- package/dist/modules/svgAssetFix.d.ts.map +1 -1
- package/dist/modules/svgAssetFix.js +124 -17
- package/dist/modules/svgAssetFix.js.map +1 -1
- package/dist/modules/svgViewBox.d.ts +34 -5
- package/dist/modules/svgViewBox.d.ts.map +1 -1
- package/dist/modules/svgViewBox.js +133 -29
- package/dist/modules/svgViewBox.js.map +1 -1
- package/dist/tests/test-fix-visual-parity.d.ts +15 -0
- package/dist/tests/test-fix-visual-parity.d.ts.map +1 -0
- package/dist/tests/test-fix-visual-parity.js +398 -0
- package/dist/tests/test-fix-visual-parity.js.map +1 -0
- package/dist/tests/test-svg-asset-fix.js +2 -2
- package/dist/tests/test-svg-asset-fix.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { extractSvgPaths,
|
|
1
|
+
import { extractSvgPaths, getVisibleContentBounds, getVisiblePaths, parseViewBox, } from './svgAssetAnalysis.js';
|
|
2
2
|
function formatNumber(value) {
|
|
3
3
|
return Number(value.toFixed(4)).toString();
|
|
4
4
|
}
|
|
5
5
|
function setRootAttribute(svgSource, name, value) {
|
|
6
|
-
return svgSource.replace(/<svg\b[
|
|
6
|
+
return svgSource.replace(/<svg\b[\s\S]*?>/i, (rootTag) => {
|
|
7
7
|
const attrRegex = new RegExp(`\\s${name}=["'][^"']*["']`, 'i');
|
|
8
8
|
if (attrRegex.test(rootTag)) {
|
|
9
9
|
return rootTag.replace(attrRegex, ` ${name}="${value}"`);
|
|
@@ -12,44 +12,26 @@ function setRootAttribute(svgSource, name, value) {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Makes the SVG
|
|
16
|
-
*
|
|
15
|
+
* Makes the SVG viewBox and root dimensions exactly match visible content bounds
|
|
16
|
+
* (path geometry + stroke extent). Single rule — no conditional padding passes.
|
|
17
17
|
*/
|
|
18
|
-
export function fitViewBoxToVisibleContent(svgSource, pad = 0
|
|
18
|
+
export function fitViewBoxToVisibleContent(svgSource, pad = 0) {
|
|
19
19
|
const paths = getVisiblePaths(extractSvgPaths(svgSource));
|
|
20
|
-
const bounds =
|
|
21
|
-
if (!bounds || !/<svg\b[
|
|
20
|
+
const bounds = getVisibleContentBounds(paths);
|
|
21
|
+
if (!bounds || !/<svg\b[\s\S]*?>/i.test(svgSource)) {
|
|
22
22
|
return { svg: svgSource, viewBox: null, applied: false };
|
|
23
23
|
}
|
|
24
24
|
const previousViewBox = parseViewBox(svgSource);
|
|
25
25
|
const padding = Number.isFinite(pad) ? Math.max(0, pad) : 0;
|
|
26
|
-
// When clipToExistingViewBox is set, restrict content bounds to the
|
|
27
|
-
// existing viewBox so that geometry clipped by it does not inflate the
|
|
28
|
-
// tight-fit calculation (used during asset standardisation).
|
|
29
|
-
let effectiveBounds = bounds;
|
|
30
|
-
if (options?.clipToExistingViewBox && previousViewBox) {
|
|
31
|
-
const vbMaxX = previousViewBox.minX + previousViewBox.width;
|
|
32
|
-
const vbMaxY = previousViewBox.minY + previousViewBox.height;
|
|
33
|
-
effectiveBounds = {
|
|
34
|
-
minX: Math.max(bounds.minX, previousViewBox.minX),
|
|
35
|
-
minY: Math.max(bounds.minY, previousViewBox.minY),
|
|
36
|
-
maxX: Math.min(bounds.maxX, vbMaxX),
|
|
37
|
-
maxY: Math.min(bounds.maxY, vbMaxY),
|
|
38
|
-
};
|
|
39
|
-
if (effectiveBounds.minX >= effectiveBounds.maxX || effectiveBounds.minY >= effectiveBounds.maxY) {
|
|
40
|
-
return { svg: svgSource, viewBox: null, applied: false };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
26
|
const viewBox = {
|
|
44
|
-
minX:
|
|
45
|
-
minY:
|
|
46
|
-
width:
|
|
47
|
-
height:
|
|
27
|
+
minX: bounds.minX - padding,
|
|
28
|
+
minY: bounds.minY - padding,
|
|
29
|
+
width: bounds.maxX - bounds.minX + padding * 2,
|
|
30
|
+
height: bounds.maxY - bounds.minY + padding * 2,
|
|
48
31
|
};
|
|
49
32
|
if (viewBox.width <= 0 || viewBox.height <= 0) {
|
|
50
33
|
return { svg: svgSource, viewBox: null, applied: false };
|
|
51
34
|
}
|
|
52
|
-
// Already tight — do not rewrite root attributes (avoids `100` → `100px` churn).
|
|
53
35
|
if (previousViewBox
|
|
54
36
|
&& Math.abs(previousViewBox.minX - viewBox.minX) < 0.01
|
|
55
37
|
&& Math.abs(previousViewBox.minY - viewBox.minY) < 0.01
|
|
@@ -62,6 +44,38 @@ export function fitViewBoxToVisibleContent(svgSource, pad = 0, options) {
|
|
|
62
44
|
svg = setRootAttribute(svg, 'height', `${formatNumber(viewBox.height)}px`);
|
|
63
45
|
return { svg, viewBox, applied: true };
|
|
64
46
|
}
|
|
47
|
+
/** Set root width/height to match viewBox when they diverge (post-fix invariant). */
|
|
48
|
+
export function syncRootDimensionsToViewBox(svgSource) {
|
|
49
|
+
const viewBox = parseViewBox(svgSource);
|
|
50
|
+
if (!viewBox || viewBox.width <= 0 || viewBox.height <= 0) {
|
|
51
|
+
return { svg: svgSource, applied: false };
|
|
52
|
+
}
|
|
53
|
+
const rootMatch = svgSource.match(/<svg\b[\s\S]*?>/i);
|
|
54
|
+
if (!rootMatch)
|
|
55
|
+
return { svg: svgSource, applied: false };
|
|
56
|
+
const widthRaw = rootMatch[0].match(/\bwidth=["']([^"']*)["']/i)?.[1] ?? null;
|
|
57
|
+
const heightRaw = rootMatch[0].match(/\bheight=["']([^"']*)["']/i)?.[1] ?? null;
|
|
58
|
+
const parsePx = (raw) => {
|
|
59
|
+
if (!raw)
|
|
60
|
+
return null;
|
|
61
|
+
const m = raw.trim().match(/^([+-]?(?:\d*\.\d+|\d+))/);
|
|
62
|
+
if (!m)
|
|
63
|
+
return null;
|
|
64
|
+
const n = Number(m[1]);
|
|
65
|
+
return Number.isFinite(n) ? n : null;
|
|
66
|
+
};
|
|
67
|
+
const rootW = parsePx(widthRaw);
|
|
68
|
+
const rootH = parsePx(heightRaw);
|
|
69
|
+
const widthMismatch = rootW === null || Math.abs(rootW - viewBox.width) > 0.5;
|
|
70
|
+
const heightMismatch = rootH === null || Math.abs(rootH - viewBox.height) > 0.5;
|
|
71
|
+
if (!widthMismatch && !heightMismatch) {
|
|
72
|
+
return { svg: svgSource, applied: false };
|
|
73
|
+
}
|
|
74
|
+
let svg = svgSource;
|
|
75
|
+
svg = setRootAttribute(svg, 'width', `${formatNumber(viewBox.width)}px`);
|
|
76
|
+
svg = setRootAttribute(svg, 'height', `${formatNumber(viewBox.height)}px`);
|
|
77
|
+
return { svg, applied: true };
|
|
78
|
+
}
|
|
65
79
|
/**
|
|
66
80
|
* Describes the layout adjustment required when a tight viewBox changes.
|
|
67
81
|
*/
|
|
@@ -81,4 +95,94 @@ export function viewBoxContainsBounds(viewBox, bounds, epsilon = 0.001) {
|
|
|
81
95
|
&& bounds.maxX <= viewBox.minX + viewBox.width + epsilon
|
|
82
96
|
&& bounds.maxY <= viewBox.minY + viewBox.height + epsilon;
|
|
83
97
|
}
|
|
98
|
+
/** Matches cartoon_maker svgEditDragTestHook VIEWBOX_TIGHT_TOLERANCE (0.01px). */
|
|
99
|
+
export const SVG_EDIT_VIEWBOX_TOLERANCE = 0.01;
|
|
100
|
+
/** Compare current viewBox to the tight content bounds (same math as fitViewBoxToVisibleContent). */
|
|
101
|
+
export function checkSvgEditViewBoxPadding(svgSource) {
|
|
102
|
+
const current = parseViewBox(svgSource);
|
|
103
|
+
const fitted = fitViewBoxToVisibleContent(svgSource);
|
|
104
|
+
const tight = fitted.viewBox;
|
|
105
|
+
if (!current) {
|
|
106
|
+
return { pass: false, reason: 'missing or invalid viewBox' };
|
|
107
|
+
}
|
|
108
|
+
if (!tight) {
|
|
109
|
+
return { pass: true, currentViewBox: current };
|
|
110
|
+
}
|
|
111
|
+
const padding = {
|
|
112
|
+
left: tight.minX - current.minX,
|
|
113
|
+
top: tight.minY - current.minY,
|
|
114
|
+
right: (current.minX + current.width) - (tight.minX + tight.width),
|
|
115
|
+
bottom: (current.minY + current.height) - (tight.minY + tight.height),
|
|
116
|
+
};
|
|
117
|
+
const overflow = {
|
|
118
|
+
left: -padding.left,
|
|
119
|
+
top: -padding.top,
|
|
120
|
+
right: -padding.right,
|
|
121
|
+
bottom: -padding.bottom,
|
|
122
|
+
};
|
|
123
|
+
const tol = SVG_EDIT_VIEWBOX_TOLERANCE;
|
|
124
|
+
const hasPadding = padding.left > tol || padding.top > tol || padding.right > tol || padding.bottom > tol;
|
|
125
|
+
const hasOverflow = overflow.left > tol || overflow.top > tol || overflow.right > tol || overflow.bottom > tol;
|
|
126
|
+
if (hasOverflow) {
|
|
127
|
+
const sides = [];
|
|
128
|
+
if (overflow.left > tol)
|
|
129
|
+
sides.push(`L=${overflow.left.toFixed(2)}`);
|
|
130
|
+
if (overflow.right > tol)
|
|
131
|
+
sides.push(`R=${overflow.right.toFixed(2)}`);
|
|
132
|
+
if (overflow.top > tol)
|
|
133
|
+
sides.push(`T=${overflow.top.toFixed(2)}`);
|
|
134
|
+
if (overflow.bottom > tol)
|
|
135
|
+
sides.push(`B=${overflow.bottom.toFixed(2)}`);
|
|
136
|
+
return {
|
|
137
|
+
pass: false,
|
|
138
|
+
hasPadding,
|
|
139
|
+
hasOverflow,
|
|
140
|
+
padding,
|
|
141
|
+
overflow,
|
|
142
|
+
currentViewBox: current,
|
|
143
|
+
tightViewBox: tight,
|
|
144
|
+
reason: `content overflows tight viewBox (${sides.join(' ')})`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (hasPadding) {
|
|
148
|
+
const sides = [];
|
|
149
|
+
if (padding.left > tol)
|
|
150
|
+
sides.push(`L=${padding.left.toFixed(2)}`);
|
|
151
|
+
if (padding.right > tol)
|
|
152
|
+
sides.push(`R=${padding.right.toFixed(2)}`);
|
|
153
|
+
if (padding.top > tol)
|
|
154
|
+
sides.push(`T=${padding.top.toFixed(2)}`);
|
|
155
|
+
if (padding.bottom > tol)
|
|
156
|
+
sides.push(`B=${padding.bottom.toFixed(2)}`);
|
|
157
|
+
return {
|
|
158
|
+
pass: false,
|
|
159
|
+
hasPadding,
|
|
160
|
+
hasOverflow,
|
|
161
|
+
padding,
|
|
162
|
+
overflow,
|
|
163
|
+
currentViewBox: current,
|
|
164
|
+
tightViewBox: tight,
|
|
165
|
+
reason: `excess viewBox padding vs tight content bounds (${sides.join(' ')})`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
pass: true,
|
|
170
|
+
hasPadding: false,
|
|
171
|
+
hasOverflow: false,
|
|
172
|
+
padding,
|
|
173
|
+
overflow,
|
|
174
|
+
currentViewBox: current,
|
|
175
|
+
tightViewBox: tight,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export function formatSvgEditViewBoxPaddingFailure(result) {
|
|
179
|
+
if (result.pass)
|
|
180
|
+
return 'pass';
|
|
181
|
+
return result.reason || 'SVG edit viewBox padding check failed';
|
|
182
|
+
}
|
|
183
|
+
export function svgEditViewBoxPaddingSeverity(result) {
|
|
184
|
+
if (result.pass || !result.overflow || !result.padding)
|
|
185
|
+
return 0;
|
|
186
|
+
return Math.max(Math.abs(result.overflow.left), Math.abs(result.overflow.right), Math.abs(result.overflow.top), Math.abs(result.overflow.bottom), Math.abs(result.padding.left), Math.abs(result.padding.right), Math.abs(result.padding.top), Math.abs(result.padding.bottom));
|
|
187
|
+
}
|
|
84
188
|
//# sourceMappingURL=svgViewBox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svgViewBox.js","sourceRoot":"","sources":["../../modules/svgViewBox.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"svgViewBox.js","sourceRoot":"","sources":["../../modules/svgViewBox.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,YAAY,GACf,MAAM,uBAAuB,CAAC;AAS/B,SAAS,YAAY,CAAC,KAAa;IAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAiB,EAAE,IAAY,EAAE,KAAa;IACpE,OAAO,SAAS,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE;QACrD,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,MAAM,IAAI,iBAAiB,EAAE,GAAG,CAAC,CAAC;QAC/D,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1B,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,OAAO,CAA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AACpE,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,MAAmC;IAC7E,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,CAAC,CAAC;IACjE,OAAO,IAAI,CAAC,GAAG,CACX,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC9B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC/B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC7B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAChC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAC7B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAC9B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAC5B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAClC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end test: verify that `fixRigAssets` preserves visual rig attributes.
|
|
3
|
+
*
|
|
4
|
+
* Flow:
|
|
5
|
+
* 1. Load an original rig JSON (tank.json)
|
|
6
|
+
* 2. Snapshot raster dimensions and all render-affecting attributes
|
|
7
|
+
* 3. Run fixRigAssets (the same transform that `distark-check fix` applies)
|
|
8
|
+
* 4. Snapshot the fixed rig
|
|
9
|
+
* 5. Compare every visual attribute and report diagnostics
|
|
10
|
+
*
|
|
11
|
+
* This test does NOT assert pass/fail — it returns a full diagnostic report
|
|
12
|
+
* showing which attributes changed, which stayed the same, and by how much.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=test-fix-visual-parity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-fix-visual-parity.d.ts","sourceRoot":"","sources":["../../tests/test-fix-visual-parity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end test: verify that `fixRigAssets` preserves visual rig attributes.
|
|
3
|
+
*
|
|
4
|
+
* Flow:
|
|
5
|
+
* 1. Load an original rig JSON (tank.json)
|
|
6
|
+
* 2. Snapshot raster dimensions and all render-affecting attributes
|
|
7
|
+
* 3. Run fixRigAssets (the same transform that `distark-check fix` applies)
|
|
8
|
+
* 4. Snapshot the fixed rig
|
|
9
|
+
* 5. Compare every visual attribute and report diagnostics
|
|
10
|
+
*
|
|
11
|
+
* This test does NOT assert pass/fail — it returns a full diagnostic report
|
|
12
|
+
* showing which attributes changed, which stayed the same, and by how much.
|
|
13
|
+
*/
|
|
14
|
+
import { readFile } from 'fs/promises';
|
|
15
|
+
import { join, dirname, isAbsolute, resolve } from 'path';
|
|
16
|
+
import { fileURLToPath } from 'url';
|
|
17
|
+
import { fixRigAssets } from '../modules/rigAssetFix.js';
|
|
18
|
+
import { computeCharacterRigData } from '../modules/renderRig.js';
|
|
19
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const ASSETS_DIR = join(__dirname, '..', '..', 'assets');
|
|
21
|
+
// ── Snapshot extraction ──────────────────────────────────────────────────────
|
|
22
|
+
function snapshotRig(rig) {
|
|
23
|
+
const dims = (rig.dimensionValues ?? {});
|
|
24
|
+
const pivots = (rig.pivotPoints ?? {});
|
|
25
|
+
const joints = (rig.jointOffset ?? {});
|
|
26
|
+
const zIdx = (rig.zIndexValues ?? {});
|
|
27
|
+
const rots = (rig.rotationValues ?? {});
|
|
28
|
+
const selfRots = (rig.selfRotationValues ?? {});
|
|
29
|
+
const eyes = (rig.eyes ?? {});
|
|
30
|
+
const mouth = (rig.mouth ?? {});
|
|
31
|
+
const dimensionValues = {};
|
|
32
|
+
for (const [k, v] of Object.entries(dims)) {
|
|
33
|
+
if (v && typeof v.width === 'number' && typeof v.height === 'number') {
|
|
34
|
+
dimensionValues[k] = { width: v.width, height: v.height };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const pivotPoints = {};
|
|
38
|
+
for (const [k, v] of Object.entries(pivots)) {
|
|
39
|
+
if (v && typeof v.x === 'number' && typeof v.y === 'number') {
|
|
40
|
+
pivotPoints[k] = { x: v.x, y: v.y };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const jointOffset = {};
|
|
44
|
+
for (const [k, v] of Object.entries(joints)) {
|
|
45
|
+
if (v && typeof v.x === 'number' && typeof v.y === 'number') {
|
|
46
|
+
jointOffset[k] = { x: v.x, y: v.y };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const eyeCoordKeys = [
|
|
50
|
+
'leftEyeXCoor', 'leftEyeYCoor', 'rightEyeXCoor', 'rightEyeYCoor',
|
|
51
|
+
'leftEyeLidXCoor', 'leftEyeLidYCoor', 'rightEyeLidXCoor', 'rightEyeLidYCoor',
|
|
52
|
+
'leftIrisXCoor', 'leftIrisYCoor', 'rightIrisXCoor', 'rightIrisYCoor',
|
|
53
|
+
];
|
|
54
|
+
const eyeSizeKeys = [
|
|
55
|
+
'leftIrisWidth', 'leftIrisHeight', 'rightIrisWidth', 'rightIrisHeight',
|
|
56
|
+
'leftEyeImageWidth', 'leftEyeImageHeight', 'rightEyeImageWidth', 'rightEyeImageHeight',
|
|
57
|
+
'leftEyeWidthRatio', 'leftEyeHeightRatio', 'rightEyeWidthRatio', 'rightEyeHeightRatio',
|
|
58
|
+
'leftIrisWidthRatio', 'leftIrisHeightRatio', 'rightIrisWidthRatio', 'rightIrisHeightRatio',
|
|
59
|
+
'leftEyeLidOpenWidth', 'leftEyeLidOpenHeight', 'rightEyeLidOpenWidth', 'rightEyeLidOpenHeight',
|
|
60
|
+
'leftEyeLidClosedWidth', 'leftEyeLidClosedHeight', 'rightEyeLidClosedWidth', 'rightEyeLidClosedHeight',
|
|
61
|
+
'leftEyeLidWidthRatio', 'leftEyeLidHeightRatio', 'rightEyeLidWidthRatio', 'rightEyeLidHeightRatio',
|
|
62
|
+
'leftEyeLidHalfClosedWidth', 'leftEyeLidHalfClosedHeight',
|
|
63
|
+
'rightEyeLidHalfClosedWidth', 'rightEyeLidHalfClosedHeight',
|
|
64
|
+
];
|
|
65
|
+
const eyeCoords = {};
|
|
66
|
+
for (const k of eyeCoordKeys) {
|
|
67
|
+
if (typeof eyes[k] === 'number')
|
|
68
|
+
eyeCoords[k] = eyes[k];
|
|
69
|
+
}
|
|
70
|
+
const eyeSizes = {};
|
|
71
|
+
for (const k of eyeSizeKeys) {
|
|
72
|
+
if (typeof eyes[k] === 'number')
|
|
73
|
+
eyeSizes[k] = eyes[k];
|
|
74
|
+
}
|
|
75
|
+
const mouthNumericKeys = ['xCoor', 'yCoor', 'width', 'height', 'size',
|
|
76
|
+
'mouthWidth', 'mouthHeight', 'mouthSize', 'mouthXCoor', 'mouthYCoor'];
|
|
77
|
+
const mouthAttrs = {};
|
|
78
|
+
for (const k of mouthNumericKeys) {
|
|
79
|
+
if (typeof mouth[k] === 'number')
|
|
80
|
+
mouthAttrs[k] = mouth[k];
|
|
81
|
+
}
|
|
82
|
+
const rigData = rig;
|
|
83
|
+
const renderData = computeCharacterRigData(rigData, {
|
|
84
|
+
canvasWidth: 800,
|
|
85
|
+
canvasHeight: 800,
|
|
86
|
+
});
|
|
87
|
+
const renderObjects = renderData.objects
|
|
88
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
89
|
+
.map(obj => ({
|
|
90
|
+
name: obj.name,
|
|
91
|
+
width: obj.width,
|
|
92
|
+
height: obj.height,
|
|
93
|
+
x: obj.x,
|
|
94
|
+
y: obj.y,
|
|
95
|
+
rotation: obj.rotation,
|
|
96
|
+
scaleX: obj.scaleX,
|
|
97
|
+
scaleY: obj.scaleY,
|
|
98
|
+
anchorX: obj.anchorX,
|
|
99
|
+
anchorY: obj.anchorY,
|
|
100
|
+
zIndex: obj.zIndex,
|
|
101
|
+
}));
|
|
102
|
+
return {
|
|
103
|
+
rigLevel: {
|
|
104
|
+
width: rig.width,
|
|
105
|
+
height: rig.height,
|
|
106
|
+
imageScale: rig.imageScale,
|
|
107
|
+
},
|
|
108
|
+
dimensionValues,
|
|
109
|
+
pivotPoints,
|
|
110
|
+
jointOffset,
|
|
111
|
+
zIndexValues: { ...zIdx },
|
|
112
|
+
rotationValues: { ...rots },
|
|
113
|
+
selfRotationValues: { ...selfRots },
|
|
114
|
+
eyeCoords,
|
|
115
|
+
eyeSizes,
|
|
116
|
+
mouthAttrs,
|
|
117
|
+
renderObjects,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function compareNumericMaps(prefix, before, after) {
|
|
121
|
+
const diffs = [];
|
|
122
|
+
const allKeys = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
123
|
+
for (const key of allKeys) {
|
|
124
|
+
const bVal = before[key];
|
|
125
|
+
const aVal = after[key];
|
|
126
|
+
if (bVal === undefined && aVal !== undefined) {
|
|
127
|
+
diffs.push({ path: `${prefix}.${key}`, before: NaN, after: aVal, delta: NaN, percentChange: NaN });
|
|
128
|
+
}
|
|
129
|
+
else if (bVal !== undefined && aVal === undefined) {
|
|
130
|
+
diffs.push({ path: `${prefix}.${key}`, before: bVal, after: NaN, delta: NaN, percentChange: NaN });
|
|
131
|
+
}
|
|
132
|
+
else if (bVal !== undefined && aVal !== undefined && bVal !== aVal) {
|
|
133
|
+
const delta = aVal - bVal;
|
|
134
|
+
const pct = bVal !== 0 ? (delta / Math.abs(bVal)) * 100 : Infinity;
|
|
135
|
+
diffs.push({ path: `${prefix}.${key}`, before: bVal, after: aVal, delta, percentChange: pct });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return diffs;
|
|
139
|
+
}
|
|
140
|
+
function compareDimensionMaps(prefix, before, after) {
|
|
141
|
+
const diffs = [];
|
|
142
|
+
const allKeys = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
143
|
+
for (const key of allKeys) {
|
|
144
|
+
const b = before[key];
|
|
145
|
+
const a = after[key];
|
|
146
|
+
if (!b && a) {
|
|
147
|
+
diffs.push({ path: `${prefix}.${key}.width`, before: NaN, after: a.width, delta: NaN, percentChange: NaN });
|
|
148
|
+
diffs.push({ path: `${prefix}.${key}.height`, before: NaN, after: a.height, delta: NaN, percentChange: NaN });
|
|
149
|
+
}
|
|
150
|
+
else if (b && !a) {
|
|
151
|
+
diffs.push({ path: `${prefix}.${key}.width`, before: b.width, after: NaN, delta: NaN, percentChange: NaN });
|
|
152
|
+
diffs.push({ path: `${prefix}.${key}.height`, before: b.height, after: NaN, delta: NaN, percentChange: NaN });
|
|
153
|
+
}
|
|
154
|
+
else if (b && a) {
|
|
155
|
+
if (b.width !== a.width) {
|
|
156
|
+
const d = a.width - b.width;
|
|
157
|
+
diffs.push({ path: `${prefix}.${key}.width`, before: b.width, after: a.width, delta: d, percentChange: b.width ? (d / b.width) * 100 : Infinity });
|
|
158
|
+
}
|
|
159
|
+
if (b.height !== a.height) {
|
|
160
|
+
const d = a.height - b.height;
|
|
161
|
+
diffs.push({ path: `${prefix}.${key}.height`, before: b.height, after: a.height, delta: d, percentChange: b.height ? (d / b.height) * 100 : Infinity });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return diffs;
|
|
166
|
+
}
|
|
167
|
+
function compareCoordMaps(prefix, before, after) {
|
|
168
|
+
const diffs = [];
|
|
169
|
+
const allKeys = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
170
|
+
for (const key of allKeys) {
|
|
171
|
+
const b = before[key];
|
|
172
|
+
const a = after[key];
|
|
173
|
+
if (!b && a) {
|
|
174
|
+
diffs.push({ path: `${prefix}.${key}.x`, before: NaN, after: a.x, delta: NaN, percentChange: NaN });
|
|
175
|
+
diffs.push({ path: `${prefix}.${key}.y`, before: NaN, after: a.y, delta: NaN, percentChange: NaN });
|
|
176
|
+
}
|
|
177
|
+
else if (b && !a) {
|
|
178
|
+
diffs.push({ path: `${prefix}.${key}.x`, before: b.x, after: NaN, delta: NaN, percentChange: NaN });
|
|
179
|
+
diffs.push({ path: `${prefix}.${key}.y`, before: b.y, after: NaN, delta: NaN, percentChange: NaN });
|
|
180
|
+
}
|
|
181
|
+
else if (b && a) {
|
|
182
|
+
if (b.x !== a.x) {
|
|
183
|
+
const d = a.x - b.x;
|
|
184
|
+
diffs.push({ path: `${prefix}.${key}.x`, before: b.x, after: a.x, delta: d, percentChange: b.x ? (d / Math.abs(b.x)) * 100 : Infinity });
|
|
185
|
+
}
|
|
186
|
+
if (b.y !== a.y) {
|
|
187
|
+
const d = a.y - b.y;
|
|
188
|
+
diffs.push({ path: `${prefix}.${key}.y`, before: b.y, after: a.y, delta: d, percentChange: b.y ? (d / Math.abs(b.y)) * 100 : Infinity });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return diffs;
|
|
193
|
+
}
|
|
194
|
+
function compareRenderObjects(before, after) {
|
|
195
|
+
const diffs = [];
|
|
196
|
+
const beforeMap = new Map(before.map(o => [o.name, o]));
|
|
197
|
+
const afterMap = new Map(after.map(o => [o.name, o]));
|
|
198
|
+
const allNames = new Set([...beforeMap.keys(), ...afterMap.keys()]);
|
|
199
|
+
const numericKeys = [
|
|
200
|
+
'width', 'height', 'x', 'y', 'rotation', 'scaleX', 'scaleY',
|
|
201
|
+
'anchorX', 'anchorY', 'zIndex',
|
|
202
|
+
];
|
|
203
|
+
for (const name of [...allNames].sort()) {
|
|
204
|
+
const b = beforeMap.get(name);
|
|
205
|
+
const a = afterMap.get(name);
|
|
206
|
+
if (!b || !a) {
|
|
207
|
+
diffs.push({
|
|
208
|
+
path: `renderObject.${name}`,
|
|
209
|
+
before: b ? 1 : NaN,
|
|
210
|
+
after: a ? 1 : NaN,
|
|
211
|
+
delta: NaN,
|
|
212
|
+
percentChange: NaN,
|
|
213
|
+
});
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
for (const key of numericKeys) {
|
|
217
|
+
const bv = b[key];
|
|
218
|
+
const av = a[key];
|
|
219
|
+
if (bv !== av) {
|
|
220
|
+
const d = av - bv;
|
|
221
|
+
const pct = bv !== 0 ? (d / Math.abs(bv)) * 100 : Infinity;
|
|
222
|
+
diffs.push({ path: `renderObject.${name}.${key}`, before: bv, after: av, delta: d, percentChange: pct });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return diffs;
|
|
227
|
+
}
|
|
228
|
+
// ── Formatting ───────────────────────────────────────────────────────────────
|
|
229
|
+
function fmtNum(n) {
|
|
230
|
+
if (isNaN(n))
|
|
231
|
+
return '(missing)';
|
|
232
|
+
return Number.isInteger(n) ? String(n) : n.toFixed(4);
|
|
233
|
+
}
|
|
234
|
+
function fmtPct(n) {
|
|
235
|
+
if (isNaN(n))
|
|
236
|
+
return 'N/A';
|
|
237
|
+
if (!isFinite(n))
|
|
238
|
+
return 'Inf';
|
|
239
|
+
return `${n >= 0 ? '+' : ''}${n.toFixed(2)}%`;
|
|
240
|
+
}
|
|
241
|
+
function printDiffTable(label, diffs) {
|
|
242
|
+
if (diffs.length === 0) {
|
|
243
|
+
console.log(` ${label}: all attributes match`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
console.log(` ${label}: ${diffs.length} difference(s)`);
|
|
247
|
+
const colW = { path: 42, before: 14, after: 14, delta: 14, pct: 10 };
|
|
248
|
+
console.log(` ${'Attribute'.padEnd(colW.path)}${'Before'.padStart(colW.before)}${'After'.padStart(colW.after)}${'Delta'.padStart(colW.delta)}${'%Change'.padStart(colW.pct)}`);
|
|
249
|
+
console.log(` ${'─'.repeat(colW.path + colW.before + colW.after + colW.delta + colW.pct)}`);
|
|
250
|
+
for (const d of diffs) {
|
|
251
|
+
console.log(` ${d.path.padEnd(colW.path)}${fmtNum(d.before).padStart(colW.before)}${fmtNum(d.after).padStart(colW.after)}${fmtNum(d.delta).padStart(colW.delta)}${fmtPct(d.percentChange).padStart(colW.pct)}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// ── Main test ────────────────────────────────────────────────────────────────
|
|
255
|
+
async function main() {
|
|
256
|
+
const cliArgs = process.argv.slice(2);
|
|
257
|
+
const rigPaths = [];
|
|
258
|
+
if (cliArgs.length > 0) {
|
|
259
|
+
for (const arg of cliArgs) {
|
|
260
|
+
const resolved = isAbsolute(arg) ? arg : resolve(process.cwd(), arg);
|
|
261
|
+
rigPaths.push({ label: arg.split(/[\\/]/).pop(), path: resolved });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
for (const f of ['tank.json', 'KidB.json']) {
|
|
266
|
+
rigPaths.push({ label: f, path: join(ASSETS_DIR, f) });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
for (const { label: rigFile, path: rigPath } of rigPaths) {
|
|
270
|
+
let rigRaw;
|
|
271
|
+
try {
|
|
272
|
+
rigRaw = await readFile(rigPath, 'utf-8');
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
console.log(`\n⚠ Skipping ${rigFile} — file not found at ${rigPath}`);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const originalRig = JSON.parse(rigRaw);
|
|
279
|
+
console.log(`\n${'═'.repeat(70)}`);
|
|
280
|
+
console.log(`FIX VISUAL PARITY DIAGNOSTIC: ${rigFile}`);
|
|
281
|
+
console.log(`${'═'.repeat(70)}`);
|
|
282
|
+
// 1. Snapshot before
|
|
283
|
+
const beforeSnap = snapshotRig(originalRig);
|
|
284
|
+
console.log(`\nBefore snapshot: ${Object.keys(beforeSnap.dimensionValues).length} dimension entries, ${beforeSnap.renderObjects.length} render objects`);
|
|
285
|
+
// 2. Run fixRigAssets
|
|
286
|
+
const fixResult = await fixRigAssets(originalRig);
|
|
287
|
+
const fixedRig = fixResult.rig;
|
|
288
|
+
console.log(`\nFix result:`);
|
|
289
|
+
console.log(` Assets processed: ${fixResult.assetsProcessed}`);
|
|
290
|
+
console.log(` Assets changed: ${fixResult.assetsChanged}`);
|
|
291
|
+
console.log(` Before compliant: ${fixResult.before.compliant}`);
|
|
292
|
+
console.log(` After compliant: ${fixResult.after.compliant}`);
|
|
293
|
+
if (fixResult.assetFixes.filter(a => a.changed).length > 0) {
|
|
294
|
+
console.log(` Applied fixes:`);
|
|
295
|
+
for (const record of fixResult.assetFixes.filter(a => a.changed)) {
|
|
296
|
+
for (const fix of record.fixes) {
|
|
297
|
+
console.log(` • ${record.partKeys[0]}: ${fix}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// 3. Snapshot after
|
|
302
|
+
const afterSnap = snapshotRig(fixedRig);
|
|
303
|
+
console.log(`\nAfter snapshot: ${Object.keys(afterSnap.dimensionValues).length} dimension entries, ${afterSnap.renderObjects.length} render objects`);
|
|
304
|
+
// 4. Compare everything
|
|
305
|
+
console.log(`\n── Attribute Comparison ──`);
|
|
306
|
+
const rigLevelDiffs = [];
|
|
307
|
+
for (const key of ['width', 'height', 'imageScale']) {
|
|
308
|
+
const bv = beforeSnap.rigLevel[key];
|
|
309
|
+
const av = afterSnap.rigLevel[key];
|
|
310
|
+
if (bv !== av) {
|
|
311
|
+
rigLevelDiffs.push({
|
|
312
|
+
path: `rig.${key}`,
|
|
313
|
+
before: bv ?? NaN,
|
|
314
|
+
after: av ?? NaN,
|
|
315
|
+
delta: (av ?? 0) - (bv ?? 0),
|
|
316
|
+
percentChange: bv ? (((av ?? 0) - bv) / Math.abs(bv)) * 100 : NaN,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
printDiffTable('Rig-level attrs', rigLevelDiffs);
|
|
321
|
+
const dimDiffs = compareDimensionMaps('dimensionValues', beforeSnap.dimensionValues, afterSnap.dimensionValues);
|
|
322
|
+
printDiffTable('dimensionValues (raster w/h)', dimDiffs);
|
|
323
|
+
const pivotDiffs = compareCoordMaps('pivotPoints', beforeSnap.pivotPoints, afterSnap.pivotPoints);
|
|
324
|
+
printDiffTable('pivotPoints', pivotDiffs);
|
|
325
|
+
const jointDiffs = compareCoordMaps('jointOffset', beforeSnap.jointOffset, afterSnap.jointOffset);
|
|
326
|
+
printDiffTable('jointOffset', jointDiffs);
|
|
327
|
+
const zDiffs = compareNumericMaps('zIndexValues', beforeSnap.zIndexValues, afterSnap.zIndexValues);
|
|
328
|
+
printDiffTable('zIndexValues', zDiffs);
|
|
329
|
+
const rotDiffs = compareNumericMaps('rotationValues', beforeSnap.rotationValues, afterSnap.rotationValues);
|
|
330
|
+
printDiffTable('rotationValues', rotDiffs);
|
|
331
|
+
const selfRotDiffs = compareNumericMaps('selfRotationValues', beforeSnap.selfRotationValues, afterSnap.selfRotationValues);
|
|
332
|
+
printDiffTable('selfRotationValues', selfRotDiffs);
|
|
333
|
+
const eyeCoordDiffs = compareNumericMaps('eyes (coords)', beforeSnap.eyeCoords, afterSnap.eyeCoords);
|
|
334
|
+
printDiffTable('Eye coordinates', eyeCoordDiffs);
|
|
335
|
+
const eyeSizeDiffs = compareNumericMaps('eyes (sizes)', beforeSnap.eyeSizes, afterSnap.eyeSizes);
|
|
336
|
+
printDiffTable('Eye sizes/ratios', eyeSizeDiffs);
|
|
337
|
+
const mouthDiffs = compareNumericMaps('mouth', beforeSnap.mouthAttrs, afterSnap.mouthAttrs);
|
|
338
|
+
printDiffTable('Mouth attrs', mouthDiffs);
|
|
339
|
+
const renderDiffs = compareRenderObjects(beforeSnap.renderObjects, afterSnap.renderObjects);
|
|
340
|
+
printDiffTable('Computed render objects', renderDiffs);
|
|
341
|
+
// 5. Summary
|
|
342
|
+
const allDiffs = [
|
|
343
|
+
...rigLevelDiffs, ...dimDiffs, ...pivotDiffs, ...jointDiffs,
|
|
344
|
+
...zDiffs, ...rotDiffs, ...selfRotDiffs,
|
|
345
|
+
...eyeCoordDiffs, ...eyeSizeDiffs, ...mouthDiffs,
|
|
346
|
+
...renderDiffs,
|
|
347
|
+
];
|
|
348
|
+
console.log(`\n── Summary ──`);
|
|
349
|
+
console.log(` Total attributes compared: ${countAttrs(beforeSnap, afterSnap)}`);
|
|
350
|
+
console.log(` Attributes with differences: ${allDiffs.length}`);
|
|
351
|
+
console.log(` Attributes identical: ${countAttrs(beforeSnap, afterSnap) - allDiffs.length}`);
|
|
352
|
+
if (allDiffs.length === 0) {
|
|
353
|
+
console.log(`\n ✅ All visual attributes are identical before and after fix.`);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
console.log(`\n ⚠ ${allDiffs.length} visual attribute(s) changed after fix.`);
|
|
357
|
+
if (dimDiffs.length > 0) {
|
|
358
|
+
console.log(` → dimensionValues changed for ${new Set(dimDiffs.map(d => d.path.split('.')[1])).size} part(s)`);
|
|
359
|
+
}
|
|
360
|
+
if (renderDiffs.length > 0) {
|
|
361
|
+
const affectedParts = new Set(renderDiffs.map(d => d.path.split('.')[1]));
|
|
362
|
+
console.log(` → Render output changed for ${affectedParts.size} part(s): ${[...affectedParts].join(', ')}`);
|
|
363
|
+
}
|
|
364
|
+
const maxPctChange = allDiffs
|
|
365
|
+
.filter(d => isFinite(d.percentChange) && !isNaN(d.percentChange))
|
|
366
|
+
.reduce((max, d) => Math.max(max, Math.abs(d.percentChange)), 0);
|
|
367
|
+
if (maxPctChange > 0) {
|
|
368
|
+
console.log(` → Maximum percent change: ${maxPctChange.toFixed(2)}%`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function countAttrs(before, after) {
|
|
374
|
+
let count = 3; // rig-level
|
|
375
|
+
const allDimKeys = new Set([...Object.keys(before.dimensionValues), ...Object.keys(after.dimensionValues)]);
|
|
376
|
+
count += allDimKeys.size * 2; // width + height
|
|
377
|
+
const allPivotKeys = new Set([...Object.keys(before.pivotPoints), ...Object.keys(after.pivotPoints)]);
|
|
378
|
+
count += allPivotKeys.size * 2;
|
|
379
|
+
const allJointKeys = new Set([...Object.keys(before.jointOffset), ...Object.keys(after.jointOffset)]);
|
|
380
|
+
count += allJointKeys.size * 2;
|
|
381
|
+
count += new Set([...Object.keys(before.zIndexValues), ...Object.keys(after.zIndexValues)]).size;
|
|
382
|
+
count += new Set([...Object.keys(before.rotationValues), ...Object.keys(after.rotationValues)]).size;
|
|
383
|
+
count += new Set([...Object.keys(before.selfRotationValues), ...Object.keys(after.selfRotationValues)]).size;
|
|
384
|
+
count += new Set([...Object.keys(before.eyeCoords), ...Object.keys(after.eyeCoords)]).size;
|
|
385
|
+
count += new Set([...Object.keys(before.eyeSizes), ...Object.keys(after.eyeSizes)]).size;
|
|
386
|
+
count += new Set([...Object.keys(before.mouthAttrs), ...Object.keys(after.mouthAttrs)]).size;
|
|
387
|
+
const allRenderNames = new Set([
|
|
388
|
+
...before.renderObjects.map(o => o.name),
|
|
389
|
+
...after.renderObjects.map(o => o.name),
|
|
390
|
+
]);
|
|
391
|
+
count += allRenderNames.size * 10; // 10 numeric props per render object
|
|
392
|
+
return count;
|
|
393
|
+
}
|
|
394
|
+
main().catch(err => {
|
|
395
|
+
console.error('Fatal error:', err);
|
|
396
|
+
process.exit(1);
|
|
397
|
+
});
|
|
398
|
+
//# sourceMappingURL=test-fix-visual-parity.js.map
|