ntk 7.7.0 → 8.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 +9 -10
- package/lib/app.js +4 -0
- package/lib/fontconfig.js +185 -61
- package/lib/index.js +2 -29
- package/lib/renderingcontext_2d.js +583 -19
- package/lib/shadow.js +199 -0
- package/lib/text/fontsource.js +47 -3
- package/lib/text/layout.js +4 -4
- package/lib/widgets/svgview.js +14 -16
- package/package.json +4 -9
- package/lib/widgets/css.js +0 -673
- package/lib/widgets/highlight.js +0 -97
- package/lib/widgets/htmlview.js +0 -893
- package/lib/widgets/markdown.js +0 -148
- package/lib/widgets/markdownview.js +0 -492
- package/lib/widgets/tex.js +0 -679
- package/lib/yoga.js +0 -119
package/lib/yoga.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// The layout engine, without a top-level await.
|
|
2
|
-
//
|
|
3
|
-
// `yoga-layout`'s default entry is `const Yoga = wrapAssembly(await
|
|
4
|
-
// loadYoga())`. That one `await` is contagious: every bundle containing ntk
|
|
5
|
-
// inherits it, esbuild then refuses to emit CommonJS ("Top-level await is
|
|
6
|
-
// currently not supported with the cjs output format"), and Node's single
|
|
7
|
-
// executable format runs its embedded main as CommonJS — so an ntk app could
|
|
8
|
-
// not be shipped as one binary at all.
|
|
9
|
-
//
|
|
10
|
-
// So ntk imports the half of the package that has no WASM in it —
|
|
11
|
-
// `yoga-layout/load` exports the enums as plain JavaScript and the assembly
|
|
12
|
-
// behind an async function — and loads the assembly during `createClient()`,
|
|
13
|
-
// which is already asynchronous.
|
|
14
|
-
//
|
|
15
|
-
// The object exported here keeps yoga's own shape, and that is the point:
|
|
16
|
-
// the flat SCREAMING_CASE constants are present from the first tick, so a
|
|
17
|
-
// consumer that builds a lookup table at module scope (ntk's own HtmlView,
|
|
18
|
-
// react-x11's styles.js) still reads them at import time. `Node`, `Config`
|
|
19
|
-
// and the rest of the assembly appear when `loadLayout()` resolves.
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
loadYoga,
|
|
23
|
-
Align,
|
|
24
|
-
BoxSizing,
|
|
25
|
-
Dimension,
|
|
26
|
-
Direction,
|
|
27
|
-
Display,
|
|
28
|
-
Edge,
|
|
29
|
-
Errata,
|
|
30
|
-
ExperimentalFeature,
|
|
31
|
-
FlexDirection,
|
|
32
|
-
Gutter,
|
|
33
|
-
Justify,
|
|
34
|
-
LogLevel,
|
|
35
|
-
MeasureMode,
|
|
36
|
-
NodeType,
|
|
37
|
-
Overflow,
|
|
38
|
-
PositionType,
|
|
39
|
-
Unit,
|
|
40
|
-
Wrap
|
|
41
|
-
} from 'yoga-layout/load';
|
|
42
|
-
|
|
43
|
-
const ENUMS = {
|
|
44
|
-
Align,
|
|
45
|
-
BoxSizing,
|
|
46
|
-
Dimension,
|
|
47
|
-
Direction,
|
|
48
|
-
Display,
|
|
49
|
-
Edge,
|
|
50
|
-
Errata,
|
|
51
|
-
ExperimentalFeature,
|
|
52
|
-
FlexDirection,
|
|
53
|
-
Gutter,
|
|
54
|
-
Justify,
|
|
55
|
-
LogLevel,
|
|
56
|
-
MeasureMode,
|
|
57
|
-
NodeType,
|
|
58
|
-
Overflow,
|
|
59
|
-
PositionType,
|
|
60
|
-
Unit,
|
|
61
|
-
Wrap
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// yoga's generator names each constant <ENUM>_<MEMBER>, both snake-cased from
|
|
65
|
-
// PascalCase: FlexDirection.ColumnReverse -> FLEX_DIRECTION_COLUMN_REVERSE.
|
|
66
|
-
// yoga-export.test.js pins every name against the real assembly, so a rename
|
|
67
|
-
// upstream fails loudly instead of yielding an undefined constant.
|
|
68
|
-
const screamingSnake = (name) => name.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toUpperCase();
|
|
69
|
-
|
|
70
|
-
/** The layout engine: enums now, assembly after `loadLayout()`. */
|
|
71
|
-
const Yoga = {};
|
|
72
|
-
for (const [enumName, members] of Object.entries(ENUMS)) {
|
|
73
|
-
// a bundler may stub yoga out entirely — the browser playground does,
|
|
74
|
-
// since no demo uses HtmlView — and importing ntk must still work
|
|
75
|
-
if (!members || typeof members !== 'object') continue;
|
|
76
|
-
const prefix = screamingSnake(enumName);
|
|
77
|
-
for (const [member, value] of Object.entries(members)) {
|
|
78
|
-
if (typeof value === 'number') Yoga[`${prefix}_${screamingSnake(member)}`] = value;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const notLoaded = (what) => () => {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`ntk: the layout engine is not loaded, so Yoga.${what} is not available yet. ` +
|
|
85
|
-
'createClient() loads it; widgets used without an App need `await loadLayout()` first.'
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// A useful message instead of "Cannot read properties of undefined"
|
|
90
|
-
for (const name of ['Node', 'Config']) {
|
|
91
|
-
Object.defineProperty(Yoga, name, { configurable: true, get: notLoaded(name) });
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let loading = null;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Load the layout engine's WebAssembly. Idempotent, and resolves with the
|
|
98
|
-
* same `Yoga` object this module exports — `createClient()` awaits it, so
|
|
99
|
-
* applications rarely call it themselves. Widgets used without an App
|
|
100
|
-
* (`new HtmlView(null, …)`) need it.
|
|
101
|
-
*/
|
|
102
|
-
export function loadLayout() {
|
|
103
|
-
if (!loading) {
|
|
104
|
-
loading = loadYoga().then((assembly) => {
|
|
105
|
-
for (const name of ['Node', 'Config']) delete Yoga[name]; // drop the throwing getters
|
|
106
|
-
Object.assign(Yoga, assembly);
|
|
107
|
-
return Yoga;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return loading;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Whether the assembly is in place — layout will not throw. */
|
|
114
|
-
export function layoutLoaded() {
|
|
115
|
-
return Object.getOwnPropertyDescriptor(Yoga, 'Node')?.value !== undefined;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export { Yoga };
|
|
119
|
-
export default Yoga;
|