@artinstack/migrator 0.1.7 → 0.1.8

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/transformers/rewrite-inline-images.ts"],"sourcesContent":["import * as cheerio from \"cheerio\";\n\nimport {\n buildMigrationMediaUrlIndex,\n createMigrationMediaRefReplaceWith,\n isMigrationMediaRef,\n normalizeAssetUrl,\n resolveMigrationMediaSourceId,\n type OriginUrlRewriteConfig,\n} from \"../lib/media-urls.js\";\n\nexport interface RewriteInlineImageRef {\n originalSrc: string;\n sourceAssetId?: string;\n}\n\nexport interface UploadedAssetRef {\n targetId: string;\n publicUrl?: string;\n}\n\nexport interface RewriteInlineImagesOptions {\n resolveAsset: (src: string) => RewriteInlineImageRef | undefined;\n /**\n * Replace a resolved source id with a migration ref or CDN URL.\n * When omitted, defaults to OSS-14 `artinstack-migration://asset/…` refs.\n */\n replaceWith?: (ref: RewriteInlineImageRef, uploaded?: UploadedAssetRef) => string;\n /**\n * When true, skip URLs that cannot be matched to an uploaded vault target.\n * Default: false when using migration refs; true when a custom `replaceWith` is supplied.\n */\n requireUploaded?: boolean;\n}\n\nexport interface RewriteInlineImagesResult {\n html: string;\n referencedSources: string[];\n unresolved: string[];\n}\n\n/** Inline CSS `background` / `background-image: url(…)` (quoted or bare). */\nconst BACKGROUND_IMAGE_URL_PATTERN =\n /background(?:-image)?\\s*:[^;]*?url\\s*\\(\\s*(['\"]?)([^'\")]+)\\1\\s*\\)/gi;\n\nfunction resolveRewriteOptions(\n options: RewriteInlineImagesOptions,\n): Required<Pick<RewriteInlineImagesOptions, \"replaceWith\" | \"requireUploaded\">> {\n const replaceWith = options.replaceWith ?? createMigrationMediaRefReplaceWith();\n const requireUploaded = options.requireUploaded ?? Boolean(options.replaceWith);\n return { replaceWith, requireUploaded };\n}\n\nfunction tryRewriteUrl(\n src: string,\n options: RewriteInlineImagesOptions,\n uploadedBySourceId: Map<string, UploadedAssetRef>,\n referencedSources: Set<string>,\n unresolved: Set<string>,\n): string | undefined {\n const normalized = normalizeAssetUrl(src);\n if (!normalized) return undefined;\n\n if (isMigrationMediaRef(normalized)) {\n referencedSources.add(normalized);\n return normalized;\n }\n\n referencedSources.add(normalized);\n const ref = options.resolveAsset(normalized);\n if (!ref?.sourceAssetId) {\n unresolved.add(normalized);\n return undefined;\n }\n\n const { replaceWith, requireUploaded } = resolveRewriteOptions(options);\n const uploaded = uploadedBySourceId.get(ref.sourceAssetId);\n if (requireUploaded && !uploaded) {\n unresolved.add(normalized);\n return undefined;\n }\n\n return replaceWith(ref, uploaded);\n}\n\nfunction rewriteBackgroundUrlsInStyle(\n style: string,\n options: RewriteInlineImagesOptions,\n uploadedBySourceId: Map<string, UploadedAssetRef>,\n referencedSources: Set<string>,\n unresolved: Set<string>,\n): string {\n return style.replace(BACKGROUND_IMAGE_URL_PATTERN, (full, quote: string, rawUrl: string) => {\n const replaced = tryRewriteUrl(rawUrl.trim(), options, uploadedBySourceId, referencedSources, unresolved);\n if (!replaced) return full;\n\n const urlCall = quote\n ? `url(${quote}${replaced}${quote})`\n : `url(${replaced})`;\n return full.replace(/url\\s*\\(\\s*(['\"]?)([^'\")]+)\\1\\s*\\)/i, urlCall);\n });\n}\n\nfunction rewriteSrcset(\n srcset: string,\n options: RewriteInlineImagesOptions,\n uploadedBySourceId: Map<string, UploadedAssetRef>,\n referencedSources: Set<string>,\n unresolved: Set<string>,\n): string {\n return srcset\n .split(\",\")\n .map((entry) => {\n const trimmed = entry.trim();\n if (!trimmed) return entry;\n const [urlPart, descriptor] = trimmed.split(/\\s+/, 2);\n const replaced = tryRewriteUrl(urlPart ?? \"\", options, uploadedBySourceId, referencedSources, unresolved);\n if (!replaced) return entry;\n return descriptor ? `${replaced} ${descriptor}` : replaced;\n })\n .join(\", \");\n}\n\n/** Rewrite `<img src>` / `srcset`, `data-bg-image`, and inline CSS backgrounds using uploaded asset targets. */\nexport function rewriteInlineImages(\n html: string,\n options: RewriteInlineImagesOptions,\n uploadedBySourceId: Map<string, UploadedAssetRef>,\n): RewriteInlineImagesResult {\n if (!html.trim()) {\n return { html, referencedSources: [], unresolved: [] };\n }\n\n const $ = cheerio.load(html, { xml: false });\n const referencedSources = new Set<string>();\n const unresolved = new Set<string>();\n\n $(\"img\").each((_, element) => {\n const img = $(element);\n const src = img.attr(\"src\")?.trim();\n if (src && !src.startsWith(\"data:\")) {\n const replaced = tryRewriteUrl(src, options, uploadedBySourceId, referencedSources, unresolved);\n if (replaced) img.attr(\"src\", replaced);\n }\n\n const srcset = img.attr(\"srcset\")?.trim();\n if (srcset) {\n img.attr(\"srcset\", rewriteSrcset(srcset, options, uploadedBySourceId, referencedSources, unresolved));\n }\n });\n\n $(\"[data-bg-image]\").each((_, element) => {\n const node = $(element);\n const bgImage = node.attr(\"data-bg-image\")?.trim();\n if (!bgImage || bgImage.startsWith(\"data:\")) return;\n const replaced = tryRewriteUrl(bgImage, options, uploadedBySourceId, referencedSources, unresolved);\n if (replaced) node.attr(\"data-bg-image\", replaced);\n });\n\n $(\"[style]\").each((_, element) => {\n const node = $(element);\n const style = node.attr(\"style\");\n if (!style?.includes(\"background\")) return;\n const rewritten = rewriteBackgroundUrlsInStyle(\n style,\n options,\n uploadedBySourceId,\n referencedSources,\n unresolved,\n );\n if (rewritten !== style) node.attr(\"style\", rewritten);\n });\n\n return {\n html: $.root().html() ?? html,\n referencedSources: [...referencedSources],\n unresolved: [...unresolved],\n };\n}\n\nexport interface StampMigrationMediaRefsOptions {\n /** Pre-built url/pathname → sourceId map (from attachments + inline assets). */\n urlToSourceId: Map<string, string>;\n /** Canonicalize lookup keys during stamp (OSS-15). */\n originUrlRewrite?: OriginUrlRewriteConfig;\n replaceWith?: RewriteInlineImagesOptions[\"replaceWith\"];\n requireUploaded?: boolean;\n}\n\n/**\n * OSS-14 — replace resolved `wp-content/uploads` URLs with `artinstack-migration://asset/…`\n * refs. Does not invent refs for unknown URLs (left unchanged + listed in `unresolved`).\n */\nexport function stampMigrationMediaRefs(\n html: string,\n options: StampMigrationMediaRefsOptions,\n): RewriteInlineImagesResult {\n return rewriteInlineImages(\n html,\n {\n resolveAsset: (src) => {\n const sourceAssetId = resolveMigrationMediaSourceId(\n src,\n options.urlToSourceId,\n options.originUrlRewrite,\n );\n if (!sourceAssetId) return undefined;\n return { originalSrc: src, sourceAssetId };\n },\n replaceWith: options.replaceWith,\n requireUploaded: options.requireUploaded ?? false,\n },\n new Map(),\n );\n}\n\n/** Build a url index from attachment rows and/or normalized assets. */\nexport { buildMigrationMediaUrlIndex };\n"],"mappings":";;;;;;;;AAAA,YAAY,aAAa;AA0CzB,IAAM,+BACJ;AAEF,SAAS,sBACP,SAC+E;AAC/E,QAAM,cAAc,QAAQ,eAAe,mCAAmC;AAC9E,QAAM,kBAAkB,QAAQ,mBAAmB,QAAQ,QAAQ,WAAW;AAC9E,SAAO,EAAE,aAAa,gBAAgB;AACxC;AAEA,SAAS,cACP,KACA,SACA,oBACA,mBACA,YACoB;AACpB,QAAM,aAAa,kBAAkB,GAAG;AACxC,MAAI,CAAC,WAAY,QAAO;AAExB,MAAI,oBAAoB,UAAU,GAAG;AACnC,sBAAkB,IAAI,UAAU;AAChC,WAAO;AAAA,EACT;AAEA,oBAAkB,IAAI,UAAU;AAChC,QAAM,MAAM,QAAQ,aAAa,UAAU;AAC3C,MAAI,CAAC,KAAK,eAAe;AACvB,eAAW,IAAI,UAAU;AACzB,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,aAAa,gBAAgB,IAAI,sBAAsB,OAAO;AACtE,QAAM,WAAW,mBAAmB,IAAI,IAAI,aAAa;AACzD,MAAI,mBAAmB,CAAC,UAAU;AAChC,eAAW,IAAI,UAAU;AACzB,WAAO;AAAA,EACT;AAEA,SAAO,YAAY,KAAK,QAAQ;AAClC;AAEA,SAAS,6BACP,OACA,SACA,oBACA,mBACA,YACQ;AACR,SAAO,MAAM,QAAQ,8BAA8B,CAAC,MAAM,OA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;AAAA,IAC9C;AAAA,IACA,oBAAI,IAAI;AAAA,EACV;AACF;","names":[]}
@@ -1,5 +1,30 @@
1
- // src/lib/content-asset-urls.ts
1
+ // src/lib/media-urls.ts
2
2
  import * as cheerio from "cheerio";
