@mgdis/core-ui-helpers 1.3.1 → 1.3.2

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.
@@ -1,369 +1,389 @@
1
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.stencil = {})));
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.stencil = {})));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- /**
8
- * Retrieve Component Storybook URL from file path
9
- * @param storybookBaseUrl - Storybook Base URL
10
- * @param filePath - Component file path
11
- * @returns Component Storybook URL
12
- */
13
- const getStorybookUrl = (storybookBaseUrl, filePath) => {
14
- if (!filePath) {
15
- return;
16
- }
17
- const split = filePath.split('/');
18
- return `${storybookBaseUrl}${split.slice(2, split.length - 1).join('-')}--docs`;
19
- };
7
+ /**
8
+ * @type {import('htmlfy').Config}
9
+ */
20
10
 
21
- /**
22
- * Retrieve Component source URL from file path
23
- * @param sourcesBaseUrl - Source base URL
24
- * @param filePath - Component file path
25
- * @returns Component source URL
26
- */
27
- const getSourcesUrl = (sourcesBaseUrl, filePath) => {
28
- if (!filePath) {
29
- return;
30
- }
31
- return `${sourcesBaseUrl}${filePath}`;
32
- };
33
- /**
34
- * Get Component element description.
35
- *
36
- * Neither WebStorm nor VS Code render the structured `attributes` /
37
- * `js.properties` arrays in the tag-level quick-doc — they only show this
38
- * markdown description. So the attribute and property listings have to live
39
- * here, even though they're redundant with the structured arrays used by the
40
- * inline autocomplete.
41
- * @param component - Component
42
- * @returns Component element description
43
- */
44
- const getElementDescription = (component) => {
45
- let description = component.overview ? `${component.overview}\n\n` : '';
46
- const attributes = component.props.filter(({ attr }) => attr !== undefined);
47
- if (attributes.length) {
48
- description += `Attributes:\n`;
49
- description += attributes.map(({ attr, docs }) => `- \`${attr}\`: ${docs}\n`).join('');
50
- description += '\n';
51
- }
52
- const properties = component.props.filter(({ attr }) => attr === undefined);
53
- if (properties.length) {
54
- description += `Properties:\n`;
55
- description += properties.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
56
- description += '\n';
57
- }
58
- if (component.methods.length) {
59
- description += `Methods:\n`;
60
- description += component.methods.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
61
- description += '\n';
62
- }
63
- if (component.events.length) {
64
- description += `Events:\n`;
65
- description += component.events.map(({ event, docs }) => `- \`${event}\`: ${docs}\n`).join('');
66
- description += '\n';
67
- }
68
- if (component.listeners.length) {
69
- description += `Listeners:\n`;
70
- description += component.listeners.map(({ event }) => `- \`${event}\`\n`).join('');
71
- description += '\n';
72
- }
73
- if (component.slots.length) {
74
- description += `Slots:\n`;
75
- description += component.slots
76
- .map(({ name, docs }) => {
77
- const label = name ? `\`${name}\`` : 'default';
78
- return `- ${label}: ${docs}\n`;
79
- })
80
- .join('');
81
- description += '\n';
82
- }
83
- return description;
84
- };
85
- /**
86
- * Get Props Description
87
- * @param prop - Component Property
88
- * @returns Props Description
89
- */
90
- const getAttributeDescription = (prop) => {
91
- return `${prop.docs}\n\nType: \`${prop.type}\``;
92
- };
93
- /**
94
- * Generate Web Types metadata for IntelliJ's IDE
95
- * @param name - Library name
96
- * @param version - Library version
97
- * @param jsonDocs - Stencil JSON doc
98
- * @param storybookBaseUrl - Storybook Base Url
99
- * @returns Web Types metadata
100
- * @example
101
- * ```ts
102
- * const webTypesJson = webTypesGenerator('@mgdis/mg-components', '1.0.0', jsonDocs, 'https://storybook.example.com');
103
- * ```
104
- */
105
- const webTypesGenerator = (name, version, jsonDocs, storybookBaseUrl) => ({
106
- $schema: 'https://json.schemastore.org/web-types',
107
- name,
108
- version,
109
- 'description-markup': 'markdown',
110
- contributions: {
111
- html: {
112
- elements: jsonDocs.components.map((component) => {
113
- const docUrl = getStorybookUrl(storybookBaseUrl, component.filePath);
114
- return {
115
- name: component.tag,
116
- description: getElementDescription(component),
117
- 'doc-url': docUrl,
118
- attributes: component.props
119
- .filter((prop) => prop.attr)
120
- .map((prop) => ({
121
- name: prop.attr,
122
- description: getAttributeDescription(prop),
123
- 'doc-url': docUrl,
124
- value: {
125
- type: prop.type,
126
- default: prop.default,
127
- required: prop.required,
128
- },
129
- })),
130
- js: {
131
- properties: component.props
132
- .filter((prop) => prop.attr === undefined)
133
- .map((prop) => ({
134
- name: prop.name,
135
- description: getAttributeDescription(prop),
136
- 'doc-url': docUrl,
137
- value: {
138
- type: prop.type,
139
- default: prop.default,
140
- required: prop.required,
141
- },
142
- })),
143
- events: component.events.map((event) => ({
144
- name: event.event,
145
- description: event.docs,
146
- })),
147
- },
148
- css: {
149
- properties: component.styles.map((style) => ({
150
- name: style.name,
151
- description: style.docs,
152
- })),
153
- },
154
- };
155
- }),
156
- },
157
- },
158
- });
159
- /**
160
- * Create Storybook Reference
161
- * @param storybookBaseUrl - Storybook Base Url
162
- * @param filePath - Component file path
163
- * @returns Storybook Reference
164
- */
165
- const getReferences = (storybookBaseUrl, sourceBaseUrl, filePath) => {
166
- return [
167
- { name: 'Storybook', url: getStorybookUrl(storybookBaseUrl, filePath) },
168
- { name: 'Sources', url: getSourcesUrl(sourceBaseUrl, filePath) },
169
- ];
170
- };
171
- /**
172
- * Get Property possible values
173
- * @param prop - Component Property
174
- * @returns Property possible values
175
- */
176
- const getValues = (prop) => {
177
- // Only values Array where all objects have a value seems to be usefull
178
- if (prop.values.some(({ value }) => value === undefined)) {
179
- return;
180
- }
181
- return prop.values.map(({ value }) => ({ name: value }));
182
- };
183
- /**
184
- * Generate custom HTML datasets for VS Code
185
- * @param jsonDocs - Stencil JSON doc
186
- * @param storybookBaseUrl - Storybook Base Url
187
- * @returns custom HTML datasets
188
- * @example
189
- * ```ts
190
- * const customDataJson = vsCodeGenerator(jsonDocs, 'https://storybook.example.com', 'https://sources.example.com');
191
- * ```
192
- */
193
- const vsCodeGenerator = (jsonDocs, storybookBaseUrl, sourceBaseUrl) => ({
194
- version: 1.1,
195
- tags: jsonDocs.components.map((component) => {
196
- const references = getReferences(storybookBaseUrl, sourceBaseUrl, component.filePath);
197
- return {
198
- name: component.tag,
199
- description: getElementDescription(component),
200
- attributes: component.props
201
- .filter((prop) => prop.attr !== undefined)
202
- .map((prop) => ({
203
- name: prop.attr,
204
- description: getAttributeDescription(prop),
205
- values: getValues(prop),
206
- references,
207
- })),
208
- references,
209
- };
210
- }),
211
- globalAttributes: [],
212
- valueSets: [],
213
- });
214
- /**
215
- * Generate custom CSS datasets for VS Code
216
- * @param jsonDocs - Stencil JSON doc
217
- * @returns custom CSS datasets
218
- * @example
219
- * ```ts
220
- * const customDataJson = vsCodeCssGenerator(jsonDocs);
221
- * ```
222
- */
223
- const vsCodeCssGenerator = (jsonDocs) => ({
224
- version: 1.1,
225
- properties: jsonDocs.components.flatMap((component) => component.styles.map((style) => ({
226
- name: style.name,
227
- description: style.docs,
228
- }))),
229
- });
11
+ const VOID_ELEMENTS = [
12
+ 'area', 'base', 'br', 'col', 'embed', 'hr',
13
+ 'img', 'input', 'link', 'meta',
14
+ 'param', 'source', 'track', 'wbr'
15
+ ];
230
16
 
