@stream-mdx/react 0.1.1 → 0.3.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 (45) hide show
  1. package/dist/components/index.cjs +497 -163
  2. package/dist/components/index.d.cts +1 -1
  3. package/dist/components/index.d.ts +1 -1
  4. package/dist/components/index.mjs +496 -163
  5. package/dist/{index-Bt1opGCs.d.cts → index-D7px9jug.d.cts} +27 -2
  6. package/dist/{index-Bt1opGCs.d.ts → index-D7px9jug.d.ts} +27 -2
  7. package/dist/index.cjs +3767 -2043
  8. package/dist/index.d.cts +43 -5
  9. package/dist/index.d.ts +43 -5
  10. package/dist/index.mjs +3991 -2265
  11. package/dist/mdx-client.cjs +60 -18
  12. package/dist/mdx-client.d.cts +11 -0
  13. package/dist/mdx-client.d.ts +11 -0
  14. package/dist/mdx-client.mjs +60 -18
  15. package/dist/mdx-coordinator.cjs +60 -18
  16. package/dist/mdx-coordinator.mjs +60 -18
  17. package/dist/renderer/node-views.cjs +466 -133
  18. package/dist/renderer/node-views.d.cts +1 -1
  19. package/dist/renderer/node-views.d.ts +1 -1
  20. package/dist/renderer/node-views.mjs +409 -68
  21. package/dist/renderer/patch-commit-scheduler.cjs +68 -7
  22. package/dist/renderer/patch-commit-scheduler.d.cts +6 -5
  23. package/dist/renderer/patch-commit-scheduler.d.ts +6 -5
  24. package/dist/renderer/patch-commit-scheduler.mjs +68 -7
  25. package/dist/renderer/store.cjs +481 -56
  26. package/dist/renderer/store.d.cts +2 -1
  27. package/dist/renderer/store.d.ts +2 -1
  28. package/dist/renderer/store.mjs +479 -47
  29. package/dist/renderer/virtualized-code.cjs +8 -2
  30. package/dist/renderer/virtualized-code.d.cts +4 -0
  31. package/dist/renderer/virtualized-code.d.ts +4 -0
  32. package/dist/renderer/virtualized-code.mjs +8 -2
  33. package/dist/renderer.cjs +3199 -2208
  34. package/dist/renderer.d.cts +4 -2
  35. package/dist/renderer.d.ts +4 -2
  36. package/dist/renderer.mjs +2956 -1957
  37. package/dist/streaming-markdown-DSC4L0xR.d.cts +157 -0
  38. package/dist/streaming-markdown-Dp1IDgMT.d.ts +157 -0
  39. package/dist/streaming-markdown.cjs +3950 -2248
  40. package/dist/streaming-markdown.d.cts +6 -95
  41. package/dist/streaming-markdown.d.ts +6 -95
  42. package/dist/streaming-markdown.mjs +3962 -2252
  43. package/dist/utils/inline-html.d.cts +1 -1
  44. package/dist/utils/inline-html.d.ts +1 -1
  45. package/package.json +3 -3
@@ -33,6 +33,8 @@ var DEFAULT_TIMEOUT_MS = 16;
33
33
  var COALESCING_DURATION_SAMPLE_LIMIT = 60;
34
34
  var COALESCING_DURATION_ACTIVATE_MS = 6;
35
35
  var COALESCING_DURATION_DEACTIVATE_MS = 4;
