@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.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/README.md +299 -299
- package/dist/ansi.d.ts +223 -0
- package/dist/ansi.js +2 -0
- package/dist/{devtools-QpCMm9JH.mjs → devtools-BhYGjb7h.js} +1 -1
- package/dist/index-DDVME65c.d.ts +919 -0
- package/dist/index.d.ts +1657 -0
- package/dist/index.js +4643 -0
- package/dist/sgr-CMfEpjSk.d.ts +91 -0
- package/dist/truncate-CBiyyZzw.js +2156 -0
- package/dist/yoga-5jKhYCJC.js +3465 -0
- package/dist/yoga.d.ts +2 -0
- package/dist/yoga.js +2 -0
- package/package.json +37 -17
- package/src/ansi/chalk.ts +179 -0
- package/src/ansi/cursor.ts +48 -0
- package/src/ansi/east-asian-width.ts +215 -0
- package/src/ansi/escapes.ts +128 -0
- package/src/ansi/index.ts +27 -0
- package/src/ansi/sgr.ts +237 -0
- package/src/ansi/slice.ts +43 -0
- package/src/ansi/string-width.ts +236 -0
- package/src/ansi/strip.ts +33 -0
- package/src/ansi/supports-color.ts +213 -0
- package/src/ansi/tokenize.ts +453 -0
- package/src/ansi/truncate.ts +194 -0
- package/src/ansi/widest-line.ts +12 -0
- package/src/ansi/wrap.ts +766 -0
- package/src/ansi-tokenizer.ts +510 -0
- package/src/auto-bind.ts +41 -0
- package/src/boxes.ts +100 -0
- package/src/code-excerpt.ts +39 -0
- package/src/colorize.ts +60 -0
- package/src/components/AccessibilityContext.ts +5 -0
- package/src/components/AnimationContext.ts +24 -0
- package/src/components/App.tsx +781 -0
- package/src/components/AppContext.ts +111 -0
- package/src/components/BackgroundContext.ts +8 -0
- package/src/components/Box.tsx +116 -0
- package/src/components/CursorContext.ts +19 -0
- package/src/components/ErrorBoundary.tsx +38 -0
- package/src/components/ErrorOverview.tsx +133 -0
- package/src/components/FocusContext.ts +30 -0
- package/src/components/Newline.tsx +15 -0
- package/src/components/Spacer.tsx +10 -0
- package/src/components/Static.tsx +59 -0
- package/src/components/StderrContext.ts +26 -0
- package/src/components/StdinContext.ts +49 -0
- package/src/components/StdoutContext.ts +28 -0
- package/src/components/Text.tsx +144 -0
- package/src/components/Transform.tsx +37 -0
- package/src/cursor-position.ts +103 -0
- package/src/devtools-window-polyfill.ts +73 -0
- package/src/devtools.ts +43 -0
- package/src/dom.ts +292 -0
- package/src/get-max-width.ts +11 -0
- package/src/global.d.ts +36 -0
- package/src/hooks/use-animation.ts +142 -0
- package/src/hooks/use-app.ts +8 -0
- package/src/hooks/use-box-metrics.ts +134 -0
- package/src/hooks/use-cursor.ts +33 -0
- package/src/hooks/use-focus-manager.ts +62 -0
- package/src/hooks/use-focus.ts +83 -0
- package/src/hooks/use-input.ts +267 -0
- package/src/hooks/use-is-screen-reader-enabled.ts +12 -0
- package/src/hooks/use-paste.ts +78 -0
- package/src/hooks/use-stderr.ts +8 -0
- package/src/hooks/use-stdin.ts +10 -0
- package/src/hooks/use-stdout.ts +8 -0
- package/src/hooks/use-window-size.ts +41 -0
- package/src/indent-string.ts +16 -0
- package/src/index.ts +44 -0
- package/src/ink.tsx +1506 -0
- package/src/input-parser.ts +283 -0
- package/src/instances.ts +9 -0
- package/src/is-in-ci.ts +7 -0
- package/src/kitty-keyboard.ts +57 -0
- package/src/log-update.ts +370 -0
- package/src/measure-element.ts +62 -0
- package/src/measure-text.ts +31 -0
- package/src/output.ts +308 -0
- package/src/parse-keypress.ts +516 -0
- package/src/parse-stack-line.ts +139 -0
- package/src/patch-console.ts +62 -0
- package/src/quick-lru.ts +85 -0
- package/src/reconciler.ts +451 -0
- package/src/render-background.ts +38 -0
- package/src/render-border.ts +134 -0
- package/src/render-node-to-output.ts +191 -0
- package/src/render-to-string.ts +131 -0
- package/src/render.ts +276 -0
- package/src/renderer.ts +73 -0
- package/src/sanitize-ansi.ts +33 -0
- package/src/signal-exit.ts +107 -0
- package/src/squash-text-nodes.ts +40 -0
- package/src/stream.ts +30 -0
- package/src/styles.ts +748 -0
- package/src/terminal-size.ts +57 -0
- package/src/throttle.ts +73 -0
- package/src/types.ts +15 -0
- package/src/utils.ts +40 -0
- package/src/wrap-text.ts +50 -0
- package/src/write-synchronized.ts +9 -0
- package/src/yoga/config.ts +57 -0
- package/src/yoga/core/absoluteLayout.ts +626 -0
- package/src/yoga/core/baseline.ts +66 -0
- package/src/yoga/core/cache.ts +136 -0
- package/src/yoga/core/calculateLayout.ts +2920 -0
- package/src/yoga/core/config.ts +104 -0
- package/src/yoga/core/flexLine.ts +177 -0
- package/src/yoga/core/helpers.ts +293 -0
- package/src/yoga/core/layoutResults.ts +167 -0
- package/src/yoga/core/node.ts +611 -0
- package/src/yoga/core/numeric.ts +44 -0
- package/src/yoga/core/pixelGrid.ts +151 -0
- package/src/yoga/core/style.ts +887 -0
- package/src/yoga/core/types.ts +224 -0
- package/src/yoga/generated/YGEnums.ts +263 -0
- package/src/yoga/index.ts +19 -0
- package/src/yoga/node.ts +1140 -0
- package/dist/index.d.mts +0 -2379
- package/dist/index.mjs +0 -10072
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Derived from Yoga. See THIRD_PARTY_NOTICES.md.
|
|
3
|
+
|
|
4
|
+
// Port of yoga/algorithm/PixelGrid.cpp.
|
|
5
|
+
|
|
6
|
+
import { Dimension, NodeType } from "../generated/YGEnums.ts";
|
|
7
|
+
import { PhysicalEdge } from "./helpers.ts";
|
|
8
|
+
import type { Node } from "./node.ts";
|
|
9
|
+
import { inexactEquals } from "./numeric.ts";
|
|
10
|
+
|
|
11
|
+
export function roundValueToPixelGrid(
|
|
12
|
+
value: number,
|
|
13
|
+
pointScaleFactor: number,
|
|
14
|
+
forceCeil: boolean,
|
|
15
|
+
forceFloor: boolean,
|
|
16
|
+
): number {
|
|
17
|
+
if (pointScaleFactor === 1 && Number.isInteger(value)) {
|
|
18
|
+
return value === 0 ? 0 : value;
|
|
19
|
+
}
|
|
20
|
+
let scaledValue = value * pointScaleFactor;
|
|
21
|
+
// We want to calculate `fractial` such that `floor(scaledValue) = scaledValue
|
|
22
|
+
// - fractial`. For negative values, adding 1 to fmod's result gives us this.
|
|
23
|
+
let fractial = scaledValue % 1.0;
|
|
24
|
+
if (fractial < 0) {
|
|
25
|
+
++fractial;
|
|
26
|
+
}
|
|
27
|
+
// The epsilon comparisons below are the inexactEquals checks from the C++
|
|
28
|
+
// inlined for the known ranges (fractial is in [0, 1) or NaN; NaN falls
|
|
29
|
+
// through every comparison to the final +0 branch).
|
|
30
|
+
if (fractial < 0.0001) {
|
|
31
|
+
// First we check if the value is already rounded
|
|
32
|
+
scaledValue = scaledValue - fractial;
|
|
33
|
+
} else if (fractial - 1.0 > -0.0001) {
|
|
34
|
+
scaledValue = scaledValue - fractial + 1.0;
|
|
35
|
+
} else if (forceCeil) {
|
|
36
|
+
// Next we check if we need to use forced rounding
|
|
37
|
+
scaledValue = scaledValue - fractial + 1.0;
|
|
38
|
+
} else if (forceFloor) {
|
|
39
|
+
scaledValue = scaledValue - fractial;
|
|
40
|
+
} else {
|
|
41
|
+
// Finally we just round the value (half-up, with the 0.5 comparison
|
|
42
|
+
// itself subject to the epsilon).
|
|
43
|
+
scaledValue = scaledValue - fractial + (fractial - 0.5 > -0.0001 ? 1.0 : 0.0);
|
|
44
|
+
}
|
|
45
|
+
return Number.isNaN(scaledValue) || Number.isNaN(pointScaleFactor)
|
|
46
|
+
? NaN
|
|
47
|
+
: scaledValue / pointScaleFactor;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function roundLayoutResultsToPixelGrid(
|
|
51
|
+
node: Node,
|
|
52
|
+
absoluteLeft: number,
|
|
53
|
+
absoluteTop: number,
|
|
54
|
+
): void {
|
|
55
|
+
const layout = node.layout;
|
|
56
|
+
const pointScaleFactor = node.config.getPointScaleFactor();
|
|
57
|
+
|
|
58
|
+
// Skip subtrees whose inputs are identical to the previous pass: no layout
|
|
59
|
+
// write anywhere below (roundingDirty), the same absolute offset, and the
|
|
60
|
+
// same point scale. The pass is a deterministic function of those inputs,
|
|
61
|
+
// so re-running it would reproduce the stored values exactly.
|
|
62
|
+
if (
|
|
63
|
+
!layout.roundingDirty &&
|
|
64
|
+
layout.roundedAbsLeft === absoluteLeft &&
|
|
65
|
+
layout.roundedAbsTop === absoluteTop &&
|
|
66
|
+
layout.roundedScale === pointScaleFactor
|
|
67
|
+
) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
layout.roundedAbsLeft = absoluteLeft;
|
|
71
|
+
layout.roundedAbsTop = absoluteTop;
|
|
72
|
+
layout.roundedScale = pointScaleFactor;
|
|
73
|
+
layout.roundingDirty = false;
|
|
74
|
+
|
|
75
|
+
const nodeLeft = layout.position(PhysicalEdge.Left);
|
|
76
|
+
const nodeTop = layout.position(PhysicalEdge.Top);
|
|
77
|
+
|
|
78
|
+
const nodeWidth = layout.dimension(Dimension.Width);
|
|
79
|
+
const nodeHeight = layout.dimension(Dimension.Height);
|
|
80
|
+
|
|
81
|
+
const absoluteNodeLeft = absoluteLeft + nodeLeft;
|
|
82
|
+
const absoluteNodeTop = absoluteTop + nodeTop;
|
|
83
|
+
|
|
84
|
+
const absoluteNodeRight = absoluteNodeLeft + nodeWidth;
|
|
85
|
+
const absoluteNodeBottom = absoluteNodeTop + nodeHeight;
|
|
86
|
+
|
|
87
|
+
if (pointScaleFactor !== 0) {
|
|
88
|
+
// If a node has a custom measure function we never want to round down its
|
|
89
|
+
// size as this could lead to unwanted text truncation.
|
|
90
|
+
const textRounding = node.nodeType === NodeType.Text;
|
|
91
|
+
|
|
92
|
+
// Written directly to the layout (not via Node.setLayoutPosition) so the
|
|
93
|
+
// pass's own writes do not re-mark the subtree as rounding-dirty.
|
|
94
|
+
layout.setPosition(
|
|
95
|
+
PhysicalEdge.Left,
|
|
96
|
+
roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
layout.setPosition(
|
|
100
|
+
PhysicalEdge.Top,
|
|
101
|
+
roundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// We multiply dimension by scale factor and if the result is close to the
|
|
105
|
+
// whole number, we don't have any fraction. To verify if the result is
|
|
106
|
+
// close to whole number we want to check both floor and ceil numbers.
|
|
107
|
+
const scaledNodeWidth = nodeWidth * pointScaleFactor;
|
|
108
|
+
const hasFractionalWidth = !inexactEquals(Math.round(scaledNodeWidth), scaledNodeWidth);
|
|
109
|
+
|
|
110
|
+
const scaledNodeHeight = nodeHeight * pointScaleFactor;
|
|
111
|
+
const hasFractionalHeight = !inexactEquals(Math.round(scaledNodeHeight), scaledNodeHeight);
|
|
112
|
+
|
|
113
|
+
node.layout.setDimension(
|
|
114
|
+
Dimension.Width,
|
|
115
|
+
roundValueToPixelGrid(
|
|
116
|
+
absoluteNodeRight,
|
|
117
|
+
pointScaleFactor,
|
|
118
|
+
textRounding && hasFractionalWidth,
|
|
119
|
+
textRounding && !hasFractionalWidth,
|
|
120
|
+
) - roundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, textRounding),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
node.layout.setDimension(
|
|
124
|
+
Dimension.Height,
|
|
125
|
+
roundValueToPixelGrid(
|
|
126
|
+
absoluteNodeBottom,
|
|
127
|
+
pointScaleFactor,
|
|
128
|
+
textRounding && hasFractionalHeight,
|
|
129
|
+
textRounding && !hasFractionalHeight,
|
|
130
|
+
) - roundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, textRounding),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
roundChildren(node, absoluteNodeLeft, absoluteNodeTop);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Recurse into children, checking the skip condition at the call site to
|
|
138
|
+
// avoid the function-call overhead for clean subtrees.
|
|
139
|
+
function roundChildren(node: Node, absoluteNodeLeft: number, absoluteNodeTop: number): void {
|
|
140
|
+
for (const child of node.children) {
|
|
141
|
+
const childLayout = child.layout;
|
|
142
|
+
if (
|
|
143
|
+
childLayout.roundingDirty ||
|
|
144
|
+
childLayout.roundedAbsLeft !== absoluteNodeLeft ||
|
|
145
|
+
childLayout.roundedAbsTop !== absoluteNodeTop ||
|
|
146
|
+
childLayout.roundedScale !== child.config.getPointScaleFactor()
|
|
147
|
+
) {
|
|
148
|
+
roundLayoutResultsToPixelGrid(child, absoluteNodeLeft, absoluteNodeTop);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|