@artinstack/migrator 0.1.9 → 0.1.12

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 (34) hide show
  1. package/dist/{bundle-B3XS20r_.d.ts → bundle-CysqqLij.d.ts} +1 -1
  2. package/dist/chunk-J7EUSPEA.js +667 -0
  3. package/dist/chunk-J7EUSPEA.js.map +1 -0
  4. package/dist/{chunk-3YJFSTYR.js → chunk-MUFGDYGI.js} +2 -1
  5. package/dist/chunk-MUFGDYGI.js.map +1 -0
  6. package/dist/{chunk-KTQGOM45.js → chunk-PFUXPS7A.js} +1 -1
  7. package/dist/chunk-PFUXPS7A.js.map +1 -0
  8. package/dist/{chunk-FB3MMCHY.js → chunk-Q44KGFIH.js} +97 -531
  9. package/dist/chunk-Q44KGFIH.js.map +1 -0
  10. package/dist/chunk-QFJXNEXG.js +355 -0
  11. package/dist/chunk-QFJXNEXG.js.map +1 -0
  12. package/dist/{chunk-PPT5RIZ4.js → chunk-VRRYN6NS.js} +40 -236
  13. package/dist/chunk-VRRYN6NS.js.map +1 -0
  14. package/dist/{chunk-S4SUJT2D.js → chunk-WCAHVNWW.js} +98 -3
  15. package/dist/chunk-WCAHVNWW.js.map +1 -0
  16. package/dist/cli/index.js +12 -6
  17. package/dist/cli/index.js.map +1 -1
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.js +9 -6
  20. package/dist/normalizer/index.d.ts +10 -4
  21. package/dist/normalizer/index.js +2 -2
  22. package/dist/sinks/index.d.ts +13 -3
  23. package/dist/sinks/index.js +5 -3
  24. package/dist/transformers/index.d.ts +1 -1
  25. package/dist/transformers/index.js +3 -2
  26. package/dist/{types-Ce4r6zqt.d.ts → types-CLNmloya.d.ts} +15 -1
  27. package/package.json +1 -1
  28. package/dist/chunk-3YJFSTYR.js.map +0 -1
  29. package/dist/chunk-BONZ3U3I.js +0 -124
  30. package/dist/chunk-BONZ3U3I.js.map +0 -1
  31. package/dist/chunk-FB3MMCHY.js.map +0 -1
  32. package/dist/chunk-KTQGOM45.js.map +0 -1
  33. package/dist/chunk-PPT5RIZ4.js.map +0 -1
  34. package/dist/chunk-S4SUJT2D.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { d as NormalizedCategory, e as NormalizedTag, b as NormalizedAsset, c as NormalizedPortfolio, N as NormalizedPost, a as NormalizedPage, P as PortfolioMediaLink, E as EntityKey, f as NormalizedEntity, g as MigrationPlatform, M as MigrationAdapter } from '../types-Ce4r6zqt.js';
1
+ import { d as NormalizedCategory, e as NormalizedTag, b as NormalizedAsset, c as NormalizedPortfolio, N as NormalizedPost, a as NormalizedPage, P as PortfolioMediaLink, E as EntityKey, f as NormalizedEntity, g as MigrationPlatform, W as WxrImportSummary, M as MigrationAdapter } from '../types-CLNmloya.js';
2
2
  import { Readable } from 'node:stream';
3
3
  import { a as RewriteInlineImagesOptions } from '../rewrite-inline-images-BsgSquzV.js';
4
4
  export { b as RewriteInlineImagesResult, r as rewriteInlineImages } from '../rewrite-inline-images-BsgSquzV.js';
5
- import { E as EntityBundle } from '../bundle-B3XS20r_.js';
5
+ import { E as EntityBundle } from '../bundle-CysqqLij.js';
6
6
  import '../media-urls-u49RCyPn.js';
7
7
 