3
+ function rewriteOriginUrlsInText(text, config) {
4
+ if (!text || config.rules.length === 0) return text;
5
+ let result = text;
6
+ for (const rule of config.rules) {
7
+ if (typeof rule.match === "string") {
8
+ if (!rule.match) continue;
9
+ result = result.split(rule.match).join(rule.replace);
10
+ continue;
11
+ }
12
+ result = result.replace(rule.match, rule.replace);
13
+ }
14
+ return result;
15
+ }
16
+ function createWpContentGatewayRewrite(gatewayBase, publicOrigin) {
17
+ const normalizedGateway = gatewayBase.replace(/\/$/, "");
18
+ const normalizedPublic = publicOrigin.replace(/\/$/, "");
19
+ return {
20
+ rules: [
21
+ {
22
+ match: `${normalizedGateway}/wp-content/`,
23
+ replace: `${normalizedPublic}/wp-content/`
24
+ }
25
+ ]
26
+ };
27
+ }
3
28
  var IMAGE_EXTENSIONS = "jpe?g|png|gif|webp|avif|svg";
4
29
  var IMAGE_EXTENSION_PATTERN = new RegExp(String.raw`\.(?:${IMAGE_EXTENSIONS})\b`, "i");
5
30
  var QUOTED_IMAGE_PATH = String.raw`[^"']+\.(?:${IMAGE_EXTENSIONS})(?:\?[^"'#]*)?(?:#.*)?`;
