@mgdis/core-ui-helpers 1.0.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 (146) hide show
  1. package/.turbo/turbo-build.log +52 -0
  2. package/CHANGELOG.md +12 -0
  3. package/LICENSE +29 -0
  4. package/README.md +95 -0
  5. package/dist/angular/index.cjs +27 -0
  6. package/dist/angular/index.cjs.map +1 -0
  7. package/dist/angular/index.d.ts +21 -0
  8. package/dist/angular/index.js +25 -0
  9. package/dist/angular/index.js.map +1 -0
  10. package/dist/angular/index.umd.js +33 -0
  11. package/dist/angular/index.umd.js.map +1 -0
  12. package/dist/locale/index.cjs +164 -0
  13. package/dist/locale/index.cjs.map +1 -0
  14. package/dist/locale/index.d.ts +103 -0
  15. package/dist/locale/index.js +156 -0
  16. package/dist/locale/index.js.map +1 -0
  17. package/dist/locale/index.umd.js +170 -0
  18. package/dist/locale/index.umd.js.map +1 -0
  19. package/dist/playwright/index.cjs +124 -0
  20. package/dist/playwright/index.cjs.map +1 -0
  21. package/dist/playwright/index.d.ts +35 -0
  22. package/dist/playwright/index.js +120 -0
  23. package/dist/playwright/index.js.map +1 -0
  24. package/dist/playwright/index.umd.js +130 -0
  25. package/dist/playwright/index.umd.js.map +1 -0
  26. package/dist/stencil/index.cjs +281 -0
  27. package/dist/stencil/index.cjs.map +1 -0
  28. package/dist/stencil/index.d.ts +111 -0
  29. package/dist/stencil/index.js +277 -0
  30. package/dist/stencil/index.js.map +1 -0
  31. package/dist/stencil/index.umd.js +287 -0
  32. package/dist/stencil/index.umd.js.map +1 -0
  33. package/dist/storybook/index.cjs +2109 -0
  34. package/dist/storybook/index.cjs.map +1 -0
  35. package/dist/storybook/index.d.ts +85 -0
  36. package/dist/storybook/index.js +2103 -0
  37. package/dist/storybook/index.js.map +1 -0
  38. package/dist/storybook/index.umd.js +2115 -0
  39. package/dist/storybook/index.umd.js.map +1 -0
  40. package/dist/tests/index.cjs +166 -0
  41. package/dist/tests/index.cjs.map +1 -0
  42. package/dist/tests/index.d.ts +91 -0
  43. package/dist/tests/index.js +161 -0
  44. package/dist/tests/index.js.map +1 -0
  45. package/dist/tests/index.umd.js +172 -0
  46. package/dist/tests/index.umd.js.map +1 -0
  47. package/dist/utils/index.cjs +433 -0
  48. package/dist/utils/index.cjs.map +1 -0
  49. package/dist/utils/index.d.ts +265 -0
  50. package/dist/utils/index.js +409 -0
  51. package/dist/utils/index.js.map +1 -0
  52. package/dist/utils/index.umd.js +439 -0
  53. package/dist/utils/index.umd.js.map +1 -0
  54. package/dist/vue/index.cjs +1934 -0
  55. package/dist/vue/index.cjs.map +1 -0
  56. package/dist/vue/index.d.ts +35 -0
  57. package/dist/vue/index.js +1932 -0
  58. package/dist/vue/index.js.map +1 -0
  59. package/dist/vue/index.umd.js +1940 -0
  60. package/dist/vue/index.umd.js.map +1 -0
  61. package/json-doc.test.json +253 -0
  62. package/package.json +80 -0
  63. package/rollup.config.mjs +61 -0
  64. package/src/angular/index.spec.ts +8 -0
  65. package/src/angular/index.ts +1 -0
  66. package/src/angular/mg-angular-logger/index.ts +1 -0
  67. package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +3 -0
  68. package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +40 -0
  69. package/src/angular/mg-angular-logger/mg-angular-logger.ts +23 -0
  70. package/src/locale/index.spec.ts +14 -0
  71. package/src/locale/index.ts +1 -0
  72. package/src/locale/locale.spec.ts +173 -0
  73. package/src/locale/locale.ts +166 -0
  74. package/src/playwright/config/index.ts +43 -0
  75. package/src/playwright/index.spec.ts +16 -0
  76. package/src/playwright/index.ts +4 -0
  77. package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +48 -0
  78. package/src/playwright/utils/index.ts +1 -0
  79. package/src/playwright/utils/utils.spec.ts +43 -0
  80. package/src/playwright/utils/utils.ts +64 -0
  81. package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +527 -0
  82. package/src/stencil/ide/ide.spec.ts +25 -0
  83. package/src/stencil/ide/ide.ts +214 -0
  84. package/src/stencil/ide/index.ts +1 -0
  85. package/src/stencil/index.spec.ts +12 -0
  86. package/src/stencil/index.ts +1 -0
  87. package/src/storybook/index.spec.ts +15 -0
  88. package/src/storybook/index.ts +1 -0
  89. package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +329 -0
  90. package/src/storybook/stencil/index.ts +1 -0
  91. package/src/storybook/stencil/stencil-shim.d.ts +1 -0
  92. package/src/storybook/stencil/stencil.conf.ts +4 -0
  93. package/src/storybook/stencil/stencil.spec.ts +142 -0
  94. package/src/storybook/stencil/stencil.ts +366 -0
  95. package/src/tests/index.spec.ts +13 -0
  96. package/src/tests/index.ts +1 -0
  97. package/src/tests/unit/__snapshots__/unit.spec.ts.snap +52 -0
  98. package/src/tests/unit/index.ts +1 -0
  99. package/src/tests/unit/unit.conf.ts +9 -0
  100. package/src/tests/unit/unit.spec.ts +44 -0
  101. package/src/tests/unit/unit.ts +171 -0
  102. package/src/utils/attributes/class-list/class-list.spec.ts +36 -0
  103. package/src/utils/attributes/class-list/class-list.ts +51 -0
  104. package/src/utils/attributes/class-list/index.ts +1 -0
  105. package/src/utils/attributes/id/id.spec.ts +51 -0
  106. package/src/utils/attributes/id/id.ts +46 -0
  107. package/src/utils/attributes/id/index.ts +1 -0
  108. package/src/utils/attributes/index.ts +3 -0
  109. package/src/utils/attributes/to-kebab-case/index.ts +1 -0
  110. package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +29 -0
  111. package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +23 -0
  112. package/src/utils/components/__snapshots__/components.spec.ts.snap +313 -0
  113. package/src/utils/components/components.conf.ts +11 -0
  114. package/src/utils/components/components.spec.ts +192 -0
  115. package/src/utils/components/components.ts +138 -0
  116. package/src/utils/components/index.ts +2 -0
  117. package/src/utils/date/date.spec.ts +12 -0
  118. package/src/utils/date/date.ts +20 -0
  119. package/src/utils/date/index.ts +1 -0
  120. package/src/utils/elements/elements.spec.ts +17 -0
  121. package/src/utils/elements/elements.ts +16 -0
  122. package/src/utils/elements/index.ts +1 -0
  123. package/src/utils/index.spec.ts +84 -0
  124. package/src/utils/index.ts +8 -0
  125. package/src/utils/number/index.ts +1 -0
  126. package/src/utils/number/number.spec.ts +14 -0
  127. package/src/utils/number/number.ts +6 -0
  128. package/src/utils/object/index.ts +2 -0
  129. package/src/utils/object/object.conf.ts +4 -0
  130. package/src/utils/object/object.spec.ts +98 -0
  131. package/src/utils/object/object.ts +26 -0
  132. package/src/utils/string/index.ts +1 -0
  133. package/src/utils/string/string.spec.ts +47 -0
  134. package/src/utils/string/string.ts +38 -0
  135. package/src/utils/windows/index.ts +1 -0
  136. package/src/utils/windows/windows.spec.ts +65 -0
  137. package/src/utils/windows/windows.ts +50 -0
  138. package/src/vue/index.spec.ts +8 -0
  139. package/src/vue/index.ts +1 -0
  140. package/src/vue/mg-model/index.ts +1 -0
  141. package/src/vue/mg-model/mg-model.conf.ts +6 -0
  142. package/src/vue/mg-model/mg-model.spec.ts +50 -0
  143. package/src/vue/mg-model/mg-model.ts +50 -0
  144. package/tsconfig.json +17 -0
  145. package/typedoc.json +14 -0
  146. package/vitest.config.mts +13 -0
