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

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.
@@ -34,7 +34,7 @@ __export(astro_exports, {
34
34
  module.exports = __toCommonJS(astro_exports);
35
35
 
36
36
  // src/version.ts
37
- var VERSION = "1.0.0-rc.5";
37
+ var VERSION = "1.0.0-rc.6";
38
38
 
39
39
  // src/core/constants.ts
40
40
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -565,6 +565,94 @@ function indexSnapshot(data) {
565
565
 
566
566
  // src/core/live-preview/patch.ts
567
567
  var import_stega2 = require("@vercel/stega");
568
+
569
+ // src/core/live-preview/internal-links.ts
570
+ var INTERNAL_HREF = /^[pa]uuid#/;
571
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
572
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
573
+ var TAGS = /<[^>]+>/g;
574
+ function anchorsIn(html) {
575
+ const out = [];
576
+ for (const match of html.matchAll(ANCHOR)) {
577
+ const attributes = match[1];
578
+ const inner = match[2];
579
+ out.push({
580
+ start: match.index ?? 0,
581
+ end: (match.index ?? 0) + match[0].length,
582
+ attributes,
583
+ inner,
584
+ href: HREF.exec(attributes)?.[3] ?? null,
585
+ text: inner.replace(TAGS, "").trim()
586
+ });
587
+ }
588
+ return out;
589
+ }
590
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
591
+ function fit(pushed, page) {
592
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
593
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
594
+ return 0;
595
+ return pushed.text === page.text ? 2 : 1;
596
+ }
597
+ function align(pushed, page) {
598
+ const rows = pushed.length + 1;
599
+ const cols = page.length + 1;
600
+ const score = Array.from(
601
+ { length: rows },
602
+ () => new Array(cols).fill(0)
603
+ );
604
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
605
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
606
+ const pair = fit(pushed[i2], page[j2]);
607
+ score[i2][j2] = Math.max(
608
+ score[i2 + 1][j2],
609
+ score[i2][j2 + 1],
610
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
611
+ );
612
+ }
613
+ }
614
+ const out = new Array(pushed.length).fill(-1);
615
+ let i = 0;
616
+ let j = 0;
617
+ while (i < pushed.length && j < page.length) {
618
+ const pair = fit(pushed[i], page[j]);
619
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
620
+ out[i++] = j++;
621
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
622
+ i++;
623
+ } else {
624
+ j++;
625
+ }
626
+ }
627
+ return out;
628
+ }
629
+ function resolveInternalLinks(current, value) {
630
+ const pushed = anchorsIn(value);
631
+ if (!pushed.some(isInternal)) return value;
632
+ const page = typeof current === "string" ? anchorsIn(current) : [];
633
+ const pairs = align(pushed, page);
634
+ let out = "";
635
+ let cursor = 0;
636
+ pushed.forEach((anchor, i) => {
637
+ if (!isInternal(anchor)) return;
638
+ out += value.slice(cursor, anchor.start);
639
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
640
+ if (match?.href != null) {
641
+ const href = match.href;
642
+ const attributes = anchor.attributes.replace(
643
+ HREF,
644
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
645
+ );
646
+ out += `<a${attributes}>${anchor.inner}</a>`;
647
+ } else {
648
+ out += anchor.inner;
649
+ }
650
+ cursor = anchor.end;
651
+ });
652
+ return out + value.slice(cursor);
653
+ }
654
+
655
+ // src/core/live-preview/patch.ts
568
656
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
569
657
  function mergeObject(current, incoming) {
570
658
  let changed = false;
@@ -662,7 +750,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
662
750
  } else if (!isPatchable(container[key])) {
663
751
  return root;
664
752
  } else {
665
- next = keepEditLink(container[key], value);
753
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
754
+ next = keepEditLink(container[key], linked);
666
755
  }
667
756
  if (container[key] === next) return root;
668
757
  const newRoot = cloneNode(root);
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "1.0.0-rc.5";
2
+ var VERSION = "1.0.0-rc.6";
3
3
 
