@artinstack/migrator 0.1.5 → 0.1.7

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.
@@ -1,157 +1,4 @@
1
- import { z } from 'zod';
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-BckVKPbh.js';
4
-
5
- type LayoutKind = "section" | "row" | "column";
6
- /** Map OSS-2 `data-layout` markers to Grapes component types (host may override). */
7
- interface LayoutTypeMap {
8
- section?: string;
9
- row?: string;
10
- column?: string;
11
- }
12
- interface HtmlToGrapesOptions {
13
- /** Map source class names to Grapes component types. */
14
- componentMap?: Record<string, string>;
15
- /** Map HTML tag names to Grapes component types (e.g. `h2` → `heading`). */
16
- tagMap?: Record<string, string>;
17
- /** Map `data-layout` section/row/column markers to Grapes component types. */
18
- layoutTypeMap?: LayoutTypeMap;
19
- }
20
- interface GrapesStyleRule {
21
- selectors: string[];
22
- style: Record<string, string>;
23
- }
24
- interface GrapesComponent {
25
- type: string;
26
- tagName?: string;
27
- attributes?: Record<string, string>;
28
- classes?: string[];
29
- components?: GrapesComponent[];
30
- content?: string;
31
- void?: boolean;
32
- }
33
- interface GrapesProjectSnapshot {
34
- content: GrapesComponent[];
35
- styles: GrapesStyleRule[];
36
- contentHtml?: string;
37
- contentCss?: string;
38
- }
39
-
40
- /** Cheerio HTML walk → Grapes `content` + root `styles`. */
41
- declare function htmlToGrapes(html: string, options?: HtmlToGrapesOptions): GrapesProjectSnapshot;
42
-
43
- /** ProseMirror / Tiptap mark (inline formatting). */
44
- interface TiptapMark {
45
- type: string;
46
- attrs?: Record<string, string>;
47
- }
48
- /** ProseMirror / Tiptap node — text nodes use `text`; others use `content`. */
49
- interface TiptapNode {
50
- type: string;
51
- attrs?: Record<string, unknown>;
52
- content?: TiptapNode[];
53
- marks?: TiptapMark[];
54
- text?: string;
55
- }
56
- /** Root Tiptap document (`content_json` shape). */
57
- interface TiptapDoc {
58
- type: "doc";
59
- content: TiptapNode[];
60
- }
61
- interface HtmlToTiptapOptions {
62
- /**
63
- * Unwrap OSS-2 `data-layout` scaffolding (section/row/column divs) into prose blocks.
64
- * @default true
65
- */
66
- unwrapLayoutMarkers?: boolean;
67
- }
68
-
69
- /** Cheerio HTML walk → Tiptap / ProseMirror `doc` JSON for blog `content_json`. */
70
- declare function htmlToTiptap(html: string, options?: HtmlToTiptapOptions): TiptapDoc;
71
-
72
- /** Parse `<style>` blocks and class rules into Grapes root `styles[]`. */
73
- declare function cssToStyles(css: string): GrapesStyleRule[];
74
-
75
- declare const grapesStyleRuleSchema: z.ZodObject<{
76
- selectors: z.ZodArray<z.ZodString, "many">;
77
- style: z.ZodRecord<z.ZodString, z.ZodString>;
78
- }, "strip", z.ZodTypeAny, {
79
- style: Record<string, string>;
80
- selectors: string[];
81
- }, {
82
- style: Record<string, string>;
83
- selectors: string[];
84
- }>;
85
- declare const grapesComponentSchema: z.ZodType<GrapesComponent>;
86
- declare const grapesProjectSnapshotSchema: z.ZodObject<{
87
- content: z.ZodArray<z.ZodType<GrapesComponent, z.ZodTypeDef, GrapesComponent>, "many">;
88
- styles: z.ZodArray<z.ZodObject<{
89
- selectors: z.ZodArray<z.ZodString, "many">;
90
- style: z.ZodRecord<z.ZodString, z.ZodString>;
91
- }, "strip", z.ZodTypeAny, {
92
- style: Record<string, string>;
93
- selectors: string[];
94
- }, {
95
- style: Record<string, string>;
96
- selectors: string[];
97
- }>, "many">;
98
- contentHtml: z.ZodOptional<z.ZodString>;
99
- contentCss: z.ZodOptional<z.ZodString>;
100
- }, "strip", z.ZodTypeAny, {
101
- content: GrapesComponent[];
102
- styles: {
103
- style: Record<string, string>;
104
- selectors: string[];
105
- }[];
106
- contentHtml?: string | undefined;
107
- contentCss?: string | undefined;
108
- }, {
109
- content: GrapesComponent[];
110
- styles: {
111
- style: Record<string, string>;
112
- selectors: string[];
113
- }[];
114
- contentHtml?: string | undefined;
115
- contentCss?: string | undefined;
116
- }>;
117
- interface ValidateGrapesProjectSnapshotOptions {
118
- /** When set, every component `type` in the tree must be in this allowlist. */
119
- allowedComponentTypes?: string[];
120
- }
121
- /**
122
- * Opt-in structural check for a Grapes project snapshot (not a full Grapes editor project file).
123
- * Does not validate host-specific component registries unless `allowedComponentTypes` is passed.
124
- */
125
- declare function validateGrapesProjectSnapshot(snapshot: unknown, options?: ValidateGrapesProjectSnapshotOptions): ValidationResult;
126
-
127
- declare const tiptapMarkSchema: z.ZodObject<{
128
- type: z.ZodString;
129
- attrs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
130
- }, "strip", z.ZodTypeAny, {
131
- type: string;
132
- attrs?: Record<string, string> | undefined;
133
- }, {
134
- type: string;
135
- attrs?: Record<string, string> | undefined;
136
- }>;
137
- declare const tiptapNodeSchema: z.ZodType<TiptapNode>;
138
- declare const tiptapDocSchema: z.ZodObject<{
139
- type: z.ZodLiteral<"doc">;
140
- content: z.ZodArray<z.ZodType<TiptapNode, z.ZodTypeDef, TiptapNode>, "many">;
141
- }, "strip", z.ZodTypeAny, {
142
- type: "doc";
143
- content: TiptapNode[];
144
- }, {
145
- type: "doc";
146
- content: TiptapNode[];
147
- }>;
148
- interface ValidateTiptapDocOptions {
149
- /** When set, every node `type` in the tree must be in this allowlist. */
150
- allowedNodeTypes?: string[];
151
- /** When set, every mark `type` must be in this allowlist. */
152
- allowedMarkTypes?: string[];
153
- }
154
- /** Opt-in structural check for a Tiptap / ProseMirror document. */
155
- declare function validateTiptapDoc(doc: unknown, options?: ValidateTiptapDocOptions): ValidationResult;
156
-
157
- export { 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, grapesComponentSchema, grapesProjectSnapshotSchema, grapesStyleRuleSchema, htmlToGrapes, htmlToTiptap, tiptapDocSchema, tiptapMarkSchema, tiptapNodeSchema, validateGrapesProjectSnapshot, validateTiptapDoc };
1
+ export { E as ExpandMigrationMediaRefsResult, G as GrapesComponent, a as GrapesProjectSnapshot, b as GrapesStyleRule, H as HtmlToGrapesOptions, c as HtmlToTiptapOptions, L as LayoutKind, d as LayoutTypeMap, T as TiptapDoc, e as TiptapMark, f as TiptapNode, V as ValidateGrapesProjectSnapshotOptions, g as ValidateTiptapDocOptions, h as buildMigrationMediaUrlIndex, i as cssToStyles, j as expandMigrationMediaRefs, k as grapesComponentSchema, l as grapesProjectSnapshotSchema, m as grapesStyleRuleSchema, n as htmlToGrapes, o as htmlToTiptap, t as tiptapDocSchema, p as tiptapMarkSchema, q as tiptapNodeSchema, v as validateGrapesProjectSnapshot, s as validateTiptapDoc } from '../index-Dp6nqBqe.js';
2
+ 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-Bq16bJA5.js';
3
+ import 'zod';
4
+ import '../types-DWOP8Dcy.js';
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  cssToStyles,
3
+ expandMigrationMediaRefs,
3
4
  grapesComponentSchema,
