@preprio/toolkit 1.0.0-rc.5 → 1.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/astro/index.cjs +93 -4
  2. package/dist/astro/index.js +93 -4
  3. package/dist/{chunk-AWFJ67AQ.js → chunk-6EWXOHZZ.js} +1 -1
  4. package/dist/{chunk-A4J3JRMY.js → chunk-GIZY3JFC.js} +1 -1
  5. package/dist/{chunk-KM2GME62.js → chunk-J4POHQKB.js} +92 -3
  6. package/dist/{chunk-GRFTP62X.js → chunk-OKP6KD3I.js} +1 -1
  7. package/dist/{chunk-A2J7R4LR.js → chunk-WQXLVSHA.js} +1 -1
  8. package/dist/index.cjs +94 -5
  9. package/dist/index.d.cts +5 -4
  10. package/dist/index.d.ts +5 -4
  11. package/dist/index.js +6 -6
  12. package/dist/{live-preview-HCBNBC6C.js → live-preview-PLHDSQ53.js} +2 -2
  13. package/dist/nextjs/components.cjs +1 -1
  14. package/dist/nextjs/components.js +2 -2
  15. package/dist/nextjs/index.cjs +93 -4
  16. package/dist/nextjs/index.d.cts +6 -2
  17. package/dist/nextjs/index.d.ts +6 -2
  18. package/dist/nextjs/index.js +93 -4
  19. package/dist/nextjs/live-action.js +3 -3
  20. package/dist/nextjs/live.cjs +117 -10
  21. package/dist/nextjs/live.d.cts +6 -2
  22. package/dist/nextjs/live.d.ts +6 -2
  23. package/dist/nextjs/live.js +18 -8
  24. package/dist/nuxt/index.cjs +1 -1
  25. package/dist/nuxt/index.js +1 -1
  26. package/dist/nuxt/{live-preview-KO4IKWTX.js → live-preview-T5YCASSA.js} +92 -3
  27. package/dist/nuxt/live.cjs +100 -3
  28. package/dist/nuxt/live.js +1 -1
  29. package/dist/react/components.cjs +1 -1
  30. package/dist/react/components.js +1 -1
  31. package/dist/sveltekit/index.cjs +1 -1
  32. package/dist/sveltekit/index.js +1 -1
  33. package/dist/sveltekit/{live-preview-KO4IKWTX.js → live-preview-T5YCASSA.js} +92 -3
  34. package/dist/sveltekit/live.cjs +100 -3
  35. package/dist/sveltekit/live.js +1 -1
  36. package/package.json +1 -1
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  createPreprPreview,
4
4
  loadTrackingPixel
5
- } from "../chunk-AWFJ67AQ.js";
6
- import "../chunk-A4J3JRMY.js";
5
+ } from "../chunk-6EWXOHZZ.js";
6
+ import "../chunk-GIZY3JFC.js";
7
7
  import "../chunk-Y7JWV7WV.js";
8
8
  import "../chunk-UTKH7DOI.js";
9
9
  import "../chunk-V7MCHPE7.js";
@@ -50,7 +50,7 @@ module.exports = __toCommonJS(nextjs_exports);
50
50
  var import_server = require("next/server");
51
51
 
52
52
  // src/version.ts
53
- var VERSION = "1.0.0-rc.5";
53
+ var VERSION = "1.0.0-rc.7";
54
54
 
55
55
  // src/core/constants.ts
56
56
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -475,6 +475,93 @@ function indexSnapshot(data) {
475
475
  return index;
476
476
  }
477
477
 
