@maily-to/shared 2.0.0-beta.7 → 2.0.0-beta.9

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/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let stylecast = require("stylecast");
2
3
  //#region src/alignment.ts
3
4
  const TEXT_ALIGNMENTS = {
4
5
  LEFT: "left",
@@ -11,55 +12,149 @@ function isAllowedTextAlignment(value) {
11
12
  return typeof value === "string" && allowedTextAligns.includes(value);
12
13
  }
13
14
  //#endregion
14
- //#region src/field-mode.ts
15
- /**
16
- * Controls how multi-value fields (padding, margin, border) are edited.
17
- * "none" disables the field, "uniform" links all sides to one value,
18
- * "mixed" allows independent per-side values, "preset" uses predefined
19
- * size options (e.g. small/medium/large).
20
- */
21
- const FIELD_MODE = {
22
- NONE: "none",
23
- MIXED: "mixed",
24
- UNIFORM: "uniform",
25
- PRESET: "preset"
26
- };
27
- const allowedFieldModes = Object.values(FIELD_MODE);
28
- function isAllowedFieldMode(mode) {
29
- return typeof mode === "string" && allowedFieldModes.includes(mode);
30
- }
31
- //#endregion
32
15
  //#region src/border.ts
33
16
  const BORDER_STYLES = {
34
17
  SOLID: "solid",
35
18
  DASHED: "dashed",
36
19
  DOTTED: "dotted"
37
20
  };
21
+ const allowedBorderStyles = Object.freeze(Object.values(BORDER_STYLES));
38
22
  const DEFAULT_BORDER_STYLE = BORDER_STYLES.SOLID;
39
- const DEFAULT_BORDER_COLOR = "#000000";
23
+ function isAllowedBorderStyle(value) {
24
+ return typeof value === "string" && allowedBorderStyles.includes(value);
25
+ }
40
26
  /**
41
- * Converts a BorderStyleConfig into CSS properties for inline styles.
42
- * When all widths or radii are equal (or the mode is "uniform"), emits
43
- * shorthand CSS; otherwise emits per-side longhand properties.
27
+ * Reads the width, style and colour of a border from the `border` shorthand,
28
+ * letting any longhand already in the style win. The shorthand lists its
29
+ * parts in any order, so each is recognised by shape rather than position.
44
30
  */
45
- function getBorderStyle(config) {
46
- const { borderStyle = DEFAULT_BORDER_STYLE, borderColor = DEFAULT_BORDER_COLOR, borderWidthMode, borderTopWidth, borderRightWidth, borderBottomWidth, borderLeftWidth, borderRadiusMode, borderTopLeftRadius, borderTopRightRadius, borderBottomRightRadius, borderBottomLeftRadius } = config;
47
- const isBorderWidthUniform = borderWidthMode === FIELD_MODE.UNIFORM || borderLeftWidth === borderRightWidth && borderRightWidth === borderBottomWidth && borderBottomWidth === borderTopWidth;
48
- const isBorderRadiusUniform = borderRadiusMode === FIELD_MODE.UNIFORM || borderTopLeftRadius === borderTopRightRadius && borderTopRightRadius === borderBottomRightRadius && borderBottomRightRadius === borderBottomLeftRadius;
31
+ function getBorderParts(style) {
32
+ const parts = (style.border ?? "").trim().split(/\s+/).filter(Boolean);
33
+ let color;
34
+ let borderStyle;
35
+ let width;
36
+ for (const part of parts) if (isAllowedBorderStyle(part) || part === "none") borderStyle = part;
37
+ else if (/^[\d.]/.test(part)) width = part;
38
+ else color = part;
49
39
  return {
50
- ...isBorderWidthUniform ? { border: `${borderTopWidth}px ${borderStyle} ${borderColor}` } : {
51
- borderTopWidth: `${borderTopWidth}px`,
52
- borderRightWidth: `${borderRightWidth}px`,
53
- borderBottomWidth: `${borderBottomWidth}px`,
54
- borderLeftWidth: `${borderLeftWidth}px`,
55
- borderStyle,
56
- borderColor
57
- },
58
- ...isBorderRadiusUniform ? { borderRadius: `${borderTopLeftRadius}px` } : { borderRadius: `${borderTopLeftRadius}px ${borderTopRightRadius}px ${borderBottomRightRadius}px ${borderBottomLeftRadius}px` }
40
+ color: style.borderColor ?? color,
41
+ style: style.borderStyle ?? borderStyle,
42
+ width: style.borderWidth ?? width
59
43
  };
60
44
  }
61
45
  //#endregion
62
- //#region src/button-kind.ts
46
+ //#region src/box.ts
47
+ const BOX_SIDES = [
48
+ "top",
49
+ "right",
50
+ "bottom",
51
+ "left"
52
+ ];
53
+ const BOX_CORNERS = [
54
+ "topLeft",
55
+ "topRight",
56
+ "bottomRight",
57
+ "bottomLeft"
58
+ ];
59
+ function capitalize(value) {
60
+ return value.charAt(0).toUpperCase() + value.slice(1);
61
+ }
62
+ /**
63
+ * CSS box shorthands repeat their values when fewer than four are given:
64
+ * one applies to every edge, two to the vertical then horizontal pair, and
65
+ * three to top, the horizontal pair, then bottom.
66
+ */
67
+ function getShorthandEdges(shorthand) {
68
+ const parts = (shorthand ?? "").trim().split(/\s+/).filter(Boolean);
69
+ if (parts.length === 0) return null;
70
+ const [first, second = first, third = first, fourth = second] = parts;
71
+ return [
72
+ first,
73
+ second,
74
+ third,
75
+ fourth
76
+ ].map(toLength);
77
+ }
78
+ function toLength(value) {
79
+ const parsed = Number.parseFloat(value);
80
+ return Number.isNaN(parsed) ? 0 : parsed;
81
+ }
82
+ function getLonghand(style, property, edge, suffix) {
83
+ return style[`${property}${capitalize(edge)}${suffix}`];
84
+ }
85
+ function toShorthand(edges) {
86
+ const [first, second, third, fourth] = edges;
87
+ return (first === third && second === fourth ? first === second ? [first] : [first, second] : [
88
+ first,
89
+ second,
90
+ third,
91
+ fourth
92
+ ]).map((value) => `${value}px`).join(" ");
93
+ }
94
+ function getBoxSides(style, property) {
95
+ const [top, right, bottom, left] = getShorthandEdges(style[property]) ?? [
96
+ 0,
97
+ 0,
98
+ 0,
99
+ 0
100
+ ];
101
+ const sides = {
102
+ bottom,
103
+ left,
104
+ right,
105
+ top
106
+ };
107
+ for (const side of BOX_SIDES) {
108
+ const longhand = getLonghand(style, property, side, "");
109
+ if (longhand !== void 0) sides[side] = toLength(longhand);
110
+ }
111
+ return sides;
112
+ }
113
+ function toBoxSides(property, values) {
114
+ const declarations = { [property]: toShorthand([
115
+ values.top,
116
+ values.right,
117
+ values.bottom,
118
+ values.left
119
+ ]) };
120
+ for (const side of BOX_SIDES) declarations[`${property}${capitalize(side)}`] = null;
121
+ return declarations;
122
+ }
123
+ /**
124
+ * Radius shorthands run clockwise from the top-left corner, and repeat the
125
+ * same way box shorthands do.
126
+ */
127
+ function getBoxCorners(style, property) {
128
+ const [topLeft, topRight, bottomRight, bottomLeft] = getShorthandEdges(style[property]) ?? [
129
+ 0,
130
+ 0,
131
+ 0,
132
+ 0
133
+ ];
134
+ const corners = {
135
+ bottomLeft,
136
+ bottomRight,
137
+ topLeft,
138
+ topRight
139
+ };
140
+ for (const corner of BOX_CORNERS) {
141
+ const longhand = getLonghand(style, "border", corner, "Radius");
142
+ if (longhand !== void 0) corners[corner] = toLength(longhand);
143
+ }
144
+ return corners;
145
+ }
146
+ function toBoxCorners(property, values) {
147
+ const declarations = { [property]: toShorthand([
148
+ values.topLeft,
149
+ values.topRight,
150
+ values.bottomRight,
151
+ values.bottomLeft
152
+ ]) };
153
+ for (const corner of BOX_CORNERS) declarations[`border${capitalize(corner)}Radius`] = null;
154
+ return declarations;
155
+ }
156
+ //#endregion
157
+ //#region src/button.ts
63
158
  /**
64
159
  * Button layout kinds.
65
160
  * "tight" renders the button at its content width,
@@ -75,14 +170,49 @@ function isAllowedButtonKind(value) {
75
170
  return typeof value === "string" && allowedButtonKinds.includes(value);
76
171
  }
77
172
  //#endregion
173
+ //#region src/math.ts
174
+ function clamp(value, [min, max]) {
175
+ return Math.min(Math.max(value, min), max);
176
+ }
177
+ function percentage(portion, total) {
178
+ return clamp(portion / total * 100, [0, 100]);
179
+ }
180
+ function roundTo(value, decimals) {
181
+ const factor = 10 ** decimals;
182
+ return Math.round(value * factor) / factor;
183
+ }
184
+ function absoluteFromPercentage(percentage, total) {
185
+ return Math.round(total * percentage / 100);
186
+ }
187
+ //#endregion
188
+ //#region src/column.ts
189
+ const PERCENTAGE_PATTERN = /^(\d+(?:\.\d+)?)%$/;
190
+ const PIXEL_PATTERN = /^(\d+(?:\.\d+)?)px$/;
191
+ const CSS_LENGTH_PATTERN = /^\d+(?:\.\d+)?(?:px|pt|pc|in|cm|mm|em|rem|ex|ch|vw|vh|vmin|vmax)$/;
192
+ function getColumnWidth(value) {
193
+ const declaration = value?.trim();
194
+ if (!declaration) return null;
195
+ const percentage = PERCENTAGE_PATTERN.exec(declaration);
196
+ if (percentage) return Number(percentage[1]);
197
+ return CSS_LENGTH_PATTERN.test(declaration) ? declaration : null;
198
+ }
199
+ function getColumnWidthValue(width) {
200
+ return typeof width === "number" ? `${width}%` : width;
201
+ }
202
+ function getColumnWidthPercent(options) {
203
+ const { containerWidth, width } = options;
204
+ if (width === null || width === void 0) return null;
205
+ if (typeof width === "number") return width;
206
+ const percentage = PERCENTAGE_PATTERN.exec(width);
207
+ if (percentage) return Number(percentage[1]);
208
+ const pixels = PIXEL_PATTERN.exec(width);
209
+ if (pixels && containerWidth > 0) return roundTo(Number(pixels[1]) / containerWidth * 100, 3);
210
+ return null;
211
+ }
212
+ //#endregion
78
213
  //#region src/constants.ts
79
- /** HTML data attribute key used to identify node types in rendered output. */
80
214
  const DATA_NODE_TYPE_KEY = "data-node-type";
81
- /** HTML data attribute key used to store serialized visibility rules. */
82
- const DATA_VISIBILITY_RULE_KEY = "data-visibility-rule";
83
- /** Prefix prepended to all Maily error messages for easy identification. */
84
215
  const MAILY_ERROR_PREFIX = "[Maily Error]";
85
- /** URL for filing bug reports against the Maily repository. */
86
216
  const MAILY_BUG_REPORT_URL = "https://github.com/arikchakma/maily.to/issues/new";
87
217
  //#endregion
88
218
  //#region src/font.ts
@@ -103,14 +233,6 @@ const allowedFallbackFonts = [
103
233
  "cursive",
104
234
  "fantasy"
105
235
  ];
106
- const allowedFontFormats = [
107
- "woff",
108
- "woff2",
109
- "truetype",
110
- "opentype",
111
- "embedded-opentype",
112
- "svg"
113
- ];
114
236
  /**
115
237
  * Default font configuration: Inter with sans-serif fallback,
116
238
  * loaded from the Maily CDN as woff2.
@@ -119,19 +241,18 @@ const DEFAULT_FONT = {
119
241
  fallbackFontFamily: "sans-serif",
120
242
  fontFamily: "Inter",
121
243
  webFont: {
122
- url: "https://cdn.usemaily.com/fonts/v0/inter.woff2",
123
- format: "woff2"
244
+ format: "woff2",
245
+ url: "https://cdn.usemaily.com/fonts/v0/inter.woff2"
124
246
  }
125
247
  };
126
- /**
127
- * Injects a @font-face style element into the document head to load
128
- * the given font. Only works in browser environments.
129
- */
130
- function loadFont(font) {
131
- const style = getFontFaceStyle(font);
132
- const styleElement = document.createElement("style");
133
- styleElement.textContent = style;
134
- document.head.appendChild(styleElement);
248
+ function getFontFamilyNames(value) {
249
+ return value.split(",").map((font) => {
250
+ return font.trim().replace(/['"]/g, "");
251
+ }).filter(Boolean);
252
+ }
253
+ function getFontFamilyValue(options) {
254
+ const { fallbackFontFamily, fontFamily } = options;
255
+ return [fontFamily ? `'${fontFamily}'` : null, fallbackFontFamily].filter(Boolean).join(", ");
135
256
  }
136
257
  /**
137
258
  * Generates a @font-face CSS rule string for the given font configuration.
@@ -139,242 +260,17 @@ function loadFont(font) {
139
260
  * source URL when available.
140
261
  */
141
262
  function getFontFaceStyle(font) {
142
- const { fontFamily, fallbackFontFamily, webFont, fontWeight = 400, fontStyle = "normal" } = font;
263
+ const { fallbackFontFamily, fontFamily, fontStyle = "normal", fontWeight = 400, webFont } = font;
143
264
  return `@font-face {font-family: '${fontFamily}';font-style: ${fontStyle};font-weight: ${fontWeight};mso-font-alt: '${fallbackFontFamily}';${webFont ? `src: url(${webFont.url}) format('${webFont.format}');` : ""}}`;
144
265
  }
145
- //#endregion
146
- //#region src/css-variables.ts
147
- /**
148
- * Returns a CSS variable object for the given name and value.
149
- * If the value is nullish or empty, returns an empty object so that
150
- * the default CSS variable value is not overridden. Numbers are
151
- * automatically suffixed with "px".
152
- */
153
- function getVariableValue(name, value) {
154
- if (value === void 0 || value === null || value === "") return {};
155
- return { [name]: typeof value === "number" ? `${value}px` : value };
156
- }
157
- /**
158
- * Converts an EditorThemeOptions object into a flat map of Maily CSS
159
- * custom properties (--mly-*). Used to apply theme overrides as inline
160
- * styles on the editor or renderer root element. Covers body background,
161
- * container dimensions and borders, button colors, link color, and
162
- * font family settings.
163
- */
164
- function getMailyCssVariables(theme) {
165
- const font = theme.font || DEFAULT_FONT;
166
- return {
167
- ...getVariableValue("--mly-body-background-color", theme.body?.backgroundColor),
168
- ...getVariableValue("--mly-body-padding-top", theme.body?.paddingTop),
169
- ...getVariableValue("--mly-body-padding-right", theme.body?.paddingRight),
170
- ...getVariableValue("--mly-body-padding-bottom", theme.body?.paddingBottom),
171
- ...getVariableValue("--mly-body-padding-left", theme.body?.paddingLeft),
172
- ...getVariableValue("--mly-container-background-color", theme.container?.backgroundColor),
173
- ...getVariableValue("--mly-container-max-width", theme.container?.maxWidth),
174
- ...getVariableValue("--mly-container-min-width", theme.container?.minWidth),
175
- ...getVariableValue("--mly-container-padding-top", theme.container?.paddingTop),
176
- ...getVariableValue("--mly-container-padding-right", theme.container?.paddingRight),
177
- ...getVariableValue("--mly-container-padding-bottom", theme.container?.paddingBottom),
178
- ...getVariableValue("--mly-container-padding-left", theme.container?.paddingLeft),
179
- ...getVariableValue("--mly-container-border-radius", theme.container?.borderRadius),
180
- ...getVariableValue("--mly-container-border-width", theme.container?.borderWidth),
181
- ...getVariableValue("--mly-container-border-color", theme.container?.borderColor),
182
- ...getVariableValue("--mly-button-background-color", theme.button?.backgroundColor),
183
- ...getVariableValue("--mly-button-text-color", theme.button?.color),
184
- ...getVariableValue("--mly-button-padding-top", theme.button?.paddingTop),
185
- ...getVariableValue("--mly-button-padding-right", theme.button?.paddingRight),
186
- ...getVariableValue("--mly-button-padding-bottom", theme.button?.paddingBottom),
187
- ...getVariableValue("--mly-button-padding-left", theme.button?.paddingLeft),
188
- ...getVariableValue("--mly-link-color", theme.link?.color),
189
- ...getVariableValue("--mly-font-family", font.fontFamily),
190
- ...getVariableValue("--mly-font-fallback-family", font.fallbackFontFamily),
191
- "--mly-font": `var(--mly-font-family), var(--mly-font-fallback-family)`
192
- };
193
- }
194
- //#endregion
195
- //#region src/html-code-block.ts
196
- /**
197
- * Tab options for the HTML code block node.
198
- * "code" shows the raw HTML source, "preview" renders it visually.
199
- */
200
- const HTML_CODE_BLOCK_TABS = {
201
- CODE: "code",
202
- PREVIEW: "preview"
203
- };
204
- const DEFAULT_HTML_CODE_BLOCK_TAB = HTML_CODE_BLOCK_TABS.CODE;
205
- //#endregion
206
- //#region src/math.ts
207
- function clamp(value, [min, max]) {
208
- return Math.min(Math.max(value, min), max);
209
- }
210
- function percentage(portion, total) {
211
- return clamp(portion / total * 100, [0, 100]);
212
- }
213
- function absoluteFromPercentage(percentage, total) {
214
- return Math.round(total * percentage / 100);
215
- }
216
- function roundTo(value, decimals) {
217
- const factor = Math.pow(10, decimals);
218
- return Math.round(value * factor) / factor;
219
- }
220
- //#endregion
221
- //#region src/image-width.ts
222
- const MIN_IMAGE_WIDTH_PERCENTAGE = 5;
223
- const MAX_IMAGE_WIDTH_PERCENTAGE = 100;
224
- const MAX_IMAGE_WIDTH_PIXELS = 600;
225
- /**
226
- * Converts any ImageWidth value to a clamped percentage number.
227
- * Handles "auto" (→ 100), percentage strings (e.g. "50%" → 50),
228
- * and legacy pixel numbers (converted relative to maxWidthPixels).
229
- * Returns 100 for null or unrecognized values.
230
- */
231
- function parseWidthToPercentage(width, maxWidthPixels = MAX_IMAGE_WIDTH_PIXELS) {
232
- if (typeof width === "string") {
233
- if (width === "auto") return 100;
234
- return width.endsWith("%") ? clampImageWidthPercentage(parseInt(width)) : 100;
235
- }
236
- if (typeof width === "number") return clampImageWidthPercentage(Math.round(100 * width / maxWidthPixels));
237
- return 100;
238
- }
239
- function clampImageWidthPercentage(width) {
240
- return clamp(width, [5, 100]);
241
- }
242
- //#endregion
243
- //#region src/mark.ts
244
- /** Registry of all inline mark type strings used in the document JSON. */
245
- const MAILY_MARK_TYPES = {
246
- BOLD: "bold",
247
- ITALIC: "italic",
248
- STRIKE: "strike",
249
- UNDERLINE: "underline",
250
- LINK: "link",
251
- CODE: "code",
252
- TEXT_STYLE: "textStyle",
253
- HIGHLIGHT: "highlight"
254
- };
255
- const allowedMarkTypes = Object.values(MAILY_MARK_TYPES);
256
- //#endregion
257
- //#region src/node.ts
258
266
  /**
259
- * Registry of all document node type strings. These map 1:1 to
260
- * Tiptap extension names and are used as discriminators in the
261
- * document JSON.
262
- */
263
- const MAILY_NODE_TYPES = {
264
- DOCUMENT: "doc",
265
- PARAGRAPH: "paragraph",
266
- TEXT: "text",
267
- HEADING: "heading",
268
- VARIABLE: "variable",
269
- IMAGE: "image",
270
- SPACER: "spacer",
271
- SECTION: "section",
272
- COLUMNS: "columns",
273
- COLUMN: "column",
274
- BULLET_LIST: "bulletList",
275
- ORDERED_LIST: "orderedList",
276
- LIST_ITEM: "listItem",
277
- HORIZONTAL_RULE: "horizontalRule",
278
- BUTTON: "button",
279
- REPEAT: "repeat",
280
- HTML_CODE_BLOCK: "htmlCodeBlock",
281
- BLOCKQUOTE: "blockquote",
282
- HARD_BREAK: "hardBreak",
283
- FOOTER: "footer",
284
- INLINE_IMAGE: "inlineImage",
285
- LINK_CARD: "linkCard"
286
- };
287
- /**
288
- * Tiptap extension types that attach attributes to nodes but are
289
- * not document nodes themselves (e.g. fontStyle, visibility).
290
- */
291
- const MAILY_EXTENSION_TYPES = {
292
- FONT_STYLE: "fontStyle",
293
- VISIBILITY: "visibility"
294
- };
295
- const allowedNodeTypes = Object.values(MAILY_NODE_TYPES);
296
- //#endregion
297
- //#region src/is.ts
298
- function guard(type) {
299
- return (node) => node.type === type;
300
- }
301
- /**
302
- * Type guards for Maily nodes and marks. Provides narrowing functions
303
- * for every node type (is.paragraph, is.button, etc.) and mark type
304
- * (is.bold, is.link, etc.), plus structural checks like is.parent
305
- * and is.marked. Each guard narrows the input to its specific type.
306
- *
307
- * Example:
308
- * if (is.paragraph(node)) {
309
- * node.attrs.textAlign // narrowed to ParagraphNode
310
- * }
267
+ * Injects a @font-face style element into the document head to load
268
+ * the given font. Only works in browser environments.
311
269
  */
312
- const is = {
313
- any(value) {
314
- return this.node(value) || this.mark(value);
315
- },
316
- parent(node) {
317
- return Array.isArray(node?.content);
318
- },
319
- marked(node) {
320
- return Array.isArray(node?.marks);
321
- },
322
- node(node) {
323
- return typeof node === "object" && node !== null && "type" in node && allowedNodeTypes.includes(node.type);
324
- },
325
- doc: guard(MAILY_NODE_TYPES.DOCUMENT),
326
- paragraph: guard(MAILY_NODE_TYPES.PARAGRAPH),
327
- text: guard(MAILY_NODE_TYPES.TEXT),
328
- heading: guard(MAILY_NODE_TYPES.HEADING),
329
- variable: guard(MAILY_NODE_TYPES.VARIABLE),
330
- image: guard(MAILY_NODE_TYPES.IMAGE),
331
- inlineImage: guard(MAILY_NODE_TYPES.INLINE_IMAGE),
332
- spacer: guard(MAILY_NODE_TYPES.SPACER),
333
- section: guard(MAILY_NODE_TYPES.SECTION),
334
- button: guard(MAILY_NODE_TYPES.BUTTON),
335
- columns: guard(MAILY_NODE_TYPES.COLUMNS),
336
- column: guard(MAILY_NODE_TYPES.COLUMN),
337
- repeat: guard(MAILY_NODE_TYPES.REPEAT),
338
- bulletList: guard(MAILY_NODE_TYPES.BULLET_LIST),
339
- orderedList: guard(MAILY_NODE_TYPES.ORDERED_LIST),
340
- listItem: guard(MAILY_NODE_TYPES.LIST_ITEM),
341
- horizontalRule: guard(MAILY_NODE_TYPES.HORIZONTAL_RULE),
342
- htmlCodeBlock: guard(MAILY_NODE_TYPES.HTML_CODE_BLOCK),
343
- blockquote: guard(MAILY_NODE_TYPES.BLOCKQUOTE),
344
- hardBreak: guard(MAILY_NODE_TYPES.HARD_BREAK),
345
- footer: guard(MAILY_NODE_TYPES.FOOTER),
346
- linkCard: guard(MAILY_NODE_TYPES.LINK_CARD),
347
- mark(mark) {
348
- return typeof mark === "object" && mark !== null && "type" in mark && allowedMarkTypes.includes(mark.type);
349
- },
350
- bold: guard(MAILY_MARK_TYPES.BOLD),
351
- italic: guard(MAILY_MARK_TYPES.ITALIC),
352
- strike: guard(MAILY_MARK_TYPES.STRIKE),
353
- underline: guard(MAILY_MARK_TYPES.UNDERLINE),
354
- link: guard(MAILY_MARK_TYPES.LINK),
355
- code: guard(MAILY_MARK_TYPES.CODE),
356
- textStyle: guard(MAILY_MARK_TYPES.TEXT_STYLE),
357
- highlight: guard(MAILY_MARK_TYPES.HIGHLIGHT)
358
- };
359
- /** Type guard that checks if a value is defined (not null or undefined). */
360
- function isDef(val) {
361
- return val !== void 0 && val !== null;
362
- }
363
- /** Type guard that checks if a value is a boolean. */
364
- function isBoolean(val) {
365
- return typeof val === "boolean";
366
- }
367
- /** Type guard that checks if a value is a number. */
368
- function isNumber(val) {
369
- return typeof val === "number";
370
- }
371
- /** Type guard that checks if a value is a string. */
372
- function isString(val) {
373
- return typeof val === "string";
374
- }
375
- /** Type guard that checks if a value is a non-null object. */
376
- function isObject(val) {
377
- return typeof val === "object" && val !== null;
270
+ function loadFont(font) {
271
+ const styleElement = document.createElement("style");
272
+ styleElement.textContent = getFontFaceStyle(font);
273
+ document.head.appendChild(styleElement);
378
274
  }
379
275
  //#endregion
380
276
  //#region src/font-style.ts
@@ -386,57 +282,57 @@ const DEFAULT_FONT_FAMILIES = [
386
282
  {
387
283
  fontFamily: "Inter",
388
284
  webFont: {
389
- url: "https://cdn.usemaily.com/fonts/v0/inter.woff2",
390
- format: "woff2"
285
+ format: "woff2",
286
+ url: "https://cdn.usemaily.com/fonts/v0/inter.woff2"
391
287
  }
392
288
  },
393
289
  {
394
290
  fontFamily: "Roboto",
395
291
  webFont: {
396
- url: "https://cdn.usemaily.com/fonts/v0/roboto.woff2",
397
- format: "woff2"
292
+ format: "woff2",
293
+ url: "https://cdn.usemaily.com/fonts/v0/roboto.woff2"
398
294
  }
399
295
  },
400
296
  {
401
297
  fontFamily: "Open Sans",
402
298
  webFont: {
403
- url: "https://cdn.usemaily.com/fonts/v0/open-sans.woff2",
404
- format: "woff2"
299
+ format: "woff2",
300
+ url: "https://cdn.usemaily.com/fonts/v0/open-sans.woff2"
405
301
  }
406
302
  },
407
303
  {
408
304
  fontFamily: "Lato",
409
305
  webFont: {
410
- url: "https://cdn.usemaily.com/fonts/v0/lato.woff2",
411
- format: "woff2"
306
+ format: "woff2",
307
+ url: "https://cdn.usemaily.com/fonts/v0/lato.woff2"
412
308
  }
413
309
  },
414
310
  {
415
311
  fontFamily: "Montserrat",
416
312
  webFont: {
417
- url: "https://cdn.usemaily.com/fonts/v0/montserrat.woff2",
418
- format: "woff2"
313
+ format: "woff2",
314
+ url: "https://cdn.usemaily.com/fonts/v0/montserrat.woff2"
419
315
  }
420
316
  },
421
317
  {
422
318
  fontFamily: "Poppins",
423
319
  webFont: {
424
- url: "https://cdn.usemaily.com/fonts/v0/poppins.woff2",
425
- format: "woff2"
320
+ format: "woff2",
321
+ url: "https://cdn.usemaily.com/fonts/v0/poppins.woff2"
426
322
  }
427
323
  },
428
324
  {
429
325
  fontFamily: "Raleway",
430
326
  webFont: {
431
- url: "https://cdn.usemaily.com/fonts/v0/raleway.woff2",
432
- format: "woff2"
327
+ format: "woff2",
328
+ url: "https://cdn.usemaily.com/fonts/v0/raleway.woff2"
433
329
  }
434
330
  },
435
331
  {
436
332
  fontFamily: "Ubuntu",
437
333
  webFont: {
438
- url: "https://cdn.usemaily.com/fonts/v0/ubuntu.woff2",
439
- format: "woff2"
334
+ format: "woff2",
335
+ url: "https://cdn.usemaily.com/fonts/v0/ubuntu.woff2"
440
336
  }
441
337
  },
442
338
  { fontFamily: "Arial" },
@@ -451,7 +347,6 @@ const FONT_STYLES = {
451
347
  NORMAL: "normal",
452
348
  ITALIC: "italic"
453
349
  };
454
- /** Preset options for the font size dropdown in the editor. */
455
350
  const FONT_SIZE_PRESETS = [
456
351
  {
457
352
  value: 12,
@@ -478,7 +373,6 @@ const FONT_SIZE_PRESETS = [
478
373
  label: "2XL"
479
374
  }
480
375
  ];
481
- /** Preset options for the line height dropdown in the editor. */
482
376
  const LINE_HEIGHT_PRESETS = [
483
377
  {
484
378
  value: 1,
@@ -502,30 +396,7 @@ const LINE_HEIGHT_PRESETS = [
502
396
  }
503
397
  ];
504
398
  const DEFAULT_FONT_FAMILY = "Inter";
505
- const DEFAULT_FONT_SIZE = 15;
506
- const DEFAULT_FONT_WEIGHT = 400;
507
- const DEFAULT_LINE_HEIGHT = 1.75;
508
399
  const DEFAULT_FONT_FALLBACK = "sans-serif";
509
- /**
510
- * Builds a CSS properties object from a node's font attributes,
511
- * falling back to the provided defaults for any null values.
512
- * Only includes properties that have a resolved value.
513
- */
514
- function getFontStyle(attrs, defaults) {
515
- const { fontFamily, fontFallback, fontSize, fontWeight, lineHeight, fontStyle } = attrs;
516
- const size = fontSize ?? defaults?.fontSize;
517
- const weight = fontWeight ?? defaults?.fontWeight;
518
- const line = lineHeight ?? defaults?.lineHeight;
519
- const style = fontStyle ?? defaults?.fontStyle;
520
- const fontFamilyParts = [fontFamily, fontFallback].filter(Boolean);
521
- return {
522
- ...fontFamilyParts.length > 0 && { fontFamily: fontFamilyParts.join(", ") },
523
- ...isDef(size) ? { fontSize: `${size}px` } : {},
524
- ...isDef(weight) ? { fontWeight: weight } : {},
525
- ...isDef(line) ? { lineHeight: line } : {},
526
- ...isDef(style) ? { fontStyle: style } : {}
527
- };
528
- }
529
400
  //#endregion
530
401
  //#region src/font-weight.ts
531
402
  /**
@@ -541,9 +412,42 @@ const FONT_WEIGHTS = {
541
412
  };
542
413
  //#endregion
543
414
  //#region src/function.ts
544
- /** A no-operation function. Useful as a default callback or placeholder. */
545
415
  function noop() {}
546
416
  //#endregion
417
+ //#region src/html-code-block.ts
418
+ /**
419
+ * Tab options for the HTML code block node.
420
+ * "code" shows the raw HTML source, "preview" renders it visually.
421
+ */
422
+ const HTML_CODE_BLOCK_TABS = {
423
+ CODE: "code",
424
+ PREVIEW: "preview"
425
+ };
426
+ const DEFAULT_HTML_CODE_BLOCK_TAB = HTML_CODE_BLOCK_TABS.CODE;
427
+ //#endregion
428
+ //#region src/image.ts
429
+ const MIN_IMAGE_WIDTH_PERCENTAGE = 5;
430
+ const MAX_IMAGE_WIDTH_PERCENTAGE = 100;
431
+ const DEFAULT_CONTAINER_WIDTH_PIXELS = 600;
432
+ const PIXEL_SUFFIX = "px";
433
+ function getPixels(value) {
434
+ const length = value.endsWith(PIXEL_SUFFIX) ? value.slice(0, -2) : value;
435
+ if (length === "") return null;
436
+ const pixels = Number(length);
437
+ return Number.isFinite(pixels) ? pixels : null;
438
+ }
439
+ function parseWidthToPercentage(width, containerWidthPixels = 600) {
440
+ if (width === null || width === void 0 || width === "auto") return 100;
441
+ const value = String(width).trim();
442
+ if (value.endsWith("%")) return clampImageWidthPercentage(Number.parseFloat(value));
443
+ const pixels = getPixels(value);
444
+ if (pixels === null) return 100;
445
+ return clampImageWidthPercentage(Math.round(100 * pixels / containerWidthPixels));
446
+ }
447
+ function clampImageWidthPercentage(width) {
448
+ return clamp(width, [5, 100]);
449
+ }
450
+ //#endregion
547
451
  //#region src/invariant.ts
548
452
  function invariant(value, message) {
549
453
  if (value === false || value === null || typeof value === "undefined") {
@@ -553,25 +457,131 @@ Please open an issue! ${MAILY_BUG_REPORT_URL}`);
553
457
  }
554
458
  }
555
459
  //#endregion
556
- //#region src/margin.ts
557
- /**
558
- * Converts a MarginStyleConfig into CSS properties for inline styles.
559
- * When all sides are equal (or mode is "uniform"), emits shorthand CSS;
560
- * otherwise emits per-side longhand properties.
561
- */
562
- function getMarginStyle(config) {
563
- const { marginMode, marginTop, marginRight, marginBottom, marginLeft } = config;
564
- if (marginMode === FIELD_MODE.UNIFORM || marginLeft === marginRight && marginRight === marginBottom && marginBottom === marginTop) return { margin: `${marginTop}px` };
565
- return {
566
- marginTop: `${marginTop}px`,
567
- marginRight: `${marginRight}px`,
568
- marginBottom: `${marginBottom}px`,
569
- marginLeft: `${marginLeft}px`
570
- };
460
+ //#region src/mark.ts
461
+ const MAILY_MARK_TYPES = {
462
+ BOLD: "bold",
463
+ ITALIC: "italic",
464
+ STRIKE: "strike",
465
+ UNDERLINE: "underline",
466
+ LINK: "link",
467
+ CODE: "code",
468
+ TEXT_STYLE: "textStyle",
469
+ HIGHLIGHT: "highlight",
470
+ SPAN: "span"
471
+ };
472
+ const allowedMarkTypes = Object.values(MAILY_MARK_TYPES);
473
+ //#endregion
474
+ //#region src/node.ts
475
+ const MAILY_NODE_TYPES = {
476
+ DOCUMENT: "doc",
477
+ BODY: "body",
478
+ CONTAINER: "container",
479
+ SECTION: "section",
480
+ COLUMNS: "columns",
481
+ COLUMN: "column",
482
+ IMAGE: "image",
483
+ INLINE_IMAGE: "inlineImage",
484
+ INLINE_SPAN: "inlineSpan",
485
+ SPACER: "spacer",
486
+ BUTTON: "button",
487
+ FOOTER: "footer",
488
+ PARAGRAPH: "paragraph",
489
+ HEADING: "heading",
490
+ BLOCKQUOTE: "blockquote",
491
+ HORIZONTAL_RULE: "horizontalRule",
492
+ HTML_CODE_BLOCK: "htmlCodeBlock",
493
+ REPEAT: "repeat",
494
+ HARD_BREAK: "hardBreak",
495
+ BULLET_LIST: "bulletList",
496
+ ORDERED_LIST: "orderedList",
497
+ LIST_ITEM: "listItem",
498
+ TEXT: "text",
499
+ VARIABLE: "variable",
500
+ TABLE: "table",
501
+ TABLE_ROW: "tableRow",
502
+ TABLE_CELL: "tableCell",
503
+ TABLE_HEADER: "tableHeader",
504
+ LINK_CARD: "linkCard"
505
+ };
506
+ const MAILY_EXTENSION_TYPES = {
507
+ STYLE: "style",
508
+ THEME: "theme",
509
+ VISIBILITY: "visibility"
510
+ };
511
+ const allowedNodeTypes = Object.values(MAILY_NODE_TYPES);
512
+ const DEFAULT_VARIABLE_ATTRIBUTES = {
513
+ fallback: null,
514
+ isDefaultEditable: true,
515
+ label: null,
516
+ required: true,
517
+ style: null
518
+ };
519
+ //#endregion
520
+ //#region src/is.ts
521
+ function guard(type) {
522
+ return (value) => value.type === type;
523
+ }
524
+ function isObject(val) {
525
+ return typeof val === "object" && val !== null;
526
+ }
527
+ const is = {
528
+ node(value) {
529
+ return typeof value === "object" && value !== null && "type" in value && allowedNodeTypes.includes(value.type);
530
+ },
531
+ mark(value) {
532
+ return typeof value === "object" && value !== null && "type" in value && allowedMarkTypes.includes(value.type);
533
+ },
534
+ parent(node) {
535
+ return Array.isArray(node?.content);
536
+ },
537
+ marked(node) {
538
+ return Array.isArray(node?.marks);
539
+ },
540
+ doc: guard(MAILY_NODE_TYPES.DOCUMENT),
541
+ body: guard(MAILY_NODE_TYPES.BODY),
542
+ container: guard(MAILY_NODE_TYPES.CONTAINER),
543
+ section: guard(MAILY_NODE_TYPES.SECTION),
544
+ columns: guard(MAILY_NODE_TYPES.COLUMNS),
545
+ column: guard(MAILY_NODE_TYPES.COLUMN),
546
+ image: guard(MAILY_NODE_TYPES.IMAGE),
547
+ inlineImage: guard(MAILY_NODE_TYPES.INLINE_IMAGE),
548
+ inlineSpan: guard(MAILY_NODE_TYPES.INLINE_SPAN),
549
+ spacer: guard(MAILY_NODE_TYPES.SPACER),
550
+ button: guard(MAILY_NODE_TYPES.BUTTON),
551
+ footer: guard(MAILY_NODE_TYPES.FOOTER),
552
+ paragraph: guard(MAILY_NODE_TYPES.PARAGRAPH),
553
+ heading: guard(MAILY_NODE_TYPES.HEADING),
554
+ blockquote: guard(MAILY_NODE_TYPES.BLOCKQUOTE),
555
+ horizontalRule: guard(MAILY_NODE_TYPES.HORIZONTAL_RULE),
556
+ hardBreak: guard(MAILY_NODE_TYPES.HARD_BREAK),
557
+ htmlCodeBlock: guard(MAILY_NODE_TYPES.HTML_CODE_BLOCK),
558
+ repeat: guard(MAILY_NODE_TYPES.REPEAT),
559
+ bulletList: guard(MAILY_NODE_TYPES.BULLET_LIST),
560
+ orderedList: guard(MAILY_NODE_TYPES.ORDERED_LIST),
561
+ listItem: guard(MAILY_NODE_TYPES.LIST_ITEM),
562
+ linkCard: guard(MAILY_NODE_TYPES.LINK_CARD),
563
+ text: guard(MAILY_NODE_TYPES.TEXT),
564
+ variable: guard(MAILY_NODE_TYPES.VARIABLE),
565
+ table: guard(MAILY_NODE_TYPES.TABLE),
566
+ tableRow: guard(MAILY_NODE_TYPES.TABLE_ROW),
567
+ tableCell: guard(MAILY_NODE_TYPES.TABLE_CELL),
568
+ tableHeader: guard(MAILY_NODE_TYPES.TABLE_HEADER),
569
+ bold: guard(MAILY_MARK_TYPES.BOLD),
570
+ italic: guard(MAILY_MARK_TYPES.ITALIC),
571
+ strike: guard(MAILY_MARK_TYPES.STRIKE),
572
+ underline: guard(MAILY_MARK_TYPES.UNDERLINE),
573
+ link: guard(MAILY_MARK_TYPES.LINK),
574
+ code: guard(MAILY_MARK_TYPES.CODE),
575
+ textStyle: guard(MAILY_MARK_TYPES.TEXT_STYLE),
576
+ highlight: guard(MAILY_MARK_TYPES.HIGHLIGHT),
577
+ span: guard(MAILY_MARK_TYPES.SPAN)
578
+ };
579
+ function isDef(value) {
580
+ return value !== void 0 && value !== null;
571
581
  }
572
582
  //#endregion
573
583
  //#region src/object.ts
574
- function isMergableObject(value) {
584
+ function isMergeableObject(value) {
575
585
  return value !== null && typeof value === "object" && !Array.isArray(value);
576
586
  }
577
587
  /**
@@ -585,332 +595,255 @@ function isMergableObject(value) {
585
595
  */
586
596
  function deepMerge(target, ...sources) {
587
597
  const result = { ...target };
588
- for (const source of sources) for (const [key, value] of Object.entries(source)) result[key] = isMergableObject(value) && isMergableObject(result[key]) ? {
598
+ for (const source of sources) for (const [key, value] of Object.entries(source)) result[key] = isMergeableObject(value) && isMergeableObject(result[key]) ? {
589
599
  ...result[key],
590
600
  ...value
591
601
  } : value;
592
602
  return result;
593
603
  }
594
- function isObjectDeepEqual(first, second) {
595
- if (first === second) return true;
596
- for (const key of Object.keys(first)) if (first[key] !== second[key]) return false;
597
- return true;
598
- }
599
604
  //#endregion
600
- //#region src/padding.ts
601
- /**
602
- * Converts a PaddingStyleConfig into CSS properties for inline styles.
603
- * When all sides are equal (or mode is "uniform"), emits shorthand CSS;
604
- * otherwise emits per-side longhand properties.
605
- */
606
- function getPaddingStyle(config) {
607
- const { paddingMode, paddingTop, paddingRight, paddingBottom, paddingLeft } = config;
608
- if (paddingMode === FIELD_MODE.UNIFORM || paddingLeft === paddingRight && paddingRight === paddingBottom && paddingBottom === paddingTop) return { padding: `${paddingTop}px` };
605
+ //#region src/spacing.ts
606
+ const BLOCK_CONTAINER_TYPES = [
607
+ MAILY_NODE_TYPES.DOCUMENT,
608
+ MAILY_NODE_TYPES.BODY,
609
+ MAILY_NODE_TYPES.CONTAINER,
610
+ MAILY_NODE_TYPES.SECTION,
611
+ MAILY_NODE_TYPES.COLUMN,
612
+ MAILY_NODE_TYPES.REPEAT,
613
+ MAILY_NODE_TYPES.BULLET_LIST,
614
+ MAILY_NODE_TYPES.ORDERED_LIST
615
+ ];
616
+ const MARGIN_TOP_ABSORBER_TYPES = [MAILY_NODE_TYPES.SPACER];
617
+ const MARGIN_BOTTOM_ABSORBER_TYPES = [MAILY_NODE_TYPES.SPACER, MAILY_NODE_TYPES.HORIZONTAL_RULE];
618
+ function getSuppressedMargins(position) {
619
+ const { isFirst, isLast, nextType, parentType, previousType } = position;
620
+ const stacks = parentType !== void 0 && BLOCK_CONTAINER_TYPES.includes(parentType);
609
621
  return {
610
- paddingTop: `${paddingTop}px`,
611
- paddingRight: `${paddingRight}px`,
612
- paddingBottom: `${paddingBottom}px`,
613
- paddingLeft: `${paddingLeft}px`
622
+ marginBottom: !stacks || isLast || MARGIN_BOTTOM_ABSORBER_TYPES.includes(nextType ?? ""),
623
+ marginTop: !stacks || isFirst || MARGIN_TOP_ABSORBER_TYPES.includes(previousType ?? "")
614
624
  };
615
625
  }
616
626
  //#endregion
617
- //#region src/promise.ts
618
- /** Returns a promise that resolves after the given number of milliseconds. */
619
- function sleep(ms) {
620
- return new Promise((resolve) => setTimeout(resolve, ms));
627
+ //#region src/style.ts
628
+ function parseInlineStyles(style) {
629
+ return (0, stylecast.objectify)(style, { reactify: true });
630
+ }
631
+ function stringifyInlineStyles(style) {
632
+ return (0, stylecast.stringify)(style, { kebabCase: true });
633
+ }
634
+ function expandInlineStyles(style) {
635
+ return (0, stylecast.expand)(style, { camelCase: true });
636
+ }
637
+ function collapseInlineStyles(style) {
638
+ return (0, stylecast.collapse)(style, { camelCase: true });
639
+ }
640
+ function mergeInlineStyles(under, over) {
641
+ return collapseInlineStyles({
642
+ ...expandInlineStyles(under),
643
+ ...expandInlineStyles(over)
644
+ });
621
645
  }
622
646
  //#endregion
623
- //#region src/text-direction.ts
624
- /** Text direction values matching the HTML `dir` attribute: ltr, rtl, auto. */
647
+ //#region src/direction.ts
625
648
  const TEXT_DIRECTIONS = {
626
649
  LTR: "ltr",
627
650
  RTL: "rtl",
628
651
  AUTO: "auto"
629
652
  };
630
- const allowedTextDirections = Object.freeze(Object.values(TEXT_DIRECTIONS));
631
653
  const DEFAULT_TEXT_DIRECTION = TEXT_DIRECTIONS.AUTO;
632
- function isAllowedTextDirection(value) {
633
- return typeof value === "string" && allowedTextDirections.includes(value);
634
- }
635
- /**
636
- * Returns a CSS `direction` property object for the given dir value.
637
- * Returns an empty object for "auto" or nullish values, since the
638
- * browser default is sufficient in those cases.
639
- */
640
654
  function getCssDirection(dir) {
641
655
  if (dir && dir !== TEXT_DIRECTIONS.AUTO) return { direction: dir };
642
656
  return {};
643
657
  }
644
658
  //#endregion
645
- //#region src/theme.ts
646
- const DEFAULT_LINK_TEXT_COLOR = "#111827";
647
- const DEFAULT_RENDERER_THEME = {
648
- paragraph: {
649
- color: "#374151",
650
- fontSize: 15,
651
- lineHeight: 1.75,
652
- fontWeight: FONT_WEIGHTS.NORMAL
653
- },
654
- heading: {
655
- defaults: { color: "#111827" },
656
- h1: {
657
- fontSize: 36,
658
- lineHeight: 1.1111111,
659
- fontWeight: FONT_WEIGHTS.SEMIBOLD
660
- },
661
- h2: {
662
- fontSize: 30,
663
- lineHeight: 1.3333333,
664
- fontWeight: FONT_WEIGHTS.SEMIBOLD
665
- },
666
- h3: {
667
- fontSize: 24,
668
- lineHeight: 1.6,
669
- fontWeight: FONT_WEIGHTS.SEMIBOLD
670
- }
671
- },
672
- footer: {
673
- color: "#64748B",
674
- fontSize: 14,
675
- lineHeight: 1.7142857,
676
- fontWeight: FONT_WEIGHTS.NORMAL
677
- },
678
- blockquote: {
679
- color: "#374151",
680
- borderColor: "#D1D5DB",
681
- fontSize: 15,
682
- lineHeight: 1.75,
683
- fontWeight: FONT_WEIGHTS.MEDIUM,
684
- fontStyle: FONT_STYLES.ITALIC
685
- },
686
- horizontalRule: { color: "#EAEAEA" },
687
- code: {
688
- color: "#111827",
689
- backgroundColor: "#EFEFEF"
690
- },
691
- linkCard: {
692
- titleColor: "#111827",
693
- descriptionColor: "#374151",
694
- badgeTextColor: "#374151",
695
- badgeBackgroundColor: "#fff085",
696
- subTitleColor: "#6B7280",
697
- borderColor: "#E5E7EB"
698
- },
699
- container: {
700
- backgroundColor: "#ffffff",
701
- maxWidth: 600,
702
- minWidth: 300,
703
- paddingTop: 8,
704
- paddingRight: 8,
705
- paddingBottom: 8,
706
- paddingLeft: 8,
707
- borderRadius: 0,
708
- borderWidth: 0,
709
- borderColor: "transparent"
710
- },
711
- body: {
712
- backgroundColor: "#ffffff",
713
- paddingTop: 0,
714
- paddingRight: 0,
715
- paddingBottom: 0,
716
- paddingLeft: 0
717
- },
718
- button: {
719
- backgroundColor: "#000000",
720
- color: "#ffffff",
721
- paddingTop: 10,
722
- paddingRight: 32,
723
- paddingBottom: 10,
724
- paddingLeft: 32,
725
- fontSize: 14,
726
- lineHeight: 1.4285714,
727
- fontWeight: FONT_WEIGHTS.SEMIBOLD
728
- },
729
- link: { color: DEFAULT_LINK_TEXT_COLOR },
730
- listMarker: { color: "#d1d5dc" },
731
- font: DEFAULT_FONT
732
- };
733
- const DEFAULT_EDITOR_THEME = {
734
- container: {
735
- backgroundColor: "#ffffff",
736
- maxWidth: 600,
737
- minWidth: 300,
738
- paddingTop: 8,
739
- paddingRight: 8,
740
- paddingBottom: 8,
741
- paddingLeft: 8,
742
- borderRadius: 0,
743
- borderWidth: 0,
744
- borderColor: "transparent"
745
- },
746
- body: {
747
- backgroundColor: "#ffffff",
748
- paddingTop: 0,
749
- paddingRight: 0,
750
- paddingBottom: 0,
751
- paddingLeft: 0
752
- },
753
- button: {
754
- backgroundColor: "#000000",
755
- color: "#ffffff",
756
- paddingTop: 10,
757
- paddingRight: 32,
758
- paddingBottom: 10,
759
- paddingLeft: 32
760
- },
761
- link: { color: DEFAULT_LINK_TEXT_COLOR },
762
- font: DEFAULT_FONT
763
- };
764
- /**
765
- * Resolves the baseline font defaults for a node type from the
766
- * renderer theme. Falls back to paragraph defaults for unknown types.
767
- */
768
- function getNodeFontStyleDefaults(nodeType, level) {
769
- const paragraph = DEFAULT_RENDERER_THEME.paragraph;
770
- const fallback = {
771
- fontSize: paragraph.fontSize,
772
- lineHeight: paragraph.lineHeight,
773
- fontWeight: paragraph.fontWeight
774
- };
775
- if (nodeType === MAILY_NODE_TYPES.HEADING) {
776
- const heading = DEFAULT_RENDERER_THEME.heading;
777
- const key = `h${level ?? 1}`;
778
- const entry = heading?.[key];
779
- return {
780
- fontSize: entry?.fontSize ?? fallback.fontSize,
781
- lineHeight: entry?.lineHeight ?? fallback.lineHeight,
782
- fontWeight: entry?.fontWeight ?? fallback.fontWeight
783
- };
784
- }
785
- if (nodeType === MAILY_NODE_TYPES.BUTTON) {
786
- const btn = DEFAULT_RENDERER_THEME.button;
787
- return {
788
- fontSize: btn?.fontSize ?? fallback.fontSize,
789
- lineHeight: btn?.lineHeight ?? fallback.lineHeight,
790
- fontWeight: btn?.fontWeight ?? fallback.fontWeight
791
- };
792
- }
793
- if (nodeType === MAILY_NODE_TYPES.BLOCKQUOTE) {
794
- const bq = DEFAULT_RENDERER_THEME.blockquote;
795
- return {
796
- fontSize: bq?.fontSize ?? fallback.fontSize,
797
- lineHeight: bq?.lineHeight ?? fallback.lineHeight,
798
- fontWeight: bq?.fontWeight ?? fallback.fontWeight,
799
- fontStyle: bq?.fontStyle ?? void 0
800
- };
801
- }
802
- if (nodeType === MAILY_NODE_TYPES.FOOTER) {
803
- const ft = DEFAULT_RENDERER_THEME.footer;
804
- return {
805
- fontSize: ft?.fontSize ?? fallback.fontSize,
806
- lineHeight: ft?.lineHeight ?? fallback.lineHeight,
807
- fontWeight: ft?.fontWeight ?? fallback.fontWeight
808
- };
809
- }
810
- return fallback;
811
- }
812
- //#endregion
813
659
  //#region src/variable.ts
814
- /** Default opening delimiter for variable placeholders in text. */
815
660
  const DEFAULT_VARIABLE_START_TRIGGER = "{{";
816
- /** Default closing delimiter for variable placeholders in text. */
817
661
  const DEFAULT_VARIABLE_END_TRIGGER = "}}";
818
- /**
819
- * Regex that matches variable placeholders like {{name}} in a string.
820
- * Uses a non-greedy match to handle multiple variables in one string.
821
- */
822
- const VARIABLE_PLACEHOLDER_REGEX = /({{.*?}})/g;
823
- /**
824
- * Delimiter used between fields inside a serialized variable string.
825
- * Format: {{id|label|required|hideDefaultValue}}.
826
- */
827
- const VARIABLE_TEXT_DELIMITER = "|";
828
- /**
829
- * Serializes a variable node's attributes into a delimited string.
830
- * Output format: `{{id|label|required|hideDefaultValue}}`.
831
- * Used to represent structured variable data as a template string
832
- * in plain text contexts.
833
- */
662
+ const LEGACY_HIDE_DEFAULT_VALUE = "hideDefaultValue";
663
+ function getQuotedValue(value) {
664
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
665
+ }
666
+ function getSerializedAttribute(options) {
667
+ const { name, value } = options;
668
+ if (value === void 0 || value === DEFAULT_VARIABLE_ATTRIBUTES[name]) return null;
669
+ if (typeof value === "boolean") return `${name}=${value}`;
670
+ return typeof value === "string" ? `${name}=${getQuotedValue(value)}` : null;
671
+ }
834
672
  function serializeVariableToText(variable) {
835
- const { id, label, required = true, hideDefaultValue = false } = variable;
673
+ const { fallback, id, isDefaultEditable, label, required, style } = variable;
836
674
  return [
837
675
  "{{",
838
- defaultStringifyValue(id),
839
- "|",
840
- defaultStringifyValue(label),
841
- "|",
842
- required,
843
- "|",
844
- hideDefaultValue,
676
+ [id, ...[
677
+ getSerializedAttribute({
678
+ name: "fallback",
679
+ value: fallback
680
+ }),
681
+ getSerializedAttribute({
682
+ name: "isDefaultEditable",
683
+ value: isDefaultEditable
684
+ }),
685
+ getSerializedAttribute({
686
+ name: "label",
687
+ value: label === id ? null : label
688
+ }),
689
+ getSerializedAttribute({
690
+ name: "required",
691
+ value: required
692
+ }),
693
+ getSerializedAttribute({
694
+ name: "style",
695
+ value: style
696
+ })
697
+ ].filter((attribute) => {
698
+ return attribute !== null;
699
+ })].join(" "),
845
700
  "}}"
846
701
  ].join("");
847
702
  }
848
- function defaultStringifyValue(value) {
849
- return value ?? "";
703
+ function getReferenceTokens(inner) {
704
+ const tokens = [];
705
+ let token = "";
706
+ let quoted = false;
707
+ for (let index = 0; index < inner.length; index += 1) {
708
+ const character = inner[index];
709
+ if (quoted && character === "\\" && index + 1 < inner.length) {
710
+ token += character + inner[index + 1];
711
+ index += 1;
712
+ continue;
713
+ }
714
+ if (character === "\"") {
715
+ quoted = !quoted;
716
+ token += character;
717
+ continue;
718
+ }
719
+ if (!quoted && /\s/.test(character)) {
720
+ if (token) {
721
+ tokens.push(token);
722
+ token = "";
723
+ }
724
+ continue;
725
+ }
726
+ token += character;
727
+ }
728
+ if (token) tokens.push(token);
729
+ return tokens;
730
+ }
731
+ function getUnquotedValue(value) {
732
+ if (value.startsWith("\"") && value.endsWith("\"") && value.length > 1) return value.slice(1, -1).replace(/\\"/g, "\"").replace(/\\\\/g, "\\");
733
+ if (value === "true") return true;
734
+ if (value === "false") return false;
735
+ return value;
850
736
  }
851
- /**
852
- * Deserializes a variable string back into VariableAttributes.
853
- * Expected input format: `{{id|label|required|hideDefaultValue}}`.
854
- * Missing fields default to undefined; boolean fields are parsed
855
- * from "true"/"false" strings.
856
- */
857
737
  function deserializeVariableFromText(text) {
858
- const [id, label, required, hideDefaultValue] = text.slice(2, text.length - 2).trim().split("|");
738
+ const [id = "", ...pairs] = getReferenceTokens(text.slice(2, text.length - 2).trim());
739
+ const attributes = { id };
740
+ for (const pair of pairs) {
741
+ const separator = pair.indexOf("=");
742
+ if (separator <= 0) continue;
743
+ const key = pair.slice(0, separator);
744
+ const value = getUnquotedValue(pair.slice(separator + 1));
745
+ if (key === LEGACY_HIDE_DEFAULT_VALUE) {
746
+ attributes.isDefaultEditable ??= value !== true;
747
+ continue;
748
+ }
749
+ attributes[key] = value;
750
+ }
859
751
  return {
860
- id,
861
- label: label || null,
862
- required: parseBoolean(required, true),
863
- hideDefaultValue: parseBoolean(hideDefaultValue, false)
752
+ ...DEFAULT_VARIABLE_ATTRIBUTES,
753
+ ...attributes
864
754
  };
865
755
  }
866
- /**
867
- * Parses a string containing variable placeholders (e.g. "Hello {{name}}")
868
- * into a Tiptap-compatible document JSON with text and variable nodes.
869
- * Splits on {{...}} boundaries and creates the appropriate node type
870
- * for each segment.
871
- */
756
+ function getVariableSegments(content) {
757
+ const segments = [];
758
+ let plain = "";
759
+ let index = 0;
760
+ while (index < content.length) {
761
+ if (!content.startsWith("{{", index)) {
762
+ plain += content[index];
763
+ index += 1;
764
+ continue;
765
+ }
766
+ const end = getReferenceEnd({
767
+ content,
768
+ start: index
769
+ });
770
+ if (end === -1) {
771
+ plain += content[index];
772
+ index += 1;
773
+ continue;
774
+ }
775
+ if (plain) {
776
+ segments.push({
777
+ isReference: false,
778
+ text: plain
779
+ });
780
+ plain = "";
781
+ }
782
+ segments.push({
783
+ isReference: true,
784
+ text: content.slice(index, end)
785
+ });
786
+ index = end;
787
+ }
788
+ if (plain) segments.push({
789
+ isReference: false,
790
+ text: plain
791
+ });
792
+ return segments;
793
+ }
794
+ function getReferenceEnd(options) {
795
+ const { content, start } = options;
796
+ let quoted = false;
797
+ for (let index = start + 2; index < content.length; index += 1) {
798
+ const character = content[index];
799
+ if (quoted && character === "\\") {
800
+ index += 1;
801
+ continue;
802
+ }
803
+ if (character === "\"") {
804
+ quoted = !quoted;
805
+ continue;
806
+ }
807
+ if (!quoted && content.startsWith("}}", index)) return index + 2;
808
+ }
809
+ return -1;
810
+ }
872
811
  function buildDocFromVariableText(content) {
873
- const parts = content.split(VARIABLE_PLACEHOLDER_REGEX);
874
812
  return {
875
813
  type: MAILY_NODE_TYPES.DOCUMENT,
876
814
  content: [{
877
815
  type: MAILY_NODE_TYPES.PARAGRAPH,
878
- content: parts.flatMap((part) => {
879
- if (part.startsWith("{{") && part.endsWith("}}")) return {
816
+ content: getVariableSegments(content).map((segment) => {
817
+ return segment.isReference ? {
880
818
  type: MAILY_NODE_TYPES.VARIABLE,
881
- attrs: deserializeVariableFromText(part)
882
- };
883
- if (part) return {
819
+ attrs: deserializeVariableFromText(segment.text)
820
+ } : {
884
821
  type: MAILY_NODE_TYPES.TEXT,
885
- text: part
822
+ text: segment.text
886
823
  };
887
- return [];
888
- }).filter(Boolean)
824
+ })
889
825
  }]
890
826
  };
891
827
  }
892
- /**
893
- * Checks if a string contains at least one variable placeholder.
894
- * Returns true for strings like "Hello {{name}}", false for plain text.
895
- * Uses index-based scanning instead of regex for performance.
896
- */
897
828
  function hasVariableInText(text) {
898
829
  const start = text.indexOf("{{");
899
830
  if (start === -1) return false;
900
831
  return text.indexOf("}}", start + 2) !== -1;
901
832
  }
902
- function parseBoolean(value, defaultValue) {
903
- if (value === "true") return true;
904
- if (value === "false") return false;
905
- return defaultValue;
906
- }
907
833
  //#endregion
908
834
  //#region src/visibility.ts
909
- /**
910
- * Comparison operators for conditional visibility rules.
911
- * Used to evaluate a template variable against a value
912
- * to decide whether a node should be shown or hidden.
913
- */
835
+ const VISIBILITY_ACTIONS = {
836
+ SHOW: "show",
837
+ HIDE: "hide"
838
+ };
839
+ const allowedVisibilityActions = Object.values(VISIBILITY_ACTIONS);
840
+ const VISIBILITY_ACTION_OPTIONS = [{
841
+ label: "Show if",
842
+ value: VISIBILITY_ACTIONS.SHOW
843
+ }, {
844
+ label: "Hide if",
845
+ value: VISIBILITY_ACTIONS.HIDE
846
+ }];
914
847
  const VISIBILITY_OPERATORS = {
915
848
  IS_TRUE: "is_true",
916
849
  IS_FALSE: "is_false",
@@ -923,96 +856,340 @@ const VISIBILITY_OPERATORS = {
923
856
  GREATER_THAN: "greater_than",
924
857
  LESS_THAN: "less_than"
925
858
  };
859
+ const allowedVisibilityOperators = Object.values(VISIBILITY_OPERATORS);
926
860
  const VISIBILITY_OPERATOR_OPTIONS = [
927
861
  {
928
- value: VISIBILITY_OPERATORS.IS_TRUE,
929
- label: "Is true"
862
+ label: "Is true",
863
+ value: VISIBILITY_OPERATORS.IS_TRUE
930
864
  },
931
865
  {
932
- value: VISIBILITY_OPERATORS.IS_FALSE,
933
- label: "Is false"
866
+ label: "Is false",
867
+ value: VISIBILITY_OPERATORS.IS_FALSE
934
868
  },
935
869
  {
936
- value: VISIBILITY_OPERATORS.EQUALS,
937
- label: "Equals"
870
+ label: "Equals",
871
+ value: VISIBILITY_OPERATORS.EQUALS
938
872
  },
939
873
  {
940
- value: VISIBILITY_OPERATORS.NOT_EQUALS,
941
- label: "Not equals"
874
+ label: "Not equals",
875
+ value: VISIBILITY_OPERATORS.NOT_EQUALS
942
876
  },
943
877
  {
944
- value: VISIBILITY_OPERATORS.CONTAINS,
945
- label: "Contains"
878
+ label: "Contains",
879
+ value: VISIBILITY_OPERATORS.CONTAINS
946
880
  },
947
881
  {
948
- value: VISIBILITY_OPERATORS.NOT_CONTAINS,
949
- label: "Not contains"
882
+ label: "Not contains",
883
+ value: VISIBILITY_OPERATORS.NOT_CONTAINS
950
884
  },
951
885
  {
952
- value: VISIBILITY_OPERATORS.STARTS_WITH,
953
- label: "Starts with"
886
+ label: "Starts with",
887
+ value: VISIBILITY_OPERATORS.STARTS_WITH
954
888
  },
955
889
  {
956
- value: VISIBILITY_OPERATORS.ENDS_WITH,
957
- label: "Ends with"
890
+ label: "Ends with",
891
+ value: VISIBILITY_OPERATORS.ENDS_WITH
958
892
  },
959
893
  {
960
- value: VISIBILITY_OPERATORS.GREATER_THAN,
961
- label: "Greater than"
894
+ label: "Greater than",
895
+ value: VISIBILITY_OPERATORS.GREATER_THAN
962
896
  },
963
897
  {
964
- value: VISIBILITY_OPERATORS.LESS_THAN,
965
- label: "Less than"
898
+ label: "Less than",
899
+ value: VISIBILITY_OPERATORS.LESS_THAN
966
900
  }
967
901
  ];
968
- /**
969
- * Unary operators that don't require a comparison value.
970
- * The UI hides the value input field when one of these is selected.
971
- */
972
- const OPERATORS_WITHOUT_VALUE = [VISIBILITY_OPERATORS.IS_TRUE, VISIBILITY_OPERATORS.IS_FALSE];
973
- const VISIBILITY_ACTIONS = {
974
- NONE: "none",
975
- SHOW: "show",
976
- HIDE: "hide"
902
+ const VISIBILITY_OPERATORS_WITHOUT_VALUE = [VISIBILITY_OPERATORS.IS_TRUE, VISIBILITY_OPERATORS.IS_FALSE];
903
+ const DEFAULT_VISIBILITY_RULE = {
904
+ action: VISIBILITY_ACTIONS.SHOW,
905
+ operator: VISIBILITY_OPERATORS.EQUALS,
906
+ value: "",
907
+ variable: ""
977
908
  };
978
- const VISIBILITY_ACTION_OPTIONS = [
979
- {
980
- value: VISIBILITY_ACTIONS.NONE,
981
- label: "None"
909
+ function getVisibilityValueSupport(operator) {
910
+ return !VISIBILITY_OPERATORS_WITHOUT_VALUE.includes(operator);
911
+ }
912
+ function getVisibilityRule(options) {
913
+ const { action, operator, value, variable } = options;
914
+ const isAllowedAction = allowedVisibilityActions.some((candidate) => {
915
+ return candidate === action;
916
+ });
917
+ const isAllowedOperator = allowedVisibilityOperators.some((candidate) => {
918
+ return candidate === operator;
919
+ });
920
+ if (!(isAllowedAction && isAllowedOperator)) return null;
921
+ return {
922
+ action,
923
+ operator,
924
+ value: getVisibilityValueSupport(operator) ? value ?? "" : "",
925
+ variable: variable ?? ""
926
+ };
927
+ }
928
+ //#endregion
929
+ //#region src/theme.ts
930
+ const DEFAULT_CONTAINER_MAX_WIDTH = 600;
931
+ const BASIC_NODE_THEME = {
932
+ blockquote: {
933
+ borderColor: "#d1d5db",
934
+ borderLeftStyle: "solid",
935
+ borderLeftWidth: "4px",
936
+ color: "#374151",
937
+ fontSize: "15px",
938
+ fontStyle: "italic",
939
+ fontWeight: "500",
940
+ lineHeight: "26px",
941
+ marginBottom: "20px",
942
+ marginLeft: "0",
943
+ marginRight: "0",
944
+ marginTop: "20px",
945
+ paddingLeft: "16px"
982
946
  },
983
- {
984
- value: VISIBILITY_ACTIONS.SHOW,
985
- label: "Show if"
947
+ body: { fontFamily: getFontFamilyValue({
948
+ fallbackFontFamily: DEFAULT_FONT.fallbackFontFamily,
949
+ fontFamily: DEFAULT_FONT.fontFamily
950
+ }) },
951
+ bulletList: {
952
+ listStyleType: "disc",
953
+ margin: "0",
954
+ paddingLeft: "26px"
986
955
  },
987
- {
988
- value: VISIBILITY_ACTIONS.HIDE,
989
- label: "Hide if"
956
+ button: {
957
+ backgroundColor: "#000000",
958
+ borderRadius: "9999px",
959
+ color: "#ffffff",
960
+ fontSize: "14px",
961
+ fontWeight: "500",
962
+ lineHeight: "20px",
963
+ padding: "10px 32px"
964
+ },
965
+ code: {
966
+ borderRadius: "8px",
967
+ fontFamily: "ui-monospace, monospace",
968
+ fontSize: "85%",
969
+ padding: "2px 6px"
970
+ },
971
+ h1: {
972
+ fontSize: "36px",
973
+ fontWeight: "800",
974
+ lineHeight: "40px"
975
+ },
976
+ h2: {
977
+ fontSize: "30px",
978
+ fontWeight: "700",
979
+ lineHeight: "40px"
980
+ },
981
+ h3: {
982
+ fontSize: "24px",
983
+ fontWeight: "600",
984
+ lineHeight: "38px"
985
+ },
986
+ heading: {
987
+ color: "#101828",
988
+ marginBottom: "12px",
989
+ marginTop: "0"
990
+ },
991
+ horizontalRule: {
992
+ border: "none",
993
+ borderTop: "1px solid #eaeaea",
994
+ marginBottom: "32px",
995
+ marginTop: "32px"
996
+ },
997
+ htmlCodeBlock: { marginBottom: "32px" },
998
+ link: {
999
+ color: "#0000ee",
1000
+ textDecoration: "underline"
1001
+ },
1002
+ listItem: {
1003
+ marginBottom: "8px",
1004
+ paddingLeft: "6px"
1005
+ },
1006
+ orderedList: {
1007
+ listStyleType: "decimal",
1008
+ margin: "0",
1009
+ paddingLeft: "26px"
1010
+ },
1011
+ footer: {
1012
+ color: "#64748B",
1013
+ display: "block",
1014
+ fontSize: "14px",
1015
+ fontWeight: "400",
1016
+ lineHeight: "24px",
1017
+ marginBottom: "0",
1018
+ marginTop: "0"
1019
+ },
1020
+ paragraph: {
1021
+ color: "#18181b",
1022
+ fontSize: "14px",
1023
+ lineHeight: "24px"
1024
+ },
1025
+ section: { padding: "8px" }
1026
+ };
1027
+ const MAILY_NODE_THEME = {
1028
+ blockquote: {
1029
+ borderLeftColor: "#d1d5db",
1030
+ borderLeftStyle: "solid",
1031
+ borderLeftWidth: "4px",
1032
+ color: "#374151",
1033
+ fontSize: "15px",
1034
+ fontStyle: "italic",
1035
+ fontWeight: "500",
1036
+ lineHeight: "1.75",
1037
+ marginBottom: "20px",
1038
+ marginLeft: "0",
1039
+ marginRight: "0",
1040
+ marginTop: "20px",
1041
+ paddingLeft: "16px"
1042
+ },
1043
+ body: {
1044
+ backgroundColor: "#ffffff",
1045
+ fontFamily: getFontFamilyValue({
1046
+ fallbackFontFamily: DEFAULT_FONT.fallbackFontFamily,
1047
+ fontFamily: DEFAULT_FONT.fontFamily
1048
+ }),
1049
+ padding: "0"
1050
+ },
1051
+ bulletList: {
1052
+ listStyleType: "disc",
1053
+ marginBottom: "20px",
1054
+ marginLeft: "0",
1055
+ marginRight: "0",
1056
+ marginTop: "0",
1057
+ paddingLeft: "26px"
1058
+ },
1059
+ button: {
1060
+ backgroundColor: "#000000",
1061
+ borderRadius: "9999px",
1062
+ color: "#ffffff",
1063
+ fontSize: "14px",
1064
+ fontWeight: "600",
1065
+ lineHeight: "1.4285714",
1066
+ marginBottom: "20px",
1067
+ padding: "10px 32px"
1068
+ },
1069
+ code: {
1070
+ backgroundColor: "#efefef",
1071
+ borderRadius: "8px",
1072
+ color: "#111827",
1073
+ fontFamily: "ui-monospace, monospace",
1074
+ fontSize: "85%",
1075
+ padding: "2px 6px"
1076
+ },
1077
+ container: {
1078
+ backgroundColor: "#ffffff",
1079
+ maxWidth: `600px`,
1080
+ minWidth: "300px",
1081
+ padding: "8px"
1082
+ },
1083
+ footer: {
1084
+ color: "#64748b",
1085
+ display: "block",
1086
+ fontSize: "14px",
1087
+ fontWeight: "400",
1088
+ lineHeight: "1.7142857",
1089
+ marginBottom: "20px",
1090
+ marginTop: "0"
1091
+ },
1092
+ h1: {
1093
+ fontSize: "36px",
1094
+ fontWeight: "600",
1095
+ lineHeight: "1.1111111"
1096
+ },
1097
+ h2: {
1098
+ fontSize: "30px",
1099
+ fontWeight: "600",
1100
+ lineHeight: "1.3333333"
1101
+ },
1102
+ h3: {
1103
+ fontSize: "24px",
1104
+ fontWeight: "600",
1105
+ lineHeight: "1.6"
1106
+ },
1107
+ heading: {
1108
+ color: "#111827",
1109
+ marginBottom: "12px",
1110
+ marginTop: "0"
1111
+ },
1112
+ horizontalRule: {
1113
+ border: "none",
1114
+ borderTop: "1px solid #eaeaea",
1115
+ marginBottom: "32px",
1116
+ marginTop: "32px"
1117
+ },
1118
+ htmlCodeBlock: { marginBottom: "32px" },
1119
+ link: {
1120
+ color: "#111827",
1121
+ textDecoration: "underline"
1122
+ },
1123
+ listItem: {
1124
+ color: "#d1d5dc",
1125
+ marginBottom: "8px",
1126
+ marginTop: "8px",
1127
+ paddingLeft: "6px"
1128
+ },
1129
+ orderedList: {
1130
+ listStyleType: "decimal",
1131
+ marginBottom: "20px",
1132
+ marginLeft: "0",
1133
+ marginRight: "0",
1134
+ marginTop: "0",
1135
+ paddingLeft: "26px"
1136
+ },
1137
+ paragraph: {
1138
+ color: "#374151",
1139
+ fontSize: "15px",
1140
+ fontWeight: "400",
1141
+ lineHeight: "1.75",
1142
+ marginBottom: "20px",
1143
+ marginTop: "0",
1144
+ MozOsxFontSmoothing: "grayscale",
1145
+ WebkitFontSmoothing: "antialiased"
1146
+ },
1147
+ section: {
1148
+ backgroundColor: "#f7f7f7",
1149
+ border: "2px solid #e2e2e2",
1150
+ borderRadius: "0",
1151
+ marginBottom: "20px",
1152
+ padding: "0"
990
1153
  }
991
- ];
1154
+ };
1155
+ function extendNodeTheme(options) {
1156
+ const { extension, preset } = options;
1157
+ return deepMerge(preset, extension);
1158
+ }
1159
+ function getThemeDeclarations(options) {
1160
+ const { attrs, theme, type } = options;
1161
+ const declarations = theme[type];
1162
+ if (type !== MAILY_NODE_TYPES.HEADING) return declarations;
1163
+ const level = typeof attrs?.level === "number" ? theme[`h${attrs.level}`] : void 0;
1164
+ if (!(declarations || level)) return;
1165
+ return {
1166
+ ...declarations,
1167
+ ...level
1168
+ };
1169
+ }
992
1170
  //#endregion
1171
+ exports.BASIC_NODE_THEME = BASIC_NODE_THEME;
1172
+ exports.BLOCK_CONTAINER_TYPES = BLOCK_CONTAINER_TYPES;
993
1173
  exports.BORDER_STYLES = BORDER_STYLES;
1174
+ exports.BOX_CORNERS = BOX_CORNERS;
1175
+ exports.BOX_SIDES = BOX_SIDES;
994
1176
  exports.BUTTON_KINDS = BUTTON_KINDS;
995
1177
  exports.DATA_NODE_TYPE_KEY = DATA_NODE_TYPE_KEY;
996
- exports.DATA_VISIBILITY_RULE_KEY = DATA_VISIBILITY_RULE_KEY;
997
- exports.DEFAULT_BORDER_COLOR = DEFAULT_BORDER_COLOR;
998
1178
  exports.DEFAULT_BORDER_STYLE = DEFAULT_BORDER_STYLE;
999
1179
  exports.DEFAULT_BUTTON_KIND = DEFAULT_BUTTON_KIND;
1000
- exports.DEFAULT_EDITOR_THEME = DEFAULT_EDITOR_THEME;
1180
+ exports.DEFAULT_CONTAINER_MAX_WIDTH = DEFAULT_CONTAINER_MAX_WIDTH;
1181
+ exports.DEFAULT_CONTAINER_WIDTH_PIXELS = DEFAULT_CONTAINER_WIDTH_PIXELS;
1001
1182
  exports.DEFAULT_FONT = DEFAULT_FONT;
1002
1183
  exports.DEFAULT_FONT_FALLBACK = DEFAULT_FONT_FALLBACK;
1003
1184
  exports.DEFAULT_FONT_FAMILIES = DEFAULT_FONT_FAMILIES;
1004
1185
  exports.DEFAULT_FONT_FAMILY = DEFAULT_FONT_FAMILY;
1005
- exports.DEFAULT_FONT_SIZE = DEFAULT_FONT_SIZE;
1006
- exports.DEFAULT_FONT_WEIGHT = DEFAULT_FONT_WEIGHT;
1007
1186
  exports.DEFAULT_HTML_CODE_BLOCK_TAB = DEFAULT_HTML_CODE_BLOCK_TAB;
1008
- exports.DEFAULT_LINE_HEIGHT = DEFAULT_LINE_HEIGHT;
1009
- exports.DEFAULT_LINK_TEXT_COLOR = DEFAULT_LINK_TEXT_COLOR;
1010
- exports.DEFAULT_RENDERER_THEME = DEFAULT_RENDERER_THEME;
1011
1187
  exports.DEFAULT_TEXT_ALIGN = DEFAULT_TEXT_ALIGN;
1012
1188
  exports.DEFAULT_TEXT_DIRECTION = DEFAULT_TEXT_DIRECTION;
1189
+ exports.DEFAULT_VARIABLE_ATTRIBUTES = DEFAULT_VARIABLE_ATTRIBUTES;
1013
1190
  exports.DEFAULT_VARIABLE_END_TRIGGER = DEFAULT_VARIABLE_END_TRIGGER;
1014
1191
  exports.DEFAULT_VARIABLE_START_TRIGGER = DEFAULT_VARIABLE_START_TRIGGER;
1015
- exports.FIELD_MODE = FIELD_MODE;
1192
+ exports.DEFAULT_VISIBILITY_RULE = DEFAULT_VISIBILITY_RULE;
1016
1193
  exports.FONT_SIZE_PRESETS = FONT_SIZE_PRESETS;
1017
1194
  exports.FONT_STYLES = FONT_STYLES;
1018
1195
  exports.FONT_WEIGHTS = FONT_WEIGHTS;
@@ -1022,60 +1199,63 @@ exports.MAILY_BUG_REPORT_URL = MAILY_BUG_REPORT_URL;
1022
1199
  exports.MAILY_ERROR_PREFIX = MAILY_ERROR_PREFIX;
1023
1200
  exports.MAILY_EXTENSION_TYPES = MAILY_EXTENSION_TYPES;
1024
1201
  exports.MAILY_MARK_TYPES = MAILY_MARK_TYPES;
1202
+ exports.MAILY_NODE_THEME = MAILY_NODE_THEME;
1025
1203
  exports.MAILY_NODE_TYPES = MAILY_NODE_TYPES;
1204
+ exports.MARGIN_BOTTOM_ABSORBER_TYPES = MARGIN_BOTTOM_ABSORBER_TYPES;
1205
+ exports.MARGIN_TOP_ABSORBER_TYPES = MARGIN_TOP_ABSORBER_TYPES;
1026
1206
  exports.MAX_IMAGE_WIDTH_PERCENTAGE = MAX_IMAGE_WIDTH_PERCENTAGE;
1027
1207
  exports.MIN_IMAGE_WIDTH_PERCENTAGE = MIN_IMAGE_WIDTH_PERCENTAGE;
1028
- exports.OPERATORS_WITHOUT_VALUE = OPERATORS_WITHOUT_VALUE;
1029
1208
  exports.TEXT_ALIGNMENTS = TEXT_ALIGNMENTS;
1030
1209
  exports.TEXT_DIRECTIONS = TEXT_DIRECTIONS;
1031
- exports.VARIABLE_PLACEHOLDER_REGEX = VARIABLE_PLACEHOLDER_REGEX;
1032
- exports.VARIABLE_TEXT_DELIMITER = VARIABLE_TEXT_DELIMITER;
1033
1210
  exports.VISIBILITY_ACTIONS = VISIBILITY_ACTIONS;
1034
1211
  exports.VISIBILITY_ACTION_OPTIONS = VISIBILITY_ACTION_OPTIONS;
1035
1212
  exports.VISIBILITY_OPERATORS = VISIBILITY_OPERATORS;
1036
1213
  exports.VISIBILITY_OPERATOR_OPTIONS = VISIBILITY_OPERATOR_OPTIONS;
1037
1214
  exports.absoluteFromPercentage = absoluteFromPercentage;
1038
- exports.allowedButtonKinds = allowedButtonKinds;
1039
1215
  exports.allowedFallbackFonts = allowedFallbackFonts;
1040
- exports.allowedFieldModes = allowedFieldModes;
1041
- exports.allowedFontFormats = allowedFontFormats;
1042
1216
  exports.allowedMarkTypes = allowedMarkTypes;
1043
1217
  exports.allowedNodeTypes = allowedNodeTypes;
1044
- exports.allowedTextAligns = allowedTextAligns;
1045
- exports.allowedTextDirections = allowedTextDirections;
1046
1218
  exports.buildDocFromVariableText = buildDocFromVariableText;
1047
1219
  exports.clamp = clamp;
1048
1220
  exports.clampImageWidthPercentage = clampImageWidthPercentage;
1049
1221
  exports.deepMerge = deepMerge;
1050
1222
  exports.deserializeVariableFromText = deserializeVariableFromText;
1051
- exports.getBorderStyle = getBorderStyle;
1223
+ exports.expandInlineStyles = expandInlineStyles;
1224
+ exports.extendNodeTheme = extendNodeTheme;
1225
+ exports.getBorderParts = getBorderParts;
1226
+ exports.getBoxCorners = getBoxCorners;
1227
+ exports.getBoxSides = getBoxSides;
1228
+ exports.getColumnWidth = getColumnWidth;
1229
+ exports.getColumnWidthPercent = getColumnWidthPercent;
1230
+ exports.getColumnWidthValue = getColumnWidthValue;
1052
1231
  exports.getCssDirection = getCssDirection;
1053
1232
  exports.getFontFaceStyle = getFontFaceStyle;
1054
- exports.getFontStyle = getFontStyle;
1055
- exports.getMailyCssVariables = getMailyCssVariables;
1056
- exports.getMarginStyle = getMarginStyle;
1057
- exports.getNodeFontStyleDefaults = getNodeFontStyleDefaults;
1058
- exports.getPaddingStyle = getPaddingStyle;
1059
- exports.getVariableValue = getVariableValue;
1233
+ exports.getFontFamilyNames = getFontFamilyNames;
1234
+ exports.getFontFamilyValue = getFontFamilyValue;
1235
+ exports.getSuppressedMargins = getSuppressedMargins;
1236
+ exports.getThemeDeclarations = getThemeDeclarations;
1237
+ exports.getVariableSegments = getVariableSegments;
1238
+ exports.getVisibilityRule = getVisibilityRule;
1239
+ exports.getVisibilityValueSupport = getVisibilityValueSupport;
1060
1240
  exports.hasVariableInText = hasVariableInText;
1061
1241
  exports.invariant = invariant;
1062
1242
  exports.is = is;
1243
+ exports.isAllowedBorderStyle = isAllowedBorderStyle;
1063
1244
  exports.isAllowedButtonKind = isAllowedButtonKind;
1064
- exports.isAllowedFieldMode = isAllowedFieldMode;
1065
1245
  exports.isAllowedTextAlignment = isAllowedTextAlignment;
1066
- exports.isAllowedTextDirection = isAllowedTextDirection;
1067
- exports.isBoolean = isBoolean;
1068
1246
  exports.isDef = isDef;
1069
- exports.isNumber = isNumber;
1247
+ exports.isMergeableObject = isMergeableObject;
1070
1248
  exports.isObject = isObject;
1071
- exports.isObjectDeepEqual = isObjectDeepEqual;
1072
- exports.isString = isString;
1073
1249
  exports.loadFont = loadFont;
1250
+ exports.mergeInlineStyles = mergeInlineStyles;
1074
1251
  exports.noop = noop;
1252
+ exports.parseInlineStyles = parseInlineStyles;
1075
1253
  exports.parseWidthToPercentage = parseWidthToPercentage;
1076
1254
  exports.percentage = percentage;
1077
1255
  exports.roundTo = roundTo;
1078
1256
  exports.serializeVariableToText = serializeVariableToText;
1079
- exports.sleep = sleep;
1257
+ exports.stringifyInlineStyles = stringifyInlineStyles;
1258
+ exports.toBoxCorners = toBoxCorners;
1259
+ exports.toBoxSides = toBoxSides;
1080
1260
 
1081
1261
  //# sourceMappingURL=index.cjs.map