@opentui/core 0.6.7 → 0.7.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.
Files changed (48) hide show
  1. package/NativeScene.d.ts +5 -26
  2. package/Renderable.d.ts +27 -32
  3. package/audio.d.ts +1 -0
  4. package/{chunk-bun-ehr9v0n8.js → chunk-bun-qkpm62w1.js} +257 -69
  5. package/chunk-bun-qkpm62w1.js.map +35 -0
  6. package/{chunk-bun-rk6266v5.js → chunk-bun-zevtbcf6.js} +851 -786
  7. package/chunk-bun-zevtbcf6.js.map +70 -0
  8. package/{chunk-node-y5p1g2pb.js → chunk-node-7bcmqh18.js} +851 -786
  9. package/chunk-node-7bcmqh18.js.map +70 -0
  10. package/{chunk-node-jhq62x0c.js → chunk-node-mzgnr3sw.js} +257 -69
  11. package/chunk-node-mzgnr3sw.js.map +34 -0
  12. package/index.bun.js +313 -91
  13. package/index.bun.js.map +12 -11
  14. package/index.node.js +313 -91
  15. package/index.node.js.map +12 -10
  16. package/lib/detect-links.d.ts +2 -0
  17. package/lib/parse.keypress-kitty.d.ts +2 -0
  18. package/lib/scroll-chain.d.ts +16 -0
  19. package/lib/stdin-parser-native.d.ts +88 -0
  20. package/native-abi.generated.d.ts +394 -5
  21. package/package.json +9 -9
  22. package/renderables/Box.d.ts +2 -2
  23. package/renderables/Code.d.ts +2 -1
  24. package/renderables/Diff.d.ts +2 -2
  25. package/renderables/EditBufferRenderable.d.ts +2 -2
  26. package/renderables/EmbeddedTerminal.d.ts +2 -2
  27. package/renderables/FrameBuffer.d.ts +3 -3
  28. package/renderables/Image.d.ts +2 -2
  29. package/renderables/Markdown.d.ts +2 -2
  30. package/renderables/ScrollBar.d.ts +3 -3
  31. package/renderables/ScrollBox.d.ts +6 -3
  32. package/renderables/Slider.d.ts +2 -2
  33. package/renderables/Text.d.ts +2 -2
  34. package/renderables/TextBufferRenderable.d.ts +2 -4
  35. package/renderer.d.ts +8 -4
  36. package/testing/test-renderer.d.ts +2 -0
  37. package/testing.bun.js +11 -4
  38. package/testing.bun.js.map +3 -3
  39. package/testing.js +11 -4
  40. package/testing.js.map +3 -3
  41. package/yoga.bun.js +1 -1
  42. package/yoga.js +1 -1
  43. package/zig-structs.d.ts +25 -0
  44. package/zig.d.ts +20 -7
  45. package/chunk-bun-ehr9v0n8.js.map +0 -35
  46. package/chunk-bun-rk6266v5.js.map +0 -69
  47. package/chunk-node-jhq62x0c.js.map +0 -34
  48. package/chunk-node-y5p1g2pb.js.map +0 -69
@@ -1,4 +1,5 @@
1
1
  import {
2
+ nativeLayouts,
2
3
  nativeConstants,
3
4
  toArrayBuffer,
4
5
  singleton,
@@ -63,7 +64,7 @@ import {
63
64
  PositionType2,
64
65
  Unit2,
65
66
  Wrap2
66
- } from "./chunk-node-jhq62x0c.js";
67
+ } from "./chunk-node-mzgnr3sw.js";
67
68
 
68
69
  // src/lib/border.ts
69
70
  var VALID_BORDER_STYLES = ["single", "double", "rounded", "heavy"];
@@ -3285,237 +3286,6 @@ function renderFontToFrameBuffer2(buffer, {
3285
3286
  };
3286
3287
  }
3287
3288
 
3288
- // src/syntax-style.ts
3289
- function cloneStyle(style) {
3290
- return {
3291
- ...style,
3292
- fg: style.fg ? RGBA2.clone(style.fg) : undefined,
3293
- bg: style.bg ? RGBA2.clone(style.bg) : undefined
3294
- };
3295
- }
3296
- function convertThemeToStyles2(theme) {
3297
- const flatStyles = {};
3298
- for (const tokenStyle of theme) {
3299
- const styleDefinition = {};
3300
- if (tokenStyle.style.foreground) {
3301
- styleDefinition.fg = parseColor2(tokenStyle.style.foreground);
3302
- }
3303
- if (tokenStyle.style.background) {
3304
- styleDefinition.bg = parseColor2(tokenStyle.style.background);
3305
- }
3306
- if (tokenStyle.style.bold !== undefined) {
3307
- styleDefinition.bold = tokenStyle.style.bold;
3308
- }
3309
- if (tokenStyle.style.italic !== undefined) {
3310
- styleDefinition.italic = tokenStyle.style.italic;
3311
- }
3312
- if (tokenStyle.style.underline !== undefined) {
3313
- styleDefinition.underline = tokenStyle.style.underline;
3314
- }
3315
- if (tokenStyle.style.dim !== undefined) {
3316
- styleDefinition.dim = tokenStyle.style.dim;
3317
- }
3318
- for (const scope of tokenStyle.scope) {
3319
- flatStyles[scope] = cloneStyle(styleDefinition);
3320
- }
3321
- }
3322
- return flatStyles;
3323
- }
3324
-
3325
- class SyntaxStyle2 {
3326
- lib;
3327
- native;
3328
- _destroyed = false;
3329
- nameCache = new Map;
3330
- styleDefs = new Map;
3331
- mergedCache = new Map;
3332
- constructor(lib, handle, source) {
3333
- const owner = source?.resourceContext;
3334
- if (!owner)
3335
- throw new Error("SyntaxStyle requires an explicit resource owner");
3336
- owner.assertAlive();
3337
- if (owner.renderLib !== lib || !handle || typeof handle !== "object" || handle.context !== owner.context) {
3338
- throw new Error("SyntaxStyle Context owner mismatch");
3339
- }
3340
- this.lib = lib;
3341
- this.native = { owner, handle };
3342
- }
3343
- static create(source) {
3344
- const owner = source?.resourceContext;
3345
- if (!owner)
3346
- throw new Error("SyntaxStyle requires an explicit resource owner: pass renderer.nativeScene, or a ResourceContext when there is no renderer");
3347
- owner.assertAlive();
3348
- const lib = owner.renderLib;
3349
- const handle = lib.createContextSyntaxStyle(owner.context);
3350
- try {
3351
- return new SyntaxStyle2(lib, handle, owner);
3352
- } catch (error) {
3353
- lib.destroyContextSyntaxStyle(owner.context, handle);
3354
- throw error;
3355
- }
3356
- }
3357
- static fromTheme(theme, owner) {
3358
- return SyntaxStyle2.fromStyles(convertThemeToStyles2(theme), owner);
3359
- }
3360
- static fromStyles(styles, owner) {
3361
- const style = SyntaxStyle2.create(owner);
3362
- try {
3363
- for (const [name, styleDef] of styles instanceof Map ? styles : Object.entries(styles)) {
3364
- style.registerStyle(name, styleDef);
3365
- }
3366
- return style;
3367
- } catch (error) {
3368
- style.destroy();
3369
- throw error;
3370
- }
3371
- }
3372
- guard() {
3373
- if (this._destroyed)
3374
- throw new Error("NativeSyntaxStyle is destroyed");
3375
- this.native.owner.assertAlive();
3376
- }
3377
- _getSceneHandle(scene) {
3378
- this.guard();
3379
- if (this.native.owner !== scene.resourceContext)
3380
- throw new Error("SyntaxStyle owner mismatch: bind definitions in the destination Context");
3381
- return this.native.handle;
3382
- }
3383
- registerStyle(name, style) {
3384
- this.guard();
3385
- const { bold, italic, underline, dim, fg: foreground, bg: background } = style;
3386
- const definition = {
3387
- bold,
3388
- italic,
3389
- underline,
3390
- dim,
3391
- fg: foreground ? RGBA2.clone(parseColor2(foreground)) : undefined,
3392
- bg: background ? RGBA2.clone(parseColor2(background)) : undefined
3393
- };
3394
- const attributes = createTextAttributes2(definition);
3395
- const fg = definition.fg ?? null;
3396
- const bg = definition.bg ?? null;
3397
- return this.lib.getYogaHost().runMutation(() => {
3398
- const id = this.lib.contextSyntaxStyleRegister(this.native.handle.context, this.native.handle, name, {
3399
- fg,
3400
- bg,
3401
- attributes
3402
- });
3403
- this.nameCache.set(name, id);
3404
- this.styleDefs.set(name, definition);
3405
- this.mergedCache.clear();
3406
- return id;
3407
- });
3408
- }
3409
- resolveStyleId(name) {
3410
- this.guard();
3411
- const cached = this.nameCache.get(name);
3412
- if (cached !== undefined)
3413
- return cached;
3414
- const id = this.lib.contextSyntaxStyleResolveByName(this.native.handle.context, this.native.handle, name);
3415
- if (id !== null) {
3416
- this.nameCache.set(name, id);
3417
- }
3418
- return id;
3419
- }
3420
- getStyleId(name) {
3421
- this.guard();
3422
- const id = this.resolveStyleId(name);
3423
- if (id !== null)
3424
- return id;
3425
- if (name.includes(".")) {
3426
- const baseName = name.split(".")[0];
3427
- return this.resolveStyleId(baseName);
3428
- }
3429
- return null;
3430
- }
3431
- getStyleCount() {
3432
- this.guard();
3433
- return this.lib.contextSyntaxStyleGetStyleCount(this.native.handle.context, this.native.handle);
3434
- }
3435
- clearNameCache() {
3436
- this.guard();
3437
- this.nameCache.clear();
3438
- }
3439
- getStyle(name) {
3440
- this.guard();
3441
- const style = this.styleDefs.get(name);
3442
- if (style)
3443
- return cloneStyle(style);
3444
- if (name.includes(".")) {
3445
- const baseName = name.split(".")[0];
3446
- const base = this.styleDefs.get(baseName);
3447
- return base ? cloneStyle(base) : undefined;
3448
- }
3449
- return;
3450
- }
3451
- mergeStyles(...styleNames) {
3452
- this.guard();
3453
- const cacheKey = styleNames.join(":");
3454
- const cached = this.mergedCache.get(cacheKey);
3455
- if (cached)
3456
- return cloneStyle(cached);
3457
- const styleDefinition = {};
3458
- for (const name of styleNames) {
3459
- const style = this.getStyle(name);
3460
- if (!style)
3461
- continue;
3462
- if (style.fg)
3463
- styleDefinition.fg = style.fg;
3464
- if (style.bg)
3465
- styleDefinition.bg = style.bg;
3466
- if (style.bold !== undefined)
3467
- styleDefinition.bold = style.bold;
3468
- if (style.italic !== undefined)
3469
- styleDefinition.italic = style.italic;
3470
- if (style.underline !== undefined)
3471
- styleDefinition.underline = style.underline;
3472
- if (style.dim !== undefined)
3473
- styleDefinition.dim = style.dim;
3474
- }
3475
- const attributes = createTextAttributes2({
3476
- bold: styleDefinition.bold,
3477
- italic: styleDefinition.italic,
3478
- underline: styleDefinition.underline,
3479
- dim: styleDefinition.dim
3480
- });
3481
- const merged = {
3482
- fg: styleDefinition.fg,
3483
- bg: styleDefinition.bg,
3484
- attributes
3485
- };
3486
- this.mergedCache.set(cacheKey, merged);
3487
- return cloneStyle(merged);
3488
- }
3489
- clearCache() {
3490
- this.guard();
3491
- this.mergedCache.clear();
3492
- }
3493
- getCacheSize() {
3494
- this.guard();
3495
- return this.mergedCache.size;
3496
- }
3497
- getAllStyles() {
3498
- this.guard();
3499
- return new Map(Array.from(this.styleDefs, ([name, style]) => [name, cloneStyle(style)]));
3500
- }
3501
- getRegisteredNames() {
3502
- this.guard();
3503
- return Array.from(this.styleDefs.keys());
3504
- }
3505
- destroy() {
3506
- if (this._destroyed)
3507
- return;
3508
- this.lib.getYogaHost().runMutation(() => {
3509
- if (!this.native.owner.disposed)
3510
- this.lib.destroyContextSyntaxStyle(this.native.handle.context, this.native.handle);
3511
- this._destroyed = true;
3512
- this.nameCache.clear();
3513
- this.styleDefs.clear();
3514
- this.mergedCache.clear();
3515
- });
3516
- }
3517
- }
3518
-
3519
3289
  // src/lib/hast-styled-text.ts
