@maizzle/framework 4.8.8 → 5.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/bin/maizzle +3 -1
  2. package/package.json +64 -55
  3. package/src/commands/build.js +244 -19
  4. package/src/commands/serve.js +2 -197
  5. package/src/generators/plaintext.js +192 -91
  6. package/src/generators/render.js +128 -0
  7. package/src/index.js +45 -13
  8. package/src/{generators/posthtml → posthtml}/defaultComponentsConfig.js +6 -4
  9. package/src/{generators/posthtml → posthtml}/defaultConfig.js +1 -1
  10. package/src/posthtml/index.js +74 -0
  11. package/src/posthtml/plugins/expandLinkTag.js +36 -0
  12. package/src/server/client.js +181 -0
  13. package/src/server/index.js +383 -0
  14. package/src/server/routes/hmr.js +24 -0
  15. package/src/server/routes/index.js +38 -0
  16. package/src/server/views/error.html +83 -0
  17. package/src/server/views/index.html +24 -0
  18. package/src/server/websockets.js +27 -0
  19. package/src/transformers/addAttributes.js +30 -0
  20. package/src/transformers/attributeToStyle.js +30 -36
  21. package/src/transformers/baseUrl.js +56 -27
  22. package/src/transformers/comb.js +51 -0
  23. package/src/transformers/core.js +20 -0
  24. package/src/transformers/filters/defaultFilters.js +90 -71
  25. package/src/transformers/filters/index.js +14 -78
  26. package/src/transformers/index.js +268 -63
  27. package/src/transformers/inline.js +240 -0
  28. package/src/transformers/markdown.js +13 -14
  29. package/src/transformers/minify.js +21 -16
  30. package/src/transformers/posthtmlMso.js +13 -8
  31. package/src/transformers/prettify.js +16 -15
  32. package/src/transformers/preventWidows.js +32 -28
  33. package/src/transformers/removeAttributes.js +19 -19
  34. package/src/transformers/replaceStrings.js +30 -9
  35. package/src/transformers/safeClassNames.js +24 -24
  36. package/src/transformers/shorthandCss.js +22 -0
  37. package/src/transformers/sixHex.js +17 -17
  38. package/src/transformers/urlParameters.js +18 -16
  39. package/src/transformers/useAttributeSizes.js +65 -0
  40. package/src/utils/getConfigByFilePath.js +124 -0
  41. package/src/utils/node.js +68 -0
  42. package/src/utils/string.js +117 -0
  43. package/types/build.d.ts +117 -57
  44. package/types/components.d.ts +130 -112
  45. package/types/config.d.ts +454 -242
  46. package/types/css/inline.d.ts +234 -0
  47. package/types/css/purge.d.ts +125 -0
  48. package/types/events.d.ts +5 -105
  49. package/types/index.d.ts +148 -116
  50. package/types/markdown.d.ts +20 -18
  51. package/types/minify.d.ts +122 -120
  52. package/types/plaintext.d.ts +46 -52
  53. package/types/posthtml.d.ts +103 -136
  54. package/types/render.d.ts +0 -117
  55. package/types/urlParameters.d.ts +21 -20
  56. package/types/widowWords.d.ts +9 -7
  57. package/src/functions/plaintext.js +0 -5
  58. package/src/functions/render.js +0 -5
  59. package/src/generators/config.js +0 -52
  60. package/src/generators/output/index.js +0 -4
  61. package/src/generators/output/to-disk.js +0 -254
  62. package/src/generators/output/to-string.js +0 -73
  63. package/src/generators/postcss.js +0 -23
  64. package/src/generators/posthtml/index.js +0 -75
  65. package/src/generators/tailwindcss.js +0 -157
  66. package/src/transformers/extraAttributes.js +0 -33
  67. package/src/transformers/inlineCss.js +0 -42
  68. package/src/transformers/removeInlineBackgroundColor.js +0 -57
  69. package/src/transformers/removeInlineSizes.js +0 -45
  70. package/src/transformers/removeInlinedSelectors.js +0 -100
  71. package/src/transformers/removeUnusedCss.js +0 -48
  72. package/src/transformers/shorthandInlineCSS.js +0 -26
  73. package/src/utils/helpers.js +0 -13
  74. package/types/baseUrl.d.ts +0 -79
  75. package/types/fetch.d.ts +0 -143
  76. package/types/inlineCss.d.ts +0 -207
  77. package/types/layouts.d.ts +0 -39
  78. package/types/removeUnusedCss.d.ts +0 -115
  79. package/types/tailwind.d.ts +0 -22
  80. package/types/templates.d.ts +0 -181
