@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.
@@ -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.6";
6
6
 
7
7
  // src/core/constants.ts
8
8
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -433,6 +433,94 @@ function indexSnapshot(data) {
433
433
 
434
434
  // src/core/live-preview/patch.ts
435
435
  import { vercelStegaSplit as vercelStegaSplit2 } from "@vercel/stega";
436
+
437
+ // src/core/live-preview/internal-links.ts
438
+ var INTERNAL_HREF = /^[pa]uuid#/;
439
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
440
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
441
+ var TAGS = /<[^>]+>/g;
442
+ function anchorsIn(html) {
443
+ const out = [];
444
+ for (const match of html.matchAll(ANCHOR)) {
445
+ const attributes = match[1];
446
+ const inner = match[2];
447
+ out.push({
448
+ start: match.index ?? 0,
449
+ end: (match.index ?? 0) + match[0].length,
450
+ attributes,
451
+ inner,
452
+ href: HREF.exec(attributes)?.[3] ?? null,
453
+ text: inner.replace(TAGS, "").trim()
454
+ });
455
+ }
456
+ return out;
457
+ }
458
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
459
+ function fit(pushed, page) {
460
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
461
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
462
+ return 0;
463
+ return pushed.text === page.text ? 2 : 1;
464
+ }
465
+ function align(pushed, page) {
466
+ const rows = pushed.length + 1;
467
+ const cols = page.length + 1;
468
+ const score = Array.from(
469
+ { length: rows },
470
+ () => new Array(cols).fill(0)
471
+ );
472
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
473
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
474
+ const pair = fit(pushed[i2], page[j2]);
475
+ score[i2][j2] = Math.max(
476
+ score[i2 + 1][j2],
477
+ score[i2][j2 + 1],
478
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
479
+ );
480
+ }
481
+ }
482
+ const out = new Array(pushed.length).fill(-1);
483
+ let i = 0;
484
+ let j = 0;
485
+ while (i < pushed.length && j < page.length) {
486
+ const pair = fit(pushed[i], page[j]);
487
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
488
+ out[i++] = j++;
489
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
490
+ i++;
491
+ } else {
492
+ j++;
493
+ }
494
+ }
495
+ return out;
496
+ }
497
+ function resolveInternalLinks(current, value) {
498
+ const pushed = anchorsIn(value);
499
+ if (!pushed.some(isInternal)) return value;
500
+ const page = typeof current === "string" ? anchorsIn(current) : [];
501
+ const pairs = align(pushed, page);
502
+ let out = "";
503
+ let cursor = 0;
504
+ pushed.forEach((anchor, i) => {
505
+ if (!isInternal(anchor)) return;
506
+ out += value.slice(cursor, anchor.start);
507
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
508
+ if (match?.href != null) {
509
+ const href = match.href;
510
+ const attributes = anchor.attributes.replace(
511
+ HREF,
512
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
513
+ );
514
+ out += `<a${attributes}>${anchor.inner}</a>`;
515
+ } else {
516
+ out += anchor.inner;
517
+ }
518
+ cursor = anchor.end;
519
+ });
520
+ return out + value.slice(cursor);
521
+ }
522
+
523
+ // src/core/live-preview/patch.ts
436
524
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
437
525
  function mergeObject(current, incoming) {
438
526
  let changed = false;
@@ -530,7 +618,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
530
618
  } else if (!isPatchable(container[key])) {
531
619
  return root;
532
620
  } else {
533
- next = keepEditLink(container[key], value);
621
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
622
+ next = keepEditLink(container[key], linked);
534
623
  }
535
624
  if (container[key] === next) return root;
536
625
  const newRoot = cloneNode(root);
@@ -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-SAOE54OB.js";
5
+ import "../chunk-OCTRCNW2.js";
6
6
  import {
7
7
  parsePatchLog
8
- } from "../chunk-KM2GME62.js";
8
+ } from "../chunk-RWFAFYHU.js";
9
9
  import "../chunk-V7MCHPE7.js";
10
10
 
11
11
  // src/nextjs/live-action.ts