478
+ // src/core/live-preview/internal-links.ts
479
+ var INTERNAL_HREF = /^[pa]uuid#/;
480
+ var INTERNAL_MARK = "uuid#";
481
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
482
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
483
+ var TAGS = /<[^>]+>/g;
484
+ var MAX_PAIRINGS = 25e4;
485
+ function anchorsIn(html) {
486
+ const out = [];
487
+ for (const match of html.matchAll(ANCHOR)) {
488
+ const attributes = match[1];
489
+ const inner = match[2];
490
+ const href = HREF.exec(attributes)?.[3] ?? null;
491
+ out.push({
492
+ start: match.index ?? 0,
493
+ end: (match.index ?? 0) + match[0].length,
494
+ attributes,
495
+ inner,
496
+ href,
497
+ internal: href !== null && INTERNAL_HREF.test(href),
498
+ text: inner.replace(TAGS, "").trim()
499
+ });
500
+ }
501
+ return out;
502
+ }
503
+ function fit(pushed, page) {
504
+ if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
505
+ return pushed.text === page.text ? 2 : 1;
506
+ }
507
+ function align(pushed, page) {
508
+ const out = new Array(pushed.length).fill(-1);
509
+ if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
510
+ const cols = page.length + 1;
511
+ const score = new Int32Array((pushed.length + 1) * cols);
512
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
513
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
514
+ const at = i2 * cols + j2;
515
+ const pair = fit(pushed[i2], page[j2]);
516
+ score[at] = Math.max(
517
+ score[at + cols],
518
+ score[at + 1],
519
+ pair ? pair + score[at + cols + 1] : 0
520
+ );
521
+ }
522
+ }
523
+ let i = 0;
524
+ let j = 0;
525
+ while (i < pushed.length && j < page.length) {
526
+ const at = i * cols + j;
527
+ const pair = fit(pushed[i], page[j]);
528
+ if (pair && score[at] === pair + score[at + cols + 1]) {
529
+ out[i++] = j++;
530
+ } else if (score[at + cols] >= score[at + 1]) {
531
+ i++;
532
+ } else {
533
+ j++;
534
+ }
535
+ }
536
+ return out;
537
+ }
538
+ function resolveInternalLinks(current, value) {
539
+ if (!value.includes(INTERNAL_MARK)) return value;
540
+ const pushed = anchorsIn(value);
541
+ if (!pushed.some((anchor) => anchor.internal)) return value;
542
+ const page = typeof current === "string" ? anchorsIn(current) : [];
543
+ const pairs = align(pushed, page);
544
+ let out = "";
545
+ let cursor = 0;
546
+ pushed.forEach((anchor, i) => {
547
+ if (!anchor.internal) return;
548
+ out += value.slice(cursor, anchor.start);
549
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
550
+ if (match?.href != null) {
551
+ const href = match.href;
552
+ const attributes = anchor.attributes.replace(
553
+ HREF,
554
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
555
+ );
556
+ out += `<a${attributes}>${anchor.inner}</a>`;
557
+ } else {
558
+ out += anchor.inner;
559
+ }
560
+ cursor = anchor.end;
561
+ });
562
+ return out + value.slice(cursor);
563
+ }
564
+
478
565
  // src/core/live-preview/patch.ts
479
566
  var import_stega2 = require("@vercel/stega");
480
567
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
@@ -574,7 +661,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
574
661
  } else if (!isPatchable(container[key])) {
575
662
  return root;
576
663
  } else {
577
- next = keepEditLink(container[key], value);
664
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
665
+ next = keepEditLink(container[key], linked);
578
666
  }
579
667
  if (container[key] === next) return root;
580
668
  const newRoot = cloneNode(root);
@@ -599,7 +687,7 @@ function listKeysOf(entry) {
599
687
  return keys;
600
688
  }
601
689
  function buildText(entry, template) {
602
- const body = typeof entry.body === "string" ? entry.body : "";
690
+ const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
603
691
  const full = {
604
692
  __typename: "Text",
605
693
  _id: entry._id,
@@ -1286,7 +1374,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
1286
1374
  out[field.key] = [];
1287
1375
  continue;
1288
1376
  }
1289
- const scalar = value === void 0 || value !== null && typeof value === "object" ? null : value;
1377
+ const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
1378
+ const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
1290
1379
  const target = typeof scalar === "string" ? editField(field.name) : null;
1291
1380
  out[field.key] = target && links ? links.encode(scalar, target) : scalar;
1292
1381
  }