8
8
  interface CreatePostResult {
@@ -138,12 +138,18 @@ interface ConflictReport {
138
138
  unsupportedBlocks: UnsupportedBlockConflict[];
139
139
  redirectLoops: RedirectLoopConflict[];
140
140
  assetDiscovery: AssetDiscoverySummary;
141
+ /** OSS-19 — unsupported WXR `post_type` counts (commerce, builder globals, …). */
142
+ skippedPostTypes: Record<string, number>;
143
+ importableItemCount: number;
144
+ unsupportedOnly: boolean;
145
+ skippedWooCommerceStubPages?: number;
141
146
  }
142
147
  declare function summarizeAssetDiscovery(bundle: EntityBundle): AssetDiscoverySummary;
143
148
  declare function emptyConflictReport(): ConflictReport;
144
149
  declare function analyzeConflicts(bundle: EntityBundle, options?: {
145
150
  staleAssetUrls?: StaleAssetUrlConflict[];
146
151
  redirectLoops?: RedirectLoopConflict[];
152
+ wxrImportSummary?: WxrImportSummary;
147
153
  }): ConflictReport;
148
154
  declare function hasBlockingConflicts(report: ConflictReport): boolean;
149
155
  declare function hasWarnings(report: ConflictReport): boolean;
@@ -173,6 +179,9 @@ interface MigrationReport {
173
179
  tags: number;
174
180
  storageBytesEstimated?: number;
175
181
  assetDiscovery?: AssetDiscoverySummary;
182
+ importableItemCount?: number;
183
+ unsupportedOnly?: boolean;
184
+ skippedPostTypes?: Record<string, number>;
176
185
  };
177
186
  warnings: string[];
178
187
  errors: string[];
@@ -248,6 +257,7 @@ interface DryRunResult {
248
257
  report: MigrationReport;
249
258
  exitCode: 0 | 1 | 2;
250
259
  }
260
+ declare function resolveAdapterImportSummary(adapter: MigrationAdapter, input: unknown): Promise<WxrImportSummary | undefined>;
251
261
  declare function runDryRun(options: DryRunOptions): Promise<DryRunResult>;
252
262
 
253
263
  declare const FALLBACK_ASSET_BYTES: number;
@@ -275,4 +285,4 @@ declare function staleUrlsFromEstimate(estimate: StorageEstimate): {
275
285
  reason: string;
276
286
  }[];
277
287
 
278
- export { type AssetDiscoverySummary, type ConflictReport, type DryRunOptions, type DryRunResult, FALLBACK_ASSET_BYTES, FilesystemMigrationSink, MIGRATION_WRITE_STAGES, type MigrationRedirect, type MigrationReport, type MigrationRunMode, type MigrationRunOptions, type MigrationRunResult, type MigrationSink, type MigrationWriteStage, RewriteInlineImagesOptions, type StorageEstimate, type UploadAssetInput, type UploadAssetResult, type WriteFilesystemOptions, analyzeConflicts, buildMigrationReport, buildRedirectMap, bundleToCombinedJson, createFilesystemMigrationSink, detectRedirectLoops, emptyConflictReport, estimateStorage, hasBlockingConflicts, hasWarnings, portfolioMediaMatchesBundle, runDryRun, runMigration, runMigrationFromBundle, staleUrlsFromEstimate, summarizeAssetDiscovery, writeFilesystemExport };
288
+ export { type AssetDiscoverySummary, type ConflictReport, type DryRunOptions, type DryRunResult, FALLBACK_ASSET_BYTES, FilesystemMigrationSink, MIGRATION_WRITE_STAGES, type MigrationRedirect, type MigrationReport, type MigrationRunMode, type MigrationRunOptions, type MigrationRunResult, type MigrationSink, type MigrationWriteStage, RewriteInlineImagesOptions, type StorageEstimate, type UploadAssetInput, type UploadAssetResult, type WriteFilesystemOptions, analyzeConflicts, buildMigrationReport, buildRedirectMap, bundleToCombinedJson, createFilesystemMigrationSink, detectRedirectLoops, emptyConflictReport, estimateStorage, hasBlockingConflicts, hasWarnings, portfolioMediaMatchesBundle, resolveAdapterImportSummary, runDryRun, runMigration, runMigrationFromBundle, staleUrlsFromEstimate, summarizeAssetDiscovery, writeFilesystemExport };
@@ -13,17 +13,18 @@ import {
13
13
  hasBlockingConflicts,
14
14
  hasWarnings,
15
15
  portfolioMediaMatchesBundle,
16
+ resolveAdapterImportSummary,
16
17
  runDryRun,
17
18
  runMigration,
18
19
  runMigrationFromBundle,
19
20
  staleUrlsFromEstimate,
20
21
  summarizeAssetDiscovery,
21
22
  writeFilesystemExport
22
- } from "../chunk-PPT5RIZ4.js";
23
- import "../chunk-KTQGOM45.js";
23
+ } from "../chunk-VRRYN6NS.js";
24
+ import "../chunk-PFUXPS7A.js";
24
25
  import {
25
26
  rewriteInlineImages
26
- } from "../chunk-BONZ3U3I.js";
27
+ } from "../chunk-QFJXNEXG.js";
27
28
  import "../chunk-XRCF73DA.js";