231
- /**
232
- * Convert a Stencil component's JsonDocs into a CEM v2 module entry.
233
- * @param component - Stencil component doc
234
- * @returns CEM module
235
- */
236
- const componentToModule = (component) => {
237
- const className = component.tag
238
- .split('-')
239
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
240
- .join('');
241
- const attributes = component.props
242
- .filter((prop) => prop.attr !== undefined)
243
- .map((prop) => ({
244
- name: prop.attr,
245
- description: prop.docs,
246
- type: { text: prop.type },
247
- ...(prop.default !== undefined && { default: prop.default }),
248
- fieldName: prop.name,
249
- }));
250
- const fieldMembers = component.props.map((prop) => ({
251
- kind: 'field',
252
- name: prop.name,
253
- description: prop.docs,
254
- type: { text: prop.type },
255
- ...(prop.default !== undefined && { default: prop.default }),
256
- ...(prop.attr !== undefined && { attribute: prop.attr }),
257
- }));
258
- const methodMembers = component.methods.map((method) => ({
259
- kind: 'method',
260
- name: method.name,
261
- description: method.docs,
262
- }));
263
- return {
264
- kind: 'javascript-module',
265
- path: component.filePath ?? '',
266
- declarations: [
267
- {
268
- kind: 'class',
269
- name: className,
270
- tagName: component.tag,
271
- customElement: true,
272
- description: component.overview ?? '',
273
- attributes,
274
- members: [...fieldMembers, ...methodMembers],
275
- events: component.events.map((event) => ({
276
- name: event.event,
277
- description: event.docs,
278
- type: { text: `CustomEvent<${event.detail}>` },
279
- })),
280
- slots: component.slots.map((slot) => ({
281
- name: slot.name,
282
- description: slot.docs,
283
- })),
284
- cssProperties: component.styles.map((style) => ({
285
- name: style.name,
286
- description: style.docs,
287
- })),
288
- cssParts: component.parts.map((part) => ({
289
- name: part.name,
290
- description: part.docs,
291
- })),
292
- },
293
- ],
294
- exports: [
295
- {
296
- kind: 'custom-element-definition',
297
- name: component.tag,
298
- declaration: {
299
- name: className,
300
- module: component.filePath ?? '',
301
- },
302
- },
303
- ],
304
- };
305
- };
306
- /**
307
- * Generate a Custom Elements Manifest v2 from Stencil JSON docs.
308
- * @param jsonDocs - Stencil JSON doc
309
- * @returns CEM v2
310
- * @example
311
- * ```ts
312
- * const cem = cemGenerator(jsonDocs);
313
- * ```
314
- */
315
- const cemGenerator = (jsonDocs) => ({
316
- schemaVersion: '2.0.0',
317
- readme: '',
318
- modules: jsonDocs.components.map(componentToModule),
319
- });
17
+ /**
18
+ * Defined per formatting operation from configuration.
19
+ *
20
+ * CONTENT_IGNORE_PLACEHOLDER
21
+ * SELF_CLOSING_PLACEHOLDER
22
+ * ATTRIBUTE_IGNORE_PLACEHOLDER
23
+ */
320
24
 
