@maizzle/framework 4.7.5 → 4.7.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.
@@ -0,0 +1,105 @@
1
+ export type beforeCreateType = (config: any) => Promise<void>;
2
+ export type beforeRenderType = (html: string, config: any) => Promise<string>;
3
+ export type afterRenderType = (html: string, config: any) => Promise<string>;
4
+ export type afterTransformersType = (html: string, config: any) => Promise<string>;
5
+ export type afterBuildType = (files: any[], config: any) => Promise<void>;
6
+
7
+ export default interface EventsConfig {
8
+ /**
9
+ Runs after the Environment config has been computed, but before Templates are processed.
10
+ Exposes the `config` object so you can further customize it.
11
+
12
+ @default undefined
13
+
14
+ @example
15
+ ```
16
+ module.exports = {
17
+ events: {
18
+ beforeCreate: async (config) => {
19
+ // do something with `config`
20
+ }
21
+ }
22
+ }
23
+ ```
24
+ */
25
+ beforeCreate: beforeCreateType;
26
+
27
+ /**
28
+ Runs after the Template's config has been computed, but just before it is compiled.
29
+ It exposes the Template's config, as well as the HTML. Must return the `html` string.
30
+
31
+ @default undefined
32
+
33
+ @example
34
+ ```
35
+ module.exports = {
36
+ events: {
37
+ beforeRender: async (html, config) => {
38
+ // do something with html and config
39
+ return html;
40
+ }
41
+ }
42
+ }
43
+ ```
44
+ */
45
+ beforeRender: beforeRenderType;
46
+
47
+ /**
48
+ Runs after the Template has been compiled, but before any Transformers have been applied.
49
+ Exposes the rendered `html` string and the `config`. Must return the `html` string.
50
+
51
+ @default undefined
52
+
53
+ @example
54
+ ```
55
+ module.exports = {
56
+ events: {
57
+ afterRender: async (html, config) => {
58
+ // do something with html and config
59
+ return html;
60
+ }
61
+ }
62
+ }
63
+ ```
64
+ */
65
+ afterRender: afterRenderType;
66
+
67
+ /**
68
+ Runs after all Transformers have been applied, just before the final HTML is returned.
69
+ Exposes the rendered `html` string and the `config`. Must return the `html` string.
70
+
71
+ @default undefined
72
+
73
+ @example
74
+ ```
75
+ module.exports = {
76
+ events: {
77
+ afterTransformers: async (html, config) => {
78
+ // do something with html and config
79
+ return html;
80
+ }
81
+ }
82
+ }
83
+ ```
84
+ */
85
+ afterTransformers: afterTransformersType;
86
+
87
+ /**
88
+ Runs after all Templates have been compiled and output to disk.
89
+ The files parameter will contain the paths to all the files inside the `build.templates.destination.path` directory.
90
+
91
+ @default undefined
92
+
93
+ @example
94
+ ```
95
+ module.exports = {
96
+ events: {
97
+ afterBuild: async (files, config) => {
98
+ // do something with files or config
99
+ }
100
+ }
101
+ }
102
+ ```
103
+ */
104
+ afterBuild: afterBuildType;
105
+ }
@@ -0,0 +1,78 @@
1
+ export default interface ExpressionsConfig {
2
+ /**
3
+ Define the starting and ending delimiters used for expressions.
4
+
5
+ @default ['{{', '}}']
6
+ */
7
+ delimiters?: string[];
8
+
9
+ /**
10
+ Define the starting and ending delimiters used for unescaped expressions.
11
+
12
+ @default ['{{{', '}}}']
13
+ */
14
+ unescapeDelimiters?: string[];
15
+
16
+ /**
17
+ Object containing data that will be available under the `page` object.
18
+
19
+ @default {}
20
+ */
21
+ locals?: Record<string, unknown>;
22
+
23
+ /**
24
+ Attribute name for `<script>` tags that contain locals.
25
+
26
+ @default 'locals'
27
+ */
28
+ localsAttr?: string;
29
+
30
+ /**
31
+ Whether to remove `<script>` tags that contain locals.
32
+
33
+ @default false
34
+ */
35
+ removeScriptLocals?: boolean;
36
+
37
+ /**
38
+ Tag names to be used for if/else statements.
39
+
40
+ @default ['if', 'elseif', 'else']
41
+ */
42
+ conditionalTags?: string[];
43
+
44
+ /**
45
+ Tag names to be used for switch statements.
46
+
47
+ @default ['switch', 'case', 'default']
48
+ */
49
+ switchTags?: string[];
50
+
51
+ /**
52
+ Tag names to be used for loops.
53
+
54
+ @default ['each', 'for']
55
+ */
56
+ loopTags?: string[];
57
+
58
+ /**
59
+ Tag names to be used for scopes.
60
+
61
+ @default ['scope']
62
+ */
63
+ scopeTags?: string[];
64
+
65
+ /**
66
+ Name of tag inside of which expression parsing is disabled.
67
+
68
+ @default 'raw'
69
+ */
70
+ ignoredTag?: string;
71
+
72
+ /**
73
+ Enabling strict mode will throw an error if an expression cannot be evaluated.
74
+
75
+ @default false
76
+ */
77
+ strictMode?: boolean;
78
+ }
@@ -0,0 +1,143 @@
1
+ import type {Options as GotOptions} from 'got';
2
+ import type ExpressionsConfig from './expressions';
3
+
4
+ export default interface PostHTMLFetchConfig {
5
+ /**
6
+ Supported tag names.
7
+ Only tags from this array will be processed by the plugin.
8
+
9
+ @default ['fetch', 'remote']
10
+
11
+ @example
12
+ ```
13
+ module.exports = {
14
+ build: {
15
+ posthtml: {
16
+ fetch: {
17
+ tags: ['get']
18
+ }
19
+ }
20
+ }
21
+ }
22
+ ```
23
+ */
24
+ tags?: string[];
25
+
26
+ /**
27
+ String representing the attribute name containing the URL to fetch.
28
+
29
+ @default 'url'
30
+
31
+ @example
32
+ ```
33
+ module.exports = {
34
+ build: {
35
+ posthtml: {
36
+ fetch: {
37
+ attribute: 'from'
38
+ }
39
+ }
40
+ }
41
+ }
42
+ ```
43
+ */
44
+ attribute?: string;
45
+
46
+ /**
47
+ `posthtml-fetch` uses `got` to fetch data.
48
+ You can pass options directly to it, inside the `got` object.
49
+
50
+ @default {}
51
+
52
+ @example
53
+ ```
54
+ module.exports = {
55
+ build: {
56
+ posthtml: {
57
+ got: {
58
+ prefixUrl: '...'
59
+ }
60
+ }
61
+ }
62
+ }
63
+ ```
64
+ */
65
+ got?: GotOptions;
66
+
67
+ /**
68
+ When set to `true`, this option will preserve the `tag`, i.e. `<fetch>` around the response body.
69
+
70
+ @default false
71
+
72
+ @example
73
+ ```
74
+ module.exports = {
75
+ build: {
76
+ posthtml: {
77
+ fetch: {
78
+ preserveTag: true
79
+ }
80
+ }
81
+ }
82
+ }
83
+ ```
84
+ */
85
+ preserveTag?: boolean;
86
+
87
+ /**
88
+ Pass options to `posthtml-expressions`.
89
+
90
+ @default {}
91
+
92
+ @example
93
+ ```
94
+ module.exports = {
95
+ build: {
96
+ posthtml: {
97
+ fetch: {
98
+ expressions: {
99
+ delimiters: ['[[', ']]']
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ ```
106
+ */
107
+ expressions?: ExpressionsConfig;
108
+
109
+ /**
110
+ List of plugins that will be called after/before receiving and processing `locals`.
111
+
112
+ @default {}
113
+
114
+ @example
115
+ ```
116
+ module.exports = {
117
+ build: {
118
+ posthtml: {
119
+ fetch: {
120
+ plugins: {
121
+ after(tree) {
122
+ // Your plugin implementation
123
+ },
124
+ before: [
125
+ tree => {
126
+ // Your plugin implementation
127
+ },
128
+ tree => {
129
+ // ..
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ ```
138
+ */
139
+ plugins?: {
140
+ after?: (tree: any) => void;
141
+ before?: Array<(tree: any) => void>;
142
+ };
143
+ }
@@ -0,0 +1,187 @@
1
+ import type {AttributeToStyleSupportedAttributes} from './inlineCss';
2
+ import type BaseURLConfig from './baseURL';
3
+ import type Config from './config';
4
+ import type {CoreBeautifyOptions} from 'js-beautify';
5
+ import type InlineCSSConfig from './inlineCss';
6
+ import type {Options as MarkdownItOptions} from 'markdown-it';
7
+ import type MinifyConfig from './minify';
8
+ import type PlaintextConfig from './plaintext';
9
+ import type RenderOptions from './render';
10
+ import type {RenderOutput} from './render';
11
+ import type RemoveUnusedCSSConfig from './removeUnusedCss';
12
+ import type URLParametersConfig from './urlParameters';
13
+ import type WidowWordsConfig from './widowWords';
14
+
15
+ declare namespace MaizzleFramework {
16
+ /**
17
+ Compile an HTML string with Maizzle.
18
+
19
+ @param {string} html The HTML string to render.
20
+ @param {RenderOptions} [options] Options to pass to the renderer.
21
+ */
22
+ function render(html: string, options?: RenderOptions): Promise<RenderOutput>;
23
+
24
+ /**
25
+ Normalize escaped character class names like `\:` or `\/` by replacing them with email-safe alternatives.
26
+
27
+ @param {string} html The HTML string to render.
28
+ @param {object} replacements Customize replacements strategy.
29
+ */
30
+ function safeClassNames(html: string, replacements: Record<string, string>): string;
31
+
32
+ /**
33
+ Compile Markdown to HTML.
34
+
35
+ @param {string} input String to compile with Markdown.
36
+ @param {Options} [options] markdown-it options.
37
+ */
38
+ function markdown(input: string, options?: MarkdownItOptions): string;
39
+
40
+ /**
41
+ Prevent widow words inside a tag by adding a `&nbsp;` between its last two words.
42
+
43
+ @param {string} html The HTML string to render.
44
+ @param {WidowWordsConfig} [options] Options to pass to the transformer.
45
+ */
46
+ function preventWidows(html: string, options?: WidowWordsConfig): string;
47
+
48
+ /**
49
+ Duplicate HTML attributes to inline CSS.
50
+
51
+ @param {string} html The HTML string to render.
52
+ @param {AttributeToStyleSupportedAttributes} [options] Options to pass to the transformer.
53
+ */
54
+ function attributeToStyle(
55
+ html: string,
56
+ options?: AttributeToStyleSupportedAttributes[]
57
+ ): string;
58
+
59
+ /**
60
+ Inline CSS styles from `<style>` tags found in `<head>`.
61
+
62
+ @param {string} html The HTML string to render.
63
+ @param {InlineCSSConfig} [options] Options to pass to the transformer.
64
+ */
65
+ function inlineCSS(html: string, options?: InlineCSSConfig): string;
66
+
67
+ /**
68
+ Rewrite longhand CSS inside style attributes with shorthand syntax.
69
+ Only works with margin, padding and border, and only when all sides are specified.
70
+
71
+ @param {string} html The HTML string to render.
72
+ */
73
+ function shorthandCSS(html: string): string;
74
+
75
+ /**
76
+ Remove unused CSS from `<style>` tags and HTML elements.
77
+
78
+ @param {string} html The HTML string to use.
79
+ @param {RemoveUnusedCSSConfig} [options] Options to pass to the transformer.
80
+ */
81
+ function removeUnusedCSS(html: string, options?: RemoveUnusedCSSConfig): string;
82
+
83
+ /**
84
+ Automatically remove HTML attributes.
85
+ @param {string} html The HTML string to use.
86
+ @param options Either an array of attribute names, or an array of objects with `name` and `value` properties.
87
+ */
88
+ function removeAttributes(
89
+ html: string,
90
+ options?:
91
+ | string[]
92
+ | Array<{
93
+ name: string;
94
+ value: string | RegExp;
95
+ }>
96
+ ): string;
97
+
98
+ /**
99
+ Add attributes to elements in your HTML.
100
+
101
+ @param {string} html The HTML string to use.
102
+ @param {object} options Attributes to add.
103
+ */
104
+ function addAttributes(html: string, options?: Record<string, unknown>): string;
105
+
106
+ /**
107
+ Pretty print HTML code so that it's nicely indented and more human-readable.
108
+ @param {string} html The HTML string to prettify.
109
+ @param {CoreBeautifyOptions} [options] Options to pass to the prettifier.
110
+ */
111
+ function prettify(html: string, options?: CoreBeautifyOptions): string;
112
+
113
+ /**
114
+ Prepend a string to sources and hrefs in an HTML string.
115
+
116
+ @param {string} html The HTML string to use.
117
+ @param {BaseURLConfig} [options] Options to pass to the transformer.
118
+ */
119
+ function applyBaseURL(html: string, options?: string | BaseURLConfig): string;
120
+
121
+ /**
122
+ Append parameters to URLs in an HTML string.
123
+ @param {string} html The HTML string to use.
124
+ @param {URLParametersConfig} [options] Options to pass to the transformer.
125
+ */
126
+ function addURLParameters(html: string, options?: URLParametersConfig): string;
127
+
128
+ /**
129
+ Ensure that all your HEX colors inside `bgcolor` and `color` attributes are defined with six digits.
130
+
131
+ @param {string} html The HTML string to use.
132
+ */
133
+ function ensureSixHex(html: string): string;
134
+
135
+ /**
136
+ Minify a string of HTML code.
137
+
138
+ @param {string} html The HTML string to minify.
139
+ @param {MinifyConfig} [options] Options to pass to the minifier.
140
+ */
141
+ function minify(html: string, options?: MinifyConfig): string;
142
+
143
+ /**
144
+ Batch-replace strings in an HTML string.
145
+
146
+ @param {string} html The HTML string to use.
147
+ @param {object} replacements Strings to find and replace.
148
+ */
149
+ function replaceStrings(html: string, replacements?: Record<string, string>): string;
150
+
151
+ /**
152
+ Generate a plaintext version of an HTML string.
153
+
154
+ @param {string} html The HTML string to use.
155
+ @param {PlaintextConfig} [options] Options to pass to the plaintext generator.
156
+ */
157
+ function plaintext(html: string, options?: PlaintextConfig): Promise<{
158
+ html: string;
159
+ plaintext: string;
160
+ destination: string;
161
+ }>;
162
+
163
+ export {
164
+ Config,
165
+ RenderOptions,
166
+ // Functions
167
+ addAttributes,
168
+ addURLParameters,
169
+ applyBaseURL,
170
+ attributeToStyle,
171
+ ensureSixHex,
172
+ inlineCSS,
173
+ markdown,
174
+ minify,
175
+ plaintext,
176
+ preventWidows,
177
+ prettify,
178
+ removeAttributes,
179
+ removeUnusedCSS,
180
+ render,
181
+ replaceStrings,
182
+ safeClassNames,
183
+ shorthandCSS
184
+ };
185
+ }
186
+
187
+ export = MaizzleFramework;
@@ -0,0 +1,207 @@
1
+ export type AttributeToStyleSupportedAttributes =
2
+ | 'width'
3
+ | 'height'
4
+ | 'bgcolor'
5
+ | 'background'
6
+ | 'align'
7
+ | 'valign';
8
+
9
+ export default interface InlineCSSConfig {
10
+ /**
11
+ Which CSS properties should be duplicated as what HTML attributes.
12
+
13
+ @default {}
14
+
15
+ @example
16
+ ```
17
+ module.exports = {
18
+ build: {
19
+ inlineCSS: {
20
+ styleToAttribute: {
21
+ 'background-color': 'bgcolor',
22
+ }
23
+ }
24
+ }
25
+ }
26
+ ```
27
+ */
28
+ styleToAttribute?: Record<string, string>;
29
+
30
+ /**
31
+ Duplicate HTML attributes to inline CSS.
32
+
33
+ @default false
34
+
35
+ @example
36
+ ```
37
+ module.exports = {
38
+ build: {
39
+ inlineCSS: {
40
+ attributeToStyle: ['width', 'bgcolor', 'background']
41
+ }
42
+ }
43
+ }
44
+ ```
45
+ */
46
+ attributeToStyle?: boolean | AttributeToStyleSupportedAttributes[];
47
+
48
+ /**
49
+ HTML elements that will receive `width` attributes based on inline CSS width.
50
+
51
+ @default []
52
+
53
+ @example
54
+ ```
55
+ module.exports = {
56
+ build: {
57
+ inlineCSS: {
58
+ applyWidthAttributes: ['td', 'th']
59
+ }
60
+ }
61
+ }
62
+ ```
63
+ */
64
+ applyWidthAttributes?: string[];
65
+
66
+ /**
67
+ HTML elements that will receive `height` attributes based on inline CSS height.
68
+
69
+ @default []
70
+
71
+ @example
72
+ ```
73
+ module.exports = {
74
+ build: {
75
+ inlineCSS: {
76
+ applyHeightAttributes: ['td', 'th']
77
+ }
78
+ }
79
+ }
80
+ ```
81
+ */
82
+ applyHeightAttributes?: string[];
83
+
84
+ /**
85
+ List of elements that should only use `width` and `height`. Their inline CSS `width` and `height` will be removed.
86
+
87
+ @example
88
+ ```
89
+ module.exports = {
90
+ inlineCSS: {
91
+ keepOnlyAttributeSizes: {
92
+ width: ['img', 'video'],
93
+ height: ['img', 'video']
94
+ }
95
+ }
96
+ }
97
+ ```
98
+ */
99
+ keepOnlyAttributeSizes?: {
100
+ /**
101
+ List of elements that should only use the `width` HTML attribute (inline CSS width will be removed).
102
+
103
+ @default []
104
+
105
+ @example
106
+ ```
107
+ module.exports = {
108
+ inlineCSS: {
109
+ keepOnlyAttributeSizes: {
110
+ width: ['img', 'video'],
111
+ }
112
+ }
113
+ }
114
+ ```
115
+ */
116
+ width?: string[];
117
+ /**
118
+ List of elements that should only use the `height` HTML attribute (inline CSS height will be removed).
119
+
120
+ @default []
121
+
122
+ @example
123
+ ```
124
+ module.exports = {
125
+ inlineCSS: {
126
+ keepOnlyAttributeSizes: {
127
+ height: ['img', 'video']
128
+ }
129
+ }
130
+ }
131
+ ```
132
+ */
133
+ height?: string[];
134
+ };
135
+
136
+ /**
137
+ Remove inlined `background-color` CSS on elements containing a `bgcolor` HTML attribute.
138
+
139
+ @default false
140
+
141
+ @example
142
+ ```
143
+ module.exports = {
144
+ inlineCSS: {
145
+ preferBgColorAttribute: ['td'] // default: ['body', 'marquee', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr']
146
+ }
147
+ }
148
+ ```
149
+ */
150
+ preferBgColorAttribute?: boolean | string[];
151
+
152
+ /**
153
+ Array of CSS property names that should be excluded from the CSS inlining process. `--tw-shadow` is excluded by default.
154
+
155
+ @default []
156
+
157
+ @example
158
+ ```
159
+ module.exports = {
160
+ inlineCSS: {
161
+ excludedProperties: ['padding', 'padding-left']
162
+ }
163
+ }
164
+ ```
165
+ */
166
+ excludedProperties?: string[];
167
+
168
+ /**
169
+ An object where each value has a `start` and `end` to specify fenced code blocks that should be ignored during CSS inlining.
170
+
171
+ @default {EJS: {}, HBS: {}}
172
+
173
+ @example
174
+ ```
175
+ module.exports = {
176
+ EJS: { start: '<%', end: '%>' },
177
+ HBS: { start: '{{', end: '}}' },
178
+ }
179
+ ```
180
+ */
181
+ codeBlocks?: {
182
+ EJS?: Record<string, string>;
183
+ HBS?: Record<string, string>;
184
+ };
185
+
186
+ /**
187
+ Provide your own CSS to be inlined. Must be vanilla or pre-compiled CSS.
188
+
189
+ Existing `<style>` in your HTML tags will be ignored and their contents won't be inlined.
190
+
191
+ @default undefined
192
+
193
+ @example
194
+ ```
195
+ module.exports = {
196
+ inlineCSS: {
197
+ customCSS: `
198
+ .custom-class {
199
+ color: red;
200
+ }
201
+ `
202
+ }
203
+ }
204
+ ```
205
+ */
206
+ customCSS?: string;
207
+ }