4
4
  // src/core/constants.ts
5
5
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -534,6 +534,94 @@ function indexSnapshot(data) {
534
534
 
535
535
  // src/core/live-preview/patch.ts
536
536
  import { vercelStegaSplit as vercelStegaSplit2 } from "@vercel/stega";
537
+
538
+ // src/core/live-preview/internal-links.ts
539
+ var INTERNAL_HREF = /^[pa]uuid#/;
540
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
541
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
542
+ var TAGS = /<[^>]+>/g;
543
+ function anchorsIn(html) {
544
+ const out = [];
545
+ for (const match of html.matchAll(ANCHOR)) {
546
+ const attributes = match[1];
547
+ const inner = match[2];
548
+ out.push({
549
+ start: match.index ?? 0,
550
+ end: (match.index ?? 0) + match[0].length,
551
+ attributes,
552
+ inner,
553
+ href: HREF.exec(attributes)?.[3] ?? null,
554
+ text: inner.replace(TAGS, "").trim()
555
+ });
556
+ }
557
+ return out;
558
+ }
559
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
560
+ function fit(pushed, page) {
561
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
562
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
563
+ return 0;
564
+ return pushed.text === page.text ? 2 : 1;
565
+ }
566
+ function align(pushed, page) {
567
+ const rows = pushed.length + 1;
568
+ const cols = page.length + 1;
569
+ const score = Array.from(
570
+ { length: rows },
571
+ () => new Array(cols).fill(0)
572
+ );
573
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
574
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
575
+ const pair = fit(pushed[i2], page[j2]);
576
+ score[i2][j2] = Math.max(
577
+ score[i2 + 1][j2],
578
+ score[i2][j2 + 1],
579
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
580
+ );
581
+ }
582
+ }
583
+ const out = new Array(pushed.length).fill(-1);
584
+ let i = 0;
585
+ let j = 0;
586
+ while (i < pushed.length && j < page.length) {
587
+ const pair = fit(pushed[i], page[j]);
588
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
589
+ out[i++] = j++;
590
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
591
+ i++;
592
+ } else {
593
+ j++;
594
+ }
595
+ }
596
+ return out;
597
+ }
598
+ function resolveInternalLinks(current, value) {
599
+ const pushed = anchorsIn(value);
600
+ if (!pushed.some(isInternal)) return value;
601
+ const page = typeof current === "string" ? anchorsIn(current) : [];
602
+ const pairs = align(pushed, page);
603
+ let out = "";
604
+ let cursor = 0;
605
+ pushed.forEach((anchor, i) => {
606
+ if (!isInternal(anchor)) return;
607
+ out += value.slice(cursor, anchor.start);
608
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
609
+ if (match?.href != null) {
610
+ const href = match.href;
611
+ const attributes = anchor.attributes.replace(
612
+ HREF,
613
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
614
+ );
615
+ out += `<a${attributes}>${anchor.inner}</a>`;
616
+ } else {
617
+ out += anchor.inner;
618
+ }
619
+ cursor = anchor.end;
620
+ });
621
+ return out + value.slice(cursor);
622
+ }
623
+
624
+ // src/core/live-preview/patch.ts
537
625
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
538
626
  function mergeObject(current, incoming) {
539
627
  let changed = false;
@@ -631,7 +719,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
631
719
  } else if (!isPatchable(container[key])) {
632
720
  return root;
633
721
  } else {
634
- next = keepEditLink(container[key], value);
722
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
723
+ next = keepEditLink(container[key], linked);
635
724
  }
636
725
  if (container[key] === next) return root;
637
726
  const newRoot = cloneNode(root);