28
29
  import "../chunk-S4GMDRGX.js";
29
30
  export {
@@ -41,6 +42,7 @@ export {
41
42
  hasBlockingConflicts,
42
43
  hasWarnings,
43
44
  portfolioMediaMatchesBundle,
45
+ resolveAdapterImportSummary,
44
46
  rewriteInlineImages,
45
47
  runDryRun,
46
48
  runMigration,
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { l as ValidationResult } from '../types-Ce4r6zqt.js';
2
+ import { l as ValidationResult } from '../types-CLNmloya.js';
3
3
  export { R as RewriteInlineImageRef, a as RewriteInlineImagesOptions, b as RewriteInlineImagesResult, S as StampMigrationMediaRefsOptions, U as UploadedAssetRef, r as rewriteInlineImages, s as stampMigrationMediaRefs } from '../rewrite-inline-images-BsgSquzV.js';
4
4
  export { d as buildMigrationMediaUrlIndex } from '../media-urls-u49RCyPn.js';
5
5
 
@@ -11,11 +11,12 @@ import {
11
11
  tiptapNodeSchema,
12
12
  validateGrapesProjectSnapshot,
13
13
  validateTiptapDoc
14
- } from "../chunk-S4SUJT2D.js";
14
+ } from "../chunk-WCAHVNWW.js";
15
+ import "../chunk-J7EUSPEA.js";
15
16
  import {
16
17
  rewriteInlineImages,
17
18
  stampMigrationMediaRefs
18
- } from "../chunk-BONZ3U3I.js";
19
+ } from "../chunk-QFJXNEXG.js";
19
20
  import {
20
21
  buildMigrationMediaUrlIndex
21
22
  } from "../chunk-S4GMDRGX.js";
@@ -39,6 +39,8 @@ interface NormalizedPage {
39
39
  contentHtml: string;
40
40
  contentCss?: string;
41
41
  isHomePage?: boolean;
42
+ /** Site portfolio listing shell (distinct from portfolio CPT singles). */
43
+ isPortfolioPage?: boolean;
42
44
  status: PublishStatus;
43
45
  seoTitle?: string;
44
46
  seoDescription?: string;
@@ -112,8 +114,18 @@ interface ValidationResult {
112
114
  portfolioCpt?: number;
113
115
  categories?: number;
114
116
  tags?: number;
117
+ /** WXR rows the parser would emit (OSS-19). */
118
+ importableItemCount?: number;
119
+ unsupportedOnly?: boolean;
120
+ skippedPostTypes?: Record<string, number>;
115
121
  };
116
122
  }
