@maizzle/framework 6.0.0-rc.4 → 6.0.0-rc.6

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.
Files changed (61) hide show
  1. package/dist/build.mjs +3 -2
  2. package/dist/build.mjs.map +1 -1
  3. package/dist/components/Body.vue +42 -0
  4. package/dist/components/Button.vue +65 -14
  5. package/dist/components/CodeBlock.vue +75 -0
  6. package/dist/components/CodeInline.vue +44 -0
  7. package/dist/components/Column.vue +61 -0
  8. package/dist/components/Container.vue +40 -0
  9. package/dist/components/Head.vue +8 -0
  10. package/dist/components/Html.vue +53 -0
  11. package/dist/components/Image.vue +70 -0
  12. package/dist/components/Overlap.vue +60 -0
  13. package/dist/components/Preview.vue +20 -0
  14. package/dist/components/Row.vue +80 -0
  15. package/dist/components/Spacer.vue +50 -7
  16. package/dist/composables/renderContext.d.mts +5 -0
  17. package/dist/composables/renderContext.d.mts.map +1 -1
  18. package/dist/composables/renderContext.mjs.map +1 -1
  19. package/dist/composables/usePreviewText.d.mts +24 -0
  20. package/dist/composables/usePreviewText.d.mts.map +1 -0
  21. package/dist/composables/usePreviewText.mjs +29 -0
  22. package/dist/composables/usePreviewText.mjs.map +1 -0
  23. package/dist/index.d.mts +3 -2
  24. package/dist/index.mjs +2 -1
  25. package/dist/render/createRenderer.d.mts +1 -0
  26. package/dist/render/createRenderer.d.mts.map +1 -1
  27. package/dist/render/createRenderer.mjs +60 -1
  28. package/dist/render/createRenderer.mjs.map +1 -1
  29. package/dist/render/index.mjs +3 -2
  30. package/dist/render/index.mjs.map +1 -1
  31. package/dist/serve.d.mts.map +1 -1
  32. package/dist/serve.mjs +31 -20
  33. package/dist/serve.mjs.map +1 -1
  34. package/dist/server/ui/pages/Preview.vue +11 -5
  35. package/dist/transformers/entities.d.mts.map +1 -1
  36. package/dist/transformers/entities.mjs +3 -0
  37. package/dist/transformers/entities.mjs.map +1 -1
  38. package/dist/transformers/filters/defaults.d.mts +6 -0
  39. package/dist/transformers/filters/defaults.d.mts.map +1 -0
  40. package/dist/transformers/filters/defaults.mjs +78 -0
  41. package/dist/transformers/filters/defaults.mjs.map +1 -0
  42. package/dist/transformers/filters/index.d.mts +22 -0
  43. package/dist/transformers/filters/index.d.mts.map +1 -0
  44. package/dist/transformers/filters/index.mjs +67 -0
  45. package/dist/transformers/filters/index.mjs.map +1 -0
  46. package/dist/transformers/index.d.mts +9 -8
  47. package/dist/transformers/index.d.mts.map +1 -1
  48. package/dist/transformers/index.mjs +15 -10
  49. package/dist/transformers/index.mjs.map +1 -1
  50. package/dist/transformers/tailwindcss.d.mts +6 -2
  51. package/dist/transformers/tailwindcss.d.mts.map +1 -1
  52. package/dist/transformers/tailwindcss.mjs +49 -21
  53. package/dist/transformers/tailwindcss.mjs.map +1 -1
  54. package/dist/types/config.d.mts +15 -1
  55. package/dist/types/config.d.mts.map +1 -1
  56. package/dist/types/index.d.mts +2 -2
  57. package/dist/utils/ast/serializer.d.mts +3 -2
  58. package/dist/utils/ast/serializer.d.mts.map +1 -1
  59. package/dist/utils/ast/serializer.mjs +24 -0
  60. package/dist/utils/ast/serializer.mjs.map +1 -1
  61. package/package.json +1 -1
package/dist/build.mjs CHANGED
@@ -59,13 +59,14 @@ async function build(options = {}) {
59
59
  html: rendered.html
60
60
  });
61
61
  const templateConfig = rendered.templateConfig;
62
- if (templateConfig.useTransformers !== false) html = await runTransformers(html, templateConfig, absolutePath);
62
+ const doctype = rendered.doctype ?? templateConfig.doctype ?? "<!DOCTYPE html>";
63
+ if (templateConfig.useTransformers !== false) html = await runTransformers(html, templateConfig, absolutePath, doctype);
63
64
  html = await events.fireAfterTransform({
64
65
  config,
65
66
  template,
66
67
  html
67
68
  });
68
- html = `${rendered.doctype ?? templateConfig.doctype ?? "<!DOCTYPE html>"}\n${html}`;
69
+ html = `${doctype}\n${html}`;
69
70
  const outputFilePath = resolveOutputPath(templatePath, outputPath, outputExtension, contentBase);
70
71
  mkdirSync(dirname(outputFilePath), { recursive: true });
