uxml-preview 0.2.0 → 0.4.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.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Differences from Unity that measurement has confirmed and that fixing the
3
+ * renderer cannot close. `docs/accuracy.md` describes 16 divergent values;
4
+ * all but one class of them are listed below.
5
+ *
6
+ * The 1px cases (3 values) are excluded on purpose: they sit inside the
7
+ * golden tests' own 0.5px-tighter-than-plan tolerance. That is a test
8
+ * judgement parameter, not a rendering limitation — listing it here would
9
+ * tell a host to worry about a difference the renderer did not actually make.
10
+ *
11
+ * If a fourth category is ever promoted here, extend this list and the
12
+ * pinned entry count in tests/known-divergences.test.ts together — do not
13
+ * let the list grow silently, since `id` is a contract hosts key off.
14
+ */
15
+ export interface KnownDivergence {
16
+ /** Stable identifier. Hosts may key off this; do not rename. */
17
+ readonly id: string;
18
+ /**
19
+ * Why this cannot simply be fixed.
20
+ *
21
+ * 'unreproducible' — the difference comes from something we cannot
22
+ * reproduce at all, such as font metrics that move with the platform.
23
+ * 'unspecified' — Unity's own rule for this case is not specified,
24
+ * so there is no target to match yet.
25
+ * 'upstream' — the difference is fully reproducible and deterministic,
26
+ * but it lives in something this renderer depends on rather than in this
27
+ * renderer's own code — the place that would need to change is not this
28
+ * repository.
29
+ */
30
+ readonly kind: 'unreproducible' | 'unspecified' | 'upstream';
31
+ /** One line, for a diagnostics list. */
32
+ readonly summary: string;
33
+ /** What is different and why, for someone deciding whether to care. */
34
+ readonly detail: string;
35
+ }
36
+ export declare const KNOWN_DIVERGENCES: readonly KnownDivergence[];
@@ -196,6 +196,7 @@ export type SheetItem = {
196
196
  kind: 'import';
197
197
  url: string;
198
198
  span: Span;
199
+ resolvedSheet?: number;
199
200
  } | {
200
201
  kind: 'unknown';
201
202
  span: Span;
@@ -244,7 +245,17 @@ export interface UxmlDocument {
244
245
  * own `source`, which is why the source text lives on the sheet.
245
246
  */
246
247
  sheets: StyleSheet[];
247
- /** Parse-time only — malformed input. Support judgments happen downstream. */
248
+ /** Stylesheet entry points and the element subtree each one is attached to. */
249
+ styleRoots?: Array<{
250
+ sheet: number;
251
+ scope: NodeId;
252
+ }>;
253
+ /**
254
+ * Parse-time only — `'malformed'` (bad syntax) and `'import-unresolved'`
255
+ * (a `<Style src="…">` or `@import` that `resolveImport` could not read).
256
+ * Support judgments (unsupported controls/properties/selectors/units,
257
+ * unresolved assets) happen downstream, in `RenderResult.warnings`.
258
+ */
248
259
  warnings: Warning[];
249
260
  }
250
261
  /**
@@ -1,7 +1,16 @@
1
1
  import { NodeId, Warning } from '../model/types';
2
2
  import { ComputedStyle } from '../style/resolve';
3
3
  export interface CssMapOptions {
4
- resolveAsset?: ((path: string) => string | null) | undefined;
4
+ /**
5
+ * `form` tells `url("...")` apart from `resource("...")` — Unity resolves
6
+ * them differently: `url()` is a path (relative to the project or
7
+ * absolute), `resource()` names an asset inside a Resources folder by its
8
+ * Unity resource path (no extension). A host that ignores `form` and
9
+ * treats every path the same will resolve `resource("foo")` as a literal
10
+ * file path, which silently draws the wrong image whenever a same-named
11
+ * file happens to sit alongside it — or resolves nothing at all.
12
+ */
13
+ resolveAsset?: ((path: string, form: 'url' | 'resource') => string | null) | undefined;
5
14
  }
6
15
  export interface CssMapResult {
7
16
  declarations: Record<string, string>;
@@ -0,0 +1,14 @@
1
+ export interface GuidIndex {
2
+ /** Absolute path of the asset with this GUID, or null. */
3
+ get(guid: string): string | null;
4
+ /** Number of entries. Lets a host report an empty scan. */
5
+ readonly size: number;
6
+ }
7
+ /**
8
+ * Purpose: resolve a `project://database/Assets/...` reference whose file has
9
+ * moved, by walking `.meta` files for their `guid:` line instead.
10
+ * Deps/Effects: reads the directory tree under `projectRoot`; unreadable
11
+ * `.meta` files are skipped rather than thrown, so one bad file cannot fail
12
+ * the whole scan.
13
+ */
14
+ export declare function buildGuidIndex(projectRoot: string): Promise<GuidIndex>;
@@ -0,0 +1,41 @@
1
+ import { readdir as c, readFile as u } from "node:fs/promises";
2
+ import { join as s } from "node:path";
3
+ const l = /* @__PURE__ */ new Set(["Library", "Temp", "obj", ".git"]), f = /^guid:\s*([0-9a-fA-F]+)/m;
4
+ async function y(n) {
5
+ const t = /* @__PURE__ */ new Map();
6
+ return await o(n, t), {
7
+ get(e) {
8
+ return t.get(e) ?? null;
9
+ },
10
+ get size() {
11
+ return t.size;
12
+ }
13
+ };
14
+ }
15
+ async function o(n, t) {
16
+ const e = await c(n, { withFileTypes: !0 });
17
+ for (const i of e) {
18
+ const a = s(n, i.name);
19
+ if (i.isDirectory()) {
20
+ if (l.has(i.name)) continue;
21
+ await o(a, t);
22
+ continue;
23
+ }
24
+ if (!i.name.endsWith(".meta")) continue;
25
+ const r = await m(a);
26
+ r !== null && t.set(r, a.slice(0, -5));
27
+ }
28
+ }
29
+ async function m(n) {
30
+ var e;
31
+ let t;
32
+ try {
33
+ t = await u(n, "utf8");
34
+ } catch {
35
+ return null;
36
+ }
37
+ return ((e = f.exec(t)) == null ? void 0 : e[1]) ?? null;
38
+ }
39
+ export {
40
+ y as buildGuidIndex
41
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "uxml-preview",
3
- "version": "0.2.0",
4
- "description": "Preview Unity UI Toolkit UXML/USS in a browser without the Unity Editor. Uses Yoga (WebAssembly), the same layout engine UI Toolkit uses: 242 of 244 element coordinates identical to Unity 6. Parses and writes files back byte-for-byte.",
3
+ "version": "0.4.0",
4
+ "description": "Preview Unity UI Toolkit UXML/USS in a browser without the Unity Editor. Uses Yoga (WebAssembly), the same layout engine UI Toolkit uses: 660 of 676 element coordinates identical to Unity 6. Parses and writes files back byte-for-byte.",
5
5
  "keywords": [
6
6
  "unity",
7
7
  "unity3d",
@@ -31,6 +31,10 @@
31
31
  ".": {
32
32
  "types": "./dist/index.d.ts",
33
33
  "import": "./dist/index.js"
34
+ },
35
+ "./unity-project": {
36
+ "types": "./dist/unity-project/index.d.ts",
37
+ "import": "./dist/unity-project/index.js"
34
38
  }
35
39
  },
36
40
  "files": [