123
+ interface WxrImportSummary {
124
+ importableItemCount: number;
125
+ unsupportedOnly: boolean;
126
+ skippedPostTypes: Record<string, number>;
127
+ skippedWooCommerceStubPages?: number;
128
+ }
117
129
  interface AdapterContext {
118
130
  input: unknown;
119
131
  cursor?: MigrationCursor;
@@ -122,6 +134,8 @@ interface MigrationAdapter {
122
134
  platform: MigrationPlatform;
123
135
  validateInput(input: unknown): ValidationResult | Promise<ValidationResult>;
124
136
  enumerateEntities(ctx: AdapterContext): AsyncIterable<NormalizedEntity>;
137
+ /** Platform-specific import accounting (e.g. WordPress skipped `post_type`s). */
138
+ getImportSummary?(input: unknown): Promise<WxrImportSummary | undefined>;
125
139
  }
126
140
  interface MigrationCursor {
127
141
  lastEntityKey?: EntityKey;
@@ -134,4 +148,4 @@ interface EntityKey {
134
148
  }
135
149
  declare function entityKey(entity: NormalizedEntity, platform: MigrationPlatform): EntityKey;
136
150
 
137
- export { type AdapterContext as A, type EntityKey as E, type MigrationAdapter as M, type NormalizedPost as N, type PortfolioMediaLink as P, type SourceMetadata as S, type ValidationIssue as V, type NormalizedPage as a, type NormalizedAsset as b, type NormalizedPortfolio as c, type NormalizedCategory as d, type NormalizedTag as e, type NormalizedEntity as f, type MigrationPlatform as g, type EntityType as h, type MigrationCursor as i, type NormalizedAssetExif as j, type PublishStatus as k, type ValidationResult as l, entityKey as m };
151
+ export { type AdapterContext as A, type EntityKey as E, type MigrationAdapter as M, type NormalizedPost as N, type PortfolioMediaLink as P, type SourceMetadata as S, type ValidationIssue as V, type WxrImportSummary as W, type NormalizedPage as a, type NormalizedAsset as b, type NormalizedPortfolio as c, type NormalizedCategory as d, type NormalizedTag as e, type NormalizedEntity as f, type MigrationPlatform as g, type EntityType as h, type MigrationCursor as i, type NormalizedAssetExif as j, type PublishStatus as k, type ValidationResult as l, entityKey as m };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artinstack/migrator",
3
- "version": "0.1.9",
3
+ "version": "0.1.12",
4
4
  "description": "Stateless content normalizer and migration framework — WordPress, SmugMug, Squarespace → platform-agnostic schema",
5
5
  "license": "MIT",
6
6
  "author": "ArtInStack",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/normalizer/validate.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport type { ValidationIssue, ValidationResult } from \"./types.js\";\n\nconst migrationPlatformSchema = z.enum([\"wordpress\", \"smugmug\", \"squarespace\", \"wix\"]);\nconst publishStatusSchema = z.enum([\"draft\", \"published\", \"archived\"]);\n\nexport const sourceMetadataSchema = z.object({\n platform: migrationPlatformSchema,\n id: z.string().min(1),\n url: z.string().optional(),\n path: z.string().optional(),\n exportedAt: z.string().optional(),\n});\n\nexport const normalizedPostSchema = z.object({\n type: z.literal(\"post\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n title: z.string().min(1),\n slug: z.string().min(1),\n excerpt: z.string().optional(),\n contentHtml: z.string(),\n publishedAt: z.string().optional(),\n status: publishStatusSchema,\n categorySlugs: z.array(z.string().min(1)).optional(),\n tagSlugs: z.array(z.string().min(1)).optional(),\n sourceFeaturedMediaId: z.string().optional(),\n featuredAssetSourceId: z.string().optional(),\n seoTitle: z.string().optional(),\n seoDescription: z.string().optional(),\n});\n\nexport const normalizedPageSchema = z.object({\n type: z.literal(\"page\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n title: z.string().min(1),\n slug: z.string().min(1),\n contentHtml: z.string(),\n contentCss: z.string().optional(),\n isHomePage: z.boolean().optional(),\n status: publishStatusSchema,\n seoTitle: z.string().optional(),\n seoDescription: z.string().optional(),\n});\n\nexport const normalizedAssetExifSchema = z.object({\n iso: z.number().optional(),\n aperture: z.number().optional(),\n shutter: z.string().optional(),\n focalLength: z.number().optional(),\n});\n\nexport const normalizedAssetSchema = z.object({\n type: z.literal(\"asset\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n sourceUrl: z.string().min(1),\n filename: z.string().min(1),\n mimeType: z.string().optional(),\n caption: z.string().optional(),\n altText: z.string().optional(),\n keywords: z.array(z.string()).optional(),\n exif: normalizedAssetExifSchema.optional(),\n portfolioSourceId: z.string().optional(),\n sort: z.number().optional(),\n});\n\nexport const normalizedPortfolioSchema = z.object({\n type: z.literal(\"portfolio\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n title: z.string().min(1),\n slug: z.string().min(1),\n description: z.string().optional(),\n parentSourceId: z.string().optional(),\n});\n\nexport const normalizedCategorySchema = z.object({\n type: z.literal(\"category\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n name: z.string().min(1),\n slug: z.string().min(1),\n});\n\nexport const normalizedTagSchema = z.object({\n type: z.literal(\"tag\"),\n source: sourceMetadataSchema,\n sourceId: z.string().min(1),\n name: z.string().min(1),\n slug: z.string().min(1),\n});\n\nexport const normalizedEntitySchema = z.discriminatedUnion(\"type\", [\n normalizedPostSchema,\n normalizedPageSchema,\n normalizedAssetSchema,\n normalizedPortfolioSchema,\n normalizedCategorySchema,\n normalizedTagSchema,\n]);\n\nfunction zodIssuesToValidationIssues(issues: z.ZodIssue[]): ValidationIssue[] {\n return issues.map((issue) => ({\n code: issue.code,\n message: issue.message,\n path: issue.path.length > 0 ? issue.path.join(\".\") : undefined,\n }));\n}\n\nfunction parseToValidationResult(schema: z.ZodTypeAny, value: unknown): ValidationResult {\n const result = schema.safeParse(value);\n if (result.success) {\n return { ok: true, issues: [] };\n }\n return { ok: false, issues: zodIssuesToValidationIssues(result.error.issues) };\n}\n\n/** Opt-in structural check for a normalized post DTO (no cross-entity FK validation). */\nexport function validateNormalizedPost(post: unknown): ValidationResult {\n return parseToValidationResult(normalizedPostSchema, post);\n}\n\n/** Opt-in structural check for a normalized page DTO (no cross-entity FK validation). */\nexport function validateNormalizedPage(page: unknown): ValidationResult {\n return parseToValidationResult(normalizedPageSchema, page);\n}\n\n/** Opt-in structural check for a normalized asset DTO. */\nexport function validateNormalizedAsset(asset: unknown): ValidationResult {\n return parseToValidationResult(normalizedAssetSchema, asset);\n}\n\n/** Opt-in structural check for a normalized portfolio DTO. */\nexport function validateNormalizedPortfolio(portfolio: unknown): ValidationResult {\n return parseToValidationResult(normalizedPortfolioSchema, portfolio);\n}\n\n/** Opt-in structural check for a normalized category DTO. */\nexport function validateNormalizedCategory(category: unknown): ValidationResult {\n return parseToValidationResult(normalizedCategorySchema, category);\n}\n\n/** Opt-in structural check for a normalized tag DTO. */\nexport function validateNormalizedTag(tag: unknown): ValidationResult {\n return parseToValidationResult(normalizedTagSchema, tag);\n}\n\n/** Opt-in structural check for any normalized entity discriminated by `type`. */\nexport function validateNormalized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M,QAAQ,CAAC,EAAE;AAAA,EAChC;AACA,SAAO,EAAE,IAAI,OAAO,QAAQ,4BAA4B,OAAO,MAAM,MAAM,EAAE;AAC/E;AAGO,SAAS,uBAAuB,MAAiC;AACtE,SAAO,wBAAwB,sBAAsB,IAAI;AAC3D;AAGO,SAAS,uBAAuB,MAAiC;AACtE,SAAO,wBAAwB,sBAAsB,IAAI;AAC3D;AAGO,SAAS,wBAAwB,OAAkC;AACxE,SAAO,wBAAwB,uBAAuB,KAAK;AAC7D;AAGO,SAAS,4BAA4B,WAAsC;AAChF,SAAO,wBAAwB,2BAA2B,SAAS;AACrE;AAGO,SAAS,2BAA2B,UAAqC;AAC9E,SAAO,wBAAwB,0BAA0B,QAAQ;AACnE;AAGO,SAAS,sBAAsB,KAAgC;AACpE,SAAO,wBAAwB,qBAAqB,GAAG;AACzD;AAGO,SAAS,yBAAyB,QAAmC;AAC1E,SAAO,wBAAwB,wBAAwB,MAAM;AAC/D;","names":[]}
@@ -1,124 +0,0 @@
1
- import {
2
- createMigrationMediaRefReplaceWith,
3
- isMigrationMediaRef,
4
- normalizeAssetUrl,
5
- resolveMigrationMediaSourceId
6
- } from "./chunk-S4GMDRGX.js";
7
-
8
- // src/transformers/rewrite-inline-images.ts
9
- import * as cheerio from "cheerio";
10
- var BACKGROUND_IMAGE_URL_PATTERN = /background(?:-image)?\s*:[^;]*?url\s*\(\s*(['"]?)([^'")]+)\1\s*\)/gi;
11
- function resolveRewriteOptions(options) {
12
- const replaceWith = options.replaceWith ?? createMigrationMediaRefReplaceWith();
13
- const requireUploaded = options.requireUploaded ?? Boolean(options.replaceWith);
14
- return { replaceWith, requireUploaded };
15
- }
16
- function tryRewriteUrl(src, options, uploadedBySourceId, referencedSources, unresolved) {
17
- const normalized = normalizeAssetUrl(src);
18
- if (!normalized) return void 0;
19
- if (isMigrationMediaRef(normalized)) {
20
- referencedSources.add(normalized);
21
- return normalized;
22
- }
23
- referencedSources.add(normalized);
24
- const ref = options.resolveAsset(normalized);
25
- if (!ref?.sourceAssetId) {
26
- unresolved.add(normalized);
27
- return void 0;
28
- }
29
- const { replaceWith, requireUploaded } = resolveRewriteOptions(options);
30
- const uploaded = uploadedBySourceId.get(ref.sourceAssetId);
31
- if (requireUploaded && !uploaded) {
32
- unresolved.add(normalized);
33
- return void 0;
34
- }
35
- return replaceWith(ref, uploaded);
36
- }
37
- function rewriteBackgroundUrlsInStyle(style, options, uploadedBySourceId, referencedSources, unresolved) {
38
- return style.replace(BACKGROUND_IMAGE_URL_PATTERN, (full, quote, rawUrl) => {
39
- const replaced = tryRewriteUrl(rawUrl.trim(), options, uploadedBySourceId, referencedSources, unresolved);
40
- if (!replaced) return full;
41
- const urlCall = quote ? `url(${quote}${replaced}${quote})` : `url(${replaced})`;
42
- return full.replace(/url\s*\(\s*(['"]?)([^'")]+)\1\s*\)/i, urlCall);
43
- });
44
- }
45
- function rewriteSrcset(srcset, options, uploadedBySourceId, referencedSources, unresolved) {
46
- return srcset.split(",").map((entry) => {
47
- const trimmed = entry.trim();
48
- if (!trimmed) return entry;
49
- const [urlPart, descriptor] = trimmed.split(/\s+/, 2);
50
- const replaced = tryRewriteUrl(urlPart ?? "", options, uploadedBySourceId, referencedSources, unresolved);
51
- if (!replaced) return entry;
52
- return descriptor ? `${replaced} ${descriptor}` : replaced;
53
- }).join(", ");
54
- }
55
- function rewriteInlineImages(html, options, uploadedBySourceId) {
56
- if (!html.trim()) {
57
- return { html, referencedSources: [], unresolved: [] };
58
- }
59
- const $ = cheerio.load(html, { xml: false });
60
- const referencedSources = /* @__PURE__ */ new Set();
61
- const unresolved = /* @__PURE__ */ new Set();
62
- $("img").each((_, element) => {
63
- const img = $(element);
64
- const src = img.attr("src")?.trim();
65
- if (src && !src.startsWith("data:")) {
66
- const replaced = tryRewriteUrl(src, options, uploadedBySourceId, referencedSources, unresolved);
67
- if (replaced) img.attr("src", replaced);
68
- }
69
- const srcset = img.attr("srcset")?.trim();
70
- if (srcset) {
71
- img.attr("srcset", rewriteSrcset(srcset, options, uploadedBySourceId, referencedSources, unresolved));
72
- }
73
- });
74
- $("[data-bg-image]").each((_, element) => {
75
- const node = $(element);
76
- const bgImage = node.attr("data-bg-image")?.trim();
77
- if (!bgImage || bgImage.startsWith("data:")) return;
78
- const replaced = tryRewriteUrl(bgImage, options, uploadedBySourceId, referencedSources, unresolved);
79
- if (replaced) node.attr("data-bg-image", replaced);
80
- });
81
- $("[style]").each((_, element) => {
82
- const node = $(element);
83
- const style = node.attr("style");
84
- if (!style?.includes("background")) return;
85
- const rewritten = rewriteBackgroundUrlsInStyle(
86
- style,
87
- options,
88
- uploadedBySourceId,
89
- referencedSources,
90
- unresolved
91
- );
92
- if (rewritten !== style) node.attr("style", rewritten);
93
- });
94
- return {
95
- html: $.root().html() ?? html,
96
- referencedSources: [...referencedSources],
97
- unresolved: [...unresolved]
98
- };
99
- }
100
- function stampMigrationMediaRefs(html, options) {
101
- return rewriteInlineImages(
102
- html,
103
- {
104
- resolveAsset: (src) => {
105
- const sourceAssetId = resolveMigrationMediaSourceId(
106
- src,
107
- options.urlToSourceId,
108
- options.originUrlRewrite
109
- );
110
- if (!sourceAssetId) return void 0;
111
- return { originalSrc: src, sourceAssetId };
112
- },
113
- replaceWith: options.replaceWith,
114
- requireUploaded: options.requireUploaded ?? false
115
- },
116
- /* @__PURE__ */ new Map()
117
- );
118
- }
119
-
120
- export {
121
- rewriteInlineImages,
122
- stampMigrationMediaRefs
123
- };
124
- //# sourceMappingURL=chunk-BONZ3U3I.js.map
@@ -1 +0,0 @@
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,aAA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