pi-cc-extensions 0.8.13 → 0.8.14

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.
@@ -188,8 +188,20 @@ class QuestionnaireBuilder {
188
188
  const questions = this.questions;
189
189
  const itemsByTab = this.itemsByTab;
190
190
  const tabsDescriptor = questions.map((q) => ({ multiSelect: q.multiSelect }));
191
- const globalLeftWidth = (paneWidth: number): number =>
192
- crossTabLeftWidthWithDonation(tabsDescriptor, itemsByTab, questions, paneWidth);
191
+ // Memoize by paneWidth — preview/naturalHeight call this many times per keystroke.
192
+ let cachedPaneWidth: number | undefined;
193
+ let cachedLeftWidth = 0;
194
+ const globalLeftWidth = (paneWidth: number): number => {
195
+ if (cachedPaneWidth === paneWidth) return cachedLeftWidth;
196
+ cachedLeftWidth = crossTabLeftWidthWithDonation(
197
+ tabsDescriptor,
198
+ itemsByTab,
199
+ questions,
200
+ paneWidth,
201
+ );
202
+ cachedPaneWidth = paneWidth;
203
+ return cachedLeftWidth;
204
+ };
193
205
  for (const tab of tabs) {
194
206
  tab.preview.setGlobalLeftWidth(globalLeftWidth);
195
207
  }
@@ -104,7 +104,13 @@ export function crossTabMaxLeftWidth(
104
104
  *
105
105
  * Pure function — O(total chars) per question; no Markdown invocation, no cache interaction.
106
106
  */
107
+ /** Per-question widest preview line; questions are immutable for a dialog lifetime. */
108
+ const previewSourceWidthCache = new WeakMap<QuestionData, number>();
109
+
107
110
  export function previewSourceWidth(question: QuestionData): number {
111
+ const cached = previewSourceWidthCache.get(question);
112
+ if (cached !== undefined) return cached;
113
+
108
114
  let max = 0;
109
115
  for (const option of question.options) {
110
116
  const text = option.preview;
@@ -114,6 +120,7 @@ export function previewSourceWidth(question: QuestionData): number {
114
120
  if (w > max) max = w;
115
121
  }
116
122
  }
123
+ previewSourceWidthCache.set(question, max);
117
124
  return max;
118
125
  }
119
126