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