@@ -146,14 +171,97 @@ function discoverContentAssetUrls(content) {
146
171
  function extractInlineImageSrcs(content) {
147
172
  return discoverContentAssetUrls(content);
148
173
  }
174
+ var MIGRATION_MEDIA_REF_SCHEME = "artinstack-migration://asset/";
175
+ function formatMigrationMediaRef(sourceAssetId) {
176
+ return `${MIGRATION_MEDIA_REF_SCHEME}${encodeURIComponent(sourceAssetId)}`;
177
+ }
178
+ function isMigrationMediaRef(value) {
179
+ return value.trim().startsWith(MIGRATION_MEDIA_REF_SCHEME);
180
+ }
181
+ function parseMigrationMediaRef(value) {
182
+ const trimmed = value.trim();
183
+ if (!trimmed.startsWith(MIGRATION_MEDIA_REF_SCHEME)) return void 0;
184
+ const encoded = trimmed.slice(MIGRATION_MEDIA_REF_SCHEME.length);
185
+ if (!encoded) return void 0;
186
+ try {
187
+ return decodeURIComponent(encoded);
188
+ } catch {
189
+ return void 0;
190
+ }
191
+ }
192
+ function createMigrationMediaRefReplaceWith() {
193
+ return (ref) => {
194
+ if (!ref.sourceAssetId) return "";
195
+ return formatMigrationMediaRef(ref.sourceAssetId);
196
+ };
197
+ }
198
+ function canonicalizeInlineAssetUrl(raw, originUrlRewrite) {
199
+ let value = raw.trim();
200
+ if (!value || value.startsWith("data:")) return void 0;
201
+ if (originUrlRewrite) {
202
+ value = rewriteOriginUrlsInText(value, originUrlRewrite);
203
+ }
204
+ const canonicalUrl = normalizeAssetUrl(value);
205
+ if (!canonicalUrl) return void 0;
206
+ return {
207
+ canonicalUrl,
208
+ sourceId: `url:${canonicalUrl}`
209
+ };
210
+ }
211
+ function urlPathname(url) {
212
+ try {
213
+ return new URL(url, "http://migration.local").pathname;
214
+ } catch {
215
+ return void 0;
216
+ }
217
+ }
218
+ function buildMigrationMediaUrlIndex(entries) {
219
+ const index = /* @__PURE__ */ new Map();
220
+ for (const entry of entries) {
221
+ index.set(entry.sourceUrl, entry.sourceId);
222
+ const normalized = normalizeAssetUrl(entry.sourceUrl);
223
+ if (normalized) index.set(normalized, entry.sourceId);
224
+ const pathname = urlPathname(entry.sourceUrl);
225
+ if (pathname) index.set(pathname, entry.sourceId);
226
+ }
227
+ return index;
228
+ }
229
+ function resolveMigrationMediaSourceId(src, urlIndex, originUrlRewrite) {
230
+ const canonical = canonicalizeInlineAssetUrl(src, originUrlRewrite);
231
+ const normalized = canonical?.canonicalUrl ?? normalizeAssetUrl(src);
232
+ if (!normalized) return void 0;
233
+ return urlIndex.get(normalized) ?? urlIndex.get(src) ?? (urlPathname(normalized) ? urlIndex.get(urlPathname(normalized)) : void 0);
234
+ }
235
+ function buildContentMediaUrlIndex(entries, originUrlRewrite) {
236
+ const canonicalEntries = [];
237
+ for (const entry of entries) {
238
+ const canonical = canonicalizeInlineAssetUrl(entry.sourceUrl, originUrlRewrite);
239
+ canonicalEntries.push({
240
+ sourceUrl: canonical?.canonicalUrl ?? entry.sourceUrl,
241
+ sourceId: entry.sourceId
242
+ });
243
+ }
244
+ return buildMigrationMediaUrlIndex(canonicalEntries);
245
+ }
149
246
 
150
247
  export {
248
+ rewriteOriginUrlsInText,
249
+ createWpContentGatewayRewrite,
151
250
  discoverRawImgSrcs,
152
251
  normalizeAssetUrl,
153
252
  isLikelyImageUrl,
154
253
  discoverFeaturedAssetCandidateUrls,
155
254
  resolveFeaturedContentAssetUrl,
156
255
  discoverContentAssetUrls,
157
- extractInlineImageSrcs
256
+ extractInlineImageSrcs,
257
+ MIGRATION_MEDIA_REF_SCHEME,
258
+ formatMigrationMediaRef,
259
+ isMigrationMediaRef,
260
+ parseMigrationMediaRef,
261
+ createMigrationMediaRefReplaceWith,
262
+ canonicalizeInlineAssetUrl,
263
+ buildMigrationMediaUrlIndex,
264
+ resolveMigrationMediaSourceId,
265
+ buildContentMediaUrlIndex
158
266
  };
159
- //# sourceMappingURL=chunk-XYP3VYDH.js.map
267
+ //# sourceMappingURL=chunk-WHGUE5FC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/media-urls.ts"],"sourcesContent":["import * as cheerio from \"cheerio\";\n\n// --- Origin URL rewrite (gateway → public origin before parse/discovery) ---\n\nexport interface OriginUrlRewriteRule {\n /** Literal substring or regex matched against the full text block. */\n match: string | RegExp;\n replace: string;\n}\n\nexport interface OriginUrlRewriteConfig {\n rules: OriginUrlRewriteRule[];\n}\n\n/** Swap legacy gateway/staging host fragments before parse, fetch, or asset discovery. */\nexport function rewriteOriginUrlsInText(text: string, config: OriginUrlRewriteConfig): string {\n if (!text || config.rules.length === 0) return text;\n\n let result = text;\n for (const rule of config.rules) {\n if (typeof rule.match === \"string\") {\n if (!rule.match) continue;\n result = result.split(rule.match).join(rule.replace);\n continue;\n }\n result = result.replace(rule.match, rule.replace);\n }\n return result;\n}\n\n/** Build a rule that rewrites API-gateway `/prod/wp-content/` paths to a public origin. */\nexport function createWpContentGatewayRewrite(gatewayBase: string, publicOrigin: string): OriginUrlRewriteConfig {\n const normalizedGateway = gatewayBase.replace(/\\/$/, \"\");\n const normalizedPublic = publicOrigin.replace(/\\/$/, \"\");\n return {\n rules: [\n {\n match: `${normalizedGateway}/wp-content/`,\n replace: `${normalizedPublic}/wp-content/`,\n },\n ],\n };\n}\n\n// --- Content asset URL discovery & normalization ---\n\nconst IMAGE_EXTENSIONS = \"jpe?g|png|gif|webp|avif|svg\";\n/** Image file extension in a path or URL (allows trailing `?query` / `#hash`). */\nconst IMAGE_EXTENSION_PATTERN = new RegExp(String.raw`\\.(?:${IMAGE_EXTENSIONS})\\b`, \"i\");\n\n/** Captured value must contain an image extension — skips `url=\"…/about\"`, `<iframe src=\"…youtube…\">`, etc. */\nconst QUOTED_IMAGE_PATH = String.raw`[^\"']+\\.(?:${IMAGE_EXTENSIONS})(?:\\?[^\"'#]*)?(?:#.*)?`;\n\nconst SHORTCODE_IMAGE_PARAM_PATTERN = new RegExp(\n String.raw`\\b(?:image|bg_image|background_image|url)\\s*=\\s*[\"'](${QUOTED_IMAGE_PATH})[\"']`,\n \"gi\",\n);\n\n/** Bare `src=\"…jpg\"` outside `<img>` (shortcode fragments); `<img src>` handled by cheerio. */\nconst BARE_SRC_PARAM_PATTERN = new RegExp(\n String.raw`\\bsrc\\s*=\\s*[\"'](${QUOTED_IMAGE_PATH})[\"']`,\n \"gi\",\n);\n\nconst DATA_BG_IMAGE_PATTERN = /\\bdata-bg-image\\s*=\\s*[\"']([^\"']+)[\"']/gi;\n\n/** Inline CSS `background` / `background-image: url(…)` (quoted or bare). */\nconst BACKGROUND_IMAGE_URL_PATTERN =\n /background(?:-image)?\\s*:[^;]*?url\\s*\\(\\s*(['\"]?)([^'\")]+)\\1\\s*\\)/gi;\n\nconst HERO_URL_PARAM_PATTERN = new RegExp(\n String.raw`\\b(?:bg_image|background_image)\\s*=\\s*[\"'](${QUOTED_IMAGE_PATH})[\"']`,\n \"gi\",\n);\n\nconst INLINE_IMAGE_PARAM_PATTERN = new RegExp(\n String.raw`\\bimage\\s*=\\s*[\"'](${QUOTED_IMAGE_PATH})[\"']`,\n \"gi\",\n);\n\nconst IMG_TAG_SRC_PATTERN = /<img\\b[^>]*\\bsrc\\s*=\\s*[\"']([^\"']+)[\"']/gi;\n\ninterface FeaturedAssetCandidate {\n url: string;\n index: number;\n tier: 0 | 1;\n}\n\nfunction ingestLikelyImageUrl(urls: Set<string>, raw: string | undefined): void {\n const normalized = normalizeAssetUrl(raw ?? \"\");\n if (normalized && isLikelyImageUrl(normalized)) {\n urls.add(normalized);\n }\n}\n\nfunction extractImgTagSrcs(content: string): string[] {\n if (!content.trim()) return [];\n const $ = cheerio.load(content, { xml: false });\n const srcs: string[] = [];\n $(\"img[src]\").each((_, el) => {\n const src = $(el).attr(\"src\")?.trim();\n if (src) srcs.push(src);\n });\n return srcs;\n}\n\nfunction hasImageExtension(value: string): boolean {\n const withoutHash = value.split(\"#\", 1)[0] ?? value;\n const withoutQuery = withoutHash.split(\"?\", 1)[0] ?? withoutHash;\n return IMAGE_EXTENSION_PATTERN.test(withoutQuery);\n}\n\nfunction extractDataBgImageUrls(content: string): string[] {\n const urls: string[] = [];\n for (const match of content.matchAll(DATA_BG_IMAGE_PATTERN)) {\n const raw = match[1]?.trim();\n if (raw) urls.push(raw);\n }\n return urls;\n}\n\nfunction extractCssBackgroundImageUrls(content: string): string[] {\n const urls: string[] = [];\n for (const match of content.matchAll(BACKGROUND_IMAGE_URL_PATTERN)) {\n const raw = match[2]?.trim();\n if (raw) urls.push(raw);\n }\n return urls;\n}\n\n/** All `<img src>` values (including those not ingested as vault assets). */\nexport function discoverRawImgSrcs(content: string): string[] {\n return extractImgTagSrcs(content).filter((src) => !src.startsWith(\"data:\"));\n}\n\n/** Normalize protocol-relative and trim; skip data URIs. */\nexport function normalizeAssetUrl(raw: string): string | undefined {\n const trimmed = raw.trim();\n if (!trimmed || trimmed.startsWith(\"data:\")) return undefined;\n if (trimmed.startsWith(\"//\")) return `https:${trimmed}`;\n return trimmed;\n}\n\n/** Heuristic: URL likely points at a raster/vector image asset, not a page link. */\nexport function isLikelyImageUrl(url: string): boolean {\n if (!url || url.startsWith(\"data:\")) return false;\n\n if (url.startsWith(\"/\")) {\n return hasImageExtension(url);\n }\n\n if (!/^https?:\\/\\//i.test(url)) return false;\n\n try {\n const { pathname } = new URL(url);\n if (hasImageExtension(pathname)) return true;\n } catch {\n // fall through — malformed absolute URL\n }\n\n return hasImageExtension(url);\n}\n\nfunction pushFeaturedCandidate(\n candidates: FeaturedAssetCandidate[],\n raw: string | undefined,\n index: number,\n tier: 0 | 1,\n): void {\n const normalized = normalizeAssetUrl(raw ?? \"\");\n if (!normalized || !isLikelyImageUrl(normalized)) return;\n candidates.push({ url: normalized, index, tier });\n}\n\nfunction collectFeaturedAssetCandidates(content: string): FeaturedAssetCandidate[] {\n const candidates: FeaturedAssetCandidate[] = [];\n\n for (const match of content.matchAll(DATA_BG_IMAGE_PATTERN)) {\n pushFeaturedCandidate(candidates, match[1], match.index ?? 0, 0);\n }\n for (const match of content.matchAll(BACKGROUND_IMAGE_URL_PATTERN)) {\n pushFeaturedCandidate(candidates, match[2], match.index ?? 0, 0);\n }\n for (const match of content.matchAll(HERO_URL_PARAM_PATTERN)) {\n pushFeaturedCandidate(candidates, match[1], match.index ?? 0, 0);\n }\n for (const match of content.matchAll(IMG_TAG_SRC_PATTERN)) {\n pushFeaturedCandidate(candidates, match[1], match.index ?? 0, 1);\n }\n for (const match of content.matchAll(INLINE_IMAGE_PARAM_PATTERN)) {\n pushFeaturedCandidate(candidates, match[1], match.index ?? 0, 1);\n }\n\n return candidates;\n}\n\n/**\n * Ordered featured-image candidates when `_thumbnail_id` is missing — heroes\n * (`data-bg-image`, CSS backgrounds, `bg_image=`) before inline assets; within\n * each tier, first in document order wins. Filename tokens (`_w`, `_2048`, …)\n * are not interpreted as quality signals.\n */\nexport function discoverFeaturedAssetCandidateUrls(content: string): string[] {\n if (!content.trim()) return [];\n\n const ranked = [...collectFeaturedAssetCandidates(content)].sort((left, right) => {\n if (left.tier !== right.tier) return left.tier - right.tier;\n return left.index - right.index;\n });\n\n const urls: string[] = [];\n const seen = new Set<string>();\n for (const candidate of ranked) {\n if (seen.has(candidate.url)) continue;\n seen.add(candidate.url);\n urls.push(candidate.url);\n }\n return urls;\n}\n\n/** Best featured-image URL from post/page HTML when attachment id is unavailable. */\nexport function resolveFeaturedContentAssetUrl(content: string): string | undefined {\n return discoverFeaturedAssetCandidateUrls(content)[0];\n}\n\n/**\n * Generic content-discovery pass: collect image URLs from HTML `<img>` tags,\n * section hero markers (`data-bg-image`), inline CSS backgrounds, and common\n * shortcode/builder attributes (`src=`, `image=`, `bg_image=`, …) without\n * parsing builder-specific structure (Tatsu, Elementor, etc.).\n */\nexport function discoverContentAssetUrls(content: string): string[] {\n if (!content.trim()) return [];\n\n const urls = new Set<string>();\n\n for (const raw of extractImgTagSrcs(content)) {\n ingestLikelyImageUrl(urls, raw);\n }\n\n for (const match of content.matchAll(SHORTCODE_IMAGE_PARAM_PATTERN)) {\n ingestLikelyImageUrl(urls, match[1]);\n }\n\n for (const match of content.matchAll(BARE_SRC_PARAM_PATTERN)) {\n ingestLikelyImageUrl(urls, match[1]);\n }\n\n for (const raw of extractDataBgImageUrls(content)) {\n ingestLikelyImageUrl(urls, raw);\n }\n\n for (const raw of extractCssBackgroundImageUrls(content)) {\n ingestLikelyImageUrl(urls, raw);\n }\n\n return [...urls];\n}\n\n/** @deprecated Use discoverContentAssetUrls — kept for call-site clarity during transition. */\nexport function extractInlineImageSrcs(content: string): string[] {\n return discoverContentAssetUrls(content);\n}\n\n// --- Migration media refs (`artinstack-migration://asset/{sourceId}`) ---\n\n/** Pseudo-URL scheme for portable migration asset pointers (not WordPress shortcodes). */\nexport const MIGRATION_MEDIA_REF_SCHEME = \"artinstack-migration://asset/\";\n\n/** Build `artinstack-migration://asset/{sourceId}` (percent-encodes the normalizer source id). */\nexport function formatMigrationMediaRef(sourceAssetId: string): string {\n return `${MIGRATION_MEDIA_REF_SCHEME}${encodeURIComponent(sourceAssetId)}`;\n}\n\nexport function isMigrationMediaRef(value: string): boolean {\n return value.trim().startsWith(MIGRATION_MEDIA_REF_SCHEME);\n}\n\n/** Parse a migration media ref back to the normalizer `sourceId`, or `undefined` if not a ref. */\nexport function parseMigrationMediaRef(value: string): string | undefined {\n const trimmed = value.trim();\n if (!trimmed.startsWith(MIGRATION_MEDIA_REF_SCHEME)) return undefined;\n const encoded = trimmed.slice(MIGRATION_MEDIA_REF_SCHEME.length);\n if (!encoded) return undefined;\n try {\n return decodeURIComponent(encoded);\n } catch {\n return undefined;\n }\n}\n\n/** Default `replaceWith` for `rewriteInlineImages` / `stampMigrationMediaRefs` (OSS-14). */\nexport function createMigrationMediaRefReplaceWith(): (\n ref: { sourceAssetId?: string },\n) => string {\n return (ref) => {\n if (!ref.sourceAssetId) return \"\";\n return formatMigrationMediaRef(ref.sourceAssetId);\n };\n}\n\n// --- Canonical inline keys & lookup index (OSS-15) ---\n\nexport interface CanonicalInlineAssetUrl {\n /** Canonical absolute URL stored on `NormalizedAsset.sourceUrl`. */\n canonicalUrl: string;\n /** Normalizer id: `url:{canonicalUrl}`. */\n sourceId: string;\n}\n\n/**\n * OSS-15: one canonical key for inline `url:` assets — apply origin rewrite then\n * `normalizeAssetUrl` so discovery, refs, and vault entities share the same id.\n */\nexport function canonicalizeInlineAssetUrl(\n raw: string,\n originUrlRewrite?: OriginUrlRewriteConfig,\n): CanonicalInlineAssetUrl | undefined {\n let value = raw.trim();\n if (!value || value.startsWith(\"data:\")) return undefined;\n\n if (originUrlRewrite) {\n value = rewriteOriginUrlsInText(value, originUrlRewrite);\n }\n\n const canonicalUrl = normalizeAssetUrl(value);\n if (!canonicalUrl) return undefined;\n\n return {\n canonicalUrl,\n sourceId: `url:${canonicalUrl}`,\n };\n}\n\nfunction urlPathname(url: string): string | undefined {\n try {\n return new URL(url, \"http://migration.local\").pathname;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Map normalized upload URLs (and pathnames) → normalizer `sourceId`.\n * Attachment ids are WXR `post_id` strings; inline discoveries use `url:{src}`.\n */\nexport function buildMigrationMediaUrlIndex(\n entries: Iterable<{ sourceUrl: string; sourceId: string }>,\n): Map<string, string> {\n const index = new Map<string, string>();\n\n for (const entry of entries) {\n index.set(entry.sourceUrl, entry.sourceId);\n const normalized = normalizeAssetUrl(entry.sourceUrl);\n if (normalized) index.set(normalized, entry.sourceId);\n const pathname = urlPathname(entry.sourceUrl);\n if (pathname) index.set(pathname, entry.sourceId);\n }\n\n return index;\n}\n\nexport function resolveMigrationMediaSourceId(\n src: string,\n urlIndex: Map<string, string>,\n originUrlRewrite?: OriginUrlRewriteConfig,\n): string | undefined {\n const canonical = canonicalizeInlineAssetUrl(src, originUrlRewrite);\n const normalized = canonical?.canonicalUrl ?? normalizeAssetUrl(src);\n if (!normalized) return undefined;\n\n return (\n urlIndex.get(normalized) ??\n urlIndex.get(src) ??\n (urlPathname(normalized) ? urlIndex.get(urlPathname(normalized)!) : undefined)\n );\n}\n\n/** Merge attachment + inline asset rows into one stamp/lookup index (OSS-15). */\nexport function buildContentMediaUrlIndex(\n entries: Iterable<{ sourceUrl: string; sourceId: string }>,\n originUrlRewrite?: OriginUrlRewriteConfig,\n): Map<string, string> {\n const canonicalEntries: { sourceUrl: string; sourceId: string }[] = [];\n for (const entry of entries) {\n const canonical = canonicalizeInlineAssetUrl(entry.sourceUrl, originUrlRewrite);\n canonicalEntries.push({\n sourceUrl: canonical?.canonicalUrl ?? entry.sourceUrl,\n sourceId: entry.sourceId,\n });\n }\n return buildMigrationMediaUrlIndex(canonicalEntries);\n}\n"],"mappings":";AAAA,YAAY,aAAa;AAelB,SAAS,wBAAwB,MAAc,QAAwC;AAC5F,MAAI,CAAC,QAAQ,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AAM,WAAW,YAAY,MAAM,SAAS;AAC5C,QAAI,SAAU,OAAM,IAAI,UAAU,MAAM,QAAQ;AAAA,EAClD;AAEA,SAAO;AACT;AAEO,SAAS,8BACd,KACA,UACA,kBACoB;AACpB,QAAM,YAAY,2BAA2B,KAAK,gBAAgB;AAClE,QAAM,aAAa,WAAW,gBAAgB,kBAAkB,GAAG;AACnE,MAAI,CAAC,WAAY,QAAO;AAExB,SACE,SAAS,IAAI,UAAU,KACvB,SAAS,IAAI,GAAG,MACf,YAAY,UAAU,IAAI,SAAS,IAAI,YAAY,UAAU,CAAE,IAAI;AAExE;AAGO,SAAS,0BACd,SACA,kBACqB;AACrB,QAAM,mBAA8D,CAAC;AACrE,aAAW,SAAS,SAAS;AAC3B,UAAM,YAAY,2BAA2B,MAAM,WAAW,gBAAgB;AAC9E,qBAAiB,KAAK;AAAA,MACpB,WAAW,WAAW,gBAAgB,MAAM;AAAA,MAC5C,UAAU,MAAM;AAAA,IAClB,CAAC;AAAA,EACH;AACA,SAAO,4BAA4B,gBAAgB;AACrD;","names":[]}
@@ -0,0 +1,24 @@
1
+ // src/lib/utility.ts
2
+ function sanitizeSlug(raw) {
3
+ return raw.trim().toLowerCase().replace(/&[^;]+;/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 200);
4
+ }
5
+ function linkToPath(link) {
6
+ if (!link) return void 0;
7
+ try {
8
+ const url = new URL(link);
9
+ const path = url.pathname;
10
+ if (!path || path === "/") return "/";
11
+ return path.endsWith("/") ? path : `${path}/`;
12
+ } catch {
13
+ if (link.startsWith("/")) {
14
+ return link.endsWith("/") ? link : `${link}/`;
15
+ }
16
+ return void 0;
17
+ }
18
+ }
19
+
20
+ export {
21
+ sanitizeSlug,
22
+ linkToPath
23
+ };
24
+ //# sourceMappingURL=chunk-XRCF73DA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/utility.ts"],"sourcesContent":["/** Lowercase URL-safe slug from WordPress post_name or title. */\nexport function sanitizeSlug(raw: string): string {\n return raw\n .trim()\n .toLowerCase()\n .replace(/&[^;]+;/g, \"\")\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 200);\n}\n\n/** Normalize absolute permalink to root-relative path. */\nexport function linkToPath(link: string | undefined): string | undefined {\n if (!link) return undefined;\n try {\n const url = new URL(link);\n const path = url.pathname;\n if (!path || path === \"/\") return \"/\";\n return path.endsWith(\"/\") ? path : `${path}/`;\n } catch {\n if (link.startsWith(\"/\")) {\n return link.endsWith(\"/\") ? link : `${link}/`;\n }\n return undefined;\n }\n}\n"],"mappings":";AACO,SAAS,aAAa,KAAqB;AAChD,SAAO,IACJ,KAAK,EACL,YAAY,EACZ,QAAQ,YAAY,EAAE,EACtB,QAAQ,eAAe,GAAG,EAC1B,QAAQ,YAAY,EAAE,EACtB,MAAM,GAAG,GAAG;AACjB;AAGO,SAAS,WAAW,MAA8C;AACvE,MAAI,CAAC,KAAM,QAAO;AAClB,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,IAAI;AACxB,UAAM,OAAO,IAAI;AACjB,QAAI,CAAC,QAAQ,SAAS,IAAK,QAAO;AAClC,WAAO,KAAK,SAAS,GAAG,IAAI,OAAO,GAAG,IAAI;AAAA,EAC5C,QAAQ;AACN,QAAI,KAAK,WAAW,GAAG,GAAG;AACxB,aAAO,KAAK,SAAS,GAAG,IAAI,OAAO,GAAG,IAAI;AAAA,IAC5C;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -7,15 +7,19 @@ import {
7
7
  shouldProcessEntity
8
8
  } from "./chunk-HI7JHWZU.js";
