@maily-to/shared 0.0.2 → 2.0.0-beta.10

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.mjs CHANGED
@@ -1,4 +1,225 @@
1
- //#region src/theme.ts
1
+ import { collapse, expand, objectify, stringify } from "stylecast";
2
+ //#region src/alignment.ts
3
+ const TEXT_ALIGNMENTS = {
4
+ LEFT: "left",
5
+ CENTER: "center",
6
+ RIGHT: "right"
7
+ };
8
+ const allowedTextAligns = Object.freeze(Object.values(TEXT_ALIGNMENTS));
9
+ const DEFAULT_TEXT_ALIGN = TEXT_ALIGNMENTS.LEFT;
10
+ function isAllowedTextAlignment(value) {
11
+ return typeof value === "string" && allowedTextAligns.includes(value);
12
+ }
13
+ //#endregion
14
+ //#region src/border.ts
15
+ const BORDER_STYLES = {
16
+ SOLID: "solid",
17
+ DASHED: "dashed",
18
+ DOTTED: "dotted"
19
+ };
20
+ const allowedBorderStyles = Object.freeze(Object.values(BORDER_STYLES));
21
+ const DEFAULT_BORDER_STYLE = BORDER_STYLES.SOLID;
22
+ function isAllowedBorderStyle(value) {
23
+ return typeof value === "string" && allowedBorderStyles.includes(value);
24
+ }
25
+ /**
26
+ * Reads the width, style and colour of a border from the `border` shorthand,
27
+ * letting any longhand already in the style win. The shorthand lists its
28
+ * parts in any order, so each is recognised by shape rather than position.
29
+ */
30
+ function getBorderParts(style) {
31
+ const parts = (style.border ?? "").trim().split(/\s+/).filter(Boolean);
32
+ let color;
33
+ let borderStyle;
34
+ let width;
35
+ for (const part of parts) if (isAllowedBorderStyle(part) || part === "none") borderStyle = part;
36
+ else if (/^[\d.]/.test(part)) width = part;
37
+ else color = part;
38
+ return {
39
+ color: style.borderColor ?? color,
40
+ style: style.borderStyle ?? borderStyle,
41
+ width: style.borderWidth ?? width
42
+ };
43
+ }
44
+ //#endregion
45
+ //#region src/box.ts
46
+ const BOX_SIDES = [
47
+ "top",
48
+ "right",
49
+ "bottom",
50
+ "left"
51
+ ];
52
+ const BOX_CORNERS = [
53
+ "topLeft",
54
+ "topRight",
55
+ "bottomRight",
56
+ "bottomLeft"
57
+ ];
58
+ function capitalize(value) {
59
+ return value.charAt(0).toUpperCase() + value.slice(1);
60
+ }
61
+ /**
62
+ * CSS box shorthands repeat their values when fewer than four are given:
63
+ * one applies to every edge, two to the vertical then horizontal pair, and
64
+ * three to top, the horizontal pair, then bottom.
65
+ */
66
+ function getShorthandEdges(shorthand) {
67
+ const parts = (shorthand ?? "").trim().split(/\s+/).filter(Boolean);
68
+ if (parts.length === 0) return null;
69
+ const [first, second = first, third = first, fourth = second] = parts;
70
+ return [
71
+ first,
72
+ second,
73
+ third,
74
+ fourth
75
+ ].map(toLength);
76
+ }
77
+ function toLength(value) {
78
+ const parsed = Number.parseFloat(value);
79
+ return Number.isNaN(parsed) ? 0 : parsed;
80
+ }
81
+ function getLonghand(style, property, edge, suffix) {
82
+ return style[`${property}${capitalize(edge)}${suffix}`];
83
+ }
84
+ function toShorthand(edges) {
85
+ const [first, second, third, fourth] = edges;
86
+ return (first === third && second === fourth ? first === second ? [first] : [first, second] : [
87
+ first,
88
+ second,
89
+ third,
90
+ fourth
91
+ ]).map((value) => `${value}px`).join(" ");
92
+ }
93
+ function getBoxSides(style, property) {
94
+ const [top, right, bottom, left] = getShorthandEdges(style[property]) ?? [
95
+ 0,
96
+ 0,
97
+ 0,
98
+ 0
99
+ ];
100
+ const sides = {
101
+ bottom,
102
+ left,
103
+ right,
104
+ top
105
+ };
106
+ for (const side of BOX_SIDES) {
107
+ const longhand = getLonghand(style, property, side, "");
108
+ if (longhand !== void 0) sides[side] = toLength(longhand);
109
+ }
110
+ return sides;
111
+ }
112
+ function toBoxSides(property, values) {
113
+ const declarations = { [property]: toShorthand([
114
+ values.top,
115
+ values.right,
116
+ values.bottom,
117
+ values.left
118
+ ]) };
119
+ for (const side of BOX_SIDES) declarations[`${property}${capitalize(side)}`] = null;
120
+ return declarations;
121
+ }
122
+ /**
123
+ * Radius shorthands run clockwise from the top-left corner, and repeat the
124
+ * same way box shorthands do.
125
+ */
126
+ function getBoxCorners(style, property) {
127
+ const [topLeft, topRight, bottomRight, bottomLeft] = getShorthandEdges(style[property]) ?? [
128
+ 0,
129
+ 0,
130
+ 0,
131
+ 0
132
+ ];
133
+ const corners = {
134
+ bottomLeft,
135
+ bottomRight,
136
+ topLeft,
137
+ topRight
138
+ };
139
+ for (const corner of BOX_CORNERS) {
140
+ const longhand = getLonghand(style, "border", corner, "Radius");
141
+ if (longhand !== void 0) corners[corner] = toLength(longhand);
142
+ }
143
+ return corners;
144
+ }
145
+ function toBoxCorners(property, values) {
146
+ const declarations = { [property]: toShorthand([
147
+ values.topLeft,
148
+ values.topRight,
149
+ values.bottomRight,
150
+ values.bottomLeft
151
+ ]) };
152
+ for (const corner of BOX_CORNERS) declarations[`border${capitalize(corner)}Radius`] = null;
153
+ return declarations;
154
+ }
155
+ //#endregion
156
+ //#region src/button.ts
157
+ /**
158
+ * Button layout kinds.
159
+ * "tight" renders the button at its content width,
160
+ * "full-width" stretches it to fill the container.
161
+ */
162
+ const BUTTON_KINDS = {
163
+ TIGHT: "tight",
164
+ FULL_WIDTH: "full-width"
165
+ };
166
+ const allowedButtonKinds = Object.freeze(Object.values(BUTTON_KINDS));
167
+ const DEFAULT_BUTTON_KIND = BUTTON_KINDS.TIGHT;
168
+ function isAllowedButtonKind(value) {
169
+ return typeof value === "string" && allowedButtonKinds.includes(value);
170
+ }
171
+ //#endregion
172
+ //#region src/math.ts
173
+ function clamp(value, [min, max]) {
174
+ return Math.min(Math.max(value, min), max);
175
+ }
176
+ function percentage(portion, total) {
177
+ return clamp(portion / total * 100, [0, 100]);
178
+ }
179
+ function roundTo(value, decimals) {
180
+ const factor = 10 ** decimals;
181
+ return Math.round(value * factor) / factor;
182
+ }
183
+ function absoluteFromPercentage(percentage, total) {
184
+ return Math.round(total * percentage / 100);
185
+ }
186
+ //#endregion
187
+ //#region src/column.ts
188
+ const PERCENTAGE_PATTERN = /^(\d+(?:\.\d+)?)%$/;
189
+ const PIXEL_PATTERN = /^(\d+(?:\.\d+)?)px$/;
190
+ const CSS_LENGTH_PATTERN = /^\d+(?:\.\d+)?(?:px|pt|pc|in|cm|mm|em|rem|ex|ch|vw|vh|vmin|vmax)$/;
191
+ function getColumnWidth(value) {
192
+ const declaration = value?.trim();
193
+ if (!declaration) return null;
194
+ const percentage = PERCENTAGE_PATTERN.exec(declaration);
195
+ if (percentage) return Number(percentage[1]);
196
+ return CSS_LENGTH_PATTERN.test(declaration) ? declaration : null;
197
+ }
198
+ function getColumnWidthValue(width) {
199
+ return typeof width === "number" ? `${width}%` : width;
200
+ }
201
+ function getColumnWidthPercent(options) {
202
+ const { containerWidth, width } = options;
203
+ if (width === null || width === void 0) return null;
204
+ if (typeof width === "number") return width;
205
+ const percentage = PERCENTAGE_PATTERN.exec(width);
206
+ if (percentage) return Number(percentage[1]);
207
+ const pixels = PIXEL_PATTERN.exec(width);
208
+ if (pixels && containerWidth > 0) return roundTo(Number(pixels[1]) / containerWidth * 100, 3);
209
+ return null;
210
+ }
211
+ //#endregion
212
+ //#region src/constants.ts
213
+ const DATA_NODE_TYPE_KEY = "data-node-type";
214
+ const MAILY_ERROR_PREFIX = "[Maily Error]";
215
+ const MAILY_BUG_REPORT_URL = "https://github.com/arikchakma/maily.to/issues/new";
216
+ //#endregion
217
+ //#region src/font.ts
218
+ /**
219
+ * List of allowed fallback font families. These are system fonts or
220
+ * generic font families that serve as fallbacks when a web font
221
+ * fails to load.
222
+ */
2
223
  const allowedFallbackFonts = [
3
224
  "Arial",
4
225
  "Helvetica",
@@ -11,193 +232,941 @@ const allowedFallbackFonts = [
11
232
  "cursive",
12
233
  "fantasy"
13
234
  ];
14
- const allowedFontFormats = [
15
- "woff",
16
- "woff2",
17
- "truetype",
18
- "opentype",
19
- "embedded-opentype",
20
- "svg"
21
- ];
235
+ /**
236
+ * Default font configuration: Inter with sans-serif fallback,
237
+ * loaded from the Maily CDN as woff2.
238
+ */
22
239
  const DEFAULT_FONT = {
23
240
  fallbackFontFamily: "sans-serif",
24
241
  fontFamily: "Inter",
25
242
  webFont: {
26
- url: "https://rsms.me/inter/font-files/Inter-Regular.woff2?v=3.19",
27
- format: "woff2"
243
+ format: "woff2",
244
+ url: "https://cdn.usemaily.com/fonts/v0/inter.woff2"
28
245
  }
29
246
  };
30
- const DEFAULT_LINK_TEXT_COLOR = "#111827";
31
- const DEFAULT_RENDERER_THEME = {
32
- colors: {
33
- heading: "#111827",
34
- paragraph: "#374151",
35
- horizontal: "#EAEAEA",
36
- footer: "#64748B",
37
- blockquoteBorder: "#D1D5DB",
38
- codeBackground: "#EFEFEF",
39
- codeText: "#111827",
40
- linkCardTitle: "#111827",
41
- linkCardDescription: "#6B7280",
42
- linkCardBadgeText: "#111827",
43
- linkCardBadgeBackground: "#FEF08A",
44
- linkCardSubTitle: "#6B7280"
45
- },
46
- fontSize: {
47
- paragraph: {
48
- size: "15px",
49
- lineHeight: "26.25px"
50
- },
51
- footer: {
52
- size: "14px",
53
- lineHeight: "24px"
247
+ function getFontFamilyNames(value) {
248
+ return value.split(",").map((font) => {
249
+ return font.trim().replace(/['"]/g, "");
250
+ }).filter(Boolean);
251
+ }
252
+ function getFontFamilyValue(options) {
253
+ const { fallbackFontFamily, fontFamily } = options;
254
+ return [fontFamily ? `'${fontFamily}'` : null, fallbackFontFamily].filter(Boolean).join(", ");
255
+ }
256
+ /**
257
+ * Generates a @font-face CSS rule string for the given font configuration.
258
+ * Includes the font family, style, weight, MSO fallback, and web font
259
+ * source URL when available.
260
+ */
261
+ function getFontFaceStyle(font) {
262
+ const { fallbackFontFamily, fontFamily, fontStyle = "normal", fontWeight = 400, webFont } = font;
263
+ return `@font-face {font-family: '${fontFamily}';font-style: ${fontStyle};font-weight: ${fontWeight};mso-font-alt: '${fallbackFontFamily}';${webFont ? `src: url(${webFont.url}) format('${webFont.format}');` : ""}}`;
264
+ }
265
+ /**
266
+ * Injects a @font-face style element into the document head to load
267
+ * the given font. Only works in browser environments.
268
+ */
269
+ function loadFont(font) {
270
+ const styleElement = document.createElement("style");
271
+ styleElement.textContent = getFontFaceStyle(font);
272
+ document.head.appendChild(styleElement);
273
+ }
274
+ //#endregion
275
+ //#region src/font-style.ts
276
+ /**
277
+ * Built-in font options served from the Maily CDN. System fonts
278
+ * (Arial, Helvetica, etc.) are included without a webFont field.
279
+ */
280
+ const DEFAULT_FONT_FAMILIES = [
281
+ {
282
+ fontFamily: "Inter",
283
+ webFont: {
284
+ format: "woff2",
285
+ url: "https://cdn.usemaily.com/fonts/v0/inter.woff2"
54
286
  }
55
287
  },
56
- container: {
57
- backgroundColor: "#ffffff",
58
- maxWidth: "600px",
59
- minWidth: "300px",
60
- paddingTop: "0.5rem",
61
- paddingRight: "0.5rem",
62
- paddingBottom: "0.5rem",
63
- paddingLeft: "0.5rem",
64
- borderRadius: "0px",
65
- borderWidth: "0px",
66
- borderColor: "transparent"
288
+ {
289
+ fontFamily: "Roboto",
290
+ webFont: {
291
+ format: "woff2",
292
+ url: "https://cdn.usemaily.com/fonts/v0/roboto.woff2"
293
+ }
67
294
  },
68
- body: {
69
- backgroundColor: "#ffffff",
70
- paddingTop: "0px",
71
- paddingRight: "0px",
72
- paddingBottom: "0px",
73
- paddingLeft: "0px"
295
+ {
296
+ fontFamily: "Open Sans",
297
+ webFont: {
298
+ format: "woff2",
299
+ url: "https://cdn.usemaily.com/fonts/v0/open-sans.woff2"
300
+ }
74
301
  },
75
- button: {
76
- backgroundColor: "#000000",
77
- color: "#ffffff",
78
- paddingTop: "10px",
79
- paddingRight: "32px",
80
- paddingBottom: "10px",
81
- paddingLeft: "32px"
302
+ {
303
+ fontFamily: "Lato",
304
+ webFont: {
305
+ format: "woff2",
306
+ url: "https://cdn.usemaily.com/fonts/v0/lato.woff2"
307
+ }
82
308
  },
83
- link: { color: DEFAULT_LINK_TEXT_COLOR },
84
- font: DEFAULT_FONT
309
+ {
310
+ fontFamily: "Montserrat",
311
+ webFont: {
312
+ format: "woff2",
313
+ url: "https://cdn.usemaily.com/fonts/v0/montserrat.woff2"
314
+ }
315
+ },
316
+ {
317
+ fontFamily: "Poppins",
318
+ webFont: {
319
+ format: "woff2",
320
+ url: "https://cdn.usemaily.com/fonts/v0/poppins.woff2"
321
+ }
322
+ },
323
+ {
324
+ fontFamily: "Raleway",
325
+ webFont: {
326
+ format: "woff2",
327
+ url: "https://cdn.usemaily.com/fonts/v0/raleway.woff2"
328
+ }
329
+ },
330
+ {
331
+ fontFamily: "Ubuntu",
332
+ webFont: {
333
+ format: "woff2",
334
+ url: "https://cdn.usemaily.com/fonts/v0/ubuntu.woff2"
335
+ }
336
+ },
337
+ { fontFamily: "Arial" },
338
+ { fontFamily: "Helvetica" },
339
+ { fontFamily: "Georgia" },
340
+ { fontFamily: "Times New Roman" },
341
+ { fontFamily: "Verdana" },
342
+ { fontFamily: "Courier New" },
343
+ { fontFamily: "Trebuchet MS" }
344
+ ];
345
+ const FONT_STYLES = {
346
+ NORMAL: "normal",
347
+ ITALIC: "italic"
85
348
  };
86
- const DEFAULT_EDITOR_THEME = {
87
- container: {
88
- backgroundColor: "#ffffff",
89
- maxWidth: "600px",
90
- minWidth: "300px",
91
- paddingTop: "8px",
92
- paddingRight: "8px",
93
- paddingBottom: "8px",
94
- paddingLeft: "8px",
95
- borderRadius: "0px",
96
- borderWidth: "0px",
97
- borderColor: "transparent"
349
+ const FONT_SIZE_PRESETS = [
350
+ {
351
+ value: 12,
352
+ label: "Small"
98
353
  },
99
- body: {
100
- backgroundColor: "#ffffff",
101
- paddingTop: "0px",
102
- paddingRight: "0px",
103
- paddingBottom: "0px",
104
- paddingLeft: "0px"
354
+ {
355
+ value: 14,
356
+ label: "Normal"
105
357
  },
106
- button: {
107
- backgroundColor: "#000000",
108
- color: "#ffffff",
109
- paddingTop: "10px",
110
- paddingRight: "32px",
111
- paddingBottom: "10px",
112
- paddingLeft: "32px"
358
+ {
359
+ value: 16,
360
+ label: "Medium"
361
+ },
362
+ {
363
+ value: 18,
364
+ label: "Large"
365
+ },
366
+ {
367
+ value: 24,
368
+ label: "XL"
369
+ },
370
+ {
371
+ value: 32,
372
+ label: "2XL"
373
+ }
374
+ ];
375
+ const LINE_HEIGHT_PRESETS = [
376
+ {
377
+ value: 1,
378
+ label: "Tight"
379
+ },
380
+ {
381
+ value: 1.25,
382
+ label: "Snug"
113
383
  },
114
- link: { color: DEFAULT_LINK_TEXT_COLOR },
115
- font: DEFAULT_FONT
384
+ {
385
+ value: 1.5,
386
+ label: "Normal"
387
+ },
388
+ {
389
+ value: 1.75,
390
+ label: "Relaxed"
391
+ },
392
+ {
393
+ value: 2,
394
+ label: "Loose"
395
+ }
396
+ ];
397
+ const DEFAULT_FONT_FAMILY = "Inter";
398
+ const DEFAULT_FONT_FALLBACK = "sans-serif";
399
+ //#endregion
400
+ //#region src/font-weight.ts
401
+ /**
402
+ * Numeric font weight values mapped to semantic names.
403
+ * Normal (400), Medium (500), Semibold (600), Bold (700), Extra Bold (800).
404
+ */
405
+ const FONT_WEIGHTS = {
406
+ NORMAL: 400,
407
+ MEDIUM: 500,
408
+ SEMIBOLD: 600,
409
+ BOLD: 700,
410
+ EXTRA_BOLD: 800
116
411
  };
117
-
118
412
  //#endregion
119
- //#region src/css-variables.ts
413
+ //#region src/function.ts
414
+ function noop() {}
415
+ //#endregion
416
+ //#region src/html-code-block.ts
120
417
  /**
121
- * if the value is undefined, it will return an empty object
122
- * so that we don't override the default value
123
- * @param name - The name of the CSS variable
124
- * @param value - The value of the CSS variable
125
- * @returns The CSS variable value
418
+ * Tab options for the HTML code block node.
419
+ * "code" shows the raw HTML source, "preview" renders it visually.
126
420
  */
127
- function getVariableValue(name, value) {
128
- if (value === void 0 || value === null || value === "") return {};
129
- return { [name]: value };
421
+ const HTML_CODE_BLOCK_TABS = {
422
+ CODE: "code",
423
+ PREVIEW: "preview"
424
+ };
425
+ const DEFAULT_HTML_CODE_BLOCK_TAB = HTML_CODE_BLOCK_TABS.CODE;
426
+ //#endregion
427
+ //#region src/image.ts
428
+ const MIN_IMAGE_WIDTH_PERCENTAGE = 5;
429
+ const MAX_IMAGE_WIDTH_PERCENTAGE = 100;
430
+ const DEFAULT_CONTAINER_WIDTH_PIXELS = 600;
431
+ const PIXEL_SUFFIX = "px";
432
+ function getPixels(value) {
433
+ const length = value.endsWith(PIXEL_SUFFIX) ? value.slice(0, -2) : value;
434
+ if (length === "") return null;
435
+ const pixels = Number(length);
436
+ return Number.isFinite(pixels) ? pixels : null;
437
+ }
438
+ function parseWidthToPercentage(width, containerWidthPixels = 600) {
439
+ if (width === null || width === void 0 || width === "auto") return 100;
440
+ const value = String(width).trim();
441
+ if (value.endsWith("%")) return clampImageWidthPercentage(Number.parseFloat(value));
442
+ const pixels = getPixels(value);
443
+ if (pixels === null) return 100;
444
+ return clampImageWidthPercentage(Math.round(100 * pixels / containerWidthPixels));
445
+ }
446
+ function clampImageWidthPercentage(width) {
447
+ return clamp(width, [5, 100]);
448
+ }
449
+ //#endregion
450
+ //#region src/invariant.ts
451
+ function invariant(value, message) {
452
+ if (value === false || value === null || typeof value === "undefined") {
453
+ console.error(`${MAILY_ERROR_PREFIX}: The following error is a bug in Maily;
454
+ Please open an issue! ${MAILY_BUG_REPORT_URL}`);
455
+ throw new Error(message);
456
+ }
457
+ }
458
+ //#endregion
459
+ //#region src/mark.ts
460
+ const MAILY_MARK_TYPES = {
461
+ BOLD: "bold",
462
+ ITALIC: "italic",
463
+ STRIKE: "strike",
464
+ UNDERLINE: "underline",
465
+ LINK: "link",
466
+ CODE: "code",
467
+ TEXT_STYLE: "textStyle",
468
+ HIGHLIGHT: "highlight",
469
+ SPAN: "span"
470
+ };
471
+ const allowedMarkTypes = Object.values(MAILY_MARK_TYPES);
472
+ //#endregion
473
+ //#region src/node.ts
474
+ const MAILY_NODE_TYPES = {
475
+ DOCUMENT: "doc",
476
+ BODY: "body",
477
+ CONTAINER: "container",
478
+ SECTION: "section",
479
+ COLUMNS: "columns",
480
+ COLUMN: "column",
481
+ IMAGE: "image",
482
+ INLINE_IMAGE: "inlineImage",
483
+ INLINE_SPAN: "inlineSpan",
484
+ SPACER: "spacer",
485
+ BUTTON: "button",
486
+ FOOTER: "footer",
487
+ PARAGRAPH: "paragraph",
488
+ HEADING: "heading",
489
+ BLOCKQUOTE: "blockquote",
490
+ HORIZONTAL_RULE: "horizontalRule",
491
+ HTML_CODE_BLOCK: "htmlCodeBlock",
492
+ REPEAT: "repeat",
493
+ HARD_BREAK: "hardBreak",
494
+ BULLET_LIST: "bulletList",
495
+ ORDERED_LIST: "orderedList",
496
+ LIST_ITEM: "listItem",
497
+ TEXT: "text",
498
+ VARIABLE: "variable",
499
+ TABLE: "table",
500
+ TABLE_ROW: "tableRow",
501
+ TABLE_CELL: "tableCell",
502
+ TABLE_HEADER: "tableHeader",
503
+ LINK_CARD: "linkCard"
504
+ };
505
+ const MAILY_EXTENSION_TYPES = {
506
+ STYLE: "style",
507
+ THEME: "theme",
508
+ VISIBILITY: "visibility"
509
+ };
510
+ const allowedNodeTypes = Object.values(MAILY_NODE_TYPES);
511
+ const DEFAULT_VARIABLE_ATTRIBUTES = {
512
+ fallback: null,
513
+ isDefaultEditable: true,
514
+ label: null,
515
+ required: true,
516
+ style: null
517
+ };
518
+ //#endregion
519
+ //#region src/is.ts
520
+ function guard(type) {
521
+ return (value) => value.type === type;
522
+ }
523
+ function isObject(val) {
524
+ return typeof val === "object" && val !== null;
525
+ }
526
+ const is = {
527
+ node(value) {
528
+ return typeof value === "object" && value !== null && "type" in value && allowedNodeTypes.includes(value.type);
529
+ },
530
+ mark(value) {
531
+ return typeof value === "object" && value !== null && "type" in value && allowedMarkTypes.includes(value.type);
532
+ },
533
+ parent(node) {
534
+ return Array.isArray(node?.content);
535
+ },
536
+ marked(node) {
537
+ return Array.isArray(node?.marks);
538
+ },
539
+ doc: guard(MAILY_NODE_TYPES.DOCUMENT),
540
+ body: guard(MAILY_NODE_TYPES.BODY),
541
+ container: guard(MAILY_NODE_TYPES.CONTAINER),
542
+ section: guard(MAILY_NODE_TYPES.SECTION),
543
+ columns: guard(MAILY_NODE_TYPES.COLUMNS),
544
+ column: guard(MAILY_NODE_TYPES.COLUMN),
545
+ image: guard(MAILY_NODE_TYPES.IMAGE),
546
+ inlineImage: guard(MAILY_NODE_TYPES.INLINE_IMAGE),
547
+ inlineSpan: guard(MAILY_NODE_TYPES.INLINE_SPAN),
548
+ spacer: guard(MAILY_NODE_TYPES.SPACER),
549
+ button: guard(MAILY_NODE_TYPES.BUTTON),
550
+ footer: guard(MAILY_NODE_TYPES.FOOTER),
551
+ paragraph: guard(MAILY_NODE_TYPES.PARAGRAPH),
552
+ heading: guard(MAILY_NODE_TYPES.HEADING),
553
+ blockquote: guard(MAILY_NODE_TYPES.BLOCKQUOTE),
554
+ horizontalRule: guard(MAILY_NODE_TYPES.HORIZONTAL_RULE),
555
+ hardBreak: guard(MAILY_NODE_TYPES.HARD_BREAK),
556
+ htmlCodeBlock: guard(MAILY_NODE_TYPES.HTML_CODE_BLOCK),
557
+ repeat: guard(MAILY_NODE_TYPES.REPEAT),
558
+ bulletList: guard(MAILY_NODE_TYPES.BULLET_LIST),
559
+ orderedList: guard(MAILY_NODE_TYPES.ORDERED_LIST),
560
+ listItem: guard(MAILY_NODE_TYPES.LIST_ITEM),
561
+ linkCard: guard(MAILY_NODE_TYPES.LINK_CARD),
562
+ text: guard(MAILY_NODE_TYPES.TEXT),
563
+ variable: guard(MAILY_NODE_TYPES.VARIABLE),
564
+ table: guard(MAILY_NODE_TYPES.TABLE),
565
+ tableRow: guard(MAILY_NODE_TYPES.TABLE_ROW),
566
+ tableCell: guard(MAILY_NODE_TYPES.TABLE_CELL),
567
+ tableHeader: guard(MAILY_NODE_TYPES.TABLE_HEADER),
568
+ bold: guard(MAILY_MARK_TYPES.BOLD),
569
+ italic: guard(MAILY_MARK_TYPES.ITALIC),
570
+ strike: guard(MAILY_MARK_TYPES.STRIKE),
571
+ underline: guard(MAILY_MARK_TYPES.UNDERLINE),
572
+ link: guard(MAILY_MARK_TYPES.LINK),
573
+ code: guard(MAILY_MARK_TYPES.CODE),
574
+ textStyle: guard(MAILY_MARK_TYPES.TEXT_STYLE),
575
+ highlight: guard(MAILY_MARK_TYPES.HIGHLIGHT),
576
+ span: guard(MAILY_MARK_TYPES.SPAN)
577
+ };
578
+ function isDef(value) {
579
+ return value !== void 0 && value !== null;
580
+ }
581
+ //#endregion
582
+ //#region src/object.ts
583
+ function isMergeableObject(value) {
584
+ return value !== null && typeof value === "object" && !Array.isArray(value);
130
585
  }
131
586
  /**
132
- * Get the CSS variables for the theme
133
- * @param theme - The theme
134
- * @returns The CSS variables
135
- * @example
136
- * ```ts
137
- * const theme = {
138
- * body: {
139
- * backgroundColor: 'red',
140
- * },
141
- * };
587
+ * One-level deep merge of plain objects. Nested plain objects are
588
+ * shallow-merged; primitives, arrays, and null are replaced outright.
589
+ * Does not mutate the target — returns a new object.
142
590
  *
143
- * const cssVariables = getCssVariables(theme);
144
- *
145
- * console.log(cssVariables);
146
- * // { '--mly-body-background-color': 'red' }
591
+ * Example:
592
+ * deepMerge({ a: 1, nested: { x: 1, y: 2 } }, { nested: { y: 3 } })
593
+ * // => { a: 1, nested: { x: 1, y: 3 } }
147
594
  */
148
- function getMailyCssVariables(theme) {
149
- const font = theme.font || DEFAULT_FONT;
595
+ function deepMerge(target, ...sources) {
596
+ const result = { ...target };
597
+ for (const source of sources) for (const [key, value] of Object.entries(source)) result[key] = isMergeableObject(value) && isMergeableObject(result[key]) ? {
598
+ ...result[key],
599
+ ...value
600
+ } : value;
601
+ return result;
602
+ }
603
+ //#endregion
604
+ //#region src/spacing.ts
605
+ const BLOCK_CONTAINER_TYPES = [
606
+ MAILY_NODE_TYPES.DOCUMENT,
607
+ MAILY_NODE_TYPES.BODY,
608
+ MAILY_NODE_TYPES.CONTAINER,
609
+ MAILY_NODE_TYPES.SECTION,
610
+ MAILY_NODE_TYPES.COLUMN,
611
+ MAILY_NODE_TYPES.REPEAT,
612
+ MAILY_NODE_TYPES.BULLET_LIST,
613
+ MAILY_NODE_TYPES.ORDERED_LIST
614
+ ];
615
+ const MARGIN_TOP_ABSORBER_TYPES = [MAILY_NODE_TYPES.SPACER];
616
+ const MARGIN_BOTTOM_ABSORBER_TYPES = [MAILY_NODE_TYPES.SPACER, MAILY_NODE_TYPES.HORIZONTAL_RULE];
617
+ function getSuppressedMargins(position) {
618
+ const { isFirst, isLast, nextType, parentType, previousType } = position;
619
+ const stacks = parentType !== void 0 && BLOCK_CONTAINER_TYPES.includes(parentType);
150
620
  return {
151
- ...getVariableValue("--mly-body-background-color", theme.body?.backgroundColor),
152
- ...getVariableValue("--mly-body-padding-top", theme.body?.paddingTop),
153
- ...getVariableValue("--mly-body-padding-right", theme.body?.paddingRight),
154
- ...getVariableValue("--mly-body-padding-bottom", theme.body?.paddingBottom),
155
- ...getVariableValue("--mly-body-padding-left", theme.body?.paddingLeft),
156
- ...getVariableValue("--mly-container-background-color", theme.container?.backgroundColor),
157
- ...getVariableValue("--mly-container-max-width", theme.container?.maxWidth),
158
- ...getVariableValue("--mly-container-min-width", theme.container?.minWidth),
159
- ...getVariableValue("--mly-container-padding-top", theme.container?.paddingTop),
160
- ...getVariableValue("--mly-container-padding-right", theme.container?.paddingRight),
161
- ...getVariableValue("--mly-container-padding-bottom", theme.container?.paddingBottom),
162
- ...getVariableValue("--mly-container-padding-left", theme.container?.paddingLeft),
163
- ...getVariableValue("--mly-container-border-radius", theme.container?.borderRadius),
164
- ...getVariableValue("--mly-container-border-width", theme.container?.borderWidth),
165
- ...getVariableValue("--mly-container-border-color", theme.container?.borderColor),
166
- ...getVariableValue("--mly-button-background-color", theme.button?.backgroundColor),
167
- ...getVariableValue("--mly-button-text-color", theme.button?.color),
168
- ...getVariableValue("--mly-button-padding-top", theme.button?.paddingTop),
169
- ...getVariableValue("--mly-button-padding-right", theme.button?.paddingRight),
170
- ...getVariableValue("--mly-button-padding-bottom", theme.button?.paddingBottom),
171
- ...getVariableValue("--mly-button-padding-left", theme.button?.paddingLeft),
172
- ...getVariableValue("--mly-link-color", theme.link?.color),
173
- ...getVariableValue("--mly-font-family", font.fontFamily),
174
- ...getVariableValue("--mly-font-fallback-family", font.fallbackFontFamily),
175
- "--mly-font": `var(--mly-font-family), var(--mly-font-fallback-family)`
621
+ marginBottom: !stacks || isLast || MARGIN_BOTTOM_ABSORBER_TYPES.includes(nextType ?? ""),
622
+ marginTop: !stacks || isFirst || MARGIN_TOP_ABSORBER_TYPES.includes(previousType ?? "")
176
623
  };
177
624
  }
178
-
179
625
  //#endregion
180
- //#region src/font.ts
181
- function loadFont(font) {
182
- const style = fontStyle(font);
183
- const styleElement = document.createElement("style");
184
- styleElement.textContent = style;
185
- document.head.appendChild(styleElement);
626
+ //#region src/style.ts
627
+ function parseInlineStyles(style) {
628
+ return objectify(style, { reactify: true });
186
629
  }
187
- function fontStyle(font) {
188
- const { fontFamily, fallbackFontFamily, webFont } = font;
189
- const src = webFont ? `src: url(${webFont.url}) format('${webFont.format}');` : "";
190
- const style = `
191
- @font-face {
192
- font-family: '${fontFamily}';
193
- font-style: normal;
194
- font-weight: 400;
195
- mso-font-alt: '${fallbackFontFamily}';
196
- ${src}
197
- }`;
198
- return style;
630
+ function stringifyInlineStyles(style) {
631
+ return stringify(style, { kebabCase: true });
632
+ }
633
+ function expandInlineStyles(style) {
634
+ return expand(style, { camelCase: true });
635
+ }
636
+ function collapseInlineStyles(style) {
637
+ return collapse(style, { camelCase: true });
638
+ }
639
+ function mergeInlineStyles(under, over) {
640
+ return collapseInlineStyles({
641
+ ...expandInlineStyles(under),
642
+ ...expandInlineStyles(over)
643
+ });
644
+ }
645
+ //#endregion
646
+ //#region src/direction.ts
647
+ const TEXT_DIRECTIONS = {
648
+ LTR: "ltr",
649
+ RTL: "rtl",
650
+ AUTO: "auto"
651
+ };
652
+ const DEFAULT_TEXT_DIRECTION = TEXT_DIRECTIONS.AUTO;
653
+ function getCssDirection(dir) {
654
+ if (dir && dir !== TEXT_DIRECTIONS.AUTO) return { direction: dir };
655
+ return {};
656
+ }
657
+ //#endregion
658
+ //#region src/variable.ts
659
+ const DEFAULT_VARIABLE_START_TRIGGER = "{{";
660
+ const DEFAULT_VARIABLE_END_TRIGGER = "}}";
661
+ const LEGACY_HIDE_DEFAULT_VALUE = "hideDefaultValue";
662
+ function getQuotedValue(value) {
663
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
664
+ }
665
+ function getSerializedAttribute(options) {
666
+ const { name, value } = options;
667
+ if (value === void 0 || value === DEFAULT_VARIABLE_ATTRIBUTES[name]) return null;
668
+ if (typeof value === "boolean") return `${name}=${value}`;
669
+ return typeof value === "string" ? `${name}=${getQuotedValue(value)}` : null;
670
+ }
671
+ function serializeVariableToText(variable) {
672
+ const { fallback, id, isDefaultEditable, label, required, style } = variable;
673
+ return [
674
+ "{{",
675
+ [id, ...[
676
+ getSerializedAttribute({
677
+ name: "fallback",
678
+ value: fallback
679
+ }),
680
+ getSerializedAttribute({
681
+ name: "isDefaultEditable",
682
+ value: isDefaultEditable
683
+ }),
684
+ getSerializedAttribute({
685
+ name: "label",
686
+ value: label === id ? null : label
687
+ }),
688
+ getSerializedAttribute({
689
+ name: "required",
690
+ value: required
691
+ }),
692
+ getSerializedAttribute({
693
+ name: "style",
694
+ value: style
695
+ })
696
+ ].filter((attribute) => {
697
+ return attribute !== null;
698
+ })].join(" "),
699
+ "}}"
700
+ ].join("");
701
+ }
702
+ function getReferenceTokens(inner) {
703
+ const tokens = [];
704
+ let token = "";
705
+ let quoted = false;
706
+ for (let index = 0; index < inner.length; index += 1) {
707
+ const character = inner[index];
708
+ if (quoted && character === "\\" && index + 1 < inner.length) {
709
+ token += character + inner[index + 1];
710
+ index += 1;
711
+ continue;
712
+ }
713
+ if (character === "\"") {
714
+ quoted = !quoted;
715
+ token += character;
716
+ continue;
717
+ }
718
+ if (!quoted && /\s/.test(character)) {
719
+ if (token) {
720
+ tokens.push(token);
721
+ token = "";
722
+ }
723
+ continue;
724
+ }
725
+ token += character;
726
+ }
727
+ if (token) tokens.push(token);
728
+ return tokens;
729
+ }
730
+ function getUnquotedValue(value) {
731
+ if (value.startsWith("\"") && value.endsWith("\"") && value.length > 1) return value.slice(1, -1).replace(/\\"/g, "\"").replace(/\\\\/g, "\\");
732
+ if (value === "true") return true;
733
+ if (value === "false") return false;
734
+ return value;
735
+ }
736
+ function deserializeVariableFromText(text) {
737
+ const [id = "", ...pairs] = getReferenceTokens(text.slice(2, text.length - 2).trim());
738
+ const attributes = { id };
739
+ for (const pair of pairs) {
740
+ const separator = pair.indexOf("=");
741
+ if (separator <= 0) continue;
742
+ const key = pair.slice(0, separator);
743
+ const value = getUnquotedValue(pair.slice(separator + 1));
744
+ if (key === LEGACY_HIDE_DEFAULT_VALUE) {
745
+ attributes.isDefaultEditable ??= value !== true;
746
+ continue;
747
+ }
748
+ attributes[key] = value;
749
+ }
750
+ return {
751
+ ...DEFAULT_VARIABLE_ATTRIBUTES,
752
+ ...attributes
753
+ };
754
+ }
755
+ function getVariableSegments(content) {
756
+ const segments = [];
757
+ let plain = "";
758
+ let index = 0;
759
+ while (index < content.length) {
760
+ if (!content.startsWith("{{", index)) {
761
+ plain += content[index];
762
+ index += 1;
763
+ continue;
764
+ }
765
+ const end = getReferenceEnd({
766
+ content,
767
+ start: index
768
+ });
769
+ if (end === -1) {
770
+ plain += content[index];
771
+ index += 1;
772
+ continue;
773
+ }
774
+ if (plain) {
775
+ segments.push({
776
+ isReference: false,
777
+ text: plain
778
+ });
779
+ plain = "";
780
+ }
781
+ segments.push({
782
+ isReference: true,
783
+ text: content.slice(index, end)
784
+ });
785
+ index = end;
786
+ }
787
+ if (plain) segments.push({
788
+ isReference: false,
789
+ text: plain
790
+ });
791
+ return segments;
792
+ }
793
+ function getReferenceEnd(options) {
794
+ const { content, start } = options;
795
+ let quoted = false;
796
+ for (let index = start + 2; index < content.length; index += 1) {
797
+ const character = content[index];
798
+ if (quoted && character === "\\") {
799
+ index += 1;
800
+ continue;
801
+ }
802
+ if (character === "\"") {
803
+ quoted = !quoted;
804
+ continue;
805
+ }
806
+ if (!quoted && content.startsWith("}}", index)) return index + 2;
807
+ }
808
+ return -1;
809
+ }
810
+ function buildDocFromVariableText(content) {
811
+ return {
812
+ type: MAILY_NODE_TYPES.DOCUMENT,
813
+ content: [{
814
+ type: MAILY_NODE_TYPES.PARAGRAPH,
815
+ content: getVariableSegments(content).map((segment) => {
816
+ return segment.isReference ? {
817
+ type: MAILY_NODE_TYPES.VARIABLE,
818
+ attrs: deserializeVariableFromText(segment.text)
819
+ } : {
820
+ type: MAILY_NODE_TYPES.TEXT,
821
+ text: segment.text
822
+ };
823
+ })
824
+ }]
825
+ };
826
+ }
827
+ function hasVariableInText(text) {
828
+ const start = text.indexOf("{{");
829
+ if (start === -1) return false;
830
+ return text.indexOf("}}", start + 2) !== -1;
831
+ }
832
+ //#endregion
833
+ //#region src/visibility.ts
834
+ const VISIBILITY_ACTIONS = {
835
+ SHOW: "show",
836
+ HIDE: "hide"
837
+ };
838
+ const allowedVisibilityActions = Object.values(VISIBILITY_ACTIONS);
839
+ const VISIBILITY_ACTION_OPTIONS = [{
840
+ label: "Show if",
841
+ value: VISIBILITY_ACTIONS.SHOW
842
+ }, {
843
+ label: "Hide if",
844
+ value: VISIBILITY_ACTIONS.HIDE
845
+ }];
846
+ const VISIBILITY_OPERATORS = {
847
+ IS_TRUE: "is_true",
848
+ IS_FALSE: "is_false",
849
+ EQUALS: "equals",
850
+ NOT_EQUALS: "not_equals",
851
+ CONTAINS: "contains",
852
+ NOT_CONTAINS: "not_contains",
853
+ STARTS_WITH: "starts_with",
854
+ ENDS_WITH: "ends_with",
855
+ GREATER_THAN: "greater_than",
856
+ LESS_THAN: "less_than"
857
+ };
858
+ const allowedVisibilityOperators = Object.values(VISIBILITY_OPERATORS);
859
+ const VISIBILITY_OPERATOR_OPTIONS = [
860
+ {
861
+ label: "Is true",
862
+ value: VISIBILITY_OPERATORS.IS_TRUE
863
+ },
864
+ {
865
+ label: "Is false",
866
+ value: VISIBILITY_OPERATORS.IS_FALSE
867
+ },
868
+ {
869
+ label: "Equals",
870
+ value: VISIBILITY_OPERATORS.EQUALS
871
+ },
872
+ {
873
+ label: "Not equals",
874
+ value: VISIBILITY_OPERATORS.NOT_EQUALS
875
+ },
876
+ {
877
+ label: "Contains",
878
+ value: VISIBILITY_OPERATORS.CONTAINS
879
+ },
880
+ {
881
+ label: "Not contains",
882
+ value: VISIBILITY_OPERATORS.NOT_CONTAINS
883
+ },
884
+ {
885
+ label: "Starts with",
886
+ value: VISIBILITY_OPERATORS.STARTS_WITH
887
+ },
888
+ {
889
+ label: "Ends with",
890
+ value: VISIBILITY_OPERATORS.ENDS_WITH
891
+ },
892
+ {
893
+ label: "Greater than",
894
+ value: VISIBILITY_OPERATORS.GREATER_THAN
895
+ },
896
+ {
897
+ label: "Less than",
898
+ value: VISIBILITY_OPERATORS.LESS_THAN
899
+ }
900
+ ];
901
+ const VISIBILITY_OPERATORS_WITHOUT_VALUE = [VISIBILITY_OPERATORS.IS_TRUE, VISIBILITY_OPERATORS.IS_FALSE];
902
+ const DEFAULT_VISIBILITY_RULE = {
903
+ action: VISIBILITY_ACTIONS.SHOW,
904
+ operator: VISIBILITY_OPERATORS.EQUALS,
905
+ value: "",
906
+ variable: ""
907
+ };
908
+ function getVisibilityValueSupport(operator) {
909
+ return !VISIBILITY_OPERATORS_WITHOUT_VALUE.includes(operator);
910
+ }
911
+ function getVisibilityRule(options) {
912
+ const { action, operator, value, variable } = options;
913
+ const isAllowedAction = allowedVisibilityActions.some((candidate) => {
914
+ return candidate === action;
915
+ });
916
+ const isAllowedOperator = allowedVisibilityOperators.some((candidate) => {
917
+ return candidate === operator;
918
+ });
919
+ if (!(isAllowedAction && isAllowedOperator)) return null;
920
+ return {
921
+ action,
922
+ operator,
923
+ value: getVisibilityValueSupport(operator) ? value ?? "" : "",
924
+ variable: variable ?? ""
925
+ };
926
+ }
927
+ //#endregion
928
+ //#region src/theme.ts
929
+ const DEFAULT_CONTAINER_MAX_WIDTH = 600;
930
+ const BASIC_NODE_THEME = {
931
+ blockquote: {
932
+ borderColor: "#d1d5db",
933
+ borderLeftStyle: "solid",
934
+ borderLeftWidth: "4px",
935
+ color: "#374151",
936
+ fontSize: "15px",
937
+ fontStyle: "italic",
938
+ fontWeight: "500",
939
+ lineHeight: "26px",
940
+ marginBottom: "20px",
941
+ marginLeft: "0",
942
+ marginRight: "0",
943
+ marginTop: "20px",
944
+ paddingLeft: "16px"
945
+ },
946
+ body: { fontFamily: getFontFamilyValue({
947
+ fallbackFontFamily: DEFAULT_FONT.fallbackFontFamily,
948
+ fontFamily: DEFAULT_FONT.fontFamily
949
+ }) },
950
+ bulletList: {
951
+ listStyleType: "disc",
952
+ margin: "0",
953
+ paddingLeft: "26px"
954
+ },
955
+ button: {
956
+ backgroundColor: "#000000",
957
+ borderRadius: "9999px",
958
+ color: "#ffffff",
959
+ fontSize: "14px",
960
+ fontWeight: "500",
961
+ lineHeight: "20px",
962
+ padding: "10px 32px"
963
+ },
964
+ code: {
965
+ borderRadius: "8px",
966
+ fontFamily: "ui-monospace, monospace",
967
+ fontSize: "85%",
968
+ padding: "2px 6px"
969
+ },
970
+ h1: {
971
+ fontSize: "36px",
972
+ fontWeight: "800",
973
+ lineHeight: "40px"
974
+ },
975
+ h2: {
976
+ fontSize: "30px",
977
+ fontWeight: "700",
978
+ lineHeight: "40px"
979
+ },
980
+ h3: {
981
+ fontSize: "24px",
982
+ fontWeight: "600",
983
+ lineHeight: "38px"
984
+ },
985
+ heading: {
986
+ color: "#101828",
987
+ marginBottom: "12px",
988
+ marginTop: "0"
989
+ },
990
+ horizontalRule: {
991
+ border: "none",
992
+ borderTop: "1px solid #eaeaea",
993
+ marginBottom: "32px",
994
+ marginTop: "32px"
995
+ },
996
+ htmlCodeBlock: { marginBottom: "32px" },
997
+ link: {
998
+ color: "#0000ee",
999
+ textDecoration: "underline"
1000
+ },
1001
+ listItem: {
1002
+ marginBottom: "8px",
1003
+ paddingLeft: "6px"
1004
+ },
1005
+ orderedList: {
1006
+ listStyleType: "decimal",
1007
+ margin: "0",
1008
+ paddingLeft: "26px"
1009
+ },
1010
+ footer: {
1011
+ color: "#64748B",
1012
+ display: "block",
1013
+ fontSize: "14px",
1014
+ fontWeight: "400",
1015
+ lineHeight: "24px",
1016
+ marginBottom: "0",
1017
+ marginTop: "0"
1018
+ },
1019
+ paragraph: {
1020
+ color: "#18181b",
1021
+ fontSize: "14px",
1022
+ lineHeight: "24px"
1023
+ },
1024
+ section: { padding: "8px" }
1025
+ };
1026
+ const MAILY_NODE_THEME = {
1027
+ blockquote: {
1028
+ borderLeftColor: "#d1d5db",
1029
+ borderLeftStyle: "solid",
1030
+ borderLeftWidth: "4px",
1031
+ color: "#374151",
1032
+ fontSize: "15px",
1033
+ fontStyle: "italic",
1034
+ fontWeight: "500",
1035
+ lineHeight: "1.75",
1036
+ marginBottom: "20px",
1037
+ marginLeft: "0",
1038
+ marginRight: "0",
1039
+ marginTop: "20px",
1040
+ paddingLeft: "16px"
1041
+ },
1042
+ body: {
1043
+ backgroundColor: "#ffffff",
1044
+ fontFamily: getFontFamilyValue({
1045
+ fallbackFontFamily: DEFAULT_FONT.fallbackFontFamily,
1046
+ fontFamily: DEFAULT_FONT.fontFamily
1047
+ }),
1048
+ padding: "0"
1049
+ },
1050
+ bulletList: {
1051
+ listStyleType: "disc",
1052
+ marginBottom: "20px",
1053
+ marginLeft: "0",
1054
+ marginRight: "0",
1055
+ marginTop: "0",
1056
+ paddingLeft: "26px"
1057
+ },
1058
+ button: {
1059
+ backgroundColor: "#000000",
1060
+ borderRadius: "9999px",
1061
+ color: "#ffffff",
1062
+ fontSize: "14px",
1063
+ fontWeight: "600",
1064
+ lineHeight: "1.4285714",
1065
+ marginBottom: "20px",
1066
+ padding: "10px 32px"
1067
+ },
1068
+ code: {
1069
+ backgroundColor: "#efefef",
1070
+ borderRadius: "8px",
1071
+ color: "#111827",
1072
+ fontFamily: "ui-monospace, monospace",
1073
+ fontSize: "85%",
1074
+ padding: "2px 6px"
1075
+ },
1076
+ container: {
1077
+ backgroundColor: "#ffffff",
1078
+ maxWidth: `600px`,
1079
+ minWidth: "300px",
1080
+ padding: "8px"
1081
+ },
1082
+ footer: {
1083
+ color: "#64748b",
1084
+ display: "block",
1085
+ fontSize: "14px",
1086
+ fontWeight: "400",
1087
+ lineHeight: "1.7142857",
1088
+ marginBottom: "20px",
1089
+ marginTop: "0"
1090
+ },
1091
+ h1: {
1092
+ fontSize: "36px",
1093
+ fontWeight: "600",
1094
+ lineHeight: "1.1111111"
1095
+ },
1096
+ h2: {
1097
+ fontSize: "30px",
1098
+ fontWeight: "600",
1099
+ lineHeight: "1.3333333"
1100
+ },
1101
+ h3: {
1102
+ fontSize: "24px",
1103
+ fontWeight: "600",
1104
+ lineHeight: "1.6"
1105
+ },
1106
+ heading: {
1107
+ color: "#111827",
1108
+ marginBottom: "12px",
1109
+ marginTop: "0"
1110
+ },
1111
+ horizontalRule: {
1112
+ border: "none",
1113
+ borderTop: "1px solid #eaeaea",
1114
+ marginBottom: "32px",
1115
+ marginTop: "32px"
1116
+ },
1117
+ htmlCodeBlock: { marginBottom: "32px" },
1118
+ link: {
1119
+ color: "#111827",
1120
+ textDecoration: "underline"
1121
+ },
1122
+ listItem: {
1123
+ color: "#d1d5dc",
1124
+ marginBottom: "8px",
1125
+ marginTop: "8px",
1126
+ paddingLeft: "6px"
1127
+ },
1128
+ orderedList: {
1129
+ listStyleType: "decimal",
1130
+ marginBottom: "20px",
1131
+ marginLeft: "0",
1132
+ marginRight: "0",
1133
+ marginTop: "0",
1134
+ paddingLeft: "26px"
1135
+ },
1136
+ paragraph: {
1137
+ color: "#374151",
1138
+ fontSize: "15px",
1139
+ fontWeight: "400",
1140
+ lineHeight: "1.75",
1141
+ marginBottom: "20px",
1142
+ marginTop: "0",
1143
+ MozOsxFontSmoothing: "grayscale",
1144
+ WebkitFontSmoothing: "antialiased"
1145
+ },
1146
+ section: {
1147
+ backgroundColor: "#f7f7f7",
1148
+ border: "2px solid #e2e2e2",
1149
+ borderRadius: "0",
1150
+ marginBottom: "20px",
1151
+ padding: "0"
1152
+ }
1153
+ };
1154
+ function extendNodeTheme(options) {
1155
+ const { extension, preset } = options;
1156
+ return deepMerge(preset, extension);
1157
+ }
1158
+ function getThemeDeclarations(options) {
1159
+ const { attrs, theme, type } = options;
1160
+ const declarations = theme[type];
1161
+ if (type !== MAILY_NODE_TYPES.HEADING) return declarations;
1162
+ const level = typeof attrs?.level === "number" ? theme[`h${attrs.level}`] : void 0;
1163
+ if (!(declarations || level)) return;
1164
+ return {
1165
+ ...declarations,
1166
+ ...level
1167
+ };
199
1168
  }
200
-
201
1169
  //#endregion
202
- export { DEFAULT_EDITOR_THEME, DEFAULT_FONT, DEFAULT_LINK_TEXT_COLOR, DEFAULT_RENDERER_THEME, allowedFallbackFonts, allowedFontFormats, fontStyle, getMailyCssVariables, getVariableValue, loadFont };
1170
+ export { BASIC_NODE_THEME, BLOCK_CONTAINER_TYPES, BORDER_STYLES, BOX_CORNERS, BOX_SIDES, BUTTON_KINDS, DATA_NODE_TYPE_KEY, DEFAULT_BORDER_STYLE, DEFAULT_BUTTON_KIND, DEFAULT_CONTAINER_MAX_WIDTH, DEFAULT_CONTAINER_WIDTH_PIXELS, DEFAULT_FONT, DEFAULT_FONT_FALLBACK, DEFAULT_FONT_FAMILIES, DEFAULT_FONT_FAMILY, DEFAULT_HTML_CODE_BLOCK_TAB, DEFAULT_TEXT_ALIGN, DEFAULT_TEXT_DIRECTION, DEFAULT_VARIABLE_ATTRIBUTES, DEFAULT_VARIABLE_END_TRIGGER, DEFAULT_VARIABLE_START_TRIGGER, DEFAULT_VISIBILITY_RULE, FONT_SIZE_PRESETS, FONT_STYLES, FONT_WEIGHTS, HTML_CODE_BLOCK_TABS, LINE_HEIGHT_PRESETS, MAILY_BUG_REPORT_URL, MAILY_ERROR_PREFIX, MAILY_EXTENSION_TYPES, MAILY_MARK_TYPES, MAILY_NODE_THEME, MAILY_NODE_TYPES, MARGIN_BOTTOM_ABSORBER_TYPES, MARGIN_TOP_ABSORBER_TYPES, MAX_IMAGE_WIDTH_PERCENTAGE, MIN_IMAGE_WIDTH_PERCENTAGE, TEXT_ALIGNMENTS, TEXT_DIRECTIONS, VISIBILITY_ACTIONS, VISIBILITY_ACTION_OPTIONS, VISIBILITY_OPERATORS, VISIBILITY_OPERATOR_OPTIONS, absoluteFromPercentage, allowedFallbackFonts, allowedMarkTypes, allowedNodeTypes, buildDocFromVariableText, clamp, clampImageWidthPercentage, deepMerge, deserializeVariableFromText, expandInlineStyles, extendNodeTheme, getBorderParts, getBoxCorners, getBoxSides, getColumnWidth, getColumnWidthPercent, getColumnWidthValue, getCssDirection, getFontFaceStyle, getFontFamilyNames, getFontFamilyValue, getSuppressedMargins, getThemeDeclarations, getVariableSegments, getVisibilityRule, getVisibilityValueSupport, hasVariableInText, invariant, is, isAllowedBorderStyle, isAllowedButtonKind, isAllowedTextAlignment, isDef, isMergeableObject, isObject, loadFont, mergeInlineStyles, noop, parseInlineStyles, parseWidthToPercentage, percentage, roundTo, serializeVariableToText, stringifyInlineStyles, toBoxCorners, toBoxSides };
1171
+
203
1172
  //# sourceMappingURL=index.mjs.map