@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.
- package/dist/build.mjs +3 -2
- package/dist/build.mjs.map +1 -1
- package/dist/components/Body.vue +42 -0
- package/dist/components/Button.vue +65 -14
- package/dist/components/CodeBlock.vue +75 -0
- package/dist/components/CodeInline.vue +44 -0
- package/dist/components/Column.vue +61 -0
- package/dist/components/Container.vue +40 -0
- package/dist/components/Head.vue +8 -0
- package/dist/components/Html.vue +53 -0
- package/dist/components/Image.vue +70 -0
- package/dist/components/Overlap.vue +60 -0
- package/dist/components/Preview.vue +20 -0
- package/dist/components/Row.vue +80 -0
- package/dist/components/Spacer.vue +50 -7
- package/dist/composables/renderContext.d.mts +5 -0
- package/dist/composables/renderContext.d.mts.map +1 -1
- package/dist/composables/renderContext.mjs.map +1 -1
- package/dist/composables/usePreviewText.d.mts +24 -0
- package/dist/composables/usePreviewText.d.mts.map +1 -0
- package/dist/composables/usePreviewText.mjs +29 -0
- package/dist/composables/usePreviewText.mjs.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +2 -1
- package/dist/render/createRenderer.d.mts +1 -0
- package/dist/render/createRenderer.d.mts.map +1 -1
- package/dist/render/createRenderer.mjs +60 -1
- package/dist/render/createRenderer.mjs.map +1 -1
- package/dist/render/index.mjs +3 -2
- package/dist/render/index.mjs.map +1 -1
- package/dist/serve.d.mts.map +1 -1
- package/dist/serve.mjs +31 -20
- package/dist/serve.mjs.map +1 -1
- package/dist/server/ui/pages/Preview.vue +11 -5
- package/dist/transformers/entities.d.mts.map +1 -1
- package/dist/transformers/entities.mjs +3 -0
- package/dist/transformers/entities.mjs.map +1 -1
- package/dist/transformers/filters/defaults.d.mts +6 -0
- package/dist/transformers/filters/defaults.d.mts.map +1 -0
- package/dist/transformers/filters/defaults.mjs +78 -0
- package/dist/transformers/filters/defaults.mjs.map +1 -0
- package/dist/transformers/filters/index.d.mts +22 -0
- package/dist/transformers/filters/index.d.mts.map +1 -0
- package/dist/transformers/filters/index.mjs +67 -0
- package/dist/transformers/filters/index.mjs.map +1 -0
- package/dist/transformers/index.d.mts +9 -8
- package/dist/transformers/index.d.mts.map +1 -1
- package/dist/transformers/index.mjs +15 -10
- package/dist/transformers/index.mjs.map +1 -1
- package/dist/transformers/tailwindcss.d.mts +6 -2
- package/dist/transformers/tailwindcss.d.mts.map +1 -1
- package/dist/transformers/tailwindcss.mjs +49 -21
- package/dist/transformers/tailwindcss.mjs.map +1 -1
- package/dist/types/config.d.mts +15 -1
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/utils/ast/serializer.d.mts +3 -2
- package/dist/utils/ast/serializer.d.mts.map +1 -1
- package/dist/utils/ast/serializer.mjs +24 -0
- package/dist/utils/ast/serializer.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useAttrs, createStaticVNode } 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 height of the overlapped (background) content. */
|
|
11
|
+
height: {
|
|
12
|
+
type: [String, Number],
|
|
13
|
+
required: true
|
|
14
|
+
},
|
|
15
|
+
/** Width of the overlay table and VML rect. */
|
|
16
|
+
width: {
|
|
17
|
+
type: [String, Number],
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
/** Height of the VML rect for Outlook. Defaults to height. */
|
|
21
|
+
msoHeight: {
|
|
22
|
+
type: [String, Number],
|
|
23
|
+
default: null
|
|
24
|
+
},
|
|
25
|
+
/** VML textbox inset value for Outlook positioning. */
|
|
26
|
+
msoInset: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: '0,-60px,0,0'
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const backgroundStyles = computed(() => {
|
|
33
|
+
return `max-height: ${normalizeToPixels(props.height)}; margin: 0 auto; text-align: center;`
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const vmlOpen = computed(() => {
|
|
37
|
+
const w = normalizeToPixels(props.width)
|
|
38
|
+
const h = normalizeToPixels(props.msoHeight ?? props.height)
|
|
39
|
+
|
|
40
|
+
return `<!--[if mso]><v:rect xmlns:v="urn:schemas-microsoft-com:vml" stroked="f" filled="f" style="width:${w};height:${h};"><v:textbox inset="${props.msoInset}"><![endif]-->`
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const VmlBefore = () => createStaticVNode(vmlOpen.value, 1)
|
|
44
|
+
const VmlAfter = () => createStaticVNode('<!--[if mso]></v:textbox></v:rect><![endif]-->', 1)
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<div v-bind="attrs" :style="backgroundStyles">
|
|
49
|
+
<slot />
|
|
50
|
+
</div>
|
|
51
|
+
<table style="max-height: 0; position: relative; opacity: 0.999;">
|
|
52
|
+
<tr>
|
|
53
|
+
<td :style="`width: ${normalizeToPixels(props.width)}; max-width: 100%; vertical-align: top;`">
|
|
54
|
+
<VmlBefore />
|
|
55
|
+
<slot name="overlay" />
|
|
56
|
+
<VmlAfter />
|
|
57
|
+
</td>
|
|
58
|
+
</tr>
|
|
59
|
+
</table>
|
|
60
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
/** Number of ` ͏` filler pairs to render. */
|
|
4
|
+
fillerCount: {
|
|
5
|
+
type: Number,
|
|
6
|
+
default: 150
|
|
7
|
+
},
|
|
8
|
+
/** Number of `­` entities to render. */
|
|
9
|
+
shyCount: {
|
|
10
|
+
type: Number,
|
|
11
|
+
default: 150
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<Teleport to="body:start">
|
|
18
|
+
<div style="display:none"><slot /><template v-for="i in fillerCount" :key="'f'+i"> ͏ </template><template v-for="i in shyCount" :key="'s'+i">­ </template> </div>
|
|
19
|
+
</Teleport>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Comment, computed, createStaticVNode, inject, provide, useAttrs, useSlots, Fragment } from 'vue'
|
|
3
|
+
import type { ComputedRef, VNode } from 'vue'
|
|
4
|
+
|
|
5
|
+
defineOptions({ inheritAttrs: false })
|
|
6
|
+
|
|
7
|
+
const attrs = useAttrs()
|
|
8
|
+
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
/** Override the inherited container width. */
|
|
11
|
+
width: {
|
|
12
|
+
type: [String, Number],
|
|
13
|
+
default: null
|
|
14
|
+
},
|
|
15
|
+
/** Override the auto-detected column count. */
|
|
16
|
+
cols: {
|
|
17
|
+
type: Number,
|
|
18
|
+
default: null
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const slots = useSlots()
|
|
23
|
+
|
|
24
|
+
function countChildren(vnodes: VNode[]): number {
|
|
25
|
+
let count = 0
|
|
26
|
+
|
|
27
|
+
for (const vnode of vnodes) {
|
|
28
|
+
if (vnode.type === Fragment && Array.isArray(vnode.children)) {
|
|
29
|
+
count += countChildren(vnode.children as VNode[])
|
|
30
|
+
} else if (vnode.type !== Comment && typeof vnode.type !== 'symbol') {
|
|
31
|
+
count++
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return count
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const columnCount = computed(() => {
|
|
39
|
+
if (props.cols) return props.cols
|
|
40
|
+
|
|
41
|
+
const children = slots.default?.() ?? []
|
|
42
|
+
return countChildren(children) || 1
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const containerWidth = inject<ComputedRef<string | number> | null>('containerWidth', null)
|
|
46
|
+
|
|
47
|
+
const rowWidth = computed(() => props.width ?? containerWidth?.value ?? '37.5em')
|
|
48
|
+
|
|
49
|
+
function divideValue(value: string | number, divisor: number): string {
|
|
50
|
+
if (typeof value === 'number') {
|
|
51
|
+
return `${value / divisor}px`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const num = Number.parseFloat(value)
|
|
55
|
+
const unit = value.replace(String(num), '') || 'px'
|
|
56
|
+
|
|
57
|
+
return `${num / divisor}${unit}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
provide('columnMinWidth', computed(() => divideValue(rowWidth.value, columnCount.value)))
|
|
61
|
+
provide('columnMsoWidth', computed(() => `${Math.round(100 / columnCount.value)}%`))
|
|
62
|
+
|
|
63
|
+
const MsoBefore = () => createStaticVNode(
|
|
64
|
+
'<!--[if mso]><table role="none" cellpadding="0" cellspacing="0" width="100%"><tr><![endif]-->',
|
|
65
|
+
1
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const MsoAfter = () => createStaticVNode(
|
|
69
|
+
'<!--[if mso]></tr></table><![endif]-->',
|
|
70
|
+
1
|
|
71
|
+
)
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<template>
|
|
75
|
+
<MsoBefore />
|
|
76
|
+
<div v-bind="attrs" style="width: 100%; font-size: 0;">
|
|
77
|
+
<slot />
|
|
78
|
+
</div>
|
|
79
|
+
<MsoAfter />
|
|
80
|
+
</template>
|
|
@@ -3,11 +3,21 @@ import { computed } from 'vue'
|
|
|
3
3
|
import { normalizeToPixels } from './utils.ts'
|
|
4
4
|
|
|
5
5
|
const props = defineProps({
|
|
6
|
-
/** The
|
|
7
|
-
|
|
6
|
+
/** The type of spacer. */
|
|
7
|
+
type: {
|
|
8
|
+
type: String as () => 'vertical' | 'horizontal',
|
|
9
|
+
default: 'vertical'
|
|
10
|
+
},
|
|
11
|
+
/** The height of the spacer (vertical). */
|
|
12
|
+
height: {
|
|
8
13
|
type: [String, Number],
|
|
9
14
|
default: null
|
|
10
15
|
},
|
|
16
|
+
/** The width of the spacer (horizontal). */
|
|
17
|
+
width: {
|
|
18
|
+
type: [String, Number],
|
|
19
|
+
default: 16
|
|
20
|
+
},
|
|
11
21
|
/** The alternative height to use in Outlook. */
|
|
12
22
|
msoHeight: {
|
|
13
23
|
type: [String, Number],
|
|
@@ -15,11 +25,16 @@ const props = defineProps({
|
|
|
15
25
|
}
|
|
16
26
|
})
|
|
17
27
|
|
|
18
|
-
|
|
28
|
+
function parsePixelValue(value: string | number): number {
|
|
29
|
+
if (typeof value === 'number') return value
|
|
30
|
+
return Number.parseFloat(value) || 0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const verticalStyles = computed(() => {
|
|
19
34
|
const s = []
|
|
20
35
|
|
|
21
|
-
if (props.
|
|
22
|
-
s.push(`line-height: ${normalizeToPixels(props.
|
|
36
|
+
if (props.height) {
|
|
37
|
+
s.push(`line-height: ${normalizeToPixels(props.height)};`)
|
|
23
38
|
}
|
|
24
39
|
|
|
25
40
|
if (props.msoHeight) {
|
|
@@ -28,9 +43,37 @@ const styles = computed(() => {
|
|
|
28
43
|
|
|
29
44
|
return s.join('')
|
|
30
45
|
})
|
|
46
|
+
|
|
47
|
+
const horizontalStyles = computed(() => {
|
|
48
|
+
return `display:inline-block; width: ${normalizeToPixels(props.width)}; font-size: 16px;${msoFontWidth.value}`
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const msoFontWidth = computed(() => {
|
|
52
|
+
const widthPx = parsePixelValue(props.width)
|
|
53
|
+
const emspBase = 16
|
|
54
|
+
const maxPercent = 500
|
|
55
|
+
const maxPerEmsp = emspBase * (maxPercent / 100)
|
|
56
|
+
const numEmsps = Math.ceil(widthPx / maxPerEmsp)
|
|
57
|
+
const percent = Math.round((widthPx / (numEmsps * emspBase)) * 100)
|
|
58
|
+
|
|
59
|
+
return ` mso-font-width:${percent}%;`
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const emspCount = computed(() => {
|
|
63
|
+
const widthPx = parsePixelValue(props.width)
|
|
64
|
+
const maxPerEmsp = 16 * 5
|
|
65
|
+
return Math.ceil(widthPx / maxPerEmsp)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const emsps = computed(() => '\u2003'.repeat(emspCount.value))
|
|
31
69
|
</script>
|
|
32
70
|
|
|
33
71
|
<template>
|
|
34
|
-
<
|
|
35
|
-
|
|
72
|
+
<template v-if="type === 'horizontal'">
|
|
73
|
+
<i :style="horizontalStyles">{{ emsps }}</i>
|
|
74
|
+
</template>
|
|
75
|
+
<template v-else>
|
|
76
|
+
<div v-if="height" role="separator" :style="verticalStyles">‍</div>
|
|
77
|
+
<div v-else role="separator">‍</div>
|
|
78
|
+
</template>
|
|
36
79
|
</template>
|
|
@@ -6,6 +6,11 @@ import { InjectionKey } from "vue";
|
|
|
6
6
|
//#region src/composables/renderContext.d.ts
|
|
7
7
|
interface RenderContext {
|
|
8
8
|
doctype?: string;
|
|
9
|
+
previewText?: {
|
|
10
|
+
text: string;
|
|
11
|
+
fillerCount: number;
|
|
12
|
+
shyCount: number;
|
|
13
|
+
};
|
|
9
14
|
sfcConfig?: MaizzleConfig;
|
|
10
15
|
sfcEventHandlers: Array<{
|
|
11
16
|
name: EventName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderContext.d.mts","names":[],"sources":["../../src/composables/renderContext.ts"],"mappings":";;;;;;UAKiB,aAAA;EACf,OAAA;EACA,SAAA,GAAY,aAAA;EACZ,gBAAA,EAAkB,KAAA;IAAQ,IAAA,EAAM,SAAA;IAAW,OAAA,EAAS,QAAA,CAAS,SAAA;EAAA;EAC7D,SAAA,GAAY,mBAAA;AAAA;AAAA,cAGD,gBAAA,EAAkB,YAAA,CAAa,aAAA"}
|
|
1
|
+
{"version":3,"file":"renderContext.d.mts","names":[],"sources":["../../src/composables/renderContext.ts"],"mappings":";;;;;;UAKiB,aAAA;EACf,OAAA;EACA,WAAA;IAAgB,IAAA;IAAc,WAAA;IAAqB,QAAA;EAAA;EACnD,SAAA,GAAY,aAAA;EACZ,gBAAA,EAAkB,KAAA;IAAQ,IAAA,EAAM,SAAA;IAAW,OAAA,EAAS,QAAA,CAAS,SAAA;EAAA;EAC7D,SAAA,GAAY,mBAAA;AAAA;AAAA,cAGD,gBAAA,EAAkB,YAAA,CAAa,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderContext.mjs","names":[],"sources":["../../src/composables/renderContext.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport type { EventName, EventMap } from '../events/index.ts'\nimport type { UsePlaintextOptions } from './usePlaintext.ts'\n\nexport interface RenderContext {\n doctype?: string\n sfcConfig?: MaizzleConfig\n sfcEventHandlers: Array<{ name: EventName; handler: EventMap[EventName] }>\n plaintext?: UsePlaintextOptions\n}\n\nexport const RenderContextKey: InjectionKey<RenderContext> = Symbol('RenderContext')\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"renderContext.mjs","names":[],"sources":["../../src/composables/renderContext.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport type { EventName, EventMap } from '../events/index.ts'\nimport type { UsePlaintextOptions } from './usePlaintext.ts'\n\nexport interface RenderContext {\n doctype?: string\n previewText?: { text: string; fillerCount: number; shyCount: number }\n sfcConfig?: MaizzleConfig\n sfcEventHandlers: Array<{ name: EventName; handler: EventMap[EventName] }>\n plaintext?: UsePlaintextOptions\n}\n\nexport const RenderContextKey: InjectionKey<RenderContext> = Symbol('RenderContext')\n"],"mappings":";AAaA,MAAa,mBAAgD,OAAO,gBAAgB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/composables/usePreviewText.d.ts
|
|
2
|
+
interface UsePreviewTextOptions {
|
|
3
|
+
/** Number of  ͏ filler pairs to render. @default 150 */
|
|
4
|
+
fillerCount?: number;
|
|
5
|
+
/** Number of ­ entities to render. @default 150 */
|
|
6
|
+
shyCount?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Set the preview/preheader text for the current email template.
|
|
10
|
+
*
|
|
11
|
+
* Injects a hidden `<div>` at the start of `<body>` with the preview text
|
|
12
|
+
* followed by filler characters that prevent email clients from pulling
|
|
13
|
+
* in body content after the preheader.
|
|
14
|
+
*
|
|
15
|
+
* Usage in SFC <script setup>:
|
|
16
|
+
* ```ts
|
|
17
|
+
* usePreviewText('Thanks for signing up!')
|
|
18
|
+
* usePreviewText('Welcome!', { fillerCount: 200, shyCount: 200 })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function usePreviewText(text: string, options?: UsePreviewTextOptions): void;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { UsePreviewTextOptions, usePreviewText };
|
|
24
|
+
//# sourceMappingURL=usePreviewText.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreviewText.d.mts","names":[],"sources":["../../src/composables/usePreviewText.ts"],"mappings":";UAGiB,qBAAA;EAAA;EAEf,WAAA;;EAEA,QAAA;AAAA;AAgBF;;;;;;;;;;;;;AAAA,iBAAgB,cAAA,CAAe,IAAA,UAAc,OAAA,GAAU,qBAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RenderContextKey } from "./renderContext.mjs";
|
|
2
|
+
import { inject } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/composables/usePreviewText.ts
|
|
5
|
+
/**
|
|
6
|
+
* Set the preview/preheader text for the current email template.
|
|
7
|
+
*
|
|
8
|
+
* Injects a hidden `<div>` at the start of `<body>` with the preview text
|
|
9
|
+
* followed by filler characters that prevent email clients from pulling
|
|
10
|
+
* in body content after the preheader.
|
|
11
|
+
*
|
|
12
|
+
* Usage in SFC <script setup>:
|
|
13
|
+
* ```ts
|
|
14
|
+
* usePreviewText('Thanks for signing up!')
|
|
15
|
+
* usePreviewText('Welcome!', { fillerCount: 200, shyCount: 200 })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function usePreviewText(text, options) {
|
|
19
|
+
const ctx = inject(RenderContextKey);
|
|
20
|
+
if (ctx) ctx.previewText = {
|
|
21
|
+
text,
|
|
22
|
+
fillerCount: options?.fillerCount ?? 150,
|
|
23
|
+
shyCount: options?.shyCount ?? 150
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { usePreviewText };
|
|
29
|
+
//# sourceMappingURL=usePreviewText.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreviewText.mjs","names":[],"sources":["../../src/composables/usePreviewText.ts"],"sourcesContent":["import { inject } from 'vue'\nimport { RenderContextKey } from './renderContext.ts'\n\nexport interface UsePreviewTextOptions {\n /** Number of  ͏ filler pairs to render. @default 150 */\n fillerCount?: number\n /** Number of ­ entities to render. @default 150 */\n shyCount?: number\n}\n\n/**\n * Set the preview/preheader text for the current email template.\n *\n * Injects a hidden `<div>` at the start of `<body>` with the preview text\n * followed by filler characters that prevent email clients from pulling\n * in body content after the preheader.\n *\n * Usage in SFC <script setup>:\n * ```ts\n * usePreviewText('Thanks for signing up!')\n * usePreviewText('Welcome!', { fillerCount: 200, shyCount: 200 })\n * ```\n */\nexport function usePreviewText(text: string, options?: UsePreviewTextOptions): void {\n const ctx = inject(RenderContextKey)\n if (ctx) {\n ctx.previewText = {\n text,\n fillerCount: options?.fillerCount ?? 150,\n shyCount: options?.shyCount ?? 150,\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,SAAgB,eAAe,MAAc,SAAuC;CAClF,MAAM,MAAM,OAAO,iBAAiB;AACpC,KAAI,IACF,KAAI,cAAc;EAChB;EACA,aAAa,SAAS,eAAe;EACrC,UAAU,SAAS,YAAY;EAChC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AttributesConfig, CssConfig, EntitiesConfig, HtmlConfig, MaizzleConfig, UrlConfig, UrlQuery, UrlQueryOptions } from "./types/config.mjs";
|
|
1
|
+
import { AttributesConfig, CssConfig, EntitiesConfig, FilterFunction, FiltersConfig, HtmlConfig, MaizzleConfig, UrlConfig, UrlQuery, UrlQueryOptions } from "./types/config.mjs";
|
|
2
2
|
import { build } from "./build.mjs";
|
|
3
3
|
import { defineConfig } from "./composables/defineConfig.mjs";
|
|
4
4
|
import { usePlaintext } from "./composables/usePlaintext.mjs";
|
|
@@ -22,8 +22,9 @@ import { shorthandCSS } from "./transformers/shorthandCSS.mjs";
|
|
|
22
22
|
import { removeAttributes } from "./transformers/removeAttributes.mjs";
|
|
23
23
|
import { addAttributes } from "./transformers/addAttributes.mjs";
|
|
24
24
|
import { purgeCSS } from "./transformers/purgeCSS.mjs";
|
|
25
|
+
import { filters } from "./transformers/filters/index.mjs";
|
|
25
26
|
import { replaceStrings } from "./transformers/replaceStrings.mjs";
|
|
26
27
|
import { format } from "./transformers/format.mjs";
|
|
27
28
|
import { minify } from "./transformers/minify.mjs";
|
|
28
29
|
import { useHead } from "@unhead/vue";
|
|
29
|
-
export { type AttributesConfig, type CreateRendererOptions, type CssConfig, type EntitiesConfig, type HtmlConfig, type MaizzleConfig, type RenderOptions, type RenderResult, type RenderedTemplate, type Renderer, type UrlConfig, type UrlQuery, type UrlQueryOptions, addAttributes, attributeToStyle, base, build, createPlaintext, createRenderer, defineConfig, entities, format, inlineCSS, inlineLink, maizzle, minify, removeAttributes, purgeCSS as removeUnusedCSS, render, replaceStrings, resolveConfig, safeClassNames, serve, shorthandCSS, urlQuery, useConfig, useDoctype, useEvent, useHead, usePlaintext };
|
|
30
|
+
export { type AttributesConfig, type CreateRendererOptions, type CssConfig, type EntitiesConfig, type FilterFunction, type FiltersConfig, type HtmlConfig, type MaizzleConfig, type RenderOptions, type RenderResult, type RenderedTemplate, type Renderer, type UrlConfig, type UrlQuery, type UrlQueryOptions, addAttributes, attributeToStyle, base, build, createPlaintext, createRenderer, defineConfig, entities, filters, format, inlineCSS, inlineLink, maizzle, minify, removeAttributes, purgeCSS as removeUnusedCSS, render, replaceStrings, resolveConfig, safeClassNames, serve, shorthandCSS, urlQuery, useConfig, useDoctype, useEvent, useHead, usePlaintext };
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { inlineCSS } from "./transformers/inlineCSS.mjs";
|
|
|
8
8
|
import { removeAttributes } from "./transformers/removeAttributes.mjs";
|
|
9
9
|
import { shorthandCSS } from "./transformers/shorthandCSS.mjs";
|
|
10
10
|
import { addAttributes } from "./transformers/addAttributes.mjs";
|
|
11
|
+
import { filters } from "./transformers/filters/index.mjs";
|
|
11
12
|
import { base } from "./transformers/base.mjs";
|
|
12
13
|
import { entities } from "./transformers/entities.mjs";
|
|
13
14
|
import { urlQuery } from "./transformers/urlQuery.mjs";
|
|
@@ -26,4 +27,4 @@ import { useEvent } from "./composables/useEvent.mjs";
|
|
|
26
27
|
import { usePlaintext } from "./composables/usePlaintext.mjs";
|
|
27
28
|
import { useHead } from "@unhead/vue";
|
|
28
29
|
|
|
29
|
-
export { addAttributes, attributeToStyle, base, build, createPlaintext, createRenderer, defineConfig, entities, format, inlineCSS, inlineLink, maizzle, minify, removeAttributes, purgeCSS as removeUnusedCSS, render, replaceStrings, resolveConfig, safeClassNames, serve, shorthandCSS, urlQuery, useConfig, useDoctype, useEvent, useHead, usePlaintext };
|
|
30
|
+
export { addAttributes, attributeToStyle, base, build, createPlaintext, createRenderer, defineConfig, entities, filters, format, inlineCSS, inlineLink, maizzle, minify, removeAttributes, purgeCSS as removeUnusedCSS, render, replaceStrings, resolveConfig, safeClassNames, serve, shorthandCSS, urlQuery, useConfig, useDoctype, useEvent, useHead, usePlaintext };
|
|
@@ -14,6 +14,7 @@ interface RenderedTemplate {
|
|
|
14
14
|
interface Renderer {
|
|
15
15
|
render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate>;
|
|
16
16
|
invalidate(filePath: string): Promise<void>;
|
|
17
|
+
invalidateAll(): Promise<void>;
|
|
17
18
|
close(): Promise<void>;
|
|
18
19
|
}
|
|
19
20
|
interface CreateRendererOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderer.d.mts","names":[],"sources":["../../src/render/createRenderer.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"createRenderer.d.mts","names":[],"sources":["../../src/render/createRenderer.ts"],"mappings":";;;;;;UA2EiB,gBAAA;EACf,IAAA;EACA,OAAA;EACA,cAAA,EAAgB,aAAA;EAChB,gBAAA,EAAkB,aAAA;EAClB,SAAA,GAAY,aAAA;AAAA;AAAA,UAGG,QAAA;EACf,MAAA,CAAO,KAAA,WAAgB,SAAA,EAAW,MAAA,EAAQ,aAAA,GAAgB,OAAA,CAAQ,gBAAA;EAClE,UAAA,CAAW,QAAA,WAAmB,OAAA;EAC9B,aAAA,IAAiB,OAAA;EACjB,KAAA,IAAS,OAAA;AAAA;AAAA,UAGM,qBAAA;EAZC;EAchB,GAAA;EAbkB;EAelB,QAAA,GAAW,OAAA;EAdC;EAgBZ,IAAA;EAhByB;EAkBzB,aAAA;AAAA;;;;;;;iBASoB,cAAA,CACpB,OAAA,GAAS,qBAAA,GACR,OAAA,CAAQ,QAAA"}
|
|
@@ -16,6 +16,36 @@ import { createHead, renderSSRHead } from "@unhead/vue/server";
|
|
|
16
16
|
|
|
17
17
|
//#region src/render/createRenderer.ts
|
|
18
18
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
/**
|
|
20
|
+
* Vite plugin that extracts raw slot content from <CodeBlock> tags
|
|
21
|
+
* and passes it as a :code prop before Vue compiles the template.
|
|
22
|
+
*
|
|
23
|
+
* This lets users write HTML naturally inside CodeBlock slots without
|
|
24
|
+
* Vue attempting to compile it as template syntax.
|
|
25
|
+
*/
|
|
26
|
+
function codeBlockExtract() {
|
|
27
|
+
const re = /<(CodeBlock|code-block)((?:\s[^>]*?)?)>([\s\S]*?)<\/\1>/g;
|
|
28
|
+
return {
|
|
29
|
+
name: "maizzle:code-block-extract",
|
|
30
|
+
enforce: "pre",
|
|
31
|
+
transform(code, id) {
|
|
32
|
+
if (!id.endsWith(".vue") && !id.endsWith(".md")) return;
|
|
33
|
+
if (!code.includes("CodeBlock") && !code.includes("code-block")) return;
|
|
34
|
+
const transformed = code.replace(re, (_match, tag, attrs, content) => {
|
|
35
|
+
if (/(?:^|\s):code\b/.test(attrs) || /v-bind:code\b/.test(attrs)) return _match;
|
|
36
|
+
const stripped = content.replace(/^\n+/, "").replace(/\s+$/, "");
|
|
37
|
+
if (!stripped) return _match;
|
|
38
|
+
const minIndent = stripped.match(/^[ \t]*(?=\S)/gm)?.reduce((min, ws) => Math.min(min, ws.length), Infinity) ?? 0;
|
|
39
|
+
const dedented = minIndent > 0 ? stripped.replace(new RegExp(`^[ \\t]{${minIndent}}`, "gm"), "") : stripped;
|
|
40
|
+
return `<${tag}${attrs} encoded-code="${Buffer.from(dedented).toString("base64")}" />`;
|
|
41
|
+
});
|
|
42
|
+
if (transformed !== code) return {
|
|
43
|
+
code: transformed,
|
|
44
|
+
map: null
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
19
49
|
const vuePkgDir = dirname(fileURLToPath(import.meta.resolve("vue/package.json")));
|
|
20
50
|
const vueServerRendererPkgDir = dirname(fileURLToPath(import.meta.resolve("@vue/server-renderer/package.json")));
|
|
21
51
|
const unheadVuePkgDir = resolve(dirname(fileURLToPath(import.meta.resolve("@unhead/vue"))), "..");
|
|
@@ -34,6 +64,7 @@ async function createRenderer(options = {}) {
|
|
|
34
64
|
const server = await createServer({
|
|
35
65
|
configFile: false,
|
|
36
66
|
plugins: [
|
|
67
|
+
codeBlockExtract(),
|
|
37
68
|
{
|
|
38
69
|
name: "maizzle:virtual-sfc",
|
|
39
70
|
resolveId(id) {
|
|
@@ -127,13 +158,38 @@ async function createRenderer(options = {}) {
|
|
|
127
158
|
app.use(head);
|
|
128
159
|
app.provide(configKey, config);
|
|
129
160
|
app.provide(contextKey, renderContext);
|
|
130
|
-
|
|
161
|
+
const ssrContext = {};
|
|
162
|
+
let html = await renderToString(app, ssrContext);
|
|
131
163
|
const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(head);
|
|
132
164
|
if (htmlAttrs) html = html.replace(/<html([^>]*)>/, `<html$1 ${htmlAttrs}>`);
|
|
133
165
|
if (headTags) html = html.replace("</head>", `${headTags}\n</head>`);
|
|
134
166
|
if (bodyAttrs) html = html.replace(/<body([^>]*)>/, `<body$1 ${bodyAttrs}>`);
|
|
135
167
|
if (bodyTagsOpen) html = html.replace(/<body([^>]*)>/, `<body$1>\n${bodyTagsOpen}`);
|
|
136
168
|
if (bodyTags) html = html.replace("</body>", `${bodyTags}\n</body>`);
|
|
169
|
+
if (ssrContext.teleports) {
|
|
170
|
+
const { parse: parseDom, serialize: serializeDom, walk } = await import("../utils/ast/index.mjs");
|
|
171
|
+
let dom = parseDom(html);
|
|
172
|
+
for (const [rawTarget, content] of Object.entries(ssrContext.teleports)) {
|
|
173
|
+
if (!content) continue;
|
|
174
|
+
const prepend = rawTarget.endsWith(":start");
|
|
175
|
+
const target = prepend ? rawTarget.slice(0, -6) : rawTarget;
|
|
176
|
+
const targetChildren = parseDom(content);
|
|
177
|
+
walk(dom, (node) => {
|
|
178
|
+
const el = node;
|
|
179
|
+
if (!el.name) return;
|
|
180
|
+
if (target === el.name || target.startsWith("#") && el.attribs?.id === target.slice(1) || target.startsWith(".") && el.attribs?.class?.split(/\s+/).includes(target.slice(1))) {
|
|
181
|
+
for (const child of targetChildren) child.parent = el;
|
|
182
|
+
el.children = prepend ? [...targetChildren, ...el.children || []] : [...el.children || [], ...targetChildren];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
html = serializeDom(dom);
|
|
187
|
+
}
|
|
188
|
+
if (renderContext.previewText) {
|
|
189
|
+
const { text, fillerCount, shyCount } = renderContext.previewText;
|
|
190
|
+
const previewHtml = `<div style="display:none">${text}${" ͏ ".repeat(fillerCount)}${" ".repeat(shyCount)}\u00A0</div>`;
|
|
191
|
+
html = html.replace(/<body([^>]*)>/, `<body$1>${previewHtml}`);
|
|
192
|
+
}
|
|
137
193
|
return {
|
|
138
194
|
html,
|
|
139
195
|
doctype: renderContext.doctype,
|
|
@@ -146,6 +202,9 @@ async function createRenderer(options = {}) {
|
|
|
146
202
|
const mod = await server.moduleGraph.getModuleByUrl(filePath);
|
|
147
203
|
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
148
204
|
},
|
|
205
|
+
async invalidateAll() {
|
|
206
|
+
for (const mod of server.moduleGraph.idToModuleMap.values()) server.moduleGraph.invalidateModule(mod);
|
|
207
|
+
},
|
|
149
208
|
async close() {
|
|
150
209
|
await server.close();
|
|
151
210
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRenderer.mjs","names":["merge"],"sources":["../../src/render/createRenderer.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { isLaravel } from '../utils/detect.ts'\nimport { createServer } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport Markdown from 'unplugin-vue-markdown/vite'\nimport AutoImport from 'unplugin-auto-import/vite'\nimport Components from 'unplugin-vue-components/vite'\nimport { unheadVueComposablesImports } from '@unhead/vue'\nimport { defu as merge } from 'defu'\nimport { createSSRApp } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\nimport { createHead, renderSSRHead } from '@unhead/vue/server'\nimport { MaizzleConfigKey } from '../composables/useConfig.ts'\nimport { RenderContextKey } from '../composables/renderContext.ts'\nimport type { Component, InjectionKey } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport type { Options as MarkdownOptions } from 'unplugin-vue-markdown/types'\nimport type { RenderContext } from '../composables/renderContext.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst vuePkgDir = dirname(fileURLToPath(import.meta.resolve('vue/package.json')))\nconst vueServerRendererPkgDir = dirname(fileURLToPath(import.meta.resolve('@vue/server-renderer/package.json')))\nconst unheadVuePkgDir = resolve(dirname(fileURLToPath(import.meta.resolve('@unhead/vue'))), '..')\nconst vueRouterPkgDir = dirname(fileURLToPath(import.meta.resolve('vue-router/package.json')))\n\nexport interface RenderedTemplate {\n html: string\n doctype?: string\n templateConfig: MaizzleConfig\n sfcEventHandlers: RenderContext['sfcEventHandlers']\n plaintext?: RenderContext['plaintext']\n}\n\nexport interface Renderer {\n render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate>\n invalidate(filePath: string): Promise<void>\n close(): Promise<void>\n}\n\nexport interface CreateRendererOptions {\n /** Generate .d.ts files for auto-imports and components (default: false) */\n dts?: boolean\n /** Options passed to unplugin-vue-markdown */\n markdown?: MarkdownOptions\n /** Root directory for resolving user component dirs and .d.ts output */\n root?: string\n /** Additional component directories to register for auto-import */\n componentDirs?: string[]\n}\n\n/**\n * Lightweight Vite SSR loader for rendering Vue SFC email templates.\n *\n * Uses only Vue + unplugin for component/auto-import resolution.\n * Tailwind CSS compilation is handled by the transformer pipeline.\n */\nexport async function createRenderer(\n options: CreateRendererOptions = {},\n): Promise<Renderer> {\n const { dts = false, markdown: markdownOptions, root = process.cwd(), componentDirs = [] } = options\n\n const dtsDir = isLaravel()\n ? resolve(process.cwd(), 'resources/js/types/maizzle')\n : resolve(root, '.maizzle')\n\n const VIRTUAL_SFC_ID = 'virtual:maizzle-sfc.vue'\n let virtualSfcSource = ''\n\n const server = await createServer({\n configFile: false,\n plugins: [\n {\n name: 'maizzle:virtual-sfc',\n resolveId(id) {\n if (id === VIRTUAL_SFC_ID) return id\n },\n load(id) {\n if (id === VIRTUAL_SFC_ID) return virtualSfcSource\n },\n },\n vue({\n include: [/\\.vue$/, /\\.md$/],\n template: {\n transformAssetUrls: false,\n },\n }),\n Markdown(merge(markdownOptions ?? {}, {\n headEnabled: true,\n wrapperDiv: false,\n })),\n AutoImport({\n dirs: [\n resolve(__dirname, '../composables'),\n resolve(__dirname, '../filters'),\n ],\n imports: ['vue', unheadVueComposablesImports],\n dts: dts ? resolve(dtsDir, 'auto-imports.d.ts') : false,\n }),\n Components({\n extensions: ['vue', 'md'],\n include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],\n dirs: [\n resolve(__dirname, '../components'),\n resolve(root, 'components'),\n ...componentDirs,\n ],\n dts: dts ? resolve(dtsDir, 'components.d.ts') : false,\n }),\n ],\n resolve: {\n alias: {\n 'vue/server-renderer': resolve(vueServerRendererPkgDir, 'dist/server-renderer.esm-bundler.js'),\n 'vue': resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js'),\n 'vue-router': vueRouterPkgDir,\n '@unhead/vue/server': resolve(unheadVuePkgDir, 'dist/server.mjs'),\n '@unhead/vue': resolve(unheadVuePkgDir, 'dist/index.mjs'),\n },\n },\n server: {\n middlewareMode: true,\n hmr: false,\n watch: null,\n fs: {\n allow: [process.cwd(), root, ...componentDirs, vuePkgDir, vueServerRendererPkgDir, unheadVuePkgDir, vueRouterPkgDir],\n },\n },\n appType: 'custom',\n logLevel: 'silent',\n optimizeDeps: {\n noDiscovery: true,\n },\n })\n\n return {\n async render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate> {\n let component: Component\n let configKey: InjectionKey<MaizzleConfig>\n let contextKey: InjectionKey<RenderContext>\n\n if (typeof input === 'string') {\n // String input goes through Vite — must use ssrLoadModule for injection keys\n // so they share the same module instance as the SFC\n const configModule = await server.ssrLoadModule(resolve(__dirname, '../composables/useConfig'))\n const contextModule = await server.ssrLoadModule(resolve(__dirname, '../composables/renderContext'))\n configKey = configModule.MaizzleConfigKey\n contextKey = contextModule.RenderContextKey\n\n if (input.includes('<template') || input.includes('<script')) {\n virtualSfcSource = input\n const mod = server.moduleGraph.getModuleById(VIRTUAL_SFC_ID)\n if (mod) server.moduleGraph.invalidateModule(mod)\n component = (await server.ssrLoadModule(VIRTUAL_SFC_ID)).default\n } else {\n component = (await server.ssrLoadModule(input)).default\n }\n } else {\n // Pre-compiled component — use directly imported keys\n component = input\n configKey = MaizzleConfigKey\n contextKey = RenderContextKey\n }\n\n const renderContext: RenderContext = {\n doctype: undefined,\n sfcConfig: undefined,\n sfcEventHandlers: [],\n }\n\n const head = createHead({ disableDefaults: true })\n const app = createSSRApp(component)\n app.use(head)\n app.provide(configKey, config)\n app.provide(contextKey, renderContext)\n\n let html: string = await renderToString(app)\n\n const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(head)\n\n // Inject head entries into the rendered HTML\n if (htmlAttrs) {\n html = html.replace(/<html([^>]*)>/, `<html$1 ${htmlAttrs}>`)\n }\n if (headTags) {\n html = html.replace('</head>', `${headTags}\\n</head>`)\n }\n if (bodyAttrs) {\n html = html.replace(/<body([^>]*)>/, `<body$1 ${bodyAttrs}>`)\n }\n if (bodyTagsOpen) {\n html = html.replace(/<body([^>]*)>/, `<body$1>\\n${bodyTagsOpen}`)\n }\n if (bodyTags) {\n html = html.replace('</body>', `${bodyTags}\\n</body>`)\n }\n\n return {\n html,\n doctype: renderContext.doctype,\n templateConfig: renderContext.sfcConfig ?? config,\n sfcEventHandlers: renderContext.sfcEventHandlers,\n plaintext: renderContext.plaintext,\n }\n },\n\n async invalidate(filePath: string): Promise<void> {\n const mod = await server.moduleGraph.getModuleByUrl(filePath)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async close(): Promise<void> {\n await server.close()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAEzD,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,QAAQ,mBAAmB,CAAC,CAAC;AACjF,MAAM,0BAA0B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MAAM,eAAe,IAAI;GAE5C,MAAM,EAAE,UAAU,UAAU,cAAc,WAAW,cAAc,MAAM,cAAc,KAAK;AAG5F,OAAI,UACF,QAAO,KAAK,QAAQ,iBAAiB,WAAW,UAAU,GAAG;AAE/D,OAAI,SACF,QAAO,KAAK,QAAQ,WAAW,GAAG,SAAS,WAAW;AAExD,OAAI,UACF,QAAO,KAAK,QAAQ,iBAAiB,WAAW,UAAU,GAAG;AAE/D,OAAI,aACF,QAAO,KAAK,QAAQ,iBAAiB,aAAa,eAAe;AAEnE,OAAI,SACF,QAAO,KAAK,QAAQ,WAAW,GAAG,SAAS,WAAW;AAGxD,UAAO;IACL;IACA,SAAS,cAAc;IACvB,gBAAgB,cAAc,aAAa;IAC3C,kBAAkB,cAAc;IAChC,WAAW,cAAc;IAC1B;;EAGH,MAAM,WAAW,UAAiC;GAChD,MAAM,MAAM,MAAM,OAAO,YAAY,eAAe,SAAS;AAC7D,OAAI,IACF,QAAO,YAAY,iBAAiB,IAAI;;EAI5C,MAAM,QAAuB;AAC3B,SAAM,OAAO,OAAO;;EAEvB"}
|
|
1
|
+
{"version":3,"file":"createRenderer.mjs","names":["merge"],"sources":["../../src/render/createRenderer.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { isLaravel } from '../utils/detect.ts'\nimport { createServer } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport Markdown from 'unplugin-vue-markdown/vite'\nimport AutoImport from 'unplugin-auto-import/vite'\nimport Components from 'unplugin-vue-components/vite'\nimport { unheadVueComposablesImports } from '@unhead/vue'\nimport { defu as merge } from 'defu'\nimport { createSSRApp } from 'vue'\nimport { renderToString } from 'vue/server-renderer'\nimport { createHead, renderSSRHead } from '@unhead/vue/server'\nimport { MaizzleConfigKey } from '../composables/useConfig.ts'\nimport { RenderContextKey } from '../composables/renderContext.ts'\nimport type { Component, InjectionKey } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport type { Options as MarkdownOptions } from 'unplugin-vue-markdown/types'\nimport type { RenderContext } from '../composables/renderContext.ts'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\n/**\n * Vite plugin that extracts raw slot content from <CodeBlock> tags\n * and passes it as a :code prop before Vue compiles the template.\n *\n * This lets users write HTML naturally inside CodeBlock slots without\n * Vue attempting to compile it as template syntax.\n */\nfunction codeBlockExtract() {\n // Matches <CodeBlock ...>content</CodeBlock> (and kebab-case <code-block>)\n const re = /<(CodeBlock|code-block)((?:\\s[^>]*?)?)>([\\s\\S]*?)<\\/\\1>/g\n\n return {\n name: 'maizzle:code-block-extract',\n enforce: 'pre' as const,\n transform(code: string, id: string) {\n if (!id.endsWith('.vue') && !id.endsWith('.md')) return\n if (!code.includes('CodeBlock') && !code.includes('code-block')) return\n\n const transformed = code.replace(re, (_match, tag, attrs, content) => {\n // Skip if already has a :code or v-bind:code prop\n if (/(?:^|\\s):code\\b/.test(attrs) || /v-bind:code\\b/.test(attrs)) return _match\n\n // Strip leading/trailing blank lines, then dedent based on\n // the minimum indent of non-empty lines (à la min-indent)\n const stripped = content.replace(/^\\n+/, '').replace(/\\s+$/, '')\n if (!stripped) return _match\n\n const minIndent = stripped.match(/^[ \\t]*(?=\\S)/gm)\n ?.reduce((min, ws) => Math.min(min, ws.length), Infinity) ?? 0\n\n const dedented = minIndent > 0\n ? stripped.replace(new RegExp(`^[ \\\\t]{${minIndent}}`, 'gm'), '')\n : stripped\n\n // Base64-encode so no characters can interfere with Vue's HTML parser.\n // The component decodes it back via Buffer.\n const encoded = Buffer.from(dedented).toString('base64')\n\n return `<${tag}${attrs} encoded-code=\"${encoded}\" />`\n })\n\n if (transformed !== code) {\n return { code: transformed, map: null }\n }\n },\n }\n}\n\nconst vuePkgDir = dirname(fileURLToPath(import.meta.resolve('vue/package.json')))\nconst vueServerRendererPkgDir = dirname(fileURLToPath(import.meta.resolve('@vue/server-renderer/package.json')))\nconst unheadVuePkgDir = resolve(dirname(fileURLToPath(import.meta.resolve('@unhead/vue'))), '..')\nconst vueRouterPkgDir = dirname(fileURLToPath(import.meta.resolve('vue-router/package.json')))\n\nexport interface RenderedTemplate {\n html: string\n doctype?: string\n templateConfig: MaizzleConfig\n sfcEventHandlers: RenderContext['sfcEventHandlers']\n plaintext?: RenderContext['plaintext']\n}\n\nexport interface Renderer {\n render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate>\n invalidate(filePath: string): Promise<void>\n invalidateAll(): Promise<void>\n close(): Promise<void>\n}\n\nexport interface CreateRendererOptions {\n /** Generate .d.ts files for auto-imports and components (default: false) */\n dts?: boolean\n /** Options passed to unplugin-vue-markdown */\n markdown?: MarkdownOptions\n /** Root directory for resolving user component dirs and .d.ts output */\n root?: string\n /** Additional component directories to register for auto-import */\n componentDirs?: string[]\n}\n\n/**\n * Lightweight Vite SSR loader for rendering Vue SFC email templates.\n *\n * Uses only Vue + unplugin for component/auto-import resolution.\n * Tailwind CSS compilation is handled by the transformer pipeline.\n */\nexport async function createRenderer(\n options: CreateRendererOptions = {},\n): Promise<Renderer> {\n const { dts = false, markdown: markdownOptions, root = process.cwd(), componentDirs = [] } = options\n\n const dtsDir = isLaravel()\n ? resolve(process.cwd(), 'resources/js/types/maizzle')\n : resolve(root, '.maizzle')\n\n const VIRTUAL_SFC_ID = 'virtual:maizzle-sfc.vue'\n let virtualSfcSource = ''\n\n const server = await createServer({\n configFile: false,\n plugins: [\n codeBlockExtract(),\n {\n name: 'maizzle:virtual-sfc',\n resolveId(id) {\n if (id === VIRTUAL_SFC_ID) return id\n },\n load(id) {\n if (id === VIRTUAL_SFC_ID) return virtualSfcSource\n },\n },\n vue({\n include: [/\\.vue$/, /\\.md$/],\n template: {\n transformAssetUrls: false,\n },\n }),\n Markdown(merge(markdownOptions ?? {}, {\n headEnabled: true,\n wrapperDiv: false,\n })),\n AutoImport({\n dirs: [\n resolve(__dirname, '../composables'),\n resolve(__dirname, '../filters'),\n ],\n imports: ['vue', unheadVueComposablesImports],\n dts: dts ? resolve(dtsDir, 'auto-imports.d.ts') : false,\n }),\n Components({\n extensions: ['vue', 'md'],\n include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],\n dirs: [\n resolve(__dirname, '../components'),\n resolve(root, 'components'),\n ...componentDirs,\n ],\n dts: dts ? resolve(dtsDir, 'components.d.ts') : false,\n }),\n ],\n resolve: {\n alias: {\n 'vue/server-renderer': resolve(vueServerRendererPkgDir, 'dist/server-renderer.esm-bundler.js'),\n 'vue': resolve(vuePkgDir, 'dist/vue.runtime.esm-bundler.js'),\n 'vue-router': vueRouterPkgDir,\n '@unhead/vue/server': resolve(unheadVuePkgDir, 'dist/server.mjs'),\n '@unhead/vue': resolve(unheadVuePkgDir, 'dist/index.mjs'),\n },\n },\n server: {\n middlewareMode: true,\n hmr: false,\n watch: null,\n fs: {\n allow: [process.cwd(), root, ...componentDirs, vuePkgDir, vueServerRendererPkgDir, unheadVuePkgDir, vueRouterPkgDir],\n },\n },\n appType: 'custom',\n logLevel: 'silent',\n optimizeDeps: {\n noDiscovery: true,\n },\n })\n\n return {\n async render(input: string | Component, config: MaizzleConfig): Promise<RenderedTemplate> {\n let component: Component\n let configKey: InjectionKey<MaizzleConfig>\n let contextKey: InjectionKey<RenderContext>\n\n if (typeof input === 'string') {\n // String input goes through Vite — must use ssrLoadModule for injection keys\n // so they share the same module instance as the SFC\n const configModule = await server.ssrLoadModule(resolve(__dirname, '../composables/useConfig'))\n const contextModule = await server.ssrLoadModule(resolve(__dirname, '../composables/renderContext'))\n configKey = configModule.MaizzleConfigKey\n contextKey = contextModule.RenderContextKey\n\n if (input.includes('<template') || input.includes('<script')) {\n virtualSfcSource = input\n const mod = server.moduleGraph.getModuleById(VIRTUAL_SFC_ID)\n if (mod) server.moduleGraph.invalidateModule(mod)\n component = (await server.ssrLoadModule(VIRTUAL_SFC_ID)).default\n } else {\n component = (await server.ssrLoadModule(input)).default\n }\n } else {\n // Pre-compiled component — use directly imported keys\n component = input\n configKey = MaizzleConfigKey\n contextKey = RenderContextKey\n }\n\n const renderContext: RenderContext = {\n doctype: undefined,\n sfcConfig: undefined,\n sfcEventHandlers: [],\n }\n\n const head = createHead({ disableDefaults: true })\n const app = createSSRApp(component)\n app.use(head)\n app.provide(configKey, config)\n app.provide(contextKey, renderContext)\n\n const ssrContext: Record<string, any> = {}\n let html: string = await renderToString(app, ssrContext)\n\n const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(head)\n\n // Inject head entries into the rendered HTML\n if (htmlAttrs) {\n html = html.replace(/<html([^>]*)>/, `<html$1 ${htmlAttrs}>`)\n }\n if (headTags) {\n html = html.replace('</head>', `${headTags}\\n</head>`)\n }\n if (bodyAttrs) {\n html = html.replace(/<body([^>]*)>/, `<body$1 ${bodyAttrs}>`)\n }\n if (bodyTagsOpen) {\n html = html.replace(/<body([^>]*)>/, `<body$1>\\n${bodyTagsOpen}`)\n }\n if (bodyTags) {\n html = html.replace('</body>', `${bodyTags}\\n</body>`)\n }\n\n // Inject SSR teleport content into their target elements\n if (ssrContext.teleports) {\n const { parse: parseDom, serialize: serializeDom, walk } = await import('../utils/ast/index.ts')\n let dom = parseDom(html)\n\n for (const [rawTarget, content] of Object.entries(ssrContext.teleports) as [string, string][]) {\n if (!content) continue\n\n const prepend = rawTarget.endsWith(':start')\n const target = prepend ? rawTarget.slice(0, -6) : rawTarget\n const targetChildren = parseDom(content)\n\n walk(dom, (node) => {\n const el = node as import('domhandler').Element\n\n if (!el.name) return\n\n const matched\n = target === el.name\n || (target.startsWith('#') && el.attribs?.id === target.slice(1))\n || (target.startsWith('.') && el.attribs?.class?.split(/\\s+/).includes(target.slice(1)))\n\n if (matched) {\n for (const child of targetChildren) {\n child.parent = el as any\n }\n\n el.children = prepend\n ? [...targetChildren, ...(el.children || [])] as any\n : [...(el.children || []), ...targetChildren] as any\n }\n })\n }\n\n html = serializeDom(dom)\n }\n\n // Inject preview/preheader text from usePreviewText() composable\n if (renderContext.previewText) {\n const { text, fillerCount, shyCount } = renderContext.previewText\n const filler = '\\u2007\\u034F '.repeat(fillerCount)\n const shys = '\\u00AD '.repeat(shyCount)\n const previewHtml = `<div style=\"display:none\">${text}${filler}${shys}\\u00A0</div>`\n html = html.replace(/<body([^>]*)>/, `<body$1>${previewHtml}`)\n }\n\n return {\n html,\n doctype: renderContext.doctype,\n templateConfig: renderContext.sfcConfig ?? config,\n sfcEventHandlers: renderContext.sfcEventHandlers,\n plaintext: renderContext.plaintext,\n }\n },\n\n async invalidate(filePath: string): Promise<void> {\n const mod = await server.moduleGraph.getModuleByUrl(filePath)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async invalidateAll(): Promise<void> {\n for (const mod of server.moduleGraph.idToModuleMap.values()) {\n server.moduleGraph.invalidateModule(mod)\n }\n },\n\n async close(): Promise<void> {\n await server.close()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;;;;;;;;AASzD,SAAS,mBAAmB;CAE1B,MAAM,KAAK;AAEX,QAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,MAAc,IAAY;AAClC,OAAI,CAAC,GAAG,SAAS,OAAO,IAAI,CAAC,GAAG,SAAS,MAAM,CAAE;AACjD,OAAI,CAAC,KAAK,SAAS,YAAY,IAAI,CAAC,KAAK,SAAS,aAAa,CAAE;GAEjE,MAAM,cAAc,KAAK,QAAQ,KAAK,QAAQ,KAAK,OAAO,YAAY;AAEpE,QAAI,kBAAkB,KAAK,MAAM,IAAI,gBAAgB,KAAK,MAAM,CAAE,QAAO;IAIzE,MAAM,WAAW,QAAQ,QAAQ,QAAQ,GAAG,CAAC,QAAQ,QAAQ,GAAG;AAChE,QAAI,CAAC,SAAU,QAAO;IAEtB,MAAM,YAAY,SAAS,MAAM,kBAAkB,EAC/C,QAAQ,KAAK,OAAO,KAAK,IAAI,KAAK,GAAG,OAAO,EAAE,SAAS,IAAI;IA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IAAI,IAAI,GAAG,SAAS,OAAO,OAAO,MAAM,EAAE,IAC5D,OAAO,WAAW,IAAI,IAAI,GAAG,SAAS,OAAO,MAAM,MAAM,CAAC,SAAS,OAAO,MAAM,EAAE,CAAC,EAE5E;AACX,YAAK,MAAM,SAAS,eAClB,OAAM,SAAS;AAGjB,UAAG,WAAW,UACV,CAAC,GAAG,gBAAgB,GAAI,GAAG,YAAY,EAAE,CAAE,GAC3C,CAAC,GAAI,GAAG,YAAY,EAAE,EAAG,GAAG,eAAe;;OAEjD;;AAGJ,WAAO,aAAa,IAAI;;AAI1B,OAAI,cAAc,aAAa;IAC7B,MAAM,EAAE,MAAM,aAAa,aAAa,cAAc;IAGtD,MAAM,cAAc,6BAA6B,OAFlC,MAAgB,OAAO,YAAY,GACrC,KAAU,OAAO,SAAS,CAC+B;AACtE,WAAO,KAAK,QAAQ,iBAAiB,WAAW,cAAc;;AAGhE,UAAO;IACL;IACA,SAAS,cAAc;IACvB,gBAAgB,cAAc,aAAa;IAC3C,kBAAkB,cAAc;IAChC,WAAW,cAAc;IAC1B;;EAGH,MAAM,WAAW,UAAiC;GAChD,MAAM,MAAM,MAAM,OAAO,YAAY,eAAe,SAAS;AAC7D,OAAI,IACF,QAAO,YAAY,iBAAiB,IAAI;;EAI5C,MAAM,gBAA+B;AACnC,QAAK,MAAM,OAAO,OAAO,YAAY,cAAc,QAAQ,CACzD,QAAO,YAAY,iBAAiB,IAAI;;EAI5C,MAAM,QAAuB;AAC3B,SAAM,OAAO,OAAO;;EAEvB"}
|
package/dist/render/index.mjs
CHANGED
|
@@ -23,8 +23,9 @@ async function render(template, options = {}) {
|
|
|
23
23
|
const isFile = typeof template === "string" && [".vue", ".md"].includes(extname(template)) && !template.includes("\n");
|
|
24
24
|
const rendered = await renderer.render(isFile ? resolve(template) : template, config);
|
|
25
25
|
let html = rendered.html;
|
|
26
|
-
|
|
27
|
-
html =
|
|
26
|
+
const doctype = rendered.doctype ?? rendered.templateConfig.doctype ?? "<!DOCTYPE html>";
|
|
27
|
+
if (rendered.templateConfig.useTransformers !== false) html = await runTransformers(html, rendered.templateConfig, isFile ? resolve(template) : void 0, doctype);
|
|
28
|
+
html = `${doctype}\n${html}`;
|
|
28
29
|
const globalPlaintext = rendered.templateConfig.plaintext;
|
|
29
30
|
const sfcPlaintext = rendered.plaintext;
|
|
30
31
|
let plaintextResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/render/index.ts"],"sourcesContent":["import { resolve, extname } from 'node:path'\nimport { resolveConfig } from '../config/index.ts'\nimport { runTransformers } from '../transformers/index.ts'\nimport { createPlaintext } from '../plaintext.ts'\nimport type { Component } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport { createRenderer, type Renderer } from './createRenderer.ts'\n\nexport type { Renderer, RenderedTemplate, CreateRendererOptions } from './createRenderer.ts'\nexport { createRenderer } from './createRenderer.ts'\n\nexport interface RenderOptions {\n /** Already-resolved or partial config. If not provided, resolves from disk + defaults. */\n config?: Partial<MaizzleConfig>\n /** Reuse an existing renderer (used internally by build/serve to avoid creating one per template) */\n _renderer?: Renderer\n}\n\nexport interface RenderResult {\n html: string\n config: MaizzleConfig\n plaintext?: string\n}\n\n/**\n * Render a Vue SFC email template to a fully-transformed HTML string.\n *\n * Accepts a file path, a raw SFC source string, or an imported Vue component.\n * Runs the full pipeline: SSR render → transformers → doctype.\n */\nexport async function render(\n template: string | Component,\n options: RenderOptions = {},\n): Promise<RenderResult> {\n const config = await resolveConfig(options.config)\n\n // Reuse provided renderer or create a temporary one\n const renderer = options._renderer ?? await createRenderer({ markdown: config.markdown, root: config.root, componentDirs: [config.components?.source ?? []].flat() })\n const ownsRenderer = !options._renderer\n\n try {\n const isFile = typeof template === 'string'\n && ['.vue', '.md'].includes(extname(template))\n && !template.includes('\\n')\n\n const rendered = await renderer.render(isFile ? resolve(template) : template, config)\n let html = rendered.html\n\n // Run transformers\n if (rendered.templateConfig.useTransformers !== false) {\n html = await runTransformers(html, rendered.templateConfig, isFile ? resolve(template) : undefined)\n }\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/render/index.ts"],"sourcesContent":["import { resolve, extname } from 'node:path'\nimport { resolveConfig } from '../config/index.ts'\nimport { runTransformers } from '../transformers/index.ts'\nimport { createPlaintext } from '../plaintext.ts'\nimport type { Component } from 'vue'\nimport type { MaizzleConfig } from '../types/index.ts'\nimport { createRenderer, type Renderer } from './createRenderer.ts'\n\nexport type { Renderer, RenderedTemplate, CreateRendererOptions } from './createRenderer.ts'\nexport { createRenderer } from './createRenderer.ts'\n\nexport interface RenderOptions {\n /** Already-resolved or partial config. If not provided, resolves from disk + defaults. */\n config?: Partial<MaizzleConfig>\n /** Reuse an existing renderer (used internally by build/serve to avoid creating one per template) */\n _renderer?: Renderer\n}\n\nexport interface RenderResult {\n html: string\n config: MaizzleConfig\n plaintext?: string\n}\n\n/**\n * Render a Vue SFC email template to a fully-transformed HTML string.\n *\n * Accepts a file path, a raw SFC source string, or an imported Vue component.\n * Runs the full pipeline: SSR render → transformers → doctype.\n */\nexport async function render(\n template: string | Component,\n options: RenderOptions = {},\n): Promise<RenderResult> {\n const config = await resolveConfig(options.config)\n\n // Reuse provided renderer or create a temporary one\n const renderer = options._renderer ?? await createRenderer({ markdown: config.markdown, root: config.root, componentDirs: [config.components?.source ?? []].flat() })\n const ownsRenderer = !options._renderer\n\n try {\n const isFile = typeof template === 'string'\n && ['.vue', '.md'].includes(extname(template))\n && !template.includes('\\n')\n\n const rendered = await renderer.render(isFile ? resolve(template) : template, config)\n let html = rendered.html\n\n // Prepend doctype\n const doctype = rendered.doctype ?? rendered.templateConfig.doctype ?? '<!DOCTYPE html>'\n\n // Run transformers\n if (rendered.templateConfig.useTransformers !== false) {\n html = await runTransformers(html, rendered.templateConfig, isFile ? resolve(template) : undefined, doctype)\n }\n html = `${doctype}\\n${html}`\n\n const globalPlaintext = rendered.templateConfig.plaintext\n const sfcPlaintext = rendered.plaintext\n\n let plaintextResult: string | undefined\n\n if (globalPlaintext || sfcPlaintext) {\n const stripOptions = typeof globalPlaintext === 'object' ? globalPlaintext : {}\n plaintextResult = createPlaintext(html, stripOptions)\n }\n\n return { html, config: rendered.templateConfig, plaintext: plaintextResult }\n } finally {\n if (ownsRenderer) {\n await renderer.close()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,eAAsB,OACpB,UACA,UAAyB,EAAE,EACJ;CACvB,MAAM,SAAS,MAAM,cAAc,QAAQ,OAAO;CAGlD,MAAM,WAAW,QAAQ,aAAa,MAAM,eAAe;EAAE,UAAU,OAAO;EAAU,MAAM,OAAO;EAAM,eAAe,CAAC,OAAO,YAAY,UAAU,EAAE,CAAC,CAAC,MAAM;EAAE,CAAC;CACrK,MAAM,eAAe,CAAC,QAAQ;AAE9B,KAAI;EACF,MAAM,SAAS,OAAO,aAAa,YAC9B,CAAC,QAAQ,MAAM,CAAC,SAAS,QAAQ,SAAS,CAAC,IAC3C,CAAC,SAAS,SAAS,KAAK;EAE7B,MAAM,WAAW,MAAM,SAAS,OAAO,SAAS,QAAQ,SAAS,GAAG,UAAU,OAAO;EACrF,IAAI,OAAO,SAAS;EAGpB,MAAM,UAAU,SAAS,WAAW,SAAS,eAAe,WAAW;AAGvE,MAAI,SAAS,eAAe,oBAAoB,MAC9C,QAAO,MAAM,gBAAgB,MAAM,SAAS,gBAAgB,SAAS,QAAQ,SAAS,GAAG,QAAW,QAAQ;AAE9G,SAAO,GAAG,QAAQ,IAAI;EAEtB,MAAM,kBAAkB,SAAS,eAAe;EAChD,MAAM,eAAe,SAAS;EAE9B,IAAI;AAEJ,MAAI,mBAAmB,aAErB,mBAAkB,gBAAgB,MADb,OAAO,oBAAoB,WAAW,kBAAkB,EAAE,CAC1B;AAGvD,SAAO;GAAE;GAAM,QAAQ,SAAS;GAAgB,WAAW;GAAiB;WACpE;AACR,MAAI,aACF,OAAM,SAAS,OAAO"}
|
package/dist/serve.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.mts","names":[],"sources":["../src/serve.ts"],"mappings":";;;;UAwBiB,YAAA;EACf,MAAA,GAAS,OAAA,CAAQ,aAAA;;EAEjB,IAAA;EAH2B;EAK3B,MAAA;AAAA;;;;;;;;AAYF;;iBAAsB,KAAA,CAAM,OAAA,GAAS,YAAA,GAAiB,OAAA,CAAA,aAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"serve.d.mts","names":[],"sources":["../src/serve.ts"],"mappings":";;;;UAwBiB,YAAA;EACf,MAAA,GAAS,OAAA,CAAQ,aAAA;;EAEjB,IAAA;EAH2B;EAK3B,MAAA;AAAA;;;;;;;;AAYF;;iBAAsB,KAAA,CAAM,OAAA,GAAS,YAAA,GAAiB,OAAA,CAAA,aAAA;AAAA,iBAqdtC,WAAA,CAAY,MAAA,EAAQ,aAAA,EAAe,WAAA"}
|