@maizzle/framework 6.0.0-rc.17 → 6.0.0-rc.19
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/bin/maizzle.mjs +1 -1
- package/dist/build.d.ts +6 -5
- package/dist/build.d.ts.map +1 -1
- package/dist/{build.mjs → build.js} +23 -15
- package/dist/build.js.map +1 -0
- package/dist/components/Body.vue +10 -0
- package/dist/components/Button.vue +86 -49
- package/dist/components/Column.vue +10 -0
- package/dist/components/Container.vue +35 -7
- package/dist/components/Hr.vue +33 -0
- package/dist/components/Html.vue +29 -1
- package/dist/components/Layout.vue +27 -12
- package/dist/components/MarkdownLayout.vue +39 -0
- package/dist/components/NotPlaintext.vue +14 -0
- package/dist/components/{Vml.vue → OutlookBg.vue} +1 -1
- package/dist/components/Overlap.vue +10 -0
- package/dist/components/Plaintext.vue +14 -0
- package/dist/components/Preheader.vue +3 -8
- package/dist/components/QrCode.vue +157 -0
- package/dist/components/Row.vue +10 -0
- package/dist/components/Section.vue +10 -0
- package/dist/components/Spacer.vue +28 -27
- package/dist/components/{utils.mjs → utils.js} +2 -2
- package/dist/components/utils.js.map +1 -0
- package/dist/composables/{defineConfig.mjs → defineConfig.js} +4 -5
- package/dist/composables/defineConfig.js.map +1 -0
- package/dist/composables/{renderContext.mjs → renderContext.js} +2 -2
- package/dist/composables/renderContext.js.map +1 -0
- package/dist/composables/useBaseUrl.d.ts +19 -0
- package/dist/composables/useBaseUrl.d.ts.map +1 -0
- package/dist/composables/useBaseUrl.js +26 -0
- package/dist/composables/useBaseUrl.js.map +1 -0
- package/dist/composables/{useConfig.mjs → useConfig.js} +2 -3
- package/dist/composables/useConfig.js.map +1 -0
- package/dist/composables/{useDoctype.mjs → useDoctype.js} +3 -4
- package/dist/composables/useDoctype.js.map +1 -0
- package/dist/composables/{useEvent.mjs → useEvent.js} +3 -4
- package/dist/composables/useEvent.js.map +1 -0
- package/dist/composables/{useFont.mjs → useFont.js} +3 -4
- package/dist/composables/useFont.js.map +1 -0
- package/dist/composables/{useOutlookFallback.mjs → useOutlookFallback.js} +2 -3
- package/dist/composables/useOutlookFallback.js.map +1 -0
- package/dist/composables/usePlaintext.d.ts +2 -0
- package/dist/composables/usePlaintext.d.ts.map +1 -1
- package/dist/composables/{usePlaintext.mjs → usePlaintext.js} +4 -4
- package/dist/composables/usePlaintext.js.map +1 -0
- package/dist/composables/{usePreheader.mjs → usePreheader.js} +3 -4
- package/dist/composables/usePreheader.js.map +1 -0
- package/dist/composables/useTransformers.d.ts +34 -0
- package/dist/composables/useTransformers.d.ts.map +1 -0
- package/dist/composables/useTransformers.js +48 -0
- package/dist/composables/useTransformers.js.map +1 -0
- package/dist/composables/useUrlQuery.d.ts +19 -0
- package/dist/composables/useUrlQuery.d.ts.map +1 -0
- package/dist/composables/useUrlQuery.js +26 -0
- package/dist/composables/useUrlQuery.js.map +1 -0
- package/dist/config/{defaults.mjs → defaults.js} +9 -3
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/{index.mjs → index.js} +4 -5
- package/dist/config/index.js.map +1 -0
- package/dist/events/index.d.ts +8 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/{index.mjs → index.js} +21 -5
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +12 -9
- package/dist/index.js +36 -0
- package/dist/{plaintext.mjs → plaintext.js} +4 -5
- package/dist/plaintext.js.map +1 -0
- package/dist/{plugin.mjs → plugin.js} +6 -7
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/postcss/{mergeMediaQueries.mjs → mergeMediaQueries.js} +2 -3
- package/dist/plugins/postcss/mergeMediaQueries.js.map +1 -0
- package/dist/plugins/postcss/{pruneVars.mjs → pruneVars.js} +2 -2
- package/dist/plugins/postcss/pruneVars.js.map +1 -0
- package/dist/plugins/postcss/{quoteFontFamilies.mjs → quoteFontFamilies.js} +2 -2
- package/dist/plugins/postcss/quoteFontFamilies.js.map +1 -0
- package/dist/plugins/postcss/{removeDeclarations.mjs → removeDeclarations.js} +2 -2
- package/dist/plugins/postcss/removeDeclarations.js.map +1 -0
- package/dist/plugins/postcss/{resolveMaizzleImports.mjs → resolveMaizzleImports.js} +2 -3
- package/dist/plugins/postcss/resolveMaizzleImports.js.map +1 -0
- package/dist/plugins/postcss/{resolveProps.mjs → resolveProps.js} +2 -2
- package/dist/plugins/postcss/resolveProps.js.map +1 -0
- package/dist/plugins/postcss/{tailwindCleanup.mjs → tailwindCleanup.js} +2 -2
- package/dist/plugins/postcss/tailwindCleanup.js.map +1 -0
- package/dist/{prepare.mjs → prepare.js} +5 -6
- package/dist/prepare.js.map +1 -0
- package/dist/render/active.d.ts +8 -0
- package/dist/render/active.d.ts.map +1 -0
- package/dist/render/active.js +12 -0
- package/dist/render/active.js.map +1 -0
- package/dist/render/createRenderer.d.ts.map +1 -1
- package/dist/render/{createRenderer.mjs → createRenderer.js} +24 -19
- package/dist/render/createRenderer.js.map +1 -0
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/{index.mjs → index.js} +18 -11
- package/dist/render/index.js.map +1 -0
- package/dist/render/{injectFonts.mjs → injectFonts.js} +3 -4
- package/dist/render/injectFonts.js.map +1 -0
- package/dist/render/plugins/{codeBlockExtract.mjs → codeBlockExtract.js} +2 -2
- package/dist/render/plugins/codeBlockExtract.js.map +1 -0
- package/dist/render/plugins/{markdownExtract.mjs → markdownExtract.js} +2 -3
- package/dist/render/plugins/markdownExtract.js.map +1 -0
- package/dist/render/plugins/{rawExtract.mjs → rawExtract.js} +2 -2
- package/dist/render/plugins/rawExtract.js.map +1 -0
- package/dist/render/plugins/{rowSourceLocation.mjs → rowSourceLocation.js} +2 -2
- package/dist/render/plugins/rowSourceLocation.js.map +1 -0
- package/dist/serve.d.ts +2 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/{serve.mjs → serve.js} +20 -15
- package/dist/serve.js.map +1 -0
- package/dist/server/{compatibility.mjs → compatibility.js} +5 -6
- package/dist/server/compatibility.js.map +1 -0
- package/dist/server/{email.mjs → email.js} +2 -3
- package/dist/server/email.js.map +1 -0
- package/dist/server/{linter.mjs → linter.js} +3 -4
- package/dist/server/linter.js.map +1 -0
- package/dist/server/{sfc-utils.mjs → sfc-utils.js} +2 -3
- package/dist/server/sfc-utils.js.map +1 -0
- package/dist/server/ui/App.vue +18 -0
- package/dist/server/ui/components/ui/command/Command.vue +4 -1
- package/dist/tests/render/_helpers.d.ts +6 -0
- package/dist/tests/render/_helpers.d.ts.map +1 -0
- package/dist/tests/render/_helpers.js +16 -0
- package/dist/tests/render/_helpers.js.map +1 -0
- package/dist/transformers/{addAttributes.mjs → addAttributes.js} +6 -7
- package/dist/transformers/addAttributes.js.map +1 -0
- package/dist/transformers/attributeToStyle.d.ts +27 -14
- package/dist/transformers/attributeToStyle.d.ts.map +1 -1
- package/dist/transformers/attributeToStyle.js +94 -0
- package/dist/transformers/attributeToStyle.js.map +1 -0
- package/dist/transformers/base.d.ts +66 -3
- package/dist/transformers/base.d.ts.map +1 -1
- package/dist/transformers/{base.mjs → base.js} +56 -30
- package/dist/transformers/base.js.map +1 -0
- package/dist/transformers/{columnWidth.mjs → columnWidth.js} +4 -5
- package/dist/transformers/columnWidth.js.map +1 -0
- package/dist/transformers/entities.d.ts +31 -2
- package/dist/transformers/entities.d.ts.map +1 -1
- package/dist/transformers/entities.js +73 -0
- package/dist/transformers/entities.js.map +1 -0
- package/dist/transformers/filters/{defaults.mjs → defaults.js} +2 -2
- package/dist/transformers/filters/defaults.js.map +1 -0
- package/dist/transformers/filters/index.d.ts +31 -10
- package/dist/transformers/filters/index.d.ts.map +1 -1
- package/dist/transformers/filters/index.js +89 -0
- package/dist/transformers/filters/index.js.map +1 -0
- package/dist/transformers/format.d.ts +14 -7
- package/dist/transformers/format.d.ts.map +1 -1
- package/dist/transformers/format.js +30 -0
- package/dist/transformers/format.js.map +1 -0
- package/dist/transformers/index.js +133 -0
- package/dist/transformers/index.js.map +1 -0
- package/dist/transformers/inlineCss.d.ts +84 -0
- package/dist/transformers/inlineCss.d.ts.map +1 -0
- package/dist/transformers/{inlineCSS.mjs → inlineCss.js} +28 -18
- package/dist/transformers/inlineCss.js.map +1 -0
- package/dist/transformers/inlineLink.d.ts +26 -5
- package/dist/transformers/inlineLink.d.ts.map +1 -1
- package/dist/transformers/{inlineLink.mjs → inlineLink.js} +34 -10
- package/dist/transformers/inlineLink.js.map +1 -0
- package/dist/transformers/minify.d.ts +13 -9
- package/dist/transformers/minify.d.ts.map +1 -1
- package/dist/transformers/minify.js +25 -0
- package/dist/transformers/minify.js.map +1 -0
- package/dist/transformers/msoPlaceholders.d.ts +28 -0
- package/dist/transformers/msoPlaceholders.d.ts.map +1 -0
- package/dist/transformers/msoPlaceholders.js +88 -0
- package/dist/transformers/msoPlaceholders.js.map +1 -0
- package/dist/transformers/purgeCss.d.ts +43 -0
- package/dist/transformers/purgeCss.d.ts.map +1 -0
- package/dist/transformers/{purgeCSS.mjs → purgeCss.js} +36 -29
- package/dist/transformers/purgeCss.js.map +1 -0
- package/dist/transformers/removeAttributes.d.ts +43 -20
- package/dist/transformers/removeAttributes.d.ts.map +1 -1
- package/dist/transformers/removeAttributes.js +70 -0
- package/dist/transformers/removeAttributes.js.map +1 -0
- package/dist/transformers/{replaceStrings.mjs → replaceStrings.js} +2 -2
- package/dist/transformers/replaceStrings.js.map +1 -0
- package/dist/transformers/{safeClassNames.mjs → safeClassNames.js} +4 -5
- package/dist/transformers/safeClassNames.js.map +1 -0
- package/dist/transformers/shorthandCss.d.ts +47 -0
- package/dist/transformers/shorthandCss.d.ts.map +1 -0
- package/dist/transformers/shorthandCss.js +61 -0
- package/dist/transformers/shorthandCss.js.map +1 -0
- package/dist/transformers/sixHex.d.ts +16 -7
- package/dist/transformers/sixHex.d.ts.map +1 -1
- package/dist/transformers/sixHex.js +42 -0
- package/dist/transformers/sixHex.js.map +1 -0
- package/dist/transformers/{tailwindComponent.mjs → tailwindComponent.js} +5 -6
- package/dist/transformers/tailwindComponent.js.map +1 -0
- package/dist/transformers/{tailwindcss.mjs → tailwindcss.js} +6 -7
- package/dist/transformers/tailwindcss.js.map +1 -0
- package/dist/transformers/urlQuery.d.ts +26 -14
- package/dist/transformers/urlQuery.d.ts.map +1 -1
- package/dist/transformers/urlQuery.js +77 -0
- package/dist/transformers/urlQuery.js.map +1 -0
- package/dist/types/config.d.ts +108 -15
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +1 -0
- package/dist/utils/ast/index.js +4 -0
- package/dist/utils/ast/{parser.mjs → parser.js} +2 -3
- package/dist/utils/ast/parser.js.map +1 -0
- package/dist/utils/ast/{serializer.mjs → serializer.js} +3 -4
- package/dist/utils/ast/serializer.js.map +1 -0
- package/dist/utils/ast/{walker.mjs → walker.js} +2 -2
- package/dist/utils/ast/walker.js.map +1 -0
- package/dist/utils/{compileTailwindCss.mjs → compileTailwindCss.js} +8 -9
- package/dist/utils/compileTailwindCss.js.map +1 -0
- package/dist/utils/{decodeStyleEntities.mjs → decodeStyleEntities.js} +2 -2
- package/dist/utils/decodeStyleEntities.js.map +1 -0
- package/dist/utils/{detect.mjs → detect.js} +2 -3
- package/dist/utils/detect.js.map +1 -0
- package/dist/utils/output-markers.d.ts +29 -0
- package/dist/utils/output-markers.d.ts.map +1 -0
- package/dist/utils/output-markers.js +68 -0
- package/dist/utils/output-markers.js.map +1 -0
- package/dist/utils/{url.mjs → url.js} +2 -3
- package/dist/utils/url.js.map +1 -0
- package/node_modules/@clack/core/CHANGELOG.md +8 -0
- package/node_modules/@clack/core/dist/index.d.mts +18 -4
- package/node_modules/@clack/core/dist/index.mjs +16 -10
- package/node_modules/@clack/core/dist/index.mjs.map +1 -1
- package/node_modules/@clack/core/package.json +5 -2
- package/node_modules/@clack/prompts/CHANGELOG.md +15 -0
- package/node_modules/@clack/prompts/README.md +107 -2
- package/node_modules/@clack/prompts/dist/index.d.mts +16 -11
- package/node_modules/@clack/prompts/dist/index.mjs +114 -107
- package/node_modules/@clack/prompts/dist/index.mjs.map +1 -1
- package/node_modules/@clack/prompts/package.json +7 -4
- package/node_modules/fast-string-truncated-width/dist/index.js +36 -96
- package/node_modules/fast-string-truncated-width/dist/types.d.ts +0 -3
- package/node_modules/fast-string-truncated-width/dist/utils.d.ts +3 -3
- package/node_modules/fast-string-truncated-width/dist/utils.js +14 -9
- package/node_modules/fast-string-truncated-width/package.json +1 -1
- package/node_modules/fast-string-truncated-width/readme.md +2 -3
- package/node_modules/fast-string-width/package.json +2 -2
- package/node_modules/fast-string-width/readme.md +0 -3
- package/node_modules/fast-wrap-ansi/lib/main.js +4 -1
- package/node_modules/fast-wrap-ansi/lib/main.js.map +1 -1
- package/node_modules/fast-wrap-ansi/package.json +2 -2
- package/node_modules/maizzle/README.md +24 -0
- package/node_modules/maizzle/dist/commands/make/component.mjs +1 -1
- package/node_modules/maizzle/dist/commands/make/config.mjs +1 -1
- package/node_modules/maizzle/dist/commands/make/layout.mjs +3 -3
- package/node_modules/maizzle/dist/commands/make/scaffold.mjs +1 -1
- package/node_modules/maizzle/dist/commands/make/stubs/Layout.vue +146 -0
- package/node_modules/maizzle/dist/commands/make/stubs/component.vue +2 -4
- package/node_modules/maizzle/dist/commands/make/stubs/config.ts +1 -5
- package/node_modules/maizzle/dist/commands/make/template.mjs +1 -1
- package/node_modules/maizzle/dist/commands/new.mjs +29 -24
- package/node_modules/maizzle/dist/index.mjs +28 -8
- package/node_modules/maizzle/package.json +1 -1
- package/node_modules/tinyexec/README.md +1 -1
- package/node_modules/tinyexec/dist/main.d.mts +6 -6
- package/node_modules/tinyexec/dist/main.mjs +126 -134
- package/node_modules/tinyexec/package.json +9 -9
- package/package.json +4 -4
- package/dist/build.mjs.map +0 -1
- package/dist/components/Divider.vue +0 -133
- package/dist/components/utils.mjs.map +0 -1
- package/dist/composables/defineConfig.mjs.map +0 -1
- package/dist/composables/renderContext.mjs.map +0 -1
- package/dist/composables/useConfig.mjs.map +0 -1
- package/dist/composables/useDoctype.mjs.map +0 -1
- package/dist/composables/useEvent.mjs.map +0 -1
- package/dist/composables/useFont.mjs.map +0 -1
- package/dist/composables/useOutlookFallback.mjs.map +0 -1
- package/dist/composables/usePlaintext.mjs.map +0 -1
- package/dist/composables/usePreheader.mjs.map +0 -1
- package/dist/config/defaults.mjs.map +0 -1
- package/dist/config/index.mjs.map +0 -1
- package/dist/events/index.mjs.map +0 -1
- package/dist/index.mjs +0 -34
- package/dist/plaintext.mjs.map +0 -1
- package/dist/plugin.mjs.map +0 -1
- package/dist/plugins/postcss/mergeMediaQueries.mjs.map +0 -1
- package/dist/plugins/postcss/pruneVars.mjs.map +0 -1
- package/dist/plugins/postcss/quoteFontFamilies.mjs.map +0 -1
- package/dist/plugins/postcss/removeDeclarations.mjs.map +0 -1
- package/dist/plugins/postcss/resolveMaizzleImports.mjs.map +0 -1
- package/dist/plugins/postcss/resolveProps.mjs.map +0 -1
- package/dist/plugins/postcss/tailwindCleanup.mjs.map +0 -1
- package/dist/prepare.mjs.map +0 -1
- package/dist/render/createRenderer.mjs.map +0 -1
- package/dist/render/index.mjs.map +0 -1
- package/dist/render/injectFonts.mjs.map +0 -1
- package/dist/render/plugins/codeBlockExtract.mjs.map +0 -1
- package/dist/render/plugins/markdownExtract.mjs.map +0 -1
- package/dist/render/plugins/rawExtract.mjs.map +0 -1
- package/dist/render/plugins/rowSourceLocation.mjs.map +0 -1
- package/dist/serve.mjs.map +0 -1
- package/dist/server/compatibility.mjs.map +0 -1
- package/dist/server/email.mjs.map +0 -1
- package/dist/server/linter.mjs.map +0 -1
- package/dist/server/sfc-utils.mjs.map +0 -1
- package/dist/transformers/addAttributes.mjs.map +0 -1
- package/dist/transformers/attributeToStyle.mjs +0 -80
- package/dist/transformers/attributeToStyle.mjs.map +0 -1
- package/dist/transformers/base.mjs.map +0 -1
- package/dist/transformers/columnWidth.mjs.map +0 -1
- package/dist/transformers/entities.mjs +0 -41
- package/dist/transformers/entities.mjs.map +0 -1
- package/dist/transformers/filters/defaults.mjs.map +0 -1
- package/dist/transformers/filters/index.mjs +0 -67
- package/dist/transformers/filters/index.mjs.map +0 -1
- package/dist/transformers/format.mjs +0 -26
- package/dist/transformers/format.mjs.map +0 -1
- package/dist/transformers/index.mjs +0 -87
- package/dist/transformers/index.mjs.map +0 -1
- package/dist/transformers/inlineCSS.d.ts +0 -17
- package/dist/transformers/inlineCSS.d.ts.map +0 -1
- package/dist/transformers/inlineCSS.mjs.map +0 -1
- package/dist/transformers/inlineLink.mjs.map +0 -1
- package/dist/transformers/minify.mjs +0 -24
- package/dist/transformers/minify.mjs.map +0 -1
- package/dist/transformers/msoWidthFromClass.d.ts +0 -19
- package/dist/transformers/msoWidthFromClass.d.ts.map +0 -1
- package/dist/transformers/msoWidthFromClass.mjs +0 -61
- package/dist/transformers/msoWidthFromClass.mjs.map +0 -1
- package/dist/transformers/purgeCSS.d.ts +0 -23
- package/dist/transformers/purgeCSS.d.ts.map +0 -1
- package/dist/transformers/purgeCSS.mjs.map +0 -1
- package/dist/transformers/removeAttributes.mjs +0 -63
- package/dist/transformers/removeAttributes.mjs.map +0 -1
- package/dist/transformers/replaceStrings.mjs.map +0 -1
- package/dist/transformers/safeClassNames.mjs.map +0 -1
- package/dist/transformers/shorthandCSS.d.ts +0 -24
- package/dist/transformers/shorthandCSS.d.ts.map +0 -1
- package/dist/transformers/shorthandCSS.mjs +0 -48
- package/dist/transformers/shorthandCSS.mjs.map +0 -1
- package/dist/transformers/sixHex.mjs +0 -30
- package/dist/transformers/sixHex.mjs.map +0 -1
- package/dist/transformers/tailwindComponent.mjs.map +0 -1
- package/dist/transformers/tailwindcss.mjs.map +0 -1
- package/dist/transformers/urlQuery.mjs +0 -65
- package/dist/transformers/urlQuery.mjs.map +0 -1
- package/dist/types/config.mjs +0 -1
- package/dist/types/index.mjs +0 -1
- package/dist/utils/ast/index.mjs +0 -5
- package/dist/utils/ast/parser.mjs.map +0 -1
- package/dist/utils/ast/serializer.mjs.map +0 -1
- package/dist/utils/ast/walker.mjs.map +0 -1
- package/dist/utils/compileTailwindCss.mjs.map +0 -1
- package/dist/utils/decodeStyleEntities.mjs.map +0 -1
- package/dist/utils/detect.mjs.map +0 -1
- package/dist/utils/url.mjs.map +0 -1
- package/node_modules/maizzle/dist/commands/make/stubs/layout.vue +0 -39
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { parse } from "../utils/ast/parser.js";
|
|
2
|
+
import { walk } from "../utils/ast/walker.js";
|
|
3
|
+
import { serialize } from "../utils/ast/serializer.js";
|
|
4
|
+
import "../utils/ast/index.js";
|
|
5
|
+
//#region src/transformers/removeAttributes.ts
|
|
6
|
+
/**
|
|
7
|
+
* Remove HTML attributes from elements.
|
|
8
|
+
*
|
|
9
|
+
* Empty `style` and `class` attributes are always stripped, regardless of
|
|
10
|
+
* what you pass. Your entries are appended to those defaults.
|
|
11
|
+
*
|
|
12
|
+
* - `'data-src'` — remove when the value is empty.
|
|
13
|
+
* - `{ name: 'id', value: 'test' }` — remove when the value matches exactly.
|
|
14
|
+
* - `{ name: 'data-id', value: /\d/ }` — remove when the value matches the regex.
|
|
15
|
+
*
|
|
16
|
+
* @param html HTML string to transform.
|
|
17
|
+
* @param attributes Additional attribute-removal rules to apply on top of the defaults.
|
|
18
|
+
* @returns The transformed HTML string.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* import { removeAttributes } from '@maizzle/framework'
|
|
22
|
+
*
|
|
23
|
+
* const out = removeAttributes('<p style="" data-x="">x</p>', [
|
|
24
|
+
* 'data-x',
|
|
25
|
+
* { name: 'role', value: 'none' },
|
|
26
|
+
* ])
|
|
27
|
+
*/
|
|
28
|
+
function removeAttributes(html, attributes = []) {
|
|
29
|
+
return serialize(removeAttributesDom(parse(html), attributes));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* DOM-form of {@link removeAttributes} used by the internal transformer
|
|
33
|
+
* pipeline. Takes a parsed DOM, returns a parsed DOM — avoids redundant
|
|
34
|
+
* serialize/parse round-trips when chained with other transformers.
|
|
35
|
+
*/
|
|
36
|
+
function removeAttributesDom(dom, attributes = []) {
|
|
37
|
+
const attributesToRemove = [
|
|
38
|
+
"style",
|
|
39
|
+
"class",
|
|
40
|
+
...attributes
|
|
41
|
+
];
|
|
42
|
+
walk(dom, (node) => {
|
|
43
|
+
const el = node;
|
|
44
|
+
if (!el.attribs) return;
|
|
45
|
+
for (const attr of attributesToRemove) {
|
|
46
|
+
let attrName;
|
|
47
|
+
let attrValue;
|
|
48
|
+
if (typeof attr === "string") {
|
|
49
|
+
attrName = attr;
|
|
50
|
+
attrValue = true;
|
|
51
|
+
} else {
|
|
52
|
+
attrName = attr.name;
|
|
53
|
+
attrValue = attr.value;
|
|
54
|
+
}
|
|
55
|
+
const currentValue = el.attribs[attrName];
|
|
56
|
+
if (currentValue === void 0) continue;
|
|
57
|
+
let shouldRemove = false;
|
|
58
|
+
if (typeof attrValue === "boolean") shouldRemove = currentValue === "" || currentValue === true;
|
|
59
|
+
else if (typeof attrValue === "string") shouldRemove = currentValue === attrValue;
|
|
60
|
+
else if (attrValue instanceof RegExp) shouldRemove = attrValue.test(currentValue);
|
|
61
|
+
else shouldRemove = currentValue === "";
|
|
62
|
+
if (shouldRemove) delete el.attribs[attrName];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return dom;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { removeAttributes, removeAttributesDom };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=removeAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeAttributes.js","names":[],"sources":["../../src/transformers/removeAttributes.ts"],"sourcesContent":["import type { ChildNode, Element } from 'domhandler'\nimport { parse, serialize, walk } from '../utils/ast/index.ts'\n\n/**\n * Single attribute-removal rule.\n */\nexport interface RemoveAttributeRule {\n /** Attribute name to match. */\n name: string\n /**\n * Match condition for the attribute's value:\n * - `string` — remove when the value matches exactly.\n * - `RegExp` — remove when the value matches the regex.\n * - `boolean` / omitted — remove when the value is empty.\n */\n value?: string | RegExp | boolean\n}\n\n/**\n * Entry passed to {@link removeAttributes}. A bare string targets the named\n * attribute and removes it when its value is empty.\n */\nexport type RemoveAttributeOption = string | RemoveAttributeRule\n\n/**\n * Remove HTML attributes from elements.\n *\n * Empty `style` and `class` attributes are always stripped, regardless of\n * what you pass. Your entries are appended to those defaults.\n *\n * - `'data-src'` — remove when the value is empty.\n * - `{ name: 'id', value: 'test' }` — remove when the value matches exactly.\n * - `{ name: 'data-id', value: /\\d/ }` — remove when the value matches the regex.\n *\n * @param html HTML string to transform.\n * @param attributes Additional attribute-removal rules to apply on top of the defaults.\n * @returns The transformed HTML string.\n *\n * @example\n * import { removeAttributes } from '@maizzle/framework'\n *\n * const out = removeAttributes('<p style=\"\" data-x=\"\">x</p>', [\n * 'data-x',\n * { name: 'role', value: 'none' },\n * ])\n */\nexport function removeAttributes(html: string, attributes: RemoveAttributeOption[] = []): string {\n return serialize(removeAttributesDom(parse(html), attributes))\n}\n\n/**\n * DOM-form of {@link removeAttributes} used by the internal transformer\n * pipeline. Takes a parsed DOM, returns a parsed DOM — avoids redundant\n * serialize/parse round-trips when chained with other transformers.\n */\nexport function removeAttributesDom(dom: ChildNode[], attributes: RemoveAttributeOption[] = []): ChildNode[] {\n // Empty style/class are always stripped; user entries are appended.\n const attributesToRemove: RemoveAttributeOption[] = ['style', 'class', ...attributes]\n\n walk(dom, (node) => {\n const el = node as Element\n if (!el.attribs) return\n\n for (const attr of attributesToRemove) {\n let attrName: string\n let attrValue: string | RegExp | boolean | undefined\n\n if (typeof attr === 'string') {\n attrName = attr\n attrValue = true // Remove when value is empty (boolean true or empty string)\n } else {\n attrName = attr.name\n attrValue = attr.value\n }\n\n const currentValue = el.attribs[attrName]\n\n // Skip if attribute doesn't exist\n if (currentValue === undefined) continue\n\n let shouldRemove = false\n\n if (typeof attrValue === 'boolean') {\n // Remove if value is empty (boolean true is treated as no-value attribute)\n shouldRemove = currentValue === '' || (currentValue as unknown) === true\n } else if (typeof attrValue === 'string') {\n // Remove if value matches exactly\n shouldRemove = currentValue === attrValue\n } else if (attrValue instanceof RegExp) {\n // Remove if value matches regex\n shouldRemove = attrValue.test(currentValue)\n } else {\n // Default: remove if empty\n shouldRemove = currentValue === ''\n }\n\n if (shouldRemove) {\n delete el.attribs[attrName]\n }\n }\n })\n\n return dom\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,SAAgB,iBAAiB,MAAc,aAAsC,EAAE,EAAU;CAC/F,OAAO,UAAU,oBAAoB,MAAM,KAAK,EAAE,WAAW,CAAC;;;;;;;AAQhE,SAAgB,oBAAoB,KAAkB,aAAsC,EAAE,EAAe;CAE3G,MAAM,qBAA8C;EAAC;EAAS;EAAS,GAAG;EAAW;CAErF,KAAK,MAAM,SAAS;EAClB,MAAM,KAAK;EACX,IAAI,CAAC,GAAG,SAAS;EAEjB,KAAK,MAAM,QAAQ,oBAAoB;GACrC,IAAI;GACJ,IAAI;GAEJ,IAAI,OAAO,SAAS,UAAU;IAC5B,WAAW;IACX,YAAY;UACP;IACL,WAAW,KAAK;IAChB,YAAY,KAAK;;GAGnB,MAAM,eAAe,GAAG,QAAQ;GAGhC,IAAI,iBAAiB,KAAA,GAAW;GAEhC,IAAI,eAAe;GAEnB,IAAI,OAAO,cAAc,WAEvB,eAAe,iBAAiB,MAAO,iBAA6B;QAC/D,IAAI,OAAO,cAAc,UAE9B,eAAe,iBAAiB;QAC3B,IAAI,qBAAqB,QAE9B,eAAe,UAAU,KAAK,aAAa;QAG3C,eAAe,iBAAiB;GAGlC,IAAI,cACF,OAAO,GAAG,QAAQ;;GAGtB;CAEF,OAAO"}
|
|
@@ -13,7 +13,7 @@ function replaceStrings(html, config = {}) {
|
|
|
13
13
|
if (!replacements || Object.keys(replacements).length === 0) return html;
|
|
14
14
|
return Object.entries(replacements).reduce((result, [pattern, replacement]) => result.replace(new RegExp(pattern, "gi"), replacement), html);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
//#endregion
|
|
18
17
|
export { replaceStrings };
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=replaceStrings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replaceStrings.js","names":[],"sources":["../../src/transformers/replaceStrings.ts"],"sourcesContent":["import type { MaizzleConfig } from '../types/config.ts'\n\n/**\n * Replace strings transformer.\n *\n * Replaces strings in the HTML using the key-value pairs defined in\n * `config.replaceStrings`. Each key is treated as a regular expression\n * pattern (case-insensitive, global), and the value is the replacement.\n *\n * Character classes must be escaped in keys, e.g. `\\\\s` for `\\s`.\n */\nexport function replaceStrings(html: string, config: MaizzleConfig = {}): string {\n const replacements = config.replaceStrings\n\n if (!replacements || Object.keys(replacements).length === 0) return html\n\n return Object.entries(replacements).reduce(\n (result, [pattern, replacement]) => result.replace(new RegExp(pattern, 'gi'), replacement),\n html,\n )\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,eAAe,MAAc,SAAwB,EAAE,EAAU;CAC/E,MAAM,eAAe,OAAO;CAE5B,IAAI,CAAC,gBAAgB,OAAO,KAAK,aAAa,CAAC,WAAW,GAAG,OAAO;CAEpE,OAAO,OAAO,QAAQ,aAAa,CAAC,QACjC,QAAQ,CAAC,SAAS,iBAAiB,OAAO,QAAQ,IAAI,OAAO,SAAS,KAAK,EAAE,YAAY,EAC1F,KACD"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { walk } from "../utils/ast/walker.
|
|
2
|
-
import "../utils/ast/index.
|
|
1
|
+
import { walk } from "../utils/ast/walker.js";
|
|
2
|
+
import "../utils/ast/index.js";
|
|
3
3
|
import postcss from "postcss";
|
|
4
4
|
import safeParser from "postcss-safe-parser";
|
|
5
|
-
|
|
6
5
|
//#region src/transformers/safeClassNames.ts
|
|
7
6
|
const DEFAULT_REPLACEMENTS = {
|
|
8
7
|
":": "-",
|
|
@@ -97,7 +96,7 @@ function safeClassNames(dom, config = {}) {
|
|
|
97
96
|
});
|
|
98
97
|
return dom;
|
|
99
98
|
}
|
|
100
|
-
|
|
101
99
|
//#endregion
|
|
102
100
|
export { safeClassNames };
|
|
103
|
-
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=safeClassNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeClassNames.js","names":[],"sources":["../../src/transformers/safeClassNames.ts"],"sourcesContent":["import postcss from 'postcss'\nimport safeParser from 'postcss-safe-parser'\nimport type { ChildNode, Element } from 'domhandler'\nimport { walk } from '../utils/ast/index.ts'\nimport type { CssConfig } from '../types/config.ts'\n\nconst DEFAULT_REPLACEMENTS: Record<string, string> = {\n ':': '-',\n '/': '-',\n '%': 'pc',\n '.': '_',\n ',': '_',\n '#': '_',\n '[': '',\n ']': '',\n '(': '',\n ')': '',\n '{': '',\n '}': '',\n '!': '-i',\n '&': 'and-',\n '<': 'lt-',\n '=': 'eq-',\n '>': 'gt-',\n '|': 'or-',\n '@': 'at-',\n '?': 'q-',\n '\\\\': '-',\n '\"': '-',\n \"'\": '-',\n '*': '-',\n '+': '-',\n ';': '-',\n '^': '-',\n '`': '-',\n '~': '-',\n '$': '-',\n}\n\nfunction escapeForRegex(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Replace escaped special characters in CSS selectors.\n *\n * Tailwind generates selectors like `.sm\\:text-base`. This function\n * replaces the `\\:` with `-` (or whatever the configured replacement is)\n * so the selector becomes `.sm-text-base`, which is safe for email clients.\n */\nfunction processCssSelectors(css: string, replacements: Record<string, string>): string {\n // Matches \\<char> in CSS selectors — e.g. \\: \\/ \\. \\[ etc.\n const selectorRegex = new RegExp(\n `\\\\\\\\(${Object.keys(replacements).map(escapeForRegex).join('|')})`,\n 'g',\n )\n\n return postcss([\n (root: postcss.Root) => {\n root.walkRules((rule: postcss.Rule) => {\n rule.selector = rule.selector\n .replace(selectorRegex, (_matched, char) => replacements[char] ?? _matched)\n // Handle CSS unicode escape for comma (\\2c → _)\n .replaceAll('\\\\2c ', '_')\n })\n },\n ]).process(css, { parser: safeParser }).css\n}\n\n/**\n * Replace unsafe special characters in a class attribute value.\n *\n * Splits on whitespace and replaces each char from the replacements map\n * in each class token individually.\n */\nfunction processClassAttr(classStr: string, replacements: Record<string, string>): string {\n return classStr\n .split(/\\s+/)\n .filter(Boolean)\n .map((cls) => {\n for (const [from, to] of Object.entries(replacements)) {\n cls = cls.split(from).join(to)\n }\n return cls\n })\n .join(' ')\n}\n\n/**\n * Safe class names transformer.\n *\n * Replaces unsafe characters (`:`, `/`, `[`, `]`, etc.) in:\n * - CSS selectors inside `<style>` tags\n * - HTML `class` attributes\n *\n * This makes Tailwind utility classes like `sm:text-base` safe for\n * email clients that cannot handle escaped characters in class names.\n *\n * Enabled by default. Disable by setting `css.safe` to `false`.\n * Customize replacements by passing a `Record<string, string>` — user\n * values are merged on top of the defaults.\n */\nexport function safeClassNames(dom: ChildNode[], config: CssConfig = {}): ChildNode[] {\n const option = config.safe ?? true\n\n if (!option) return dom\n\n const replacements: Record<string, string> =\n option && typeof option === 'object'\n ? { ...DEFAULT_REPLACEMENTS, ...option }\n : DEFAULT_REPLACEMENTS\n\n walk(dom, (node) => {\n const el = node as Element\n\n // Process CSS selectors inside <style> tags\n if (el.name === 'style' && el.children?.length) {\n const text = el.children.find((c) => c.type === 'text') as any\n if (text?.data?.trim()) {\n text.data = processCssSelectors(text.data, replacements)\n }\n }\n\n // Replace special chars in class attributes\n if ('attribs' in el && el.attribs?.class) {\n el.attribs.class = processClassAttr(el.attribs.class, replacements)\n }\n })\n\n return dom\n}\n"],"mappings":";;;;;AAMA,MAAM,uBAA+C;CACnD,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAM;CACN,MAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACN;AAED,SAAS,eAAe,GAAmB;CACzC,OAAO,EAAE,QAAQ,uBAAuB,OAAO;;;;;;;;;AAUjD,SAAS,oBAAoB,KAAa,cAA8C;CAEtF,MAAM,gBAAgB,IAAI,OACxB,QAAQ,OAAO,KAAK,aAAa,CAAC,IAAI,eAAe,CAAC,KAAK,IAAI,CAAC,IAChE,IACD;CAED,OAAO,QAAQ,EACZ,SAAuB;EACtB,KAAK,WAAW,SAAuB;GACrC,KAAK,WAAW,KAAK,SAClB,QAAQ,gBAAgB,UAAU,SAAS,aAAa,SAAS,SAAS,CAE1E,WAAW,SAAS,IAAI;IAC3B;GAEL,CAAC,CAAC,QAAQ,KAAK,EAAE,QAAQ,YAAY,CAAC,CAAC;;;;;;;;AAS1C,SAAS,iBAAiB,UAAkB,cAA8C;CACxF,OAAO,SACJ,MAAM,MAAM,CACZ,OAAO,QAAQ,CACf,KAAK,QAAQ;EACZ,KAAK,MAAM,CAAC,MAAM,OAAO,OAAO,QAAQ,aAAa,EACnD,MAAM,IAAI,MAAM,KAAK,CAAC,KAAK,GAAG;EAEhC,OAAO;GACP,CACD,KAAK,IAAI;;;;;;;;;;;;;;;;AAiBd,SAAgB,eAAe,KAAkB,SAAoB,EAAE,EAAe;CACpF,MAAM,SAAS,OAAO,QAAQ;CAE9B,IAAI,CAAC,QAAQ,OAAO;CAEpB,MAAM,eACJ,UAAU,OAAO,WAAW,WACxB;EAAE,GAAG;EAAsB,GAAG;EAAQ,GACtC;CAEN,KAAK,MAAM,SAAS;EAClB,MAAM,KAAK;EAGX,IAAI,GAAG,SAAS,WAAW,GAAG,UAAU,QAAQ;GAC9C,MAAM,OAAO,GAAG,SAAS,MAAM,MAAM,EAAE,SAAS,OAAO;GACvD,IAAI,MAAM,MAAM,MAAM,EACpB,KAAK,OAAO,oBAAoB,KAAK,MAAM,aAAa;;EAK5D,IAAI,aAAa,MAAM,GAAG,SAAS,OACjC,GAAG,QAAQ,QAAQ,iBAAiB,GAAG,QAAQ,OAAO,aAAa;GAErE;CAEF,OAAO"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ChildNode } from "domhandler";
|
|
2
|
+
|
|
3
|
+
//#region src/transformers/shorthandCss.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options for the `shorthandCss` transformer.
|
|
6
|
+
*/
|
|
7
|
+
interface ShorthandCssOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Restrict the transform to a list of HTML tag names. Omit to apply to
|
|
10
|
+
* every element with a `style` attribute.
|
|
11
|
+
*
|
|
12
|
+
* @example ['td', 'div']
|
|
13
|
+
*/
|
|
14
|
+
tags?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Rewrite longhand CSS inside inline `style` attributes with shorthand
|
|
18
|
+
* syntax. Works with margin, padding, and border when all sides are
|
|
19
|
+
* specified.
|
|
20
|
+
*
|
|
21
|
+
* For example:
|
|
22
|
+
* `margin-left: 2px; margin-right: 2px; margin-top: 4px; margin-bottom: 4px`
|
|
23
|
+
* becomes:
|
|
24
|
+
* `margin: 4px 2px`
|
|
25
|
+
*
|
|
26
|
+
* @param html HTML string to transform.
|
|
27
|
+
* @param options Optional Maizzle options (`tags`).
|
|
28
|
+
* @returns The transformed HTML string.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import { shorthandCss } from '@maizzle/framework'
|
|
32
|
+
*
|
|
33
|
+
* const out = shorthandCss(
|
|
34
|
+
* '<p style="margin-top: 4px; margin-right: 2px; margin-bottom: 4px; margin-left: 2px;">x</p>',
|
|
35
|
+
* { tags: ['p'] },
|
|
36
|
+
* )
|
|
37
|
+
*/
|
|
38
|
+
declare function shorthandCss(html: string, options?: ShorthandCssOptions): string;
|
|
39
|
+
/**
|
|
40
|
+
* DOM-form of {@link shorthandCss} used by the internal transformer
|
|
41
|
+
* pipeline. Takes a parsed DOM, returns a parsed DOM — avoids redundant
|
|
42
|
+
* serialize/parse round-trips when chained with other transformers.
|
|
43
|
+
*/
|
|
44
|
+
declare function shorthandCssDom(dom: ChildNode[], options?: ShorthandCssOptions): ChildNode[];
|
|
45
|
+
//#endregion
|
|
46
|
+
export { ShorthandCssOptions, shorthandCss, shorthandCssDom };
|
|
47
|
+
//# sourceMappingURL=shorthandCss.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shorthandCss.d.ts","names":[],"sources":["../../src/transformers/shorthandCss.ts"],"mappings":";;;;;AASA;UAAiB,mBAAA;;;;AAgCjB;;;EAzBE,IAAA;AAAA;;;;;AAkCF;;;;;;;;;;;;;;;;;;iBATgB,YAAA,CAAa,IAAA,UAAc,OAAA,GAAS,mBAAA;;;;;;iBASpC,eAAA,CAAgB,GAAA,EAAK,SAAA,IAAa,OAAA,GAAS,mBAAA,GAA2B,SAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { parse } from "../utils/ast/parser.js";
|
|
2
|
+
import { walk } from "../utils/ast/walker.js";
|
|
3
|
+
import { serialize } from "../utils/ast/serializer.js";
|
|
4
|
+
import "../utils/ast/index.js";
|
|
5
|
+
import postcss from "postcss";
|
|
6
|
+
import safeParser from "postcss-safe-parser";
|
|
7
|
+
import mergeLonghand from "postcss-merge-longhand";
|
|
8
|
+
//#region src/transformers/shorthandCss.ts
|
|
9
|
+
/**
|
|
10
|
+
* Rewrite longhand CSS inside inline `style` attributes with shorthand
|
|
11
|
+
* syntax. Works with margin, padding, and border when all sides are
|
|
12
|
+
* specified.
|
|
13
|
+
*
|
|
14
|
+
* For example:
|
|
15
|
+
* `margin-left: 2px; margin-right: 2px; margin-top: 4px; margin-bottom: 4px`
|
|
16
|
+
* becomes:
|
|
17
|
+
* `margin: 4px 2px`
|
|
18
|
+
*
|
|
19
|
+
* @param html HTML string to transform.
|
|
20
|
+
* @param options Optional Maizzle options (`tags`).
|
|
21
|
+
* @returns The transformed HTML string.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { shorthandCss } from '@maizzle/framework'
|
|
25
|
+
*
|
|
26
|
+
* const out = shorthandCss(
|
|
27
|
+
* '<p style="margin-top: 4px; margin-right: 2px; margin-bottom: 4px; margin-left: 2px;">x</p>',
|
|
28
|
+
* { tags: ['p'] },
|
|
29
|
+
* )
|
|
30
|
+
*/
|
|
31
|
+
function shorthandCss(html, options = {}) {
|
|
32
|
+
return serialize(shorthandCssDom(parse(html), options));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* DOM-form of {@link shorthandCss} used by the internal transformer
|
|
36
|
+
* pipeline. Takes a parsed DOM, returns a parsed DOM — avoids redundant
|
|
37
|
+
* serialize/parse round-trips when chained with other transformers.
|
|
38
|
+
*/
|
|
39
|
+
function shorthandCssDom(dom, options = {}) {
|
|
40
|
+
const allowedTags = options.tags ?? [];
|
|
41
|
+
const hasTagFilter = allowedTags.length > 0;
|
|
42
|
+
walk(dom, (node) => {
|
|
43
|
+
const el = node;
|
|
44
|
+
if (!el.attribs?.style) return;
|
|
45
|
+
if (hasTagFilter && !allowedTags.includes(el.name)) return;
|
|
46
|
+
const styleValue = el.attribs.style;
|
|
47
|
+
try {
|
|
48
|
+
const { css } = postcss().use(mergeLonghand).process(`div { ${styleValue} }`, { parser: safeParser });
|
|
49
|
+
const match = css.match(/div\s*\{\s*([^}]+)\s*\}/);
|
|
50
|
+
if (match && match[1]) {
|
|
51
|
+
const newStyle = match[1].trim();
|
|
52
|
+
if (newStyle !== styleValue) el.attribs.style = newStyle;
|
|
53
|
+
}
|
|
54
|
+
} catch {}
|
|
55
|
+
});
|
|
56
|
+
return dom;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { shorthandCss, shorthandCssDom };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=shorthandCss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shorthandCss.js","names":[],"sources":["../../src/transformers/shorthandCss.ts"],"sourcesContent":["import postcss from 'postcss'\nimport safeParser from 'postcss-safe-parser'\nimport mergeLonghand from 'postcss-merge-longhand'\nimport type { ChildNode, Element } from 'domhandler'\nimport { parse, serialize, walk } from '../utils/ast/index.ts'\n\n/**\n * Options for the `shorthandCss` transformer.\n */\nexport interface ShorthandCssOptions {\n /**\n * Restrict the transform to a list of HTML tag names. Omit to apply to\n * every element with a `style` attribute.\n *\n * @example ['td', 'div']\n */\n tags?: string[]\n}\n\n/**\n * Rewrite longhand CSS inside inline `style` attributes with shorthand\n * syntax. Works with margin, padding, and border when all sides are\n * specified.\n *\n * For example:\n * `margin-left: 2px; margin-right: 2px; margin-top: 4px; margin-bottom: 4px`\n * becomes:\n * `margin: 4px 2px`\n *\n * @param html HTML string to transform.\n * @param options Optional Maizzle options (`tags`).\n * @returns The transformed HTML string.\n *\n * @example\n * import { shorthandCss } from '@maizzle/framework'\n *\n * const out = shorthandCss(\n * '<p style=\"margin-top: 4px; margin-right: 2px; margin-bottom: 4px; margin-left: 2px;\">x</p>',\n * { tags: ['p'] },\n * )\n */\nexport function shorthandCss(html: string, options: ShorthandCssOptions = {}): string {\n return serialize(shorthandCssDom(parse(html), options))\n}\n\n/**\n * DOM-form of {@link shorthandCss} used by the internal transformer\n * pipeline. Takes a parsed DOM, returns a parsed DOM — avoids redundant\n * serialize/parse round-trips when chained with other transformers.\n */\nexport function shorthandCssDom(dom: ChildNode[], options: ShorthandCssOptions = {}): ChildNode[] {\n const allowedTags = options.tags ?? []\n const hasTagFilter = allowedTags.length > 0\n\n walk(dom, (node) => {\n const el = node as Element\n\n // Skip if no attribs or no style\n if (!el.attribs?.style) {\n return\n }\n\n // Skip if tag filter is active and this tag is not allowed\n if (hasTagFilter && !allowedTags.includes(el.name)) {\n return\n }\n\n const styleValue = el.attribs.style\n\n try {\n // Process the style with postcss-merge-longhand\n // Wrap in a dummy selector since postcss needs a rule\n const { css } = postcss()\n .use(mergeLonghand)\n .process(`div { ${styleValue} }`, { parser: safeParser })\n\n // Extract the content between the braces\n const match = css.match(/div\\s*\\{\\s*([^}]+)\\s*\\}/)\n if (match && match[1]) {\n const newStyle = match[1].trim()\n if (newStyle !== styleValue) {\n el.attribs.style = newStyle\n }\n }\n } catch {\n // If processing fails, keep the original style\n }\n })\n\n return dom\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAAa,MAAc,UAA+B,EAAE,EAAU;CACpF,OAAO,UAAU,gBAAgB,MAAM,KAAK,EAAE,QAAQ,CAAC;;;;;;;AAQzD,SAAgB,gBAAgB,KAAkB,UAA+B,EAAE,EAAe;CAChG,MAAM,cAAc,QAAQ,QAAQ,EAAE;CACtC,MAAM,eAAe,YAAY,SAAS;CAE1C,KAAK,MAAM,SAAS;EAClB,MAAM,KAAK;EAGX,IAAI,CAAC,GAAG,SAAS,OACf;EAIF,IAAI,gBAAgB,CAAC,YAAY,SAAS,GAAG,KAAK,EAChD;EAGF,MAAM,aAAa,GAAG,QAAQ;EAE9B,IAAI;GAGF,MAAM,EAAE,QAAQ,SAAS,CACtB,IAAI,cAAc,CAClB,QAAQ,SAAS,WAAW,KAAK,EAAE,QAAQ,YAAY,CAAC;GAG3D,MAAM,QAAQ,IAAI,MAAM,0BAA0B;GAClD,IAAI,SAAS,MAAM,IAAI;IACrB,MAAM,WAAW,MAAM,GAAG,MAAM;IAChC,IAAI,aAAa,YACf,GAAG,QAAQ,QAAQ;;UAGjB;GAGR;CAEF,OAAO"}
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import { CssConfig } from "../types/config.js";
|
|
2
1
|
import { ChildNode } from "domhandler";
|
|
3
2
|
|
|
4
3
|
//#region src/transformers/sixHex.d.ts
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Converts 3-digit HEX color codes to 6-digit in `bgcolor` and `color`
|
|
5
|
+
* Convert 3-digit HEX color codes to 6-digit in `bgcolor` and `color`
|
|
9
6
|
* attributes, for better email client compatibility.
|
|
10
7
|
*
|
|
11
|
-
*
|
|
8
|
+
* @param html HTML string to transform.
|
|
9
|
+
* @returns The transformed HTML string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { sixHex } from '@maizzle/framework'
|
|
13
|
+
*
|
|
14
|
+
* const out = sixHex('<font color="#abc">x</font>')
|
|
15
|
+
*/
|
|
16
|
+
declare function sixHex(html: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* DOM-form of {@link sixHex} used by the internal transformer pipeline.
|
|
19
|
+
* Takes a parsed DOM, returns a parsed DOM — avoids redundant
|
|
20
|
+
* serialize/parse round-trips when chained with other transformers.
|
|
12
21
|
*/
|
|
13
|
-
declare function
|
|
22
|
+
declare function sixHexDom(dom: ChildNode[]): ChildNode[];
|
|
14
23
|
//#endregion
|
|
15
|
-
export { sixHex };
|
|
24
|
+
export { sixHex, sixHexDom };
|
|
16
25
|
//# sourceMappingURL=sixHex.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sixHex.d.ts","names":[],"sources":["../../src/transformers/sixHex.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sixHex.d.ts","names":[],"sources":["../../src/transformers/sixHex.ts"],"mappings":";;;;;AAkBA;;;;;AASA;;;;;iBATgB,MAAA,CAAO,IAAA;;;;;;iBASP,SAAA,CAAU,GAAA,EAAK,SAAA,KAAc,SAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { parse } from "../utils/ast/parser.js";
|
|
2
|
+
import { walk } from "../utils/ast/walker.js";
|
|
3
|
+
import { serialize } from "../utils/ast/serializer.js";
|
|
4
|
+
import "../utils/ast/index.js";
|
|
5
|
+
import { conv } from "color-shorthand-hex-to-six-digit";
|
|
6
|
+
//#region src/transformers/sixHex.ts
|
|
7
|
+
const targets = new Set(["bgcolor", "color"]);
|
|
8
|
+
/**
|
|
9
|
+
* Convert 3-digit HEX color codes to 6-digit in `bgcolor` and `color`
|
|
10
|
+
* attributes, for better email client compatibility.
|
|
11
|
+
*
|
|
12
|
+
* @param html HTML string to transform.
|
|
13
|
+
* @returns The transformed HTML string.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { sixHex } from '@maizzle/framework'
|
|
17
|
+
*
|
|
18
|
+
* const out = sixHex('<font color="#abc">x</font>')
|
|
19
|
+
*/
|
|
20
|
+
function sixHex(html) {
|
|
21
|
+
return serialize(sixHexDom(parse(html)));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* DOM-form of {@link sixHex} used by the internal transformer pipeline.
|
|
25
|
+
* Takes a parsed DOM, returns a parsed DOM — avoids redundant
|
|
26
|
+
* serialize/parse round-trips when chained with other transformers.
|
|
27
|
+
*/
|
|
28
|
+
function sixHexDom(dom) {
|
|
29
|
+
walk(dom, (node) => {
|
|
30
|
+
const el = node;
|
|
31
|
+
if (!el.attribs) return;
|
|
32
|
+
for (const attr of targets) {
|
|
33
|
+
const value = el.attribs[attr];
|
|
34
|
+
if (value) el.attribs[attr] = conv(value);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return dom;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { sixHex, sixHexDom };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=sixHex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sixHex.js","names":[],"sources":["../../src/transformers/sixHex.ts"],"sourcesContent":["import { conv } from 'color-shorthand-hex-to-six-digit'\nimport type { ChildNode, Element } from 'domhandler'\nimport { parse, serialize, walk } from '../utils/ast/index.ts'\n\nconst targets = new Set(['bgcolor', 'color'])\n\n/**\n * Convert 3-digit HEX color codes to 6-digit in `bgcolor` and `color`\n * attributes, for better email client compatibility.\n *\n * @param html HTML string to transform.\n * @returns The transformed HTML string.\n *\n * @example\n * import { sixHex } from '@maizzle/framework'\n *\n * const out = sixHex('<font color=\"#abc\">x</font>')\n */\nexport function sixHex(html: string): string {\n return serialize(sixHexDom(parse(html)))\n}\n\n/**\n * DOM-form of {@link sixHex} used by the internal transformer pipeline.\n * Takes a parsed DOM, returns a parsed DOM — avoids redundant\n * serialize/parse round-trips when chained with other transformers.\n */\nexport function sixHexDom(dom: ChildNode[]): ChildNode[] {\n walk(dom, (node) => {\n const el = node as Element\n\n if (!el.attribs) {\n return\n }\n\n for (const attr of targets) {\n const value = el.attribs[attr]\n\n if (value) {\n el.attribs[attr] = conv(value)\n }\n }\n })\n\n return dom\n}\n"],"mappings":";;;;;;AAIA,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,QAAQ,CAAC;;;;;;;;;;;;;AAc7C,SAAgB,OAAO,MAAsB;CAC3C,OAAO,UAAU,UAAU,MAAM,KAAK,CAAC,CAAC;;;;;;;AAQ1C,SAAgB,UAAU,KAA+B;CACvD,KAAK,MAAM,SAAS;EAClB,MAAM,KAAK;EAEX,IAAI,CAAC,GAAG,SACN;EAGF,KAAK,MAAM,QAAQ,SAAS;GAC1B,MAAM,QAAQ,GAAG,QAAQ;GAEzB,IAAI,OACF,GAAG,QAAQ,QAAQ,KAAK,MAAM;;GAGlC;CAEF,OAAO"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { walk } from "../utils/ast/walker.
|
|
2
|
-
import "../utils/ast/index.
|
|
3
|
-
import { compileTailwindCss } from "../utils/compileTailwindCss.
|
|
1
|
+
import { walk } from "../utils/ast/walker.js";
|
|
2
|
+
import "../utils/ast/index.js";
|
|
3
|
+
import { compileTailwindCss } from "../utils/compileTailwindCss.js";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
|
-
|
|
6
5
|
//#region src/transformers/tailwindComponent.ts
|
|
7
6
|
const DEFAULT_SEED = "@import \"@maizzle/tailwindcss\";";
|
|
8
7
|
const OPEN_RE = /^mz-tw:(\S+)$/;
|
|
@@ -87,7 +86,7 @@ function buildCssInput(configCss, classes) {
|
|
|
87
86
|
if (!classes.size) return seed;
|
|
88
87
|
return `${seed}\n@source inline("${[...classes].join(" ").replace(/"/g, "\\\"")}");`;
|
|
89
88
|
}
|
|
90
|
-
|
|
91
89
|
//#endregion
|
|
92
90
|
export { tailwindComponent };
|
|
93
|
-
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=tailwindComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tailwindComponent.js","names":[],"sources":["../../src/transformers/tailwindComponent.ts"],"sourcesContent":["import { resolve } from 'node:path'\nimport type { ChildNode, Element, Comment } from 'domhandler'\nimport { walk } from '../utils/ast/index.ts'\nimport { compileTailwindCss } from '../utils/compileTailwindCss.ts'\nimport type { TailwindBlock } from '../composables/renderContext.ts'\nimport type { MaizzleConfig } from '../types/config.ts'\n\nconst DEFAULT_SEED = '@import \"@maizzle/tailwindcss\";'\n\ninterface BlockMeta {\n id: string\n configCss?: string\n nested: boolean\n classes: Set<string>\n}\n\nconst OPEN_RE = /^mz-tw:(\\S+)$/\nconst CLOSE_RE = /^\\/mz-tw:(\\S+)$/\n\n/**\n * Compile Tailwind CSS for each top-level <Tailwind> block in the render\n * context. Nested <Tailwind> instances are flattened: their classes flow\n * up to the outermost block, their `#config` slot (if any) is ignored.\n * One <style> per outermost block is appended to <head>; marker comments\n * are stripped after.\n */\nexport async function tailwindComponent(\n dom: ChildNode[],\n blocks: TailwindBlock[],\n config: MaizzleConfig,\n filePath?: string,\n): Promise<ChildNode[]> {\n if (!blocks.length) return dom\n\n const map = new Map<string, BlockMeta>()\n for (const b of blocks) {\n map.set(b.id, { id: b.id, configCss: b.css, nested: false, classes: new Set() })\n }\n\n const stack: string[] = []\n const markers: Comment[] = []\n\n walk(dom, (node) => {\n if (node.type === 'comment') {\n const data = (node as Comment).data\n const open = data.match(OPEN_RE)\n const close = data.match(CLOSE_RE)\n if (open) {\n const id = open[1]\n const meta = map.get(id)\n if (meta && stack.length > 0) meta.nested = true\n if (meta) stack.push(id)\n markers.push(node as Comment)\n } else if (close) {\n const id = close[1]\n if (stack[stack.length - 1] === id) stack.pop()\n markers.push(node as Comment)\n }\n return\n }\n\n const el = node as Element\n // Always assign to the OUTERMOST active marker (stack[0]) so nested\n // <Tailwind> blocks merge their classes into the parent's scope.\n if (el.attribs?.class && stack.length > 0) {\n map.get(stack[0])!.classes.add(el.attribs.class)\n }\n })\n\n const fromPath = filePath ?? resolve(process.cwd(), 'template.vue')\n\n let head: Element | undefined\n walk(dom, (n) => {\n if (!head && (n as Element).name === 'head') head = n as Element\n })\n\n if (!head) {\n throw new Error('`Tailwind` component requires `Head` component to be present in the template.')\n }\n\n // Compile + inject one <style raw> per outermost block. `raw` opts the\n // existing tailwindcss transformer out of recompiling already-compiled CSS.\n for (const meta of map.values()) {\n if (meta.nested) continue\n\n const cssInput = buildCssInput(meta.configCss, meta.classes)\n const css = (await compileTailwindCss(cssInput, config, `${fromPath}?tw=${meta.id}`)).trim()\n if (!css) continue\n\n const styleNode: Element = {\n type: 'tag',\n name: 'style',\n attribs: { raw: '' },\n children: [],\n parent: head,\n prev: null,\n next: null,\n } as any\n\n const textNode = {\n type: 'text',\n data: css,\n parent: styleNode,\n prev: null,\n next: null,\n } as any\n\n styleNode.children = [textNode]\n head.children.push(styleNode)\n }\n\n // Strip marker comments from their parents\n for (const c of markers) {\n const parent = c.parent as Element | null\n if (!parent?.children) continue\n const i = parent.children.indexOf(c)\n if (i >= 0) parent.children.splice(i, 1)\n }\n\n return dom\n}\n\nfunction buildCssInput(configCss: string | undefined, classes: Set<string>): string {\n const seed = configCss ?? DEFAULT_SEED\n\n if (!classes.size) return seed\n\n const inline = [...classes].join(' ').replace(/\"/g, '\\\\\"')\n return `${seed}\\n@source inline(\"${inline}\");`\n}\n"],"mappings":";;;;;AAOA,MAAM,eAAe;AASrB,MAAM,UAAU;AAChB,MAAM,WAAW;;;;;;;;AASjB,eAAsB,kBACpB,KACA,QACA,QACA,UACsB;CACtB,IAAI,CAAC,OAAO,QAAQ,OAAO;CAE3B,MAAM,sBAAM,IAAI,KAAwB;CACxC,KAAK,MAAM,KAAK,QACd,IAAI,IAAI,EAAE,IAAI;EAAE,IAAI,EAAE;EAAI,WAAW,EAAE;EAAK,QAAQ;EAAO,yBAAS,IAAI,KAAK;EAAE,CAAC;CAGlF,MAAM,QAAkB,EAAE;CAC1B,MAAM,UAAqB,EAAE;CAE7B,KAAK,MAAM,SAAS;EAClB,IAAI,KAAK,SAAS,WAAW;GAC3B,MAAM,OAAQ,KAAiB;GAC/B,MAAM,OAAO,KAAK,MAAM,QAAQ;GAChC,MAAM,QAAQ,KAAK,MAAM,SAAS;GAClC,IAAI,MAAM;IACR,MAAM,KAAK,KAAK;IAChB,MAAM,OAAO,IAAI,IAAI,GAAG;IACxB,IAAI,QAAQ,MAAM,SAAS,GAAG,KAAK,SAAS;IAC5C,IAAI,MAAM,MAAM,KAAK,GAAG;IACxB,QAAQ,KAAK,KAAgB;UACxB,IAAI,OAAO;IAChB,MAAM,KAAK,MAAM;IACjB,IAAI,MAAM,MAAM,SAAS,OAAO,IAAI,MAAM,KAAK;IAC/C,QAAQ,KAAK,KAAgB;;GAE/B;;EAGF,MAAM,KAAK;EAGX,IAAI,GAAG,SAAS,SAAS,MAAM,SAAS,GACtC,IAAI,IAAI,MAAM,GAAG,CAAE,QAAQ,IAAI,GAAG,QAAQ,MAAM;GAElD;CAEF,MAAM,WAAW,YAAY,QAAQ,QAAQ,KAAK,EAAE,eAAe;CAEnE,IAAI;CACJ,KAAK,MAAM,MAAM;EACf,IAAI,CAAC,QAAS,EAAc,SAAS,QAAQ,OAAO;GACpD;CAEF,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,gFAAgF;CAKlG,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE;EAC/B,IAAI,KAAK,QAAQ;EAGjB,MAAM,OAAO,MAAM,mBADF,cAAc,KAAK,WAAW,KAAK,QACN,EAAE,QAAQ,GAAG,SAAS,MAAM,KAAK,KAAK,EAAE,MAAM;EAC5F,IAAI,CAAC,KAAK;EAEV,MAAM,YAAqB;GACzB,MAAM;GACN,MAAM;GACN,SAAS,EAAE,KAAK,IAAI;GACpB,UAAU,EAAE;GACZ,QAAQ;GACR,MAAM;GACN,MAAM;GACP;EAUD,UAAU,WAAW,CAAC;GAPpB,MAAM;GACN,MAAM;GACN,QAAQ;GACR,MAAM;GACN,MAAM;GAGsB,CAAC;EAC/B,KAAK,SAAS,KAAK,UAAU;;CAI/B,KAAK,MAAM,KAAK,SAAS;EACvB,MAAM,SAAS,EAAE;EACjB,IAAI,CAAC,QAAQ,UAAU;EACvB,MAAM,IAAI,OAAO,SAAS,QAAQ,EAAE;EACpC,IAAI,KAAK,GAAG,OAAO,SAAS,OAAO,GAAG,EAAE;;CAG1C,OAAO;;AAGT,SAAS,cAAc,WAA+B,SAA8B;CAClF,MAAM,OAAO,aAAa;CAE1B,IAAI,CAAC,QAAQ,MAAM,OAAO;CAG1B,OAAO,GAAG,KAAK,oBADA,CAAC,GAAG,QAAQ,CAAC,KAAK,IAAI,CAAC,QAAQ,MAAM,OACX,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { walk } from "../utils/ast/walker.
|
|
2
|
-
import "../utils/ast/index.
|
|
3
|
-
import { compileTailwindCss } from "../utils/compileTailwindCss.
|
|
4
|
-
import { decodeStyleEntities } from "../utils/decodeStyleEntities.
|
|
1
|
+
import { walk } from "../utils/ast/walker.js";
|
|
2
|
+
import "../utils/ast/index.js";
|
|
3
|
+
import { compileTailwindCss } from "../utils/compileTailwindCss.js";
|
|
4
|
+
import { decodeStyleEntities } from "../utils/decodeStyleEntities.js";
|
|
5
5
|
import { dirname, relative, resolve } from "node:path";
|
|
6
|
-
|
|
7
6
|
//#region src/transformers/tailwindcss.ts
|
|
8
7
|
/**
|
|
9
8
|
* Check if CSS content uses Tailwind features that require source scanning.
|
|
@@ -92,7 +91,7 @@ async function tailwindcss(dom, config, filePath) {
|
|
|
92
91
|
}
|
|
93
92
|
return dom;
|
|
94
93
|
}
|
|
95
|
-
|
|
96
94
|
//#endregion
|
|
97
95
|
export { tailwindcss };
|
|
98
|
-
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=tailwindcss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tailwindcss.js","names":[],"sources":["../../src/transformers/tailwindcss.ts"],"sourcesContent":["import { resolve, dirname, relative } from 'node:path'\nimport type { ChildNode, Element } from 'domhandler'\nimport { walk } from '../utils/ast/index.ts'\nimport { decodeStyleEntities } from '../utils/decodeStyleEntities.ts'\nimport { compileTailwindCss } from '../utils/compileTailwindCss.ts'\nimport type { MaizzleConfig } from '../types/config.ts'\n\n/**\n * Check if CSS content uses Tailwind features that require source scanning.\n *\n * Only CSS that imports Tailwind (or @maizzle/tailwindcss) needs @source\n * directives. Plain CSS without Tailwind imports doesn't need scanning\n * and would pass through @source directives unconsumed.\n */\nfunction usesTailwind(css: string): boolean {\n return /((@import|@reference)\\s+[\"'](tailwindcss|@maizzle\\/tailwindcss)|@tailwind\\s)/.test(css)\n}\n\n/**\n * Build @source directives for Tailwind CSS scanning.\n *\n * Configures two types of sources:\n * 1. Exclusions for output dir and user-configured paths\n * 2. Inline source with all class attribute values from the rendered DOM,\n * capturing classes from all components (built-in + user), dynamic\n * expressions, and the template itself — Tailwind's scanner handles\n * the actual class extraction from these raw values\n */\nfunction buildSourceDirectives(dom: ChildNode[], config: MaizzleConfig, fromDir: string): string {\n const directives: string[] = []\n\n // Exclude output dir and user-configured paths\n const excludePaths = [\n resolve(config.output?.path ?? 'dist'),\n ...(config.css?.exclude ?? []).map(p => resolve(p)),\n ]\n\n for (const p of excludePaths) {\n directives.push(`@source not \"${relative(fromDir, resolve(p))}\";`)\n }\n\n // Inline source: collect all class attribute values from the rendered DOM.\n // After Vue SSR, the DOM contains every class from every component\n // (built-in framework components, user components, dynamic bindings).\n // We pass these raw values to Tailwind's scanner via @source inline().\n const classes: string[] = []\n walk(dom, (n) => {\n const cls = (n as Element).attribs?.class\n if (cls) classes.push(cls)\n })\n\n if (classes.length) {\n directives.push(`@source inline(\"${classes.join(' ')}\");`)\n }\n\n return directives.join('\\n')\n}\n\n/**\n * Tailwind CSS transformer.\n *\n * Compiles CSS inside <style> tags in the DOM using\n * @tailwindcss/postcss, then lowers modern CSS syntax with lightningcss.\n *\n * Configures Tailwind sources to scan:\n * - Rendered class attributes (via `@source inline`) for all classes from all components\n * - User project files (via Tailwind's auto-detection from base/from path)\n *\n * User `@source` and `@source not directives` in style tags are preserved.\n * Source directives are only added to style tags that import Tailwind.\n *\n * Runs as the first transformer in the pipeline so that subsequent\n * transformers (inliner, purge, etc.) work with fully compiled CSS.\n */\nexport async function tailwindcss(dom: ChildNode[], config: MaizzleConfig, filePath?: string): Promise<ChildNode[]> {\n const styleTags: { node: Element; cssContent: string }[] = []\n\n walk(dom, (node) => {\n if ((node as Element).name !== 'style') return\n\n const el = node as Element\n const attrs = el.attribs || {}\n\n // `raw` opts out of compilation entirely (marker is consumed here).\n // `embed`/`data-embed` only signal \"preserve tag after inlining\" — they\n // still need to go through compile so Tailwind/@apply resolves.\n if ('raw' in attrs) {\n delete el.attribs.raw\n return\n }\n\n // Get text content from children and decode HTML entities\n const rawContent = el.children\n .filter(child => child.type === 'text')\n .map(child => (child as any).data)\n .join('')\n\n if (!rawContent.trim()) return\n\n styleTags.push({ node: el, cssContent: decodeStyleEntities(rawContent) })\n })\n\n if (!styleTags.length) return dom\n\n const fromPath = filePath ?? resolve(process.cwd(), 'template.vue')\n const fromDir = dirname(fromPath)\n\n // Only compute source directives if at least one style tag uses Tailwind\n const hasTailwindStyles = styleTags.some(({ cssContent }) => usesTailwind(cssContent))\n const sourceDirectives = hasTailwindStyles\n ? buildSourceDirectives(dom, config, fromDir)\n : ''\n\n for (let i = 0; i < styleTags.length; i++) {\n const { node, cssContent } = styleTags[i]\n\n // Only add source directives to style tags that import Tailwind —\n // plain CSS doesn't need them and @tailwindcss/postcss would leave\n // the directives unconsumed in the output\n const fullCss = usesTailwind(cssContent)\n ? `${cssContent}\\n${sourceDirectives}`\n : cssContent\n\n try {\n const optimized = await compileTailwindCss(fullCss, config, `${fromPath}?style=${i}`)\n\n // Replace the style tag's children with the compiled CSS\n node.children = [{\n type: 'text',\n data: optimized,\n parent: node,\n } as any]\n } catch {\n // If CSS processing fails, still replace with decoded content\n // so HTML entities don't break the CSS\n node.children = [{\n type: 'text',\n data: cssContent,\n parent: node,\n } as any]\n }\n }\n\n return dom\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,aAAa,KAAsB;CAC1C,OAAO,+EAA+E,KAAK,IAAI;;;;;;;;;;;;AAajG,SAAS,sBAAsB,KAAkB,QAAuB,SAAyB;CAC/F,MAAM,aAAuB,EAAE;CAG/B,MAAM,eAAe,CACnB,QAAQ,OAAO,QAAQ,QAAQ,OAAO,EACtC,IAAI,OAAO,KAAK,WAAW,EAAE,EAAE,KAAI,MAAK,QAAQ,EAAE,CAAC,CACpD;CAED,KAAK,MAAM,KAAK,cACd,WAAW,KAAK,gBAAgB,SAAS,SAAS,QAAQ,EAAE,CAAC,CAAC,IAAI;CAOpE,MAAM,UAAoB,EAAE;CAC5B,KAAK,MAAM,MAAM;EACf,MAAM,MAAO,EAAc,SAAS;EACpC,IAAI,KAAK,QAAQ,KAAK,IAAI;GAC1B;CAEF,IAAI,QAAQ,QACV,WAAW,KAAK,mBAAmB,QAAQ,KAAK,IAAI,CAAC,KAAK;CAG5D,OAAO,WAAW,KAAK,KAAK;;;;;;;;;;;;;;;;;;AAmB9B,eAAsB,YAAY,KAAkB,QAAuB,UAAyC;CAClH,MAAM,YAAqD,EAAE;CAE7D,KAAK,MAAM,SAAS;EAClB,IAAK,KAAiB,SAAS,SAAS;EAExC,MAAM,KAAK;EAMX,IAAI,UALU,GAAG,WAAW,EAAE,GAKV;GAClB,OAAO,GAAG,QAAQ;GAClB;;EAIF,MAAM,aAAa,GAAG,SACnB,QAAO,UAAS,MAAM,SAAS,OAAO,CACtC,KAAI,UAAU,MAAc,KAAK,CACjC,KAAK,GAAG;EAEX,IAAI,CAAC,WAAW,MAAM,EAAE;EAExB,UAAU,KAAK;GAAE,MAAM;GAAI,YAAY,oBAAoB,WAAW;GAAE,CAAC;GACzE;CAEF,IAAI,CAAC,UAAU,QAAQ,OAAO;CAE9B,MAAM,WAAW,YAAY,QAAQ,QAAQ,KAAK,EAAE,eAAe;CACnE,MAAM,UAAU,QAAQ,SAAS;CAIjC,MAAM,mBADoB,UAAU,MAAM,EAAE,iBAAiB,aAAa,WAAW,CAC3C,GACtC,sBAAsB,KAAK,QAAQ,QAAQ,GAC3C;CAEJ,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,EAAE,MAAM,eAAe,UAAU;EAKvC,MAAM,UAAU,aAAa,WAAW,GACpC,GAAG,WAAW,IAAI,qBAClB;EAEJ,IAAI;GAIF,KAAK,WAAW,CAAC;IACf,MAAM;IACN,MAAM,MALgB,mBAAmB,SAAS,QAAQ,GAAG,SAAS,SAAS,IAAI;IAMnF,QAAQ;IACT,CAAQ;UACH;GAGN,KAAK,WAAW,CAAC;IACf,MAAM;IACN,MAAM;IACN,QAAQ;IACT,CAAQ;;;CAIb,OAAO"}
|
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UrlQueryOptions } from "../types/config.js";
|
|
2
2
|
import { ChildNode } from "domhandler";
|
|
3
3
|
|
|
4
4
|
//#region src/transformers/urlQuery.d.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Append query parameters to URLs found in matching attributes/elements.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* @param html HTML string to transform.
|
|
9
|
+
* @param params Query parameters to append (e.g. `{ utm_source: 'newsletter' }`).
|
|
10
|
+
* @param options Behaviour overrides — `tags` (CSS selectors, default `['a']`),
|
|
11
|
+
* `attributes` (default `['src', 'href', 'poster', 'srcset', 'background']`),
|
|
12
|
+
* `strict` (default `true`, only rewrites absolute URLs),
|
|
13
|
+
* `qs` (forwarded to `query-string`, default `{ encode: false }`).
|
|
14
|
+
* @returns The transformed HTML string.
|
|
10
15
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* The `_options` key inside `query` controls behaviour:
|
|
14
|
-
* - `tags` — CSS selectors for elements to process. Default: `['a']`
|
|
15
|
-
* - `attributes` — attribute names to process. Default: `['src', 'href', 'poster', 'srcset', 'background']`
|
|
16
|
-
* - `strict` — only append to absolute URLs. Default: `true`
|
|
17
|
-
* - `qs` — options forwarded to query-string. Default: `{ encode: false }`
|
|
16
|
+
* @example
|
|
17
|
+
* import { urlQuery } from '@maizzle/framework'
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* const out = urlQuery(
|
|
20
|
+
* '<a href="https://example.com">x</a>',
|
|
21
|
+
* { utm_source: 'newsletter' },
|
|
22
|
+
* )
|
|
23
|
+
*
|
|
24
|
+
* // Restrict to specific tags / attributes:
|
|
25
|
+
* urlQuery(html, { ref: 'email' }, { tags: ['a', 'img'], attributes: ['href', 'src'] })
|
|
26
|
+
*/
|
|
27
|
+
declare function urlQuery(html: string, params?: Record<string, unknown>, options?: UrlQueryOptions): string;
|
|
28
|
+
/**
|
|
29
|
+
* DOM-form of {@link urlQuery} used by the internal transformer pipeline.
|
|
30
|
+
* Takes a parsed DOM, returns a parsed DOM — avoids redundant
|
|
31
|
+
* serialize/parse round-trips when chained with other transformers.
|
|
20
32
|
*/
|
|
21
|
-
declare function
|
|
33
|
+
declare function urlQueryDom(dom: ChildNode[], params?: Record<string, unknown>, options?: UrlQueryOptions): ChildNode[];
|
|
22
34
|
//#endregion
|
|
23
|
-
export { urlQuery };
|
|
35
|
+
export { urlQuery, urlQueryDom };
|
|
24
36
|
//# sourceMappingURL=urlQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlQuery.d.ts","names":[],"sources":["../../src/transformers/urlQuery.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"urlQuery.d.ts","names":[],"sources":["../../src/transformers/urlQuery.ts"],"mappings":";;;;;;AAiDA;;;;;;;;;;;AAaA;;;;;;;;;iBAbgB,QAAA,CACd,IAAA,UACA,MAAA,GAAQ,MAAA,mBACR,OAAA,GAAS,eAAA;;;;;;iBAUK,WAAA,CACd,GAAA,EAAK,SAAA,IACL,MAAA,GAAQ,MAAA,mBACR,OAAA,GAAS,eAAA,GACR,SAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { parse } from "../utils/ast/parser.js";
|
|
2
|
+
import { serialize } from "../utils/ast/serializer.js";
|
|
3
|
+
import "../utils/ast/index.js";
|
|
4
|
+
import { isAbsoluteUrl } from "../utils/url.js";
|
|
5
|
+
import queryString from "query-string";
|
|
6
|
+
import { selectAll } from "css-select";
|
|
7
|
+
//#region src/transformers/urlQuery.ts
|
|
8
|
+
const DEFAULT_ATTRIBUTES = [
|
|
9
|
+
"src",
|
|
10
|
+
"href",
|
|
11
|
+
"poster",
|
|
12
|
+
"srcset",
|
|
13
|
+
"background"
|
|
14
|
+
];
|
|
15
|
+
const DEFAULT_TAGS = ["a"];
|
|
16
|
+
/**
|
|
17
|
+
* Append query parameters to a URL string using query-string.
|
|
18
|
+
*/
|
|
19
|
+
function appendParams(url, params, qsOptions, strict) {
|
|
20
|
+
if (strict && !isAbsoluteUrl(url)) return url;
|
|
21
|
+
return queryString.stringifyUrl({
|
|
22
|
+
url,
|
|
23
|
+
query: params
|
|
24
|
+
}, qsOptions);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Append query parameters to URLs found in matching attributes/elements.
|
|
28
|
+
*
|
|
29
|
+
* @param html HTML string to transform.
|
|
30
|
+
* @param params Query parameters to append (e.g. `{ utm_source: 'newsletter' }`).
|
|
31
|
+
* @param options Behaviour overrides — `tags` (CSS selectors, default `['a']`),
|
|
32
|
+
* `attributes` (default `['src', 'href', 'poster', 'srcset', 'background']`),
|
|
33
|
+
* `strict` (default `true`, only rewrites absolute URLs),
|
|
34
|
+
* `qs` (forwarded to `query-string`, default `{ encode: false }`).
|
|
35
|
+
* @returns The transformed HTML string.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* import { urlQuery } from '@maizzle/framework'
|
|
39
|
+
*
|
|
40
|
+
* const out = urlQuery(
|
|
41
|
+
* '<a href="https://example.com">x</a>',
|
|
42
|
+
* { utm_source: 'newsletter' },
|
|
43
|
+
* )
|
|
44
|
+
*
|
|
45
|
+
* // Restrict to specific tags / attributes:
|
|
46
|
+
* urlQuery(html, { ref: 'email' }, { tags: ['a', 'img'], attributes: ['href', 'src'] })
|
|
47
|
+
*/
|
|
48
|
+
function urlQuery(html, params = {}, options = {}) {
|
|
49
|
+
return serialize(urlQueryDom(parse(html), params, options));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* DOM-form of {@link urlQuery} used by the internal transformer pipeline.
|
|
53
|
+
* Takes a parsed DOM, returns a parsed DOM — avoids redundant
|
|
54
|
+
* serialize/parse round-trips when chained with other transformers.
|
|
55
|
+
*/
|
|
56
|
+
function urlQueryDom(dom, params = {}, options = {}) {
|
|
57
|
+
if (!params || Object.keys(params).length === 0) return dom;
|
|
58
|
+
const tags = options.tags ?? DEFAULT_TAGS;
|
|
59
|
+
const attributes = options.attributes ?? DEFAULT_ATTRIBUTES;
|
|
60
|
+
const strict = options.strict ?? true;
|
|
61
|
+
const qsOptions = {
|
|
62
|
+
encode: false,
|
|
63
|
+
...options.qs ?? {}
|
|
64
|
+
};
|
|
65
|
+
const elements = selectAll(tags.join(", "), dom);
|
|
66
|
+
for (const el of elements) for (const attr of attributes) {
|
|
67
|
+
const value = el.attribs[attr];
|
|
68
|
+
if (!value) continue;
|
|
69
|
+
const updated = appendParams(value, params, qsOptions, strict);
|
|
70
|
+
if (updated !== value) el.attribs[attr] = updated;
|
|
71
|
+
}
|
|
72
|
+
return dom;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { urlQuery, urlQueryDom };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=urlQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlQuery.js","names":[],"sources":["../../src/transformers/urlQuery.ts"],"sourcesContent":["import queryString from 'query-string'\nimport { selectAll } from 'css-select'\nimport type { ChildNode, Element } from 'domhandler'\nimport { parse, serialize } from '../utils/ast/index.ts'\nimport { isAbsoluteUrl } from '../utils/url.ts'\nimport type { UrlQueryOptions } from '../types/config.ts'\n\nconst DEFAULT_ATTRIBUTES = ['src', 'href', 'poster', 'srcset', 'background']\nconst DEFAULT_TAGS = ['a']\n\n/**\n * Append query parameters to a URL string using query-string.\n */\nfunction appendParams(\n url: string,\n params: Record<string, unknown>,\n qsOptions: queryString.StringifyOptions,\n strict: boolean,\n): string {\n if (strict && !isAbsoluteUrl(url)) return url\n\n return queryString.stringifyUrl(\n { url, query: params as queryString.StringifiableRecord },\n qsOptions,\n )\n}\n\n/**\n * Append query parameters to URLs found in matching attributes/elements.\n *\n * @param html HTML string to transform.\n * @param params Query parameters to append (e.g. `{ utm_source: 'newsletter' }`).\n * @param options Behaviour overrides — `tags` (CSS selectors, default `['a']`),\n * `attributes` (default `['src', 'href', 'poster', 'srcset', 'background']`),\n * `strict` (default `true`, only rewrites absolute URLs),\n * `qs` (forwarded to `query-string`, default `{ encode: false }`).\n * @returns The transformed HTML string.\n *\n * @example\n * import { urlQuery } from '@maizzle/framework'\n *\n * const out = urlQuery(\n * '<a href=\"https://example.com\">x</a>',\n * { utm_source: 'newsletter' },\n * )\n *\n * // Restrict to specific tags / attributes:\n * urlQuery(html, { ref: 'email' }, { tags: ['a', 'img'], attributes: ['href', 'src'] })\n */\nexport function urlQuery(\n html: string,\n params: Record<string, unknown> = {},\n options: UrlQueryOptions = {},\n): string {\n return serialize(urlQueryDom(parse(html), params, options))\n}\n\n/**\n * DOM-form of {@link urlQuery} used by the internal transformer pipeline.\n * Takes a parsed DOM, returns a parsed DOM — avoids redundant\n * serialize/parse round-trips when chained with other transformers.\n */\nexport function urlQueryDom(\n dom: ChildNode[],\n params: Record<string, unknown> = {},\n options: UrlQueryOptions = {},\n): ChildNode[] {\n if (!params || Object.keys(params).length === 0) return dom\n\n const tags = options.tags ?? DEFAULT_TAGS\n const attributes = options.attributes ?? DEFAULT_ATTRIBUTES\n const strict = options.strict ?? true\n const qsOptions: queryString.StringifyOptions = { encode: false, ...((options.qs ?? {}) as queryString.StringifyOptions) }\n\n // Use css-select to find all elements matching any of the tag selectors\n const selector = tags.join(', ')\n const elements = selectAll(selector, dom) as Element[]\n\n for (const el of elements) {\n for (const attr of attributes) {\n const value = el.attribs[attr]\n if (!value) continue\n\n const updated = appendParams(value, params, qsOptions, strict)\n if (updated !== value) {\n el.attribs[attr] = updated\n }\n }\n }\n\n return dom\n}\n"],"mappings":";;;;;;;AAOA,MAAM,qBAAqB;CAAC;CAAO;CAAQ;CAAU;CAAU;CAAa;AAC5E,MAAM,eAAe,CAAC,IAAI;;;;AAK1B,SAAS,aACP,KACA,QACA,WACA,QACQ;CACR,IAAI,UAAU,CAAC,cAAc,IAAI,EAAE,OAAO;CAE1C,OAAO,YAAY,aACjB;EAAE;EAAK,OAAO;EAA2C,EACzD,UACD;;;;;;;;;;;;;;;;;;;;;;;;AAyBH,SAAgB,SACd,MACA,SAAkC,EAAE,EACpC,UAA2B,EAAE,EACrB;CACR,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,QAAQ,QAAQ,CAAC;;;;;;;AAQ7D,SAAgB,YACd,KACA,SAAkC,EAAE,EACpC,UAA2B,EAAE,EAChB;CACb,IAAI,CAAC,UAAU,OAAO,KAAK,OAAO,CAAC,WAAW,GAAG,OAAO;CAExD,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,YAA0C;EAAE,QAAQ;EAAO,GAAK,QAAQ,MAAM,EAAE;EAAoC;CAI1H,MAAM,WAAW,UADA,KAAK,KAAK,KACQ,EAAE,IAAI;CAEzC,KAAK,MAAM,MAAM,UACf,KAAK,MAAM,QAAQ,YAAY;EAC7B,MAAM,QAAQ,GAAG,QAAQ;EACzB,IAAI,CAAC,OAAO;EAEZ,MAAM,UAAU,aAAa,OAAO,QAAQ,WAAW,OAAO;EAC9D,IAAI,YAAY,OACd,GAAG,QAAQ,QAAQ;;CAKzB,OAAO"}
|