@xynogen/pix-display 0.3.5 → 0.3.7

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/code-blocks.ts +29 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-display",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Pi core extension — inline chips, thinking blocks, and framed code rendering",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -39,8 +39,8 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@xynogen/pix-pretty": "^1.37.0",
43
- "@xynogen/pix-runtime": "^0.17.0"
42
+ "@xynogen/pix-pretty": "^1.38.0",
43
+ "@xynogen/pix-runtime": "^0.18.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@earendil-works/pi-coding-agent": "*",
@@ -19,6 +19,7 @@ type RenderMode = "tui" | "rpc" | "json" | "print";
19
19
  type PatchablePrototype = {
20
20
  [PATCHED]?: boolean;
21
21
  render(width: number): string[];
22
+ invalidate(): void;
22
23
  };
23
24
 
24
25
  let activeTheme: CodeFrameTheme | undefined;
@@ -136,9 +137,36 @@ function patchAssistantRenderer(): void {
136
137
  if (prototype[PATCHED]) return;
137
138
 
138
139
  const nativeRender = prototype.render;
140
+ const nativeInvalidate = prototype.invalidate;
141
+ const cache = new WeakMap<
142
+ PatchablePrototype,
143
+ {
144
+ width: number;
145
+ theme: CodeFrameTheme;
146
+ input: string[];
147
+ output: string[];
148
+ }
149
+ >();
150
+ prototype.invalidate = function invalidateCodeFrames(): void {
151
+ cache.delete(this);
152
+ nativeInvalidate.call(this);
153
+ };
139
154
  prototype.render = function renderWithCodeFrames(width: number): string[] {
140
155
  const lines = nativeRender.call(this, width);
141
- return activeTheme ? renderCodeFences(lines, width, activeTheme) : lines;
156
+ if (!activeTheme) return lines;
157
+ const previous = cache.get(this);
158
+ if (
159
+ previous &&
160
+ previous.width === width &&
161
+ previous.theme === activeTheme &&
162
+ previous.input.length === lines.length &&
163
+ lines.every((line, i) => line === previous.input[i])
164
+ ) {
165
+ return previous.output;
166
+ }
167
+ const output = renderCodeFences(lines, width, activeTheme);
168
+ cache.set(this, { width, theme: activeTheme, input: [...lines], output });
169
+ return output;
142
170
  };
143
171
  prototype[PATCHED] = true;
144
172
  }