@@ -215,6 +215,98 @@ 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
+ out.push({
225
+ start: match.index ?? 0,
226
+ end: (match.index ?? 0) + match[0].length,
227
+ attributes,
228
+ inner,
229
+ href: HREF.exec(attributes)?.[3] ?? null,
230
+ text: inner.replace(TAGS, "").trim()
231
+ });
232
+ }
233
+ return out;
234
+ }
235
+ function fit(pushed, page) {
236
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
237
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
238
+ return 0;
239
+ return pushed.text === page.text ? 2 : 1;
240
+ }
241
+ function align(pushed, page) {
242
+ const rows = pushed.length + 1;
243
+ const cols = page.length + 1;
244
+ const score = Array.from(
245
+ { length: rows },
246
+ () => new Array(cols).fill(0)
247
+ );
248
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
249
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
250
+ const pair = fit(pushed[i2], page[j2]);
251
+ score[i2][j2] = Math.max(
252
+ score[i2 + 1][j2],
253
+ score[i2][j2 + 1],
254
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
255
+ );
256
+ }
257
+ }
258
+ const out = new Array(pushed.length).fill(-1);
259
+ let i = 0;
260
+ let j = 0;
261
+ while (i < pushed.length && j < page.length) {
262
+ const pair = fit(pushed[i], page[j]);
263
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
264
+ out[i++] = j++;
265
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
266
+ i++;
267
+ } else {
268
+ j++;
269
+ }
270
+ }
271
+ return out;
272
+ }
273
+ function resolveInternalLinks(current, value) {
274
+ const pushed = anchorsIn(value);
275
+ if (!pushed.some(isInternal)) 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 (!isInternal(anchor)) 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, ANCHOR, HREF, TAGS, isInternal;
299
+ var init_internal_links = __esm({
300
+ "src/core/live-preview/internal-links.ts"() {
301
+ "use strict";
302
+ INTERNAL_HREF = /^[pa]uuid#/;
303
+ ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
304
+ HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
305
+ TAGS = /<[^>]+>/g;
306
+ isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
307
+ }
308
+ });
309
+
218
310
  // src/core/live-preview/patch.ts
219
311
  function mergeObject(current, incoming) {
220
312
  let changed = false;
@@ -382,7 +474,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
382
474
  } else if (!isPatchable(container[key])) {
383
475
  return root;
384
476
  } else {
385
- next = keepEditLink(container[key], value);
477
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
478
+ next = keepEditLink(container[key], linked);
386
479
  }
387
480
  if (container[key] === next) return root;
388
481
  const newRoot = cloneNode(root);
@@ -498,6 +591,7 @@ var init_patch = __esm({
498
591
  init_guards();
499
592
  import_stega = require("@vercel/stega");
500
593
  init_field_name();
594
+ init_internal_links();
501
595
  INDEX_SEGMENT = /^\d+$/;
502
596
  FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
503
597
  }
@@ -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-NUDEDAYQ.js").then((runtime) => {
49
49
  const started = runtime.createLiveStore(options.storeOptions?.());
50
50
  options.onStart?.(started, runtime);
51
51
  bridge = runtime.createLiveBridge(started, {
@@ -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.6";
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.6";
15
15
 
16
16
  // src/core/features.ts
17
17
  function isEnabled(config) {
@@ -150,6 +150,92 @@ function isTextEntry(record) {
150
150
  return "html" in record || "text" in record && "format" in record;
151
151
  }
152
152
 
153
+ // src/core/live-preview/internal-links.ts
154
+ var INTERNAL_HREF = /^[pa]uuid#/;
155
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
156
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
157
+ var TAGS = /<[^>]+>/g;
158
+ function anchorsIn(html) {
159
+ const out = [];
160
+ for (const match of html.matchAll(ANCHOR)) {
161
+ const attributes = match[1];
162
+ const inner = match[2];
163
+ out.push({
164
+ start: match.index ?? 0,
165
+ end: (match.index ?? 0) + match[0].length,
166
+ attributes,
167
+ inner,
168
+ href: HREF.exec(attributes)?.[3] ?? null,
169
+ text: inner.replace(TAGS, "").trim()
170
+ });
171
+ }
172
+ return out;
173
+ }
174
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
175
+ function fit(pushed, page) {
176
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
177
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
178
+ return 0;
179
+ return pushed.text === page.text ? 2 : 1;
180
+ }
181
+ function align(pushed, page) {
182
+ const rows = pushed.length + 1;
183
+ const cols = page.length + 1;
184
+ const score = Array.from(
185
+ { length: rows },
186
+ () => new Array(cols).fill(0)
187
+ );
188
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
189
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
190
+ const pair = fit(pushed[i2], page[j2]);
191
+ score[i2][j2] = Math.max(
192
+ score[i2 + 1][j2],
193
+ score[i2][j2 + 1],
194
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
195
+ );
196
+ }
197
+ }
198
+ const out = new Array(pushed.length).fill(-1);
199
+ let i = 0;
200
+ let j = 0;
201
+ while (i < pushed.length && j < page.length) {
202
+ const pair = fit(pushed[i], page[j]);
203
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
204
+ out[i++] = j++;
205
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
206
+ i++;
207
+ } else {
208
+ j++;
209
+ }
210
+ }
211
+ return out;
212
+ }
213
+ function resolveInternalLinks(current, value) {
214
+ const pushed = anchorsIn(value);
215
+ if (!pushed.some(isInternal)) return value;
216
+ const page = typeof current === "string" ? anchorsIn(current) : [];
217
+ const pairs = align(pushed, page);
218
+ let out = "";
219
+ let cursor = 0;
220
+ pushed.forEach((anchor, i) => {
221
+ if (!isInternal(anchor)) return;
222
+ out += value.slice(cursor, anchor.start);
223
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
224
+ if (match?.href != null) {
225
+ const href = match.href;
226
+ const attributes = anchor.attributes.replace(
227
+ HREF,
228
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
229
+ );
230
+ out += `<a${attributes}>${anchor.inner}</a>`;
231
+ } else {
232
+ out += anchor.inner;
233
+ }
234
+ cursor = anchor.end;
235
+ });
236
+ return out + value.slice(cursor);
237
+ }
238
+
153
239
  // src/core/live-preview/patch.ts
154
240
  var INDEX_SEGMENT = /^\d+$/;
155
241
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
@@ -319,7 +405,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
319
405
  } else if (!isPatchable(container[key])) {
320
406
  return root;
321
407
  } else {
322
- next = keepEditLink(container[key], value);
408
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
409
+ next = keepEditLink(container[key], linked);
323
410
  }
324
411
  if (container[key] === next) return root;
325
412
  const newRoot = cloneNode(root);
@@ -540,6 +540,98 @@ var init_field_name = __esm({
540
540
  }
541
541
  });
