uxml-preview 0.6.1 → 0.7.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/CHANGELOG.md +250 -0
- package/README.ja.md +7 -2
- package/README.ko.md +7 -2
- package/README.md +7 -2
- package/README.zh-CN.md +7 -2
- package/dist/controls/registry.d.ts +34 -6
- package/dist/controls/theme.d.ts +52 -76
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2715 -1905
- package/dist/known-divergences.d.ts +2 -2
- package/dist/layout/yoga.d.ts +12 -3
- package/dist/render/fonts.d.ts +2 -1
- package/dist/render/measure.d.ts +9 -1
- package/dist/render/paint.d.ts +3 -0
- package/dist/style/resolve.d.ts +5 -0
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Differences from Unity that measurement has confirmed and that fixing the
|
|
3
|
-
* renderer cannot close. `docs/accuracy.md` describes
|
|
3
|
+
* renderer cannot close. `docs/accuracy.md` describes 14 divergent values;
|
|
4
4
|
* all but one class of them are listed below.
|
|
5
5
|
*
|
|
6
|
-
* The 1px cases (
|
|
6
|
+
* The 1px cases (2 values) are excluded on purpose: they sit inside the
|
|
7
7
|
* golden tests' own 0.5px-tighter-than-plan tolerance. That is a test
|
|
8
8
|
* judgement parameter, not a rendering limitation — listing it here would
|
|
9
9
|
* tell a host to worry about a difference the renderer did not actually make.
|
package/dist/layout/yoga.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ElementNode, NodeId, Warning } from '../model/types';
|
|
2
2
|
import { ComputedStyle, DeclarationLocator } from '../style/resolve';
|
|
3
|
+
import { Theme } from '../controls/theme';
|
|
3
4
|
import { FaceInfo } from '../render/measure';
|
|
4
5
|
/**
|
|
5
6
|
* Purpose: load the Yoga WebAssembly module.
|
|
@@ -36,6 +37,8 @@ export interface TextContext {
|
|
|
36
37
|
}
|
|
37
38
|
export type MeasureText = (text: string, context: TextContext, availableWidth: number) => TextMetrics;
|
|
38
39
|
export interface LayoutOptions {
|
|
40
|
+
/** Built-in theme; defaults to 'runtime'. */
|
|
41
|
+
theme?: Theme;
|
|
39
42
|
fonts?: ReadonlyMap<ComputedStyle, {
|
|
40
43
|
family: string;
|
|
41
44
|
faceInfo?: FaceInfo;
|
|
@@ -68,8 +71,12 @@ export interface LayoutPart {
|
|
|
68
71
|
name: string;
|
|
69
72
|
/** The element whose control built it. */
|
|
70
73
|
owner: NodeId;
|
|
74
|
+
/** Index in this owner’s laid-out parts, null for the owner itself. */
|
|
75
|
+
parent?: number | null;
|
|
76
|
+
/** Present for a measured text leaf; wrappers omit it. Text is entity-decoded. */
|
|
77
|
+
text?: string;
|
|
71
78
|
box: LayoutBox;
|
|
72
|
-
/**
|
|
79
|
+
/** Cascade output, including inheritance, theme and author rules. */
|
|
73
80
|
style: ComputedStyle;
|
|
74
81
|
}
|
|
75
82
|
export interface LayoutTree {
|
|
@@ -77,7 +84,7 @@ export interface LayoutTree {
|
|
|
77
84
|
boxes: ReadonlyMap<NodeId, LayoutBox>;
|
|
78
85
|
/**
|
|
79
86
|
* Parts each element's control built, outermost first. The element's own
|
|
80
|
-
* children were laid out inside the last
|
|
87
|
+
* children were laid out inside the last wrapper; text parts are leading siblings.
|
|
81
88
|
*/
|
|
82
89
|
parts: ReadonlyMap<NodeId, readonly LayoutPart[]>;
|
|
83
90
|
/** Elements that were laid out, parents before children. */
|
|
@@ -92,7 +99,9 @@ export interface LayoutTree {
|
|
|
92
99
|
/**
|
|
93
100
|
* Purpose: build a Yoga tree, compute layout, hand back boxes in panel
|
|
94
101
|
* coordinates.
|
|
95
|
-
* Deps/Effects:
|
|
102
|
+
* Deps/Effects: owns created Yoga nodes until returning the tree, which owns
|
|
103
|
+
* them until disposed; on any failure frees all roots and rethrows.
|
|
104
|
+
* Calls host measureText and appends measurement warnings.
|
|
96
105
|
* Requires: `loadLayoutEngine()` must have resolved.
|
|
97
106
|
*/
|
|
98
107
|
export declare function layoutDocument(root: ElementNode, styles: ReadonlyMap<NodeId, ComputedStyle>,
|
package/dist/render/fonts.d.ts
CHANGED
|
@@ -10,12 +10,13 @@ export type ResolveFont = (path: string, form: 'url' | 'resource') => string | R
|
|
|
10
10
|
* Purpose: resolve font assets for measurement and painting, applying Unity's
|
|
11
11
|
* documented but unmeasured -unity-font-definition precedence.
|
|
12
12
|
* Deps/Effects: calls the host hook once per distinct (path, form) per invocation.
|
|
13
|
+
* Element and part styles share the cache and declaration warnings.
|
|
13
14
|
* Ensures: filters only not-rendered property warnings for processed font
|
|
14
15
|
* declarations, keyed by property, source document and offset
|
|
15
16
|
* (or node when no offset exists). Unresolved assets replace those
|
|
16
17
|
* warnings with one asset-unresolved warning per declaration.
|
|
17
18
|
*/
|
|
18
|
-
export declare function resolveFonts(styles: ReadonlyMap<NodeId, ComputedStyle>, warnings: readonly Warning[], locate: DeclarationLocator, resolve?: ResolveFont): {
|
|
19
|
+
export declare function resolveFonts(styles: ReadonlyMap<NodeId, ComputedStyle>, warnings: readonly Warning[], locate: DeclarationLocator, resolve?: ResolveFont, partStyles?: ReadonlyMap<NodeId, ReadonlyMap<string, ComputedStyle>>): {
|
|
19
20
|
fonts: Map<ComputedStyle, ResolvedFont>;
|
|
20
21
|
warnings: Warning[];
|
|
21
22
|
};
|
package/dist/render/measure.d.ts
CHANGED
|
@@ -6,8 +6,16 @@ export interface FaceInfo {
|
|
|
6
6
|
lineHeight?: number;
|
|
7
7
|
}
|
|
8
8
|
export declare const EDITOR_DEFAULT_FACE_INFO: FaceInfo;
|
|
9
|
-
export declare function textHeight(lines: number, fontSize: number, face: FaceInfo, paragraphBreaks?: number, paragraphSpacing?: number): number;
|
|
9
|
+
export declare function textHeight(lines: number, fontSize: number, face: FaceInfo, paragraphBreaks?: number, paragraphSpacing?: number, generator?: 'standard' | 'advanced'): number;
|
|
10
10
|
export declare function fontList(family?: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Purpose: share the canvas-derived host face between measurement and painting.
|
|
13
|
+
* Deps/Effects: probes current canvas font metrics on every call so asynchronously loaded
|
|
14
|
+
* fonts are reflected; sets the supplied context's font or creates a canvas.
|
|
15
|
+
* Ensures: missing canvas metrics retain the editor fallback.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hostFontFace(doc: Document | undefined, family: string, fontStyle?: string, context?: CanvasRenderingContext2D | null): FaceInfo;
|
|
18
|
+
export declare const CJK_BREAK: RegExp;
|
|
11
19
|
/**
|
|
12
20
|
* Purpose: measure text with a canvas when one is available.
|
|
13
21
|
* Deps/Effects: creates one offscreen canvas and reuses it.
|
package/dist/render/paint.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Theme } from '../controls/theme';
|
|
1
2
|
import { FaceInfo } from './measure';
|
|
2
3
|
import { ElementNode, NodeId, Warning } from '../model/types';
|
|
3
4
|
import { ComputedStyle } from '../style/resolve';
|
|
@@ -23,6 +24,8 @@ export interface PaintResult {
|
|
|
23
24
|
}
|
|
24
25
|
export interface PaintOptions extends CssMapOptions {
|
|
25
26
|
document: Document;
|
|
27
|
+
checkedNodes?: ReadonlySet<NodeId>;
|
|
28
|
+
theme?: Theme;
|
|
26
29
|
fonts?: ReadonlyMap<ComputedStyle, {
|
|
27
30
|
family: string;
|
|
28
31
|
faceInfo?: FaceInfo;
|
package/dist/style/resolve.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ElementNode, NodeId, StyleOrigin, UxmlDocument, Warning } from '../model/types';
|
|
2
|
+
import { Theme } from '../controls/theme';
|
|
2
3
|
import { Specificity } from './specificity';
|
|
3
4
|
export interface ComputedValue {
|
|
4
5
|
/** `var()` already substituted. Otherwise exactly as the author wrote it. */
|
|
@@ -7,6 +8,8 @@ export interface ComputedValue {
|
|
|
7
8
|
}
|
|
8
9
|
export type ComputedStyle = ReadonlyMap<string, ComputedValue>;
|
|
9
10
|
export interface ResolveOptions {
|
|
11
|
+
/** Built-in theme; defaults to 'runtime'. */
|
|
12
|
+
theme?: Theme;
|
|
10
13
|
/**
|
|
11
14
|
* Pseudo-classes to treat as active on every element, e.g. `new Set(['hover'])`.
|
|
12
15
|
*
|
|
@@ -30,6 +33,8 @@ export interface ResolveOptions {
|
|
|
30
33
|
states?: Readonly<Record<string, readonly string[]>>;
|
|
31
34
|
}
|
|
32
35
|
export interface ResolveResult {
|
|
36
|
+
/** @internal Resolved Checked bits shared by styling and the substitute check glyph. */
|
|
37
|
+
checkedNodes: ReadonlySet<NodeId>;
|
|
33
38
|
/** @internal Element matches collected during this cascade, keyed by sheet and item. */
|
|
34
39
|
matchedNodes: ReadonlyMap<string, readonly NodeId[]>;
|
|
35
40
|
styles: ReadonlyMap<NodeId, ComputedStyle>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uxml-preview",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Render Unity UI Toolkit UXML/USS in a browser without the Unity Editor. Laid out by Yoga, the engine UI Toolkit uses; reference Unity 6.3 LTS, measured against real Unity. Byte-exact round trips.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unity",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"test": "vitest run",
|
|
68
68
|
"test:watch": "vitest",
|
|
69
69
|
"test:roundtrip": "vitest run tests/roundtrip",
|
|
70
|
-
"test:text": "node tests/text-cohort/run.mjs && node tests/text-cohort/paint.mjs",
|
|
70
|
+
"test:text": "node tests/text-cohort/run.mjs && node tests/text-cohort/paint.mjs && node tests/text-cohort/paint-r15.mjs && node tests/text-cohort/measure-real.mjs",
|
|
71
71
|
"test:golden": "vitest run tests/golden --passWithNoTests",
|
|
72
72
|
"golden:emit": "node --experimental-strip-types --no-warnings scripts/emit-golden-cases.mjs",
|
|
73
73
|
"template:emit": "node --experimental-strip-types --no-warnings scripts/emit-template-cases.mjs",
|