@@ -14,7 +14,7 @@ import {
14
14
  parseListEntries,
15
15
  patchSnapshot,
16
16
  syncListSnapshot
17
- } from "./chunk-KM2GME62.js";
17
+ } from "./chunk-RWFAFYHU.js";
18
18
  import {
19
19
  createScopedLogger,
20
20
  getTrustedParentOrigin,
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "1.0.0-rc.5";
2
+ var VERSION = "1.0.0-rc.6";
3
3
 
4
4
  // src/core/features.ts
5
5
  function isEnabled(config) {
@@ -282,6 +282,94 @@ function indexSnapshot(data) {
282
282
 
283
283
  // src/core/live-preview/patch.ts
284
284
  import { vercelStegaSplit as vercelStegaSplit2 } from "@vercel/stega";
285
+
286
+ // src/core/live-preview/internal-links.ts
287
+ var INTERNAL_HREF = /^[pa]uuid#/;
288
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
289
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
290
+ var TAGS = /<[^>]+>/g;
291
+ function anchorsIn(html) {
292
+ const out = [];
293
+ for (const match of html.matchAll(ANCHOR)) {
294
+ const attributes = match[1];
295
+ const inner = match[2];
296
+ out.push({
297
+ start: match.index ?? 0,
298
+ end: (match.index ?? 0) + match[0].length,
299
+ attributes,
300
+ inner,
301
+ href: HREF.exec(attributes)?.[3] ?? null,
302
+ text: inner.replace(TAGS, "").trim()
303
+ });
304
+ }
305
+ return out;
306
+ }
307
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
308
+ function fit(pushed, page) {
309
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
310
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
311
+ return 0;
312
+ return pushed.text === page.text ? 2 : 1;
313
+ }
314
+ function align(pushed, page) {
315
+ const rows = pushed.length + 1;
316
+ const cols = page.length + 1;
317
+ const score = Array.from(
318
+ { length: rows },
319
+ () => new Array(cols).fill(0)
320
+ );
321
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
322
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
323
+ const pair = fit(pushed[i2], page[j2]);
324
+ score[i2][j2] = Math.max(
325
+ score[i2 + 1][j2],
326
+ score[i2][j2 + 1],
327
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
328
+ );
329
+ }
330
+ }
331
+ const out = new Array(pushed.length).fill(-1);
332
+ let i = 0;
333
+ let j = 0;
334
+ while (i < pushed.length && j < page.length) {
335
+ const pair = fit(pushed[i], page[j]);
336
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
337
+ out[i++] = j++;
338
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
339
+ i++;
340
+ } else {
341
+ j++;
342
+ }
343
+ }
344
+ return out;
345
+ }
346
+ function resolveInternalLinks(current, value) {
347
+ const pushed = anchorsIn(value);
348
+ if (!pushed.some(isInternal)) return value;
349
+ const page = typeof current === "string" ? anchorsIn(current) : [];
350
+ const pairs = align(pushed, page);
351
+ let out = "";
352
+ let cursor = 0;
353
+ pushed.forEach((anchor, i) => {
354
+ if (!isInternal(anchor)) return;
355
+ out += value.slice(cursor, anchor.start);
356
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
357
+ if (match?.href != null) {
358
+ const href = match.href;
359
+ const attributes = anchor.attributes.replace(
360
+ HREF,
361
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
362
+ );
363
+ out += `<a${attributes}>${anchor.inner}</a>`;
364
+ } else {
365
+ out += anchor.inner;
366
+ }
367
+ cursor = anchor.end;
368
+ });
369
+ return out + value.slice(cursor);
370
+ }
371
+
372
+ // src/core/live-preview/patch.ts
285
373
  var INDEX_SEGMENT = /^\d+$/;
286
374
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
287
375
  function mergeObject(current, incoming) {
@@ -450,7 +538,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
450
538
  } else if (!isPatchable(container[key])) {
451
539
  return root;
452
540
  } else {
453
- next = keepEditLink(container[key], value);
541
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
542
+ next = keepEditLink(container[key], linked);
454
543
  }
455
544
  if (container[key] === next) return root;
456
545
  const newRoot = cloneNode(root);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  VERSION,