542
542
 
543
+ // src/core/live-preview/internal-links.ts
544
+ function anchorsIn(html) {
545
+ const out = [];
546
+ for (const match of html.matchAll(ANCHOR)) {
547
+ const attributes = match[1];
548
+ const inner = match[2];
549
+ out.push({
550
+ start: match.index ?? 0,
551
+ end: (match.index ?? 0) + match[0].length,
552
+ attributes,
553
+ inner,
554
+ href: HREF.exec(attributes)?.[3] ?? null,
555
+ text: inner.replace(TAGS, "").trim()
556
+ });
557
+ }
558
+ return out;
559
+ }
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
+ var INTERNAL_HREF, ANCHOR, HREF, TAGS, isInternal;
624
+ var init_internal_links = __esm({
625
+ "src/core/live-preview/internal-links.ts"() {
626
+ "use strict";
627
+ INTERNAL_HREF = /^[pa]uuid#/;
628
+ ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
629
+ HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
630
+ TAGS = /<[^>]+>/g;
631
+ isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
632
+ }
633
+ });
634
+
543
635
  // src/core/live-preview/patch.ts
544
636
  function mergeObject(current, incoming) {
545
637
  let changed = false;
@@ -707,7 +799,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
707
799
  } else if (!isPatchable(container[key])) {
708
800
  return root;
709
801
  } else {
710
- next = keepEditLink(container[key], value);
802
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
803
+ next = keepEditLink(container[key], linked);
711
804
  }
712
805
  if (container[key] === next) return root;
713
806
  const newRoot = cloneNode(root);
@@ -823,6 +916,7 @@ var init_patch = __esm({
823
916
  init_guards();
824
917
  import_stega2 = require("@vercel/stega");
825
918
  init_field_name();
919
+ init_internal_links();
826
920
  INDEX_SEGMENT = /^\d+$/;
827
921
  FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
828
922
  }
package/dist/nuxt/live.js CHANGED
@@ -164,7 +164,7 @@ function createLiveStarter(options = {}) {
164
164
  }
165
165
  },