321
- /**
322
- * Per the HTML spec, a boolean attribute is `true` whenever it is present on the
323
- * element, regardless of its value (including `="false"`). Stencil's default Prop
324
- * parser converts the string `"false"` to the boolean `false`, which breaks this
325
- * contract for consumers writing markup. Call this helper from `componentWillLoad`
326
- * to re-normalize every present attribute that maps to a boolean-typed Prop.
327
- *
328
- * Iterates the host element's attributes and, for each one whose camelCase name
329
- * matches a `typeof === 'boolean'` Prop on the instance, rewrites the attribute
330
- * to `''` — Stencil's parser then turns that into `true` via the standard
331
- * attribute → prop pipeline (no need for `mutable: true` on the Prop, since the
332
- * write goes through Stencil's internal setter, not through user code).
333
- *
334
- * Non-boolean Props and non-Prop attributes (`class`, `id`, ...) are skipped
335
- * naturally by the type check.
336
- *
337
- * @param target - the component instance (must expose `element` via `@Element()`)
338
- *
339
- * @example
340
- * ```typescript
341
- * @Component({ tag: 'my-input' })
342
- * export class MyInput {
343
- * @Element() element: HTMLMyInputElement;
344
- * @Prop() readonly = false;
345
- * @Prop() disabled = false;
346
- *
347
- * componentWillLoad() {
348
- * normalizeBooleanAttributes(this);
349
- * }
350
- * }
351
- * ```
352
- */
353
- const normalizeBooleanAttributes = (target) => {
354
- for (const attr of Array.from(target.element.attributes)) {
355
- const propName = attr.name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
356
- if (typeof target[propName] === 'boolean') {
357
- target.element.setAttribute(attr.name, '');
358
- }
359
- }
360
- };
25
+ new Set(VOID_ELEMENTS);
361
26
 
