@artinstack/migrator 0.1.6 → 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.
- package/README.md +30 -1
- package/dist/{chunk-CIOYDRY5.js → chunk-ALLFBWBO.js} +115 -2
- package/dist/chunk-ALLFBWBO.js.map +1 -0
- package/dist/{chunk-XQVKA54A.js → chunk-CB5KRANW.js} +247 -59
- package/dist/chunk-CB5KRANW.js.map +1 -0
- package/dist/chunk-EJTWYEAX.js +1 -0
- package/dist/chunk-EJTWYEAX.js.map +1 -0
- package/dist/{chunk-EXYXTAZM.js → chunk-KYNKJ4XV.js} +39 -6
- package/dist/chunk-KYNKJ4XV.js.map +1 -0
- package/dist/{chunk-XYP3VYDH.js → chunk-WHGUE5FC.js} +111 -3
- package/dist/chunk-WHGUE5FC.js.map +1 -0
- package/dist/chunk-XRCF73DA.js +24 -0
- package/dist/chunk-XRCF73DA.js.map +1 -0
- package/dist/{chunk-IPYHS5R2.js → chunk-Z3L6N63Y.js} +45 -34
- package/dist/chunk-Z3L6N63Y.js.map +1 -0
- package/dist/cli/index.js +7 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +5 -17
- package/dist/index.js +38 -9
- package/dist/lib/index.d.ts +7 -25
- package/dist/lib/index.js +32 -3
- package/dist/media-urls-w46-CWUp.d.ts +74 -0
- package/dist/rewrite-inline-images-DyxKUNs3.d.ts +45 -0
- package/dist/sinks/index.d.ts +3 -2
- package/dist/sinks/index.js +4 -3
- package/dist/transformers/index.d.ts +15 -2
- package/dist/transformers/index.js +11 -4
- package/package.json +1 -1
- package/dist/chunk-CIOYDRY5.js.map +0 -1
- package/dist/chunk-EXYXTAZM.js.map +0 -1
- package/dist/chunk-IPYHS5R2.js.map +0 -1
- package/dist/chunk-XQVKA54A.js.map +0 -1
- package/dist/chunk-XYP3VYDH.js.map +0 -1
- package/dist/rewrite-inline-images-DPoxyzVC.d.ts +0 -21
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,26 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
declare function discoverRawImgSrcs(content: string): string[];
|
|
3
|
-
/** Normalize protocol-relative and trim; skip data URIs. */
|
|
4
|
-
declare function normalizeAssetUrl(raw: string): string | undefined;
|
|
5
|
-
/** Heuristic: URL likely points at a raster/vector image asset, not a page link. */
|
|
6
|
-
declare function isLikelyImageUrl(url: string): boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Ordered featured-image candidates when `_thumbnail_id` is missing — heroes
|
|
9
|
-
* (`data-bg-image`, CSS backgrounds, `bg_image=`) before inline assets; within
|
|
10
|
-
* each tier, first in document order wins. Filename tokens (`_w`, `_2048`, …)
|
|
11
|
-
* are not interpreted as quality signals.
|
|
12
|
-
*/
|
|
13
|
-
declare function discoverFeaturedAssetCandidateUrls(content: string): string[];
|
|
14
|
-
/** Best featured-image URL from post/page HTML when attachment id is unavailable. */
|
|
15
|
-
declare function resolveFeaturedContentAssetUrl(content: string): string | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Generic content-discovery pass: collect image URLs from HTML `<img>` tags,
|
|
18
|
-
* section hero markers (`data-bg-image`), inline CSS backgrounds, and common
|
|
19
|
-
* shortcode/builder attributes (`src=`, `image=`, `bg_image=`, …) without
|
|
20
|
-
* parsing builder-specific structure (Tatsu, Elementor, etc.).
|
|
21
|
-
*/
|
|
22
|
-
declare function discoverContentAssetUrls(content: string): string[];
|
|
23
|
-
/** @deprecated Use discoverContentAssetUrls — kept for call-site clarity during transition. */
|
|
24
|
-
declare function extractInlineImageSrcs(content: string): string[];
|
|
1
|
+
export { C as CanonicalInlineAssetUrl, M as MIGRATION_MEDIA_REF_SCHEME, O as OriginUrlRewriteConfig, a as OriginUrlRewriteRule, b as buildContentMediaUrlIndex, c as buildMigrationMediaUrlIndex, d as canonicalizeInlineAssetUrl, e as createMigrationMediaRefReplaceWith, f as createWpContentGatewayRewrite, g as discoverContentAssetUrls, h as discoverFeaturedAssetCandidateUrls, i as discoverRawImgSrcs, j as extractInlineImageSrcs, k as formatMigrationMediaRef, l as isLikelyImageUrl, m as isMigrationMediaRef, n as normalizeAssetUrl, p as parseMigrationMediaRef, r as resolveFeaturedContentAssetUrl, o as resolveMigrationMediaSourceId, q as rewriteOriginUrlsInText } from '../media-urls-w46-CWUp.js';
|
|
25
2
|
|
|
26
|
-
|
|
3
|
+
/** Lowercase URL-safe slug from WordPress post_name or title. */
|
|
4
|
+
declare function sanitizeSlug(raw: string): string;
|
|
5
|
+
/** Normalize absolute permalink to root-relative path. */
|
|
6
|
+
declare function linkToPath(link: string | undefined): string | undefined;
|
|
7
|
+
|
|
8
|
+
export { linkToPath, sanitizeSlug };
|
package/dist/lib/index.js
CHANGED
|
@@ -1,19 +1,48 @@
|
|
|
1
|
+
import "../chunk-EJTWYEAX.js";
|
|
1
2
|
import {
|
|
3
|
+
linkToPath,
|
|
4
|
+
sanitizeSlug
|
|
5
|
+
} from "../chunk-XRCF73DA.js";
|
|
6
|
+
import {
|
|
7
|
+
MIGRATION_MEDIA_REF_SCHEME,
|
|
8
|
+
buildContentMediaUrlIndex,
|
|
9
|
+
buildMigrationMediaUrlIndex,
|
|
10
|
+
canonicalizeInlineAssetUrl,
|
|
11
|
+
createMigrationMediaRefReplaceWith,
|
|
12
|
+
createWpContentGatewayRewrite,
|
|
2
13
|
discoverContentAssetUrls,
|
|
3
14
|
discoverFeaturedAssetCandidateUrls,
|
|
4
15
|
discoverRawImgSrcs,
|
|
5
16
|
extractInlineImageSrcs,
|
|
17
|
+
formatMigrationMediaRef,
|
|
6
18
|
isLikelyImageUrl,
|
|
19
|
+
isMigrationMediaRef,
|
|
7
20
|
normalizeAssetUrl,
|
|
8
|
-
|
|
9
|
-
|
|
21
|
+
parseMigrationMediaRef,
|
|
22
|
+
resolveFeaturedContentAssetUrl,
|
|
23
|
+
resolveMigrationMediaSourceId,
|
|
24
|
+
rewriteOriginUrlsInText
|
|
25
|
+
} from "../chunk-WHGUE5FC.js";
|
|
10
26
|
export {
|
|
27
|
+
MIGRATION_MEDIA_REF_SCHEME,
|
|
28
|
+
buildContentMediaUrlIndex,
|
|
29
|
+
buildMigrationMediaUrlIndex,
|
|
30
|
+
canonicalizeInlineAssetUrl,
|
|
31
|
+
createMigrationMediaRefReplaceWith,
|
|
32
|
+
createWpContentGatewayRewrite,
|
|
11
33
|
discoverContentAssetUrls,
|
|
12
34
|
discoverFeaturedAssetCandidateUrls,
|
|
13
35
|
discoverRawImgSrcs,
|
|
14
36
|
extractInlineImageSrcs,
|
|
37
|
+
formatMigrationMediaRef,
|
|
15
38
|
isLikelyImageUrl,
|
|
39
|
+
isMigrationMediaRef,
|
|
40
|
+
linkToPath,
|
|
16
41
|
normalizeAssetUrl,
|
|
17
|
-
|
|
42
|
+
parseMigrationMediaRef,
|
|
43
|
+
resolveFeaturedContentAssetUrl,
|
|
44
|
+
resolveMigrationMediaSourceId,
|
|
45
|
+
rewriteOriginUrlsInText,
|
|
46
|
+
sanitizeSlug
|
|
18
47
|
};
|
|
19
48
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
interface OriginUrlRewriteRule {
|
|
2
|
+
/** Literal substring or regex matched against the full text block. */
|
|
3
|
+
match: string | RegExp;
|
|
4
|
+
replace: string;
|
|
5
|
+
}
|
|
6
|
+
interface OriginUrlRewriteConfig {
|
|
7
|
+
rules: OriginUrlRewriteRule[];
|
|
8
|
+
}
|
|
9
|
+
/** Swap legacy gateway/staging host fragments before parse, fetch, or asset discovery. */
|
|
10
|
+
declare function rewriteOriginUrlsInText(text: string, config: OriginUrlRewriteConfig): string;
|
|
11
|
+
/** Build a rule that rewrites API-gateway `/prod/wp-content/` paths to a public origin. */
|
|
12
|
+
declare function createWpContentGatewayRewrite(gatewayBase: string, publicOrigin: string): OriginUrlRewriteConfig;
|
|
13
|
+
/** All `<img src>` values (including those not ingested as vault assets). */
|
|
14
|
+
declare function discoverRawImgSrcs(content: string): string[];
|
|
15
|
+
/** Normalize protocol-relative and trim; skip data URIs. */
|
|
16
|
+
declare function normalizeAssetUrl(raw: string): string | undefined;
|
|
17
|
+
/** Heuristic: URL likely points at a raster/vector image asset, not a page link. */
|
|
18
|
+
declare function isLikelyImageUrl(url: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Ordered featured-image candidates when `_thumbnail_id` is missing — heroes
|
|
21
|
+
* (`data-bg-image`, CSS backgrounds, `bg_image=`) before inline assets; within
|
|
22
|
+
* each tier, first in document order wins. Filename tokens (`_w`, `_2048`, …)
|
|
23
|
+
* are not interpreted as quality signals.
|
|
24
|
+
*/
|
|
25
|
+
declare function discoverFeaturedAssetCandidateUrls(content: string): string[];
|
|
26
|
+
/** Best featured-image URL from post/page HTML when attachment id is unavailable. */
|
|
27
|
+
declare function resolveFeaturedContentAssetUrl(content: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Generic content-discovery pass: collect image URLs from HTML `<img>` tags,
|
|
30
|
+
* section hero markers (`data-bg-image`), inline CSS backgrounds, and common
|
|
31
|
+
* shortcode/builder attributes (`src=`, `image=`, `bg_image=`, …) without
|
|
32
|
+
* parsing builder-specific structure (Tatsu, Elementor, etc.).
|
|
33
|
+
*/
|
|
34
|
+
declare function discoverContentAssetUrls(content: string): string[];
|
|
35
|
+
/** @deprecated Use discoverContentAssetUrls — kept for call-site clarity during transition. */
|
|
36
|
+
declare function extractInlineImageSrcs(content: string): string[];
|
|
37
|
+
/** Pseudo-URL scheme for portable migration asset pointers (not WordPress shortcodes). */
|
|
38
|
+
declare const MIGRATION_MEDIA_REF_SCHEME = "artinstack-migration://asset/";
|
|
39
|
+
/** Build `artinstack-migration://asset/{sourceId}` (percent-encodes the normalizer source id). */
|
|
40
|
+
declare function formatMigrationMediaRef(sourceAssetId: string): string;
|
|
41
|
+
declare function isMigrationMediaRef(value: string): boolean;
|
|
42
|
+
/** Parse a migration media ref back to the normalizer `sourceId`, or `undefined` if not a ref. */
|
|
43
|
+
declare function parseMigrationMediaRef(value: string): string | undefined;
|
|
44
|
+
/** Default `replaceWith` for `rewriteInlineImages` / `stampMigrationMediaRefs` (OSS-14). */
|
|
45
|
+
declare function createMigrationMediaRefReplaceWith(): (ref: {
|
|
46
|
+
sourceAssetId?: string;
|
|
47
|
+
}) => string;
|
|
48
|
+
interface CanonicalInlineAssetUrl {
|
|
49
|
+
/** Canonical absolute URL stored on `NormalizedAsset.sourceUrl`. */
|
|
50
|
+
canonicalUrl: string;
|
|
51
|
+
/** Normalizer id: `url:{canonicalUrl}`. */
|
|
52
|
+
sourceId: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* OSS-15: one canonical key for inline `url:` assets — apply origin rewrite then
|
|
56
|
+
* `normalizeAssetUrl` so discovery, refs, and vault entities share the same id.
|
|
57
|
+
*/
|
|
58
|
+
declare function canonicalizeInlineAssetUrl(raw: string, originUrlRewrite?: OriginUrlRewriteConfig): CanonicalInlineAssetUrl | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Map normalized upload URLs (and pathnames) → normalizer `sourceId`.
|
|
61
|
+
* Attachment ids are WXR `post_id` strings; inline discoveries use `url:{src}`.
|
|
62
|
+
*/
|
|
63
|
+
declare function buildMigrationMediaUrlIndex(entries: Iterable<{
|
|
64
|
+
sourceUrl: string;
|
|
65
|
+
sourceId: string;
|
|
66
|
+
}>): Map<string, string>;
|
|
67
|
+
declare function resolveMigrationMediaSourceId(src: string, urlIndex: Map<string, string>, originUrlRewrite?: OriginUrlRewriteConfig): string | undefined;
|
|
68
|
+
/** Merge attachment + inline asset rows into one stamp/lookup index (OSS-15). */
|
|
69
|
+
declare function buildContentMediaUrlIndex(entries: Iterable<{
|
|
70
|
+
sourceUrl: string;
|
|
71
|
+
sourceId: string;
|
|
72
|
+
}>, originUrlRewrite?: OriginUrlRewriteConfig): Map<string, string>;
|
|
73
|
+
|
|
74
|
+
export { type CanonicalInlineAssetUrl as C, MIGRATION_MEDIA_REF_SCHEME as M, type OriginUrlRewriteConfig as O, type OriginUrlRewriteRule as a, buildContentMediaUrlIndex as b, buildMigrationMediaUrlIndex as c, canonicalizeInlineAssetUrl as d, createMigrationMediaRefReplaceWith as e, createWpContentGatewayRewrite as f, discoverContentAssetUrls as g, discoverFeaturedAssetCandidateUrls as h, discoverRawImgSrcs as i, extractInlineImageSrcs as j, formatMigrationMediaRef as k, isLikelyImageUrl as l, isMigrationMediaRef as m, normalizeAssetUrl as n, resolveMigrationMediaSourceId as o, parseMigrationMediaRef as p, rewriteOriginUrlsInText as q, resolveFeaturedContentAssetUrl as r };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { O as OriginUrlRewriteConfig } from './media-urls-w46-CWUp.js';
|
|
2
|
+
|
|
3
|
+
interface RewriteInlineImageRef {
|
|
4
|
+
originalSrc: string;
|
|
5
|
+
sourceAssetId?: string;
|
|
6
|
+
}
|
|
7
|
+
interface UploadedAssetRef {
|
|
8
|
+
targetId: string;
|
|
9
|
+
publicUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
interface RewriteInlineImagesOptions {
|
|
12
|
+
resolveAsset: (src: string) => RewriteInlineImageRef | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Replace a resolved source id with a migration ref or CDN URL.
|
|
15
|
+
* When omitted, defaults to OSS-14 `artinstack-migration://asset/…` refs.
|
|
16
|
+
*/
|
|
17
|
+
replaceWith?: (ref: RewriteInlineImageRef, uploaded?: UploadedAssetRef) => string;
|
|
18
|
+
/**
|
|
19
|
+
* When true, skip URLs that cannot be matched to an uploaded vault target.
|
|
20
|
+
* Default: false when using migration refs; true when a custom `replaceWith` is supplied.
|
|
21
|
+
*/
|
|
22
|
+
requireUploaded?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface RewriteInlineImagesResult {
|
|
25
|
+
html: string;
|
|
26
|
+
referencedSources: string[];
|
|
27
|
+
unresolved: string[];
|
|
28
|
+
}
|
|
29
|
+
/** Rewrite `<img src>` / `srcset`, `data-bg-image`, and inline CSS backgrounds using uploaded asset targets. */
|
|
30
|
+
declare function rewriteInlineImages(html: string, options: RewriteInlineImagesOptions, uploadedBySourceId: Map<string, UploadedAssetRef>): RewriteInlineImagesResult;
|
|
31
|
+
interface StampMigrationMediaRefsOptions {
|
|
32
|
+
/** Pre-built url/pathname → sourceId map (from attachments + inline assets). */
|
|
33
|
+
urlToSourceId: Map<string, string>;
|
|
34
|
+
/** Canonicalize lookup keys during stamp (OSS-15). */
|
|
35
|
+
originUrlRewrite?: OriginUrlRewriteConfig;
|
|
36
|
+
replaceWith?: RewriteInlineImagesOptions["replaceWith"];
|
|
37
|
+
requireUploaded?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* OSS-14 — replace resolved `wp-content/uploads` URLs with `artinstack-migration://asset/…`
|
|
41
|
+
* refs. Does not invent refs for unknown URLs (left unchanged + listed in `unresolved`).
|
|
42
|
+
*/
|
|
43
|
+
declare function stampMigrationMediaRefs(html: string, options: StampMigrationMediaRefsOptions): RewriteInlineImagesResult;
|
|
44
|
+
|
|
45
|
+
export { type RewriteInlineImageRef as R, type StampMigrationMediaRefsOptions as S, type UploadedAssetRef as U, type RewriteInlineImagesOptions as a, type RewriteInlineImagesResult as b, rewriteInlineImages as r, stampMigrationMediaRefs as s };
|
package/dist/sinks/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
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-DWOP8Dcy.js';
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
|
-
import { a as RewriteInlineImagesOptions } from '../rewrite-inline-images-
|
|
4
|
-
export { b as RewriteInlineImagesResult, r as rewriteInlineImages } from '../rewrite-inline-images-
|
|
3
|
+
import { a as RewriteInlineImagesOptions } from '../rewrite-inline-images-DyxKUNs3.js';
|
|
4
|
+
export { b as RewriteInlineImagesResult, r as rewriteInlineImages } from '../rewrite-inline-images-DyxKUNs3.js';
|
|
5
5
|
import { E as EntityBundle } from '../bundle-uAAHehbv.js';
|
|
6
|
+
import '../media-urls-w46-CWUp.js';
|
|
6
7
|
|
|
7
8
|
interface CreatePostResult {
|
|
8
9
|
targetId: string;
|
package/dist/sinks/index.js
CHANGED
|
@@ -18,12 +18,13 @@ import {
|
|
|
18
18
|
runMigrationFromBundle,
|
|
19
19
|
staleUrlsFromEstimate,
|
|
20
20
|
writeFilesystemExport
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-Z3L6N63Y.js";
|
|
22
22
|
import "../chunk-HI7JHWZU.js";
|
|
23
23
|
import {
|
|
24
24
|
rewriteInlineImages
|
|
25
|
-
} from "../chunk-
|
|
26
|
-
import "../chunk-
|
|
25
|
+
} from "../chunk-KYNKJ4XV.js";
|
|
26
|
+
import "../chunk-XRCF73DA.js";
|
|
27
|
+
import "../chunk-WHGUE5FC.js";
|
|
27
28
|
export {
|
|
28
29
|
FALLBACK_ASSET_BYTES,
|
|
29
30
|
FilesystemMigrationSink,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { l as ValidationResult } from '../types-DWOP8Dcy.js';
|
|
3
|
-
export { R as RewriteInlineImageRef, a as RewriteInlineImagesOptions, b as RewriteInlineImagesResult, U as UploadedAssetRef, r as rewriteInlineImages } from '../rewrite-inline-images-
|
|
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-DyxKUNs3.js';
|
|
4
|
+
export { c as buildMigrationMediaUrlIndex } from '../media-urls-w46-CWUp.js';
|
|
4
5
|
|
|
5
6
|
type LayoutKind = "section" | "row" | "column";
|
|
6
7
|
/** Map OSS-2 `data-layout` markers to Grapes component types (host may override). */
|
|
@@ -16,6 +17,8 @@ interface HtmlToGrapesOptions {
|
|
|
16
17
|
tagMap?: Record<string, string>;
|
|
17
18
|
/** Map `data-layout` section/row/column markers to Grapes component types. */
|
|
18
19
|
layoutTypeMap?: LayoutTypeMap;
|
|
20
|
+
/** Grapes type for OSS-12 `data-wp-widget` markers. Default: `wp-widget`. */
|
|
21
|
+
widgetComponentType?: string;
|
|
19
22
|
}
|
|
20
23
|
interface GrapesStyleRule {
|
|
21
24
|
selectors: string[];
|
|
@@ -154,4 +157,14 @@ interface ValidateTiptapDocOptions {
|
|
|
154
157
|
/** Opt-in structural check for a Tiptap / ProseMirror document. */
|
|
155
158
|
declare function validateTiptapDoc(doc: unknown, options?: ValidateTiptapDocOptions): ValidationResult;
|
|
156
159
|
|
|
157
|
-
|
|
160
|
+
interface ExpandMigrationMediaRefsResult {
|
|
161
|
+
html: string;
|
|
162
|
+
unresolved: string[];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Expand OSS-14 `artinstack-migration://asset/…` refs to host CDN URLs.
|
|
166
|
+
* Lookup (`migration_entities` → `publicUrl`) is host-supplied via `resolvePublicUrl`.
|
|
167
|
+
*/
|
|
168
|
+
declare function expandMigrationMediaRefs(html: string, resolvePublicUrl: (sourceId: string) => string | undefined): ExpandMigrationMediaRefsResult;
|
|
169
|
+
|
|
170
|
+
export { type ExpandMigrationMediaRefsResult, type GrapesComponent, type GrapesProjectSnapshot, type GrapesStyleRule, type HtmlToGrapesOptions, type HtmlToTiptapOptions, type LayoutKind, type LayoutTypeMap, type TiptapDoc, type TiptapMark, type TiptapNode, type ValidateGrapesProjectSnapshotOptions, type ValidateTiptapDocOptions, cssToStyles, expandMigrationMediaRefs, grapesComponentSchema, grapesProjectSnapshotSchema, grapesStyleRuleSchema, htmlToGrapes, htmlToTiptap, tiptapDocSchema, tiptapMarkSchema, tiptapNodeSchema, validateGrapesProjectSnapshot, validateTiptapDoc };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
cssToStyles,
|
|
3
|
+
expandMigrationMediaRefs,
|
|
3
4
|
grapesComponentSchema,
|
|
4
5
|
grapesProjectSnapshotSchema,
|
|
5
6
|
grapesStyleRuleSchema,
|
|
@@ -10,19 +11,25 @@ import {
|
|
|
10
11
|
tiptapNodeSchema,
|
|
11
12
|
validateGrapesProjectSnapshot,
|
|
12
13
|
validateTiptapDoc
|
|
13
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-ALLFBWBO.js";
|
|
14
15
|
import {
|
|
15
|
-
rewriteInlineImages
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
rewriteInlineImages,
|
|
17
|
+
stampMigrationMediaRefs
|
|
18
|
+
} from "../chunk-KYNKJ4XV.js";
|
|
19
|
+
import {
|
|
20
|
+
buildMigrationMediaUrlIndex
|
|
21
|
+
} from "../chunk-WHGUE5FC.js";
|
|
18
22
|
export {
|
|
23
|
+
buildMigrationMediaUrlIndex,
|
|
19
24
|
cssToStyles,
|
|
25
|
+
expandMigrationMediaRefs,
|
|
20
26
|
grapesComponentSchema,
|
|
21
27
|
grapesProjectSnapshotSchema,
|
|
22
28
|
grapesStyleRuleSchema,
|
|
23
29
|
htmlToGrapes,
|
|
24
30
|
htmlToTiptap,
|
|
25
31
|
rewriteInlineImages,
|
|
32
|
+
stampMigrationMediaRefs,
|
|
26
33
|
tiptapDocSchema,
|
|
27
34
|
tiptapMarkSchema,
|
|
28
35
|
tiptapNodeSchema,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/transformers/html-to-grapes/index.ts","../src/transformers/css-to-styles/index.ts","../src/transformers/html-to-grapes/walk.ts","../src/transformers/html-to-tiptap/index.ts","../src/transformers/html-to-tiptap/walk.ts","../src/transformers/validate-snapshot.ts","../src/transformers/validate-tiptap-doc.ts"],"sourcesContent":["import * as cheerio from \"cheerio\";\n\nimport { cssToStyles } from \"../css-to-styles/index.js\";\nimport type { GrapesProjectSnapshot, HtmlToGrapesOptions } from \"./types.js\";\nimport { walkHtmlToComponents } from \"./walk.js\";\n\nexport type {\n GrapesComponent,\n GrapesProjectSnapshot,\n GrapesStyleRule,\n HtmlToGrapesOptions,\n LayoutKind,\n LayoutTypeMap,\n} from \"./types.js\";\n\n/** Cheerio HTML walk → Grapes `content` + root `styles`. */\nexport function htmlToGrapes(html: string, options: HtmlToGrapesOptions = {}): GrapesProjectSnapshot {\n const trimmed = html.trim();\n if (!trimmed) {\n return { content: [], styles: [] };\n }\n\n const $ = cheerio.load(trimmed, { xml: false });\n const styleBlocks: string[] = [];\n\n $(\"style\").each((_, element) => {\n styleBlocks.push($(element).html() ?? \"\");\n $(element).remove();\n });\n\n const contentCss = styleBlocks.join(\"\\n\").trim();\n const styles = cssToStyles(contentCss);\n const content = walkHtmlToComponents($, options);\n const contentHtml = serializeContentHtml($);\n\n return {\n content,\n styles,\n ...(contentHtml ? { contentHtml } : {}),\n ...(contentCss ? { contentCss } : {}),\n };\n}\n\nfunction serializeContentHtml($: cheerio.CheerioAPI): string | undefined {\n const body = $(\"body\");\n if (body.length) {\n const html = body.html()?.trim();\n return html || undefined;\n }\n\n const rootHtml = $.root().html()?.trim();\n return rootHtml || undefined;\n}\n","import type { GrapesStyleRule } from \"../html-to-grapes/types.js\";\n\nfunction stripCssComments(css: string): string {\n return css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n}\n\nfunction parseDeclarations(block: string): Record<string, string> {\n const style: Record<string, string> = {};\n for (const declaration of block.split(\";\")) {\n const trimmed = declaration.trim();\n if (!trimmed) continue;\n const separator = trimmed.indexOf(\":\");\n if (separator === -1) continue;\n const property = trimmed.slice(0, separator).trim();\n const value = trimmed.slice(separator + 1).trim();\n if (!property || !value) continue;\n style[property] = value;\n }\n return style;\n}\n\n/** Parse `<style>` blocks and class rules into Grapes root `styles[]`. */\nexport function cssToStyles(css: string): GrapesStyleRule[] {\n const cleaned = stripCssComments(css);\n const rules: GrapesStyleRule[] = [];\n const rulePattern = /([^{]+)\\{([^}]*)\\}/g;\n\n for (const match of cleaned.matchAll(rulePattern)) {\n const selectorText = match[1]?.trim() ?? \"\";\n const declarationBlock = match[2] ?? \"\";\n if (!selectorText || selectorText.startsWith(\"@\")) continue;\n\n const style = parseDeclarations(declarationBlock);\n if (Object.keys(style).length === 0) continue;\n\n const selectors = selectorText\n .split(\",\")\n .map((selector) => selector.trim())\n .filter(Boolean);\n\n if (selectors.length === 0) continue;\n rules.push({ selectors, style });\n }\n\n return rules;\n}\n","import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { AnyNode } from \"domhandler\";\n\nimport type { GrapesComponent, HtmlToGrapesOptions, LayoutKind } from \"./types.js\";\n\ntype CheerioSelection = Cheerio<AnyNode>;\n\nconst INLINE_TAGS = new Set([\n \"a\",\n \"abbr\",\n \"b\",\n \"br\",\n \"cite\",\n \"code\",\n \"del\",\n \"em\",\n \"i\",\n \"img\",\n \"ins\",\n \"mark\",\n \"q\",\n \"s\",\n \"small\",\n \"span\",\n \"strong\",\n \"sub\",\n \"sup\",\n \"u\",\n \"wbr\",\n]);\n\nconst VOID_TAGS = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\nconst TEXT_CONTAINER_TAGS = new Set([\n \"blockquote\",\n \"figcaption\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"label\",\n \"li\",\n \"p\",\n \"pre\",\n \"td\",\n \"th\",\n]);\n\nconst SKIP_TAGS = new Set([\"script\", \"style\", \"noscript\", \"template\"]);\n\nconst DEFAULT_TYPES: Record<string, string> = {\n a: \"link\",\n img: \"image\",\n};\n\nconst LAYOUT_DATA_ATTR = \"data-layout\";\n\nconst DEFAULT_LAYOUT_TYPE_MAP: Record<LayoutKind, string> = {\n section: \"section\",\n row: \"row\",\n column: \"column\",\n};\n\nfunction parseLayoutKind(attributes: Record<string, string> | undefined): LayoutKind | undefined {\n const value = attributes?.[LAYOUT_DATA_ATTR];\n if (value === \"section\" || value === \"row\" || value === \"column\") return value;\n return undefined;\n}\n\nfunction resolveLayoutComponentType(kind: LayoutKind, options: HtmlToGrapesOptions): string {\n return options.layoutTypeMap?.[kind] ?? DEFAULT_LAYOUT_TYPE_MAP[kind];\n}\n\nfunction layoutAttributesForComponent(\n attributes: Record<string, string> | undefined,\n): Record<string, string> | undefined {\n if (!attributes) return undefined;\n const { [LAYOUT_DATA_ATTR]: _layout, ...rest } = attributes;\n return Object.keys(rest).length > 0 ? rest : undefined;\n}\n\nfunction tagNameOf($el: CheerioSelection): string | undefined {\n const raw = $el.prop(\"tagName\");\n return typeof raw === \"string\" ? raw.toLowerCase() : undefined;\n}\n\nfunction applyElementMeta(\n component: GrapesComponent,\n meta: Pick<GrapesComponent, \"attributes\" | \"classes\">,\n): GrapesComponent {\n if (meta.attributes) component.attributes = meta.attributes;\n if (meta.classes) component.classes = meta.classes;\n return component;\n}\n\nfunction pickElementMeta($el: CheerioSelection): Pick<GrapesComponent, \"attributes\" | \"classes\"> {\n const attributes: Record<string, string> = {};\n const classes: string[] = [];\n\n if (typeof $el.attr() === \"object\") {\n for (const [key, value] of Object.entries($el.attr() ?? {})) {\n if (key === \"class\") {\n classes.push(...value.split(/\\s+/).filter(Boolean));\n continue;\n }\n attributes[key] = value;\n }\n }\n\n return {\n attributes: Object.keys(attributes).length > 0 ? attributes : undefined,\n classes: classes.length > 0 ? classes : undefined,\n };\n}\n\nfunction resolveComponentType(\n tagName: string,\n classes: string[] | undefined,\n options: HtmlToGrapesOptions,\n fallback = \"default\",\n): string {\n if (options.componentMap && classes) {\n for (const className of classes) {\n const mapped = options.componentMap[className];\n if (mapped) return mapped;\n }\n }\n const tagMapped = options.tagMap?.[tagName];\n if (tagMapped) return tagMapped;\n return DEFAULT_TYPES[tagName] ?? fallback;\n}\n\nfunction hasOnlyInlineContent($: CheerioAPI, $el: CheerioSelection): boolean {\n let inlineOnly = true;\n\n $el.contents().each((_, node) => {\n if (!inlineOnly) return;\n const $child = $(node);\n if ($child.get(0)?.type === \"text\") return;\n const childTag = tagNameOf($child);\n if (!childTag || !INLINE_TAGS.has(childTag)) {\n inlineOnly = false;\n return;\n }\n if (!hasOnlyInlineContent($, $child)) {\n inlineOnly = false;\n }\n });\n\n return inlineOnly;\n}\n\nfunction walkChildren(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToGrapesOptions,\n): GrapesComponent[] {\n const components: GrapesComponent[] = [];\n\n $el.contents().each((_, node) => {\n const walked = walkNode($, $(node), options);\n if (!walked) return;\n if (Array.isArray(walked)) {\n components.push(...walked);\n } else {\n components.push(walked);\n }\n });\n\n return components;\n}\n\nfunction walkNode(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToGrapesOptions,\n): GrapesComponent | GrapesComponent[] | null {\n const node = $el.get(0);\n if (!node) return null;\n\n if (node.type === \"text\") {\n const text = \"data\" in node ? String(node.data ?? \"\") : \"\";\n if (!text.trim()) return null;\n return { type: \"textnode\", content: text };\n }\n\n if (node.type !== \"tag\") return null;\n\n const tagName = tagNameOf($el);\n if (!tagName || SKIP_TAGS.has(tagName)) return null;\n\n const meta = pickElementMeta($el);\n\n const layoutKind = parseLayoutKind(meta.attributes);\n if (layoutKind) {\n const components = walkChildren($, $el, options);\n const component = applyElementMeta(\n {\n type: resolveLayoutComponentType(layoutKind, options),\n tagName,\n },\n {\n attributes: layoutAttributesForComponent(meta.attributes),\n classes: meta.classes,\n },\n );\n if (components.length > 0) {\n component.components = components;\n }\n return component;\n }\n\n if (VOID_TAGS.has(tagName)) {\n return applyElementMeta(\n {\n type: resolveComponentType(tagName, meta.classes, options),\n tagName,\n void: true,\n },\n meta,\n );\n }\n\n if (TEXT_CONTAINER_TAGS.has(tagName) && hasOnlyInlineContent($, $el)) {\n return applyElementMeta(\n {\n type: resolveComponentType(tagName, meta.classes, options, \"text\"),\n tagName,\n content: $el.html() ?? \"\",\n },\n meta,\n );\n }\n\n if (INLINE_TAGS.has(tagName)) {\n return applyElementMeta(\n {\n type: \"text\",\n content: $.html($el) ?? \"\",\n },\n meta,\n );\n }\n\n const components = walkChildren($, $el, options);\n const component = applyElementMeta(\n {\n type: resolveComponentType(tagName, meta.classes, options),\n tagName,\n },\n meta,\n );\n\n if (components.length > 0) {\n component.components = components;\n }\n\n return component;\n}\n\nfunction appendWalked(\n content: GrapesComponent[],\n walked: GrapesComponent | GrapesComponent[] | null,\n): void {\n if (!walked) return;\n if (Array.isArray(walked)) {\n content.push(...walked);\n return;\n }\n content.push(walked);\n}\n\nfunction walkNodes(\n $: CheerioAPI,\n $nodes: CheerioSelection,\n content: GrapesComponent[],\n options: HtmlToGrapesOptions,\n): void {\n $nodes.each((_, node) => {\n appendWalked(content, walkNode($, $(node), options));\n });\n}\n\nexport function walkHtmlToComponents(\n $: CheerioAPI,\n options: HtmlToGrapesOptions = {},\n): GrapesComponent[] {\n const content: GrapesComponent[] = [];\n const body = $(\"body\");\n\n if (body.length) {\n walkNodes($, body.contents(), content, options);\n return content;\n }\n\n const children = $.root().children();\n if (children.length) {\n walkNodes($, children, content, options);\n } else {\n walkNodes($, $.root().contents(), content, options);\n }\n\n return content;\n}\n","import * as cheerio from \"cheerio\";\n\nimport type { HtmlToTiptapOptions, TiptapDoc } from \"./types.js\";\nimport { prepareHtmlForTiptap, walkHtmlToTiptapDoc } from \"./walk.js\";\n\nexport type { HtmlToTiptapOptions, TiptapDoc, TiptapMark, TiptapNode } from \"./types.js\";\n\n/** Cheerio HTML walk → Tiptap / ProseMirror `doc` JSON for blog `content_json`. */\nexport function htmlToTiptap(html: string, options: HtmlToTiptapOptions = {}): TiptapDoc {\n const trimmed = html.trim();\n if (!trimmed) {\n return { type: \"doc\", content: [{ type: \"paragraph\" }] };\n }\n\n const $ = cheerio.load(trimmed, { xml: false });\n prepareHtmlForTiptap($);\n return walkHtmlToTiptapDoc($, options);\n}\n","import type { Cheerio, CheerioAPI } from \"cheerio\";\nimport type { AnyNode, Element } from \"domhandler\";\n\nimport type { HtmlToTiptapOptions, TiptapDoc, TiptapMark, TiptapNode } from \"./types.js\";\n\ntype CheerioSelection = Cheerio<AnyNode>;\n\nconst SKIP_TAGS = new Set([\"script\", \"style\", \"noscript\", \"template\"]);\nconst HEADING_TAGS = new Set([\"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\"]);\nconst UNWRAP_TAGS = new Set([\n \"article\",\n \"aside\",\n \"div\",\n \"figure\",\n \"footer\",\n \"header\",\n \"main\",\n \"nav\",\n \"section\",\n \"span\",\n]);\n\nconst INLINE_TAGS = new Set([\n \"a\",\n \"abbr\",\n \"b\",\n \"br\",\n \"cite\",\n \"code\",\n \"del\",\n \"em\",\n \"i\",\n \"ins\",\n \"mark\",\n \"q\",\n \"s\",\n \"small\",\n \"strong\",\n \"sub\",\n \"sup\",\n \"u\",\n \"wbr\",\n]);\n\nconst LAYOUT_ATTR = \"data-layout\";\n\nfunction tagNameOf($el: CheerioSelection): string | undefined {\n const raw = $el.prop(\"tagName\");\n return typeof raw === \"string\" ? raw.toLowerCase() : undefined;\n}\n\nfunction headingLevel(tagName: string): number {\n const level = Number.parseInt(tagName.slice(1), 10);\n return Number.isFinite(level) ? level : 1;\n}\n\nfunction isLayoutMarker($el: CheerioSelection, options: HtmlToTiptapOptions): boolean {\n if (options.unwrapLayoutMarkers === false) return false;\n return $el.attr(LAYOUT_ATTR) !== undefined;\n}\n\nfunction hasOnlyInlineContent($: CheerioAPI, $el: CheerioSelection): boolean {\n let inlineOnly = true;\n\n $el.contents().each((_, node) => {\n if (!inlineOnly) return;\n const $child = $(node);\n if ($child.get(0)?.type === \"text\") return;\n const childTag = tagNameOf($child);\n if (!childTag || childTag === \"br\" || childTag === \"img\") return;\n if (!INLINE_TAGS.has(childTag)) {\n inlineOnly = false;\n return;\n }\n if (!hasOnlyInlineContent($, $child)) {\n inlineOnly = false;\n }\n });\n\n return inlineOnly;\n}\n\nfunction hasBlockChild($: CheerioAPI, $el: CheerioSelection): boolean {\n let hasBlock = false;\n $el.contents().each((_, node) => {\n if (hasBlock) return;\n const $child = $(node);\n if ($child.get(0)?.type === \"text\") return;\n const childTag = tagNameOf($child);\n if (!childTag) return;\n if (\n HEADING_TAGS.has(childTag) ||\n childTag === \"p\" ||\n childTag === \"ul\" ||\n childTag === \"ol\" ||\n childTag === \"blockquote\" ||\n childTag === \"pre\" ||\n childTag === \"hr\" ||\n childTag === \"img\" ||\n childTag === \"table\" ||\n isLayoutMarker($child, { unwrapLayoutMarkers: true }) ||\n (UNWRAP_TAGS.has(childTag) && hasBlockChild($, $child))\n ) {\n hasBlock = true;\n }\n });\n return hasBlock;\n}\n\nfunction textNode(text: string, marks: TiptapMark[] = []): TiptapNode {\n const node: TiptapNode = { type: \"text\", text };\n if (marks.length > 0) node.marks = marks;\n return node;\n}\n\nfunction paragraph(content: TiptapNode[]): TiptapNode {\n return content.length > 0 ? { type: \"paragraph\", content } : { type: \"paragraph\" };\n}\n\nfunction appendMarks(existing: TiptapMark[], added: TiptapMark): TiptapMark[] {\n if (existing.some((mark) => mark.type === added.type)) return existing;\n return [...existing, added];\n}\n\nfunction marksForTag(tagName: string, $el: CheerioSelection): TiptapMark[] {\n switch (tagName) {\n case \"strong\":\n case \"b\":\n return [{ type: \"bold\" }];\n case \"em\":\n case \"i\":\n return [{ type: \"italic\" }];\n case \"s\":\n case \"del\":\n case \"strike\":\n return [{ type: \"strike\" }];\n case \"u\":\n return [{ type: \"underline\" }];\n case \"code\":\n return [{ type: \"code\" }];\n case \"a\": {\n const href = $el.attr(\"href\");\n if (!href) return [];\n const attrs: Record<string, string> = { href };\n const target = $el.attr(\"target\");\n if (target) attrs.target = target;\n const rel = $el.attr(\"rel\");\n if (rel) attrs.rel = rel;\n return [{ type: \"link\", attrs }];\n }\n default:\n return [];\n }\n}\n\nfunction imageNode($el: CheerioSelection): TiptapNode | null {\n const src = $el.attr(\"src\");\n if (!src) return null;\n const attrs: Record<string, unknown> = { src };\n const alt = $el.attr(\"alt\");\n if (alt !== undefined) attrs.alt = alt;\n const title = $el.attr(\"title\");\n if (title) attrs.title = title;\n return { type: \"image\", attrs };\n}\n\nfunction parseInlineContent(\n $: CheerioAPI,\n $el: CheerioSelection,\n marks: TiptapMark[] = [],\n): TiptapNode[] {\n const rootTag = tagNameOf($el);\n if (rootTag && INLINE_TAGS.has(rootTag) && rootTag !== \"br\") {\n marks = marksForTag(rootTag, $el).reduce((acc, mark) => appendMarks(acc, mark), marks);\n }\n\n const nodes: TiptapNode[] = [];\n\n $el.contents().each((_, node) => {\n if (node.type === \"text\") {\n const text = String(node.data ?? \"\");\n if (text) nodes.push(textNode(text, marks));\n return;\n }\n\n if (node.type !== \"tag\") return;\n\n const $child = $(node);\n const tagName = tagNameOf($child);\n if (!tagName || SKIP_TAGS.has(tagName)) return;\n\n if (tagName === \"br\") {\n nodes.push({ type: \"hardBreak\" });\n return;\n }\n\n if (tagName === \"img\") {\n return;\n }\n\n const childMarks = marksForTag(tagName, $child);\n const combinedMarks = childMarks.reduce((acc, mark) => appendMarks(acc, mark), [...marks]);\n nodes.push(...parseInlineContent($, $child, combinedMarks));\n });\n\n return nodes;\n}\n\n/** Parse a block container that holds inline content (p, heading, etc.). Splits on nested block/img. */\nfunction parseMixedBlockContent(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToTiptapOptions,\n): TiptapNode[] {\n const blocks: TiptapNode[] = [];\n let inlineBuffer: TiptapNode[] = [];\n\n function flushInline(): void {\n if (inlineBuffer.length === 0) return;\n blocks.push(paragraph(inlineBuffer));\n inlineBuffer = [];\n }\n\n $el.contents().each((_, node) => {\n if (node.type === \"text\") {\n const text = String(node.data ?? \"\");\n if (text) inlineBuffer.push(textNode(text));\n return;\n }\n\n if (node.type !== \"tag\") return;\n\n const $child = $(node);\n const tagName = tagNameOf($child);\n if (!tagName || SKIP_TAGS.has(tagName)) return;\n\n if (tagName === \"br\") {\n inlineBuffer.push({ type: \"hardBreak\" });\n return;\n }\n\n if (tagName === \"img\") {\n flushInline();\n const image = imageNode($child);\n if (image) blocks.push(image);\n return;\n }\n\n if (INLINE_TAGS.has(tagName)) {\n inlineBuffer.push(...parseInlineContent($, $child));\n return;\n }\n\n flushInline();\n blocks.push(...walkBlockNodes($, $child, options));\n });\n\n flushInline();\n return blocks;\n}\n\nfunction walkListItem($: CheerioAPI, $el: CheerioSelection, options: HtmlToTiptapOptions): TiptapNode {\n const blocks = walkBlockNodes($, $el, options);\n if (blocks.length === 0) {\n return { type: \"listItem\", content: [{ type: \"paragraph\" }] };\n }\n\n const normalized: TiptapNode[] = [];\n for (const block of blocks) {\n if (\n block.type === \"paragraph\" ||\n block.type === \"image\" ||\n block.type === \"blockquote\" ||\n block.type === \"bulletList\" ||\n block.type === \"orderedList\"\n ) {\n normalized.push(block);\n continue;\n }\n normalized.push(paragraph(block.content ?? []));\n }\n\n return { type: \"listItem\", content: normalized };\n}\n\nfunction walkBlockNode(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToTiptapOptions,\n): TiptapNode[] {\n const node = $el.get(0);\n if (!node) return [];\n\n if (node.type === \"text\") {\n const text = String(node.data ?? \"\").trim();\n return text ? [paragraph([textNode(text)])] : [];\n }\n\n if (node.type !== \"tag\") return [];\n\n const tagName = tagNameOf($el);\n if (!tagName || SKIP_TAGS.has(tagName)) return [];\n\n if (isLayoutMarker($el, options)) {\n return walkBlockNodes($, $el, options);\n }\n\n if (UNWRAP_TAGS.has(tagName)) {\n if (hasBlockChild($, $el)) {\n return walkBlockNodes($, $el, options);\n }\n if (hasOnlyInlineContent($, $el)) {\n const inline = parseInlineContent($, $el);\n return inline.length > 0 ? [paragraph(inline)] : [];\n }\n return walkBlockNodes($, $el, options);\n }\n\n if (HEADING_TAGS.has(tagName)) {\n const content = parseInlineContent($, $el);\n if (content.length === 0) return [];\n return [{ type: \"heading\", attrs: { level: headingLevel(tagName) }, content }];\n }\n\n if (tagName === \"p\") {\n return parseMixedBlockContent($, $el, options);\n }\n\n if (tagName === \"ul\") {\n const items: TiptapNode[] = [];\n $el.children(\"li\").each((_, li) => {\n items.push(walkListItem($, $(li), options));\n });\n return items.length > 0 ? [{ type: \"bulletList\", content: items }] : [];\n }\n\n if (tagName === \"ol\") {\n const items: TiptapNode[] = [];\n $el.children(\"li\").each((_, li) => {\n items.push(walkListItem($, $(li), options));\n });\n return items.length > 0 ? [{ type: \"orderedList\", content: items }] : [];\n }\n\n if (tagName === \"li\") {\n return [walkListItem($, $el, options)];\n }\n\n if (tagName === \"blockquote\") {\n const blocks = walkBlockNodes($, $el, options);\n if (blocks.length === 0) return [];\n return [{ type: \"blockquote\", content: blocks }];\n }\n\n if (tagName === \"pre\") {\n const code = $el.find(\"code\").first();\n const text = (code.length ? code.text() : $el.text()).replace(/\\n$/, \"\");\n if (!text) return [];\n return [{ type: \"codeBlock\", content: [textNode(text)] }];\n }\n\n if (tagName === \"hr\") {\n return [{ type: \"horizontalRule\" }];\n }\n\n if (tagName === \"img\") {\n const image = imageNode($el);\n return image ? [image] : [];\n }\n\n if (tagName === \"table\") {\n const rows: string[] = [];\n $el.find(\"tr\").each((_, tr) => {\n const cells: string[] = [];\n $(tr)\n .find(\"th, td\")\n .each((__, cell) => {\n const text = $(cell).text().trim();\n if (text) cells.push(text);\n });\n if (cells.length > 0) rows.push(cells.join(\" | \"));\n });\n return rows.map((row) => paragraph([textNode(row)]));\n }\n\n return walkBlockNodes($, $el, options);\n}\n\nfunction walkBlockNodes(\n $: CheerioAPI,\n $el: CheerioSelection,\n options: HtmlToTiptapOptions,\n): TiptapNode[] {\n const blocks: TiptapNode[] = [];\n\n $el.contents().each((_, node) => {\n blocks.push(...walkBlockNode($, $(node), options));\n });\n\n return blocks;\n}\n\nfunction normalizeDocContent(content: TiptapNode[]): TiptapNode[] {\n const normalized: TiptapNode[] = [];\n\n for (const block of content) {\n if (block.type === \"paragraph\" && (!block.content || block.content.length === 0)) {\n continue;\n }\n normalized.push(block);\n }\n\n return normalized;\n}\n\nexport function walkHtmlToTiptapDoc(\n $: CheerioAPI,\n options: HtmlToTiptapOptions = {},\n): TiptapDoc {\n const resolved: HtmlToTiptapOptions = {\n unwrapLayoutMarkers: options.unwrapLayoutMarkers ?? true,\n };\n\n let content: TiptapNode[] = [];\n const body = $(\"body\");\n\n if (body.length) {\n content = walkBlockNodes($, body, resolved);\n } else {\n const children = $.root().children();\n if (children.length) {\n content = walkBlockNodes($, children, resolved);\n } else {\n content = walkBlockNodes($, $.root(), resolved);\n }\n }\n\n content = normalizeDocContent(content);\n if (content.length === 0) {\n content = [{ type: \"paragraph\" }];\n }\n\n return { type: \"doc\", content };\n}\n\n/** Strip layout/style noise before walking (mutates loaded DOM). */\nexport function prepareHtmlForTiptap($: CheerioAPI): void {\n $(\"style, script, noscript, template\").remove();\n}\n\nexport function isElementNode(node: AnyNode): node is Element {\n return node.type === \"tag\";\n}\n","import { z } from \"zod\";\n\nimport type { ValidationIssue, ValidationResult } from \"../normalizer/types.js\";\nimport type { GrapesComponent, GrapesProjectSnapshot } from \"./html-to-grapes/types.js\";\n\nexport const grapesStyleRuleSchema = z.object({\n selectors: z.array(z.string().min(1)).min(1),\n style: z.record(z.string(), z.string()),\n});\n\nexport const grapesComponentSchema: z.ZodType<GrapesComponent> = z.lazy(() =>\n z.object({\n type: z.string().min(1),\n tagName: z.string().optional(),\n attributes: z.record(z.string(), z.string()).optional(),\n classes: z.array(z.string()).optional(),\n components: z.array(grapesComponentSchema).optional(),\n content: z.string().optional(),\n void: z.boolean().optional(),\n }),\n);\n\nexport const grapesProjectSnapshotSchema = z.object({\n content: z.array(grapesComponentSchema),\n styles: z.array(grapesStyleRuleSchema),\n contentHtml: z.string().optional(),\n contentCss: z.string().optional(),\n});\n\nexport interface ValidateGrapesProjectSnapshotOptions {\n /** When set, every component `type` in the tree must be in this allowlist. */\n allowedComponentTypes?: string[];\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 collectComponentTypes(components: GrapesComponent[]): string[] {\n const types: string[] = [];\n for (const component of components) {\n types.push(component.type);\n if (component.components?.length) {\n types.push(...collectComponentTypes(component.components));\n }\n }\n return types;\n}\n\nfunction validateAllowedComponentTypes(\n snapshot: GrapesProjectSnapshot,\n allowedComponentTypes: string[],\n): ValidationIssue[] {\n const allowlist = new Set(allowedComponentTypes);\n const issues: ValidationIssue[] = [];\n\n for (const componentType of collectComponentTypes(snapshot.content)) {\n if (!allowlist.has(componentType)) {\n issues.push({\n code: \"invalid_component_type\",\n message: `Component type \"${componentType}\" is not in allowedComponentTypes`,\n path: \"content\",\n });\n }\n }\n\n return issues;\n}\n\n/**\n * Opt-in structural check for a Grapes project snapshot (not a full Grapes editor project file).\n * Does not validate host-specific component registries unless `allowedComponentTypes` is passed.\n */\nexport function validateGrapesProjectSnapshot(\n snapshot: unknown,\n options: ValidateGrapesProjectSnapshotOptions = {},\n): ValidationResult {\n const result = grapesProjectSnapshotSchema.safeParse(snapshot);\n if (!result.success) {\n return { ok: false, issues: zodIssuesToValidationIssues(result.error.issues) };\n }\n\n if (options.allowedComponentTypes?.length) {\n const typeIssues = validateAllowedComponentTypes(result.data, options.allowedComponentTypes);\n if (typeIssues.length > 0) {\n return { ok: false, issues: typeIssues };\n }\n }\n\n return { ok: true, issues: [] };\n}\n","import { z } from \"zod\";\n\nimport type { ValidationIssue, ValidationResult } from \"../normalizer/types.js\";\nimport type { TiptapDoc, TiptapNode } from \"./html-to-tiptap/types.js\";\n\nexport const tiptapMarkSchema = z.object({\n type: z.string().min(1),\n attrs: z.record(z.string(), z.string()).optional(),\n});\n\nexport const tiptapNodeSchema: z.ZodType<TiptapNode> = z.lazy(() =>\n z.union([\n z.object({\n type: z.literal(\"text\"),\n text: z.string(),\n marks: z.array(tiptapMarkSchema).optional(),\n }),\n z.object({\n type: z.string().min(1),\n attrs: z.record(z.unknown()).optional(),\n content: z.array(tiptapNodeSchema).optional(),\n marks: z.array(tiptapMarkSchema).optional(),\n }),\n ]),\n);\n\nexport const tiptapDocSchema = z.object({\n type: z.literal(\"doc\"),\n content: z.array(tiptapNodeSchema),\n});\n\nexport interface ValidateTiptapDocOptions {\n /** When set, every node `type` in the tree must be in this allowlist. */\n allowedNodeTypes?: string[];\n /** When set, every mark `type` must be in this allowlist. */\n allowedMarkTypes?: string[];\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 collectNodeTypes(nodes: TiptapNode[]): string[] {\n const types: string[] = [];\n for (const node of nodes) {\n types.push(node.type);\n if (node.content?.length) {\n types.push(...collectNodeTypes(node.content));\n }\n }\n return types;\n}\n\nfunction collectMarkTypes(nodes: TiptapNode[]): string[] {\n const types: string[] = [];\n for (const node of nodes) {\n if (node.marks?.length) {\n types.push(...node.marks.map((mark) => mark.type));\n }\n if (node.content?.length) {\n types.push(...collectMarkTypes(node.content));\n }\n }\n return types;\n}\n\nfunction validateAllowedTypes(\n doc: TiptapDoc,\n allowedNodeTypes: string[] | undefined,\n allowedMarkTypes: string[] | undefined,\n): ValidationIssue[] {\n const issues: ValidationIssue[] = [];\n\n if (allowedNodeTypes) {\n const allowlist = new Set(allowedNodeTypes);\n for (const nodeType of collectNodeTypes(doc.content)) {\n if (!allowlist.has(nodeType)) {\n issues.push({\n code: \"invalid_node_type\",\n message: `Node type \"${nodeType}\" is not in allowedNodeTypes`,\n path: \"content\",\n });\n }\n }\n }\n\n if (allowedMarkTypes) {\n const allowlist = new Set(allowedMarkTypes);\n for (const markType of collectMarkTypes(doc.content)) {\n if (!allowlist.has(markType)) {\n issues.push({\n code: \"invalid_mark_type\",\n message: `Mark type \"${markType}\" is not in allowedMarkTypes`,\n path: \"content\",\n });\n }\n }\n }\n\n return issues;\n}\n\n/** Opt-in structural check for a Tiptap / ProseMirror document. */\nexport function validateTiptapDoc(\n doc: unknown,\n options: ValidateTiptapDocOptions = {},\n): ValidationResult {\n const parsed = tiptapDocSchema.safeParse(doc);\n if (!parsed.success) {\n return { ok: false, issues: zodIssuesToValidationIssues(parsed.error.issues) };\n }\n\n const typeIssues = validateAllowedTypes(\n parsed.data,\n options.allowedNodeTypes,\n options.allowedMarkTypes,\n );\n if (typeIssues.length > 0) {\n return { ok: false, issues: typeIssues };\n }\n\n return { ok: true, issues: [] };\n}\n"],"mappings":";AAAA,YAAY,aAAa;;;ACEzB,SAAS,iBAAiB,KAAqB;AAC7C,SAAO,IAAI,QAAQ,qBAAqB,EAAE;AAC5C;AAEA,SAAS,kBAAkB,OAAuC;AAChE,QAAM,QAAgC,CAAC;AACvC,aAAW,eAAe,MAAM,MAAM,GAAG,GAAG;AAC1C,UAAM,UAAU,YAAY,KAAK;AACjC,QAAI,CAAC,QAAS;AACd,UAAM,YAAY,QAAQ,QAAQ,GAAG;AACrC,QAAI,cAAc,GAAI;AACtB,UAAM,WAAW,QAAQ,MAAM,GAAG,SAAS,EAAE,KAAK;AAClD,UAAM,QAAQ,QAAQ,MAAM,YAAY,CAAC,EAAE,KAAK;AAChD,QAAI,CAAC,YAAY,CAAC,MAAO;AACzB,UAAM,QAAQ,IAAI;AAAA,EACpB;AACA,SAAO;AACT;AAGO,SAAS,YAAY,KAAgC;AAC1D,QAAM,UAAU,iBAAiB,GAAG;AACpC,QAAM,QAA2B,CAAC;AAClC,QAAM,cAAc;AAEpB,aAAW,SAAS,QAAQ,SAAS,WAAW,GAAG;AACjD,UAAM,eAAe,MAAM,CAAC,GAAG,KAAK,KAAK;AACzC,UAAM,mBAAmB,MAAM,CAAC,KAAK;AACrC,QAAI,CAAC,gBAAgB,aAAa,WAAW,GAAG,EAAG;AAEnD,UAAM,QAAQ,kB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,IAAI,gBAAgB;AAC1C,eAAW,YAAY,iBAAiB,IAAI,OAAO,GAAG;AACpD,UAAI,CAAC,UAAU,IAAI,QAAQ,GAAG;AAC5B,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,SAAS,cAAc,QAAQ;AAAA,UAC/B,MAAM;AAAA,QACR,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAGO,SAAS,kBACd,KACA,UAAoC,CAAC,GACnB;AAClB,QAAM,SAAS,gBAAgB,UAAU,GAAG;AAC5C,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,EAAE,IAAI,OAAO,QAAQA,6BAA4B,OAAO,MAAM,MAAM,EAAE;AAAA,EAC/E;AAEA,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AACA,MAAI,WAAW,SAAS,GAAG;AACzB,WAAO,EAAE,IAAI,OAAO,QAAQ,WAAW;AAAA,EACzC;AAEA,SAAO,EAAE,IAAI,MAAM,QAAQ,CAAC,EAAE;AAChC;","names":["components","component","cheerio","SKIP_TAGS","INLINE_TAGS","tagNameOf","hasOnlyInlineContent","z","zodIssuesToValidationIssues"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/transformers/rewrite-inline-images.ts"],"sourcesContent":["import * as cheerio from \"cheerio\";\n\nimport { normalizeAssetUrl } from \"../lib/content-asset-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 replaceWith: (ref: RewriteInlineImageRef, uploaded: UploadedAssetRef) => string;\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 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 referencedSources.add(normalized);\n const ref = options.resolveAsset(normalized);\n if (!ref?.sourceAssetId) {\n unresolved.add(normalized);\n return undefined;\n }\n\n const uploaded = uploadedBySourceId.get(ref.sourceAssetId);\n if (!uploaded) {\n unresolved.add(normalized);\n return undefined;\n }\n\n return options.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"],"mappings":";;;;;AAAA,YAAY,aAAa;AA0BzB,IAAM,+BACJ;AAEF,SAAS,cACP,KACA,SACA,oBACA,mBACA,YACoB;AACpB,QAAM,aAAa,kBAAkB,GAAG;AACxC,MAAI,CAAC,WAAY,QAAO;AAExB,oBAAkB,IAAI,UAAU;AAChC,QAAM,MAAM,QAAQ,aAAa,UAAU;AAC3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