@wix/himalaya-cli 0.1079.0 → 0.1081.0
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/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +20 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +62 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-shell.d.ts +0 -14
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/validator.d.ts +36 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/rich-content/src/display.d.ts +26 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/rich-content/src/index.d.ts +79 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +25 -49
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +508 -41
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-rich-content.mjs +345 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/package.json +4 -0
- package/dist/cli.mjs +2043 -1280
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/component-reference.json +10 -1
- package/guides/component-reference.md +20 -2
- package/guides/importable-sdks.md +1 -0
- package/guides/index.json +1 -1
- package/guides/sdk-reference.json +74 -1
- package/guides/splash-screens.md +13 -1
- package/package.json +2 -2
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/beauty-salon-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/community-club-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/community-club-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/community-club-owner/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
- package/templates/events-meetups-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/events-meetups-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/gym-fitness-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/nonprofit-cause-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
- package/templates/owner-lite/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/owner-lite/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/owner-lite/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/podcast-creator-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/portfolio-creative-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/restaurant-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/restaurant-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
- package/templates/retail-store-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/retail-store-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-post-content.ts +7 -26
- package/templates/yoga-studio-owner/tier5-src/_shared/owner-rich-guard.ts +12 -41
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-event-form/index.ts +2 -2
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
// ../../stdlib/wix-sdk/media/src/index.ts
|
|
2
|
+
var WIX_LIST_IMAGE = { width: 1e3, height: 1e3, quality: 85 };
|
|
3
|
+
var WIX_DETAIL_IMAGE = { width: 1400, height: 1400, quality: 85 };
|
|
4
|
+
var WIX_MEDIA = /^https?:\/\/static\.wixstatic\.com\/media\/[^/]/;
|
|
5
|
+
var WIX_IMAGE = /^wix:image:\/\/v1\/([^/]+)/i;
|
|
6
|
+
var WIX_TRANSFORM = /^(https?:\/\/static\.wixstatic\.com\/media\/[^/]+\/v1\/)([^/]+)\/([^/?#]+)(?:\/([^/?#]+))?([?#].*)?$/i;
|
|
7
|
+
var SIZING_PARAM = /^(w|h|q)_\d+$/i;
|
|
8
|
+
var WEB_URL = /^https?:\/\//i;
|
|
9
|
+
var RESIZABLE_MODES = /* @__PURE__ */ new Set(["fit", "fill"]);
|
|
10
|
+
var OWNED_PARAM = /^(w|h|q)_/i;
|
|
11
|
+
var DROPPED_PARAM = /^enc_/i;
|
|
12
|
+
function wixMediaId(reference) {
|
|
13
|
+
return WIX_IMAGE.exec(reference)?.[1] ?? (reference.includes("/") || reference.includes(":") ? "" : reference);
|
|
14
|
+
}
|
|
15
|
+
function resolveWixMediaReference(reference) {
|
|
16
|
+
const mediaId = wixMediaId(reference);
|
|
17
|
+
return mediaId ? `https://static.wixstatic.com/media/${mediaId}` : reference;
|
|
18
|
+
}
|
|
19
|
+
function requestedParams(size) {
|
|
20
|
+
return [`w_${size.width}`, `h_${size.height}`, `q_${size.quality ?? 85}`];
|
|
21
|
+
}
|
|
22
|
+
function fittedParams(size, source, mode) {
|
|
23
|
+
const quality = `q_${size.quality ?? 85}`;
|
|
24
|
+
const { width: sourceWidth, height: sourceHeight } = source;
|
|
25
|
+
if (sourceWidth && sourceHeight) {
|
|
26
|
+
if (mode.toLowerCase() === "fill") {
|
|
27
|
+
const scale = Math.min(size.width / sourceWidth, size.height / sourceHeight, 1);
|
|
28
|
+
return [
|
|
29
|
+
`w_${Math.max(1, Math.round(sourceWidth * scale))}`,
|
|
30
|
+
`h_${Math.max(1, Math.round(sourceHeight * scale))}`,
|
|
31
|
+
quality
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
return [
|
|
35
|
+
`w_${Math.min(sourceWidth, size.width)}`,
|
|
36
|
+
`h_${Math.min(sourceHeight, size.height)}`,
|
|
37
|
+
quality
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
if (sourceWidth) return [`w_${Math.min(sourceWidth, size.width)}`, quality];
|
|
41
|
+
if (sourceHeight) return [`h_${Math.min(sourceHeight, size.height)}`, quality];
|
|
42
|
+
return requestedParams(size);
|
|
43
|
+
}
|
|
44
|
+
function resizeWixTransform(url, size) {
|
|
45
|
+
const transform = WIX_TRANSFORM.exec(url);
|
|
46
|
+
if (!transform || !RESIZABLE_MODES.has(transform[2].toLowerCase())) return url;
|
|
47
|
+
const [, base, mode, rawParams, filename, suffix] = transform;
|
|
48
|
+
const source = rawParams.split(",").filter(Boolean);
|
|
49
|
+
if (!filename && !source.some((param) => SIZING_PARAM.test(param))) return url;
|
|
50
|
+
const dimensions = dimensionsOf(source);
|
|
51
|
+
if (mode.toLowerCase() === "fill" && !dimensions.width && !dimensions.height) return url;
|
|
52
|
+
const stated = [dimensions.width, dimensions.height].filter((d) => d !== void 0);
|
|
53
|
+
if (stated.length > 0 && (dimensions.width ?? 0) <= size.width && (dimensions.height ?? 0) <= size.height) return url;
|
|
54
|
+
const carried = source.filter((p) => !OWNED_PARAM.test(p) && !DROPPED_PARAM.test(p));
|
|
55
|
+
const params = [...fittedParams(size, dimensions, mode), ...carried];
|
|
56
|
+
return `${base}${mode}/${params.join(",")}/image.jpg${suffix ?? ""}`;
|
|
57
|
+
}
|
|
58
|
+
function wixTransformDimension(params, name) {
|
|
59
|
+
const match = params.find((param) => new RegExp(`^${name}_\\d+$`, "i").test(param));
|
|
60
|
+
return match ? Number(match.slice(2)) : void 0;
|
|
61
|
+
}
|
|
62
|
+
function dimensionsOf(params) {
|
|
63
|
+
return {
|
|
64
|
+
width: wixTransformDimension(params, "w"),
|
|
65
|
+
height: wixTransformDimension(params, "h")
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function wixMediaUrl(value, size = WIX_LIST_IMAGE) {
|
|
69
|
+
const reference = typeof value === "string" ? value.trim() : "";
|
|
70
|
+
if (!reference) return "";
|
|
71
|
+
const resolvedUrl = resolveWixMediaReference(reference);
|
|
72
|
+
if (!WEB_URL.test(resolvedUrl)) return "";
|
|
73
|
+
if (size === null) return resolvedUrl;
|
|
74
|
+
if (!WIX_MEDIA.test(resolvedUrl)) return resolvedUrl;
|
|
75
|
+
const base = resolvedUrl.split(/[?#]/)[0];
|
|
76
|
+
if (base.includes("/v1/")) return resizeWixTransform(resolvedUrl, size);
|
|
77
|
+
const suffix = resolvedUrl.slice(base.length);
|
|
78
|
+
return `${base}/v1/fit/${requestedParams(size).join(",")}/image.jpg${suffix}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ../../stdlib/wix-sdk/rich-content/src/display.ts
|
|
82
|
+
var HTTPS = /^https:\/\/[^\s/?#]\S*$/i;
|
|
83
|
+
var LINK = /^(https?:\/\/[^\s/?#]\S*|mailto:\S+|tel:\S+)$/i;
|
|
84
|
+
var HTTP_HOST = /^https?:\/\/([^\s/?#]+)/i;
|
|
85
|
+
var VIDEO_CARD_HOST = /^(?:(?:www\.|m\.)?youtube\.com|youtu\.be|(?:www\.|player\.)?vimeo\.com)$/;
|
|
86
|
+
function trimAscii(s) {
|
|
87
|
+
return s.replace(/^[\t\n\v\f\r ]+|[\t\n\v\f\r ]+$/g, "");
|
|
88
|
+
}
|
|
89
|
+
function normalizeMediaRef(s) {
|
|
90
|
+
return s.trim().replace(/^http:\/\/(static|video)\.wixstatic\.com\//i, (_all, sub) => `https://${sub.toLowerCase()}.wixstatic.com/`);
|
|
91
|
+
}
|
|
92
|
+
var hostOf = (url) => HTTP_HOST.exec(url)?.[1]?.toLowerCase().replace(/:\d+$/, "");
|
|
93
|
+
function cleanLink(url) {
|
|
94
|
+
if (typeof url !== "string") return void 0;
|
|
95
|
+
const t = trimAscii(url);
|
|
96
|
+
return LINK.test(t) ? t : void 0;
|
|
97
|
+
}
|
|
98
|
+
function ricosImageUrl(holder, width) {
|
|
99
|
+
const src = holder?.image?.src;
|
|
100
|
+
const fromUrl = typeof src?.url === "string" ? normalizeMediaRef(src.url) : "";
|
|
101
|
+
const ref = fromUrl !== "" ? fromUrl : typeof src?.id === "string" ? normalizeMediaRef(src.id) : src?.id;
|
|
102
|
+
const url = wixMediaUrl(ref, { width, height: width, quality: 85 });
|
|
103
|
+
return HTTPS.test(url) ? url : "";
|
|
104
|
+
}
|
|
105
|
+
function ricosVideoUrl(src) {
|
|
106
|
+
if (!src || typeof src !== "object") return "";
|
|
107
|
+
const { url, id } = src;
|
|
108
|
+
if (typeof url === "string" && url.trim() !== "") {
|
|
109
|
+
const link = cleanLink(url);
|
|
110
|
+
const linkHost = link === void 0 ? void 0 : hostOf(link);
|
|
111
|
+
if (link !== void 0 && linkHost !== void 0 && VIDEO_CARD_HOST.test(linkHost)) return link;
|
|
112
|
+
const media = normalizeMediaRef(url);
|
|
113
|
+
const mediaHost = hostOf(media);
|
|
114
|
+
return HTTPS.test(media) && !(mediaHost !== void 0 && VIDEO_CARD_HOST.test(mediaHost)) ? media : "";
|
|
115
|
+
}
|
|
116
|
+
const ref = typeof id === "string" ? id.trim().replace(/^video\//, "") : "";
|
|
117
|
+
if (/^\w[\w~.-]*$/.test(ref)) return `https://video.wixstatic.com/video/${ref}/file`;
|
|
118
|
+
if (/^\w[\w~.-]*\/[\w~./-]+$/.test(ref)) return `https://video.wixstatic.com/video/${ref}`;
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ../../stdlib/wix-sdk/rich-content/src/index.ts
|
|
123
|
+
var RICH_CONTENT_LIMITS = { maxBytes: 262144, maxNodes: 5e3, maxDepth: 16 };
|
|
124
|
+
var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
125
|
+
function parseRicosJson(value) {
|
|
126
|
+
let v = value;
|
|
127
|
+
if (typeof v === "string") {
|
|
128
|
+
if (v.trim() === "") return null;
|
|
129
|
+
try {
|
|
130
|
+
v = JSON.parse(v);
|
|
131
|
+
} catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return isObj(v) && Array.isArray(v.nodes) ? v : null;
|
|
136
|
+
}
|
|
137
|
+
function ricosToPlainText(doc) {
|
|
138
|
+
const kids = (v) => Array.isArray(v) ? v.filter(isObj) : [];
|
|
139
|
+
const inline = (node) => typeof node.textData?.text === "string" ? node.textData.text : kids(node.nodes).map(inline).join("");
|
|
140
|
+
const blocks = (nodes) => nodes.flatMap((node) => node.type === "PARAGRAPH" || node.type === "HEADING" || node.type === "TEXT" ? [inline(node)] : blocks(kids(node.nodes)));
|
|
141
|
+
return blocks(kids(doc?.nodes)).join("\n\n");
|
|
142
|
+
}
|
|
143
|
+
function plainTextToRicos(text) {
|
|
144
|
+
return { nodes: text.split("\n\n").map((t) => ({ type: "PARAGRAPH", nodes: [{ type: "TEXT", textData: { text: t, decorations: [] } }] })) };
|
|
145
|
+
}
|
|
146
|
+
var onlyKeys = (o, allowed) => Object.keys(o).every((k) => allowed.includes(k));
|
|
147
|
+
var emptyObject = (v) => v === void 0 || v === null || typeof v === "object" && Object.keys(v).length === 0;
|
|
148
|
+
function defaultParagraphData(pd) {
|
|
149
|
+
if (pd === void 0) return true;
|
|
150
|
+
if (!pd || typeof pd !== "object" || !onlyKeys(pd, ["textStyle", "indentation"])) return false;
|
|
151
|
+
const { textStyle, indentation } = pd;
|
|
152
|
+
if (indentation !== void 0 && indentation !== 0) return false;
|
|
153
|
+
if (textStyle === void 0) return true;
|
|
154
|
+
if (!textStyle || typeof textStyle !== "object" || !onlyKeys(textStyle, ["textAlignment"])) return false;
|
|
155
|
+
const align = textStyle.textAlignment;
|
|
156
|
+
return align === void 0 || align === "AUTO";
|
|
157
|
+
}
|
|
158
|
+
function plainRun(raw) {
|
|
159
|
+
if (!raw || typeof raw !== "object") return false;
|
|
160
|
+
const t = raw;
|
|
161
|
+
return t.type === "TEXT" && onlyKeys(t, ["type", "id", "textData", "nodes"]) && (t.nodes === void 0 || Array.isArray(t.nodes) && t.nodes.length === 0) && !(Array.isArray(t.textData?.decorations) && t.textData.decorations.length > 0);
|
|
162
|
+
}
|
|
163
|
+
function isPlainRicos(doc) {
|
|
164
|
+
if (doc === null || doc === void 0) return true;
|
|
165
|
+
if (typeof doc !== "object" || Array.isArray(doc)) return false;
|
|
166
|
+
if (!emptyObject(doc.documentStyle)) return false;
|
|
167
|
+
if (doc.nodes !== void 0 && !Array.isArray(doc.nodes)) return false;
|
|
168
|
+
const nodes = Array.isArray(doc.nodes) ? doc.nodes : [];
|
|
169
|
+
return nodes.every((raw) => {
|
|
170
|
+
if (!raw || typeof raw !== "object") return false;
|
|
171
|
+
const n = raw;
|
|
172
|
+
if (n.nodes !== void 0 && !Array.isArray(n.nodes)) return false;
|
|
173
|
+
return n.type === "PARAGRAPH" && onlyKeys(n, ["type", "id", "nodes", "paragraphData"]) && defaultParagraphData(n.paragraphData) && (Array.isArray(n.nodes) ? n.nodes : []).every(plainRun);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
var HTML_TAG = /<[a-z!/?]/i;
|
|
177
|
+
function htmlIsTrivial(html) {
|
|
178
|
+
const s = (html ?? "").trim();
|
|
179
|
+
return !s || !HTML_TAG.test(s) || /^<p>[^<>]*<\/p>$/.test(s);
|
|
180
|
+
}
|
|
181
|
+
function encodeRichContent(doc, opts = {}) {
|
|
182
|
+
if (doc === null || doc === void 0) return { json: "" };
|
|
183
|
+
if (!isObj(doc) || !Array.isArray(doc.nodes)) return { json: "", rejected: "not_a_document" };
|
|
184
|
+
const w = opts.imageWidth;
|
|
185
|
+
const imageWidth = typeof w === "number" && Number.isInteger(w) && w > 0 ? Math.min(w, WIX_DETAIL_IMAGE.width) : WIX_DETAIL_IMAGE.width;
|
|
186
|
+
const ctx = {
|
|
187
|
+
imageWidth,
|
|
188
|
+
// Gallery tiles and video posters are half-width at most, so the list budget caps them.
|
|
189
|
+
tileWidth: Math.min(imageWidth, WIX_LIST_IMAGE.width),
|
|
190
|
+
// Serialized nesting allowed: each node level is a node and its `nodes` array, plus generous room for type
|
|
191
|
+
// data. Past it the document is rejected rather than overflowing the worker's stack.
|
|
192
|
+
maxJsonDepth: RICH_CONTENT_LIMITS.maxDepth * 2 + 64,
|
|
193
|
+
ids: /* @__PURE__ */ new Set()
|
|
194
|
+
};
|
|
195
|
+
let nodes;
|
|
196
|
+
let json;
|
|
197
|
+
try {
|
|
198
|
+
nodes = cleanNodes(doc.nodes, "", 1, ctx, void 0);
|
|
199
|
+
if (nodes.length === 0) return { json: "" };
|
|
200
|
+
const out = { nodes };
|
|
201
|
+
if (doc.documentStyle !== void 0) out.documentStyle = doc.documentStyle;
|
|
202
|
+
if (doc.metadata !== void 0) out.metadata = doc.metadata;
|
|
203
|
+
json = canonicalJson(out, 0, ctx.maxJsonDepth);
|
|
204
|
+
} catch (e) {
|
|
205
|
+
if (e === TOO_DEEP) return { json: "", rejected: "too_deep" };
|
|
206
|
+
throw e;
|
|
207
|
+
}
|
|
208
|
+
if (utf8Length(json) > RICH_CONTENT_LIMITS.maxBytes) return { json: "", rejected: "too_large" };
|
|
209
|
+
if (countNodes(nodes) > RICH_CONTENT_LIMITS.maxNodes) return { json: "", rejected: "too_many_nodes" };
|
|
210
|
+
return { json };
|
|
211
|
+
}
|
|
212
|
+
var TOO_DEEP = { reason: "too_deep" };
|
|
213
|
+
var PATH_SHAPED = /^[0-9.]+$/;
|
|
214
|
+
var unusableId = (id) => PATH_SHAPED.test(id) || id.includes("/") || id.includes("$");
|
|
215
|
+
var isWrapper = (t) => t === "COLLAPSIBLE_LIST" || t === "COLLAPSIBLE_ITEM" || t === "COLLAPSIBLE_ITEM_TITLE" || t === "COLLAPSIBLE_ITEM_BODY";
|
|
216
|
+
var holdsBlocks = (t) => t === void 0 || t === "BULLETED_LIST" || t === "ORDERED_LIST" || t === "LIST_ITEM" || t === "BLOCKQUOTE" || isWrapper(t);
|
|
217
|
+
var LINK_FIELDS = {
|
|
218
|
+
EMBED: [["embedData", "oembed", "url"], ["embedData", "src"]],
|
|
219
|
+
HTML: [["htmlData", "url"]],
|
|
220
|
+
APP_EMBED: [["appEmbedData", "url"]],
|
|
221
|
+
LINK_PREVIEW: [["linkPreviewData", "link", "url"]],
|
|
222
|
+
FILE: [["fileData", "src", "url"]],
|
|
223
|
+
AUDIO: [["audioData", "audio", "src", "url"]],
|
|
224
|
+
GIF: [["gifData", "original", "gif"]],
|
|
225
|
+
IMAGE: [["imageData", "link", "url"]]
|
|
226
|
+
};
|
|
227
|
+
function rewriteAt(v, path, fix) {
|
|
228
|
+
if (!isObj(v) || !(path[0] in v)) return v;
|
|
229
|
+
const [k, ...rest] = path;
|
|
230
|
+
if (rest.length > 0) return { ...v, [k]: rewriteAt(v[k], rest, fix) };
|
|
231
|
+
const next = fix(v[k]);
|
|
232
|
+
if (next === v[k]) return v;
|
|
233
|
+
const { [k]: _old, ...kept } = v;
|
|
234
|
+
return next === void 0 ? kept : { ...kept, [k]: next };
|
|
235
|
+
}
|
|
236
|
+
function getAt(v, path) {
|
|
237
|
+
let cur = v;
|
|
238
|
+
for (const k of path) cur = isObj(cur) ? cur[k] : void 0;
|
|
239
|
+
return cur;
|
|
240
|
+
}
|
|
241
|
+
var drop = () => void 0;
|
|
242
|
+
var LINK_DECORATION_URL = ["linkData", "link", "url"];
|
|
243
|
+
var BUTTON_URL = ["link", "url"];
|
|
244
|
+
function cleanNodes(nodes, base, depth, ctx, parentType) {
|
|
245
|
+
const out = [];
|
|
246
|
+
for (const raw of nodes) {
|
|
247
|
+
if (!isObj(raw)) continue;
|
|
248
|
+
if (depth > RICH_CONTENT_LIMITS.maxDepth) throw TOO_DEEP;
|
|
249
|
+
const path = base === "" ? String(out.length) : `${base}.${out.length}`;
|
|
250
|
+
const node = cleanNode({ ...raw }, path, depth, ctx, parentType);
|
|
251
|
+
if (node) out.push(node);
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
function cleanNode(node, path, depth, ctx, parentType) {
|
|
256
|
+
if (node.type === "TEXT") {
|
|
257
|
+
const decorations = node.textData?.decorations;
|
|
258
|
+
if (Array.isArray(decorations)) {
|
|
259
|
+
const kept = decorations.flatMap((d) => {
|
|
260
|
+
if (!(isObj(d) && d.type === "LINK")) return [d];
|
|
261
|
+
const next = rewriteAt(d, LINK_DECORATION_URL, cleanLink);
|
|
262
|
+
return getAt(next, LINK_DECORATION_URL) === void 0 ? [] : [next];
|
|
263
|
+
});
|
|
264
|
+
node.textData = { ...node.textData, decorations: kept };
|
|
265
|
+
}
|
|
266
|
+
} else if (node.type === "IMAGE") {
|
|
267
|
+
const data = isObj(node.imageData) ? node.imageData : {};
|
|
268
|
+
const url = ricosImageUrl(data, ctx.imageWidth);
|
|
269
|
+
if (!url) return null;
|
|
270
|
+
node.imageData = { ...data, image: { ...isObj(data.image) ? data.image : {}, src: { url } } };
|
|
271
|
+
} else if (node.type === "GALLERY") {
|
|
272
|
+
const data = isObj(node.galleryData) ? node.galleryData : {};
|
|
273
|
+
const items = (Array.isArray(data.items) ? data.items : []).flatMap((item) => {
|
|
274
|
+
if (!isObj(item) || !isObj(item.image)) return [];
|
|
275
|
+
const media = isObj(item.image.media) ? item.image.media : {};
|
|
276
|
+
const url = ricosImageUrl({ image: media }, ctx.tileWidth);
|
|
277
|
+
return url ? [{ ...item, image: { ...item.image, media: { ...media, src: { url } } } }] : [];
|
|
278
|
+
});
|
|
279
|
+
if (items.length === 0) return null;
|
|
280
|
+
node.galleryData = { ...data, items };
|
|
281
|
+
} else if (node.type === "VIDEO") {
|
|
282
|
+
const data = isObj(node.videoData) ? { ...node.videoData } : {};
|
|
283
|
+
const video = isObj(data.video) ? data.video : {};
|
|
284
|
+
const url = ricosVideoUrl(video.src);
|
|
285
|
+
if (!url) return null;
|
|
286
|
+
data.video = { ...video, src: { url } };
|
|
287
|
+
const poster = ricosImageUrl({ image: data.thumbnail }, ctx.tileWidth);
|
|
288
|
+
if (poster) data.thumbnail = { ...data.thumbnail, src: { url: poster } };
|
|
289
|
+
else delete data.thumbnail;
|
|
290
|
+
node.videoData = data;
|
|
291
|
+
} else if (node.type === "BUTTON" || node.type === "LINK_BUTTON") {
|
|
292
|
+
node.buttonData = rewriteAt(node.buttonData, BUTTON_URL, cleanLink);
|
|
293
|
+
if (getAt(node.buttonData, BUTTON_URL) === void 0) return null;
|
|
294
|
+
} else if (node.type === "HTML") {
|
|
295
|
+
node.htmlData = rewriteAt(node.htmlData, ["html"], drop);
|
|
296
|
+
} else if (node.type === "EMBED") {
|
|
297
|
+
node.embedData = rewriteAt(node.embedData, ["oembed", "html"], drop);
|
|
298
|
+
}
|
|
299
|
+
for (const [field, ...rest] of (typeof node.type === "string" ? LINK_FIELDS[node.type] : void 0) ?? []) {
|
|
300
|
+
if (field in node) node[field] = rewriteAt(node[field], rest, cleanLink);
|
|
301
|
+
}
|
|
302
|
+
const inBlocks = holdsBlocks(parentType);
|
|
303
|
+
if (node.type !== "TEXT" || inBlocks) {
|
|
304
|
+
const own = typeof node.id === "string" ? node.id : "";
|
|
305
|
+
const usable = own !== "" && !unusableId(own);
|
|
306
|
+
if (inBlocks && !isWrapper(node.type)) {
|
|
307
|
+
if (usable && !ctx.ids.has(own)) ctx.ids.add(own);
|
|
308
|
+
else node.id = path;
|
|
309
|
+
} else if (!usable) node.id = path;
|
|
310
|
+
}
|
|
311
|
+
if (Array.isArray(node.nodes)) node.nodes = cleanNodes(node.nodes, path, depth + 1, ctx, typeof node.type === "string" ? node.type : "");
|
|
312
|
+
return node;
|
|
313
|
+
}
|
|
314
|
+
function countNodes(nodes) {
|
|
315
|
+
return nodes.reduce((n, node) => isObj(node) ? n + 1 + (Array.isArray(node.nodes) ? countNodes(node.nodes) : 0) : n, 0);
|
|
316
|
+
}
|
|
317
|
+
function canonicalJson(v, depth, max) {
|
|
318
|
+
if (depth > max) throw TOO_DEEP;
|
|
319
|
+
if (Array.isArray(v)) return `[${v.map((x) => x === void 0 ? "null" : canonicalJson(x, depth + 1, max)).join(",")}]`;
|
|
320
|
+
if (isObj(v)) return `{${Object.keys(v).sort().filter((k) => v[k] !== void 0).map((k) => `${JSON.stringify(k)}:${canonicalJson(v[k], depth + 1, max)}`).join(",")}}`;
|
|
321
|
+
return JSON.stringify(v) ?? "null";
|
|
322
|
+
}
|
|
323
|
+
function utf8Length(s) {
|
|
324
|
+
let bytes = 0;
|
|
325
|
+
for (let i = 0; i < s.length; i++) {
|
|
326
|
+
const c = s.charCodeAt(i);
|
|
327
|
+
if (c < 128) bytes += 1;
|
|
328
|
+
else if (c < 2048) bytes += 2;
|
|
329
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < s.length && s.charCodeAt(i + 1) >= 56320 && s.charCodeAt(i + 1) <= 57343) {
|
|
330
|
+
bytes += 4;
|
|
331
|
+
i++;
|
|
332
|
+
} else bytes += 3;
|
|
333
|
+
}
|
|
334
|
+
return bytes;
|
|
335
|
+
}
|
|
336
|
+
export {
|
|
337
|
+
RICH_CONTENT_LIMITS,
|
|
338
|
+
encodeRichContent,
|
|
339
|
+
htmlIsTrivial,
|
|
340
|
+
isPlainRicos,
|
|
341
|
+
parseRicosJson,
|
|
342
|
+
plainTextToRicos,
|
|
343
|
+
ricosToPlainText
|
|
344
|
+
};
|
|
345
|
+
//# sourceMappingURL=wix-rich-content.mjs.map
|
|
@@ -434,6 +434,10 @@
|
|
|
434
434
|
"types": "./dist/_types/stdlib/wix-sdk/reviews/src/index.d.ts",
|
|
435
435
|
"import": "./dist/wix-reviews.mjs"
|
|
436
436
|
},
|
|
437
|
+
"./wix-rich-content": {
|
|
438
|
+
"types": "./dist/_types/stdlib/wix-sdk/rich-content/src/index.d.ts",
|
|
439
|
+
"import": "./dist/wix-rich-content.mjs"
|
|
440
|
+
},
|
|
437
441
|
"./wix-seo": {
|
|
438
442
|
"types": "./dist/_types/stdlib/wix-sdk/seo-v1/src/index.d.ts",
|
|
439
443
|
"import": "./dist/wix-seo.mjs"
|