71
72
  writeFileSync(outputFilePath, html);
@@ -1 +1 @@
1
- {"version":3,"file":"build.mjs","names":[],"sources":["../src/build.ts"],"sourcesContent":["import { readFileSync, writeFileSync, mkdirSync, cpSync, existsSync, rmSync } from 'node:fs'\nimport { resolve, dirname, basename, relative, join } from 'node:path'\nimport { glob } from 'tinyglobby'\nimport ora from 'ora'\nimport { resolveConfig } from './config/index.ts'\nimport { EventManager } from './events/index.ts'\nimport { runTransformers } from './transformers/index.ts'\nimport { createRenderer } from './render/createRenderer.ts'\nimport { createPlaintext } from './plaintext.ts'\nimport type { MaizzleConfig } from './types/index.ts'\n\nexport interface BuildOptions {\n config?: Partial<MaizzleConfig> | string\n}\n\nexport interface BuildResult {\n files: string[]\n config: MaizzleConfig\n}\n\n/**\n * Build all SFC email templates to HTML files.\n *\n * Creates a single Renderer instance, then loops through each template\n * calling render → transformers → write to disk.\n */\nexport async function build(options: BuildOptions = {}): Promise<BuildResult> {\n const start = Date.now()\n const spinner = ora('Building templates...').start()\n\n const config = await resolveConfig(options.config)\n\n const events = new EventManager()\n events.registerConfig(config)\n await events.fireBeforeCreate({ config })\n\n const outputPath = resolve(config.output?.path ?? 'dist')\n const outputExtension = config.output?.extension ?? 'html'\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const contentBase = computeContentBase(contentPatterns)\n const templateFiles = await glob(contentPatterns)\n\n if (templateFiles.length === 0) {\n spinner.succeed('No templates found')\n return { files: [], config }\n }\n\n // Clear the output directory before writing fresh output\n if (existsSync(outputPath)) {\n rmSync(outputPath, { recursive: true, force: true })\n }\n\n const renderer = await createRenderer({ markdown: config.markdown, root: config.root, componentDirs: [config.components?.source ?? []].flat() })\n const outputFiles: string[] = []\n\n try {\n for (const templatePath of templateFiles) {\n const absolutePath = resolve(templatePath)\n let template = readFileSync(absolutePath, 'utf-8')\n\n template = await events.fireBeforeRender({ config, template })\n\n const rendered = await renderer.render(absolutePath, config)\n\n let html = await events.fireAfterRender({ config, template, html: rendered.html })\n\n // Use the per-template merged config (from defineConfig() in the SFC) so that\n // template-level overrides like css.safe: false are respected by transformers.\n const templateConfig = rendered.templateConfig\n\n if (templateConfig.useTransformers !== false) {\n html = await runTransformers(html, templateConfig, absolutePath)\n }\n\n html = await events.fireAfterTransform({ config, template, html })\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n html = `${doctype}\\n${html}`\n\n const outputFilePath = resolveOutputPath(templatePath, outputPath, outputExtension, contentBase)\n mkdirSync(dirname(outputFilePath), { recursive: true })\n writeFileSync(outputFilePath, html)\n outputFiles.push(outputFilePath)\n\n // Generate plaintext version if configured\n const globalPlaintext = templateConfig.plaintext\n const sfcPlaintext = rendered.plaintext\n\n if (globalPlaintext || sfcPlaintext) {\n const stripOptions = typeof globalPlaintext === 'object' ? globalPlaintext : {}\n const plaintext = createPlaintext(html, stripOptions)\n const ptExtension = sfcPlaintext?.extension ?? 'txt'\n\n let ptOutputPath: string\n\n if (sfcPlaintext?.destination) {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n ptOutputPath = join(resolve(sfcPlaintext.destination), `${name}.${ptExtension}`)\n } else if (typeof globalPlaintext === 'string') {\n ptOutputPath = resolveOutputPath(templatePath, resolve(globalPlaintext), ptExtension, contentBase)\n } else {\n ptOutputPath = resolveOutputPath(templatePath, outputPath, ptExtension, contentBase)\n }\n\n mkdirSync(dirname(ptOutputPath), { recursive: true })\n writeFileSync(ptOutputPath, plaintext)\n }\n\n // Register SFC event handlers that were collected during render\n for (const { name, handler } of rendered.sfcEventHandlers) {\n events.on(name, handler)\n }\n\n events.clearSfcHandlers()\n }\n\n await copyStatic(config, outputPath)\n await events.fireAfterBuild({ files: outputFiles, config })\n } finally {\n await renderer.close()\n }\n\n const duration = ((Date.now() - start) / 1000).toFixed(2)\n const count = outputFiles.length\n spinner.stopAndPersist({\n symbol: '✅',\n text: `Built ${count} template${count !== 1 ? 's' : ''} in ${duration}s`,\n })\n\n return { files: outputFiles, config }\n}\n\n/**\n * Extract the static (non-glob) prefix from content patterns.\n *\n * For example, `['/abs/path/emails/**\\/*.vue']` → `'/abs/path/emails'`\n *\n * This is used to strip the content base from template paths\n * so the output preserves only the subdirectory structure.\n */\nfunction computeContentBase(patterns: string[]): string {\n // Use the first non-negated pattern\n const pattern = patterns.find(p => !p.startsWith('!')) ?? patterns[0]\n\n // Split on first glob character (* { ? [) and take the directory part\n const staticPart = pattern.split(/[*{?[]/)[0]\n\n // Ensure we have a clean directory path (not a partial segment)\n return resolve(staticPart.endsWith('/') ? staticPart : dirname(staticPart))\n}\n\nfunction resolveOutputPath(templatePath: string, outputDir: string, extension: string, contentBase: string): string {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n const absTemplate = resolve(templatePath)\n const rel = relative(contentBase, dirname(absTemplate))\n\n return join(outputDir, rel, `${name}.${extension}`)\n}\n\nasync function copyStatic(config: MaizzleConfig, outputPath: string): Promise<void> {\n const sources = config.static?.source ?? ['public/**/*.*']\n const destination = config.static?.destination ?? 'public'\n\n const files = await glob(sources)\n\n for (const file of files) {\n const destPath = join(outputPath, destination, relative(dirname(sources[0]).replace(/\\*.*$/, ''), file))\n const destDir = dirname(destPath)\n\n if (!existsSync(destDir)) {\n mkdirSync(destDir, { recursive: true })\n }\n\n cpSync(file, destPath)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,eAAsB,MAAM,UAAwB,EAAE,EAAwB;CAC5E,MAAM,QAAQ,KAAK,KAAK;CACxB,MAAM,UAAU,IAAI,wBAAwB,CAAC,OAAO;CAEpD,MAAM,SAAS,MAAM,cAAc,QAAQ,OAAO;CAElD,MAAM,SAAS,IAAI,cAAc;AACjC,QAAO,eAAe,OAAO;AAC7B,OAAM,OAAO,iBAAiB,EAAE,QAAQ,CAAC;CAEzC,MAAM,aAAa,QAAQ,OAAO,QAAQ,QAAQ,OAAO;CACzD,MAAM,kBAAkB,OAAO,QAAQ,aAAa;CAEpD,MAAM,kBAAkB,OAAO,W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e,GAAG;AAI9D,QAAO,KAAK,WAFA,SAAS,aAAa,QADd,QAAQ,aAAa,CACa,CAAC,EAE3B,GAAG,KAAK,GAAG,YAAY;;AAGrD,eAAe,WAAW,QAAuB,YAAmC;CAClF,MAAM,UAAU,OAAO,QAAQ,UAAU,CAAC,gBAAgB;CAC1D,MAAM,cAAc,OAAO,QAAQ,eAAe;CAElD,MAAM,QAAQ,MAAM,KAAK,QAAQ;AAEjC,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,KAAK,YAAY,aAAa,SAAS,QAAQ,QAAQ,GAAG,CAAC,QAAQ,SAAS,GAAG,EAAE,KAAK,CAAC;EACxG,MAAM,UAAU,QAAQ,SAAS;AAEjC,MAAI,CAAC,WAAW,QAAQ,CACtB,WAAU,SAAS,EAAE,WAAW,MAAM,CAAC;AAGzC,SAAO,MAAM,SAAS"}
1
+ {"version":3,"file":"build.mjs","names":[],"sources":["../src/build.ts"],"sourcesContent":["import { readFileSync, writeFileSync, mkdirSync, cpSync, existsSync, rmSync } from 'node:fs'\nimport { resolve, dirname, basename, relative, join } from 'node:path'\nimport { glob } from 'tinyglobby'\nimport ora from 'ora'\nimport { resolveConfig } from './config/index.ts'\nimport { EventManager } from './events/index.ts'\nimport { runTransformers } from './transformers/index.ts'\nimport { createRenderer } from './render/createRenderer.ts'\nimport { createPlaintext } from './plaintext.ts'\nimport type { MaizzleConfig } from './types/index.ts'\n\nexport interface BuildOptions {\n config?: Partial<MaizzleConfig> | string\n}\n\nexport interface BuildResult {\n files: string[]\n config: MaizzleConfig\n}\n\n/**\n * Build all SFC email templates to HTML files.\n *\n * Creates a single Renderer instance, then loops through each template\n * calling render → transformers → write to disk.\n */\nexport async function build(options: BuildOptions = {}): Promise<BuildResult> {\n const start = Date.now()\n const spinner = ora('Building templates...').start()\n\n const config = await resolveConfig(options.config)\n\n const events = new EventManager()\n events.registerConfig(config)\n await events.fireBeforeCreate({ config })\n\n const outputPath = resolve(config.output?.path ?? 'dist')\n const outputExtension = config.output?.extension ?? 'html'\n\n const contentPatterns = config.content ?? ['emails/**/*.vue']\n const contentBase = computeContentBase(contentPatterns)\n const templateFiles = await glob(contentPatterns)\n\n if (templateFiles.length === 0) {\n spinner.succeed('No templates found')\n return { files: [], config }\n }\n\n // Clear the output directory before writing fresh output\n if (existsSync(outputPath)) {\n rmSync(outputPath, { recursive: true, force: true })\n }\n\n const renderer = await createRenderer({ markdown: config.markdown, root: config.root, componentDirs: [config.components?.source ?? []].flat() })\n const outputFiles: string[] = []\n\n try {\n for (const templatePath of templateFiles) {\n const absolutePath = resolve(templatePath)\n let template = readFileSync(absolutePath, 'utf-8')\n\n template = await events.fireBeforeRender({ config, template })\n\n const rendered = await renderer.render(absolutePath, config)\n\n let html = await events.fireAfterRender({ config, template, html: rendered.html })\n\n // Use the per-template merged config (from defineConfig() in the SFC) so that\n // template-level overrides like css.safe: false are respected by transformers.\n const templateConfig = rendered.templateConfig\n\n const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'\n\n if (templateConfig.useTransformers !== false) {\n html = await runTransformers(html, templateConfig, absolutePath, doctype)\n }\n\n html = await events.fireAfterTransform({ config, template, html })\n html = `${doctype}\\n${html}`\n\n const outputFilePath = resolveOutputPath(templatePath, outputPath, outputExtension, contentBase)\n mkdirSync(dirname(outputFilePath), { recursive: true })\n writeFileSync(outputFilePath, html)\n outputFiles.push(outputFilePath)\n\n // Generate plaintext version if configured\n const globalPlaintext = templateConfig.plaintext\n const sfcPlaintext = rendered.plaintext\n\n if (globalPlaintext || sfcPlaintext) {\n const stripOptions = typeof globalPlaintext === 'object' ? globalPlaintext : {}\n const plaintext = createPlaintext(html, stripOptions)\n const ptExtension = sfcPlaintext?.extension ?? 'txt'\n\n let ptOutputPath: string\n\n if (sfcPlaintext?.destination) {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n ptOutputPath = join(resolve(sfcPlaintext.destination), `${name}.${ptExtension}`)\n } else if (typeof globalPlaintext === 'string') {\n ptOutputPath = resolveOutputPath(templatePath, resolve(globalPlaintext), ptExtension, contentBase)\n } else {\n ptOutputPath = resolveOutputPath(templatePath, outputPath, ptExtension, contentBase)\n }\n\n mkdirSync(dirname(ptOutputPath), { recursive: true })\n writeFileSync(ptOutputPath, plaintext)\n }\n\n // Register SFC event handlers that were collected during render\n for (const { name, handler } of rendered.sfcEventHandlers) {\n events.on(name, handler)\n }\n\n events.clearSfcHandlers()\n }\n\n await copyStatic(config, outputPath)\n await events.fireAfterBuild({ files: outputFiles, config })\n } finally {\n await renderer.close()\n }\n\n const duration = ((Date.now() - start) / 1000).toFixed(2)\n const count = outputFiles.length\n spinner.stopAndPersist({\n symbol: '✅',\n text: `Built ${count} template${count !== 1 ? 's' : ''} in ${duration}s`,\n })\n\n return { files: outputFiles, config }\n}\n\n/**\n * Extract the static (non-glob) prefix from content patterns.\n *\n * For example, `['/abs/path/emails/**\\/*.vue']` → `'/abs/path/emails'`\n *\n * This is used to strip the content base from template paths\n * so the output preserves only the subdirectory structure.\n */\nfunction computeContentBase(patterns: string[]): string {\n // Use the first non-negated pattern\n const pattern = patterns.find(p => !p.startsWith('!')) ?? patterns[0]\n\n // Split on first glob character (* { ? [) and take the directory part\n const staticPart = pattern.split(/[*{?[]/)[0]\n\n // Ensure we have a clean directory path (not a partial segment)\n return resolve(staticPart.endsWith('/') ? staticPart : dirname(staticPart))\n}\n\nfunction resolveOutputPath(templatePath: string, outputDir: string, extension: string, contentBase: string): string {\n const name = basename(templatePath).replace(/\\.(vue|md)$/, '')\n const absTemplate = resolve(templatePath)\n const rel = relative(contentBase, dirname(absTemplate))\n\n return join(outputDir, rel, `${name}.${extension}`)\n}\n\nasync function copyStatic(config: MaizzleConfig, outputPath: string): Promise<void> {\n const sources = config.static?.source ?? ['public/**/*.*']\n const destination = config.static?.destination ?? 'public'\n\n const files = await glob(sources)\n\n for (const file of files) {\n const destPath = join(outputPath, destination, relative(dirname(sources[0]).replace(/\\*.*$/, ''), file))\n const destDir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11
+ default: 'en'
12
+ },
13
+ dir: {
14
+ type: String as PropType<'ltr' | 'rtl'>,
15
+ default: 'ltr'
16
+ }
17
+ },
18
+ setup(props, { slots, attrs }) {
19
+ return () => {
20
+ const extraAttrs = Object.entries(attrs)
21
+ .map(([key, value]) => value === true ? key : `${key}="${value}"`)
22
+ .join(' ')
23
+
24
+ const parts = [
25
+ `xml:lang="${props.xmlLang}"`,
26
+ `dir="${props.dir}"`,
27
+ 'style="margin: 0; padding: 0; width: 100%; word-break: break-word;"',
28
+ ]
29
+
30
+ if (extraAttrs) {
31
+ parts.push(extraAttrs)
32
+ }
33
+
34
+ return [
35
+ createStaticVNode(`<body ${parts.join(' ')}>`, 1),
36
+ slots.default?.(),
37
+ createStaticVNode('</body>', 1),
38
+ ]
39
+ }
40
+ }
41
+ }
42
+ </script>
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, useAttrs } from 'vue'
3
+ import type { PropType } from 'vue'
3
4
  import { twMerge } from 'tailwind-merge'