9
9
  import {
10
- createMigrationMediaRefReplaceWith,
11
- isMigrationMediaRef,
12
10
  rewriteInlineImages
13
- } from "./chunk-BOYB6XRA.js";
11
+ } from "./chunk-KYNKJ4XV.js";
14
12
  import {
13
+ linkToPath,
14
+ sanitizeSlug
15
+ } from "./chunk-XRCF73DA.js";
16
+ import {
17
+ createMigrationMediaRefReplaceWith,
15
18
  discoverContentAssetUrls,
16
19
  discoverRawImgSrcs,
20
+ isMigrationMediaRef,
17
21
  normalizeAssetUrl
18
- } from "./chunk-XYP3VYDH.js";
22
+ } from "./chunk-WHGUE5FC.js";
19
23
 
20
24
  // src/sinks/types.ts
21
25
  var MIGRATION_WRITE_STAGES = [
@@ -37,25 +41,6 @@ import * as cheerio2 from "cheerio";
37
41
  import { readFile } from "fs/promises";
38
42
  import { basename } from "path";
39
43
 
40
- // src/lib/utility.ts
41
- function sanitizeSlug(raw) {
42
- return raw.trim().toLowerCase().replace(/&[^;]+;/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 200);
43
- }
44
- function linkToPath(link) {
45
- if (!link) return void 0;
46
- try {
47
- const url = new URL(link);
48
- const path = url.pathname;
49
- if (!path || path === "/") return "/";
50
- return path.endsWith("/") ? path : `${path}/`;
51
- } catch {
52
- if (link.startsWith("/")) {
53
- return link.endsWith("/") ? link : `${link}/`;
54
- }
55
- return void 0;
56
- }
57
- }
58
-
59
44
  // src/parsers/squarespace/collect.ts
60
45
  import * as cheerio from "cheerio";
61
46
  import { z } from "zod";
@@ -963,8 +948,35 @@ function fractionalLayoutMap(config) {
963
948
  bgParamName: config.bgParamName
964
949
  };
965
950
  }