3
3
  resolveFeatures
4
- } from "./chunk-A4J3JRMY.js";
4
+ } from "./chunk-OCTRCNW2.js";
5
5
 
6
6
  // src/core/server.ts
7
7
  var PreprError = class extends Error {
@@ -2,7 +2,7 @@ import {
2
2
  ALL_FEATURES_ENABLED,
3
3
  VERSION,
4
4
  resolveFeatures
5
- } from "./chunk-A4J3JRMY.js";
5
+ } from "./chunk-OCTRCNW2.js";
6
6
  import {
7
7
  createIframeBridge,
8
8
  isLocale,
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ __export(src_exports, {
51
51
  module.exports = __toCommonJS(src_exports);
52
52
 
53
53
  // src/version.ts
54
- var VERSION = "1.0.0-rc.5";
54
+ var VERSION = "1.0.0-rc.6";
55
55
 
56
56
  // src/core/features.ts
57
57
  function isEnabled(config) {
@@ -4048,6 +4048,94 @@ function indexSnapshot(data) {
4048
4048
 
4049
4049
  // src/core/live-preview/patch.ts
4050
4050
  var import_stega6 = require("@vercel/stega");
4051
+
4052
+ // src/core/live-preview/internal-links.ts
4053
+ var INTERNAL_HREF = /^[pa]uuid#/;
4054
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
4055
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
4056
+ var TAGS = /<[^>]+>/g;
4057
+ function anchorsIn(html) {
4058
+ const out = [];
4059
+ for (const match of html.matchAll(ANCHOR)) {
4060
+ const attributes = match[1];
4061
+ const inner = match[2];
4062
+ out.push({
4063
+ start: match.index ?? 0,
4064
+ end: (match.index ?? 0) + match[0].length,
4065
+ attributes,
4066
+ inner,
4067
+ href: HREF.exec(attributes)?.[3] ?? null,
4068
+ text: inner.replace(TAGS, "").trim()
4069
+ });
4070
+ }
4071
+ return out;
4072
+ }
4073
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
4074
+ function fit(pushed, page) {
4075
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
4076
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
4077
+ return 0;
4078
+ return pushed.text === page.text ? 2 : 1;
4079
+ }
4080
+ function align(pushed, page) {
4081
+ const rows = pushed.length + 1;
4082
+ const cols = page.length + 1;
4083
+ const score = Array.from(
4084
+ { length: rows },
4085
+ () => new Array(cols).fill(0)
4086
+ );
4087
+ for (let i3 = pushed.length - 1; i3 >= 0; i3--) {
4088
+ for (let j3 = page.length - 1; j3 >= 0; j3--) {
4089
+ const pair = fit(pushed[i3], page[j3]);
4090
+ score[i3][j3] = Math.max(
4091
+ score[i3 + 1][j3],
4092
+ score[i3][j3 + 1],
4093
+ pair ? pair + score[i3 + 1][j3 + 1] : 0
4094
+ );
4095
+ }
4096
+ }
4097
+ const out = new Array(pushed.length).fill(-1);
4098
+ let i2 = 0;
4099
+ let j2 = 0;
4100
+ while (i2 < pushed.length && j2 < page.length) {
4101
+ const pair = fit(pushed[i2], page[j2]);
4102
+ if (pair && score[i2][j2] === pair + score[i2 + 1][j2 + 1]) {
4103
+ out[i2++] = j2++;
4104
+ } else if (score[i2 + 1][j2] >= score[i2][j2 + 1]) {
4105
+ i2++;
4106
+ } else {
4107
+ j2++;
4108
+ }
4109
+ }
4110
+ return out;
4111
+ }
4112
+ function resolveInternalLinks(current, value) {
4113
+ const pushed = anchorsIn(value);
4114
+ if (!pushed.some(isInternal)) return value;
4115
+ const page = typeof current === "string" ? anchorsIn(current) : [];
4116
+ const pairs = align(pushed, page);
4117
+ let out = "";
4118
+ let cursor = 0;
4119
+ pushed.forEach((anchor, i2) => {
4120
+ if (!isInternal(anchor)) return;
4121
+ out += value.slice(cursor, anchor.start);
4122
+ const match = pairs[i2] >= 0 ? page[pairs[i2]] : null;
4123
+ if (match?.href != null) {
4124
+ const href = match.href;
4125
+ const attributes = anchor.attributes.replace(
4126
+ HREF,
4127
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
4128
+ );
4129
+ out += `<a${attributes}>${anchor.inner}</a>`;
4130
+ } else {
4131
+ out += anchor.inner;
4132
+ }
4133
+ cursor = anchor.end;
4134
+ });
4135
+ return out + value.slice(cursor);
4136
+ }
4137
+
4138
+ // src/core/live-preview/patch.ts
4051
4139
  var INDEX_SEGMENT2 = /^\d+$/;
4052
4140
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
4053
4141
  function mergeObject(current, incoming) {
@@ -4216,7 +4304,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
4216
4304
  } else if (!isPatchable(container[key])) {
4217
4305
  return root;
4218
4306
  } else {
4219
- next = keepEditLink(container[key], value);
4307
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
4308
+ next = keepEditLink(container[key], linked);
4220
4309
  }
4221
4310
  if (container[key] === next) return root;
4222
4311
  const newRoot = cloneNode(root);
package/dist/index.d.cts CHANGED
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "1.0.0-rc.5";
8
+ declare const VERSION = "1.0.0-rc.6";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "1.0.0-rc.5";
8
+ declare const VERSION = "1.0.0-rc.6";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  setTrackingParam,
9
9
  stegaClean,
10
10
  trackEvent
11
- } from "./chunk-AWFJ67AQ.js";
11
+ } from "./chunk-WQRPW3TM.js";
12
12
  import {
13
13
  PreprError,
14
14
  extractAccessToken,
@@ -19,15 +19,15 @@ import {
19
19
  getPreprUUIDFromHeaders,
20
20
  getToolbarPropsFromHeaders,
21
21
  validatePreprToken
22
- } from "./chunk-GRFTP62X.js";
22
+ } from "./chunk-SAOE54OB.js";
23
23
  import {
24
24
  VERSION,
25
25
  resolveFeatures
26
- } from "./chunk-A4J3JRMY.js";
26
+ } from "./chunk-OCTRCNW2.js";
27
27
  import {
28
28
  createLiveBridge,
29
29
  createLiveStore
30
- } from "./chunk-A2J7R4LR.js";
30
+ } from "./chunk-I26P2EQI.js";
31
31
  import "./chunk-Y7JWV7WV.js";
32
32
  import {
33
33
  COOKIE_HUBSPOT,
@@ -48,7 +48,7 @@ import {
48
48
  normalizeQuery,
49
49
  parsePatchLog,
50
50
  readQueryDocument
51
- } from "./chunk-KM2GME62.js";
51
+ } from "./chunk-RWFAFYHU.js";
52
52
  import {
53
53
  createScopedLogger
54
54
  } from "./chunk-V7MCHPE7.js";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  createLiveBridge,
3
3
  createLiveStore
4
- } from "./chunk-A2J7R4LR.js";
4
+ } from "./chunk-I26P2EQI.js";
5
5
  import "./chunk-Y7JWV7WV.js";
