@mariozechner/pi-tui 0.23.0 → 0.23.1
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/dist/components/box.d.ts
CHANGED
|
@@ -7,11 +7,16 @@ export declare class Box implements Component {
|
|
|
7
7
|
private paddingX;
|
|
8
8
|
private paddingY;
|
|
9
9
|
private bgFn?;
|
|
10
|
+
private cachedWidth?;
|
|
11
|
+
private cachedChildLines?;
|
|
12
|
+
private cachedBgSample?;
|
|
13
|
+
private cachedLines?;
|
|
10
14
|
constructor(paddingX?: number, paddingY?: number, bgFn?: (text: string) => string);
|
|
11
15
|
addChild(component: Component): void;
|
|
12
16
|
removeChild(component: Component): void;
|
|
13
17
|
clear(): void;
|
|
14
18
|
setBgFn(bgFn?: (text: string) => string): void;
|
|
19
|
+
private invalidateCache;
|
|
15
20
|
invalidate(): void;
|
|
16
21
|
render(width: number): string[];
|
|
17
22
|
private applyBg;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,qBAAa,GAAI,YAAW,SAAS;IACpC,QAAQ,EAAE,SAAS,EAAE,CAAM;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAC,CAA2B;
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,qBAAa,GAAI,YAAW,SAAS;IACpC,QAAQ,EAAE,SAAS,EAAE,CAAM;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAC,CAA2B;IAGxC,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAClC,OAAO,CAAC,cAAc,CAAC,CAAS;IAChC,OAAO,CAAC,WAAW,CAAC,CAAW;IAE/B,YAAY,QAAQ,SAAI,EAAE,QAAQ,SAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EAItE;IAED,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAGnC;IAED,WAAW,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAMtC;IAED,KAAK,IAAI,IAAI,CAGZ;IAED,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAG7C;IAED,OAAO,CAAC,eAAe;IAOvB,UAAU,IAAI,IAAI,CAKjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA4D9B;IAED,OAAO,CAAC,OAAO;CAUf","sourcesContent":["import type { Component } from \"../tui.js\";\nimport { applyBackgroundToLine, visibleWidth } from \"../utils.js\";\n\n/**\n * Box component - a container that applies padding and background to all children\n */\nexport class Box implements Component {\n\tchildren: Component[] = [];\n\tprivate paddingX: number;\n\tprivate paddingY: number;\n\tprivate bgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cachedWidth?: number;\n\tprivate cachedChildLines?: string;\n\tprivate cachedBgSample?: string;\n\tprivate cachedLines?: string[];\n\n\tconstructor(paddingX = 1, paddingY = 1, bgFn?: (text: string) => string) {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t\tthis.bgFn = bgFn;\n\t}\n\n\taddChild(component: Component): void {\n\t\tthis.children.push(component);\n\t\tthis.invalidateCache();\n\t}\n\n\tremoveChild(component: Component): void {\n\t\tconst index = this.children.indexOf(component);\n\t\tif (index !== -1) {\n\t\t\tthis.children.splice(index, 1);\n\t\t\tthis.invalidateCache();\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.children = [];\n\t\tthis.invalidateCache();\n\t}\n\n\tsetBgFn(bgFn?: (text: string) => string): void {\n\t\tthis.bgFn = bgFn;\n\t\t// Don't invalidate here - we'll detect bgFn changes by sampling output\n\t}\n\n\tprivate invalidateCache(): void {\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedChildLines = undefined;\n\t\tthis.cachedBgSample = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.invalidateCache();\n\t\tfor (const child of this.children) {\n\t\t\tchild.invalidate?.();\n\t\t}\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.children.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\t\tconst leftPad = \" \".repeat(this.paddingX);\n\n\t\t// Render all children\n\t\tconst childLines: string[] = [];\n\t\tfor (const child of this.children) {\n\t\t\tconst lines = child.render(contentWidth);\n\t\t\tfor (const line of lines) {\n\t\t\t\tchildLines.push(leftPad + line);\n\t\t\t}\n\t\t}\n\n\t\tif (childLines.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Check if bgFn output changed by sampling\n\t\tconst bgSample = this.bgFn ? this.bgFn(\"test\") : undefined;\n\n\t\t// Check cache validity\n\t\tconst childLinesKey = childLines.join(\"\\n\");\n\t\tif (\n\t\t\tthis.cachedLines &&\n\t\t\tthis.cachedWidth === width &&\n\t\t\tthis.cachedChildLines === childLinesKey &&\n\t\t\tthis.cachedBgSample === bgSample\n\t\t) {\n\t\t\treturn this.cachedLines;\n\t\t}\n\n\t\t// Apply background and padding\n\t\tconst result: string[] = [];\n\n\t\t// Top padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Content\n\t\tfor (const line of childLines) {\n\t\t\tresult.push(this.applyBg(line, width));\n\t\t}\n\n\t\t// Bottom padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Update cache\n\t\tthis.cachedWidth = width;\n\t\tthis.cachedChildLines = childLinesKey;\n\t\tthis.cachedBgSample = bgSample;\n\t\tthis.cachedLines = result;\n\n\t\treturn result;\n\t}\n\n\tprivate applyBg(line: string, width: number): string {\n\t\tconst visLen = visibleWidth(line);\n\t\tconst padNeeded = Math.max(0, width - visLen);\n\t\tconst padded = line + \" \".repeat(padNeeded);\n\n\t\tif (this.bgFn) {\n\t\t\treturn applyBackgroundToLine(padded, width, this.bgFn);\n\t\t}\n\t\treturn padded;\n\t}\n}\n"]}
|
package/dist/components/box.js
CHANGED
|
@@ -7,6 +7,11 @@ export class Box {
|
|
|
7
7
|
paddingX;
|
|
8
8
|
paddingY;
|
|
9
9
|
bgFn;
|
|
10
|
+
// Cache for rendered output
|
|
11
|
+
cachedWidth;
|
|
12
|
+
cachedChildLines;
|
|
13
|
+
cachedBgSample;
|
|
14
|
+
cachedLines;
|
|
10
15
|
constructor(paddingX = 1, paddingY = 1, bgFn) {
|
|
11
16
|
this.paddingX = paddingX;
|
|
12
17
|
this.paddingY = paddingY;
|
|
@@ -14,20 +19,31 @@ export class Box {
|
|
|
14
19
|
}
|
|
15
20
|
addChild(component) {
|
|
16
21
|
this.children.push(component);
|
|
22
|
+
this.invalidateCache();
|
|
17
23
|
}
|
|
18
24
|
removeChild(component) {
|
|
19
25
|
const index = this.children.indexOf(component);
|
|
20
26
|
if (index !== -1) {
|
|
21
27
|
this.children.splice(index, 1);
|
|
28
|
+
this.invalidateCache();
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
clear() {
|
|
25
32
|
this.children = [];
|
|
33
|
+
this.invalidateCache();
|
|
26
34
|
}
|
|
27
35
|
setBgFn(bgFn) {
|
|
28
36
|
this.bgFn = bgFn;
|
|
37
|
+
// Don't invalidate here - we'll detect bgFn changes by sampling output
|
|
38
|
+
}
|
|
39
|
+
invalidateCache() {
|
|
40
|
+
this.cachedWidth = undefined;
|
|
41
|
+
this.cachedChildLines = undefined;
|
|
42
|
+
this.cachedBgSample = undefined;
|
|
43
|
+
this.cachedLines = undefined;
|
|
29
44
|
}
|
|
30
45
|
invalidate() {
|
|
46
|
+
this.invalidateCache();
|
|
31
47
|
for (const child of this.children) {
|
|
32
48
|
child.invalidate?.();
|
|
33
49
|
}
|
|
@@ -49,6 +65,16 @@ export class Box {
|
|
|
49
65
|
if (childLines.length === 0) {
|
|
50
66
|
return [];
|
|
51
67
|
}
|
|
68
|
+
// Check if bgFn output changed by sampling
|
|
69
|
+
const bgSample = this.bgFn ? this.bgFn("test") : undefined;
|
|
70
|
+
// Check cache validity
|
|
71
|
+
const childLinesKey = childLines.join("\n");
|
|
72
|
+
if (this.cachedLines &&
|
|
73
|
+
this.cachedWidth === width &&
|
|
74
|
+
this.cachedChildLines === childLinesKey &&
|
|
75
|
+
this.cachedBgSample === bgSample) {
|
|
76
|
+
return this.cachedLines;
|
|
77
|
+
}
|
|
52
78
|
// Apply background and padding
|
|
53
79
|
const result = [];
|
|
54
80
|
// Top padding
|
|
@@ -63,6 +89,11 @@ export class Box {
|
|
|
63
89
|
for (let i = 0; i < this.paddingY; i++) {
|
|
64
90
|
result.push(this.applyBg("", width));
|
|
65
91
|
}
|
|
92
|
+
// Update cache
|
|
93
|
+
this.cachedWidth = width;
|
|
94
|
+
this.cachedChildLines = childLinesKey;
|
|
95
|
+
this.cachedBgSample = bgSample;
|
|
96
|
+
this.cachedLines = result;
|
|
66
97
|
return result;
|
|
67
98
|
}
|
|
68
99
|
applyBg(line, width) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"box.js","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAElE;;GAEG;AACH,MAAM,OAAO,GAAG;IACf,QAA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CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QACtC,CAAC;QAED,eAAe;QACf,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,gBAAgB,GAAG,aAAa,CAAC;QACtC,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAE1B,OAAO,MAAM,CAAC;IAAA,CACd;IAEO,OAAO,CAAC,IAAY,EAAE,KAAa,EAAU;QACpD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAE5C,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,OAAO,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,MAAM,CAAC;IAAA,CACd;CACD","sourcesContent":["import type { Component } from \"../tui.js\";\nimport { applyBackgroundToLine, visibleWidth } from \"../utils.js\";\n\n/**\n * Box component - a container that applies padding and background to all children\n */\nexport class Box implements Component {\n\tchildren: Component[] = [];\n\tprivate paddingX: number;\n\tprivate paddingY: number;\n\tprivate bgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cachedWidth?: number;\n\tprivate cachedChildLines?: string;\n\tprivate cachedBgSample?: string;\n\tprivate cachedLines?: string[];\n\n\tconstructor(paddingX = 1, paddingY = 1, bgFn?: (text: string) => string) {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t\tthis.bgFn = bgFn;\n\t}\n\n\taddChild(component: Component): void {\n\t\tthis.children.push(component);\n\t\tthis.invalidateCache();\n\t}\n\n\tremoveChild(component: Component): void {\n\t\tconst index = this.children.indexOf(component);\n\t\tif (index !== -1) {\n\t\t\tthis.children.splice(index, 1);\n\t\t\tthis.invalidateCache();\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.children = [];\n\t\tthis.invalidateCache();\n\t}\n\n\tsetBgFn(bgFn?: (text: string) => string): void {\n\t\tthis.bgFn = bgFn;\n\t\t// Don't invalidate here - we'll detect bgFn changes by sampling output\n\t}\n\n\tprivate invalidateCache(): void {\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedChildLines = undefined;\n\t\tthis.cachedBgSample = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.invalidateCache();\n\t\tfor (const child of this.children) {\n\t\t\tchild.invalidate?.();\n\t\t}\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.children.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\t\tconst leftPad = \" \".repeat(this.paddingX);\n\n\t\t// Render all children\n\t\tconst childLines: string[] = [];\n\t\tfor (const child of this.children) {\n\t\t\tconst lines = child.render(contentWidth);\n\t\t\tfor (const line of lines) {\n\t\t\t\tchildLines.push(leftPad + line);\n\t\t\t}\n\t\t}\n\n\t\tif (childLines.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Check if bgFn output changed by sampling\n\t\tconst bgSample = this.bgFn ? this.bgFn(\"test\") : undefined;\n\n\t\t// Check cache validity\n\t\tconst childLinesKey = childLines.join(\"\\n\");\n\t\tif (\n\t\t\tthis.cachedLines &&\n\t\t\tthis.cachedWidth === width &&\n\t\t\tthis.cachedChildLines === childLinesKey &&\n\t\t\tthis.cachedBgSample === bgSample\n\t\t) {\n\t\t\treturn this.cachedLines;\n\t\t}\n\n\t\t// Apply background and padding\n\t\tconst result: string[] = [];\n\n\t\t// Top padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Content\n\t\tfor (const line of childLines) {\n\t\t\tresult.push(this.applyBg(line, width));\n\t\t}\n\n\t\t// Bottom padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Update cache\n\t\tthis.cachedWidth = width;\n\t\tthis.cachedChildLines = childLinesKey;\n\t\tthis.cachedBgSample = bgSample;\n\t\tthis.cachedLines = result;\n\n\t\treturn result;\n\t}\n\n\tprivate applyBg(line: string, width: number): string {\n\t\tconst visLen = visibleWidth(line);\n\t\tconst padNeeded = Math.max(0, width - visLen);\n\t\tconst padded = line + \" \".repeat(padNeeded);\n\n\t\tif (this.bgFn) {\n\t\t\treturn applyBackgroundToLine(padded, width, this.bgFn);\n\t\t}\n\t\treturn padded;\n\t}\n}\n"]}
|
package/package.json
CHANGED