4
5
  import Outlook from './Outlook.vue'
5
6
 
@@ -10,42 +11,92 @@ const attrs = useAttrs()
10
11
  const props = defineProps({
11
12
  /** The URL the button links to. */
12
13
  href: String,
13
- type: {
14
- type: String,
15
- default: 'solid'
14
+ /**
15
+ * The button style variant.
16
+ * - `solid` — filled background (default)
17
+ * - `outline` — transparent background with a border
18
+ * - `ghost` — transparent background, no border
19
+ * - `link` — plain anchor with no button chrome
20
+ * @default 'solid'
21
+ */
22
+ variant: {
23
+ type: String as PropType<'solid' | 'outline' | 'ghost' | 'link'>,
24
+ default: 'solid' as const
16
25
  },
26
+ /**
27
+ * Horizontal alignment of the button wrapper.
28
+ * Accepts `'left'`, `'center'`, or `'right'`.
29
+ * @default null
30
+ */
17
31
  align: {
18
- type: String,
32
+ type: String as PropType<'left' | 'center' | 'right' | null>,
19
33
  default: null
20
34
  },
35
+ /**
36
+ * Background color for `solid` and `outline` variants.
37
+ * Also used as the text color for `outline` and `ghost` variants when `color` is not set.
38
+ * @default '#4338ca'
39
+ */
21
40
  bgColor: {
22
41
  type: String,
23
42
  default: '#4338ca'
24
43
  },
44
+ /**
45
+ * Explicit text color. When omitted, `solid` buttons use `#fffffe`
46
+ * and all other variants fall back to `bgColor`.
47
+ * @default null
48
+ */
25
49
  color: {
26
50
  type: String,
27
51
  default: null
28
52
  },
53
+ /**
54
+ * `mso-text-raise` value applied to the inner `<span>` elements.
55
+ * Controls vertical text alignment inside the button in old Outlook.
56
+ * @default '16px'
57
+ */
29
58
  msoPt: {
30
59
  type: String,
31
60
  default: '16px'
32
61
  },
62
+ /**
63
+ * `mso-text-raise` value applied to the spacer `<i>` element rendered for Outlook.
64
+ * Adjusts the bottom spacing that old Outlook uses to simulate padding.
65
+ * @default '31px'
66
+ */
33
67
  msoPb: {
34
68
  type: String,
35
69
  default: '31px'
36
70
  },
71
+ /**
72
+ * URL or path to an icon image displayed alongside the button label.
73
+ * @default null
74
+ */
37
75
  icon: {
38
76
  type: String,
39
77
  default: null
40
78
  },
79
+ /**
80
+ * Width of the icon image in pixels.
81
+ * @default 12
82
+ */
41
83
  iconWidth: {
42
84
  type: [String, Number],
43
85
  default: 12
44
86
  },
87
+ /**
88
+ * Side on which the icon is placed relative to the button label.
89
+ * Accepts `'left'` or `'right'`.
90
+ * @default 'right'
91
+ */
45
92
  iconPosition: {
46
- type: String,
47
- default: 'right'
93
+ type: String as PropType<'left' | 'right'>,
94
+ default: 'right' as const
48
95
  },
96
+ /**
97
+ * Additional CSS classes applied to the icon `<img>` element.
98
+ * @default ''
99
+ */
49
100
  iconClass: {
50
101
  type: String,
51
102
  default: ''
@@ -54,20 +105,20 @@ const props = defineProps({
54
105
 
55
106
  const parsedIconWidth = computed(() => parseInt(String(props.iconWidth), 10))
56
107
 
57
- const alignClass = computed(() => ({
108
+ const alignClass = computed(() => props.align ? ({
58
109
  left: 'text-left',
59
110
  center: 'text-center',
60
111
  right: 'text-right',
61
- })[props.align] || '')
112
+ })[props.align] || '' : '')
62
113
 
63
114
  const textColor = computed(() => {
64
115
  if (props.color) return props.color
65
116
 
66
- return props.type === 'solid' ? '#fffffe' : props.bgColor
117
+ return props.variant === 'solid' ? '#fffffe' : props.bgColor
67
118
  })
68
119
 
69
120
  const styles = computed(() => {
70
- if (props.type === 'link') {
121
+ if (props.variant === 'link') {
71
122
  return [
72
123
  'text-decoration: none;',
73
124
  `color: ${textColor.value};`,
@@ -84,12 +135,12 @@ const styles = computed(() => {
84
135
  `color: ${textColor.value};`,
85
136
  ]
86
137
 
87
- if (props.type === 'outline') {
138
+ if (props.variant === 'outline') {
88
139
  base.push(
89
140
  'background-color: transparent;',
90
141
  `border: 1px solid ${props.bgColor};`,
91
142
  )
92
- } else if (props.type === 'ghost') {
143
+ } else if (props.variant === 'ghost') {
93
144
  base.push('background-color: transparent;')
94
145
  } else {
95
146
  base.push(`background-color: ${props.bgColor};`)
@@ -98,10 +149,10 @@ const styles = computed(() => {
98
149
  return base.join('')
99
150
  })
100
151
 
101
- const isLink = computed(() => props.type === 'link')
152
+ const isLink = computed(() => props.variant === 'link')
102
153
 
103
154
  const defaultClasses = computed(() => {
104
- if (props.type === 'ghost') return 'hover:bg-indigo-50'
155
+ if (props.variant === 'ghost') return 'hover:bg-indigo-50'
105
156
  return ''
106
157
  })
107
158
 
@@ -0,0 +1,75 @@
1
+ <script lang="ts">
2
+ import { createStaticVNode } from 'vue'
3
+ import { codeToHtml, getSingletonHighlighter } from 'shiki'
4
+
5
+ export default {
6
+ props: {
7
+ /** The code to highlight. */
8
+ code: {
9
+ type: String,
10
+ default: ''
11
+ },
12
+ /** Base64-encoded code, set by the Vite transform for slot content. */
13
+ encodedCode: {
14
+ type: String,
15
+ default: ''
16
+ },
17
+ /** The language for syntax highlighting. @default 'html' */
18
+ lang: {
19
+ type: String,
20
+ default: 'html'
21
+ },
22
+ /** The shiki theme to use. @default 'github-light' */
23
+ theme: {
24
+ type: String,
25
+ default: 'github-light'
26
+ },
27
+ /** CSS class for the wrapping table cell. @default 'max-w-0 mso-padding-alt-6' */
28
+ tdClass: {
29
+ type: String,
30
+ default: 'max-w-0 mso-padding-alt-6'
31
+ }
32
+ },
33
+ inheritAttrs: false,
34
+ async setup(props, { slots, attrs }) {
35
+ // Prefer encodedCode (from Vite transform) → code prop → slot text
36
+ let source = props.encodedCode
37
+ ? Buffer.from(props.encodedCode, 'base64').toString('utf-8')
38
+ : props.code
39
+
40
+ if (!source) {
41
+ const slotContent = slots.default?.()
42
+ source = slotContent
43
+ ?.map((vnode: any) => (typeof vnode.children === 'string' ? vnode.children : ''))
44
+ .join('') ?? ''
45
+ }
46
+
47
+ source = source.trim()
48
+
49
+ if (!source) {
50
+ return () => createStaticVNode('', 0)
51
+ }
52
+
53
+ const highlighted = await codeToHtml(source, {
54
+ lang: props.lang,
55
+ theme: props.theme,
56
+ })
57
+
58
+ const hl = await getSingletonHighlighter({ themes: [props.theme], langs: [] })
59
+ const bg = hl.getTheme(props.theme).bg
60
+
61
+ // Shiki outputs <pre><code>...</code></pre>, extract the inner content
62
+ const codeContent = highlighted
63
+ .replace(/^<pre[^>]*><code>/, '')
64
+ .replace(/<\/code><\/pre>$/, '')
65
+
66
+ const classes = ['font-mono', attrs.class].filter(Boolean).join(' ')
67
+ const baseStyles = `background-color:${bg};padding:24px;overflow:auto;white-space:pre;word-wrap:normal;word-break:normal;word-spacing:normal`
68
+ const styles = [baseStyles, attrs.style].filter(Boolean).join(';')
69
+
70
+ const html = `<table class="w-full"><tr><td class="${props.tdClass}"><pre class="${classes}" style="${styles}"><code>${codeContent}</code></pre></td></tr></table>`
71
+
72
+ return () => createStaticVNode(html, 1)
73
+ }
74
+ }
75
+ </script>
@@ -0,0 +1,44 @@
1
+ <script lang="ts">
2
+ import { createStaticVNode } from 'vue'
3
+
4
+ export default {
5
+ inheritAttrs: false,
6
+ props: {
7
+ /** The inline code text. */
8
+ code: {
9
+ type: String,
10
+ default: ''
11
+ }
12
+ },
13
+ setup(props, { slots, attrs }) {
14
+ let source = props.code
15
+
16
+ if (!source) {
17
+ const slotContent = slots.default?.()
18
+ source = slotContent
19
+ ?.map((vnode: any) => (typeof vnode.children === 'string' ? vnode.children : ''))
20
+ .join('') ?? ''
21
+ }
22
+
23
+ source = source.trim()
24
+
25
+ if (!source) {
26
+ return () => createStaticVNode('', 0)
27
+ }
28
+
29
+ const classes = attrs.class ? ` class="${attrs.class}"` : ''
30
+ const baseStyles = 'white-space:normal;border-radius:6px;border:1px solid #d1d5db;background-color:#f3f4f6;padding:2px 6px;font-size:11px;color:inherit'
31
+ const styles = [baseStyles, attrs.style].filter(Boolean).join(';')
32
+
33
+ const escaped = source
34
+ .replace(/&/g, '&amp;')
35
+ .replace(/</g, '&lt;')
36
+ .replace(/>/g, '&gt;')
37
+ .replace(/"/g, '&quot;')
38
+
39
+ const html = `<code${classes} style="${styles}">${escaped}</code>`
40
+
41
+ return () => createStaticVNode(html, 1)
42
+ }
43
+ }
44
+ </script>
@@ -0,0 +1,61 @@
1
+ <script setup lang="ts">
2
+ import { computed, createStaticVNode, inject, useAttrs } from 'vue'
3
+ import type { ComputedRef } from 'vue'
4
+ import { normalizeToPixels } from './utils.ts'
5
+
6
+ defineOptions({ inheritAttrs: false })
7
+
8
+ const attrs = useAttrs()
9
+
10
+ const props = defineProps({
11
+ /** Override the auto-computed min-width. */
12
+ width: {
13
+ type: [String, Number],
14
+ default: null
15
+ }
16
+ })
17
+
18
+ const injectedMinWidth = inject<ComputedRef<string> | null>('columnMinWidth', null)
19
+ const containerWidth = inject<ComputedRef<string | number> | null>('containerWidth', null)
20
+ const injectedMsoWidth = inject<ComputedRef<string> | null>('columnMsoWidth', null)
21
+
22
+ const minWidth = computed(() => {
23
+ if (props.width) return normalizeToPixels(props.width)
24
+ if (injectedMinWidth?.value) return injectedMinWidth.value
25
+
26
+ // Fallback: divide container width by 2 if available
27
+ if (containerWidth?.value) {
28
+ const val = containerWidth.value
29
+ if (typeof val === 'number') return `${val / 2}px`
30
+ const num = Number.parseFloat(val)
31
+ const unit = val.replace(String(num), '') || 'px'
32
+ return `${num / 2}${unit}`
33
+ }
34
+
35
+ return '18.75em'
36
+ })
37
+
38
+ const msoWidth = computed(() => injectedMsoWidth?.value ?? '50%')
39
+
40
+ const styles = computed(() => {
41
+ return `display: inline-block; min-width: ${minWidth.value}; font-size: 16px; vertical-align: top;`
42
+ })
43
+
44
+ const MsoBefore = () => createStaticVNode(
45
+ `<!--[if mso]><td width="${msoWidth.value}" style="vertical-align:top"><![endif]-->`,
46
+ 1
47
+ )
48
+
49
+ const MsoAfter = () => createStaticVNode(
50
+ '<!--[if mso]></td><![endif]-->',
51
+ 1
52
+ )
53
+ </script>
54
+
55
+ <template>
56
+ <MsoBefore />
57
+ <div v-bind="attrs" :style="styles">
58
+ <slot />
59
+ </div>
60
+ <MsoAfter />
61
+ </template>
@@ -0,0 +1,40 @@
1
+ <script setup lang="ts">
2
+ import { computed, provide, createStaticVNode, useAttrs } from 'vue'
3
+ import { normalizeToPixels } from './utils.ts'
4
+
5
+ defineOptions({ inheritAttrs: false })
6
+
7
+ const attrs = useAttrs()
8
+
9
+ const props = defineProps({
10
+ /** Max width of the container. */
11
+ width: {
12
+ type: [String, Number],
13
+ default: '37.5em'
14
+ }
15
+ })
16
+
17
+ provide('containerWidth', computed(() => props.width))
18
+
19
+ const styles = computed(() => {
20
+ return `max-width: ${normalizeToPixels(props.width)}; margin: 0 auto;`
21
+ })
22
+
23
+ const MsoBefore = () => createStaticVNode(
24
+ `<!--[if mso]><table role="none" cellpadding="0" cellspacing="0" style="width:${normalizeToPixels(props.width)}" align="center"><tr><td><![endif]-->`,
25
+ 1
26
+ )
27
+
28
+ const MsoAfter = () => createStaticVNode(
29
+ '<!--[if mso]></td></tr></table><![endif]-->',
30
+ 1
31
+ )
32
+ </script>
33
+
34
+ <template>
35
+ <MsoBefore />
36
+ <div v-bind="attrs" :style="styles">
37
+ <slot />
38
+ </div>
39
+ <MsoAfter />
40
+ </template>
@@ -0,0 +1,8 @@
1
+ <template>
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <meta name="x-apple-disable-message-reformatting">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <slot />
7
+ </head>
8
+ </template>
@@ -0,0 +1,53 @@
1
+ <script lang="ts">
2
+ import { createStaticVNode } from 'vue'
3
+ import type { PropType } from 'vue'
4
+
5
+ export default {
6
+ name: 'Html',
7
+ inheritAttrs: false,
8
+ props: {
9
+ lang: {
10
+ type: String,
11
+ default: 'en'
12
+ },
13
+ dir: {
14
+ type: String as PropType<'ltr' | 'rtl'>,
15
+ default: 'ltr'
16
+ },
17
+ xmlns: {
18
+ type: String,
19
+ default: null
20
+ }
21
+ },
22
+ setup(props, { slots, attrs }) {
23
+ return () => {
24
+ const extraAttrs = Object.entries(attrs)
25
+ .map(([key, value]) => value === true ? key : `${key}="${value}"`)
26
+ .join(' ')
27
+
28
+ const parts = [
29
+ `lang="${props.lang}"`,
30
+ `dir="${props.dir}"`,
31
+ ]
32
+
33
+ if (props.xmlns) {
34
+ parts.push(
35
+ `xmlns="${props.xmlns}"`,
36
+ 'xmlns:v="urn:schemas-microsoft-com:vml"',
37
+ 'xmlns:o="urn:schemas-microsoft-com:office:office"',
38
+ )
39
+ }
40
+
41
+ if (extraAttrs) {
42
+ parts.push(extraAttrs)
43
+ }
44
+
45
+ return [
46
+ createStaticVNode(`<html ${parts.join(' ')}>`, 1),
47
+ slots.default?.(),
48
+ createStaticVNode('</html>', 1),
49
+ ]
50
+ }
51
+ }
52
+ }
53
+ </script>
@@ -0,0 +1,70 @@
1
+ <script setup lang="ts">
2
+ import { computed, useAttrs } from 'vue'
3
+
4
+ defineOptions({ inheritAttrs: false })
5
+
6
+ const attrs = useAttrs()
7
+
8
+ const props = defineProps({
9
+ /** The image source URL. When reducedMotionSrc is used, this becomes the static fallback. */
10
+ src: {
11
+ type: String,
12
+ required: true
13
+ },
14
+ /** Alt text for the image. */
15
+ alt: {
16
+ type: String,
17
+ default: ''
18
+ },
19
+ /** Image source for dark mode. */
20
+ darkSrc: {
21
+ type: String,
22
+ default: null
23
+ },
24
+ /** The width of the image, rendered without units. */
25
+ width: {
26
+ type: [String, Number],
27
+ required: true
28
+ },
29
+ /** Animated image source, shown when user has no reduced motion preference. */
30
+ reducedMotionSrc: {
31
+ type: String,
32
+ default: null
33
+ }
34
+ })
35
+
36
+ function mimeFromExtension(src: string): string {
37
+ const ext = src.split('.').pop()?.toLowerCase() ?? ''
38
+
39
+ const types: Record<string, string> = {
40
+ apng: 'image/apng',
41
+ avif: 'image/avif',
42
+ gif: 'image/gif',
43
+ jpg: 'image/jpeg',
44
+ jpeg: 'image/jpeg',
45
+ jfif: 'image/jpeg',
46
+ png: 'image/png',
47
+ svg: 'image/svg+xml',
48
+ webp: 'image/webp',
49
+ }
50
+
51
+ return types[ext] ?? ''
52
+ }
53
+
54
+ const reducedMotionType = computed(() => mimeFromExtension(props.reducedMotionSrc ?? ''))
55
+
56
+ const imgWidth = computed(() => Number.parseInt(String(props.width), 10))
57
+
58
+ const usePicture = computed(() => props.darkSrc || props.reducedMotionSrc)
59
+
60
+ const imgStyle = 'max-width: 100%; vertical-align: middle;'
61
+ </script>
62
+
63
+ <template>
64
+ <picture v-if="usePicture">
65
+ <source v-if="darkSrc" :srcset="darkSrc" media="(prefers-color-scheme: dark)">
66
+ <source v-if="reducedMotionSrc" :srcset="reducedMotionSrc" :type="reducedMotionType || undefined" media="(prefers-reduced-motion: no-preference)">
67
+ <img v-bind="attrs" :src="src" :alt="alt" :width="imgWidth" :style="imgStyle">
68
+ </picture>
69
+ <img v-else v-bind="attrs" :src="src" :alt="alt" :width="imgWidth" :style="imgStyle">
70
+ </template>