ink 3.2.0 → 4.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/build/colorize.d.ts +3 -3
- package/build/colorize.js +30 -35
- package/build/colorize.js.map +1 -1
- package/build/components/App.d.ts +12 -12
- package/build/components/App.js +287 -208
- package/build/components/App.js.map +1 -1
- package/build/components/AppContext.d.ts +2 -2
- package/build/components/AppContext.js +5 -6
- package/build/components/AppContext.js.map +1 -1
- package/build/components/Box.d.ts +77 -5
- package/build/components/Box.js +20 -38
- package/build/components/Box.js.map +1 -1
- package/build/components/ErrorOverview.d.ts +5 -5
- package/build/components/ErrorOverview.js +40 -58
- package/build/components/ErrorOverview.js.map +1 -1
- package/build/components/FocusContext.d.ts +2 -2
- package/build/components/FocusContext.js +13 -14
- package/build/components/FocusContext.js.map +1 -1
- package/build/components/Newline.d.ts +4 -5
- package/build/components/Newline.js +4 -9
- package/build/components/Newline.js.map +1 -1
- package/build/components/Spacer.d.ts +2 -3
- package/build/components/Spacer.js +5 -10
- package/build/components/Spacer.js.map +1 -1
- package/build/components/Static.d.ts +5 -9
- package/build/components/Static.js +12 -33
- package/build/components/Static.js.map +1 -1
- package/build/components/StderrContext.d.ts +4 -4
- package/build/components/StderrContext.js +7 -7
- package/build/components/StderrContext.js.map +1 -1
- package/build/components/StdinContext.d.ts +4 -4
- package/build/components/StdinContext.js +8 -7
- package/build/components/StdinContext.js.map +1 -1
- package/build/components/StdoutContext.d.ts +4 -4
- package/build/components/StdoutContext.js +7 -7
- package/build/components/StdoutContext.js.map +1 -1
- package/build/components/Text.d.ts +9 -10
- package/build/components/Text.js +14 -29
- package/build/components/Text.js.map +1 -1
- package/build/components/Transform.d.ts +4 -5
- package/build/components/Transform.js +4 -11
- package/build/components/Transform.js.map +1 -1
- package/build/devtools-window-polyfill.js +3 -8
- package/build/devtools-window-polyfill.js.map +1 -1
- package/build/devtools.d.ts +1 -1
- package/build/devtools.js +6 -6
- package/build/devtools.js.map +1 -1
- package/build/dom.d.ts +17 -20
- package/build/dom.js +35 -47
- package/build/dom.js.map +1 -1
- package/build/get-max-width.d.ts +3 -3
- package/build/get-max-width.js +8 -11
- package/build/get-max-width.js.map +1 -1
- package/build/hooks/use-app.d.ts +1 -1
- package/build/hooks/use-app.js +4 -9
- package/build/hooks/use-app.js.map +1 -1
- package/build/hooks/use-focus-manager.d.ts +3 -3
- package/build/hooks/use-focus-manager.js +4 -9
- package/build/hooks/use-focus-manager.js.map +1 -1
- package/build/hooks/use-focus.d.ts +4 -4
- package/build/hooks/use-focus.js +11 -16
- package/build/hooks/use-focus.js.map +1 -1
- package/build/hooks/use-input.d.ts +5 -5
- package/build/hooks/use-input.js +13 -14
- package/build/hooks/use-input.js.map +1 -1
- package/build/hooks/use-stderr.d.ts +1 -1
- package/build/hooks/use-stderr.js +4 -9
- package/build/hooks/use-stderr.js.map +1 -1
- package/build/hooks/use-stdin.d.ts +1 -1
- package/build/hooks/use-stdin.js +4 -9
- package/build/hooks/use-stdin.js.map +1 -1
- package/build/hooks/use-stdout.d.ts +1 -1
- package/build/hooks/use-stdout.js +4 -9
- package/build/hooks/use-stdout.js.map +1 -1
- package/build/index.d.ts +27 -20
- package/build/index.js +15 -32
- package/build/index.js.map +1 -1
- package/build/ink.d.ts +6 -4
- package/build/ink.js +188 -99
- package/build/ink.js.map +1 -1
- package/build/instances.d.ts +4 -2
- package/build/instances.js +2 -3
- package/build/instances.js.map +1 -1
- package/build/log-update.d.ts +5 -6
- package/build/log-update.js +8 -12
- package/build/log-update.js.map +1 -1
- package/build/measure-element.d.ts +5 -5
- package/build/measure-element.js +5 -9
- package/build/measure-element.js.map +1 -1
- package/build/measure-text.d.ts +4 -4
- package/build/measure-text.js +7 -10
- package/build/measure-text.js.map +1 -1
- package/build/output.d.ts +12 -4
- package/build/output.js +108 -31
- package/build/output.js.map +1 -1
- package/build/reconciler.d.ts +1 -1
- package/build/reconciler.js +104 -76
- package/build/reconciler.js.map +1 -1
- package/build/render-border.d.ts +4 -4
- package/build/render-border.js +8 -12
- package/build/render-border.js.map +1 -1
- package/build/render-node-to-output.d.ts +3 -3
- package/build/render-node-to-output.js +44 -24
- package/build/render-node-to-output.js.map +1 -1
- package/build/render.d.ts +8 -8
- package/build/render.js +23 -20
- package/build/render.js.map +1 -1
- package/build/renderer.d.ts +5 -5
- package/build/renderer.js +9 -17
- package/build/renderer.js.map +1 -1
- package/build/squash-text-nodes.d.ts +1 -1
- package/build/squash-text-nodes.js +1 -3
- package/build/squash-text-nodes.js.map +1 -1
- package/build/styles.d.ts +30 -9
- package/build/styles.js +60 -46
- package/build/styles.js.map +1 -1
- package/build/wrap-text.d.ts +3 -3
- package/build/wrap-text.js +9 -12
- package/build/wrap-text.js.map +1 -1
- package/license +1 -1
- package/package.json +87 -67
- package/readme.md +202 -57
package/build/output.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OutputTransformer } from './render-node-to-output';
|
|
1
|
+
import { type OutputTransformer } from './render-node-to-output.js';
|
|
2
2
|
/**
|
|
3
3
|
* "Virtual" output class
|
|
4
4
|
*
|
|
@@ -7,18 +7,26 @@ import { OutputTransformer } from './render-node-to-output';
|
|
|
7
7
|
*
|
|
8
8
|
* Used to generate the final output of all nodes before writing it to actual output stream (e.g. stdout)
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
type Options = {
|
|
11
11
|
width: number;
|
|
12
12
|
height: number;
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
|
+
type Clip = {
|
|
15
|
+
x1: number | undefined;
|
|
16
|
+
x2: number | undefined;
|
|
17
|
+
y1: number | undefined;
|
|
18
|
+
y2: number | undefined;
|
|
19
|
+
};
|
|
14
20
|
export default class Output {
|
|
15
21
|
width: number;
|
|
16
22
|
height: number;
|
|
17
|
-
private readonly
|
|
23
|
+
private readonly operations;
|
|
18
24
|
constructor(options: Options);
|
|
19
25
|
write(x: number, y: number, text: string, options: {
|
|
20
26
|
transformers: OutputTransformer[];
|
|
21
27
|
}): void;
|
|
28
|
+
clip(clip: Clip): void;
|
|
29
|
+
unclip(): void;
|
|
22
30
|
get(): {
|
|
23
31
|
output: string;
|
|
24
32
|
height: number;
|
package/build/output.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const slice_ansi_1 = __importDefault(require("slice-ansi"));
|
|
7
|
-
const string_width_1 = __importDefault(require("string-width"));
|
|
8
|
-
class Output {
|
|
1
|
+
import sliceAnsi from 'slice-ansi';
|
|
2
|
+
import stringWidth from 'string-width';
|
|
3
|
+
import widestLine from 'widest-line';
|
|
4
|
+
export default class Output {
|
|
9
5
|
constructor(options) {
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
Object.defineProperty(this, "width", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: void 0
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "height", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "operations", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: []
|
|
23
|
+
});
|
|
12
24
|
const { width, height } = options;
|
|
13
25
|
this.width = width;
|
|
14
26
|
this.height = height;
|
|
@@ -18,41 +30,106 @@ class Output {
|
|
|
18
30
|
if (!text) {
|
|
19
31
|
return;
|
|
20
32
|
}
|
|
21
|
-
this.
|
|
33
|
+
this.operations.push({
|
|
34
|
+
type: 'write',
|
|
35
|
+
x,
|
|
36
|
+
y,
|
|
37
|
+
text,
|
|
38
|
+
transformers
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
clip(clip) {
|
|
42
|
+
this.operations.push({
|
|
43
|
+
type: 'clip',
|
|
44
|
+
clip
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
unclip() {
|
|
48
|
+
this.operations.push({
|
|
49
|
+
type: 'unclip'
|
|
50
|
+
});
|
|
22
51
|
}
|
|
23
52
|
get() {
|
|
53
|
+
// Initialize output array with a specific set of rows, so that margin/padding at the bottom is preserved
|
|
24
54
|
const output = [];
|
|
25
55
|
for (let y = 0; y < this.height; y++) {
|
|
26
56
|
output.push(' '.repeat(this.width));
|
|
27
57
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
const clips = [];
|
|
59
|
+
for (const operation of this.operations) {
|
|
60
|
+
if (operation.type === 'clip') {
|
|
61
|
+
clips.push(operation.clip);
|
|
62
|
+
}
|
|
63
|
+
if (operation.type === 'unclip') {
|
|
64
|
+
clips.pop();
|
|
65
|
+
}
|
|
66
|
+
if (operation.type === 'write') {
|
|
67
|
+
const { text, transformers } = operation;
|
|
68
|
+
let { x, y } = operation;
|
|
69
|
+
let lines = text.split('\n');
|
|
70
|
+
const clip = clips[clips.length - 1];
|
|
71
|
+
if (clip) {
|
|
72
|
+
const clipHorizontally = typeof clip?.x1 === 'number' && typeof clip?.x2 === 'number';
|
|
73
|
+
const clipVertically = typeof clip?.y1 === 'number' && typeof clip?.y2 === 'number';
|
|
74
|
+
// If text is positioned outside of clipping area altogether,
|
|
75
|
+
// skip to the next operation to avoid unnecessary calculations
|
|
76
|
+
if (clipHorizontally) {
|
|
77
|
+
const width = widestLine(text);
|
|
78
|
+
if (x + width < clip.x1 || x > clip.x2) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (clipVertically) {
|
|
83
|
+
const height = lines.length;
|
|
84
|
+
if (y + height < clip.y1 || y > clip.y2) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (clipHorizontally) {
|
|
89
|
+
lines = lines.map(line => {
|
|
90
|
+
const from = x < clip.x1 ? clip.x1 - x : 0;
|
|
91
|
+
const width = stringWidth(line);
|
|
92
|
+
const to = x + width > clip.x2 ? clip.x2 - x : width;
|
|
93
|
+
return sliceAnsi(line, from, to);
|
|
94
|
+
});
|
|
95
|
+
if (x < clip.x1) {
|
|
96
|
+
x = clip.x1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (clipVertically) {
|
|
100
|
+
const from = y < clip.y1 ? clip.y1 - y : 0;
|
|
101
|
+
const height = lines.length;
|
|
102
|
+
const to = y + height > clip.y2 ? clip.y2 - y : height;
|
|
103
|
+
lines = lines.slice(from, to);
|
|
104
|
+
if (y < clip.y1) {
|
|
105
|
+
y = clip.y1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
37
108
|
}
|
|
38
|
-
|
|
39
|
-
for (
|
|
40
|
-
|
|
109
|
+
let offsetY = 0;
|
|
110
|
+
for (let line of lines) {
|
|
111
|
+
const currentLine = output[y + offsetY];
|
|
112
|
+
// Line can be missing if `text` is taller than height of pre-initialized `this.output`
|
|
113
|
+
if (!currentLine) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const width = stringWidth(line);
|
|
117
|
+
for (const transformer of transformers) {
|
|
118
|
+
line = transformer(line);
|
|
119
|
+
}
|
|
120
|
+
output[y + offsetY] =
|
|
121
|
+
sliceAnsi(currentLine, 0, x) +
|
|
122
|
+
line +
|
|
123
|
+
sliceAnsi(currentLine, x + width);
|
|
124
|
+
offsetY++;
|
|
41
125
|
}
|
|
42
|
-
output[y + offsetY] =
|
|
43
|
-
slice_ansi_1.default(currentLine, 0, x) +
|
|
44
|
-
line +
|
|
45
|
-
slice_ansi_1.default(currentLine, x + width);
|
|
46
|
-
offsetY++;
|
|
47
126
|
}
|
|
48
127
|
}
|
|
49
|
-
|
|
50
|
-
const generatedOutput = output.map(line => line.trimRight()).join('\n');
|
|
128
|
+
const generatedOutput = output.map(line => line.trimEnd()).join('\n');
|
|
51
129
|
return {
|
|
52
130
|
output: generatedOutput,
|
|
53
131
|
height: output.length
|
|
54
132
|
};
|
|
55
133
|
}
|
|
56
134
|
}
|
|
57
|
-
exports.default = Output;
|
|
58
135
|
//# sourceMappingURL=output.js.map
|
package/build/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,UAAU,MAAM,aAAa,CAAC;AA2CrC,MAAM,CAAC,OAAO,OAAO,MAAM;IAM1B,YAAY,OAAgB;QAL5B;;;;;WAAc;QACd;;;;;WAAe;QAEf;;;;mBAA2C,EAAE;WAAC;QAG7C,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC;QAEhC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,KAAK,CACJ,CAAS,EACT,CAAS,EACT,IAAY,EACZ,OAA4C;QAE5C,MAAM,EAAC,YAAY,EAAC,GAAG,OAAO,CAAC;QAE/B,IAAI,CAAC,IAAI,EAAE;YACV,OAAO;SACP;QAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACpB,IAAI,EAAE,OAAO;YACb,CAAC;YACD,CAAC;YACD,IAAI;YACJ,YAAY;SACZ,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,IAAU;QACd,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACpB,IAAI,EAAE,MAAM;YACZ,IAAI;SACJ,CAAC,CAAC;IACJ,CAAC;IAED,MAAM;QACL,IA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
1
|
import createReconciler from 'react-reconciler';
|
|
2
|
-
import { TextNode, DOMElement } from './dom';
|
|
2
|
+
import { type TextNode, type DOMElement } from './dom.js';
|
|
3
3
|
declare const _default: createReconciler.Reconciler<DOMElement, DOMElement, TextNode, DOMElement, unknown>;
|
|
4
4
|
export default _default;
|
package/build/reconciler.js
CHANGED
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const react_reconciler_1 = __importDefault(require("react-reconciler"));
|
|
8
|
-
const yoga_layout_prebuilt_1 = __importDefault(require("yoga-layout-prebuilt"));
|
|
9
|
-
const dom_1 = require("./dom");
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import createReconciler from 'react-reconciler';
|
|
3
|
+
import { DefaultEventPriority } from 'react-reconciler/constants.js';
|
|
4
|
+
// eslint-disable-next-line n/file-extension-in-import
|
|
5
|
+
import Yoga from 'yoga-wasm-web/auto';
|
|
6
|
+
import { createTextNode, appendChildNode, insertBeforeNode, removeChildNode, setStyle, setTextNodeValue, createNode, setAttribute } from './dom.js';
|
|
10
7
|
// We need to conditionally perform devtools connection to avoid
|
|
11
8
|
// accidentally breaking other third-party code.
|
|
12
9
|
// See https://github.com/vadimdemedes/ink/issues/384
|
|
13
|
-
if (process.env
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
if (process.env['DEV'] === 'true') {
|
|
11
|
+
try {
|
|
12
|
+
await import('./devtools.js');
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
17
|
+
console.warn(`
|
|
18
|
+
Debugging with React Devtools requires \`react-devtools-core\` dependency to be installed.
|
|
19
|
+
|
|
20
|
+
$ npm install --save-dev react-devtools-core
|
|
21
|
+
`.trim() + '\n');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
const cleanupYogaNode = (node) => {
|
|
18
|
-
node
|
|
19
|
-
node
|
|
30
|
+
node?.unsetMeasureFunc();
|
|
31
|
+
node?.freeRecursive();
|
|
20
32
|
};
|
|
21
|
-
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
schedulePassiveEffects: scheduler_1.unstable_scheduleCallback,
|
|
24
|
-
cancelPassiveEffects: scheduler_1.unstable_cancelCallback,
|
|
25
|
-
now: Date.now,
|
|
33
|
+
export default createReconciler({
|
|
26
34
|
getRootHostContext: () => ({
|
|
27
35
|
isInsideText: false
|
|
28
36
|
}),
|
|
29
37
|
prepareForCommit: () => null,
|
|
30
38
|
preparePortalMount: () => null,
|
|
31
39
|
clearContainer: () => false,
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
resetAfterCommit(rootNode) {
|
|
41
|
+
if (typeof rootNode.onComputeLayout === 'function') {
|
|
42
|
+
rootNode.onComputeLayout();
|
|
43
|
+
}
|
|
34
44
|
// Since renders are throttled at the instance level and <Static> component children
|
|
35
45
|
// are rendered only once and then get deleted, we need an escape hatch to
|
|
36
46
|
// trigger an immediate render to ensure <Static> children are written to output before they get erased
|
|
@@ -45,7 +55,7 @@ exports.default = react_reconciler_1.default({
|
|
|
45
55
|
rootNode.onRender();
|
|
46
56
|
}
|
|
47
57
|
},
|
|
48
|
-
getChildHostContext
|
|
58
|
+
getChildHostContext(parentHostContext, type) {
|
|
49
59
|
const previousIsInsideText = parentHostContext.isInsideText;
|
|
50
60
|
const isInsideText = type === 'ink-text' || type === 'ink-virtual-text';
|
|
51
61
|
if (previousIsInsideText === isInsideText) {
|
|
@@ -54,59 +64,58 @@ exports.default = react_reconciler_1.default({
|
|
|
54
64
|
return { isInsideText };
|
|
55
65
|
},
|
|
56
66
|
shouldSetTextContent: () => false,
|
|
57
|
-
createInstance
|
|
67
|
+
createInstance(originalType, newProps, _root, hostContext) {
|
|
58
68
|
if (hostContext.isInsideText && originalType === 'ink-box') {
|
|
59
69
|
throw new Error(`<Box> can’t be nested inside <Text> component`);
|
|
60
70
|
}
|
|
61
71
|
const type = originalType === 'ink-text' && hostContext.isInsideText
|
|
62
72
|
? 'ink-virtual-text'
|
|
63
73
|
: originalType;
|
|
64
|
-
const node =
|
|
74
|
+
const node = createNode(type);
|
|
65
75
|
for (const [key, value] of Object.entries(newProps)) {
|
|
66
76
|
if (key === 'children') {
|
|
67
77
|
continue;
|
|
68
78
|
}
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
if (key === 'style') {
|
|
80
|
+
setStyle(node, value);
|
|
81
|
+
continue;
|
|
71
82
|
}
|
|
72
|
-
|
|
83
|
+
if (key === 'internal_transform') {
|
|
73
84
|
node.internal_transform = value;
|
|
85
|
+
continue;
|
|
74
86
|
}
|
|
75
|
-
|
|
87
|
+
if (key === 'internal_static') {
|
|
76
88
|
node.internal_static = true;
|
|
89
|
+
continue;
|
|
77
90
|
}
|
|
78
|
-
|
|
79
|
-
dom_1.setAttribute(node, key, value);
|
|
80
|
-
}
|
|
91
|
+
setAttribute(node, key, value);
|
|
81
92
|
}
|
|
82
93
|
return node;
|
|
83
94
|
},
|
|
84
|
-
createTextInstance
|
|
95
|
+
createTextInstance(text, _root, hostContext) {
|
|
85
96
|
if (!hostContext.isInsideText) {
|
|
86
97
|
throw new Error(`Text string "${text}" must be rendered inside <Text> component`);
|
|
87
98
|
}
|
|
88
|
-
return
|
|
99
|
+
return createTextNode(text);
|
|
89
100
|
},
|
|
90
|
-
resetTextContent
|
|
91
|
-
hideTextInstance
|
|
92
|
-
|
|
101
|
+
resetTextContent() { },
|
|
102
|
+
hideTextInstance(node) {
|
|
103
|
+
setTextNodeValue(node, '');
|
|
93
104
|
},
|
|
94
|
-
unhideTextInstance
|
|
95
|
-
|
|
105
|
+
unhideTextInstance(node, text) {
|
|
106
|
+
setTextNodeValue(node, text);
|
|
96
107
|
},
|
|
97
108
|
getPublicInstance: instance => instance,
|
|
98
|
-
hideInstance
|
|
99
|
-
|
|
100
|
-
(_a = node.yogaNode) === null || _a === void 0 ? void 0 : _a.setDisplay(yoga_layout_prebuilt_1.default.DISPLAY_NONE);
|
|
109
|
+
hideInstance(node) {
|
|
110
|
+
node.yogaNode?.setDisplay(Yoga.DISPLAY_NONE);
|
|
101
111
|
},
|
|
102
|
-
unhideInstance
|
|
103
|
-
|
|
104
|
-
(_a = node.yogaNode) === null || _a === void 0 ? void 0 : _a.setDisplay(yoga_layout_prebuilt_1.default.DISPLAY_FLEX);
|
|
112
|
+
unhideInstance(node) {
|
|
113
|
+
node.yogaNode?.setDisplay(Yoga.DISPLAY_FLEX);
|
|
105
114
|
},
|
|
106
|
-
appendInitialChild:
|
|
107
|
-
appendChild:
|
|
108
|
-
insertBefore:
|
|
109
|
-
finalizeInitialChildren
|
|
115
|
+
appendInitialChild: appendChildNode,
|
|
116
|
+
appendChild: appendChildNode,
|
|
117
|
+
insertBefore: insertBeforeNode,
|
|
118
|
+
finalizeInitialChildren(node, _type, _props, rootNode) {
|
|
110
119
|
if (node.internal_static) {
|
|
111
120
|
rootNode.isStaticDirty = true;
|
|
112
121
|
// Save reference to <Static> node to skip traversal of entire
|
|
@@ -115,14 +124,27 @@ exports.default = react_reconciler_1.default({
|
|
|
115
124
|
}
|
|
116
125
|
return false;
|
|
117
126
|
},
|
|
127
|
+
isPrimaryRenderer: true,
|
|
118
128
|
supportsMutation: true,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
supportsPersistence: false,
|
|
130
|
+
supportsHydration: false,
|
|
131
|
+
scheduleTimeout: setTimeout,
|
|
132
|
+
cancelTimeout: clearTimeout,
|
|
133
|
+
noTimeout: -1,
|
|
134
|
+
getCurrentEventPriority: () => DefaultEventPriority,
|
|
135
|
+
beforeActiveInstanceBlur() { },
|
|
136
|
+
afterActiveInstanceBlur() { },
|
|
137
|
+
detachDeletedInstance() { },
|
|
138
|
+
getInstanceFromNode: () => null,
|
|
139
|
+
prepareScopeUpdate() { },
|
|
140
|
+
getInstanceFromScope: () => null,
|
|
141
|
+
appendChildToContainer: appendChildNode,
|
|
142
|
+
insertInContainerBefore: insertBeforeNode,
|
|
143
|
+
removeChildFromContainer(node, removeNode) {
|
|
144
|
+
removeChildNode(node, removeNode);
|
|
123
145
|
cleanupYogaNode(removeNode.yogaNode);
|
|
124
146
|
},
|
|
125
|
-
prepareUpdate
|
|
147
|
+
prepareUpdate(node, _type, oldProps, newProps, rootNode) {
|
|
126
148
|
if (node.internal_static) {
|
|
127
149
|
rootNode.isStaticDirty = true;
|
|
128
150
|
}
|
|
@@ -131,32 +153,37 @@ exports.default = react_reconciler_1.default({
|
|
|
131
153
|
for (const key of keys) {
|
|
132
154
|
if (newProps[key] !== oldProps[key]) {
|
|
133
155
|
const isStyle = key === 'style' &&
|
|
134
|
-
typeof newProps
|
|
135
|
-
typeof oldProps
|
|
156
|
+
typeof newProps['style'] === 'object' &&
|
|
157
|
+
typeof oldProps['style'] === 'object';
|
|
136
158
|
if (isStyle) {
|
|
137
|
-
const newStyle = newProps
|
|
138
|
-
const oldStyle = oldProps
|
|
159
|
+
const newStyle = newProps['style'];
|
|
160
|
+
const oldStyle = oldProps['style'];
|
|
139
161
|
const styleKeys = Object.keys(newStyle);
|
|
140
162
|
for (const styleKey of styleKeys) {
|
|
141
163
|
// Always include `borderColor` and `borderStyle` to ensure border is rendered,
|
|
164
|
+
// and `overflowX` and `overflowY` to ensure content is clipped,
|
|
142
165
|
// otherwise resulting `updatePayload` may not contain them
|
|
143
166
|
// if they weren't changed during this update
|
|
144
167
|
if (styleKey === 'borderStyle' || styleKey === 'borderColor') {
|
|
145
|
-
if (typeof updatePayload
|
|
168
|
+
if (typeof updatePayload['style'] !== 'object') {
|
|
146
169
|
// Linter didn't like `= {} as Style`
|
|
147
170
|
const style = {};
|
|
148
|
-
updatePayload
|
|
171
|
+
updatePayload['style'] = style;
|
|
149
172
|
}
|
|
150
|
-
updatePayload
|
|
151
|
-
|
|
173
|
+
updatePayload['style'].borderStyle =
|
|
174
|
+
newStyle.borderStyle;
|
|
175
|
+
updatePayload['style'].borderColor =
|
|
176
|
+
newStyle.borderColor;
|
|
177
|
+
updatePayload['style'].overflowX = newStyle.overflowX;
|
|
178
|
+
updatePayload['style'].overflowY = newStyle.overflowY;
|
|
152
179
|
}
|
|
153
180
|
if (newStyle[styleKey] !== oldStyle[styleKey]) {
|
|
154
|
-
if (typeof updatePayload
|
|
181
|
+
if (typeof updatePayload['style'] !== 'object') {
|
|
155
182
|
// Linter didn't like `= {} as Style`
|
|
156
183
|
const style = {};
|
|
157
|
-
updatePayload
|
|
184
|
+
updatePayload['style'] = style;
|
|
158
185
|
}
|
|
159
|
-
updatePayload
|
|
186
|
+
updatePayload['style'][styleKey] = newStyle[styleKey];
|
|
160
187
|
}
|
|
161
188
|
}
|
|
162
189
|
continue;
|
|
@@ -166,30 +193,31 @@ exports.default = react_reconciler_1.default({
|
|
|
166
193
|
}
|
|
167
194
|
return updatePayload;
|
|
168
195
|
},
|
|
169
|
-
commitUpdate
|
|
196
|
+
commitUpdate(node, updatePayload) {
|
|
170
197
|
for (const [key, value] of Object.entries(updatePayload)) {
|
|
171
198
|
if (key === 'children') {
|
|
172
199
|
continue;
|
|
173
200
|
}
|
|
174
|
-
|
|
175
|
-
|
|
201
|
+
if (key === 'style') {
|
|
202
|
+
setStyle(node, value);
|
|
203
|
+
continue;
|
|
176
204
|
}
|
|
177
|
-
|
|
205
|
+
if (key === 'internal_transform') {
|
|
178
206
|
node.internal_transform = value;
|
|
207
|
+
continue;
|
|
179
208
|
}
|
|
180
|
-
|
|
209
|
+
if (key === 'internal_static') {
|
|
181
210
|
node.internal_static = true;
|
|
211
|
+
continue;
|
|
182
212
|
}
|
|
183
|
-
|
|
184
|
-
dom_1.setAttribute(node, key, value);
|
|
185
|
-
}
|
|
213
|
+
setAttribute(node, key, value);
|
|
186
214
|
}
|
|
187
215
|
},
|
|
188
|
-
commitTextUpdate
|
|
189
|
-
|
|
216
|
+
commitTextUpdate(node, _oldText, newText) {
|
|
217
|
+
setTextNodeValue(node, newText);
|
|
190
218
|
},
|
|
191
|
-
removeChild
|
|
192
|
-
|
|
219
|
+
removeChild(node, removeNode) {
|
|
220
|
+
removeChildNode(node, removeNode);
|
|
193
221
|
cleanupYogaNode(removeNode.yogaNode);
|
|
194
222
|
}
|
|
195
223
|
});
|
package/build/reconciler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../src/reconciler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../src/reconciler.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AACnE,sDAAsD;AACtD,OAAO,IAA6B,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACN,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,YAAY,EAKZ,MAAM,UAAU,CAAC;AAIlB,gEAAgE;AAChE,gDAAgD;AAChD,qDAAqD;AACrD,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE;IAClC,IAAI;QACH,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QAC9B,oEAAoE;KACpE;IAAC,OAAO,KAAU,EAAE;QACpB,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB,EAAE;YACtC,OAAO,CAAC,IAAI,CACX;;;;KAIC,CAAC,IAAI,EAAE,GAAG,IAAI,CACf,CAAC;SACF;aAAM;YACN,+DAA+D;YAC/D,MAAM,KAAK,CAAC;SACZ;KACD;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AG,IAAI,CAAC;gBAC5B,SAAS;aACT;YAED,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,KAAyB,CAAC,CAAC;SACnD;IACF,CAAC;IACD,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO;QACvC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,WAAW,CAAC,IAAI,EAAE,UAAU;QAC3B,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAClC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACD,CAAC,CAAC"}
|
package/build/render-border.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOMNode } from './dom';
|
|
2
|
-
import Output from './output';
|
|
3
|
-
declare const
|
|
4
|
-
export default
|
|
1
|
+
import { type DOMNode } from './dom.js';
|
|
2
|
+
import type Output from './output.js';
|
|
3
|
+
declare const renderBorder: (x: number, y: number, node: DOMNode, output: Output) => void;
|
|
4
|
+
export default renderBorder;
|
package/build/render-border.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const cli_boxes_1 = __importDefault(require("cli-boxes"));
|
|
7
|
-
const colorize_1 = __importDefault(require("./colorize"));
|
|
8
|
-
exports.default = (x, y, node, output) => {
|
|
1
|
+
import cliBoxes from 'cli-boxes';
|
|
2
|
+
import colorize from './colorize.js';
|
|
3
|
+
const renderBorder = (x, y, node, output) => {
|
|
9
4
|
if (typeof node.style.borderStyle === 'string') {
|
|
10
5
|
const width = node.yogaNode.getComputedWidth();
|
|
11
6
|
const height = node.yogaNode.getComputedHeight();
|
|
12
7
|
const color = node.style.borderColor;
|
|
13
|
-
const box =
|
|
14
|
-
const topBorder =
|
|
15
|
-
const verticalBorder = (
|
|
16
|
-
const bottomBorder =
|
|
8
|
+
const box = cliBoxes[node.style.borderStyle];
|
|
9
|
+
const topBorder = colorize(box.topLeft + box.top.repeat(width - 2) + box.topRight, color, 'foreground');
|
|
10
|
+
const verticalBorder = (colorize(box.left, color, 'foreground') + '\n').repeat(height - 2);
|
|
11
|
+
const bottomBorder = colorize(box.bottomLeft + box.bottom.repeat(width - 2) + box.bottomRight, color, 'foreground');
|
|
17
12
|
output.write(x, y, topBorder, { transformers: [] });
|
|
18
13
|
output.write(x, y + 1, verticalBorder, { transformers: [] });
|
|
19
14
|
output.write(x + width - 1, y + 1, verticalBorder, { transformers: [] });
|
|
20
15
|
output.write(x, y + height - 1, bottomBorder, { transformers: [] });
|
|
21
16
|
}
|
|
22
17
|
};
|
|
18
|
+
export default renderBorder;
|
|
23
19
|
//# sourceMappingURL=render-border.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-border.js","sourceRoot":"","sources":["../src/render-border.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-border.js","sourceRoot":"","sources":["../src/render-border.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,QAAQ,MAAM,eAAe,CAAC;AAIrC,MAAM,YAAY,GAAG,CACpB,CAAS,EACT,CAAS,EACT,IAAa,EACb,MAAc,EACP,EAAE;IACT,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,KAAK,QAAQ,EAAE;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAS,CAAC,gBAAgB,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAS,CAAC,iBAAiB,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;QACrC,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAE7C,MAAM,SAAS,GAAG,QAAQ,CACzB,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,EACtD,KAAK,EACL,YAAY,CACZ,CAAC;QAEF,MAAM,cAAc,GAAG,CACtB,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,IAAI,CAC9C,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAErB,MAAM,YAAY,GAAG,QAAQ,CAC5B,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,WAAW,EAC/D,KAAK,EACL,YAAY,CACZ,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,cAAc,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,cAAc,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;QACvE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,YAAY,EAAE,EAAC,YAAY,EAAE,EAAE,EAAC,CAAC,CAAC;KAClE;AACF,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DOMElement } from './dom';
|
|
2
|
-
import Output from './output';
|
|
3
|
-
export
|
|
1
|
+
import { type DOMElement } from './dom.js';
|
|
2
|
+
import type Output from './output.js';
|
|
3
|
+
export type OutputTransformer = (s: string) => string;
|
|
4
4
|
declare const renderNodeToOutput: (node: DOMElement, output: Output, options: {
|
|
5
5
|
offsetX?: number;
|
|
6
6
|
offsetY?: number;
|