4
5
  grapesProjectSnapshotSchema,
5
6
  grapesStyleRuleSchema,
@@ -10,19 +11,24 @@ import {
10
11
  tiptapNodeSchema,
11
12
  validateGrapesProjectSnapshot,
12
13
  validateTiptapDoc
13
- } from "../chunk-CIOYDRY5.js";
14
+ } from "../chunk-S4XYG4SM.js";
14
15
  import {
15
- rewriteInlineImages
16
- } from "../chunk-S7TRWILI.js";
17
- import "../chunk-2PNSVE5Y.js";
16
+ buildMigrationMediaUrlIndex,
17
+ rewriteInlineImages,
18
+ stampMigrationMediaRefs
19
+ } from "../chunk-BOYB6XRA.js";
20
+ import "../chunk-XYP3VYDH.js";
18
21
  export {
22
+ buildMigrationMediaUrlIndex,
19
23
  cssToStyles,
24
+ expandMigrationMediaRefs,
20
25
  grapesComponentSchema,
21
26
  grapesProjectSnapshotSchema,
22
27
  grapesStyleRuleSchema,
23
28
  htmlToGrapes,
24
29
  htmlToTiptap,
25
30
  rewriteInlineImages,
31
+ stampMigrationMediaRefs,
26
32
  tiptapDocSchema,
27
33
  tiptapMarkSchema,
28
34
  tiptapNodeSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artinstack/migrator",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Stateless content normalizer and migration framework — WordPress, SmugMug, Squarespace → platform-agnostic schema",
5
5
  "license": "MIT",
6
6
  "author": "ArtInStack",
@@ -1,67 +0,0 @@
1
- // src/lib/content-asset-urls.ts
2
- import * as cheerio from "cheerio";
3
- var ASSET_URL_PARAM_PATTERN = /\b(?:src|image|url)\s*=\s*["']([^"']+)["']/gi;
4
- var IMAGE_EXTENSION_PATTERN = /\.(?:jpe?g|png|gif|webp|avif|svg)(?:[?#]|$)/i;
5
- var WP_UPLOADS_PATTERN = /\/wp-content\/uploads\//i;
6
- function extractImgTagSrcs(content) {
7
- if (!content.trim()) return [];
8
- const $ = cheerio.load(content, { xml: false });
9
- const srcs = [];
10
- $("img[src]").each((_, el) => {
11
- const src = $(el).attr("src")?.trim();
12
- if (src) srcs.push(src);
13
- });
14
- return srcs;
15
- }
16
- function discoverRawImgSrcs(content) {
17
- return extractImgTagSrcs(content).filter((src) => !src.startsWith("data:"));
18
- }
19
- function normalizeAssetUrl(raw) {
20
- const trimmed = raw.trim();
21
- if (!trimmed || trimmed.startsWith("data:")) return void 0;
22
- if (trimmed.startsWith("//")) return `https:${trimmed}`;
23
- return trimmed;
24
- }
25
- function isLikelyImageUrl(url) {
26
- if (!url || url.startsWith("data:")) return false;
27
- if (url.startsWith("/")) {
28
- return WP_UPLOADS_PATTERN.test(url) || IMAGE_EXTENSION_PATTERN.test(url);
29
- }
30
- if (!/^https?:\/\//i.test(url)) return false;
31
- if (WP_UPLOADS_PATTERN.test(url)) return true;
32
- try {
33
- const pathname = new URL(url).pathname;
34
- return IMAGE_EXTENSION_PATTERN.test(pathname);
35
- } catch {
36
- return IMAGE_EXTENSION_PATTERN.test(url);
37
- }
38
- }
39
- function discoverContentAssetUrls(content) {
40
- if (!content.trim()) return [];
41
- const urls = /* @__PURE__ */ new Set();
42
- for (const raw of extractImgTagSrcs(content)) {
43
- const normalized = normalizeAssetUrl(raw);
44
- if (normalized && isLikelyImageUrl(normalized)) {
45
- urls.add(normalized);
46
- }
47
- }
48
- for (const match of content.matchAll(ASSET_URL_PARAM_PATTERN)) {
49
- const normalized = normalizeAssetUrl(match[1] ?? "");
50
- if (normalized && isLikelyImageUrl(normalized)) {
51
- urls.add(normalized);
52
- }
53
- }
54
- return [...urls];
55
- }
56
- function extractInlineImageSrcs(content) {
57
- return discoverContentAssetUrls(content);
58
- }
59
-
60
- export {
61
- discoverRawImgSrcs,
62
- normalizeAssetUrl,
63
- isLikelyImageUrl,
64
- discoverContentAssetUrls,
65
- extractInlineImageSrcs
66
- };
67
- //# sourceMappingURL=chunk-2PNSVE5Y.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/content-asset-urls.ts"],"sourcesContent":["import * as cheerio from \"cheerio\";\n\n/** Builder-agnostic attribute names that commonly hold image URLs in post_content. */\nconst ASSET_URL_PARAM_PATTERN =\n /\\b(?:src|image|url)\\s*=\\s*[\"']([^\"']+)[\"']/gi;\n\nconst IMAGE_EXTENSION_PATTERN = /\\.(?:jpe?g|png|gif|webp|avif|svg)(?:[?#]|$)/i;\nconst WP_UPLOADS_PATTERN = /\\/wp-content\\/uploads\\//i;\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\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 WP_UPLOADS_PATTERN.test(url) || IMAGE_EXTENSION_PATTERN.test(url);\n }\n\n if (!/^https?:\\/\\//i.test(url)) return false;\n\n if (WP_UPLOADS_PATTERN.test(url)) return true;\n\n try {\n const pathname = new URL(url).pathname;\n return IMAGE_EXTENSION_PATTERN.test(pathname);\n } catch {\n return IMAGE_EXTENSION_PATTERN.test(url);\n }\n}\n\n/**\n * Generic content-discovery pass: collect image URLs from HTML `<img>` tags and\n * common shortcode/builder attributes (`src=`, `image=`, `url=`) without parsing\n * 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 const normalized = normalizeAssetUrl(raw);\n if (normalized && isLikelyImageUrl(normalized)) {\n urls.add(normalized);\n }\n }\n\n for (const match of content.matchAll(ASSET_URL_PARAM_PATTERN)) {\n const normalized = normalizeAssetUrl(match[1] ?? \"\");\n if (normalized && isLikelyImageUrl(normalized)) {\n urls.add(normalized);\n }\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 discoverContentAss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AC,QAAQ,KAAK,EAAG,QAAO,CAAC;AAE7B,QAAM,OAAO,oBAAI,IAAY;AAE7B,aAAW,OAAO,kBAAkB,OAAO,GAAG;AAC5C,UAAM,aAAa,kBAAkB,GAAG;AACxC,QAAI,cAAc,iBAAiB,UAAU,GAAG;AAC9C,WAAK,IAAI,UAAU;AAAA,IACrB;AAAA,EACF;AAEA,aAAW,SAAS,QAAQ,SAAS,uBAAuB,GAAG;AAC7D,UAAM,aAAa,kBAAkB,MAAM,CAAC,KAAK,EAAE;AACnD,QAAI,cAAc,iBAAiB,UAAU,GAAG;AAC9C,WAAK,IAAI,UAAU;AAAA,IACrB;AAAA,EACF;AAEA,SAAO,CAAC,GAAG,IAAI;AACjB;AAGO,SAAS,uBAAuB,SAA2B;AAChE,SAAO,yBAAyB,OAAO;AACzC;","names":[]}
@@ -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;;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AE;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,71 +0,0 @@
1
- import {
2
- normalizeAssetUrl
3
- } from "./chunk-2PNSVE5Y.js";
4
-
5
- // src/transformers/rewrite-inline-images.ts
6
- import * as cheerio from "cheerio";
7
- function rewriteSrcset(srcset, options, uploadedBySourceId, referencedSources, unresolved) {
8
- return srcset.split(",").map((entry) => {
9
- const trimmed = entry.trim();
10
- if (!trimmed) return entry;
11
- const [urlPart, descriptor] = trimmed.split(/\s+/, 2);
12
- const normalized = normalizeAssetUrl(urlPart ?? "");
13
- if (!normalized) return entry;
14
- referencedSources.add(normalized);
15
- const ref = options.resolveAsset(normalized);
16
- if (!ref?.sourceAssetId) {
17
- unresolved.add(normalized);
18
- return entry;
19
- }
20
- const uploaded = uploadedBySourceId.get(ref.sourceAssetId);
21
- if (!uploaded) {
22
- unresolved.add(normalized);
23
- return entry;
24
- }
25
- const replaced = options.replaceWith(ref, uploaded);
26
- return descriptor ? `${replaced} ${descriptor}` : replaced;
27
- }).join(", ");
28
- }
29
- function rewriteInlineImages(html, options, uploadedBySourceId) {
30
- if (!html.trim()) {
31
- return { html, referencedSources: [], unresolved: [] };
32
- }
33
- const $ = cheerio.load(html, { xml: false });
34
- const referencedSources = /* @__PURE__ */ new Set();
35
- const unresolved = /* @__PURE__ */ new Set();
36
- $("img").each((_, element) => {
37
- const img = $(element);
38
- const src = img.attr("src")?.trim();
39
- if (src && !src.startsWith("data:")) {
40
- const normalized = normalizeAssetUrl(src);
41
- if (normalized) {
42
- referencedSources.add(normalized);
43
- const ref = options.resolveAsset(normalized);
44
- if (!ref?.sourceAssetId) {
45
- unresolved.add(normalized);
46
- } else {
47
- const uploaded = uploadedBySourceId.get(ref.sourceAssetId);
48
- if (!uploaded) {
49
- unresolved.add(normalized);
50
- } else {
51
- img.attr("src", options.replaceWith(ref, uploaded));
52
- }
53
- }
54
- }
55
- }
56
- const srcset = img.attr("srcset")?.trim();
57
- if (srcset) {
58
- img.attr("srcset", rewriteSrcset(srcset, options, uploadedBySourceId, referencedSources, unresolved));
59
- }
60
- });
61
- return {
62
- html: $.root().html() ?? html,
63
- referencedSources: [...referencedSources],
64
- unresolved: [...unresolved]
65
- };
66
- }
67
-
68
- export {
69
- rewriteInlineImages
70
- };
71
- //# sourceMappingURL=chunk-S7TRWILI.js.map
@@ -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\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 normalized = normalizeAssetUrl(urlPart ?? \"\");\n if (!normalized) return entry;\n referencedSources.add(normalized);\n const ref = options.resolveAsset(normalized);\n if (!ref?.sourceAssetId) {\n unresolved.add(normalized);\n return entry;\n }\n const uploaded = uploadedBySourceId.get(ref.sourceAssetId);\n if (!uploaded) {\n unresolved.add(normalized);\n return entry;\n }\n const replaced = options.replaceWith(ref, uploaded);\n return descriptor ? `${replaced} ${descriptor}` : replaced;\n })\n .join(\", \");\n}\n\n/** Rewrite `<img src>` / `srcset` using uploaded asset targets supplied by the host sink. */\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 normalized = normalizeAssetUrl(src);\n if (normalized) {\n referencedSources.add(normalized);\n const ref = options.resolveAsset(normalized);\n if (!ref?.sourceAssetId) {\n unresolved.add(normalized);\n } else {\n const uploaded = uploadedBySourceId.get(ref.sourceAssetId);\n if (!uploaded) {\n unresolved.add(normalized);\n } else {\n img.attr(\"src\", options.replaceWith(ref, uploaded));\n }\n }\n }\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 return {\n html: $.root().html() ?? html,\n referencedSources: [...referencedSources],\n unresolved: [...unresolved],\n };\n}\n"],"mappings":";;;;;AAAA,YAAY,aAAa;AAyBzB,SAAS,cACP,QACA,SACA,oBACA,mBACA,YACQ;AACR,SAAO,OACJ,MAAM,GAAG,EACT,IAAI,CAAC,UAAU;AACd,UAAM,UAAU,MAAM,KAAK;AAC3B,QAAI,CAAC,QAAS,QAAO;AACrB,UAAM,CAAC,SAAS,UAAU,IAAI,QAAQ,MAAM,OAAO,CAAC;AACpD,UAAM,aAAa,k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