@@ -0,0 +1,130 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CoreUiHelpers = global.CoreUiHelpers || {}, global.CoreUiHelpers.playwright = {})));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ const config = {
8
+ testMatch: '*.e2e.ts',
9
+ snapshotPathTemplate: '{testFileDir}/__screenshots__/{arg}-{projectName}{ext}',
10
+ /* Maximum time one test can run for. */
11
+ timeout: 30 * 1000,
12
+ expect: {
13
+ /**
14
+ * Maximum time expect() should wait for the condition to be met.
15
+ * For example in `await expect(locator).toHaveText();`
16
+ */
17
+ timeout: 5000,
18
+ },
19
+ /* Run tests in files in parallel */
20
+ fullyParallel: true,
21
+ /* Fail the build on CI if you accidentally left test.only in the source code. */
22
+ forbidOnly: !!process.env.CI,
23
+ /* Retry on CI only */
24
+ retries: process.env.CI ? 2 : 0,
25
+ /* Stop on CI on first failure */
26
+ maxFailures: process.env.CI ? 1 : 0,
27
+ /* Opt out of parallel tests on CI. */
28
+ workers: process.env.CI ? 1 : undefined,
29
+ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
30
+ reporter: [
31
+ ['html', { open: 'never' }],
32
+ ['junit', { outputFile: 'results.xml' }],
33
+ ],
34
+ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35
+ use: {
36
+ headless: true,
37
+ /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
38
+ actionTimeout: 0,
39
+ /* Base URL to use in actions like `await page.goto('/')`. */
40
+ // baseURL: 'http://localhost:3000',
41
+ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
42
+ trace: 'on-first-retry',
43
+ },
44
+ };
45
+
46
+ /**
47
+ * Check if a value is of object type.
48
+ * @param object - The value to validate.
49
+ * @returns `true` if the value is a valid object (non-null and not an array), otherwise `false`.
50
+ */
51
+ const isObject = (object) => typeof object === 'object' && !Array.isArray(object) && object !== null;
52
+
53
+ /**
54
+ * Typeguard function to check if all array items are strings.
55
+ * @param items - items to check
56
+ * @returns `true` if all items are strings
57
+ */
58
+ /**
59
+ * Validate string
60
+ * @param value - value to check
61
+ * @returns `true` if string is valid
62
+ */
63
+ const isValidString = (value) => typeof value === 'string' && value.trim() !== '';
64
+
65
+ /**
66
+ * Render attributes from props objects
67
+ * @param args - argument to render as string. ex: `{status: 'visible'}`
68
+ * @returns formated inline attributed. ex: 'status="visible"'
69
+ * @example
70
+ * ```ts
71
+ * import { renderAttributes } from '@mgdis/core-ui-helpers/dist/playwright';
72
+ *
73
+ * const attributes = renderAttributes({ status: 'visible', color: 'red' });
74
+ * console.log(attributes); // Output: 'status="visible" color="red"'
75
+ * ```
76
+ */
77
+ const renderAttributes = (args) => (isObject(args) &&
78
+ Object.keys(args)
79
+ .filter(key => ![null, undefined, false].includes(args[key]) && !['object', 'function'].includes(typeof args[key]))
80
+ .map(key => {
81
+ const attribute = key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
82
+ const value = ['number', 'boolean'].includes(typeof args[key]) || isValidString(args[key]) ? String(args[key]).replace(/"/g, "'") : '';
83
+ return `${attribute}="${value}"`;
84
+ })
85
+ .join(' ')) ||
86
+ '';
87
+ /**
88
+ * Render properties from props objects.
89
+ * Insert return value in <script></script> element
90
+ * @param args - argument to render as script. ex: `{status: 'visible'}`
91
+ * @param selector - querySelector get targetted element and bind properties on it
92
+ * @returns stringified properties script
93
+ * @example
94
+ * ```ts
95
+ * import { renderProperties } from '@mgdis/core-ui-helpers/dist/playwright';
96
+ *
97
+ * const propertiesScript = renderProperties({ status: 'visible', color: 'red' }, '.targetElement');
98
+ * console.log(propertiesScript);
99
+ * // Output: 'document.querySelector(".targetElement").status="visible"; document.querySelector(".targetElement").color="red";'
100
+ * ```
101
+ */
102
+ const renderProperties = (args, selector) => {
103
+ // has generated id selector starting with "#" create charcters (ex: '#0j3xzw4w7m') make test crashed sometime with "querySelector"
104
+ // we use "getElementById" document query
105
+ const query = selector.startsWith('#') ? 'getElementById' : 'querySelector';
106
+ if (query === 'getElementById')
107
+ selector = selector.replace('#', '');
108
+ return args !== null && typeof args === 'object' && Object.keys(args).length > 0
109
+ ? `
110
+ ${Object.keys(args)
111
+ .filter(key => ['object', 'function'].includes(typeof args[key]))
112
+ .map(key => {
113
+ const value = JSON.stringify(args[key], (_key, val) => (typeof val === 'function' ? `<fn>${val}</fn>` : val));
114
+ return `document.${query}('${selector}').${key}=${value}`;
115
+ }) // stringify json AND keep function values
116
+ .join(';') // create string
117
+ .split('"<fn>') // remove fn start decorator
118
+ .join('')
119
+ .split('</fn>"')
120
+ .join('') // remove fn end decorator
121
+ }`
122
+ : '';
123
+ };
124
+
125
+ exports.playwrightBaseConfig = config;
126
+ exports.renderAttributes = renderAttributes;
127
+ exports.renderProperties = renderProperties;
128
+
129
+ }));
130
+ //# sourceMappingURL=index.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.umd.js","sources":["../../src/playwright/config/index.ts","../../src/utils/object/object.ts","../../src/utils/string/string.ts","../../src/playwright/utils/utils.ts"],"sourcesContent":[null,null,null,null],"names":[],"mappings":"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"}
@@ -0,0 +1,281 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ Stencil Client Platform v4.28.2 | MIT Licensed | https://stenciljs.com
5
+ */
6
+ var __defProp = Object.defineProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+
12
+ // src/utils/result.ts
13
+ var result_exports = {};
14
+ __export(result_exports, {
15
+ err: () => err,
16
+ map: () => map,
17
+ ok: () => ok,
18
+ unwrap: () => unwrap,
19
+ unwrapErr: () => unwrapErr
20
+ });
21
+ var ok = (value) => ({
22
+ isOk: true,
23
+ isErr: false,
24
+ value
25
+ });
26
+ var err = (value) => ({
27
+ isOk: false,
28
+ isErr: true,
29
+ value
30
+ });
31
+ function map(result, fn) {
32
+ if (result.isOk) {
33
+ const val = fn(result.value);
34
+ if (val instanceof Promise) {
35
+ return val.then((newVal) => ok(newVal));
36
+ } else {
37
+ return ok(val);
38
+ }
39
+ }
40
+ if (result.isErr) {
41
+ const value = result.value;
42
+ return err(value);
43
+ }
44
+ throw "should never get here";
45
+ }
46
+ var unwrap = (result) => {
47
+ if (result.isOk) {
48
+ return result.value;
49
+ } else {
50
+ throw result.value;
51
+ }
52
+ };
53
+ var unwrapErr = (result) => {
54
+ if (result.isErr) {
55
+ return result.value;
56
+ } else {
57
+ throw result.value;
58
+ }
59
+ };
60
+
61
+ /**
62
+ * Retrieve Component Storybook URL from file path
63
+ * @param storybookBaseUrl - Storybook Base URL
64
+ * @param filePath - Component file path
65
+ * @returns Component Storybook URL
66
+ */
67
+ const getStorybookUrl = (storybookBaseUrl, filePath) => {
68
+ if (!filePath) {
69
+ return;
70
+ }
71
+ const split = filePath.split('/');
72
+ return `${storybookBaseUrl}${split.slice(2, split.length - 1).join('-')}--docs`;
73
+ };
74
+
75
+ /**
76
+ * Retrieve Component source URL from file path
77
+ * @param sourcesBaseUrl - Source base URL
78
+ * @param filePath - Component file path
79
+ * @returns Component source URL
80
+ */
81
+ const getSourcesUrl = (sourcesBaseUrl, filePath) => {
82
+ if (!filePath) {
83
+ return;
84
+ }
85
+ return `${sourcesBaseUrl}${filePath}`;
86
+ };
87
+ /**
88
+ * Get Component element description
89
+ * @param component - Component
90
+ * @returns Component element description
91
+ */
92
+ const getElementDescription = (component) => {
93
+ // Init description
94
+ let description = component.overview ? `${component.overview}\n\n` : '';
95
+ // Attributes
96
+ const attributes = component.props.filter(({ attr }) => attr !== undefined);
97
+ if (attributes.length) {
98
+ description += `Attributes:\n`;
99
+ description += attributes.map(({ attr, docs }) => `- \`${attr}\`: ${docs}\n`).join('');
100
+ description += '\n';
101
+ }
102
+ // Properties
103
+ const properties = component.props.filter(({ attr }) => attr === undefined);
104
+ if (properties.length) {
105
+ description += `Properties:\n`;
106
+ description += properties.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
107
+ description += '\n';
108
+ }
109
+ // Methods
110
+ if (component.methods.length) {
111
+ description += `Methods:\n`;
112
+ description += component.methods.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
113
+ description += '\n';
114
+ }
115
+ // Events
116
+ if (component.events.length) {
117
+ description += `Events:\n`;
118
+ description += component.events.map(({ event, docs }) => `- \`${event}\`: ${docs}\n`).join('');
119
+ description += '\n';
120
+ }
121
+ // Listeners
122
+ if (component.listeners.length) {
123
+ description += `Listeners:\n`;
124
+ description += component.listeners.map(({ event }) => `- \`${event}\`\n`).join('');
125
+ description += '\n';
126
+ }
127
+ // Slots
128
+ if (component.slots.length) {
129
+ description += `Slots:\n`;
130
+ description += component.slots.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
131
+ description += '\n';
132
+ }
133
+ // Return
134
+ return description;
135
+ };
136
+ /**
137
+ * Get Props Description
138
+ * @param prop - Component Property
139
+ * @returns Props Description
140
+ */
141
+ const getAttributeDescription = (prop) => {
142
+ return `${prop.docs}\n\nType: \`${prop.type}\``;
143
+ };
144
+ /**
145
+ * Generate Web Types metadata for IntelliJ's IDE
146
+ * @param name - Library name
147
+ * @param version - Library version
148
+ * @param jsonDocs - Stencil JSON doc
149
+ * @param storybookBaseUrl - Storybook Base Url
150
+ * @returns Web Types metadata
151
+ * @example
152
+ * ```ts
153
+ * const webTypesJson = webTypesGenerator('@mgdis/mg-components', '1.0.0', jsonDocs, 'https://storybook.example.com');
154
+ * ```
155
+ */
156
+ const webTypesGenerator = (name, version, jsonDocs, storybookBaseUrl) => ({
157
+ '$schema': 'https://json.schemastore.org/web-types',
158
+ name,
159
+ version,
160
+ 'description-markup': 'markdown',
161
+ 'contributions': {
162
+ html: {
163
+ elements: jsonDocs.components.map(component => {
164
+ const docUrl = getStorybookUrl(storybookBaseUrl, component.filePath);
165
+ return {
166
+ 'name': component.tag,
167
+ 'description': getElementDescription(component),
168
+ 'doc-url': docUrl,
169
+ 'attributes': component.props
170
+ .filter(prop => prop.attr)
171
+ .map(prop => ({
172
+ 'name': prop.attr,
173
+ 'description': getAttributeDescription(prop),
174
+ 'doc-url': docUrl,
175
+ 'value': {
176
+ type: prop.type,
177
+ default: prop.default,
178
+ required: prop.required,
179
+ },
180
+ })),
181
+ 'js': {
182
+ properties: component.props.map(prop => ({
183
+ 'name': prop.name,
184
+ 'description': getAttributeDescription(prop),
185
+ 'doc-url': docUrl,
186
+ 'value': {
187
+ type: prop.type,
188
+ default: prop.default,
189
+ required: prop.required,
190
+ },
191
+ })),
192
+ events: component.events.map(event => ({
193
+ name: event.event,
194
+ description: event.docs,
195
+ })),
196
+ },
197
+ 'css': {
198
+ properties: component.styles.map(style => ({
199
+ name: style.name,
200
+ description: style.docs,
201
+ })),
202
+ },
203
+ };
204
+ }),
205
+ },
206
+ },
207
+ });
208
+ /**
209
+ * Create Storybook Reference
210
+ * @param storybookBaseUrl - Storybook Base Url
211
+ * @param filePath - Component file path
212
+ * @returns Storybook Reference
213
+ */
214
+ const getReferences = (storybookBaseUrl, sourceBaseUrl, filePath) => {
215
+ return [
216
+ { name: 'Storybook', url: getStorybookUrl(storybookBaseUrl, filePath) },
217
+ { name: 'Sources', url: getSourcesUrl(sourceBaseUrl, filePath) },
218
+ ];
219
+ };
220
+ /**
221
+ * Get Property possible values
222
+ * @param prop - Component Property
223
+ * @returns Property possible values
224
+ */
225
+ const getValues = (prop) => {
226
+ // Only values Array where all objects have a value seems to be usefull
227
+ if (prop.values.some(({ value }) => value === undefined)) {
228
+ return;
229
+ }
230
+ return prop.values.map(({ value }) => ({ name: value }));
231
+ };
232
+ /**
233
+ * Generate custom HTML datasets for VS Code
234
+ * @param jsonDocs - Stencil JSON doc
235
+ * @param storybookBaseUrl - Storybook Base Url
236
+ * @returns custom HTML datasets
237
+ * @example
238
+ * ```ts
239
+ * const customDataJson = vsCodeGenerator(jsonDocs, 'https://storybook.example.com', 'https://sources.example.com');
240
+ * ```
241
+ */
242
+ const vsCodeGenerator = (jsonDocs, storybookBaseUrl, sourceBaseUrl) => ({
243
+ version: 1.1,
244
+ tags: jsonDocs.components.map(component => {
245
+ const references = getReferences(storybookBaseUrl, sourceBaseUrl, component.filePath);
246
+ return {
247
+ name: component.tag,
248
+ description: getElementDescription(component),
249
+ attributes: component.props.map(prop => ({
250
+ name: prop.attr ?? prop.name,
251
+ description: getAttributeDescription(prop),
252
+ values: getValues(prop),
253
+ references,
254
+ })),
255
+ references,
256
+ };
257
+ }),
258
+ globalAttributes: [],
259
+ valueSets: [],
260
+ });
261
+ /**
262
+ * Generate custom CSS datasets for VS Code
263
+ * @param jsonDocs - Stencil JSON doc
264
+ * @returns custom CSS datasets
265
+ * @example
266
+ * ```ts
267
+ * const customDataJson = vsCodeCssGenerator(jsonDocs);
268
+ * ```
269
+ */
270
+ const vsCodeCssGenerator = (jsonDocs) => ({
271
+ version: 1.1,
272
+ properties: jsonDocs.components.flatMap(component => component.styles.map(style => ({
273
+ name: style.name,
274
+ description: style.docs,
275
+ }))),
276
+ });
277
+
278
+ exports.vsCodeCssGenerator = vsCodeCssGenerator;
279
+ exports.vsCodeGenerator = vsCodeGenerator;
280
+ exports.webTypesGenerator = webTypesGenerator;
281
+ //# sourceMappingURL=index.cjs.map