166
166
  start() {
167
- starting ?? (starting = import("./live-preview-KO4IKWTX.js").then((runtime) => {
167
+ starting ?? (starting = import("./live-preview-V2X6GPSK.js").then((runtime) => {
168
168
  const started = runtime.createLiveStore(options.storeOptions?.());
169
169
  options.onStart?.(started, runtime);
170
170
  bridge = runtime.createLiveBridge(started, {
@@ -3703,7 +3703,7 @@ function createPreprPreview(opts = {}) {
3703
3703
  }
3704
3704
 
3705
3705
  // src/version.ts
3706
- var VERSION = "1.0.0-rc.5";
3706
+ var VERSION = "1.0.0-rc.6";
3707
3707
 
3708
3708
  // src/core/pixel.ts
3709
3709
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
@@ -3679,7 +3679,7 @@ function createPreprPreview(opts = {}) {
3679
3679
  }
3680
3680
 
3681
3681
  // src/version.ts
3682
- var VERSION = "1.0.0-rc.5";
3682
+ var VERSION = "1.0.0-rc.6";
3683
3683
 
3684
3684
  // src/core/pixel.ts
3685
3685
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
@@ -35,7 +35,7 @@ __export(sveltekit_exports, {
35
35
  module.exports = __toCommonJS(sveltekit_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "1.0.0-rc.5";
38
+ var VERSION = "1.0.0-rc.6";
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.6";
15
15
 
16
16
  // src/core/features.ts
17
17
  function isEnabled(config) {
@@ -150,6 +150,92 @@ function isTextEntry(record) {
150
150
  return "html" in record || "text" in record && "format" in record;
151
151
  }
152
152
 
153
+ // src/core/live-preview/internal-links.ts
154
+ var INTERNAL_HREF = /^[pa]uuid#/;
155
+ var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
156
+ var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
157
+ var TAGS = /<[^>]+>/g;
158
+ function anchorsIn(html) {
159
+ const out = [];
160
+ for (const match of html.matchAll(ANCHOR)) {
161
+ const attributes = match[1];
162
+ const inner = match[2];
163
+ out.push({
164
+ start: match.index ?? 0,
165
+ end: (match.index ?? 0) + match[0].length,
166
+ attributes,
167
+ inner,
168
+ href: HREF.exec(attributes)?.[3] ?? null,
169
+ text: inner.replace(TAGS, "").trim()
170
+ });
171
+ }
172
+ return out;
173
+ }
174
+ var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
175
+ function fit(pushed, page) {
176
+ if (!isInternal(pushed) && pushed.href !== page.href) return 0;
177
+ if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
178
+ return 0;
179
+ return pushed.text === page.text ? 2 : 1;
180
+ }
181
+ function align(pushed, page) {
182
+ const rows = pushed.length + 1;
183
+ const cols = page.length + 1;
184
+ const score = Array.from(
185
+ { length: rows },
186
+ () => new Array(cols).fill(0)
187
+ );
188
+ for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
189
+ for (let j2 = page.length - 1; j2 >= 0; j2--) {
190
+ const pair = fit(pushed[i2], page[j2]);
191
+ score[i2][j2] = Math.max(
192
+ score[i2 + 1][j2],
193
+ score[i2][j2 + 1],
194
+ pair ? pair + score[i2 + 1][j2 + 1] : 0
195
+ );
196
+ }
197
+ }
198
+ const out = new Array(pushed.length).fill(-1);
199
+ let i = 0;
200
+ let j = 0;
201
+ while (i < pushed.length && j < page.length) {
202
+ const pair = fit(pushed[i], page[j]);
203
+ if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
204
+ out[i++] = j++;
205
+ } else if (score[i + 1][j] >= score[i][j + 1]) {
206
+ i++;
207
+ } else {
208
+ j++;
209
+ }
210
+ }
211
+ return out;
212
+ }
213
+ function resolveInternalLinks(current, value) {
214
+ const pushed = anchorsIn(value);
215
+ if (!pushed.some(isInternal)) return value;
216
+ const page = typeof current === "string" ? anchorsIn(current) : [];
217
+ const pairs = align(pushed, page);
218
+ let out = "";
219
+ let cursor = 0;
220
+ pushed.forEach((anchor, i) => {
221
+ if (!isInternal(anchor)) return;
222
+ out += value.slice(cursor, anchor.start);
223
+ const match = pairs[i] >= 0 ? page[pairs[i]] : null;
224
+ if (match?.href != null) {
225
+ const href = match.href;
226
+ const attributes = anchor.attributes.replace(
227
+ HREF,
228
+ (_all, lead, quote) => `${lead}${quote}${href}${quote}`
229
+ );
230
+ out += `<a${attributes}>${anchor.inner}</a>`;
231
+ } else {
232
+ out += anchor.inner;
233
+ }
234
+ cursor = anchor.end;
235
+ });
236
+ return out + value.slice(cursor);
237
+ }
238
+
153
239
  // src/core/live-preview/patch.ts
154
240
  var INDEX_SEGMENT = /^\d+$/;
155
241
  var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
@@ -319,7 +405,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
319
405
  } else if (!isPatchable(container[key])) {
320
406
  return root;
321
407
  } else {
322
- next = keepEditLink(container[key], value);
408
+ const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
409
+ next = keepEditLink(container[key], linked);
323
410
  }
324
411
  if (container[key] === next) return root;
325
412
  const newRoot = cloneNode(root);