@@ -1,62 +1,56 @@
1
- import type {Opts as PlaintextOptions} from 'string-strip-html';
1
+ import type { Opts as PlaintextOptions } from 'string-strip-html';
2
2
 
3
3
  export default interface PlaintextConfig extends PlaintextOptions {
4
4
  /**
5
- Configure where plaintext files should be output.
6
-
7
- @example
8
- ```
9
- module.exports = {
10
- build: {
11
- plaintext: {
12
- destination: {
13
- path: 'dist/brand/plaintext',
14
- extension: 'rtxt'
15
- }
16
- }
17
- }
18
- }
19
- ```
20
- */
21
- destination?: {
5
+ * Configure where plaintext files should be output.
6
+ *
7
+ * @example
8
+ * ```
9
+ * export default {
10
+ * plaintext: {
11
+ * output: {
12
+ * path: 'dist/brand/plaintext',
13
+ * extension: 'rtxt'
14
+ * }
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ output?: {
22
20
  /**
23
- Directory where Maizzle should output compiled Plaintext files.
24
-
25
- @default 'build_{env}'
26
-
27
- @example
28
- ```
29
- module.exports = {
30
- build: {
31
- plaintext: {
32
- destination: {
33
- path: 'dist/brand/plaintext'
34
- }
35
- }
36
- }
37
- }
38
- ```
39
- */
21
+ * Directory where Maizzle should output compiled Plaintext files.
22
+ *
23
+ * @default 'build_{env}'
24
+ *
25
+ * @example
26
+ * ```
27
+ * export default {
28
+ * plaintext: {
29
+ * output: {
30
+ * path: 'dist/brand/plaintext'
31
+ * }
32
+ * }
33
+ * }
34
+ * ```
35
+ */
40
36
  path?: string;
41
37
 
42
38
  /**
43
- File extension to be used for compiled Plaintext files.
44
-
45
- @default 'txt'
46
-
47
- @example
48
- ```
49
- module.exports = {
50
- build: {
51
- plaintext: {
52
- destination: {
53
- extension: 'rtxt'
54
- }
55
- }
56
- }
57
- }
58
- ```
59
- */
39
+ * File extension to be used for compiled Plaintext files.
40
+ *
41
+ * @default 'txt'
42
+ *
43
+ * @example
44
+ * ```
45
+ * export default {
46
+ * plaintext: {
47
+ * output: {
48
+ * extension: 'rtxt'
49
+ * }
50
+ * }
51
+ * }
52
+ * ```
53
+ */
60
54
  extension: string;
61
55
  };
62
56
  }
@@ -1,128 +1,128 @@
1
- import type PostHTMLFetchConfig from './fetch';
1
+ import type { Directive } from 'posthtml-parser';
2
2
  import type ExpressionsConfig from './expressions';
3
3
 
4
4
  export interface PostHTMLOptions {
5
5
  /**
6
- Configure the PostHTML parser to process custom directives.
7
-
8
- @default []
9
- */
10
- directives?: any[];
6
+ * Configure the PostHTML parser to process custom directives.
7
+ *
8
+ * @default []
9
+ */
10
+ directives?: Directive[];
11
11
 
12
12
  /**
13
- Enable `xmlMode` if you're using Maizzle to output XML content, and not actual HTML.
14
-
15
- @default false
16
- */
13
+ * Enable `xmlMode` if you're using Maizzle to output XML content, and not actual HTML.
14
+ *
15
+ * @default false
16
+ */
17
17
  xmlMode?: boolean;
18
18
 
19
19
  /**
20
- Decode entities in the HTML.
21
-
22
- @default false
23
- */
20
+ * Decode entities in the HTML.
21
+ *
22
+ * @default false
23
+ */
24
24
  decodeEntities?: boolean;
25
25
 
26
26
  /**
27
- Output all tags in lowercase. Works only when `xmlMode` is disabled.
28
-
29
- @default false
30
- */
27
+ * Output all tags in lowercase. Works only when `xmlMode` is disabled.
28
+ *
29
+ * @default false
30
+ */
31
31
  lowerCaseTags?: boolean;
32
32
 
33
33
  /**
34
- Output all attribute names in lowercase.
35
-
36
- @default false
37
- */
34
+ * Output all attribute names in lowercase.
35
+ *
36
+ * @default false
37
+ */
38
38
  lowerCaseAttributeNames?: boolean;
39
39
 
40
40
  /**
41
- Recognize CDATA sections as text even if the `xmlMode` option is disabled.
42
-
43
- @default false
44
- */
41
+ * Recognize CDATA sections as text even if the `xmlMode` option is disabled.
42
+ *
43
+ * @default false
44
+ */
45
45
  recognizeCDATA?: boolean;
46
46
 
47
47
  /**
48
- Recognize self-closing tags.
49
- Disabling this will cause rendering to stop at the first self-closing custom (non-HTML) tag.
50
-
51
- @default true
52
- */
48
+ * Recognize self-closing tags.
49
+ * Disabling this will cause rendering to stop at the first self-closing custom (non-HTML) tag.
50
+ *
51
+ * @default true
52
+ */
53
53
  recognizeSelfClosing?: boolean;
54
54
 
55
55
  /**
56
- If enabled, AST nodes will have a location property containing the `start` and `end` line and column position of the node.
57
-
58
- @default false
59
- */
56
+ * If enabled, AST nodes will have a location property containing the `start` and `end` line and column position of the node.
57
+ *
58
+ * @default false
59
+ */
60
60
  sourceLocations?: boolean;
61
61
 
62
62
  /**
63
- Whether attributes with no values should render exactly as they were written, without `=""` appended.
64
-
65
- @default true
66
- */
63
+ * Whether attributes with no values should render exactly as they were written, without `=""` appended.
64
+ *
65
+ * @default true
66
+ */
67
67
  recognizeNoValueAttribute?: boolean;
68
68
 
69
69
  /**
70
- Tell PostHTML to treat custom tags as self-closing.
71
-
72
- @default []
73
- */
70
+ * Make PostHTML to treat custom tags as self-closing.
71
+ *
72
+ * @default []
73
+ */
74
74
  singleTags?: string[] | RegExp[];
75
75
 
76
76
  /**
77
- Define the closing format for single tags.
78
-
79
- @default 'default'
80
- */
77
+ * Define the closing format for single tags.
78
+ *
79
+ * @default 'default'
80
+ */
81
81
  closingSingleTag?: 'tag' | 'slash';
82
82
 
83
83
  /**
84
- Whether to quote all attribute values.
85
-
86
- @default true
87
- */
84
+ * Whether to quote all attribute values.
85
+ *
86
+ * @default true
87
+ */
88
88
  quoteAllAttributes?: boolean;
89
89
 
90
90
  /**
91
- Replaces quotes in attribute values with `&quote;`.
92
-
93
- @default true
94
- */
91
+ * Replaces quotes in attribute values with `&quote;`.
92
+ *
93
+ * @default true
94
+ */
95
95
  replaceQuote?: boolean;
96
96
 
97
97
  /**
98
- Specify the style of quote around the attribute values.
99
-
100
- @default 2
101
-
102
- @example
103
-
104
- `0` - Quote style is based on attribute values (an alternative for `replaceQuote` option)
105
-
106
- ```
107
- <img src="example.jpg" onload='testFunc("test")'>
108
- ```
109
-
110
- @example
111
-
112
- `1` - Attribute values are wrapped in single quotes
113
-
114
- ```
115
- <img src='example.jpg' onload='testFunc("test")'>
116
- ```
117
-
118
- @example
119
-
120
- `2` - Attribute values are wrapped in double quotes
121
-
122
- ```
123
- <img src="example.jpg" onload="testFunc("test")">
124
- ```
125
- */
98
+ * Specify the style of quote around the attribute values.
99
+ *
100
+ * @default 2
101
+ *
102
+ * @example
103
+ *
104
+ * `0` - Quote style is based on attribute values (an alternative for `replaceQuote` option)
105
+ *
106
+ * ```
107
+ * <img src="example.jpg" onload='testFunc("test")'>
108
+ * ```
109
+ *
110
+ * @example
111
+ *
112
+ * `1` - Attribute values are wrapped in single quotes
113
+ *
114
+ * ```
115
+ * <img src='example.jpg' onload='testFunc("test")'>
116
+ * ```
117
+ *
118
+ * @example
119
+ *
120
+ * `2` - Attribute values are wrapped in double quotes
121
+ *
122
+ * ```
123
+ * <img src="example.jpg" onload="testFunc("test")">
124
+ * ```
125
+ */
126
126
  quoteStyle?: 0 | 1 | 2;
127
127
  }
128
128
 
@@ -138,58 +138,25 @@ export default interface PostHTMLConfig {
138
138
  options?: PostHTMLOptions;
139
139
 
140
140
  /**
141
- Additional PostHTML plugins that you would like to use.
142
-
143
- These will run last, after components.
144
-
145
- @default []
146
-
147
- @example
148
- ```
149
- const spaceless = require('posthtml-spaceless')
150
- module.exports = {
151
- build: {
152
- posthtml: {
153
- plugins: [
154
- spaceless()
155
- ]
156
- }
157
- }
158
- }
159
- ```
160
- */
161
- plugins?: any[];
162
-
163
- /**
164
- Configure the `posthtml-mso` plugin.
165
- */
166
- outlook?: {
141
+ * PostHTML plugins to apply before or after Maizzle's own plugins.
142
+ *
143
+ * @example
144
+ * ```
145
+ * import spaceless from 'posthtml-spaceless'
146
+ * export default {
147
+ * posthtml: {
148
+ * plugins: [
149
+ * spaceless()
150
+ * ]
151
+ * }
152
+ * }
153
+ * ```
154
+ */
155
+ plugins?: {
156
+ before: Array<() => void>;
167
157
  /**
168
- The tag name to use for Outlook conditional comments.
169
-
170
- @default 'outlook'
171
-
172
- @example
173
- ```
174
- module.exports = {
175
- build: {
176
- posthtml: {
177
- outlook: {
178
- tag: 'mso'
179
- }
180
- }
181
- }
182
- }
183
- // You now write <mso>...</mso> instead of <outlook>...</outlook>
184
- ```
185
- */
186
- tag?: string;
187
- };
188
-
189
- /**
190
- Configure the `<fetch>` tag behavior.
191
-
192
- @default {}
193
- */
194
- fetch?: PostHTMLFetchConfig;
158
+ * Plugins to apply after Maizzle's own plugins.
159
+ */
160
+ after: Array<() => void>;
161
+ } | (() => void)[];
195
162
  }
package/types/render.d.ts CHANGED
@@ -1,10 +1,4 @@
1
- import {
2
- beforeRenderType,
3
- afterRenderType,
4
- afterTransformersType
5
- } from './events';
6
1
  import type Config from './config';
7
- import type TailwindConfig from './tailwind';
8
2
 
9
3
  export type RenderOutput = {
10
4
  /**
@@ -17,114 +11,3 @@ export type RenderOutput = {
17
11
  */
18
12
  config: Config;
19
13
  };
20
-
21
- export default interface RenderOptions {
22
- /**
23
- A Maizzle configuration object.
24
-
25
- @default {}
26
-
27
- @example
28
- ```
29
- const Maizzle = require('@maizzle/framework');
30
-
31
- Maizzle
32
- .render(`html string`, {
33
- maizzle: {
34
- inlineCSS: true,
35
- }
36
- })
37
- .then(({html, config}) => console.log(html, config))
38
- ```
39
- */
40
- maizzle: Config;
41
-
42
- /**
43
- Tailwind CSS configuration object.
44
-
45
- @default {}
46
-
47
- @example
48
- ```
49
- const Maizzle = require('@maizzle/framework');
50
-
51
- Maizzle
52
- .render(`html string`, {
53
- tailwind: {
54
- config: './tailwind-custom.config.js',
55
- },
56
- })
57
- .then(({html, config}) => console.log(html, config))
58
- ```
59
- */
60
- tailwind?: TailwindConfig;
61
-
62
- /**
63
- A function that runs after the Template's config has been computed, but just before it is compiled.
64
-
65
- It exposes the Template's config, as well as the HTML.
66
-
67
- @default undefined
68
-
69
- @example
70
- ```
71
- const Maizzle = require('@maizzle/framework');
72
-
73
- Maizzle
74
- .render(`html string`, {
75
- beforeRender: (html, config) => {
76
- // do something with html and config
77
- return html;
78
- },
79
- })
80
- .then(({html, config}) => console.log(html, config))
81
- ```
82
- */
83
- beforeRender?: beforeRenderType;
84
-
85
- /**
86
- A function that runs after the Template has been compiled, but before any Transformers have been applied.
87
-
88
- Exposes the rendered html string and the Templates' config.
89
-
90
- @default undefined
91
-
92
- @example
93
- ```
94
- const Maizzle = require('@maizzle/framework');
95
-
96
- Maizzle
97
- .render(`html string`, {
98
- afterRender: (html, config) => {
99
- // do something with html and config
100
- return html;
101
- },
102
- })
103
- .then(({html, config}) => console.log(html, config))
104
- ```
105
- */
106
- afterRender?: afterRenderType;
107
-
108
- /**
109
- A function that runs after all Transformers have been applied, just before the final HTML is returned.
110
-
111
- It exposes the Template's config, as well as the HTML.
112
-
113
- @default undefined
114
-
115
- @example
116
- ```
117
- const Maizzle = require('@maizzle/framework');
118
-
119
- Maizzle
120
- .render(`html string`, {
121
- afterTransformers: (html, config) => {
122
- // do something with html and config
123
- return html;
124
- },
125
- })
126
- .then(({html, config}) => console.log(html, config))
127
- ```
128
- */
129
- afterTransformers?: afterTransformersType;
130
- }
@@ -1,27 +1,28 @@
1
- import type {StringifyOptions} from 'query-string';
1
+ import type { URLParametersConfig as URLParamsConfig } from 'posthtml-url-parameters';
2
2
 
3
3
  export default interface URLParametersConfig {
4
- [key: string]: any;
4
+ [key: string]: any; // eslint-disable-line
5
5
 
6
6
  _options?: {
7
7
  /**
8
- Array of tag names to process. Only URLs inside `href` attributes of tags in this array will be processed.
9
-
10
- @default ['a']
11
-
12
- @example
13
- ```
14
- module.exports = {
15
- urlParameters: {
16
- _options: {
17
- tags: ['a[href*="example.com"]'],
18
- },
19
- utm_source: 'maizzle',
20
- }
21
- }
22
- ```
23
- */
24
- tags?: string[];
8
+ * Array of tag names to process. Only URLs inside `href` attributes
9
+ * of tags in this array will be processed.
10
+ *
11
+ * @default ['a']
12
+ *
13
+ * @example
14
+ * ```
15
+ * export default {
16
+ * urlParameters: {
17
+ * _options: {
18
+ * tags: ['a[href*="example.com"]'],
19
+ * },
20
+ * utm_source: 'maizzle',
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ tags?: URLParamsConfig['tags'];
25
26
 
26
27
  /**
27
28
  By default, query parameters are appended only to valid URLs.
@@ -34,6 +35,6 @@ export default interface URLParametersConfig {
34
35
  /**
35
36
  Options to pass to the `query-string` library.
36
37
  */
37
- qs?: StringifyOptions;
38
+ qs?: URLParamsConfig['qs'];
38
39
  };
39
40
  }
@@ -1,3 +1,5 @@
1
+ import type { Opts } from 'string-remove-widows';
2
+
1
3
  export default interface WidowWordsConfig {
2
4
  /**
3
5
  The attribute name to use.
@@ -12,45 +14,45 @@ export default interface WidowWordsConfig {
12
14
 
13
15
  @default false
14
16
  */
15
- removeWindowPreventionMeasures?: boolean;
17
+ removeWidowPreventionMeasures?: Opts['removeWidowPreventionMeasures'];
16
18
 
17
19
  /**
18
20
  Convert the space entity to the `targetLanguage`.
19
21
 
20
22
  @default true
21
23
  */
22
- convertEntities?: boolean;
24
+ convertEntities?: Opts['convertEntities'];
23
25
 
24
26
  /**
25
27
  Language to encode non-breaking spaces in.
26
28
 
27
29
  @default 'html'
28
30
  */
29
- targetLanguage?: 'html' | 'css' | 'js';
31
+ targetLanguage?: Opts['targetLanguage'];
30
32
 
31
33
  /**
32
34
  Should whitespace in front of dashes (-), n-dashes (–) or m-dashes (—) be replaced with a `&nbsp;`.
33
35
 
34
36
  @default true
35
37
  */
36
- hyphens?: boolean;
38
+ hyphens?: Opts['hyphens'];
37
39
 
38
40
  /**
39
41
  The minimum amount of words in a target string, in order to trigger the transformer.
40
42
 
41
43
  @default 3
42
44
  */
43
- minWordCount?: number;
45
+ minWordCount?: Opts['minWordCount'];
44
46
 
45
47
  /**
46
48
  The minimum amount non-whitespace characters in a target string, in order to trigger the transformer.
47
49
 
48
50
  @default 20
49
51
  */
50
- minCharCount?: number;
52
+ minCharCount?: Opts['minCharCount'];
51
53
 
52
54
  /**
53
55
  Start/end pairs of strings that will prevent the transformer from removing widow words inside them.
54
56
  */
55
- ignore?: string | string[];
57
+ ignore?: Opts['ignore'];
56
58
  }
@@ -1,5 +0,0 @@
1
- const Plaintext = require('../generators/plaintext')
2
-
3
- const toPlaintext = async (html, config = {}) => Plaintext.generate(html, false, config)
4
-
5
- module.exports = toPlaintext
@@ -1,5 +0,0 @@
1
- const Output = require('../generators/output')
2
-
3
- const render = async (html, options) => Output.toString(html, options)
4
-
5
- module.exports = render