@muonic/muon 0.0.2-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 (124) hide show
  1. package/.nycrc +17 -0
  2. package/.versionrc +3 -0
  3. package/CHANGELOG.md +389 -0
  4. package/components/card/index.js +1 -0
  5. package/components/card/src/card-component.js +43 -0
  6. package/components/card/src/card-styles.css +25 -0
  7. package/components/card/src/config-tokens.json +11 -0
  8. package/components/card/src/design-tokens.json +34 -0
  9. package/components/card/story.js +52 -0
  10. package/components/cta/index.js +1 -0
  11. package/components/cta/src/config-tokens.json +11 -0
  12. package/components/cta/src/cta-component.js +174 -0
  13. package/components/cta/src/cta-styles.css +105 -0
  14. package/components/cta/src/design-tokens.json +132 -0
  15. package/components/cta/story.js +99 -0
  16. package/components/detail/index.js +1 -0
  17. package/components/detail/src/config-tokens.json +11 -0
  18. package/components/detail/src/design-tokens.json +102 -0
  19. package/components/detail/src/detail-component.js +27 -0
  20. package/components/detail/src/detail-styles.css +83 -0
  21. package/components/detail/story.js +33 -0
  22. package/components/form/index.js +1 -0
  23. package/components/form/src/config-tokens.json +11 -0
  24. package/components/form/src/design-tokens.json +9 -0
  25. package/components/form/src/form-component.js +197 -0
  26. package/components/form/src/form-styles.css +10 -0
  27. package/components/form/story.js +71 -0
  28. package/components/icon/index.js +1 -0
  29. package/components/icon/src/config-tokens.json +31 -0
  30. package/components/icon/src/design-tokens.json +8 -0
  31. package/components/icon/src/icon-component.js +91 -0
  32. package/components/icon/src/icon-styles.css +26 -0
  33. package/components/icon/story.js +26 -0
  34. package/components/image/index.js +1 -0
  35. package/components/image/src/config-tokens.json +26 -0
  36. package/components/image/src/image-component.js +96 -0
  37. package/components/image/src/image-styles.css +71 -0
  38. package/components/image/story.js +31 -0
  39. package/components/inputter/index.js +1 -0
  40. package/components/inputter/src/config-tokens.json +14 -0
  41. package/components/inputter/src/design-tokens.json +308 -0
  42. package/components/inputter/src/inputter-component.js +227 -0
  43. package/components/inputter/src/inputter-styles-detail.css +59 -0
  44. package/components/inputter/src/inputter-styles.css +305 -0
  45. package/components/inputter/src/inputter-styles.slotted.css +64 -0
  46. package/components/inputter/story.js +243 -0
  47. package/css/accessibility.css +3 -0
  48. package/css/default.css +9 -0
  49. package/css/global.css +8 -0
  50. package/directives/image-loader-directive.js +116 -0
  51. package/directives/svg-loader-directive.js +94 -0
  52. package/index.js +52 -0
  53. package/mixins/card-mixin.js +27 -0
  54. package/mixins/detail-mixin.js +128 -0
  55. package/mixins/form-associate-mixin.js +36 -0
  56. package/mixins/form-element-mixin.js +378 -0
  57. package/mixins/image-holder-mixin.js +20 -0
  58. package/mixins/mask-mixin.js +159 -0
  59. package/mixins/validation-mixin.js +272 -0
  60. package/muon-element/index.js +97 -0
  61. package/package.json +72 -0
  62. package/rollup.config.mjs +30 -0
  63. package/scripts/build/storybook/index.mjs +11 -0
  64. package/scripts/build/storybook/run.mjs +47 -0
  65. package/scripts/rollup-plugins.mjs +116 -0
  66. package/scripts/serve/index.mjs +11 -0
  67. package/scripts/serve/run.mjs +27 -0
  68. package/scripts/style-dictionary.mjs +64 -0
  69. package/scripts/utils/config.mjs +30 -0
  70. package/scripts/utils/index.mjs +283 -0
  71. package/storybook/find-stories.js +36 -0
  72. package/storybook/server.config.mjs +19 -0
  73. package/storybook/stories.js +86 -0
  74. package/storybook/tokens/color.js +87 -0
  75. package/storybook/tokens/font.js +52 -0
  76. package/storybook/tokens/spacer.js +48 -0
  77. package/tests/README.md +3 -0
  78. package/tests/components/card/__snapshots__/card.test.snap.js +70 -0
  79. package/tests/components/card/card.test.js +81 -0
  80. package/tests/components/cta/__snapshots__/cta.test.snap.js +246 -0
  81. package/tests/components/cta/cta.test.js +212 -0
  82. package/tests/components/form/__snapshots__/form.test.snap.js +115 -0
  83. package/tests/components/form/form.test.js +336 -0
  84. package/tests/components/icon/__snapshots__/icon.test.snap.js +95 -0
  85. package/tests/components/icon/icon.test.js +197 -0
  86. package/tests/components/image/__snapshots__/image.test.snap.js +205 -0
  87. package/tests/components/image/image.test.js +314 -0
  88. package/tests/components/image/images/15.png +0 -0
  89. package/tests/components/image/images/150.png +0 -0
  90. package/tests/components/inputter/__snapshots__/inputter.test.snap.js +357 -0
  91. package/tests/components/inputter/inputter.test.js +427 -0
  92. package/tests/helpers/index.js +30 -0
  93. package/tests/mixins/__snapshots__/card.test.snap.js +35 -0
  94. package/tests/mixins/__snapshots__/detail.test.snap.js +237 -0
  95. package/tests/mixins/__snapshots__/form-element.test.snap.js +137 -0
  96. package/tests/mixins/__snapshots__/mask.test.snap.js +53 -0
  97. package/tests/mixins/__snapshots__/validation.test.snap.js +297 -0
  98. package/tests/mixins/card.test.js +63 -0
  99. package/tests/mixins/detail.test.js +223 -0
  100. package/tests/mixins/form-element.test.js +473 -0
  101. package/tests/mixins/mask.test.js +261 -0
  102. package/tests/mixins/muon-element.test.js +52 -0
  103. package/tests/mixins/validation.test.js +423 -0
  104. package/tests/runner/commands.mjs +19 -0
  105. package/tests/scripts/utils/card-component.js +26 -0
  106. package/tests/scripts/utils/muon.config.test.json +13 -0
  107. package/tests/scripts/utils/single.component.config.json +5 -0
  108. package/tests/scripts/utils/test-runner.mjs +1 -0
  109. package/tests/scripts/utils/utils-test.mjs +284 -0
  110. package/tests/utils/validation.functions.test.js +199 -0
  111. package/tokens/theme/color.json +482 -0
  112. package/tokens/theme/font.json +61 -0
  113. package/tokens/theme/size.json +27 -0
  114. package/tokens/theme/spacer.json +73 -0
  115. package/tokens/utils/formats/reference.js +17 -0
  116. package/tokens/utils/modular-scale.js +33 -0
  117. package/tokens/utils/templates/font-face.css.template +30 -0
  118. package/tokens/utils/transforms/color.js +27 -0
  119. package/tokens/utils/transforms/string.js +6 -0
  120. package/tokens/utils/validation.json +76 -0
  121. package/utils/scroll/index.js +31 -0
  122. package/utils/validation/index.js +205 -0
  123. package/web-test-runner.browserstack.config.mjs +123 -0
  124. package/web-test-runner.config.mjs +44 -0