362
- exports.cemGenerator = cemGenerator;
363
- exports.normalizeBooleanAttributes = normalizeBooleanAttributes;
364
- exports.vsCodeCssGenerator = vsCodeCssGenerator;
365
- exports.vsCodeGenerator = vsCodeGenerator;
366
- exports.webTypesGenerator = webTypesGenerator;
27
+ /**
28
+ * Retrieve Component Storybook URL from file path
29
+ * @param storybookBaseUrl - Storybook Base URL
30
+ * @param filePath - Component file path
31
+ * @returns Component Storybook URL
32
+ */
33
+ const getStorybookUrl = (storybookBaseUrl, filePath) => {
34
+ if (!filePath) {
35
+ return;
36
+ }
37
+ const split = filePath.split('/');
38
+ return `${storybookBaseUrl}${split.slice(2, split.length - 1).join('-')}--docs`;
39
+ };
40
+
41
+ /**
42
+ * Retrieve Component source URL from file path
43
+ * @param sourcesBaseUrl - Source base URL
44
+ * @param filePath - Component file path
45
+ * @returns Component source URL
46
+ */
47
+ const getSourcesUrl = (sourcesBaseUrl, filePath) => {
48
+ if (!filePath) {
49
+ return;
50
+ }
51
+ return `${sourcesBaseUrl}${filePath}`;
52
+ };
53
+ /**
54
+ * Get Component element description.
55
+ *
56
+ * Neither WebStorm nor VS Code render the structured `attributes` /
57
+ * `js.properties` arrays in the tag-level quick-doc — they only show this
58
+ * markdown description. So the attribute and property listings have to live
59
+ * here, even though they're redundant with the structured arrays used by the
60
+ * inline autocomplete.
61
+ * @param component - Component
62
+ * @returns Component element description
63
+ */
64
+ const getElementDescription = (component) => {
65
+ let description = component.overview ? `${component.overview}\n\n` : '';
66
+ const attributes = component.props.filter(({ attr }) => attr !== undefined);
67
+ if (attributes.length) {
68
+ description += `Attributes:\n`;
69
+ description += attributes.map(({ attr, docs }) => `- \`${attr}\`: ${docs}\n`).join('');
70
+ description += '\n';
71
+ }
72
+ const properties = component.props.filter(({ attr }) => attr === undefined);
73
+ if (properties.length) {
74
+ description += `Properties:\n`;
75
+ description += properties.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
76
+ description += '\n';
77
+ }
78
+ if (component.methods.length) {
79
+ description += `Methods:\n`;
80
+ description += component.methods.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
81
+ description += '\n';
82
+ }
83
+ if (component.events.length) {
84
+ description += `Events:\n`;
85
+ description += component.events.map(({ event, docs }) => `- \`${event}\`: ${docs}\n`).join('');
86
+ description += '\n';
87
+ }
88
+ if (component.listeners.length) {
89
+ description += `Listeners:\n`;
90
+ description += component.listeners.map(({ event }) => `- \`${event}\`\n`).join('');
91
+ description += '\n';
92
+ }
93
+ if (component.slots.length) {
94
+ description += `Slots:\n`;
95
+ description += component.slots
96
+ .map(({ name, docs }) => {
97
+ const label = name ? `\`${name}\`` : 'default';
98
+ return `- ${label}: ${docs}\n`;
99
+ })
100
+ .join('');
101
+ description += '\n';
102
+ }
103
+ return description;
104
+ };
105
+ /**
106
+ * Get Props Description
107
+ * @param prop - Component Property
108
+ * @returns Props Description
109
+ */
110
+ const getAttributeDescription = (prop) => {
111
+ return `${prop.docs}\n\nType: \`${prop.type}\``;
112
+ };
113
+ /**
114
+ * Generate Web Types metadata for IntelliJ's IDE
115
+ * @param name - Library name
116
+ * @param version - Library version
117
+ * @param jsonDocs - Stencil JSON doc
118
+ * @param storybookBaseUrl - Storybook Base Url
119
+ * @returns Web Types metadata
120
+ * @example
121
+ * ```ts
122
+ * const webTypesJson = webTypesGenerator('@mgdis/mg-components', '1.0.0', jsonDocs, 'https://storybook.example.com');
123
+ * ```
124
+ */
125
+ const webTypesGenerator = (name, version, jsonDocs, storybookBaseUrl) => ({
126
+ $schema: 'https://json.schemastore.org/web-types',
127
+ name,
128
+ version,
129
+ 'description-markup': 'markdown',
130
+ contributions: {
131
+ html: {
132
+ elements: jsonDocs.components.map((component) => {
133
+ const docUrl = getStorybookUrl(storybookBaseUrl, component.filePath);
134
+ return {
135
+ name: component.tag,
136
+ description: getElementDescription(component),
137
+ 'doc-url': docUrl,
138
+ attributes: component.props
139
+ .filter((prop) => prop.attr)
140
+ .map((prop) => ({
141
+ name: prop.attr,
142
+ description: getAttributeDescription(prop),
143
+ 'doc-url': docUrl,
144
+ value: {
145
+ type: prop.type,
146
+ default: prop.default,
147
+ required: prop.required,
148
+ },
149
+ })),
150
+ js: {
151
+ properties: component.props
152
+ .filter((prop) => prop.attr === undefined)
153
+ .map((prop) => ({
154
+ name: prop.name,
155
+ description: getAttributeDescription(prop),
156
+ 'doc-url': docUrl,
157
+ value: {
158
+ type: prop.type,
159
+ default: prop.default,
160
+ required: prop.required,
161
+ },
162
+ })),
163
+ events: component.events.map((event) => ({
164
+ name: event.event,
165
+ description: event.docs,
166
+ })),
167
+ },
168
+ css: {
169
+ properties: component.styles.map((style) => ({
170
+ name: style.name,
171
+ description: style.docs,
172
+ })),
173
+ },
174
+ };
175
+ }),
176
+ },
177
+ },
178
+ });
179
+ /**
180
+ * Create Storybook Reference
181
+ * @param storybookBaseUrl - Storybook Base Url
182
+ * @param filePath - Component file path
183
+ * @returns Storybook Reference
184
+ */
185
+ const getReferences = (storybookBaseUrl, sourceBaseUrl, filePath) => {
186
+ return [
187
+ { name: 'Storybook', url: getStorybookUrl(storybookBaseUrl, filePath) },
188
+ { name: 'Sources', url: getSourcesUrl(sourceBaseUrl, filePath) },
189
+ ];
190
+ };
191
+ /**
192
+ * Get Property possible values
193
+ * @param prop - Component Property
194
+ * @returns Property possible values
195
+ */
196
+ const getValues = (prop) => {
197
+ // Only values Array where all objects have a value seems to be usefull
198
+ if (prop.values.some(({ value }) => value === undefined)) {
199
+ return;
200
+ }
201
+ return prop.values.map(({ value }) => ({ name: value }));
202
+ };
203
+ /**
204
+ * Generate custom HTML datasets for VS Code
205
+ * @param jsonDocs - Stencil JSON doc
206
+ * @param storybookBaseUrl - Storybook Base Url
207
+ * @returns custom HTML datasets
208
+ * @example
209
+ * ```ts
210
+ * const customDataJson = vsCodeGenerator(jsonDocs, 'https://storybook.example.com', 'https://sources.example.com');
211
+ * ```
212
+ */
213
+ const vsCodeGenerator = (jsonDocs, storybookBaseUrl, sourceBaseUrl) => ({
214
+ version: 1.1,
215
+ tags: jsonDocs.components.map((component) => {
216
+ const references = getReferences(storybookBaseUrl, sourceBaseUrl, component.filePath);
217
+ return {
218
+ name: component.tag,
219
+ description: getElementDescription(component),
220
+ attributes: component.props
221
+ .filter((prop) => prop.attr !== undefined)
222
+ .map((prop) => ({
223
+ name: prop.attr,
224
+ description: getAttributeDescription(prop),
225
+ values: getValues(prop),
226
+ references,
227
+ })),
228
+ references,
229
+ };
230
+ }),
231
+ globalAttributes: [],
232
+ valueSets: [],
233
+ });
234
+ /**
235
+ * Generate custom CSS datasets for VS Code
236
+ * @param jsonDocs - Stencil JSON doc
237
+ * @returns custom CSS datasets
238
+ * @example
239
+ * ```ts
240
+ * const customDataJson = vsCodeCssGenerator(jsonDocs);
241
+ * ```
242
+ */
243
+ const vsCodeCssGenerator = (jsonDocs) => ({
244
+ version: 1.1,
245
+ properties: jsonDocs.components.flatMap((component) => component.styles.map((style) => ({
246
+ name: style.name,
247
+ description: style.docs,
248
+ }))),
249
+ });
250
+
251
+ /**
252
+ * Convert a Stencil component's JsonDocs into a CEM v2 module entry.
253
+ * @param component - Stencil component doc
254
+ * @returns CEM module
255
+ */
256
+ const componentToModule = (component) => {
257
+ const className = component.tag
258
+ .split('-')
259
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
260
+ .join('');
261
+ const attributes = component.props
262
+ .filter((prop) => prop.attr !== undefined)
263
+ .map((prop) => ({
264
+ name: prop.attr,
265
+ description: prop.docs,
266
+ type: { text: prop.type },
267
+ ...(prop.default !== undefined && { default: prop.default }),
268
+ fieldName: prop.name,
269
+ }));
270
+ const fieldMembers = component.props.map((prop) => ({
271
+ kind: 'field',
272
+ name: prop.name,
273
+ description: prop.docs,
274
+ type: { text: prop.type },
275
+ ...(prop.default !== undefined && { default: prop.default }),
276
+ ...(prop.attr !== undefined && { attribute: prop.attr }),
277
+ }));
278
+ const methodMembers = component.methods.map((method) => ({
279
+ kind: 'method',
280
+ name: method.name,
281
+ description: method.docs,
282
+ }));
283
+ return {
284
+ kind: 'javascript-module',
285
+ path: component.filePath ?? '',
286
+ declarations: [
287
+ {
288
+ kind: 'class',
289
+ name: className,
290
+ tagName: component.tag,
291
+ customElement: true,
292
+ description: component.overview ?? '',
293
+ attributes,
294
+ members: [...fieldMembers, ...methodMembers],
295
+ events: component.events.map((event) => ({
296
+ name: event.event,
297
+ description: event.docs,
298
+ type: { text: `CustomEvent<${event.detail}>` },
299
+ })),
300
+ slots: component.slots.map((slot) => ({
301
+ name: slot.name,
302
+ description: slot.docs,
303
+ })),
304
+ cssProperties: component.styles.map((style) => ({
305
+ name: style.name,
306
+ description: style.docs,
307
+ })),
308
+ cssParts: component.parts.map((part) => ({
309
+ name: part.name,
310
+ description: part.docs,
311
+ })),
312
+ },
313
+ ],
314
+ exports: [
315
+ {
316
+ kind: 'custom-element-definition',
317
+ name: component.tag,
318
+ declaration: {
319
+ name: className,
320
+ module: component.filePath ?? '',
321
+ },
322
+ },
323
+ ],
324
+ };
325
+ };
326
+ /**
327
+ * Generate a Custom Elements Manifest v2 from Stencil JSON docs.
328
+ * @param jsonDocs - Stencil JSON doc
329
+ * @returns CEM v2
330
+ * @example
331
+ * ```ts
332
+ * const cem = cemGenerator(jsonDocs);
333
+ * ```
334
+ */
335
+ const cemGenerator = (jsonDocs) => ({
336
+ schemaVersion: '2.0.0',
337
+ readme: '',
338
+ modules: jsonDocs.components.map(componentToModule),
339
+ });
340
+
341
+ /**
342
+ * Per the HTML spec, a boolean attribute is `true` whenever it is present on the
343
+ * element, regardless of its value (including `="false"`). Stencil's default Prop
344
+ * parser converts the string `"false"` to the boolean `false`, which breaks this
345
+ * contract for consumers writing markup. Call this helper from `componentWillLoad`
346
+ * to re-normalize every present attribute that maps to a boolean-typed Prop.
347
+ *
348
+ * Iterates the host element's attributes and, for each one whose camelCase name
349
+ * matches a `typeof === 'boolean'` Prop on the instance, rewrites the attribute
350
+ * to `''` — Stencil's parser then turns that into `true` via the standard
351
+ * attribute → prop pipeline (no need for `mutable: true` on the Prop, since the
352
+ * write goes through Stencil's internal setter, not through user code).
353
+ *
354
+ * Non-boolean Props and non-Prop attributes (`class`, `id`, ...) are skipped
355
+ * naturally by the type check.
356
+ *
357
+ * @param target - the component instance (must expose `element` via `@Element()`)
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * @Component({ tag: 'my-input' })
362
+ * export class MyInput {
363
+ * @Element() element: HTMLMyInputElement;
364
+ * @Prop() readonly = false;
365
+ * @Prop() disabled = false;
366
+ *
367
+ * componentWillLoad() {
368
+ * normalizeBooleanAttributes(this);
369
+ * }
370
+ * }
371
+ * ```
372
+ */
373
+ const normalizeBooleanAttributes = (target) => {
374
+ for (const attr of Array.from(target.element.attributes)) {
375
+ const propName = attr.name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
376
+ if (typeof target[propName] === 'boolean') {
377
+ target.element.setAttribute(attr.name, '');
378
+ }
379
+ }
380
+ };
381
+
382
+ exports.cemGenerator = cemGenerator;
383
+ exports.normalizeBooleanAttributes = normalizeBooleanAttributes;
384
+ exports.vsCodeCssGenerator = vsCodeCssGenerator;
385
+ exports.vsCodeGenerator = vsCodeGenerator;
386
+ exports.webTypesGenerator = webTypesGenerator;
367
387
 
368
388
  }));
369
389
  //# sourceMappingURL=index.umd.js.map