@@ -382,8 +382,12 @@ interface PreprRefreshProps {
382
382
  strictMode?: boolean;
383
383
  /**
384
384
  * How long typing must pause, in milliseconds, before the unsaved changes
385
- * go to the server. Default 150. Lower shows changes sooner at the cost of
386
- * more server renders; raise it when a render is expensive.
385
+ * go to the server. Default 0: a change goes out as soon as the editor
386
+ * sends it, which it does after a pause of its own. Renders run one at a
387
+ * time either way; raise this when a render is expensive, to have fewer of
388
+ * them. While typing continues, changes still go out at least every four
389
+ * times this value (600 ms at the least), so the preview never stalls
390
+ * until a pause.
387
391
  */
388
392
  syncDebounceMs?: number;
389
393
  }
@@ -382,8 +382,12 @@ interface PreprRefreshProps {
382
382
  strictMode?: boolean;
383
383
  /**
384
384
  * How long typing must pause, in milliseconds, before the unsaved changes
385
- * go to the server. Default 150. Lower shows changes sooner at the cost of
386
- * more server renders; raise it when a render is expensive.
385
+ * go to the server. Default 0: a change goes out as soon as the editor
386
+ * sends it, which it does after a pause of its own. Renders run one at a
387
+ * time either way; raise this when a render is expensive, to have fewer of
388
+ * them. While typing continues, changes still go out at least every four
389
+ * times this value (600 ms at the least), so the preview never stalls
390
+ * until a pause.
387
391
  */
388
392
  syncDebounceMs?: number;
389
393
  }
@@ -2,7 +2,7 @@
2
2
  import { NextResponse } from "next/server";
3
3
 
4
4
  // src/version.ts
5
- var VERSION = "1.0.0-rc.5";
5
+ var VERSION = "1.0.0-rc.7";
6
6
 
7
7
  // src/core/constants.ts
8
8
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -431,6 +431,93 @@ function indexSnapshot(data) {
431
431
  return index;
432
432
  }
433
433
 
434
+ // src/core/live-preview/internal-links.ts
435
+ var INTERNAL_HREF = /^[pa]uuid#/;
436
+ var INTERNAL_MARK = "uuid#";
437
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
438
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
439
+ var TAGS = /<[^>]+>/g;
440
+ var MAX_PAIRINGS = 25e4;
441
+ function anchorsIn(html) {
442
+ const out = [];
443
+ for (const match of html.matchAll(ANCHOR)) {
444
+ const attributes = match[1];
445
+ const inner = match[2];
446
+ const href = HREF.exec(attributes)?.[3] ?? null;
447
+ out.push({
448
+ start: match.index ?? 0,
449
+ end: (match.index ?? 0) + match[0].length,
450
+ attributes,
451
+ inner,
452
+ href,
453
+ internal: href !== null && INTERNAL_HREF.test(href),
454
+ text: inner.replace(TAGS, "").trim()
455
+ });
456
+ }
457
+ return out;
458
+ }
459
+ function fit(pushed, page) {
460
+ if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
461
+ return pushed.text === page.text ? 2 : 1;
462
+ }
463
+ function align(pushed, page) {
464
+ const out = new Array(pushed.length).fill(-1);
465
+ if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
466
+ const cols = page.length + 1;
467
+ const score = new Int32Array((pushed.length + 1) * cols);
468
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
469
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
470
+ const at = i2 * cols + j2;
471
+ const pair = fit(pushed[i2], page[j2]);
472
+ score[at] = Math.max(
473
+ score[at + cols],
474
+ score[at + 1],
475
+ pair ? pair + score[at + cols + 1] : 0
476
+ );
477
+ }
478
+ }
479
+ let i = 0;
480
+ let j = 0;
481
+ while (i < pushed.length && j < page.length) {
482
+ const at = i * cols + j;
483
+ const pair = fit(pushed[i], page[j]);
484
+ if (pair && score[at] === pair + score[at + cols + 1]) {
485
+ out[i++] = j++;
486
+ } else if (score[at + cols] >= score[at + 1]) {
487
+ i++;
488
+ } else {
489
+ j++;
490
+ }
491
+ }
492
+ return out;
493
+ }
494
+ function resolveInternalLinks(current, value) {
495
+ if (!value.includes(INTERNAL_MARK)) return value;
496
+ const pushed = anchorsIn(value);
497
+ if (!pushed.some((anchor) => anchor.internal)) return value;
498
+ const page = typeof current === "string" ? anchorsIn(current) : [];
499
+ const pairs = align(pushed, page);
500
+ let out = "";
501
+ let cursor = 0;
502
+ pushed.forEach((anchor, i) => {
503
+ if (!anchor.internal) return;
504
+ out += value.slice(cursor, anchor.start);
505
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
506
+ if (match?.href != null) {
507
+ const href = match.href;
508
+ const attributes = anchor.attributes.replace(
509
+ HREF,
510
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
511
+ );
512
+ out += `<a${attributes}>${anchor.inner}</a>`;
513
+ } else {
514
+ out += anchor.inner;
515
+ }
516
+ cursor = anchor.end;
517
+ });
518
+ return out + value.slice(cursor);
519
+ }
520
+
434
521
  // src/core/live-preview/patch.ts