@@ -0,0 +1,272 @@
1
+ import { html, repeat, dedupeMixin } from '@muonic/muon';
2
+ import customValidation from '@muon/utils/validation/index.js';
3
+ import { FormElementMixin } from '@muon/mixins/form-element-mixin';
4
+
5
+ /**
6
+ * A mixin to hold the validation state of a form element.
7
+ *
8
+ * @mixin
9
+ */
10
+
11
+ export const ValidationMixin = dedupeMixin((superClass) =>
12
+ class ValidationMixinClass extends FormElementMixin(superClass) {
13
+
14
+ static get properties() {
15
+ return {
16
+ validation: {
17
+ type: Array
18
+ },
19
+
20
+ disableNative: {
21
+ type: Boolean
22
+ },
23
+
24
+ showMessage: {
25
+ type: Boolean
26
+ },
27
+
28
+ _pristine: {
29
+ type: Boolean,
30
+ state: true
31
+ },
32
+
33
+ _validationState: {
34
+ type: Object,
35
+ state: true
36
+ }
37
+ };
38
+ }
39
+
40
+ constructor() {
41
+ super();
42
+
43
+ this.validation = [];
44
+ this.disableNative = false;
45
+ this.showMessage = true;
46
+ this._pristine = true;
47
+ this._validationState = [];
48
+ }
49
+
50
+ /**
51
+ * A getter method to get pristine state of the form element.
52
+ *
53
+ * @returns {boolean} - Pristine state.
54
+ * @public
55
+ */
56
+ get isPristine() {
57
+ return this._pristine;
58
+ }
59
+
60
+ /**
61
+ * A getter method to get dirty state of the form element.
62
+ *
63
+ * @returns {boolean} - Dirty state.
64
+ * @public
65
+ */
66
+ get isDirty() {
67
+ return !this._pristine;
68
+ }
69
+
70
+ reportValidity() {
71
+ return this.validity;
72
+ }
73
+
74
+ get validity() {
75
+ this._pristine = false;
76
+ return this.validate();
77
+ }
78
+
79
+ reset() {
80
+ super.reset();
81
+ this._pristine = true;
82
+ this._validationState = [];
83
+ }
84
+
85
+ /**
86
+ * A method to validate the value of the form element.
87
+ *
88
+ * @returns {ValidityState} - Validity state of the form element.
89
+ * @public
90
+ * @override
91
+ */
92
+ validate() {
93
+ let validationState = [];
94
+ this.__updateAllValidity('');
95
+ if (this.validation?.length > 0) {
96
+ validationState = this.validation.map((val) => {
97
+ const vf = this.__parseValidationFunction(val);
98
+ const functionName = vf.functionName;
99
+ const params = [this, this.value].concat(vf.params);
100
+ return {
101
+ name: functionName,
102
+ value: customValidation[functionName].apply(this, params)
103
+ };
104
+ });
105
+ }
106
+
107
+ const nativeValidationState = this.__validateNative();
108
+ if (nativeValidationState) {
109
+ validationState.push(nativeValidationState);
110
+ }
111
+
112
+ this._validationState = validationState;
113
+ this.__updateAllValidity(this.validationMessage);
114
+ return this._slottedInputs[0].validity;
115
+ }
116
+
117
+ /**
118
+ * A method to do native html form element validation.
119
+ *
120
+ * @returns {object} - Validation state.
121
+ * @private
122
+ */
123
+ __validateNative() {
124
+ if (this.disableNative) {
125
+ return undefined;
126
+ }
127
+
128
+ let message;
129
+ this._slottedInputs.forEach((input) => {
130
+ if (!input.validity.valid) {
131
+ if (input.validity.patternMismatch && input.title) {
132
+ message = input.title;
133
+ } else {
134
+ message = input.validationMessage;
135
+ }
136
+ }
137
+ });
138
+ return message ? {
139
+ name: 'native',
140
+ value: message
141
+ } : undefined;
142
+ }
143
+
144
+ /**
145
+ * A method to parse the validation function name to return function name and parameter list (if any).
146
+ *
147
+ * @param {string} validation - Validation function name.
148
+ * @returns {object} - Parsed function name and parameter list.
149
+ * @private
150
+ */
151
+ __parseValidationFunction(validation) {
152
+ let params = [];
153
+ const arr = validation.split('(');
154
+ const functionName = arr[0];
155
+ const paramString = arr.length > 1 && arr[1].split(')')[0];
156
+ if (paramString) {
157
+ params = paramString.split(',').map((value) => {
158
+ const int = parseInt(value, 10);
159
+ const clean = value.split('');
160
+ // remove quotes from 'string'
161
+ clean.pop();
162
+ clean.shift();
163
+ return isNaN(int) ? clean.join('') : int;
164
+ });
165
+ }
166
+ return {
167
+ functionName,
168
+ params
169
+ };
170
+ }
171
+
172
+ /**
173
+ * A method to update the custom validity of the html form elements.
174
+ *
175
+ * @param {string} validationMessage - Validation message to be set.
176
+ * @returns {void}
177
+ * @private
178
+ */
179
+ __updateAllValidity(validationMessage) {
180
+ if (this.isDirty) {
181
+ this._slottedInputs.forEach((input) => {
182
+ if (input.setCustomValidity) {
183
+ input.setCustomValidity(validationMessage);
184
+ }
185
+ });
186
+ }
187
+ }
188
+
189
+ /**
190
+ * A getter method to return warning icon of validation message.
191
+ *
192
+ * @protected
193
+ * @override
194
+ * @readonly
195
+ */
196
+ get _addValidationIcon() {
197
+ return undefined;
198
+ }
199
+
200
+ /**
201
+ * A method to get a validation message combind from the validity states.
202
+ *
203
+ * @returns {string} - Validation message.
204
+ */
205
+ get validationMessage() {
206
+ return this._validationState?.filter((state) => {
207
+ return state?.value;
208
+ }).map((state) => {
209
+ return state.value + '.';
210
+ }).join(' ');
211
+ }
212
+
213
+ /**
214
+ * A method to get validation message template.
215
+ *
216
+ * @returns {object} TemplateResult - validation message template.
217
+ * @protected
218
+ * @override
219
+ */
220
+ get _addValidationMessage() {
221
+ if (this.showMessage && this.isDirty && this.validationMessage) {
222
+ return html`
223
+ <div class="validation">
224
+ ${this._addValidationIcon}
225
+ <div class="message">
226
+ ${this.validationMessage}
227
+ </div>
228
+ </div>`;
229
+ }
230
+
231
+ return html``;
232
+ }
233
+
234
+ /**
235
+ * A method to get list view of validation message template.
236
+ *
237
+ * @returns {object} TemplateResult - validation message template.
238
+ * @protected
239
+ * @override
240
+ */
241
+ get _addValidationListMessage() {
242
+ if (this.showMessage && this.isDirty && this.validationMessage) {
243
+ const failedValidationStates = this._validationState?.filter((state) => {
244
+ return state?.value;
245
+ });
246
+ if (failedValidationStates) {
247
+ return html`
248
+ <div class="validation">
249
+ <ul>
250
+ ${repeat(failedValidationStates, (validationState) => html`<li>${this._addValidationState(validationState.name, validationState.value)}</li>`)}
251
+ </ul>
252
+ </div>`;
253
+ }
254
+ }
255
+
256
+ return html``;
257
+ }
258
+
259
+ /**
260
+ * A method to render each of validation state message template.
261
+ *
262
+ * @param {string} key - Validation function name.
263
+ * @param {string} value - Validation state or message.
264
+ * @returns {object} TemplateResult validation template.
265
+ * @protected
266
+ * @override
267
+ */
268
+ _addValidationState(key, value) {
269
+ return html`<p> ${value}. </p>`;
270
+ }
271
+ }
272
+ );
@@ -0,0 +1,97 @@
1
+ import { html, LitElement, adoptStyles, supportsAdoptingStyleSheets } from '@muonic/muon';
2
+
3
+ /**
4
+ * @typedef {module:lit.CSSResultOrNative} CSSResultOrNative - define css type
5
+ */
6
+
7
+ export const MuonElementMixin = (superClass) => class extends superClass {
8
+
9
+ static get properties() {
10
+ return {
11
+ type: { type: String }
12
+ };
13
+ }
14
+
15
+ constructor() {
16
+ super();
17
+
18
+ this.type = 'standard';
19
+
20
+ this.__addLightDOM();
21
+
22
+ }
23
+
24
+ /**
25
+ * A method to inject light DOM styles into parent.
26
+ * This currently has some limitations:
27
+ * - Cannot easily target the element with attributes.
28
+ * - With this implementation CSS can be written outside of host, leaking styles.
29
+ * - :host might not be the right use here as users might believe they can use its other features.
30
+ *
31
+ * @returns {CSSResultOrNative} - Return modified css that is injected.
32
+ * @private
33
+ */
34
+ __addLightDOM() {
35
+ const checkSheets = (styleSheets, styleName) => {
36
+ return [].slice.call(styleSheets).filter((sheet) => {
37
+ return sheet.title === styleName;
38
+ });
39
+ };
40
+
41
+ this.updateComplete.then(() => {
42
+ const css = this.slottedStyles;
43
+
44
+ if (!css) {
45
+ return undefined;
46
+ }
47
+
48
+ const clonedCSS = Object.assign({}, css);
49
+
50
+ const nodeName = this.nodeName.toLowerCase();
51
+ const parentNode = this.getRootNode();
52
+ const parentNodeType = parentNode.nodeName;
53
+ const styleName = `${nodeName}-styles`;
54
+
55
+ // First need to replace `:host` with the component name
56
+ clonedCSS.cssText = clonedCSS.cssText.replace(/:host/g, nodeName);
57
+
58
+ // How we add the styles depends on where it is being added, HTMLDocument or another ShadowDom.
59
+ // If the Document we don't want to add multiple times
60
+ if (parentNodeType === '#document-fragment') {
61
+ // If it is within a shadowDom
62
+ let stylesAdded;
63
+
64
+ if (supportsAdoptingStyleSheets) {
65
+ const stylesheet = new CSSStyleSheet();
66
+
67
+ stylesheet.replaceSync(clonedCSS.cssText);
68
+ stylesAdded = [...parentNode.adoptedStyleSheets, stylesheet];
69
+ } else {
70
+ stylesAdded = [clonedCSS];
71
+ }
72
+
73
+ adoptStyles(parentNode, stylesAdded);
74
+ } else if (parentNodeType === '#document') {
75
+ // If it is in the parent DOM
76
+ const styleSheets = parentNode.styleSheets;
77
+
78
+ if (!Array.from(checkSheets(styleSheets, styleName)).length > 0) {
79
+ const style = document.createElement('style');
80
+ style.innerHTML = String.raw`${clonedCSS.cssText}`;
81
+ style.title = styleName;
82
+ document.head.appendChild(style);
83
+ }
84
+ }
85
+
86
+ return clonedCSS;
87
+
88
+ });
89
+ return undefined;
90
+ }
91
+
92
+ render() {
93
+ return html`${this[`${this.type}Template`]}`;
94
+ }
95
+ };
96
+
97
+ export const MuonElement = MuonElementMixin(LitElement);
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@muonic/muon",
3
+ "version": "0.0.2-beta.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "web-test-runner \"./tests/**/*.test.js\" --coverage",
8
+ "test:scripts": "NODE_OPTIONS=--loader=esmock c8 ava \"tests/scripts/utils/utils-test.mjs\"",
9
+ "test:browserstack": "web-test-runner \"./tests/**/*.test.js\" --config web-test-runner.browserstack.config.mjs",
10
+ "release": "standard-version"
11
+ },
12
+ "bin": {
13
+ "muon-serve": "./scripts/serve/index.mjs",
14
+ "muon-build-storybook": "./scripts/build/storybook/index.mjs"
15
+ },
16
+ "keywords": [],
17
+ "author": "",
18
+ "license": "ISC",
19
+ "dependencies": {
20
+ "@open-wc/building-rollup": "2.0.1",
21
+ "@open-wc/scoped-elements": "2.1.2",
22
+ "@rollup/plugin-alias": "3.1.9",
23
+ "@rollup/plugin-json": "4.1.0",
24
+ "@rollup/plugin-node-resolve": "14.0.0",
25
+ "@rollup/plugin-replace": "4.0.0",
26
+ "@rollup/plugin-virtual": "2.1.0",
27
+ "@web/dev-server": "0.1.32",
28
+ "@web/dev-server-rollup": "0.3.18",
29
+ "@web/dev-server-storybook": "0.5.4",
30
+ "@web/storybook-prebuilt": "0.1.34",
31
+ "@webcomponents/scoped-custom-element-registry": "0.0.5",
32
+ "app-root-path": "3.0.0",
33
+ "autoprefixer": "10.4.7",
34
+ "chokidar": "3.5.3",
35
+ "chroma-js": "2.4.2",
36
+ "command-line-args": "5.2.1",
37
+ "deepmerge": "4.2.2",
38
+ "glob": "8.0.3",
39
+ "glob-to-regexp": "0.4.1",
40
+ "lit": "2.2.7",
41
+ "lodash": "4.17.21",
42
+ "path-is-inside": "1.0.2",
43
+ "postcss": "8.4.14",
44
+ "postcss-clean": "1.2.2",
45
+ "postcss-import": "14.1.0",
46
+ "postcss-preset-env": "7.7.2",
47
+ "postcss-simple-vars": "6.0.3",
48
+ "rollup-plugin-lit-css": "4.0.0",
49
+ "rollup-plugin-styles": "4.0.0",
50
+ "style-dictionary": "3.7.1",
51
+ "typescript": "4.8.2",
52
+ "web-component-analyzer": "1.1.6"
53
+ },
54
+ "devDependencies": {
55
+ "@open-wc/testing": "3.1.6",
56
+ "@web/dev-server-esbuild": "0.3.2",
57
+ "@web/test-runner": "0.14.0",
58
+ "@web/test-runner-browserstack": "0.5.1",
59
+ "@web/test-runner-playwright": "0.8.10",
60
+ "ava": "4.3.3",
61
+ "c8": "^7.12.0",
62
+ "esmock": "^2.0.3",
63
+ "sinon": "14.0.0"
64
+ },
65
+ "engines": {
66
+ "node": ">=16.13.0"
67
+ },
68
+ "browserslist": [
69
+ "defaults",
70
+ "not IE 11"
71
+ ]
72
+ }
@@ -0,0 +1,30 @@
1
+ import merge from 'deepmerge';
2
+ import { rollupPlugins } from '@muonic/muon/scripts/rollup-plugins.mjs';
3
+ import virtual from '@rollup/plugin-virtual';
4
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
5
+ import { createBasicConfig } from '@open-wc/building-rollup';
6
+ import { componentDefiner, getDestination } from '@muonic/muon/scripts/utils/index.mjs';
7
+ import path from 'path';
8
+
9
+ const config = createBasicConfig();
10
+ const input = 'index.js';
11
+
12
+ export default merge(config, {
13
+ ...config,
14
+ input,
15
+ treeshake: false,
16
+ plugins: [
17
+ virtual({
18
+ 'component-definitions.js': componentDefiner()
19
+ }),
20
+ ...rollupPlugins,
21
+ nodeResolve()
22
+ ],
23
+ output: {
24
+ ...config.output,
25
+ dir: undefined,
26
+ file: path.join(getDestination(), 'index.js'),
27
+ sourcemap: false,
28
+ inlineDynamicImports: true
29
+ }
30
+ });
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import path from 'path';
3
+ import { runner } from '../../utils/index.mjs';
4
+
5
+ import { fileURLToPath } from 'url';
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ const file = path.join(__dirname, 'run.mjs');
10
+
11
+ runner(file);
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execFileSync } from 'child_process';
4
+ import path from 'path';
5
+ import fs from 'fs';
6
+
7
+ import commandLineArgs from 'command-line-args';
8
+
9
+ const args = commandLineArgs([
10
+ {
11
+ name: 'config-dir',
12
+ alias: 'c',
13
+ type: String,
14
+ defaultValue: './.storybook'
15
+ },
16
+ {
17
+ name: 'output-dir',
18
+ alias: 'o',
19
+ type: String,
20
+ defaultValue: 'storybook-static'
21
+ },
22
+ {
23
+ name: 'type',
24
+ alias: 't',
25
+ type: String,
26
+ defaultValue: 'web-components'
27
+ }
28
+ ]);
29
+
30
+ const main = async () => {
31
+ const configDir = path.resolve(args['config-dir']);
32
+ const outputDir = path.resolve(args['output-dir']);
33
+ const execArgs = [
34
+ '--config-dir', configDir,
35
+ '--output-dir', outputDir,
36
+ ];
37
+
38
+ if (!fs.existsSync(outputDir)) {
39
+ fs.mkdirSync(outputDir);
40
+ }
41
+
42
+ execFileSync('build-storybook', execArgs);
43
+
44
+ console.log('Storybook build completed');
45
+ };
46
+
47
+ main();
@@ -0,0 +1,116 @@
1
+ import { fromRollup } from '@web/dev-server-rollup';
2
+ import stylesPlugin from 'rollup-plugin-styles';
3
+ import replacePlugin from '@rollup/plugin-replace';
4
+ import aliasPlugin from '@rollup/plugin-alias';
5
+ import autoprefixer from 'autoprefixer';
6
+ import postcssPreset from 'postcss-preset-env';
7
+ import postcssImport from 'postcss-import';
8
+ import postcssVariables from 'postcss-simple-vars';
9
+ import litcssPlugin from 'rollup-plugin-lit-css';
10
+ import { cleanup, getConfig, getDestination, createTokens, sourceFilesAnalyzer, getAliasPaths } from './utils/index.mjs';
11
+
12
+ import path from 'path';
13
+ import fs from 'fs';
14
+
15
+ import { fileURLToPath } from 'url';
16
+ const __filename = fileURLToPath(import.meta.url);
17
+ const __dirname = path.dirname(__filename);
18
+
19
+ const config = getConfig();
20
+
21
+ const muonPlugin = () => {
22
+ return {
23
+ name: 'muon',
24
+ async buildStart() {
25
+ const destination = getDestination();
26
+ cleanup(destination, true).then(async () => {
27
+ const cejson = await sourceFilesAnalyzer();
28
+ fs.writeFileSync(path.join(destination, 'custom-elements.json'), cejson);
29
+ });
30
+ }
31
+ };
32
+ };
33
+
34
+ const tokenPath = path.join(__dirname, '..', 'build', 'tokens', 'es6', 'muon-tokens.mjs');
35
+ let designTokens = {};
36
+
37
+ const buildTokensPlugin = () => {
38
+ return {
39
+ name: 'generate-tokens-plugin',
40
+ async buildStart() {
41
+ await createTokens();
42
+ designTokens = await import(tokenPath);
43
+ }
44
+ };
45
+ };
46
+
47
+ const styles = fromRollup(stylesPlugin);
48
+ const replace = fromRollup(replacePlugin);
49
+ const litcss = fromRollup(litcssPlugin);
50
+ const alias = fromRollup(aliasPlugin);
51
+ const muon = fromRollup(muonPlugin);
52
+ const buildTokens = fromRollup(buildTokensPlugin);
53
+
54
+ const aliasConfig = {
55
+ entries: getAliasPaths('regex')
56
+ };
57
+
58
+ const postcssPlugins = [
59
+ postcssVariables({
60
+ variables() {
61
+ return designTokens;
62
+ },
63
+ unknown(node) {
64
+ node.remove(); // removing unknown or unset tokens
65
+ }
66
+ }),
67
+ postcssImport(),
68
+ postcssPreset({
69
+ stage: 0,
70
+ features: {
71
+ 'logical-properties-and-values': false /* allowing start end values */
72
+ }
73
+ }),
74
+ autoprefixer({ grid: true })
75
+ ];
76
+
77
+ // @TODO: bring back when global css is used
78
+ // const createGlobalCSS = async (destination) => {
79
+ // const globalCSSUrl = path.join(__filename, '..', '..', '..', 'css', 'global.css');
80
+ // const globalCSSDest = path.join(destination, 'muon.min.css');
81
+ // const globalCSS = fs.readFileSync(globalCSSUrl);
82
+ // const processedCSS = await postcss(postcssPlugins).process(globalCSS, { from: globalCSSUrl, to: globalCSSDest });
83
+
84
+ // fs.writeFileSync(globalCSSDest, processedCSS.css, 'utf8');
85
+ // };
86
+
87
+ const styleConfig = {
88
+ mode: 'emit',
89
+ minimize: true,
90
+ plugins: postcssPlugins
91
+ };
92
+
93
+ const replaceConfig = {
94
+ preventAssignment: true,
95
+ values: {
96
+ 'process.env.MUON_PREFIX': JSON.stringify(config?.components?.prefix || 'muon')
97
+ }
98
+ };
99
+
100
+ export const serverPlugins = [
101
+ buildTokens(),
102
+ alias(aliasConfig),
103
+ replace(replaceConfig),
104
+ styles(styleConfig),
105
+ litcss({ exclude: ['**/css/*.css', '**/dist/*.css', 'muon.min.css'] }),
106
+ muon()
107
+ ];
108
+
109
+ export const rollupPlugins = [
110
+ buildTokensPlugin(),
111
+ aliasPlugin(aliasConfig),
112
+ replacePlugin(replaceConfig),
113
+ stylesPlugin(styleConfig),
114
+ litcssPlugin({ exclude: ['**/css/*.css', '**/dist/*.css', 'muon.min.css'] }),
115
+ muonPlugin()
116
+ ];
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import path from 'path';
3
+ import { runner } from '../utils/index.mjs';
4
+
5
+ import { fileURLToPath } from 'url';
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ const file = path.join(__dirname, 'run.mjs');
10
+
11
+ runner(file);
@@ -0,0 +1,27 @@
1
+ import { startDevServer } from '@web/dev-server';
2
+ import commandLineArgs from 'command-line-args';
3
+ import StorybookConfig from '../../storybook/server.config.mjs';
4
+
5
+ const myServerDefinitions = [
6
+ { name: 'no-open', type: Boolean },
7
+ { name: 'no-watch', type: Boolean }
8
+ ];
9
+
10
+ const myConfig = commandLineArgs(myServerDefinitions, { partial: true });
11
+
12
+ const main = async () => {
13
+ await startDevServer({
14
+ argv: myConfig._unknown,
15
+ config: {
16
+ ...StorybookConfig,
17
+ open: !myConfig['no-open'],
18
+ watch: !myConfig['no-watch'],
19
+ mimeTypes: {
20
+ // '**/muon.min.css': 'text/css', // @TODO: pass global style file name from config
21
+ ...StorybookConfig.mimeTypes
22
+ }
23
+ }
24
+ });
25
+ };
26
+
27
+ main();