3520
3290
  function hastToTextChunks(node, syntaxStyle, parentStyles = []) {
3521
3291
  const chunks = [];
@@ -8049,7 +7819,7 @@ class ExtmarksController2 {
8049
7819
  this.originalMoveCursorLeft();
8050
7820
  return;
8051
7821
  }
8052
- const currentOffset = this.editorView.getVisualCursor().offset;
7822
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8053
7823
  const hasSelection = this.editorView.hasSelection();
8054
7824
  if (hasSelection) {
8055
7825
  this.originalMoveCursorLeft();
@@ -8072,7 +7842,7 @@ class ExtmarksController2 {
8072
7842
  this.originalMoveCursorRight();
8073
7843
  return;
8074
7844
  }
8075
- const currentOffset = this.editorView.getVisualCursor().offset;
7845
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8076
7846
  const hasSelection = this.editorView.hasSelection();
8077
7847
  if (hasSelection) {
8078
7848
  this.originalMoveCursorRight();
@@ -8100,9 +7870,9 @@ class ExtmarksController2 {
8100
7870
  this.originalMoveUpVisual();
8101
7871
  return;
8102
7872
  }
8103
- const currentOffset = this.editorView.getVisualCursor().offset;
7873
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8104
7874
  this.originalMoveUpVisual();
8105
- const newOffset = this.editorView.getVisualCursor().offset;
7875
+ const newOffset = this.editBuffer.getCursorPosition().offset;
8106
7876
  const virtualExtmark = this.findVirtualExtmarkContaining(newOffset);
8107
7877
  if (virtualExtmark) {
8108
7878
  const distanceToStart = newOffset - virtualExtmark.start;
@@ -8124,9 +7894,9 @@ class ExtmarksController2 {
8124
7894
  this.originalMoveDownVisual();
8125
7895
  return;
8126
7896
  }
8127
- const currentOffset = this.editorView.getVisualCursor().offset;
7897
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8128
7898
  this.originalMoveDownVisual();
8129
- const newOffset = this.editorView.getVisualCursor().offset;
7899
+ const newOffset = this.editBuffer.getCursorPosition().offset;
8130
7900
  const virtualExtmark = this.findVirtualExtmarkContaining(newOffset);
8131
7901
  if (virtualExtmark) {
8132
7902
  const distanceToStart = newOffset - virtualExtmark.start;
@@ -8145,7 +7915,7 @@ class ExtmarksController2 {
8145
7915
  this.originalSetCursorByOffset(offset);
8146
7916
  return;
8147
7917
  }
8148
- const currentOffset = this.editorView.getVisualCursor().offset;
7918
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8149
7919
  const hasSelection = this.editorView.hasSelection();
8150
7920
  if (hasSelection) {
8151
7921
  this.originalSetCursorByOffset(offset);
@@ -8175,7 +7945,7 @@ class ExtmarksController2 {
8175
7945
  this.originalDeleteCharBackward();
8176
7946
  return;
8177
7947
  }
8178
- const currentOffset = this.editorView.getVisualCursor().offset;
7948
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8179
7949
  const hadSelection = this.editorView.hasSelection();
8180
7950
  if (currentOffset === 0 || hadSelection) {
8181
7951
  this.originalDeleteCharBackward();
@@ -8208,7 +7978,7 @@ class ExtmarksController2 {
8208
7978
  this.originalDeleteChar();
8209
7979
  return;
8210
7980
  }
8211
- const currentOffset = this.editorView.getVisualCursor().offset;
7981
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8212
7982
  const hadSelection = this.editorView.hasSelection();
8213
7983
  if (hadSelection) {
8214
7984
  this.originalDeleteChar();
@@ -8267,7 +8037,7 @@ class ExtmarksController2 {
8267
8037
  this.originalInsertText(text);
8268
8038
  return;
8269
8039
  }
8270
- const currentOffset = this.editorView.getVisualCursor().offset;
8040
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8271
8041
  this.originalInsertText(text);
8272
8042
  this.saveSnapshot();
8273
8043
  const insertLength = this.editBuffer.getCursorPosition().offset - currentOffset;
@@ -8280,7 +8050,7 @@ class ExtmarksController2 {
8280
8050
  this.originalInsertChar(char);
8281
8051
  return;
8282
8052
  }
8283
- const currentOffset = this.editorView.getVisualCursor().offset;
8053
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8284
8054
  this.originalInsertChar(char);
8285
8055
  this.saveSnapshot();
8286
8056
  const insertLength = this.editBuffer.getCursorPosition().offset - currentOffset;
@@ -8323,7 +8093,7 @@ class ExtmarksController2 {
8323
8093
  this.originalNewLine();
8324
8094
  return;
8325
8095
  }
8326
- const currentOffset = this.editorView.getVisualCursor().offset;
8096
+ const currentOffset = this.editBuffer.getCursorPosition().offset;
8327
8097
  this.originalNewLine();
8328
8098
  this.saveSnapshot();
8329
8099
  this.adjustExtmarksAfterInsertion(currentOffset, 1);
@@ -8443,7 +8213,7 @@ class ExtmarksController2 {
8443
8213
  }
8444
8214
  getNextCursorOffset(currentOffset) {
8445
8215
  this.originalMoveCursorRight();
8446
- const nextOffset = this.editorView.getVisualCursor().offset;
8216
+ const nextOffset = this.editBuffer.getCursorPosition().offset;
8447
8217
  this.originalSetCursorByOffset(currentOffset);
8448
8218
  return nextOffset;
8449
8219
  }
@@ -9687,12 +9457,13 @@ function detectLinks2(chunks, context) {
9687
9457
  highlightedIndex++;
9688
9458
  if (highlightedIndex < ranges.length && ranges[highlightedIndex].start < end)
9689
9459
  continue;
9690
- ranges.push({ start, end, url });
9460
+ ranges.push({ start, end, url, bare: true });
9691
9461
  }
9692
9462
  }
9693
9463
  if (ranges.length === 0)
9694
9464
  return chunks;
9695
9465
  ranges.sort((a, b) => a.start - b.start || b.end - a.end || Number(b.label ?? false) - Number(a.label ?? false));
9466
+ const bareStyle = context.syntaxStyle?.mergeStyles("markup.link.label");
9696
9467
  const linkedChunks = [];
9697
9468
  let contentPos = 0;
9698
9469
  let rangeIndex = 0;
@@ -9731,16 +9502,16 @@ function detectLinks2(chunks, context) {
9731
9502
  if (linkStart > position) {
9732
9503
  linkedChunks.push({ ...chunk, text: chunk.text.slice(position - start, linkStart - start) });
9733
9504
  }
9734
- if (linkStart === start && linkEnd === end) {
9735
- chunk.link = { url: range.url };
9736
- linkedChunks.push(chunk);
9737
- } else {
9738
- linkedChunks.push({
9739
- ...chunk,
9740
- text: chunk.text.slice(linkStart - start, linkEnd - start),
9741
- link: { url: range.url }
9742
- });
9505
+ const linked = linkStart === start && linkEnd === end ? chunk : { ...chunk, text: chunk.text.slice(linkStart - start, linkEnd - start) };
9506
+ linked.link = { url: range.url };
9507
+ if (range.bare && bareStyle) {
9508
+ if (bareStyle.fg)
9509
+ linked.fg = bareStyle.fg;
9510
+ if (bareStyle.bg)
9511
+ linked.bg = bareStyle.bg;
9512
+ linked.attributes = (linked.attributes ?? 0) | bareStyle.attributes;
9743
9513
  }
9514
+ linkedChunks.push(linked);
9744
9515
  position = linkEnd;
9745
9516
  if (position === end)
9746
9517
  break;
@@ -10533,26 +10304,16 @@ function isSizeType(value) {
10533
10304
 
10534
10305
  // src/Renderable.ts
10535
10306
  var BrandedRenderable = Symbol.for("@opentui/core/Renderable");
10536
- var nativeSceneMethodNames = [
10307
+ var hookNames = [
10537
10308
  "renderSelf",
10538
10309
  "onResize",
10539
10310
  "onLayoutResize",
10540
10311
  "onUpdate",
10541
10312
  "renderBefore",
10542
10313
  "renderAfter",
10543
- "onLifecyclePass",
10544
- "selectable"
10314
+ "onLifecyclePass"
10545
10315
  ];
10546
- var nativeSceneMethodDefaults = {
10547
- selectable: false,
10548
- onLifecyclePass: null,
10549
- renderBefore: undefined,
10550
- renderAfter: undefined
10551
- };
10552
- var nativeSceneHookUpdates = nativeConstants.OT_SCENE_HOOK_UPDATE | nativeConstants.OT_SCENE_HOOK_IDLE_UPDATE;
10553
- var nativeSceneHookListeners = nativeConstants.OT_SCENE_HOOK_RESIZE | nativeConstants.OT_SCENE_HOOK_LAYOUT_CHANGED;
10554
10316
  var nativeSceneHookBeforeAfter = nativeConstants.OT_SCENE_HOOK_RENDER_BEFORE | nativeConstants.OT_SCENE_HOOK_RENDER_AFTER;
10555
- var nativeSceneHookHostMethods = nativeConstants.OT_SCENE_HOOK_UPDATE | nativeSceneHookBeforeAfter | nativeConstants.OT_SCENE_HOOK_RENDER_SELF;
10556
10317
  function isRowFlexDirection(direction) {
10557
10318
  return direction === FlexDirection2.Row || direction === FlexDirection2.RowReverse;
10558
10319
  }
@@ -10620,6 +10381,15 @@ class Renderable2 extends BaseRenderable2 {
10620
10381
  kind: "custom",
10621
10382
  body: { native: this.prototype.renderSelf }
10622
10383
  };
10384
+ static baseHooks = {
10385
+ renderSelf: this.prototype.renderSelf,
10386
+ onResize: this.prototype.onResize,
10387
+ onLayoutResize: this.prototype.onLayoutResize,
10388
+ onUpdate: this.prototype.onUpdate,
10389
+ renderBefore: undefined,
10390
+ renderAfter: undefined,
10391
+ onLifecyclePass: null
10392
+ };
10623
10393
  nativeIntegration;
10624
10394
  _isDestroyed = false;
10625
10395
  _cleanupInProgress = false;
@@ -10644,18 +10414,14 @@ class Renderable2 extends BaseRenderable2 {
10644
10414
  _live = false;
10645
10415
  _liveCount = 0;
10646
10416
  _sizeChangeListener = undefined;
10647
- _nativeSceneHookFlags = 0;
10417
+ _hooks = Renderable2.baseHooks;
10648
10418
  _nativeSceneHookGeneration = 0n;
10649
10419
  _nativeSceneHooksRegistered = false;
10650
10420
  _nativeSceneResize = false;
10651
- _nativeSceneResizeCallbacks;
10652
- _nativeSceneHookLayout;
10421
+ _paintLayout;
10653
10422
  _observedLayout;
10654
10423
  _observedLayoutRevision = -1;
10655
- _computedLayout;
10656
- _computedLayoutRevision = -1;
10657
- _nativeSceneMethods;
10658
- _nativeSceneMethodsPending = false;
10424
+ _selectable = false;
10659
10425
  _mouseListener = null;
10660
10426
  _mouseListeners = {};
10661
10427
  _pasteListener = undefined;
@@ -10667,6 +10433,24 @@ class Renderable2 extends BaseRenderable2 {
10667
10433
  _flexShrink = 1;
10668
10434
  _childrenInLayoutOrder = [];
10669
10435
  parent = null;
10436
+ get onLifecyclePass() {
10437
+ return this._hooks.onLifecyclePass;
10438
+ }
10439
+ set onLifecyclePass(value) {
10440
+ this.setHook("onLifecyclePass", value);
10441
+ }
10442
+ get renderBefore() {
10443
+ return this._hooks.renderBefore;
10444
+ }
10445
+ set renderBefore(value) {
10446
+ this.setHook("renderBefore", value);
10447
+ }
10448
+ get renderAfter() {
10449
+ return this._hooks.renderAfter;
10450
+ }
10451
+ set renderAfter(value) {
10452
+ this.setHook("renderAfter", value);
10453
+ }
10670
10454
  constructor(ctx, options) {
10671
10455
  super(options);
10672
10456
  this._ctx = ctx;
@@ -10683,12 +10467,14 @@ class Renderable2 extends BaseRenderable2 {
10683
10467
  this._liveCount = this._live && this._visible ? 1 : 0;
10684
10468
  this._opacity = clampOpacity(options.opacity);
10685
10469
  ctx.nativeScene.createNode(this, options);
10686
- if (options.renderBefore !== undefined)
10687
- this.renderBefore = options.renderBefore;
10688
- if (options.renderAfter !== undefined)
10689
- this.renderAfter = options.renderAfter;
10690
- if (this.nativeSceneNeedsHookPublish())
10691
- this.setNativeSceneHooks(this._nativeSceneHookFlags);
10470
+ const hooks = {};
10471
+ for (const name of hookNames)
10472
+ hooks[name] = this[name];
10473
+ for (const name of ["renderBefore", "renderAfter"]) {
10474
+ if (options[name] !== undefined)
10475
+ hooks[name] = Renderable2.normalizeHook(name, options[name]);
10476
+ }
10477
+ this.publishHooks(hooks);
10692
10478
  this.setDisplay(this._visible ? 0 /* Flex */ : 1 /* None */);
10693
10479
  this.setupYogaProperties(options);
10694
10480
  if (this.nativeIntegration.measure)
@@ -10700,9 +10486,6 @@ class Renderable2 extends BaseRenderable2 {
10700
10486
  if (this.buffered) {
10701
10487
  this.createFrameBuffer();
10702
10488
  }
10703
- if (!Object.hasOwn(new.target, "nativeIntegration") || this.nativeIntegration.construction !== "prototype") {
10704
- ctx.nativeScene.scheduleHookScan(this);
10705
- }
10706
10489
  } catch (error) {
10707
10490
  try {
10708
10491
  this.destroyLayoutBacking();
@@ -10981,22 +10764,16 @@ class Renderable2 extends BaseRenderable2 {
10981
10764
  return this.isFreed() ? this._destroyedLayout?.screenY ?? 0 : this.getNativeSceneLayout().screenY;
10982
10765
  }
10983
10766
  get _screenX() {
10984
- return this.getNativeScenePaintLayout()?.screenX ?? this.screenX;
10767
+ return this._paintLayout?.screenX ?? this.screenX;
10985
10768
  }
10986
10769
  get _screenY() {
10987
- return this.getNativeScenePaintLayout()?.screenY ?? this.screenY;
10770
+ return this._paintLayout?.screenY ?? this.screenY;
10988
10771
  }
10989
- getNativeScenePaintLayout() {
10990
- const cached = this._nativeSceneHookLayout;
10991
- if (!cached)
10992
- return;
10993
- const scene = this._ctx.nativeScene;
10994
- const revision = scene.currentGeometryRevision;
10995
- if (!this._isDestroyed && cached.paintRevision !== revision) {
10996
- cached.paintLayout = scene.getLayout(this, "paint");
10997
- cached.paintRevision = revision;
10998
- }
10999
- return cached.paintLayout;
10772
+ get _paintWidth() {
10773
+ return this._paintLayout?.width ?? this.width;
10774
+ }
10775
+ get _paintHeight() {
10776
+ return this._paintLayout?.height ?? this.height;
11000
10777
  }
11001
10778
  get x() {
11002
10779
  if (!this.isFreed())
@@ -11079,22 +10856,16 @@ class Renderable2 extends BaseRenderable2 {
11079
10856
  return typeof value === "number" ? value : 0;
11080
10857
  }
11081
10858
  getNativeSceneLayout() {
11082
- const scene = this._ctx.nativeScene;
11083
- const cached = this._nativeSceneHookLayout;
11084
- const revision = scene.currentGeometryRevision;
11085
- if (cached?.layout && cached.revision === revision)
11086
- return cached.layout;
11087
- const layoutRevision = scene.observedLayoutRevision;
11088
- if (layoutRevision !== undefined && this._observedLayoutRevision === layoutRevision)
10859
+ const revision = this._ctx.nativeScene.observedLayoutRevision;
10860
+ if (revision !== undefined && this._observedLayoutRevision === revision)
11089
10861
  return this._observedLayout;
11090
- const layout = scene.getLayout(this);
11091
- if (cached) {
11092
- cached.revision = revision;
11093
- cached.layout = layout;
11094
- }
11095
- if (layoutRevision !== undefined) {
10862
+ return this.observeLayout(this._ctx.nativeScene.getLayout(this));
10863
+ }
10864
+ observeLayout(layout) {
10865
+ const revision = this._ctx.nativeScene.observedLayoutRevision;
10866
+ if (layout && revision !== undefined) {
11096
10867
  this._observedLayout = layout;
11097
- this._observedLayoutRevision = layoutRevision;
10868
+ this._observedLayoutRevision = revision;
11098
10869
  }
11099
10870
  return layout;
11100
10871
  }
@@ -11305,17 +11076,7 @@ class Renderable2 extends BaseRenderable2 {
11305
11076
  return this.yogaGetValue(YogaValueKind.Gap, gutter);
11306
11077
  }
11307
11078
  getComputedLayout() {
11308
- const scene = this._ctx.nativeScene;
11309
- const revision = scene.observedLayoutRevision;
11310
- let layout = this._computedLayout;
11311
- if (revision === undefined || this._computedLayoutRevision !== revision || layout === undefined || this._yogaFreed) {
11312
- layout = scene.getLayout(this, true);
11313
- if (revision !== undefined) {
11314
- this._computedLayout = layout;
11315
- this._computedLayoutRevision = revision;
11316
- }
11317
- }
11318
- const { left, top, right, bottom, width, height } = layout;
11079
+ const { left, top, right, bottom, width, height } = this._ctx.nativeScene.getLayout(this, true);
11319
11080
  return { left, top, right, bottom, width, height };
11320
11081
  }
11321
11082
  setMeasureFunc(measure) {
@@ -11608,7 +11369,7 @@ class Renderable2 extends BaseRenderable2 {
11608
11369
  onLayoutResize(width, height) {
11609
11370
  if (this._visible) {
11610
11371
  this.handleFrameBufferResize(width, height);
11611
- this.onResize(width, height);
11372
+ this._hooks.onResize.call(this, width, height);
11612
11373
  this.requestRender();
11613
11374
  }
11614
11375
  }
@@ -11645,8 +11406,6 @@ class Renderable2 extends BaseRenderable2 {
11645
11406
  if (this._ctx.nativeScene !== child._ctx.nativeScene) {
11646
11407
  throw new Error("Cannot move renderables between native scenes");
11647
11408
  }
11648
- if (!child.isDestroyed)
11649
- this._ctx.nativeScene.refreshPendingHooks(child);
11650
11409
  let previous = child.parent;
11651
11410
  if (previous && previous !== this && previous.remove !== Renderable2.prototype.remove) {
11652
11411
  previous.remove(child);
@@ -11876,252 +11635,123 @@ class Renderable2 extends BaseRenderable2 {
11876
11635
  return;
11877
11636
  this._ctx.nativeScene.setPaint(this, paint);
11878
11637
  }
11879
- static nativeSceneMethods = nativeSceneMethodNames.map((name) => {
11880
- const normalize = (value) => {
11881
- if (name === "selectable")
11882
- return value;
11883
- if (name === "onLifecyclePass")
11884
- value ??= null;
11885
- else if (name === "renderBefore" || name === "renderAfter")
11886
- value ??= undefined;
11887
- else if (name === "onUpdate")
11888
- value ??= nativeSceneMethodDefaults.onUpdate;
11889
- if (typeof value !== "function" && !((name === "renderBefore" || name === "renderAfter" || name === "onLifecyclePass") && value == null))
11890
- throw new TypeError(`Invalid ${name} hook`);
11891
- return value;
11892
- };
11893
- return {
11894
- name,
11895
- normalize,
11896
- descriptor: {
11897
- configurable: true,
11898
- get() {
11899
- const methods = this._nativeSceneMethods;
11900
- if (methods && name in methods)
11901
- return methods[name];
11902
- return nativeSceneMethodDefaults[name];
11903
- },
11904
- set(value) {
11905
- if (name === "selectable") {
11906
- if (this.isFreed())
11907
- return;
11908
- this.assertMutable();
11909
- this.ensureNativeSceneMethods()[name] = value;
11910
- return;
11911
- }
11912
- value = normalize(value);
11913
- if (value === this[name])
11914
- return;
11915
- this.setNativeSceneHooks(this._nativeSceneHookFlags, { [name]: value });
11916
- this.ensureNativeSceneMethods()[name] = value;
11917
- if (name === "onLifecyclePass") {
11918
- if (!value)
11919
- this._ctx.unregisterLifecyclePass(this);
11920
- else if (this.parent)
11921
- this._ctx.registerLifecyclePass(this);
11922
- else
11923
- this._ctx.nativeScene.lifecyclePasses.refresh(this);
11924
- }
11925
- }
11926
- }
11927
- };
11928
- });
11929
11638
  static {
11930
- const prototype = this.prototype;
11931
- nativeSceneMethodDefaults.renderSelf = prototype.renderSelf;
11932
- nativeSceneMethodDefaults.onResize = prototype.onResize;
11933
- nativeSceneMethodDefaults.onLayoutResize = prototype.onLayoutResize;
11934
- nativeSceneMethodDefaults.onUpdate = prototype.onUpdate;
11935
- for (const method of this.nativeSceneMethods) {
11936
- if (method.name === "renderSelf" || method.name === "onResize" || method.name === "onLayoutResize" || method.name === "onUpdate") {
11937
- this.installNativeSceneMethod(prototype, method, nativeSceneMethodDefaults[method.name]);
11938
- } else {
11939
- Object.defineProperty(prototype, method.name, method.descriptor);
11940
- }
11941
- }
11942
- }
11943
- static defineNativeIntegration(integration) {
11944
- for (const method of Renderable2.nativeSceneMethods) {
11945
- let prototype = this.prototype;
11946
- while (prototype) {
11947
- const descriptor = Object.getOwnPropertyDescriptor(prototype, method.name);
11948
- if (descriptor) {
11949
- if ("value" in descriptor)
11950
- this.installNativeSceneMethod(this.prototype, method, descriptor.value);
11951
- break;
11952
- }
11953
- prototype = Object.getPrototypeOf(prototype);
11954
- }
11955
- }
11956
- return integration;
11957
- }
11958
- static installNativeSceneMethod(prototype, method, handler) {
11959
- const instance = {
11960
- ...method.descriptor,
11961
- get() {
11962
- const methods = this._nativeSceneMethods;
11963
- return methods && method.name in methods ? methods[method.name] : handler;
11964
- }
11965
- };
11966
- Object.defineProperty(prototype, method.name, {
11639
+ Object.defineProperty(this.prototype, "selectable", {
11967
11640
  configurable: true,
11968
11641
  get() {
11969
- return handler;
11642
+ return this._selectable;
11970
11643
  },
11971
11644
  set(value) {
11972
- Object.defineProperty(this, method.name, instance);
11973
- method.descriptor.set.call(this, value);
11645
+ if (this.isFreed())
11646
+ return;
11647
+ this.assertMutable();
11648
+ this._selectable = value;
11974
11649
  }
11975
11650
  });
11976
11651
  }
11652
+ static normalizeHook(name, value) {
11653
+ if (value == null && name !== "renderSelf" && name !== "onResize" && name !== "onLayoutResize") {
11654
+ return name === "onUpdate" ? Renderable2.baseHooks.onUpdate : name === "onLifecyclePass" ? null : undefined;
11655
+ }
11656
+ if (typeof value !== "function")
11657
+ throw new TypeError(`Invalid ${name} hook`);
11658
+ return value;
11659
+ }
11660
+ setHook(name, value) {
11661
+ value = Renderable2.normalizeHook(name, value);
11662
+ if (value === this._hooks[name])
11663
+ return;
11664
+ const hooks = { ...this._hooks, [name]: value };
11665
+ if (name !== "onLifecyclePass")
11666
+ return this.publishHooks(hooks);
11667
+ this._hooks = hooks;
11668
+ this.syncLifecyclePass();
11669
+ }
11670
+ syncLifecyclePass() {
11671
+ if (!this.onLifecyclePass)
11672
+ this._ctx.unregisterLifecyclePass(this);
11673
+ else if (this.parent)
11674
+ this._ctx.registerLifecyclePass(this);
11675
+ else
11676
+ this._ctx.nativeScene.lifecyclePasses.refresh(this);
11677
+ }
11977
11678
  refreshHooks() {
11978
11679
  if (this._isDestroyed)
11979
11680
  return;
11980
11681
  this.assertMutable();
11981
- try {
11982
- this._scanNativeSceneHooks();
11983
- } catch (error) {
11984
- this._ctx.nativeScene.scheduleHookScan(this);
11985
- throw error;
11682
+ const hooks = {};
11683
+ for (const name of hookNames)
11684
+ hooks[name] = Renderable2.normalizeHook(name, this[name]);
11685
+ this.publishHooks(hooks);
11686
+ for (const name of ["renderBefore", "renderAfter", "onLifecyclePass"]) {
11687
+ if (!Object.hasOwn(this, name))
11688
+ continue;
11689
+ delete this[name];
11690
+ if (this[name] !== hooks[name])
11691
+ Reflect.set(this, name, hooks[name]);
11986
11692
  }
11693
+ this.syncLifecyclePass();
11694
+ this._refreshNativeSceneSurface();
11987
11695
  this.requestRender();
11988
11696
  }
11989
- _scanNativeSceneHooks() {
11990
- if (!this._isDestroyed)
11991
- this.refreshNativeSceneMethods();
11992
- }
11993
- ensureNativeSceneMethods() {
11994
- return this._nativeSceneMethods ??= {};
11995
- }
11996
- nativeSceneNeedsHookPublish() {
11997
- if (this.buffered)
11998
- return true;
11999
- if (!this.usesNativeDrawing(this.renderSelf))
12000
- return true;
12001
- if (this.hostUpdateFlags(this.onUpdate) !== 0)
12002
- return true;
12003
- const onResize = this.onResize;
12004
- const onLayoutResize = this.onLayoutResize;
12005
- if (onLayoutResize !== nativeSceneMethodDefaults.onLayoutResize)
12006
- return true;
12007
- if (!this._nativeSceneHooksRegistered && this.nativeIntegration.beforeAfter !== false && (this.renderBefore || this.renderAfter))
12008
- return true;
12009
- return this.needsHostResize(onResize);
12010
- }
12011
11697
  usesNativeDrawing(renderSelf) {
12012
11698
  const body = this.nativeIntegration.body;
12013
11699
  return typeof body === "object" && "native" in body && (!this.buffered || body.buffered === true) && renderSelf === body.native;
12014
11700
  }
12015
11701
  needsHostResize(onResize) {
12016
11702
  const resize = this.nativeIntegration.lifecycle?.resize;
12017
- return onResize !== nativeSceneMethodDefaults.onResize && onResize !== resize?.native;
11703
+ return onResize !== Renderable2.baseHooks.onResize && onResize !== resize?.native;
12018
11704
  }
12019
11705
  hostUpdateFlags(onUpdate) {
12020
11706
  const update = this.nativeIntegration.lifecycle?.update;
12021
11707
  if (update && onUpdate === update.idle) {
12022
11708
  return update.active(this) ? NativeSceneHook2.Update : NativeSceneHook2.IdleUpdate;
12023
11709
  }
12024
- return onUpdate === nativeSceneMethodDefaults.onUpdate ? 0 : NativeSceneHook2.Update;
12025
- }
12026
- refreshNativeSceneMethods() {
12027
- this._refreshNativeSceneSurface();
12028
- const methods = Renderable2.nativeSceneMethods;
12029
- for (let index = 0;index < methods.length; index++) {
12030
- const method = methods[index];
12031
- const name = method.name;
12032
- const own = Object.getOwnPropertyDescriptor(this, name);
12033
- if (own?.set === method.descriptor.set)
12034
- continue;
12035
- const handler = method.normalize(this[name]);
12036
- if (!own && handler === nativeSceneMethodDefaults[name])
12037
- continue;
12038
- this.ensureNativeSceneMethods()[name] = handler;
12039
- Object.defineProperty(this, name, method.descriptor);
12040
- if (own)
12041
- this._nativeSceneMethodsPending = true;
12042
- }
12043
- if (this._nativeSceneMethodsPending) {
12044
- this.setNativeSceneHooks(this._nativeSceneHookFlags, {
12045
- onResize: this.onResize,
12046
- onLayoutResize: this.onLayoutResize
12047
- });
12048
- if (!this.onLifecyclePass)
12049
- this._ctx.unregisterLifecyclePass(this);
12050
- else if (this.parent)
12051
- this._ctx.registerLifecyclePass(this);
12052
- else
12053
- this._ctx.nativeScene.lifecyclePasses.refresh(this);
12054
- this._nativeSceneMethodsPending = false;
12055
- }
11710
+ return onUpdate === Renderable2.baseHooks.onUpdate ? 0 : NativeSceneHook2.Update;
12056
11711
  }
12057
11712
  refreshNativeSceneHooks() {
12058
- this.setNativeSceneHooks(this._nativeSceneHookFlags);
11713
+ this.publishHooks(this._hooks);
12059
11714
  }
12060
11715
  _refreshNativeSceneSurface() {}
12061
- setNativeSceneHooks(flags, overrides = {}, lineInfo) {
12062
- if (this.isFreed())
12063
- return;
12064
- const scene = this._ctx.nativeScene;
12065
- const previousFlags = this._nativeSceneHookFlags;
12066
- const previousGeneration = this._nativeSceneHookGeneration;
12067
- const method = (name) => (name in overrides) ? overrides[name] : this[name];
12068
- const onUpdate = method("onUpdate");
12069
- flags = flags & ~nativeSceneHookHostMethods | (method("renderBefore") ? NativeSceneHook2.RenderBefore : 0) | (method("renderAfter") ? NativeSceneHook2.RenderAfter : 0);
12070
- const renderSelf = method("renderSelf");
12071
- if (!this.usesNativeDrawing(renderSelf))
12072
- flags |= NativeSceneHook2.RenderSelf;
12073
- const overridden = ("onUpdate" in overrides ? nativeSceneHookUpdates : 0) | ("onResize" in overrides || "onLayoutResize" in overrides ? NativeSceneHook2.Resize : 0) | ("renderBefore" in overrides ? NativeSceneHook2.RenderBefore : 0) | ("renderAfter" in overrides ? NativeSceneHook2.RenderAfter : 0) | ("renderSelf" in overrides ? NativeSceneHook2.RenderSelf : 0);
12074
- const changed = (previousFlags ^ this._nativeSceneHookFlags) & ~overridden;
12075
- flags = flags & ~changed | this._nativeSceneHookFlags & changed;
12076
- const resizeCallbacks = {
12077
- onResize: "onResize" in overrides ? overrides.onResize : this._nativeSceneResizeCallbacks?.onResize ?? this.onResize,
12078
- onLayoutResize: "onLayoutResize" in overrides ? overrides.onLayoutResize : this._nativeSceneResizeCallbacks?.onLayoutResize ?? this.onLayoutResize
12079
- };
12080
- const resize = this.buffered || resizeCallbacks.onLayoutResize !== Renderable2.prototype.onLayoutResize || this.needsHostResize(resizeCallbacks.onResize);
12081
- if (this._nativeSceneResize !== resize)
12082
- flags = flags & ~NativeSceneHook2.Resize | (this._sizeChangeListener || this.listenerCount("resize") ? NativeSceneHook2.Resize : 0);
12083
- if (resize)
12084
- flags |= NativeSceneHook2.Resize;
12085
- lineInfo ??= !!this.nativeIntegration.lineInfo && this.listenerCount("line-info-change") > 0;
12086
- const update = "onUpdate" in overrides || previousGeneration === this._nativeSceneHookGeneration ? this.hostUpdateFlags(onUpdate) : this._nativeSceneHookFlags & nativeSceneHookUpdates;
12087
- flags = flags & ~nativeSceneHookUpdates | update;
12088
- const generation = this._nativeSceneHookGeneration + 1n;
12089
- if (flags !== 0 || lineInfo || this._nativeSceneHooksRegistered) {
12090
- let nativeFlags = flags;
12091
- if (this.nativeIntegration.beforeAfter === false) {
12092
- nativeFlags &= ~nativeSceneHookBeforeAfter;
12093
- }
12094
- const nativeResize = this.nativeIntegration.lifecycle?.resize;
12095
- if (!resize && nativeResize) {
12096
- nativeFlags = nativeFlags & ~NativeSceneHook2.Resize | (lineInfo && this.nativeIntegration.lineInfo ? NativeSceneHook2.Resize : 0);
12097
- }
12098
- if (nativeFlags & NativeSceneHook2.RenderSelf)
12099
- nativeFlags |= NativeSceneHook2.RenderAfter;
12100
- scene.setHooks(this, nativeFlags, generation, this.styledDimension("width"), this.styledDimension("height"));
12101
- this._nativeSceneHooksRegistered = true;
12102
- }
12103
- this._nativeSceneResizeCallbacks = resize ? resizeCallbacks : undefined;
12104
- this._nativeSceneResize = resize;
12105
- this._nativeSceneHookFlags = flags;
12106
- this._nativeSceneHookGeneration = generation;
11716
+ publishHooks(hooks, pending = {}) {
11717
+ if (!this.isFreed()) {
11718
+ const integration = this.nativeIntegration;
11719
+ const resize = this.buffered || hooks.onLayoutResize !== Renderable2.baseHooks.onLayoutResize || this.needsHostResize(hooks.onResize);
11720
+ const sizeChange = "sizeChange" in pending ? pending.sizeChange : this._sizeChangeListener;
11721
+ const lineInfo = pending.lineInfo ?? (!!integration.lineInfo && this.listenerCount("line-info-change") > 0);
11722
+ const flags = (hooks.renderBefore ? NativeSceneHook2.RenderBefore : 0) | (hooks.renderAfter ? NativeSceneHook2.RenderAfter : 0) | (this.usesNativeDrawing(hooks.renderSelf) ? 0 : NativeSceneHook2.RenderSelf) | this.hostUpdateFlags(hooks.onUpdate) | (resize || sizeChange || (pending.resize ?? this.listenerCount("resize")) > 0 ? NativeSceneHook2.Resize : 0) | ((pending.layout ?? this.listenerCount("layout-changed" /* LAYOUT_CHANGED */)) > 0 ? NativeSceneHook2.LayoutChanged : 0);
11723
+ const generation = this._nativeSceneHookGeneration + 1n;
11724
+ if (flags !== 0 || lineInfo || this._nativeSceneHooksRegistered) {
11725
+ let nativeFlags = flags;
11726
+ if (integration.beforeAfter === false)
11727
+ nativeFlags &= ~nativeSceneHookBeforeAfter;
11728
+ if (!resize && integration.lifecycle?.resize) {
11729
+ nativeFlags = nativeFlags & ~NativeSceneHook2.Resize | (lineInfo && integration.lineInfo ? NativeSceneHook2.Resize : 0);
11730
+ }
11731
+ if (nativeFlags & NativeSceneHook2.RenderSelf)
11732
+ nativeFlags |= NativeSceneHook2.RenderAfter;
11733
+ const scene = this._ctx.nativeScene;
11734
+ scene.setHooks(this, nativeFlags, generation, this.styledDimension("width"), this.styledDimension("height"));
11735
+ this._nativeSceneHooksRegistered = true;
11736
+ }
11737
+ this._nativeSceneResize = resize;
11738
+ this._nativeSceneHookGeneration = generation;
11739
+ }
11740
+ this._hooks = hooks;
12107
11741
  }
12108
11742
  _runNativeSceneHook(request, deltaTime) {
12109
11743
  if (this._isDestroyed || request.hookGeneration !== this._nativeSceneHookGeneration)
12110
11744
  return;
12111
- const previousLayout = this._nativeSceneHookLayout;
12112
- const revision = this._ctx.nativeScene.currentGeometryRevision;
12113
- const currentGeometry = request.geometryRevision === revision;
12114
- this._nativeSceneHookLayout = { revision, layout: currentGeometry ? request.publicLayout : undefined };
11745
+ this.observeLayout(request.publicLayout);
11746
+ this._paintLayout = request.paintLayout;
12115
11747
  try {
12116
11748
  switch (request.kind) {
12117
11749
  case NativeSceneFrame2.Update:
12118
- this.onUpdate(deltaTime);
11750
+ this._hooks.onUpdate.call(this, deltaTime);
12119
11751
  break;
12120
11752
  case NativeSceneFrame2.Resize:
12121
11753
  if (this._nativeSceneResize) {
12122
- this._nativeSceneHookLayout.paintLayout = currentGeometry && request.paintLayout || this._ctx.nativeScene.getLayout(this, "paint");
12123
- this._nativeSceneHookLayout.paintRevision = revision;
12124
- this.onLayoutResize(request.width, request.height);
11754
+ this._hooks.onLayoutResize.call(this, request.width, request.height);
12125
11755
  } else {
12126
11756
  const resize = this.nativeIntegration.lifecycle?.resize;
12127
11757
  if (!resize) {
@@ -12138,25 +11768,19 @@ class Renderable2 extends BaseRenderable2 {
12138
11768
  break;
12139
11769
  }
12140
11770
  } finally {
12141
- this._nativeSceneHookLayout = previousLayout;
11771
+ this._paintLayout = undefined;
12142
11772
  }
12143
11773
  }
12144
- _recordNativeScenePaint(slot, index, deltaTime, frame, recorder, geometryRevision) {
11774
+ _recordNativeScenePaint(slot, index, deltaTime, frame, recorder, publicLayout) {
12145
11775
  if (this._isDestroyed)
12146
11776
  return;
12147
- const previousLayout = this._nativeSceneHookLayout;
12148
- const revision = this._ctx.nativeScene.currentGeometryRevision;
12149
- this._nativeSceneHookLayout = {
12150
- revision,
12151
- layout: geometryRevision === revision ? slot.publicLayout : undefined,
12152
- paintLayout: slot.paintLayout,
12153
- paintRevision: revision
12154
- };
11777
+ this.observeLayout(publicLayout);
11778
+ this._paintLayout = slot.paintLayout;
12155
11779
  const buffer = this.nativeIntegration.paintBuffer !== "destination" && this.nativeIntegration.bufferComposition !== "native" && this.buffered && this.frameBuffer ? this.frameBuffer : frame;
12156
11780
  try {
12157
11781
  if (slot.hooks & NativeSceneHook2.RenderBefore) {
12158
11782
  recorder.slot(index, NativeScenePaintPhase2.Before, slot.opacity);
12159
- this.renderBefore?.call(this, buffer, deltaTime);
11783
+ this._hooks.renderBefore?.call(this, buffer, deltaTime);
12160
11784
  if (this._isDestroyed)
12161
11785
  return;
12162
11786
  }
@@ -12171,18 +11795,18 @@ class Renderable2 extends BaseRenderable2 {
12171
11795
  if (slot.hooks & NativeSceneHook2.RenderAfter) {
12172
11796
  recorder.slot(index, NativeScenePaintPhase2.After, slot.opacity);
12173
11797
  if (this.nativeIntegration.beforeAfter !== false) {
12174
- this.renderAfter?.call(this, buffer, deltaTime);
11798
+ this._hooks.renderAfter?.call(this, buffer, deltaTime);
12175
11799
  this.markClean();
12176
11800
  }
12177
11801
  if (!this._isDestroyed && this.nativeIntegration.bufferComposition !== "native" && this.buffered && this.frameBuffer)
12178
11802
  frame.drawFrameBuffer(Math.trunc(this._screenX), Math.trunc(this._screenY), this.frameBuffer);
12179
11803
  }
12180
11804
  } finally {
12181
- this._nativeSceneHookLayout = previousLayout;
11805
+ this._paintLayout = undefined;
12182
11806
  }
12183
11807
  }
12184
11808
  _invokeNativePaint(buffer, deltaTime) {
12185
- this.renderSelf(buffer, deltaTime);
11809
+ this._hooks.renderSelf.call(this, buffer, deltaTime);
12186
11810
  }
12187
11811
  get isDestroyed() {
12188
11812
  return this._isDestroyed;
@@ -12416,14 +12040,12 @@ class Renderable2 extends BaseRenderable2 {
12416
12040
  else
12417
12041
  layout += delta;
12418
12042
  }
12419
- this.setNativeSceneHooks(this._nativeSceneHookFlags & ~nativeSceneHookListeners | (resize > 0 || this._sizeChangeListener ? NativeSceneHook2.Resize : 0) | (layout > 0 ? NativeSceneHook2.LayoutChanged : 0), {}, lineInfo > 0);
12043
+ this.publishHooks(this._hooks, { resize, layout, lineInfo: lineInfo > 0 });
12420
12044
  this.runCleanup((run) => {
12421
12045
  run(change);
12422
12046
  run(() => {
12423
- if (!this._isDestroyed) {
12424
- const flags = this._nativeSceneHookFlags & ~nativeSceneHookListeners | (this.listenerCount("resize") > 0 || this._sizeChangeListener ? NativeSceneHook2.Resize : 0) | (this.listenerCount("layout-changed" /* LAYOUT_CHANGED */) > 0 ? NativeSceneHook2.LayoutChanged : 0);
12425
- this.setNativeSceneHooks(flags);
12426
- }
12047
+ if (!this._isDestroyed)
12048
+ this.publishHooks(this._hooks);
12427
12049
  });
12428
12050
  });
12429
12051
  return this;
@@ -12508,8 +12130,7 @@ class Renderable2 extends BaseRenderable2 {
12508
12130
  if (handler !== this._sizeChangeListener) {
12509
12131
  if (handler != null && typeof handler !== "function")
12510
12132
  throw new TypeError("Invalid size change hook");
12511
- const flags = this._nativeSceneHookFlags & ~NativeSceneHook2.Resize;
12512
- this.setNativeSceneHooks(flags | (handler || this.listenerCount("resize") > 0 ? NativeSceneHook2.Resize : 0));
12133
+ this.publishHooks(this._hooks, { sizeChange: handler });
12513
12134
  }
12514
12135
  this._sizeChangeListener = handler;
12515
12136
  }
@@ -12534,11 +12155,10 @@ class Renderable2 extends BaseRenderable2 {
12534
12155
  }
12535
12156
 
12536
12157
  class RootRenderable2 extends Renderable2 {
12537
- static nativeIntegration = this.defineNativeIntegration({
12158
+ static nativeIntegration = {
12538
12159
  ...Renderable2.nativeIntegration,
12539
- kind: "root",
12540
- construction: "prototype"
12541
- });
12160
+ kind: "root"
12161
+ };
12542
12162
  _currentRenderable;
12543
12163
  constructor(ctx) {
12544
12164
  super(ctx, {
@@ -12664,7 +12284,6 @@ function maybeMakeRenderable2(ctx, node) {
12664
12284
  function wrapWithDelegates2(instance, delegateMap) {
12665
12285
  if (!delegateMap || Object.keys(delegateMap).length === 0)
12666
12286
  return instance;
12667
- instance.refreshHooks();
12668
12287
  const getDescendant = (id) => {
12669
12288
  return instance.findDescendantById(id);
12670
12289
  };
@@ -14225,11 +13844,10 @@ function borderMask(sides) {
14225
13844
  }
14226
13845
 
14227
13846
  class BoxRenderable2 extends Renderable2 {
14228
- static nativeIntegration = this.defineNativeIntegration({
13847
+ static nativeIntegration = {
14229
13848
  kind: "box",
14230
- body: { native: this.prototype.renderSelf },
14231
- construction: "prototype"
14232
- });
13849
+ body: { native: this.prototype.renderSelf }
13850
+ };
14233
13851
  _backgroundColor;
14234
13852
  _border;
14235
13853
  _borderStyle;
@@ -14454,8 +14072,8 @@ class BoxRenderable2 extends Renderable2 {
14454
14072
  buffer.drawBox({
14455
14073
  x: screenX,
14456
14074
  y: screenY,
14457
- width: this.width,
14458
- height: this.height,
14075
+ width: this._paintWidth,
14076
+ height: this._paintHeight,
14459
14077
  borderStyle: this._borderStyle,
14460
14078
  customBorderChars: this._customBorderChars,
14461
14079
  border: this._border,
@@ -14523,16 +14141,31 @@ class BoxRenderable2 extends Renderable2 {
14523
14141
  }
14524
14142
  }
14525
14143
 
14144
+ // src/lib/scroll-chain.ts
14145
+ var takers = new WeakMap;
14146
+ function wheelDirection(event) {
14147
+ const direction = event.scroll?.direction;
14148
+ if (!direction || !event.modifiers?.shift)
14149
+ return direction;
14150
+ return direction === "up" ? "left" : direction === "down" ? "right" : direction === "right" ? "down" : "up";
14151
+ }
14152
+ function scrollOnce(event, scroller, scroll) {
14153
+ for (let node = takers.get(event) ?? null;node; node = node.parent)
14154
+ if (node === scroller)
14155
+ return;
14156
+ if (scroll())
14157
+ takers.set(event, scroller);
14158
+ }
14159
+
14526
14160
  // src/renderables/TextBufferRenderable.ts
14527
14161
  class TextBufferRenderable2 extends Renderable2 {
14528
- static nativeIntegration = this.defineNativeIntegration({
14162
+ static nativeIntegration = {
14529
14163
  kind: "text",
14530
14164
  body: { native: this.prototype.renderSelf },
14531
14165
  lifecycle: { resize: { native: this.prototype.onResize } },
14532
14166
  beforeAfter: false,
14533
- paintBuffer: "destination",
14534
- construction: "prototype"
14535
- });
14167
+ paintBuffer: "destination"
14168
+ };
14536
14169
  _defaultFg;
14537
14170
  _defaultBg;
14538
14171
  _defaultAttributes;
@@ -14549,7 +14182,6 @@ class TextBufferRenderable2 extends Renderable2 {
14549
14182
  _firstLineOffset = 0;
14550
14183
  textBuffer;
14551
14184
  textBufferView;
14552
- _textBufferSyntaxStyle;
14553
14185
  nativeTextScene;
14554
14186
  _defaultOptions = {
14555
14187
  fg: RGBA2.fromValues(1, 1, 1, 1),
@@ -14569,7 +14201,6 @@ class TextBufferRenderable2 extends Renderable2 {
14569
14201
  this.nativeTextScene = sharedText ? undefined : ctx.nativeScene;
14570
14202
  let textBuffer;
14571
14203
  let textBufferView;
14572
- let syntaxStyle;
14573
14204
  try {
14574
14205
  this._defaultFg = RGBA2.clone(parseColor2(options.fg ?? this._defaultOptions.fg));
14575
14206
  this._defaultBg = RGBA2.clone(parseColor2(options.bg ?? this._defaultOptions.bg));
@@ -14593,9 +14224,6 @@ class TextBufferRenderable2 extends Renderable2 {
14593
14224
  textBufferView = TextBufferView2.create(textBuffer);
14594
14225
  this.textBufferView = textBufferView;
14595
14226
  this._firstLineOffset = ctx.claimFirstLineOffset?.(this) ?? 0;
14596
- syntaxStyle = SyntaxStyle2.create(ctx.nativeScene);
14597
- this._textBufferSyntaxStyle = syntaxStyle;
14598
- textBuffer.setSyntaxStyle(syntaxStyle);
14599
14227
  this.textBufferView.setWrapMode(this._wrapMode);
14600
14228
  this.textBufferView.setTextAlign(this._textAlign);
14601
14229
  this.textBufferView.setFirstLineOffset(this._firstLineOffset);
@@ -14616,8 +14244,6 @@ class TextBufferRenderable2 extends Renderable2 {
14616
14244
  this.updateTextInfo();
14617
14245
  } catch (error) {
14618
14246
  this.abortConstruction(error, (run) => {
14619
- run(() => textBuffer?.setSyntaxStyle(null));
14620
- run(() => syntaxStyle?.destroy());
14621
14247
  run(() => textBufferView?.destroy());
14622
14248
  run(() => textBuffer?.destroy());
14623
14249
  });
@@ -14625,19 +14251,24 @@ class TextBufferRenderable2 extends Renderable2 {
14625
14251
  }
14626
14252
  onMouseEvent(event) {
14627
14253
  if (event.type === "scroll") {
14628
- this.handleScroll(event);
14254
+ scrollOnce(event, this, () => {
14255
+ const [x, y] = [this.scrollX, this.scrollY];
14256
+ this.handleScroll(event);
14257
+ return this.scrollX !== x || this.scrollY !== y;
14258
+ });
14629
14259
  }
14630
14260
  }
14631
14261
  handleScroll(event) {
14632
14262
  if (!event.scroll)
14633
14263
  return;
14634
- const { direction, delta } = event.scroll;
14264
+ const { delta } = event.scroll;
14265
+ const direction = wheelDirection(event);
14635
14266
  if (direction === "up") {
14636
14267
  this.scrollY -= delta;
14637
14268
  } else if (direction === "down") {
14638
14269
  this.scrollY += delta;
14639
14270
  }
14640
- if (this._wrapMode === "none") {
14271
+ if (this._wrapMode === "none" && !this._truncate) {
14641
14272
  if (direction === "left") {
14642
14273
  this.scrollX -= delta;
14643
14274
  } else if (direction === "right") {
@@ -14835,6 +14466,8 @@ class TextBufferRenderable2 extends Renderable2 {
14835
14466
  if (width > 0)
14836
14467
  this.textBufferView.setWrapWidth(Math.trunc(width));
14837
14468
  }
14469
+ if (value !== "none")
14470
+ this.scrollX = 0;
14838
14471
  this.requestRender();
14839
14472
  });
14840
14473
  }
@@ -14894,6 +14527,8 @@ class TextBufferRenderable2 extends Renderable2 {
14894
14527
  if (!this.nativeTextScene)
14895
14528
  this.textBufferView.setTruncate(value);
14896
14529
  this._truncate = value;
14530
+ if (value)
14531
+ this.scrollX = 0;
14897
14532
  this.requestRender();
14898
14533
  });
14899
14534
  }
@@ -14977,8 +14612,6 @@ class TextBufferRenderable2 extends Renderable2 {
14977
14612
  if (this.nativeTextScene)
14978
14613
  return;
14979
14614
  this.runCleanup((run) => {
14980
- run(() => this.textBuffer.setSyntaxStyle(null));
14981
- run(() => this._textBufferSyntaxStyle.destroy());
14982
14615
  run(() => this.textBufferView.destroy());
14983
14616
  run(() => this.textBuffer.destroy());
14984
14617
  });
@@ -15006,7 +14639,7 @@ class TextBufferRenderable2 extends Renderable2 {
15006
14639
 
15007
14640
  // src/renderables/Code.ts
15008
14641
  class CodeRenderable2 extends TextBufferRenderable2 {
15009
- static nativeIntegration = this.defineNativeIntegration({
14642
+ static nativeIntegration = {
15010
14643
  ...TextBufferRenderable2.nativeIntegration,
15011
14644
  kind: "text_view",
15012
14645
  body: { native: this.prototype.renderSelf },
@@ -15017,7 +14650,7 @@ class CodeRenderable2 extends TextBufferRenderable2 {
15017
14650
  active: (renderable) => renderable._highlightsDirty
15018
14651
  }
15019
14652
  }
15020
- });
14653
+ };
15021
14654
  _content;
15022
14655
  _filetype;
15023
14656
  _syntaxStyle;
@@ -16185,12 +15818,11 @@ function pixelResolution(ctx) {
16185
15818
  }
16186
15819
 
16187
15820
  class ImageRenderable2 extends Renderable2 {
16188
- static nativeIntegration = this.defineNativeIntegration({
15821
+ static nativeIntegration = {
16189
15822
  kind: "image",
16190
15823
  body: { native: this.prototype.renderSelf, buffered: true },
16191
- bufferComposition: "native",
16192
- construction: "prototype"
16193
- });
15824
+ bufferComposition: "native"
15825
+ };
16194
15826
  _source;
16195
15827
  _image = null;
16196
15828
  _pendingImage = null;
@@ -16331,15 +15963,17 @@ class ImageRenderable2 extends Renderable2 {
16331
15963
  }
16332
15964
  }
16333
15965
  renderSelf(buffer) {
16334
- if (!this._image || this.width <= 0 || this.height <= 0)
15966
+ const width = this._paintWidth;
15967
+ const height = this._paintHeight;
15968
+ if (!this._image || width <= 0 || height <= 0)
16335
15969
  return;
16336
- const fitted = this._fit === "cover" ? { width: this.width, height: this.height } : this.getFittedSize(this.width, this.height);
15970
+ const fitted = this._fit === "cover" ? { width, height } : this.getFittedSize(width, height);
16337
15971
  if (fitted.width <= 0 || fitted.height <= 0)
16338
15972
  return;
16339
15973
  const originX = this.buffered ? 0 : this._screenX;
16340
15974
  const originY = this.buffered ? 0 : this._screenY;
16341
- const x = originX + Math.floor((this.width - fitted.width) / 2);
16342
- const y = originY + Math.floor((this.height - fitted.height) / 2);
15975
+ const x = originX + Math.floor((width - fitted.width) / 2);
15976
+ const y = originY + Math.floor((height - fitted.height) / 2);
16343
15977
  const resolution = pixelResolution(this._ctx);
16344
15978
  const pixelWidth = resolution ? Math.max(1, Math.round(fitted.width * resolution.width / this._ctx.terminalWidth)) : 0;
16345
15979
  const pixelHeight = resolution ? Math.max(1, Math.round(fitted.height * resolution.height / this._ctx.terminalHeight)) : 0;
@@ -16348,7 +15982,7 @@ class ImageRenderable2 extends Renderable2 {
16348
15982
  let sourceWidth = this._image.width;
16349
15983
  let sourceHeight = this._image.height;
16350
15984
  if (this._fit === "cover") {
16351
- const targetAspect = this.width / (this.height * this.cellAspectRatio);
15985
+ const targetAspect = width / (height * this.cellAspectRatio);
16352
15986
  const sourceAspect = sourceWidth / sourceHeight;
16353
15987
  if (sourceAspect > targetAspect) {
16354
15988
  sourceWidth = Math.max(1, Math.round(sourceHeight * targetAspect));
@@ -16734,10 +16368,10 @@ class RootTextNodeRenderable2 extends TextNodeRenderable2 {
16734
16368
 
16735
16369
  // src/renderables/Text.ts
16736
16370
  class TextRenderable2 extends TextBufferRenderable2 {
16737
- static nativeIntegration = this.defineNativeIntegration({
16371
+ static nativeIntegration = {
16738
16372
  ...TextBufferRenderable2.nativeIntegration,
16739
16373
  lineInfo: true
16740
- });
16374
+ };
16741
16375
  _text;
16742
16376
  _hasManualStyledText = false;
16743
16377
  rootTextNode;
@@ -18855,7 +18489,7 @@ function isEditBufferRenderable2(obj) {
18855
18489
  }
18856
18490
 
18857
18491
  class EditBufferRenderable2 extends Renderable2 {
18858
- static nativeIntegration = this.defineNativeIntegration({
18492
+ static nativeIntegration = {
18859
18493
  kind: "editor",
18860
18494
  body: { native: this.prototype.renderSelf },
18861
18495
  lifecycle: {
@@ -18867,9 +18501,8 @@ class EditBufferRenderable2 extends Renderable2 {
18867
18501
  },
18868
18502
  beforeAfter: false,
18869
18503
  paintBuffer: "destination",
18870
- bufferComposition: "native",
18871
- construction: "prototype"
18872
- });
18504
+ bufferComposition: "native"
18505
+ };
18873
18506
  [BrandedEditBufferRenderable] = true;
18874
18507
  static defaultFocusable = true;
18875
18508
  _traits = {};
@@ -19009,7 +18642,7 @@ class EditBufferRenderable2 extends Renderable2 {
19009
18642
  return this.editorView.getVisualCursor();
19010
18643
  }
19011
18644
  get cursorOffset() {
19012
- return this.visualCursor.offset;
18645
+ return this.editorView.isDestroyed ? emptyVisualCursor.offset : this.editBuffer.getCursorPosition().offset;
19013
18646
  }
19014
18647
  set cursorOffset(offset) {
19015
18648
  this.clearSelection();
@@ -19191,13 +18824,19 @@ class EditBufferRenderable2 extends Renderable2 {
19191
18824
  }
19192
18825
  onMouseEvent(event) {
19193
18826
  if (event.type === "scroll") {
19194
- this.handleScroll(event);
18827
+ scrollOnce(event, this, () => {
18828
+ const before = this.editorView.getViewport();
18829
+ this.handleScroll(event);
18830
+ const after = this.editorView.getViewport();
18831
+ return after.offsetX !== before.offsetX || after.offsetY !== before.offsetY;
18832
+ });
19195
18833
  }
19196
18834
  }
19197
18835
  handleScroll(event) {
19198
18836
  if (!event.scroll)
19199
18837
  return;
19200
- const { direction, delta } = event.scroll;
18838
+ const { delta } = event.scroll;
18839
+ const direction = wheelDirection(event);
19201
18840
  const viewport = this.editorView.getViewport();
19202
18841
  if (direction === "up") {
19203
18842
  const newOffsetY = Math.max(0, viewport.offsetY - delta);
@@ -19216,7 +18855,8 @@ class EditBufferRenderable2 extends Renderable2 {
19216
18855
  this.editorView.setViewport(newOffsetX, viewport.offsetY, viewport.width, viewport.height, true);
19217
18856
  this.requestRender();
19218
18857
  } else if (direction === "right") {
19219
- const newOffsetX = viewport.offsetX + delta;
18858
+ const maxOffsetX = Math.max(0, this.lineInfo.lineWidthColsMax - viewport.width);
18859
+ const newOffsetX = Math.min(viewport.offsetX + delta, Math.max(viewport.offsetX, maxOffsetX));
19220
18860
  this.editorView.setViewport(newOffsetX, viewport.offsetY, viewport.width, viewport.height, true);
19221
18861
  this.requestRender();
19222
18862
  }
@@ -19867,7 +19507,6 @@ class NativeLifecyclePasses extends Set {
19867
19507
  class NativeScene {
19868
19508
  driver;
19869
19509
  renderer;
19870
- workBudget;
19871
19510
  get resourceContext() {
19872
19511
  return this.driver.resourceContext;
19873
19512
  }
@@ -19876,27 +19515,19 @@ class NativeScene {
19876
19515
  nodes = new Map;
19877
19516
  paintedFrame = null;
19878
19517
  paintRecording;
19879
- cancelPaintYield = null;
19880
19518
  destroyed = false;
19881
19519
  destroying = false;
19882
- geometryRevision = 0;
19883
19520
  layoutRevision = 0;
19884
19521
  staging = new SceneStaging;
19885
- hookScans = new Set;
19886
- scanningHooks = false;
19887
19522
  yogaHost;
19888
- constructor(driver, renderer, workBudget) {
19523
+ constructor(driver, renderer) {
19889
19524
  this.driver = driver;
19890
19525
  this.renderer = renderer;
19891
- this.workBudget = workBudget;
19892
19526
  this.yogaHost = driver.renderLib.getYogaHost();
19893
19527
  }
19894
19528
  get frame() {
19895
19529
  return this.paintedFrame;
19896
19530
  }
19897
- get currentGeometryRevision() {
19898
- return this.geometryRevision;
19899
- }
19900
19531
  get observedLayoutRevision() {
19901
19532
  if (this.yogaHost.inCallback || this.destroyed || this.driver.disposed)
19902
19533
  return;
@@ -19905,10 +19536,6 @@ class NativeScene {
19905
19536
  get stopped() {
19906
19537
  return this.destroyed || this.destroying || this.driver.disposed || this.renderer.isDestroyed;
19907
19538
  }
19908
- changeGeometry() {
19909
- this.geometryRevision = this.geometryRevision === Number.MAX_SAFE_INTEGER ? 0 : this.geometryRevision + 1;
19910
- this.changeLayout();
19911
- }
19912
19539
  changeLayout() {
19913
19540
  this.layoutRevision = this.layoutRevision === Number.MAX_SAFE_INTEGER ? 0 : this.layoutRevision + 1;
19914
19541
  }
@@ -19934,54 +19561,6 @@ class NativeScene {
19934
19561
  this.yogaHost.forgetScene(this);
19935
19562
  }
19936
19563
  }
19937
- scheduleHookScan(renderable) {
19938
- if (this.stopped)
19939
- return;
19940
- this.hookScans.add(renderable);
19941
- }
19942
- refreshPendingHooks(renderable) {
19943
- if (this.scanningHooks || !this.hookScans.has(renderable))
19944
- return;
19945
- this.scanningHooks = true;
19946
- try {
19947
- renderable._scanNativeSceneHooks();
19948
- } finally {
19949
- this.scanningHooks = false;
19950
- }
19951
- }
19952
- drainHookScans() {
19953
- if (this.scanningHooks)
19954
- throw new Error("Native scene hook discovery is already active");
19955
- if (this.hookScans.size === 0)
19956
- return;
19957
- this.scanningHooks = true;
19958
- let visits = 0;
19959
- try {
19960
- while (this.hookScans.size !== 0) {
19961
- const pending = this.hookScans;
19962
- this.hookScans = new Set;
19963
- try {
19964
- for (const renderable of pending) {
19965
- if (this.stopped)
19966
- return;
19967
- if (++visits > maxHostRequests)
19968
- throw new Error("Native scene hook discovery work limit exceeded");
19969
- renderable._scanNativeSceneHooks();
19970
- pending.delete(renderable);
19971
- }
19972
- } catch (error) {
19973
- if (!this.stopped) {
19974
- for (const renderable of this.hookScans)
19975
- pending.add(renderable);
19976
- this.hookScans = pending;
19977
- }
19978
- throw error;
19979
- }
19980
- }
19981
- } finally {
19982
- this.scanningHooks = false;
19983
- }
19984
- }
19985
19564
  getRenderables() {
19986
19565
  return this.nodes.values();
19987
19566
  }
@@ -20012,7 +19591,7 @@ class NativeScene {
20012
19591
  const handle = child._getSceneHandle(this);
20013
19592
  const parentHandle = parent?._getSceneHandle(this) ?? null;
20014
19593
  this.driver.renderLib.sceneMoveNode(this.driver.context, handle, parentHandle, index);
20015
- this.changeGeometry();
19594
+ this.changeLayout();
20016
19595
  }
20017
19596
  setViewport(content, viewport) {
20018
19597
  this.flushStaged();
@@ -20036,10 +19615,9 @@ class NativeScene {
20036
19615
  this.staging.discard(handle);
20037
19616
  if (!this.staging.pending)
20038
19617
  this.yogaHost.forgetScene(this);
20039
- this.changeGeometry();
19618
+ this.changeLayout();
20040
19619
  renderable._releaseSceneHandle();
20041
19620
  this.nodes.delete(renderable.num);
20042
- this.hookScans.delete(renderable);
20043
19621
  this.renderer.unregisterLifecyclePass(renderable);
20044
19622
  } catch (error) {
20045
19623
  if (flushFailure) {
@@ -20062,7 +19640,6 @@ class NativeScene {
20062
19640
  if (this.staging.stageStyle(this.driver.context, handle, group, kind, edge, unit, value, flags)) {
20063
19641
  this.yogaHost.stageScene(this);
20064
19642
  }
20065
- this.changeGeometry();
20066
19643
  }
20067
19644
  getStyle(node, group, kind, edge) {
20068
19645
  const handle = node._getSceneHandle(this);
@@ -20102,7 +19679,9 @@ class NativeScene {
20102
19679
  this.flushStaged();
20103
19680
  if (this.staging.stagePaint(this.driver.context, handle, paint, renderable))
20104
19681
  this.yogaHost.stageScene(this);
20105
- this.changeGeometry();
19682
+ const { translateX = renderable.translateX, translateY = renderable.translateY } = paint;
19683
+ if (translateX !== renderable.translateX || translateY !== renderable.translateY)
19684
+ this.changeLayout();
20106
19685
  }
20107
19686
  setBackground(renderable, color) {
20108
19687
  this.yogaHost.assertMutable();
@@ -20225,9 +19804,7 @@ class NativeScene {
20225
19804
  if (!attached)
20226
19805
  owner.add(root);
20227
19806
  try {
20228
- this.drainHookScans();
20229
19807
  this.runLifecyclePasses();
20230
- this.drainHookScans();
20231
19808
  this.assertAlive();
20232
19809
  this.flushStaged();
20233
19810
  try {
@@ -20244,14 +19821,11 @@ class NativeScene {
20244
19821
  paint(deltaTime, getPaintOptions) {
20245
19822
  this.yogaHost.assertMutable();
20246
19823
  this.assertAlive();
20247
- if (this.cancelPaintYield || this.paintedFrame)
19824
+ if (this.paintedFrame)
20248
19825
  throw new Error("Native scene is already painting a frame");
20249
19826
  this.renderer.root._setCurrentRenderable(undefined);
20250
- this.drainHookScans();
20251
19827
  this.runLifecyclePasses();
20252
- const continuation = this.advancePaint(deltaTime, getPaintOptions);
20253
- if (continuation)
20254
- return this.resumePaint(deltaTime, getPaintOptions, continuation);
19828
+ this.advancePaint(deltaTime, getPaintOptions);
20255
19829
  }
20256
19830
  runLifecyclePasses() {
20257
19831
  if (this.renderer.root.visible) {
@@ -20264,67 +19838,29 @@ class NativeScene {
20264
19838
  if (!renderable.isDestroyed) {
20265
19839
  renderable.onLifecyclePass?.call(renderable);
20266
19840
  }
20267
- this.drainHookScans();
20268
19841
  }
20269
19842
  }
20270
19843
  }
20271
- async resumePaint(deltaTime, getPaintOptions, continuation) {
20272
- while (continuation) {
20273
- await continuation.wait;
20274
- this.cancelPaintYield = null;
20275
- if (continuation.interrupted === "restart") {
20276
- this.cancelAttempt(continuation.request);
20277
- this.drainHookScans();
20278
- this.runLifecyclePasses();
20279
- continuation = undefined;
20280
- }
20281
- continuation = this.advancePaint(deltaTime, getPaintOptions, continuation);
20282
- }
20283
- }
20284
- advancePaint(deltaTime, getPaintOptions, continuation) {
20285
- let request = continuation?.request ?? null;
19844
+ advancePaint(deltaTime, getPaintOptions) {
19845
+ let request = null;
20286
19846
  let recording = null;
20287
- let yielded = false;
20288
19847
  try {
20289
- while (continuation?.interrupted !== "cancel" && !this.stopped) {
20290
- this.drainHookScans();
19848
+ while (!this.stopped) {
20291
19849
  const options = { ...getPaintOptions(), maxLayoutRounds, maxHostRequests };
20292
19850
  if (this.stopped || this.renderer.controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */)
20293
19851
  return;
20294
19852
  this.flushStaged();
20295
- const geometryRevision = this.geometryRevision;
20296
19853
  try {
20297
- request = this.driver.renderLib.sceneFrameStep(this.driver.context, this.driver.session, request, options, this.workBudget, recording);
19854
+ request = this.driver.renderLib.sceneFrameStep(this.driver.context, this.driver.session, request, options, recording);
20298
19855
  } finally {
20299
19856
  this.changeLayout();
20300
19857
  this.paintRecording?.recorder.settle();
20301
19858
  }
20302
19859
  recording = null;
20303
- request.geometryRevision = geometryRevision;
20304
19860
  if (request.kind === NativeSceneFrame2.Done) {
20305
19861
  this.paintedFrame = request;
20306
19862
  return;
20307
19863
  }
20308
- if (request.kind === NativeSceneFrame2.Yield) {
20309
- const wait = Promise.withResolvers();
20310
- const state = continuation ?? { request, wait: wait.promise };
20311
- state.request = request;
20312
- state.wait = wait.promise;
20313
- const cancel = this.driver.scheduler.schedule(wait.resolve);
20314
- this.cancelPaintYield = (restart = false) => {
20315
- const first = state.interrupted === undefined;
20316
- state.interrupted = restart && state.interrupted !== "cancel" ? "restart" : "cancel";
20317
- if (!first)
20318
- return;
20319
- try {
20320
- cancel();
20321
- } finally {
20322
- wait.resolve();
20323
- }
20324
- };
20325
- yielded = true;
20326
- return state;
20327
- }
20328
19864
  if (!sameHandle(request.session, this.driver.session) || !sameHandle(request.root, this.renderer.root._getSceneHandle(this))) {
20329
19865
  throw new Error("Native scene returned a stale host request");
20330
19866
  }
@@ -20342,7 +19878,7 @@ class NativeScene {
20342
19878
  }
20343
19879
  } finally {
20344
19880
  this.paintRecording?.recorder.settle();
20345
- if (!yielded && request && request !== this.paintedFrame)
19881
+ if (request && request !== this.paintedFrame)
20346
19882
  this.cancelAttempt(request);
20347
19883
  }
20348
19884
  }
@@ -20358,6 +19894,7 @@ class NativeScene {
20358
19894
  const { renderLib: lib, context, session } = this.driver;
20359
19895
  const slots = lib.sceneFrameGetPaintSlots(context, session, request);
20360
19896
  const paint = this.paintRecording ??= this.createPaintRecording();
19897
+ const revision = this.layoutRevision;
20361
19898
  paint.recorder.begin(context);
20362
19899
  try {
20363
19900
  for (let index = 0;index < slots.length; index++) {
@@ -20371,7 +19908,7 @@ class NativeScene {
20371
19908
  throw new Error("Native scene returned a stale paint slot");
20372
19909
  }
20373
19910
  this.renderer.root._setCurrentRenderable(renderable);
20374
- renderable._recordNativeScenePaint(slot, index, deltaTime, paint.buffer, paint.recorder, request.geometryRevision);
19911
+ renderable._recordNativeScenePaint(slot, index, deltaTime, paint.buffer, paint.recorder, this.layoutRevision === revision ? slot.publicLayout : undefined);
20375
19912
  this.renderer.root._setCurrentRenderable(undefined);
20376
19913
  }
20377
19914
  return paint.recorder.recording;
@@ -20401,18 +19938,11 @@ class NativeScene {
20401
19938
  return result;
20402
19939
  }
20403
19940
  cancelFrame() {
20404
- this.cancelPaintYield?.();
20405
19941
  const frame = this.paintedFrame;
20406
19942
  this.paintedFrame = null;
20407
19943
  if (frame)
20408
19944
  this.cancelAttempt(frame);
20409
19945
  }
20410
- interruptPaint() {
20411
- this.cancelPaintYield?.();
20412
- }
20413
- restartPaint() {
20414
- this.cancelPaintYield?.(true);
20415
- }
20416
19946
  hitTest(x, y) {
20417
19947
  this.assertAlive();
20418
19948
  const id = this.driver.renderLib.sceneHitTest(this.driver.context, this.driver.session, x, y);
@@ -20426,14 +19956,8 @@ class NativeScene {
20426
19956
  this.destroying = true;
20427
19957
  this.staging.clear();
20428
19958
  this.yogaHost.forgetScene(this);
20429
- this.hookScans.clear();
20430
19959
  let failure;
20431
19960
  try {
20432
- try {
20433
- this.cancelPaintYield?.();
20434
- } catch (error) {
20435
- failure = { error };
20436
- }
20437
19961
  for (const renderable of this.nodes.values()) {
20438
19962
  try {
20439
19963
  renderable.destroyRecursively();
@@ -20625,6 +20149,492 @@ function parsePixelResolution(sequence) {
20625
20149
  return null;
20626
20150
  }
20627
20151
 
20152
+ // src/lib/stdin-parser-native.ts
20153
+ import { Buffer as Buffer4 } from "node:buffer";
20154
+ var RECORD_CAPACITY = 64;
20155
+ var PAYLOAD_CAPACITY = 16 * 1024;
20156
+ var RECORD = nativeLayouts.ot_input_event;
20157
+ var FIELD = {
20158
+ kind: RECORD.fields.kind.offset,
20159
+ action: RECORD.fields.action.offset,
20160
+ modifiers: RECORD.fields.modifiers.offset,
20161
+ flags: RECORD.fields.flags.offset,
20162
+ code: RECORD.fields.code.offset / 4,
20163
+ baseCode: RECORD.fields.base_code.offset / 4,
20164
+ x: RECORD.fields.x.offset / 2,
20165
+ y: RECORD.fields.y.offset / 2,
20166
+ rawOffset: RECORD.fields.raw_offset.offset / 4,
20167
+ rawLength: RECORD.fields.raw_len.offset / 4,
20168
+ textOffset: RECORD.fields.text_offset.offset / 4,
20169
+ textLength: RECORD.fields.text_len.offset / 4
20170
+ };
20171
+ var C = nativeConstants;
20172
+ var EMPTY = new Uint8Array(0);
20173
+ var UTF8 = new TextDecoder;
20174
+ var MOUSE_TYPES = {
20175
+ [C.OT_INPUT_MOUSE_DOWN]: "down",
20176
+ [C.OT_INPUT_MOUSE_UP]: "up",
20177
+ [C.OT_INPUT_MOUSE_MOVE]: "move",
20178
+ [C.OT_INPUT_MOUSE_DRAG]: "drag",
20179
+ [C.OT_INPUT_MOUSE_SCROLL]: "scroll"
20180
+ };
20181
+ var SCROLL_DIRECTIONS = ["up", "down", "left", "right"];
20182
+ var NO_EXPECTATIONS = {
20183
+ kittyKeyboardEnabled: false,
20184
+ privateCapabilityRepliesActive: false,
20185
+ pixelResolutionQueryActive: false,
20186
+ explicitWidthCprActive: false,
20187
+ startupCursorCprActive: false
20188
+ };
20189
+ var REPLY_PROTOCOLS = {
20190
+ [C.OT_INPUT_REPLY_CSI]: "csi",
20191
+ [C.OT_INPUT_REPLY_SS3]: "unknown",
20192
+ [C.OT_INPUT_REPLY_OSC]: "osc",
20193
+ [C.OT_INPUT_REPLY_DCS]: "dcs",
20194
+ [C.OT_INPUT_REPLY_APC]: "apc"
20195
+ };
20196
+ var LEGACY_CODE_RE = /^\x1b+(O|\[\[?)(?:(\d+)(?:;\d+)?([~^$])|(?:1;)?\d*([a-zA-Z]))/;
20197
+ var LEGACY_SEQUENCE_RE = /^\x1b\x1b?[[O]./s;
20198
+ var KEYPAD_TEXT = new Set(Object.values(printableKeypadText));
20199
+ function concat(parts) {
20200
+ let length = 0;
20201
+ for (const part of parts)
20202
+ length += part.length;
20203
+ const bytes = new Uint8Array(length);
20204
+ let offset = 0;
20205
+ for (const part of parts) {
20206
+ bytes.set(part, offset);
20207
+ offset += part.length;
20208
+ }
20209
+ return bytes;
20210
+ }
20211
+ function latin1(bytes) {
20212
+ return Buffer4.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("latin1");
20213
+ }
20214
+ function expectationFlags(context) {
20215
+ const cursorPosition = context.explicitWidthCprActive || context.startupCursorCprActive;
20216
+ const replies = context.privateCapabilityRepliesActive || context.pixelResolutionQueryActive || cursorPosition;
20217
+ return (replies ? C.OT_INPUT_EXPECT_REPLIES : 0) | (context.kittyKeyboardEnabled ? C.OT_INPUT_EXPECT_KITTY_KEYBOARD : 0) | (cursorPosition ? C.OT_INPUT_EXPECT_CURSOR_POSITION : 0);
20218
+ }
20219
+
20220
+ class NativeStdinParser {
20221
+ lib;
20222
+ context;
20223
+ session;
20224
+ ownsContext;
20225
+ records = new Uint8Array(RECORD_CAPACITY * RECORD.size);
20226
+ words = new Uint32Array(this.records.buffer);
20227
+ halves = new Uint16Array(this.records.buffer);
20228
+ payload = new Uint8Array(PAYLOAD_CAPACITY);
20229
+ events = [];
20230
+ clock;
20231
+ armTimeouts;
20232
+ onTimeoutFlush;
20233
+ protocolContext;
20234
+ appliedExpectations = 0;
20235
+ timeoutId = null;
20236
+ deadlineNs = null;
20237
+ lastNs = 0n;
20238
+ paste = null;
20239
+ suspended = false;
20240
+ sessionGone = false;
20241
+ destroyed = false;
20242
+ constructor(options = {}) {
20243
+ this.clock = options.clock ?? new SystemClock2;
20244
+ this.armTimeouts = options.armTimeouts ?? true;
20245
+ this.onTimeoutFlush = options.onTimeoutFlush ?? null;
20246
+ this.protocolContext = { ...NO_EXPECTATIONS, ...options.protocolContext };
20247
+ if (options.session) {
20248
+ this.lib = options.session.lib;
20249
+ this.context = options.session.context;
20250
+ this.session = options.session.session;
20251
+ this.ownsContext = false;
20252
+ } else {
20253
+ this.lib = resolveRenderLib2();
20254
+ this.context = this.lib.createContext({ objectCapacity: 4, renderCellsMax: 1 });
20255
+ try {
20256
+ this.session = this.lib.createSession(this.context, { chunkSize: 4096, spanCapacity: 2, maxBytes: 8192n });
20257
+ } catch (error) {
20258
+ this.destroyContext();
20259
+ throw error;
20260
+ }
20261
+ this.ownsContext = true;
20262
+ }
20263
+ try {
20264
+ this.applyExpectations();
20265
+ } catch (error) {
20266
+ if (this.ownsContext)
20267
+ this.destroyContext();
20268
+ throw error;
20269
+ }
20270
+ }
20271
+ updateProtocolContext(patch) {
20272
+ this.ensureAlive();
20273
+ this.protocolContext = { ...this.protocolContext, ...patch };
20274
+ this.native(() => {
20275
+ this.applyExpectations();
20276
+ this.feed(EMPTY, this.nowNs());
20277
+ });
20278
+ this.reconcileTimeout(this.events.length > 0);
20279
+ }
20280
+ push(data) {
20281
+ this.ensureAlive();
20282
+ this.native(() => this.feed(data, this.nowNs()));
20283
+ this.reconcileTimeout();
20284
+ }
20285
+ read() {
20286
+ this.ensureAlive();
20287
+ return this.events.shift() ?? null;
20288
+ }
20289
+ drain(onEvent) {
20290
+ this.ensureAlive();
20291
+ while (!this.destroyed) {
20292
+ const event = this.events.shift();
20293
+ if (!event)
20294
+ return;
20295
+ onEvent(event);
20296
+ }
20297
+ }
20298
+ flushTimeout(nowMsValue = this.clock.now()) {
20299
+ this.ensureAlive();
20300
+ this.native(() => this.feed(EMPTY, this.toNs(nowMsValue)));
20301
+ this.reconcileTimeout();
20302
+ }
20303
+ suspend() {
20304
+ this.ensureAlive();
20305
+ this.suspended = true;
20306
+ this.clearTimeout();
20307
+ }
20308
+ resume() {
20309
+ this.ensureAlive();
20310
+ this.suspended = false;
20311
+ this.native(() => this.lib.sessionInputReset(this.context, this.session, C.OT_INPUT_RESET_KEEP_REPLY));
20312
+ this.paste = null;
20313
+ this.deadlineNs = null;
20314
+ }
20315
+ reset() {
20316
+ if (this.destroyed)
20317
+ return;
20318
+ this.clearTimeout();
20319
+ this.native(() => this.lib.sessionInputReset(this.context, this.session, 0));
20320
+ this.events.length = 0;
20321
+ this.paste = null;
20322
+ this.deadlineNs = null;
20323
+ }
20324
+ destroy() {
20325
+ if (this.destroyed)
20326
+ return;
20327
+ this.clearTimeout();
20328
+ this.destroyed = true;
20329
+ this.events.length = 0;
20330
+ this.paste = null;
20331
+ if (this.ownsContext)
20332
+ this.destroyContext();
20333
+ }
20334
+ ensureAlive() {
20335
+ if (this.destroyed)
20336
+ throw new Error("StdinParser has been destroyed");
20337
+ }
20338
+ native(call) {
20339
+ if (this.sessionGone)
20340
+ return;
20341
+ try {
20342
+ call();
20343
+ } catch (error) {
20344
+ if (!(error instanceof NativeError2) || error.status !== -12 /* SessionClosed */ && error.status !== -15 /* OutputFailed */ && error.status !== -9 /* StaleHandle */ && error.status !== -7 /* WrongContext */) {
20345
+ throw error;
20346
+ }
20347
+ this.sessionGone = true;
20348
+ this.deadlineNs = null;
20349
+ this.paste = null;
20350
+ this.clearTimeout();
20351
+ }
20352
+ }
20353
+ destroyContext() {
20354
+ this.lib.getYogaHost().runMutation(() => this.lib.destroyContext(this.context));
20355
+ }
20356
+ applyExpectations() {
20357
+ const flags = expectationFlags(this.protocolContext);
20358
+ if (flags === this.appliedExpectations)
20359
+ return;
20360
+ this.lib.sessionInputExpect(this.context, this.session, flags);
20361
+ this.appliedExpectations = flags;
20362
+ }
20363
+ toNs(ms) {
20364
+ const ns = BigInt(Math.max(0, Math.round(ms * 1e6)));
20365
+ return ns > this.lastNs ? ns : this.lastNs;
20366
+ }
20367
+ nowNs() {
20368
+ return this.suspended ? this.lastNs : this.toNs(this.clock.now());
20369
+ }
20370
+ feed(bytes, nowNs) {
20371
+ this.lastNs = nowNs;
20372
+ let offset = 0;
20373
+ do {
20374
+ const rest = offset === 0 ? bytes : bytes.subarray(offset);
20375
+ const drain = this.lib.sessionInputFeed(this.context, this.session, rest, nowNs, this.records, this.payload);
20376
+ this.deadlineNs = drain.deadlineNs;
20377
+ for (let index = 0;index < drain.count; index++)
20378
+ this.translate(index);
20379
+ if (drain.consumed === 0 && drain.count === 0 && offset < bytes.length) {
20380
+ throw new Error("native input parser made no progress");
20381
+ }
20382
+ offset += drain.consumed;
20383
+ } while (offset < bytes.length);
20384
+ }
20385
+ reconcileTimeout(flushNow = false) {
20386
+ if (!this.armTimeouts)
20387
+ return;
20388
+ this.clearTimeout();
20389
+ const deadline = flushNow ? null : this.deadlineNs;
20390
+ if (deadline === null && !flushNow || this.suspended || this.sessionGone)
20391
+ return;
20392
+ const delayMs = deadline === null ? 0 : Number((deadline - this.lastNs + 999999n) / 1000000n);
20393
+ this.timeoutId = this.clock.setTimeout(() => {
20394
+ this.timeoutId = null;
20395
+ if (this.destroyed)
20396
+ return;
20397
+ try {
20398
+ const now = this.nowNs();
20399
+ this.native(() => this.feed(EMPTY, deadline !== null && now < deadline ? deadline : now));
20400
+ this.reconcileTimeout();
20401
+ this.onTimeoutFlush?.();
20402
+ } catch (error) {
20403
+ console.error("stdin parser timeout flush failed", error);
20404
+ }
20405
+ }, delayMs);
20406
+ }
20407
+ clearTimeout() {
20408
+ if (this.timeoutId === null)
20409
+ return;
20410
+ this.clock.clearTimeout(this.timeoutId);
20411
+ this.timeoutId = null;
20412
+ }
20413
+ span(offset, length) {
20414
+ return this.payload.subarray(offset, offset + length);
20415
+ }
20416
+ translate(index) {
20417
+ const base = index * RECORD.size;
20418
+ const word = base / 4;
20419
+ const half = base / 2;
20420
+ const kind = this.records[base + FIELD.kind];
20421
+ const action = this.records[base + FIELD.action];
20422
+ const modifiers = this.records[base + FIELD.modifiers];
20423
+ const flags = this.records[base + FIELD.flags];
20424
+ const code = this.words[word + FIELD.code];
20425
+ const raw = this.span(this.words[word + FIELD.rawOffset], this.words[word + FIELD.rawLength]);
20426
+ const text = this.span(this.words[word + FIELD.textOffset], this.words[word + FIELD.textLength]);
20427
+ switch (kind) {
20428
+ case C.OT_INPUT_KEY: {
20429
+ const key = parsedKey(code, this.words[word + FIELD.baseCode], action, modifiers, flags, raw, text);
20430
+ this.events.push({ type: "key", raw: key.raw, key });
20431
+ return;
20432
+ }
20433
+ case C.OT_INPUT_MOUSE: {
20434
+ const sequence = latin1(raw);
20435
+ const encoding = raw[2] === 60 ? "sgr" : "x10";
20436
+ const event = rawMouseEvent(action, code, this.halves[half + FIELD.x], this.halves[half + FIELD.y], modifiers, encoding);
20437
+ this.events.push({ type: "mouse", raw: sequence, encoding, event });
20438
+ return;
20439
+ }
20440
+ case C.OT_INPUT_PASTE: {
20441
+ if (flags & C.OT_INPUT_PASTE_START)
20442
+ this.paste = [];
20443
+ if (text.length > 0)
20444
+ this.paste.push(Uint8Array.from(text));
20445
+ if (flags & C.OT_INPUT_PASTE_END) {
20446
+ const parts = this.paste;
20447
+ this.paste = null;
20448
+ this.events.push({ type: "paste", bytes: parts.length === 1 ? parts[0] : concat(parts) });
20449
+ }
20450
+ return;
20451
+ }
20452
+ case C.OT_INPUT_FOCUS:
20453
+ this.events.push({ type: "response", protocol: "csi", sequence: latin1(raw) });
20454
+ return;
20455
+ case C.OT_INPUT_REPLY: {
20456
+ const protocol = flags & C.OT_INPUT_REPLY_CURSOR_POSITION ? "cpr" : flags & C.OT_INPUT_REPLY_FRAGMENT ? "unknown" : REPLY_PROTOCOLS[code];
20457
+ this.events.push({ type: "response", protocol, sequence: latin1(raw) });
20458
+ return;
20459
+ }
20460
+ }
20461
+ throw new Error(`Unknown native input event kind: ${kind}`);
20462
+ }
20463
+ }
20464
+ function keyRaw(raw) {
20465
+ if (raw.length === 1 && raw[0] >= 128)
20466
+ return "\x1B" + String.fromCharCode(raw[0] & 127);
20467
+ return UTF8.decode(raw);
20468
+ }
20469
+ function compatCode(raw, code, kitty) {
20470
+ if (kitty) {
20471
+ if (!raw.endsWith("u") || kittyKeyMap[code] === undefined)
20472
+ return;
20473
+ return `[${/^\x1b+\[(\d+)/.exec(raw)[1]}u`;
20474
+ }
20475
+ if (kittyKeyMap[code] === undefined && !KEYPAD_TEXT.has(String.fromCodePoint(code)))
20476
+ return;
20477
+ const match = LEGACY_CODE_RE.exec(raw);
20478
+ return match ? [match[1], match[2], match[3], match[4]].filter(Boolean).join("") : undefined;
20479
+ }
20480
+ function parsedKey(code, baseCode, action, modifiers, flags, rawBytes, textBytes) {
20481
+ const kitty = (flags & C.OT_INPUT_KEY_KITTY) !== 0;
20482
+ const raw = keyRaw(rawBytes);
20483
+ const text = textBytes.length === 0 ? "" : UTF8.decode(textBytes);
20484
+ const alt = (modifiers & C.OT_INPUT_MOD_ALT) !== 0;
20485
+ const sequence = kitty || LEGACY_SEQUENCE_RE.test(raw);
20486
+ let shift = (modifiers & C.OT_INPUT_MOD_SHIFT) !== 0;
20487
+ let name;
20488
+ if (code === 0) {
20489
+ name = text;
20490
+ } else if (kittyKeyMap[code] !== undefined) {
20491
+ name = code === C.OT_INPUT_KEY_ENTER && !kitty && raw.endsWith(`
20492
+ `) ? "linefeed" : kittyKeyMap[code];
20493
+ } else if (code === 32) {
20494
+ name = "space";
20495
+ } else {
20496
+ name = String.fromCodePoint(code);
20497
+ if (!sequence && code >= 65 && code <= 90) {
20498
+ shift = true;
20499
+ if (!alt)
20500
+ name = name.toLowerCase();
20501
+ }
20502
+ }
20503
+ const key = {
20504
+ name,
20505
+ ctrl: (modifiers & C.OT_INPUT_MOD_CTRL) !== 0,
20506
+ meta: alt || (modifiers & C.OT_INPUT_MOD_META) !== 0,
20507
+ shift,
20508
+ option: alt && sequence,
20509
+ sequence: text || raw,
20510
+ number: /^[0-9]$/.test(name),
20511
+ raw,
20512
+ eventType: action === C.OT_INPUT_KEY_RELEASE ? "release" : "press",
20513
+ source: kitty ? "kitty" : "raw",
20514
+ super: (modifiers & C.OT_INPUT_MOD_SUPER) !== 0,
20515
+ hyper: (modifiers & C.OT_INPUT_MOD_HYPER) !== 0,
20516
+ capsLock: (modifiers & C.OT_INPUT_MOD_CAPS_LOCK) !== 0,
20517
+ numLock: (modifiers & C.OT_INPUT_MOD_NUM_LOCK) !== 0
20518
+ };
20519
+ if (action === C.OT_INPUT_KEY_REPEAT)
20520
+ key.repeated = true;
20521
+ if (baseCode !== 0)
20522
+ key.baseCode = baseCode;
20523
+ const legacy = compatCode(raw, code, kitty);
20524
+ if (legacy !== undefined)
20525
+ key.code = legacy;
20526
+ return key;
20527
+ }
20528
+ function rawMouseEvent(action, code, x, y, modifiers, encoding) {
20529
+ const type = MOUSE_TYPES[action];
20530
+ if (!type)
20531
+ throw new Error(`Unknown native mouse action: ${action}`);
20532
+ let button = code;
20533
+ if (code === C.OT_INPUT_MOUSE_BUTTON_NONE)
20534
+ button = encoding === "x10" ? -1 : 0;
20535
+ if (type === "scroll")
20536
+ button = encoding === "x10" || code === 3 ? 0 : code;
20537
+ const event = {
20538
+ type,
20539
+ button,
20540
+ x,
20541
+ y,
20542
+ modifiers: {
20543
+ shift: (modifiers & C.OT_INPUT_MOD_SHIFT) !== 0,
20544
+ alt: (modifiers & C.OT_INPUT_MOD_ALT) !== 0,
20545
+ ctrl: (modifiers & C.OT_INPUT_MOD_CTRL) !== 0
20546
+ }
20547
+ };
20548
+ if (type === "scroll")
20549
+ event.scroll = { direction: SCROLL_DIRECTIONS[code & 3], delta: 1 };
20550
+ return event;
20551
+ }
20552
+ var SHADOW_BACKLOG_MAX = 256;
20553
+ var SHADOW_WINDOW = 8;
20554
+ function describeEvent(event) {
20555
+ switch (event.type) {
20556
+ case "key": {
20557
+ const { name, ctrl, meta, shift, eventType } = event.key;
20558
+ return JSON.stringify(["key", event.raw, name, ctrl, meta, shift, eventType]);
20559
+ }
20560
+ case "mouse": {
20561
+ const { type, button, x, y, modifiers } = event.event;
20562
+ return JSON.stringify(["mouse", event.raw, type, button, x, y, modifiers.shift, modifiers.alt, modifiers.ctrl]);
20563
+ }
20564
+ case "paste":
20565
+ return JSON.stringify(["paste", event.bytes.length, Buffer4.from(event.bytes).toString("base64")]);
20566
+ case "response":
20567
+ return JSON.stringify(["response", event.protocol, event.sequence]);
20568
+ }
20569
+ }
20570
+
20571
+ class StdinShadowComparator {
20572
+ primaryName;
20573
+ log;
20574
+ delivered = [];
20575
+ shadowed = [];
20576
+ constructor(primaryName, log) {
20577
+ this.primaryName = primaryName;
20578
+ this.log = log;
20579
+ }
20580
+ primary(event) {
20581
+ this.queue(this.delivered, event);
20582
+ }
20583
+ shadow(event) {
20584
+ this.queue(this.shadowed, event);
20585
+ }
20586
+ flush() {
20587
+ this.pair(true);
20588
+ }
20589
+ queue(events, event) {
20590
+ events.push(describeEvent(event));
20591
+ this.pair(false);
20592
+ if (events.length > SHADOW_BACKLOG_MAX) {
20593
+ const dropped = events.shift();
20594
+ if (events === this.delivered)
20595
+ this.report(dropped, "");
20596
+ else
20597
+ this.report("", dropped);
20598
+ }
20599
+ }
20600
+ pair(final) {
20601
+ const { delivered, shadowed } = this;
20602
+ while (delivered.length > 0 && shadowed.length > 0) {
20603
+ const [i, j] = commonEvent(delivered, shadowed) ?? [-1, -1];
20604
+ if (i >= 0) {
20605
+ for (let k = 0;k < Math.max(i, j); k++)
20606
+ this.report(k < i ? delivered[k] : "", k < j ? shadowed[k] : "");
20607
+ delivered.splice(0, i + 1);
20608
+ shadowed.splice(0, j + 1);
20609
+ } else if (final || Math.min(delivered.length, shadowed.length) >= SHADOW_WINDOW) {
20610
+ this.report(delivered.shift(), shadowed.shift());
20611
+ } else
20612
+ return;
20613
+ }
20614
+ if (final) {
20615
+ for (const event of delivered.splice(0))
20616
+ this.report(event, "");
20617
+ for (const event of shadowed.splice(0))
20618
+ this.report("", event);
20619
+ }
20620
+ }
20621
+ report(delivered, shadowed) {
20622
+ const shadowName = this.primaryName === "native" ? "legacy" : "native";
20623
+ this.log(`[stdin-shadow] ${this.primaryName}=${delivered || "none"} ${shadowName}=${shadowed || "none"}`);
20624
+ }
20625
+ }
20626
+ function commonEvent(a, b) {
20627
+ const aEnd = Math.min(a.length, SHADOW_WINDOW);
20628
+ const bEnd = Math.min(b.length, SHADOW_WINDOW);
20629
+ for (let sum = 0;sum < aEnd + bEnd - 1; sum++) {
20630
+ for (let i = Math.max(0, sum - bEnd + 1);i <= Math.min(sum, aEnd - 1); i++) {
20631
+ if (a[i] === b[sum - i])
20632
+ return [i, sum - i];
20633
+ }
20634
+ }
20635
+ return null;
20636
+ }
20637
+
20628
20638
  // src/renderer-theme-mode.ts
20629
20639
  var OSC_THEME_RESPONSE = /\x1b](10|11);(?:(?:rgb:)([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)|#([0-9a-fA-F]{6}))(?:\x07|\x1b\\)/g;
20630
20640
  function scaleOscThemeComponent(component) {
@@ -20810,6 +20820,18 @@ registerEnvVar2({
20810
20820
  type: "boolean",
20811
20821
  default: false
20812
20822
  });
20823
+ registerEnvVar2({
20824
+ name: "OTUI_NATIVE_INPUT_PARSER",
20825
+ description: "Parse stdin with the experimental native input parser unless experimental_nativeInput is set.",
20826
+ type: "boolean",
20827
+ default: false
20828
+ });
20829
+ registerEnvVar2({
20830
+ name: "OTUI_NATIVE_INPUT_SHADOW",
20831
+ description: "Also run the other stdin parser and log one line for each event that differs.",
20832
+ type: "boolean",
20833
+ default: false
20834
+ });
20813
20835
  var KITTY_IMAGE_TRANSPORTS = ["raw", "zlib", "file"];
20814
20836
  var DEFAULT_FOOTER_HEIGHT = 12;
20815
20837
  var MAX_SCROLLBACK_SURFACE_HEIGHT_PASSES = 4;
@@ -21311,6 +21333,7 @@ class CliRenderer2 extends EventEmitter8 {
21311
21333
  _resolution = null;
21312
21334
  _keyHandler;
21313
21335
  stdinParser = null;
21336
+ stdinShadow = null;
21314
21337
  oscSubscribers = new Set;
21315
21338
  hasLoggedStdinParserError = false;
21316
21339
  animationRequest = new Map;
@@ -21442,16 +21465,16 @@ Captured external output:
21442
21465
  }).catch((error) => console.error("Native scene shutdown failed:", error));
21443
21466
  }).bind(this);
21444
21467
  nativeProcessExitHandler = () => {
21445
- if (!this.nativeSession || this.nativeSession.disposed)
21446
- return;
21447
- const restored = this.nativeSession.restoreOnExit();
21468
+ const disposed = this.nativeSession.disposed;
21469
+ const restored = !disposed && this.nativeSession.restoreOnExit();
21448
21470
  try {
21471
+ this.leaveRawMode();
21449
21472
  this.destroy();
21450
21473
  if (this.flushTerminalInputOnClose)
21451
21474
  this.lib.terminalFlushInput();
21452
21475
  } finally {
21453
21476
  this.nativeSession.dispose();
21454
- if (!restored && this._terminalIsSetup) {
21477
+ if (!disposed && !restored && this._terminalIsSetup) {
21455
21478
  console.error("Native scene output cancelled at process exit; terminal restoration did not complete");
21456
21479
  }
21457
21480
  }
@@ -21472,9 +21495,8 @@ Captured external output:
21472
21495
  this.stdout = stdout;
21473
21496
  this._usesProcessStdout = stdout === process.stdout;
21474
21497
  this.realStdoutWrite = stdout.write;
21475
- const workBudget = config.nativeSceneWorkBudget;
21476
- if (workBudget !== undefined && (!Number.isInteger(workBudget) || workBudget <= 0 || workBudget > 4294967295)) {
21477
- throw new Error("nativeSceneWorkBudget must be a positive u32");
21498
+ if (config.nativeSceneWorkBudget !== undefined) {
21499
+ throw new Error("nativeSceneWorkBudget was removed: frames always paint synchronously");
21478
21500
  }
21479
21501
  this.kittyTransportMode = config.kittyImageTransport ?? "raw";
21480
21502
  const transportCode = KITTY_IMAGE_TRANSPORTS.indexOf(this.kittyTransportMode);
@@ -21529,12 +21551,14 @@ Captured external output:
21529
21551
  this.nativeClosed = this.nativeSession.closed.finally(() => this.nativeDestroyWait.promise).finally(() => {
21530
21552
  if (this.nativeSession.error && !this.nativeSession.disposed)
21531
21553
  this.nativeSession.dispose();
21554
+ this.leaveRawMode();
21555
+ this.removeCleanupListener(process, "exit", this.nativeProcessExitHandler);
21532
21556
  if (this.flushTerminalInputOnClose)
21533
21557
  this.lib.terminalFlushInput();
21534
21558
  this.releaseStreamLease();
21535
21559
  });
21536
21560
  this.nativeClosed.catch(() => {});
21537
- this.nativeScene = new NativeScene(this.nativeSession, this, config.nativeSceneWorkBudget);
21561
+ this.nativeScene = new NativeScene(this.nativeSession, this);
21538
21562
  this.nativeSession.setKittyImageTransport(transportCode);
21539
21563
  } catch (error) {
21540
21564
  if (!config.nativeSession || this.nativeSession)
@@ -21619,23 +21643,41 @@ Captured external output:
21619
21643
  });
21620
21644
  this.addExitListeners();
21621
21645
  const stdinParserMaxBufferBytes = config.stdinParserMaxBufferBytes ?? DEFAULT_STDIN_PARSER_MAX_BUFFER_BYTES;
21622
- this.stdinParser = new StdinParser2({
21623
- timeoutMs: 20,
21624
- maxPendingBytes: stdinParserMaxBufferBytes,
21625
- armTimeouts: true,
21626
- onTimeoutFlush: () => {
21627
- this.drainStdinParser();
21628
- },
21629
- useKittyKeyboard: useKittyForParsing,
21630
- protocolContext: {
21646
+ const createStdinParser = (native, onTimeoutFlush) => {
21647
+ const protocolContext = {
21631
21648
  kittyKeyboardEnabled: useKittyForParsing,
21632
21649
  privateCapabilityRepliesActive: false,
21633
21650
  pixelResolutionQueryActive: false,
21634
21651
  explicitWidthCprActive: false,
21635
21652
  startupCursorCprActive: false
21636
- },
21637
- clock: this.clock
21638
- });
21653
+ };
21654
+ if (native) {
21655
+ return new NativeStdinParser({
21656
+ armTimeouts: true,
21657
+ onTimeoutFlush,
21658
+ protocolContext,
21659
+ clock: this.clock,
21660
+ session: { lib: this.lib, context: this.nativeSession.context, session: this.nativeSession.session }
21661
+ });
21662
+ }
21663
+ return new StdinParser2({
21664
+ timeoutMs: 20,
21665
+ maxPendingBytes: stdinParserMaxBufferBytes,
21666
+ armTimeouts: true,
21667
+ onTimeoutFlush,
21668
+ useKittyKeyboard: useKittyForParsing,
21669
+ protocolContext,
21670
+ clock: this.clock
21671
+ });
21672
+ };
21673
+ const nativeInput = config.experimental_nativeInput ?? env2.OTUI_NATIVE_INPUT_PARSER;
21674
+ this.stdinParser = createStdinParser(nativeInput, () => this.drainStdinParser());
21675
+ if (env2.OTUI_NATIVE_INPUT_SHADOW) {
21676
+ this.stdinShadow = {
21677
+ parser: createStdinParser(!nativeInput, () => this.drainStdinShadow()),
21678
+ comparator: new StdinShadowComparator(nativeInput ? "native" : "legacy", (line) => console.warn(line))
21679
+ };
21680
+ }
21639
21681
  this._console = new TerminalConsole2(this, {
21640
21682
  ...config.consoleOptions ?? {},
21641
21683
  clock: this.clock
@@ -21649,9 +21691,8 @@ Captured external output:
21649
21691
  this.stdout.write = externalOutputMode === "capture-stdout" ? this.interceptStdoutWrite : this.realStdoutWrite;
21650
21692
  this._openConsoleOnError = config.openConsoleOnError ?? true;
21651
21693
  this._onDestroy = config.onDestroy;
21652
- this.setupInput();
21653
21694
  process.on("exit", this.nativeProcessExitHandler);
21654
- this.nativeSession.closed.then(() => this.removeCleanupListener(process, "exit", this.nativeProcessExitHandler), () => this.removeCleanupListener(process, "exit", this.nativeProcessExitHandler));
21695
+ this.setupInput();
21655
21696
  this.nativeSession.closed.catch((error) => {
21656
21697
  if (this._isDestroyed)
21657
21698
  return;
@@ -22696,7 +22737,8 @@ Captured external output:
22696
22737
  }
22697
22738
  abortSplitStartupCursorSeed() {
22698
22739
  this.clearSplitStartupCursorSeed();
22699
- this.stdinParser?.abortPendingStartupCursorCpr();
22740
+ for (const parser of this.legacyStdinParsers())
22741
+ parser.abortPendingStartupCursorCpr();
22700
22742
  this.updateStdinParserProtocolContext({ startupCursorCprActive: false });
22701
22743
  }
22702
22744
  resetSplitScrollback(seedRows = 0) {
@@ -22927,7 +22969,8 @@ Captured external output:
22927
22969
  }
22928
22970
  this._useMouse = false;
22929
22971
  this.capturedRenderable = undefined;
22930
- this.stdinParser?.resetMouseState();
22972
+ for (const parser of this.legacyStdinParsers())
22973
+ parser.resetMouseState();
22931
22974
  }
22932
22975
  enableKittyKeyboard(flags = 3) {
22933
22976
  if (this.nativeTerminalTransition || this._controlState === "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
@@ -23056,6 +23099,12 @@ Captured external output:
23056
23099
  } catch (error) {
23057
23100
  this.handleStdinParserFailure(error);
23058
23101
  }
23102
+ try {
23103
+ this.stdinShadow?.parser.push(data);
23104
+ this.drainStdinShadow();
23105
+ } catch (error) {
23106
+ console.warn("[stdin-shadow] parser failure", error);
23107
+ }
23059
23108
  }).bind(this);
23060
23109
  addInputHandler(handler) {
23061
23110
  this.sequenceHandlers.push(handler);
@@ -23070,8 +23119,13 @@ Captured external output:
23070
23119
  if (!this.stdinParser)
23071
23120
  return;
23072
23121
  this.stdinParser.updateProtocolContext(patch);
23122
+ this.stdinShadow?.parser.updateProtocolContext(patch);
23073
23123
  if (drain)
23074
23124
  this.drainStdinParser();
23125
+ this.drainStdinShadow();
23126
+ }
23127
+ legacyStdinParsers() {
23128
+ return [this.stdinParser, this.stdinShadow?.parser].filter((parser) => parser instanceof StdinParser2);
23075
23129
  }
23076
23130
  subscribeOsc(handler) {
23077
23131
  this.oscSubscribers.add(handler);
@@ -23155,9 +23209,14 @@ Captured external output:
23155
23209
  if (!this.stdinParser)
23156
23210
  return;
23157
23211
  this.stdinParser.drain((event) => {
23212
+ this.stdinShadow?.comparator.primary(event);
23158
23213
  this.handleStdinEvent(event);
23159
23214
  });
23160
23215
  }
23216
+ drainStdinShadow() {
23217
+ const shadow = this.stdinShadow;
23218
+ shadow?.parser.drain((event) => shadow.comparator.shadow(event));
23219
+ }
23161
23220
  handleStdinEvent(event) {
23162
23221
  if (event.type === "response" && event.sequence.startsWith("\x1B_G")) {
23163
23222
  try {
@@ -23217,6 +23276,7 @@ Captured external output:
23217
23276
  }
23218
23277
  try {
23219
23278
  this.stdinParser?.reset();
23279
+ this.stdinShadow?.parser.reset();
23220
23280
  } catch (resetError) {
23221
23281
  console.error("stdin parser reset failed after parser error", resetError);
23222
23282
  }
@@ -23631,9 +23691,6 @@ Captured external output:
23631
23691
  else {
23632
23692
  this.nativeSession.setScreen(this._screenMode === "alternate-screen", nextGeometry.renderWidth, nextGeometry.renderHeight, this.lib.encoder.encode(ANSI.moveCursorAndClear(clearStart, 1)));
23633
23693
  }
23634
- if (nextGeometry.renderWidth !== this.width || nextGeometry.renderHeight !== this.height) {
23635
- this.nativeScene.restartPaint();
23636
- }
23637
23694
  this._terminalWidth = width;
23638
23695
  this._terminalHeight = height;
23639
23696
  this._splitHeight = nextGeometry.effectiveFooterHeight;
@@ -23642,7 +23699,8 @@ Captured external output:
23642
23699
  this._resolution = null;
23643
23700
  this.lib.sessionSetImageResolution(this.nativeSession.context, this.nativeSession.session, 0, 0, 0, 0);
23644
23701
  this.capturedRenderable = undefined;
23645
- this.stdinParser?.resetMouseState();
23702
+ for (const parser of this.legacyStdinParsers())
23703
+ parser.resetMouseState();
23646
23704
  if (splitFooterActive) {
23647
23705
  this.forceFullRepaintRequested = true;
23648
23706
  }
@@ -23909,7 +23967,6 @@ Captured external output:
23909
23967
  this._controlState = "explicit_suspended" /* EXPLICIT_SUSPENDED */;
23910
23968
  this._cancelPaletteDetection?.(new Error("Cannot detect palette while renderer is suspended"));
23911
23969
  this.resolveXtVersionWaiters();
23912
- this.nativeScene.interruptPaint();
23913
23970
  this.halt(false);
23914
23971
  this.clearSplitStartupCursorSeed();
23915
23972
  this.disableMouse();
@@ -23919,11 +23976,8 @@ Captured external output:
23919
23976
  pixelResolutionQueryActive: this.waitingForPixelResolution,
23920
23977
  explicitWidthCprActive: false,
23921
23978
  startupCursorCprActive: false
23922
- });
23923
- if (this.stdinParser?.hasPendingPixelResolutionResponse())
23924
- this.stdinParser.pausePendingTimeout();
23925
- else
23926
- this.stdinParser?.reset();
23979
+ }, true);
23980
+ this.pauseStdinParsers(false);
23927
23981
  this.stdin.removeListener("data", this.stdinListener);
23928
23982
  this.stopTerminalKeepAlive();
23929
23983
  this.themeModeState?.cancelRefresh();
@@ -23934,7 +23988,7 @@ Captured external output:
23934
23988
  return nativeTransition;
23935
23989
  }
23936
23990
  resume() {
23937
- if (!this._terminalIsSetup || this.nativeTerminalTransition || this._controlState !== "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
23991
+ if (!this._terminalIsSetup || this._isDestroyed || this.nativeTerminalTransition || this._controlState !== "explicit_suspended" /* EXPLICIT_SUSPENDED */) {
23938
23992
  throw new Error("Native scene resume requires completed suspension");
23939
23993
  }
23940
23994
  if (this.pendingSplitFooterTransition) {
@@ -23942,6 +23996,12 @@ Captured external output:
23942
23996
  kind: "clear-transition"
23943
23997
  });
23944
23998
  }
23999
+ try {
24000
+ this.stdin.setRawMode?.(true);
24001
+ } catch (error) {
24002
+ return Promise.reject(error);
24003
+ }
24004
+ this.addExitListeners();
23945
24005
  const resumed = this.trackNativeTerminalTransition(this.nativeSession.resume(), () => {
23946
24006
  if (this._isDestroyed)
23947
24007
  return;
@@ -23957,21 +24017,24 @@ Captured external output:
23957
24017
  resumed.catch(() => {});
23958
24018
  return resumed;
23959
24019
  }
23960
- finishResume() {
23961
- if (this.stdin.setRawMode) {
23962
- this.stdin.setRawMode(true);
24020
+ pauseStdinParsers(resuming) {
24021
+ for (const parser of [this.stdinParser, this.stdinShadow?.parser]) {
24022
+ if (parser instanceof NativeStdinParser)
24023
+ resuming ? parser.resume() : parser.suspend();
24024
+ else if (parser?.hasPendingPixelResolutionResponse())
24025
+ parser.pausePendingTimeout();
24026
+ else
24027
+ parser?.reset();
23963
24028
  }
24029
+ }
24030
+ finishResume() {
23964
24031
  let drained;
23965
24032
  while ((drained = this.stdin.read()) !== null)
23966
24033
  this.stdinListener(drained);
23967
- if (this.stdinParser?.hasPendingPixelResolutionResponse())
23968
- this.stdinParser.pausePendingTimeout();
23969
- else
23970
- this.stdinParser?.reset();
24034
+ this.pauseStdinParsers(true);
23971
24035
  this.stdin.on("data", this.stdinListener);
23972
24036
  this.stdin.resume();
23973
24037
  this.startTerminalKeepAlive();
23974
- this.addExitListeners();
23975
24038
  this._useMouse = this._suspendedMouseEnabled;
23976
24039
  if (this._screenMode === "split-footer" && this._splitHeight > 0) {
23977
24040
  this.syncSplitFooterState();
@@ -23982,7 +24045,8 @@ Captured external output:
23982
24045
  this._controlState = this._previousControlState;
23983
24046
  if (this.pixelResolutionRequeryPending)
23984
24047
  this.queryPixelResolution();
23985
- this.stdinParser?.resumePendingTimeout();
24048
+ for (const parser of this.legacyStdinParsers())
24049
+ parser.resumePendingTimeout();
23986
24050
  this.applyPendingNativeResize();
23987
24051
  if (this._previousControlState === "auto_started" /* AUTO_STARTED */ || this._previousControlState === "explicit_started" /* EXPLICIT_STARTED */) {
23988
24052
  this.internalStart();
@@ -24093,13 +24157,6 @@ Captured external output:
24093
24157
  this.capturedRenderable = undefined;
24094
24158
  this.removeCleanupListener(this.stdin, "data", this.stdinListener);
24095
24159
  this.stopTerminalKeepAlive();
24096
- if (this.stdin.setRawMode) {
24097
- try {
24098
- this.stdin.setRawMode(false);
24099
- } catch (e) {
24100
- console.error("Error disabling raw mode during destroy:", e);
24101
- }
24102
- }
24103
24160
  try {
24104
24161
  this.stdin.pause();
24105
24162
  } catch (e) {
@@ -24155,6 +24212,9 @@ Captured external output:
24155
24212
  }
24156
24213
  this.stdinParser?.destroy();
24157
24214
  this.stdinParser = null;
24215
+ this.stdinShadow?.parser.destroy();
24216
+ this.stdinShadow?.comparator.flush();
24217
+ this.stdinShadow = null;
24158
24218
  this.oscSubscribers.clear();
24159
24219
  try {
24160
24220
  this._console?.destroy();
@@ -24192,6 +24252,13 @@ Captured external output:
24192
24252
  this.nativeDestroyWait?.resolve();
24193
24253
  this.resolveIdleIfNeeded();
24194
24254
  }
24255
+ leaveRawMode() {
24256
+ try {
24257
+ this.stdin.setRawMode?.(false);
24258
+ } catch (e) {
24259
+ console.error("Error disabling raw mode:", e);
24260
+ }
24261
+ }
24195
24262
  releaseStreamLease() {
24196
24263
  if (!this._streamLeaseAcquired)
24197
24264
  return;
@@ -24284,13 +24351,11 @@ Captured external output:
24284
24351
  const sceneStart = performance.now();
24285
24352
  const requestedBeforeScene = this.immediateRerenderRequested;
24286
24353
  try {
24287
- const painting = this.nativeScene.paint(deltaTime, () => ({
24354
+ this.nativeScene.paint(deltaTime, () => ({
24288
24355
  background: this.backgroundColor,
24289
24356
  useMouse: this._useMouse,
24290
24357
  excludedHitNum: this.capturedRenderable?.num ?? 0
24291
24358
  }));
24292
- if (painting)
24293
- await painting;
24294
24359
  } catch (error) {
24295
24360
  this.immediateRerenderRequested = requestedBeforeScene;
24296
24361
  throw error;
@@ -24876,7 +24941,7 @@ Captured external output:
24876
24941
  }
24877
24942
  }
24878
24943
 
24879
- export { isValidBorderStyle2, parseBorderStyle2, BorderChars2, getBorderFromSides2, getBorderSides2, borderCharsToArray2, BorderCharArrays2, KeyEvent2, PasteEvent2, KeyHandler2, InternalKeyHandler2, fonts2, measureText2, getCharacterPositions2, coordinateToCharacterIndex2, renderFontToFrameBuffer2, convertThemeToStyles2, SyntaxStyle2, hastToStyledText2, SystemClock2, nonAlphanumericKeys2, terminalNamedSingleStrokeKeys2, parseKeypress2, LinearScrollAccel2, MacOSScrollAccel2, parseAlign2, parseAlignItems2, parseBoxSizing2, parseDimension2, parseDirection2, parseDisplay2, parseEdge2, parseFlexDirection2, parseGutter2, parseJustify2, parseLogLevel2, parseMeasureMode2, parseOverflow2, parsePositionType2, parseUnit2, parseWrap2, MouseParser2, Selection2, convertGlobalToLocalSelection2, ASCIIFontSelectionHelper2, StdinParser2, addDefaultParsers2, TreeSitterClient2, treeSitterToTextChunks2, treeSitterToStyledText2, DataPathsManager2, getDataPaths2, extensionToFiletype2, basenameToFiletype2, extToFiletype2, pathToFiletype2, infoStringToFiletype2, getTreeSitterClient2, destroyTreeSitterClient2, ExtmarksController2, createExtmarksController2, TerminalPalette2, createTerminalPalette2, normalizeTerminalPalette2, buildTerminalPaletteSignature2, decodePasteBytes2, stripAnsiSequences2, createHostClipboard2, createClipboard2, ClipboardTarget2, createRendererClipboardAdapter2, normalizeMarkdownLinkTarget, detectLinks2, acquireSessionBufferLease2, ResourceContext2, OptimizedBuffer2, h2, isVNode2, maybeMakeRenderable2, wrapWithDelegates2, instantiate2, delegate2, LayoutEvents2, RenderableEvents2, isRenderable2, BaseRenderable2, Renderable2, RootRenderable2, TextBuffer2, TextBufferView2, EditBuffer2, measureEditText2, EditorView2, Timeline2, engine2, getTimelineEngine2, createTimeline2, ANSI, BoxRenderable2, TextBufferRenderable2, CodeRenderable2, ImageLoadError2, ImageError2, imageInfo2, NativeImage2, NativeImagePool2, resolveImageRenderProtocol2, ImageRenderable2, isTextNodeRenderable2, TextNodeRenderable2, RootTextNodeRenderable2, TextRenderable2, NativeSession2, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture2, ConsolePosition2, TerminalConsole2, EditBufferRenderableEvents2, isEditBufferRenderable2, EditBufferRenderable2, buildKittyKeyboardFlags2, MouseEvent2, MouseButton2, createCliRenderer2, CliRenderEvents2, RendererControlState2, CliRenderer2 };
24944
+ export { isValidBorderStyle2, parseBorderStyle2, BorderChars2, getBorderFromSides2, getBorderSides2, borderCharsToArray2, BorderCharArrays2, KeyEvent2, PasteEvent2, KeyHandler2, InternalKeyHandler2, fonts2, measureText2, getCharacterPositions2, coordinateToCharacterIndex2, renderFontToFrameBuffer2, hastToStyledText2, SystemClock2, nonAlphanumericKeys2, terminalNamedSingleStrokeKeys2, parseKeypress2, LinearScrollAccel2, MacOSScrollAccel2, parseAlign2, parseAlignItems2, parseBoxSizing2, parseDimension2, parseDirection2, parseDisplay2, parseEdge2, parseFlexDirection2, parseGutter2, parseJustify2, parseLogLevel2, parseMeasureMode2, parseOverflow2, parsePositionType2, parseUnit2, parseWrap2, MouseParser2, Selection2, convertGlobalToLocalSelection2, ASCIIFontSelectionHelper2, StdinParser2, addDefaultParsers2, TreeSitterClient2, treeSitterToTextChunks2, treeSitterToStyledText2, DataPathsManager2, getDataPaths2, extensionToFiletype2, basenameToFiletype2, extToFiletype2, pathToFiletype2, infoStringToFiletype2, getTreeSitterClient2, destroyTreeSitterClient2, ExtmarksController2, createExtmarksController2, TerminalPalette2, createTerminalPalette2, normalizeTerminalPalette2, buildTerminalPaletteSignature2, decodePasteBytes2, stripAnsiSequences2, createHostClipboard2, createClipboard2, ClipboardTarget2, createRendererClipboardAdapter2, normalizeMarkdownLinkTarget, detectLinks2, acquireSessionBufferLease2, ResourceContext2, OptimizedBuffer2, h2, isVNode2, maybeMakeRenderable2, wrapWithDelegates2, instantiate2, delegate2, LayoutEvents2, RenderableEvents2, isRenderable2, BaseRenderable2, Renderable2, RootRenderable2, TextBuffer2, TextBufferView2, EditBuffer2, measureEditText2, EditorView2, Timeline2, engine2, getTimelineEngine2, createTimeline2, ANSI, BoxRenderable2, wheelDirection, scrollOnce, TextBufferRenderable2, CodeRenderable2, ImageLoadError2, ImageError2, imageInfo2, NativeImage2, NativeImagePool2, resolveImageRenderProtocol2, ImageRenderable2, isTextNodeRenderable2, TextNodeRenderable2, RootTextNodeRenderable2, TextRenderable2, NativeSession2, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture2, ConsolePosition2, TerminalConsole2, EditBufferRenderableEvents2, isEditBufferRenderable2, EditBufferRenderable2, buildKittyKeyboardFlags2, MouseEvent2, MouseButton2, createCliRenderer2, CliRenderEvents2, RendererControlState2, CliRenderer2 };
24880
24945
 
24881
- //# debugId=61919B83A1CBC72664756E2164756E21
24882
- //# sourceMappingURL=chunk-node-y5p1g2pb.js.map
24946
+ //# debugId=37A13ADEE7EBAEBB64756E2164756E21
24947
+ //# sourceMappingURL=chunk-node-7bcmqh18.js.map