36
+ var RETAIN_TOUCHED_IN_HISTORY = typeof process !== "undefined" && process.env ? process.env.NODE_ENV !== "production" : true;
37
+ var EMPTY_TOUCHED_SET = /* @__PURE__ */ new Set();
36
38
  function getDefaultNow() {
37
39
  if (typeof performance !== "undefined" && typeof performance.now === "function") {
38
40
  return () => performance.now();
@@ -74,15 +76,18 @@ var PatchCommitScheduler = class {
74
76
  this.adaptiveBudgetActive = false;
75
77
  this.store = params.store;
76
78
  this.onFlush = params.onFlush;
77
- this.frameBudgetMs = Math.max(1, params.options?.frameBudgetMs ?? 8);
78
- this.maxBatchesPerFlush = params.options?.maxBatchesPerFlush;
79
+ this.frameBudgetMs = Math.max(1, params.options?.frameBudgetMs ?? 10);
80
+ this.maxBatchesPerFlush = params.options?.maxBatchesPerFlush ?? 12;
79
81
  this.now = params.options?.now ?? getDefaultNow();
80
82
  this.raf = params.options?.raf ?? getDefaultRaf();
81
83
  this.cancelRaf = params.options?.cancelRaf ?? getDefaultCancelRaf();
82
84
  this.timeoutMs = Math.max(1, params.options?.timeoutMs ?? DEFAULT_TIMEOUT_MS);
83
- this.lowPriorityFrameBudgetMs = Math.max(1, params.options?.lowPriorityFrameBudgetMs ?? Math.max(2, Math.floor(this.frameBudgetMs / 2)));
84
- this.maxLowPriorityBatchesPerFlush = params.options?.maxLowPriorityBatchesPerFlush ?? 1;
85
- this.urgentQueueThreshold = Math.max(1, params.options?.urgentQueueThreshold ?? 3);
85
+ this.lowPriorityFrameBudgetMs = Math.max(
86
+ 1,
87
+ params.options?.lowPriorityFrameBudgetMs ?? Math.max(2, Math.floor(this.frameBudgetMs * 0.6))
88
+ );
89
+ this.maxLowPriorityBatchesPerFlush = params.options?.maxLowPriorityBatchesPerFlush ?? 2;
90
+ this.urgentQueueThreshold = Math.max(1, params.options?.urgentQueueThreshold ?? 4);
86
91
  this.historyLimit = Math.max(1, params.options?.historyLimit ?? 200);
87
92
  const requestedBatch = params.options?.batch;
88
93
  if (requestedBatch === "microtask") {
@@ -92,7 +97,7 @@ var PatchCommitScheduler = class {
92
97
  } else if (requestedBatch === "rAF") {
93
98
  this.batchStrategy = this.raf ? "rAF" : "timeout";
94
99
  } else {
95
- this.batchStrategy = this.raf ? "rAF" : "timeout";
100
+ this.batchStrategy = "microtask";
96
101
  }
97
102
  if (this.batchStrategy === "microtask" && typeof queueMicrotask !== "function") {
98
103
  this.batchStrategy = this.raf ? "rAF" : "timeout";
@@ -396,7 +401,18 @@ var PatchCommitScheduler = class {
396
401
  }
397
402
  }
398
403
  recordHistory(result) {
399
- this.history.push(result);
404
+ if (RETAIN_TOUCHED_IN_HISTORY) {
405
+ this.history.push(result);
406
+ } else {
407
+ const trimmed = {
408
+ ...result,
409
+ batches: result.batches.map((batch) => ({
410
+ ...batch,
411
+ touched: EMPTY_TOUCHED_SET
412
+ }))
413
+ };
414
+ this.history.push(trimmed);
415
+ }
400
416
  if (this.history.length > this.historyLimit) {
401
417
  this.history.splice(0, this.history.length - this.historyLimit);
402
418
  }
@@ -447,6 +463,51 @@ var PatchCommitScheduler = class {
447
463
  this.history.splice(0, this.history.length - this.historyLimit);
448
464
  }
449
465
  }
466
+ updateOptions(options) {
467
+ if (!options) return;
468
+ let shouldReschedule = false;
469
+ if (typeof options.frameBudgetMs !== "undefined") {
470
+ this.frameBudgetMs = Math.max(1, options.frameBudgetMs);
471
+ shouldReschedule = true;
472
+ }
473
+ if (typeof options.maxBatchesPerFlush !== "undefined") {
474
+ this.maxBatchesPerFlush = options.maxBatchesPerFlush;
475
+ shouldReschedule = true;
476
+ }
477
+ if (typeof options.lowPriorityFrameBudgetMs !== "undefined") {
478
+ this.lowPriorityFrameBudgetMs = Math.max(1, options.lowPriorityFrameBudgetMs);
479
+ shouldReschedule = true;
480
+ }
481
+ if (typeof options.maxLowPriorityBatchesPerFlush !== "undefined") {
482
+ this.maxLowPriorityBatchesPerFlush = options.maxLowPriorityBatchesPerFlush;
483
+ shouldReschedule = true;
484
+ }
485
+ if (typeof options.urgentQueueThreshold !== "undefined") {
486
+ this.urgentQueueThreshold = Math.max(1, options.urgentQueueThreshold);
487
+ shouldReschedule = true;
488
+ }
489
+ if (typeof options.historyLimit !== "undefined") {
490
+ this.setHistoryLimit(options.historyLimit);
491
+ }
492
+ if (typeof options.batch !== "undefined") {
493
+ const requestedBatch = options.batch;
494
+ if (requestedBatch === "microtask") {
495
+ this.batchStrategy = "microtask";
496
+ } else if (requestedBatch === "timeout") {
497
+ this.batchStrategy = "timeout";
498
+ } else if (requestedBatch === "rAF") {
499
+ this.batchStrategy = this.raf ? "rAF" : "timeout";
500
+ }
501
+ if (this.batchStrategy === "microtask" && typeof queueMicrotask !== "function") {
502
+ this.batchStrategy = this.raf ? "rAF" : "timeout";
503
+ }
504
+ shouldReschedule = true;
505
+ }
506
+ if (shouldReschedule && !this.paused && !this.flushing && this.getPendingCount() > 0) {
507
+ this.cancelScheduled();
508
+ this.schedule();
509
+ }
510
+ }
450
511
  clearHistory() {
451
512
  this.history = [];
452
513
  }
@@ -69,15 +69,15 @@ interface PatchCommitSchedulerOptions {
69
69
  declare class PatchCommitScheduler {
70
70
  private readonly store;
71
71
  private readonly onFlush;
72
- private readonly frameBudgetMs;
73
- private readonly maxBatchesPerFlush?;
72
+ private frameBudgetMs;
73
+ private maxBatchesPerFlush?;
74
74
  private readonly now;
75
75
  private readonly raf;
76
76
  private readonly cancelRaf;
77
77
  private readonly timeoutMs;
78
- private readonly lowPriorityFrameBudgetMs;
79
- private readonly maxLowPriorityBatchesPerFlush?;
80
- private readonly urgentQueueThreshold;
78
+ private lowPriorityFrameBudgetMs;
79
+ private maxLowPriorityBatchesPerFlush?;
80
+ private urgentQueueThreshold;
81
81
  private highQueue;
82
82
  private lowQueue;
83
83
  private scheduled;
@@ -122,6 +122,7 @@ declare class PatchCommitScheduler {
122
122
  restart(): void;
123
123
  getHistory(limit?: number): ReadonlyArray<PatchFlushResult>;
124
124
  setHistoryLimit(limit: number): void;
125
+ updateOptions(options: PatchCommitSchedulerOptions): void;
125
126
  clearHistory(): void;
126
127
  }
127
128
 
@@ -69,15 +69,15 @@ interface PatchCommitSchedulerOptions {
69
69
  declare class PatchCommitScheduler {
70
70
  private readonly store;
71
71
  private readonly onFlush;
72
- private readonly frameBudgetMs;
73
- private readonly maxBatchesPerFlush?;
72
+ private frameBudgetMs;
73
+ private maxBatchesPerFlush?;
74
74
  private readonly now;
75
75
  private readonly raf;
76
76
  private readonly cancelRaf;
77
77
  private readonly timeoutMs;
78
- private readonly lowPriorityFrameBudgetMs;
79
- private readonly maxLowPriorityBatchesPerFlush?;
80
- private readonly urgentQueueThreshold;
78
+ private lowPriorityFrameBudgetMs;
79
+ private maxLowPriorityBatchesPerFlush?;
80
+ private urgentQueueThreshold;
81
81
  private highQueue;
82
82
  private lowQueue;
83
83
  private scheduled;
@@ -122,6 +122,7 @@ declare class PatchCommitScheduler {
122
122
  restart(): void;
123
123
  getHistory(limit?: number): ReadonlyArray<PatchFlushResult>;
124
124
  setHistoryLimit(limit: number): void;
125
+ updateOptions(options: PatchCommitSchedulerOptions): void;
125
126
  clearHistory(): void;
126
127
  }
127
128
 
@@ -14,6 +14,8 @@ var DEFAULT_TIMEOUT_MS = 16;
14
14
  var COALESCING_DURATION_SAMPLE_LIMIT = 60;
15
15
  var COALESCING_DURATION_ACTIVATE_MS = 6;
16
16
  var COALESCING_DURATION_DEACTIVATE_MS = 4;
17
+ var RETAIN_TOUCHED_IN_HISTORY = typeof process !== "undefined" && process.env ? process.env.NODE_ENV !== "production" : true;
18
+ var EMPTY_TOUCHED_SET = /* @__PURE__ */ new Set();
17
19
  function getDefaultNow() {
18
20
  if (typeof performance !== "undefined" && typeof performance.now === "function") {
19
21
  return () => performance.now();
@@ -55,15 +57,18 @@ var PatchCommitScheduler = class {
55
57
  this.adaptiveBudgetActive = false;
56
58
  this.store = params.store;
57
59
  this.onFlush = params.onFlush;
58
- this.frameBudgetMs = Math.max(1, params.options?.frameBudgetMs ?? 8);
59
- this.maxBatchesPerFlush = params.options?.maxBatchesPerFlush;
60
+ this.frameBudgetMs = Math.max(1, params.options?.frameBudgetMs ?? 10);
61
+ this.maxBatchesPerFlush = params.options?.maxBatchesPerFlush ?? 12;
60
62
  this.now = params.options?.now ?? getDefaultNow();
61
63
  this.raf = params.options?.raf ?? getDefaultRaf();
62
64
  this.cancelRaf = params.options?.cancelRaf ?? getDefaultCancelRaf();
63
65
  this.timeoutMs = Math.max(1, params.options?.timeoutMs ?? DEFAULT_TIMEOUT_MS);
64
- this.lowPriorityFrameBudgetMs = Math.max(1, params.options?.lowPriorityFrameBudgetMs ?? Math.max(2, Math.floor(this.frameBudgetMs / 2)));
65
- this.maxLowPriorityBatchesPerFlush = params.options?.maxLowPriorityBatchesPerFlush ?? 1;
66
- this.urgentQueueThreshold = Math.max(1, params.options?.urgentQueueThreshold ?? 3);
66
+ this.lowPriorityFrameBudgetMs = Math.max(
67
+ 1,
68
+ params.options?.lowPriorityFrameBudgetMs ?? Math.max(2, Math.floor(this.frameBudgetMs * 0.6))
69
+ );
70
+ this.maxLowPriorityBatchesPerFlush = params.options?.maxLowPriorityBatchesPerFlush ?? 2;
71
+ this.urgentQueueThreshold = Math.max(1, params.options?.urgentQueueThreshold ?? 4);
67
72
  this.historyLimit = Math.max(1, params.options?.historyLimit ?? 200);
68
73
  const requestedBatch = params.options?.batch;
69
74
  if (requestedBatch === "microtask") {
@@ -73,7 +78,7 @@ var PatchCommitScheduler = class {
73
78
  } else if (requestedBatch === "rAF") {
74
79
  this.batchStrategy = this.raf ? "rAF" : "timeout";
75
80
  } else {
76
- this.batchStrategy = this.raf ? "rAF" : "timeout";
81
+ this.batchStrategy = "microtask";
77
82
  }
78
83
  if (this.batchStrategy === "microtask" && typeof queueMicrotask !== "function") {
79
84
  this.batchStrategy = this.raf ? "rAF" : "timeout";
@@ -377,7 +382,18 @@ var PatchCommitScheduler = class {
377
382
  }
378
383
  }
379
384
  recordHistory(result) {
380
- this.history.push(result);
385
+ if (RETAIN_TOUCHED_IN_HISTORY) {
386
+ this.history.push(result);
387
+ } else {
388
+ const trimmed = {
389
+ ...result,
390
+ batches: result.batches.map((batch) => ({
391
+ ...batch,
392
+ touched: EMPTY_TOUCHED_SET
393
+ }))
394
+ };
395
+ this.history.push(trimmed);
396
+ }
381
397
  if (this.history.length > this.historyLimit) {
382
398
  this.history.splice(0, this.history.length - this.historyLimit);
383
399
  }
@@ -428,6 +444,51 @@ var PatchCommitScheduler = class {
428
444
  this.history.splice(0, this.history.length - this.historyLimit);
429
445
  }
430
446
  }
447
+ updateOptions(options) {
448
+ if (!options) return;
449
+ let shouldReschedule = false;
450
+ if (typeof options.frameBudgetMs !== "undefined") {
451
+ this.frameBudgetMs = Math.max(1, options.frameBudgetMs);
452
+ shouldReschedule = true;
453
+ }
454
+ if (typeof options.maxBatchesPerFlush !== "undefined") {
455
+ this.maxBatchesPerFlush = options.maxBatchesPerFlush;
456
+ shouldReschedule = true;
457
+ }
458
+ if (typeof options.lowPriorityFrameBudgetMs !== "undefined") {
459
+ this.lowPriorityFrameBudgetMs = Math.max(1, options.lowPriorityFrameBudgetMs);
460
+ shouldReschedule = true;
461
+ }
462
+ if (typeof options.maxLowPriorityBatchesPerFlush !== "undefined") {
463
+ this.maxLowPriorityBatchesPerFlush = options.maxLowPriorityBatchesPerFlush;
464
+ shouldReschedule = true;
465
+ }
466
+ if (typeof options.urgentQueueThreshold !== "undefined") {
467
+ this.urgentQueueThreshold = Math.max(1, options.urgentQueueThreshold);
468
+ shouldReschedule = true;
469
+ }
470
+ if (typeof options.historyLimit !== "undefined") {
471
+ this.setHistoryLimit(options.historyLimit);
472
+ }
473
+ if (typeof options.batch !== "undefined") {
474
+ const requestedBatch = options.batch;
475
+ if (requestedBatch === "microtask") {
476
+ this.batchStrategy = "microtask";
477
+ } else if (requestedBatch === "timeout") {
478
+ this.batchStrategy = "timeout";
479
+ } else if (requestedBatch === "rAF") {
480
+ this.batchStrategy = this.raf ? "rAF" : "timeout";
481
+ }
482
+ if (this.batchStrategy === "microtask" && typeof queueMicrotask !== "function") {
483
+ this.batchStrategy = this.raf ? "rAF" : "timeout";
484
+ }
485
+ shouldReschedule = true;
486
+ }
487
+ if (shouldReschedule && !this.paused && !this.flushing && this.getPendingCount() > 0) {
488
+ this.cancelScheduled();
489
+ this.schedule();
490
+ }
491
+ }
431
492
  clearHistory() {
432
493
  this.history = [];
433
494
  }