435
522
  import { vercelStegaSplit as vercelStegaSplit2 } from "@vercel/stega";
436
523
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
@@ -530,7 +617,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
530
617
  } else if (!isPatchable(container[key])) {
531
618
  return root;
532
619
  } else {
533
- next = keepEditLink(container[key], value);
620
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
621
+ next = keepEditLink(container[key], linked);
534
622
  }
535
623
  if (container[key] === next) return root;
536
624
  const newRoot = cloneNode(root);
@@ -555,7 +643,7 @@ function listKeysOf(entry) {
555
643
  return keys;
556
644
  }
557
645
  function buildText(entry, template) {
558
- const body = typeof entry.body === "string" ? entry.body : "";
646
+ const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
559
647
  const full = {
560
648
  __typename: "Text",
561
649
  _id: entry._id,
@@ -1242,7 +1330,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
1242
1330
  out[field.key] = [];
1243
1331
  continue;
1244
1332
  }
1245
- const scalar = value === void 0 || value !== null && typeof value === "object" ? null : value;
1333
+ const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
1334
+ const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
1246
1335
  const target = typeof scalar === "string" ? editField(field.name) : null;
1247
1336
  out[field.key] = target && links ? links.encode(scalar, target) : scalar;
1248
1337
  }
@@ -1,11 +1,11 @@
1
1
  "use server";
2
2
  import {
3
3
  isPreviewFromHeaders
4
- } from "../chunk-GRFTP62X.js";
5
- import "../chunk-A4J3JRMY.js";
4
+ } from "../chunk-OKP6KD3I.js";
5
+ import "../chunk-GIZY3JFC.js";
6
6
  import {
7
7
  parsePatchLog
8
- } from "../chunk-KM2GME62.js";
8
+ } from "../chunk-J4POHQKB.js";
9
9
  import "../chunk-V7MCHPE7.js";
10
10
 
11
11
  // src/nextjs/live-action.ts
@@ -215,6 +215,99 @@ var init_field_name = __esm({
215
215
  }
216
216
  });
217
217
 