951
+ var WP_WIDGET_PLACEHOLDER = "\u200B";
952
+ var WORDPRESS_WIDGET_REGISTRY = {
953
+ mapShortcodePrefixes: [
954
+ "blox_gmap",
955
+ "tatsu_gmap",
956
+ "tatsu_map",
957
+ "et_pb_map",
958
+ "vc_gmaps",
959
+ "vc_map"
960
+ ],
961
+ contactFormRules: [
962
+ { tag: "contact-form-7", source: "contact-form-7", idParam: "id" },
963
+ { tag: "contact_form", source: "contact-form-7", idParam: "id" },
964
+ { tag: "gravityform", source: "gravityforms", idParam: "id" },
965
+ { tag: "ninja_form", source: "ninja-forms", idParam: "id" },
966
+ { tag: "wpforms", source: "wpforms", idParam: "id" }
967
+ ],
968
+ videoShortcodePrefixes: [
969
+ "youtube",
970
+ "vimeo",
971
+ "embed",
972
+ "tatsu_video",
973
+ "et_pb_video",
974
+ "vc_video"
975
+ ],
976
+ portfolioShortcode: "portfolio",
977
+ galleryShortcode: "gallery"
978
+ };
966
979
  var UNRESOLVABLE_SHORTCODE_PREFIXES = [
967
- "portfolio",
968
980
  "recent_posts",
969
981
  "woocommerce_cart",
970
982
  "woocommerce_checkout",
@@ -988,8 +1000,7 @@ var WORDPRESS_BUILDER_REGISTRY = [
988
1000
  ],
989
1001
  urlRules: [
990
1002
  { shortcodePrefix: "tatsu_image", urlParams: ["image", "url", "src"], tag: "img" },
991
- { shortcodePrefix: "tatsu_single_image", urlParams: ["image", "url", "src"], tag: "img" },
992
- { shortcodePrefix: "tatsu_video", urlParams: ["video", "src", "url"], tag: "video" }
1003
+ { shortcodePrefix: "tatsu_single_image", urlParams: ["image", "url", "src"], tag: "img" }
993
1004
  ],
994
1005
  iconImageRules: [
995
1006
  { shortcodePrefix: "tatsu_icon", imageParam: "icon_image", hrefParam: "href" }
@@ -1099,12 +1110,6 @@ var WORDPRESS_BUILDER_REGISTRY = [
1099
1110
  urlRules: [
1100
1111
  { shortcodePrefix: "blox_image", urlParams: ["image", "img", "src", "url"], tag: "img" }
1101
1112
  ],
1102
- placeholderRules: [
1103
- {
1104
- shortcodePrefix: "blox_gmap",
1105
- html: '<p data-unresolved-shortcode="blox_gmap"><!-- Map embed removed during migration --></p>'
1106
- }
1107
- ],
1108
1113
  scaffoldingPrefixes: ["blox_", "animate_icon"],
1109
1114
  legacyScaffoldingTokens: ["text", "icon", "linebreak", "grids", "testimonials"]
1110
1115
  }
@@ -1688,8 +1693,6 @@ async function runDryRun(options) {
1688
1693
 
1689
1694
  export {
1690
1695
  MIGRATION_WRITE_STAGES,
1691
- sanitizeSlug,
1692
- linkToPath,
1693
1696
  SQUARESPACE_JSON_FORMAT,
1694
1697
  buildJsonPrettyUrl,
1695
1698
  mapJsonPrettyWire,
@@ -1697,6 +1700,8 @@ export {
1697
1700
  enumerateSquarespaceEntities,
1698
1701
  summarizeSquarespaceExport,
1699
1702
  validateSquarespaceExportFile,
1703
+ WP_WIDGET_PLACEHOLDER,
1704
+ WORDPRESS_WIDGET_REGISTRY,
1700
1705
  WORDPRESS_BUILDER_REGISTRY,
1701
1706
  emptyConflictReport,
1702
1707
  analyzeConflicts,
@@ -1717,4 +1722,4 @@ export {
1717
1722
  staleUrlsFromEstimate,
1718
1723
  runDryRun
1719
1724
  };
1720
- //# sourceMappingURL=chunk-MDSY3FEZ.js.map
1725
+ //# sourceMappingURL=chunk-Z3L6N63Y.js.map