6
6
  import "./chunk-UTKH7DOI.js";
7
7
  import {
8
8
  applyPatchLog,
9
9
  normalizeQuery,
10
10
  parsePatchLog
11
- } from "./chunk-KM2GME62.js";
11
+ } from "./chunk-RWFAFYHU.js";
12
12
  import "./chunk-V7MCHPE7.js";
13
13
  export {
14
14
  applyPatchLog,
@@ -3707,7 +3707,7 @@ function createPreprPreview(opts = {}) {
3707
3707
  var import_react = require("react");
3708
3708
 
3709
3709
  // src/version.ts
3710
- var VERSION = "1.0.0-rc.5";
3710
+ var VERSION = "1.0.0-rc.6";
3711
3711
 
3712
3712
  // src/core/pixel.ts
3713
3713
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
@@ -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-WQRPW3TM.js";
6
+ import "../chunk-OCTRCNW2.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.6";
54
54
 
55
55
  // src/core/constants.ts
56
56
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -477,6 +477,94 @@ function indexSnapshot(data) {
477
477
 
478
478
  // src/core/live-preview/patch.ts
479
479
  var import_stega2 = require("@vercel/stega");
480
+
481
+ // src/core/live-preview/internal-links.ts
482
+ var INTERNAL_HREF = /^[pa]uuid#/;
483
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
484
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
485
+ var TAGS = /<[^>]+>/g;
486
+ function anchorsIn(html) {
487
+ const out = [];
488
+ for (const match of html.matchAll(ANCHOR)) {
489
+ const attributes = match[1];
490
+ const inner = match[2];
491
+ out.push({
492
+ start: match.index ?? 0,
493
+ end: (match.index ?? 0) + match[0].length,
494
+ attributes,
495
+ inner,
496
+ href: HREF.exec(attributes)?.[3] ?? null,
497
+ text: inner.replace(TAGS, "").trim()
498
+ });
499
+ }
500
+ return out;
501
+ }
502
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
503
+ function fit(pushed, page) {
504
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
505
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
506
+ return 0;
507
+ return pushed.text === page.text ? 2 : 1;
508
+ }
509
+ function align(pushed, page) {
510
+ const rows = pushed.length + 1;
511
+ const cols = page.length + 1;
512
+ const score = Array.from(
513
+ { length: rows },
514
+ () => new Array(cols).fill(0)
515
+ );
516
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
517
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
518
+ const pair = fit(pushed[i2], page[j2]);
519
+ score[i2][j2] = Math.max(
520
+ score[i2 + 1][j2],
521
+ score[i2][j2 + 1],
522
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
523
+ );
524
+ }
525
+ }
526
+ const out = new Array(pushed.length).fill(-1);
527
+ let i = 0;
528
+ let j = 0;
529
+ while (i < pushed.length && j < page.length) {
530
+ const pair = fit(pushed[i], page[j]);
531
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
532
+ out[i++] = j++;
533
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
534
+ i++;
535
+ } else {
536
+ j++;
537
+ }
538
+ }
539
+ return out;
540
+ }
541
+ function resolveInternalLinks(current, value) {
542
+ const pushed = anchorsIn(value);
543
+ if (!pushed.some(isInternal)) return value;
544
+ const page = typeof current === "string" ? anchorsIn(current) : [];
545
+ const pairs = align(pushed, page);
546
+ let out = "";
547
+ let cursor = 0;
548
+ pushed.forEach((anchor, i) => {
549
+ if (!isInternal(anchor)) return;
550
+ out += value.slice(cursor, anchor.start);
551
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
552
+ if (match?.href != null) {
553
+ const href = match.href;
554
+ const attributes = anchor.attributes.replace(
555
+ HREF,
556
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
557
+ );
558
+ out += `<a${attributes}>${anchor.inner}</a>`;
559
+ } else {
560
+ out += anchor.inner;
561
+ }
562
+ cursor = anchor.end;
563
+ });
564
+ return out + value.slice(cursor);
565
+ }
566
+
567
+ // src/core/live-preview/patch.ts
480
568
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
481
569
  function mergeObject(current, incoming) {
482
570
  let changed = false;
@@ -574,7 +662,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
574
662
  } else if (!isPatchable(container[key])) {
575
663
  return root;
576
664
  } else {
577
- next = keepEditLink(container[key], value);
665
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
666
+ next = keepEditLink(container[key], linked);
578
667
  }
579
668
  if (container[key] === next) return root;
580
669
  const newRoot = cloneNode(root);