218
+ // src/core/live-preview/internal-links.ts
219
+ function anchorsIn(html) {
220
+ const out = [];
221
+ for (const match of html.matchAll(ANCHOR)) {
222
+ const attributes = match[1];
223
+ const inner = match[2];
224
+ const href = HREF.exec(attributes)?.[3] ?? null;
225
+ out.push({
226
+ start: match.index ?? 0,
227
+ end: (match.index ?? 0) + match[0].length,
228
+ attributes,
229
+ inner,
230
+ href,
231
+ internal: href !== null && INTERNAL_HREF.test(href),
232
+ text: inner.replace(TAGS, "").trim()
233
+ });
234
+ }
235
+ return out;
236
+ }
237
+ function fit(pushed, page) {
238
+ if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
239
+ return pushed.text === page.text ? 2 : 1;
240
+ }
241
+ function align(pushed, page) {
242
+ const out = new Array(pushed.length).fill(-1);
243
+ if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
244
+ const cols = page.length + 1;
245
+ const score = new Int32Array((pushed.length + 1) * cols);
246
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
247
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
248
+ const at = i2 * cols + j2;
249
+ const pair = fit(pushed[i2], page[j2]);
250
+ score[at] = Math.max(
251
+ score[at + cols],
252
+ score[at + 1],
253
+ pair ? pair + score[at + cols + 1] : 0
254
+ );
255
+ }
256
+ }
257
+ let i = 0;
258
+ let j = 0;
259
+ while (i < pushed.length && j < page.length) {
260
+ const at = i * cols + j;
261
+ const pair = fit(pushed[i], page[j]);
262
+ if (pair && score[at] === pair + score[at + cols + 1]) {
263
+ out[i++] = j++;
264
+ } else if (score[at + cols] >= score[at + 1]) {
265
+ i++;
266
+ } else {
267
+ j++;
268
+ }
269
+ }
270
+ return out;
271
+ }
272
+ function resolveInternalLinks(current, value) {
273
+ if (!value.includes(INTERNAL_MARK)) return value;
274
+ const pushed = anchorsIn(value);
275
+ if (!pushed.some((anchor) => anchor.internal)) return value;
276
+ const page = typeof current === "string" ? anchorsIn(current) : [];
277
+ const pairs = align(pushed, page);
278
+ let out = "";
279
+ let cursor = 0;
280
+ pushed.forEach((anchor, i) => {
281
+ if (!anchor.internal) return;
282
+ out += value.slice(cursor, anchor.start);
283
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
284
+ if (match?.href != null) {
285
+ const href = match.href;
286
+ const attributes = anchor.attributes.replace(
287
+ HREF,
288
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
289
+ );
290
+ out += `<a${attributes}>${anchor.inner}</a>`;
291
+ } else {
292
+ out += anchor.inner;
293
+ }
294
+ cursor = anchor.end;
295
+ });
296
+ return out + value.slice(cursor);
297
+ }
298
+ var INTERNAL_HREF, INTERNAL_MARK, ANCHOR, HREF, TAGS, MAX_PAIRINGS;
299
+ var init_internal_links = __esm({
300
+ "src/core/live-preview/internal-links.ts"() {
301
+ "use strict";
302
+ INTERNAL_HREF = /^[pa]uuid#/;
303
+ INTERNAL_MARK = "uuid#";
304
+ ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
305
+ HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
306
+ TAGS = /<[^>]+>/g;
307
+ MAX_PAIRINGS = 25e4;
308
+ }
309
+ });
310
+
218
311
  // src/core/live-preview/patch.ts
219
312
  function mergeObject(current, incoming) {
220
313
  let changed = false;
@@ -382,7 +475,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
382
475
  } else if (!isPatchable(container[key])) {
383
476
  return root;
384
477
  } else {
385
- next = keepEditLink(container[key], value);
478
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
479
+ next = keepEditLink(container[key], linked);
386
480
  }
387
481
  if (container[key] === next) return root;
388
482
  const newRoot = cloneNode(root);
@@ -407,7 +501,7 @@ function listKeysOf(entry) {
407
501
  return keys;
408
502
  }
409
503
  function buildText(entry, template) {
410
- const body = typeof entry.body === "string" ? entry.body : "";
504
+ const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
411
505
  const full = {
412
506
  __typename: "Text",
413
507
  _id: entry._id,
@@ -498,6 +592,7 @@ var init_patch = __esm({
498
592
  init_guards();
499
593
  import_stega = require("@vercel/stega");
500
594
  init_field_name();
595
+ init_internal_links();
501
596
  INDEX_SEGMENT = /^\d+$/;
502
597
  FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
503
598
  }
@@ -1620,7 +1715,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
1620
1715
  out[field.key] = [];
1621
1716
  continue;
1622
1717
  }
1623
- const scalar = value === void 0 || value !== null && typeof value === "object" ? null : value;
1718
+ const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
1719
+ const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
1624
1720
  const target = typeof scalar === "string" ? editField(field.name) : null;
1625
1721
  out[field.key] = target && links ? links.encode(scalar, target) : scalar;
1626
1722
  }
@@ -1686,6 +1782,7 @@ var init_normalize_query = __esm({
1686
1782
  init_utils();
1687
1783
  init_field_name();
1688
1784
  init_index_snapshot();
1785
+ init_internal_links();
1689
1786
  init_patch();
1690
1787
  init_query_document();
1691
1788
  init_validate();
@@ -1797,12 +1894,13 @@ function createLiveStarter(options = {}) {
1797
1894
  // src/nextjs/live.ts
1798
1895
  var import_live_action = require("./live-action.cjs");
1799
1896
  var debug6 = createScopedLogger("live-preview:next");
1800
- var LOG_SYNC_DEBOUNCE_MS = 150;
1897
+ var LOG_SYNC_DEBOUNCE_MS = 0;
1898
+ var MIN_SYNC_MAX_WAIT_MS = 600;
1801
1899
  var debounceOf = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : LOG_SYNC_DEBOUNCE_MS;
1802
1900
  var starter = createLiveStarter({
1803
1901
  storeOptions() {
1804
1902
  const skipped = new Set(quarantined());
1805
- return { accept: (patch) => !skipped.has(patchKey(patch)) };
1903
+ return skipped.size ? { accept: (patch) => !skipped.has(patchKey(patch)) } : {};
1806
1904
  },
1807
1905
  onStart: (store) => watchClientRenders(store),
1808
1906
  onReset() {
@@ -1950,6 +2048,8 @@ function watchClientRenders(watched) {
1950
2048
  });
1951
2049
  }
1952
2050
  function createLogSync(debounceMs) {
2051
+ const maxWaitMs = Math.max(debounceMs * 4, MIN_SYNC_MAX_WAIT_MS);
2052
+ let waitingSince = null;
1953
2053
  let timer = null;
1954
2054
  let inFlight = false;
1955
2055
  let pending = null;
@@ -1997,15 +2097,22 @@ function createLogSync(debounceMs) {
1997
2097
  schedule(log) {
1998
2098
  cancelled = false;
1999
2099
  if (timer) clearTimeout(timer);
2000
- timer = setTimeout(() => {
2001
- timer = null;
2002
- if (inFlight) pending = log;
2003
- else void send(log);
2004
- }, debounceMs);
2100
+ waitingSince ?? (waitingSince = Date.now());
2101
+ const left = waitingSince + maxWaitMs - Date.now();
2102
+ timer = setTimeout(
2103
+ () => {
2104
+ timer = null;
2105
+ waitingSince = null;
2106
+ if (inFlight) pending = log;
2107
+ else void send(log);
2108
+ },
2109
+ Math.max(0, Math.min(debounceMs, left))
2110
+ );
2005
2111
  },
2006
2112
  cancel() {
2007
2113
  cancelled = true;
2008
2114
  pending = null;
2115
+ waitingSince = null;
2009
2116
  if (timer) clearTimeout(timer);
2010
2117
  timer = null;
2011
2118
  },
@@ -25,8 +25,12 @@ interface PreprRefreshProps {
25
25
  strictMode?: boolean;
26
26
  /**
27
27
  * How long typing must pause, in milliseconds, before the unsaved changes
28
- * go to the server. Default 150. Lower shows changes sooner at the cost of
29
- * more server renders; raise it when a render is expensive.
28
+ * go to the server. Default 0: a change goes out as soon as the editor
29
+ * sends it, which it does after a pause of its own. Renders run one at a
30
+ * time either way; raise this when a render is expensive, to have fewer of
31
+ * them. While typing continues, changes still go out at least every four
32
+ * times this value (600 ms at the least), so the preview never stalls
33
+ * until a pause.
30
34
  */
31
35
  syncDebounceMs?: number;
32
36
  }
@@ -25,8 +25,12 @@ interface PreprRefreshProps {
25
25
  strictMode?: boolean;
26
26
  /**
27
27
  * How long typing must pause, in milliseconds, before the unsaved changes
28
- * go to the server. Default 150. Lower shows changes sooner at the cost of
29
- * more server renders; raise it when a render is expensive.
28
+ * go to the server. Default 0: a change goes out as soon as the editor
29
+ * sends it, which it does after a pause of its own. Renders run one at a
30
+ * time either way; raise this when a render is expensive, to have fewer of
31
+ * them. While typing continues, changes still go out at least every four
32
+ * times this value (600 ms at the least), so the preview never stalls
33
+ * until a pause.
30
34
  */
31
35
  syncDebounceMs?: number;
32
36
  }
@@ -45,7 +45,7 @@ function createLiveStarter(options = {}) {
45
45
  }
46
46
  },
47
47
  start() {
48
- starting ?? (starting = import("../live-preview-HCBNBC6C.js").then((runtime) => {
48
+ starting ?? (starting = import("../live-preview-PLHDSQ53.js").then((runtime) => {
49
49
  const started = runtime.createLiveStore(options.storeOptions?.());
50
50
  options.onStart?.(started, runtime);
51
51
  bridge = runtime.createLiveBridge(started, {
@@ -75,12 +75,13 @@ function createLiveStarter(options = {}) {
75
75
  // src/nextjs/live.ts
76
76
  import { syncPreprLiveLog } from "./live-action.js";
77
77
  var debug = createScopedLogger("live-preview:next");
78
- var LOG_SYNC_DEBOUNCE_MS = 150;
78
+ var LOG_SYNC_DEBOUNCE_MS = 0;
79
+ var MIN_SYNC_MAX_WAIT_MS = 600;
79
80
  var debounceOf = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : LOG_SYNC_DEBOUNCE_MS;
80
81
  var starter = createLiveStarter({
81
82
  storeOptions() {
82
83
  const skipped = new Set(quarantined());
83
- return { accept: (patch) => !skipped.has(patchKey(patch)) };
84
+ return skipped.size ? { accept: (patch) => !skipped.has(patchKey(patch)) } : {};
84
85
  },
85
86
  onStart: (store) => watchClientRenders(store),
86
87
  onReset() {
@@ -228,6 +229,8 @@ function watchClientRenders(watched) {
228
229
  });
229
230
  }
230
231
  function createLogSync(debounceMs) {
232
+ const maxWaitMs = Math.max(debounceMs * 4, MIN_SYNC_MAX_WAIT_MS);
233
+ let waitingSince = null;
231
234
  let timer = null;
232
235
  let inFlight = false;
233
236
  let pending = null;
@@ -275,15 +278,22 @@ function createLogSync(debounceMs) {
275
278
  schedule(log) {
276
279
  cancelled = false;
277
280
  if (timer) clearTimeout(timer);
278
- timer = setTimeout(() => {
279
- timer = null;
280
- if (inFlight) pending = log;
281
- else void send(log);
282
- }, debounceMs);
281
+ waitingSince ?? (waitingSince = Date.now());
282
+ const left = waitingSince + maxWaitMs - Date.now();
283
+ timer = setTimeout(
284
+ () => {
285
+ timer = null;
286
+ waitingSince = null;
287
+ if (inFlight) pending = log;
288
+ else void send(log);
289
+ },
290
+ Math.max(0, Math.min(debounceMs, left))
291
+ );
283
292
  },
284
293
  cancel() {
285
294
  cancelled = true;
286
295
  pending = null;
296
+ waitingSince = null;
287
297
  if (timer) clearTimeout(timer);
288
298
  timer = null;
289
299
  },
@@ -35,7 +35,7 @@ __export(nuxt_exports, {
35
35
  module.exports = __toCommonJS(nuxt_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "1.0.0-rc.5";
38
+ var VERSION = "1.0.0-rc.7";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-LUKVPOJ2.js";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = "1.0.0-rc.5";
14
+ var VERSION = "1.0.0-rc.7";
15
15
 
16
16
  // src/core/features.ts
17
17
  function isEnabled(config) {