@italia/rating 1.0.0-alpha.11 → 1.0.0-alpha.13

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.
@@ -5,19 +5,6 @@ import { ItRadio } from '@italia/radio';
5
5
  import '@italia/icon';
6
6
 
7
7
  var styles = css`@charset "UTF-8";
8
- /***************************** 1 ****************************************/
9
- /***************************** 2 ****************************************/
10
- /***************************** 1 ****************************************/
11
- /***************************** 2 ****************************************/
12
- /***************************** 1 ****************************************/
13
- /***************************** 2 ****************************************/
14
- /***************************** 3 ****************************************/
15
- /***************************** 1 ****************************************/
16
- /***************************** 2 ****************************************/
17
- /***************************** 3 ****************************************/
18
- /***************************** NEUTRAL 1 ****************************************/
19
- /***************************** NEUTRAL 2 ****************************************/
20
- /***************************** NEUTRAL 2 / 3 ****************************************/
21
8
  *,
22
9
  *::before,
23
10
  *::after {
@@ -1 +1 @@
1
- {"version":3,"file":"it-rating-item.js","sources":["../../../src/it-rating-item.ts"],"sourcesContent":["import { html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { ItRadio } from '@italia/radio';\nimport '@italia/icon';\n\nimport styles from './rating-item.scss';\n\n/**\n * Rating item component - extends it-radio to render a star icon\n *\n * @element it-rating-item\n *\n * @slot label - The accessibility label for the star (e.g., \"Valuta 3 stelle su 5\")\n */\n@customElement('it-rating-item')\nexport class ItRatingItem extends ItRadio {\n static override styles = styles;\n\n /**\n * Override group getter to find parent it-rating instead of it-radio-group\n */\n override get group() {\n return this.closest('it-rating');\n }\n\n get icon(): string {\n return this.group?.icon || 'it-star-outline';\n }\n\n /**\n * Override _renderInput to render icon instead of radio circle\n * Now that _renderInput is protected in parent, we can override it\n */\n protected override _renderInput() {\n // Get the parent rating to determine which items should be filled\n const rating = this.closest('it-rating');\n const ratingValue = rating ? parseInt((rating as any).value || '0', 10) : 0;\n const thisValue = parseInt(this.value || '0', 10);\n\n // Icon should be filled if its value is <= the rating value\n const isFilled = thisValue <= ratingValue;\n\n // Use primary color only for filled icons\n const iconColor = isFilled ? 'primary' : 'secondary';\n let renderedIcon = this.icon;\n if (isFilled && this.icon === 'it-star-outline') {\n renderedIcon = 'it-star-full';\n }\n\n return html`\n <div id=\"input\" part=\"input\"></div>\n <it-icon id=\"star\" part=\"star\" name=\"${renderedIcon}\" size=\"sm\" aria-hidden=\"true\" color=\"${iconColor}\"></it-icon>\n `;\n }\n\n private handleSlotChange() {\n // Notify assistive technologies of label change\n this.labelElements.forEach((el) => {\n el.classList.add('visually-hidden');\n });\n }\n\n /**\n * Override render to use rating-specific structure\n */\n override render() {\n return html`\n <div class=\"rating-item-control\">\n ${this._renderInput()}\n <slot name=\"label\" @slotchange=${this.handleSlotChange}></slot>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'it-rating-item': ItRatingItem;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;AAMG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,OAAO,CAAA;AAGvC;;AAEG;AACH,IAAA,IAAa,KAAK,GAAA;AAChB,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;IAClC;AAEA,IAAA,IAAI,IAAI,GAAA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["import { html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { ItRadio } from '@italia/radio';\nimport '@italia/icon';\n\nimport styles from './rating-item.scss';\n\n/**\n * Rating item component - extends it-radio to render a star icon\n *\n * @element it-rating-item\n *\n * @slot label - The accessibility label for the star (e.g., \"Valuta 3 stelle su 5\")\n */\n@customElement('it-rating-item')\nexport class ItRatingItem extends ItRadio {\n static override styles = styles;\n\n /**\n * Override group getter to find parent it-rating instead of it-radio-group\n */\n override get group() {\n return this.closest('it-rating');\n }\n\n get icon(): string {\n return this.group?.icon || 'it-star-outline';\n }\n\n /**\n * Override _renderInput to render icon instead of radio circle\n * Now that _renderInput is protected in parent, we can override it\n */\n protected override _renderInput() {\n // Get the parent rating to determine which items should be filled\n const rating = this.closest('it-rating');\n const ratingValue = rating ? parseInt((rating as any).value || '0', 10) : 0;\n const thisValue = parseInt(this.value || '0', 10);\n\n // Icon should be filled if its value is <= the rating value\n const isFilled = thisValue <= ratingValue;\n\n // Use primary color only for filled icons\n const iconColor = isFilled ? 'primary' : 'secondary';\n let renderedIcon = this.icon;\n if (isFilled && this.icon === 'it-star-outline') {\n renderedIcon = 'it-star-full';\n }\n\n return html`\n <div id=\"input\" part=\"input\"></div>\n <it-icon id=\"star\" part=\"star\" name=\"${renderedIcon}\" size=\"sm\" aria-hidden=\"true\" color=\"${iconColor}\"></it-icon>\n `;\n }\n\n private handleSlotChange() {\n // Notify assistive technologies of label change\n this.labelElements.forEach((el) => {\n el.classList.add('visually-hidden');\n });\n }\n\n /**\n * Override render to use rating-specific structure\n */\n override render() {\n return html`\n <div class=\"rating-item-control\">\n ${this._renderInput()}\n <slot name=\"label\" @slotchange=${this.handleSlotChange}></slot>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'it-rating-item': ItRatingItem;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;AAE8B,2CAAA,EAAA,YAAY,yCAAyC,SAAS,CAAA;KACtG;IACH;IAEQ,gBAAgB,GAAA;;QAEtB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;AAChC,YAAA,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC;AACrC,QAAA,CAAC,CAAC;IACJ;AAEA;;AAEG;IACM,MAAM,GAAA;AACb,QAAA,OAAO,IAAI,CAAA;;UAEL,IAAI,CAAC,YAAY,EAAE;AACY,uCAAA,EAAA,IAAI,CAAC,gBAAgB,CAAA;;KAEzD;IACH;;AAxDgB,YAAA,CAAA,MAAM,GAAG,MAAH;AADX,YAAY,GAAA,UAAA,CAAA;IADxB,aAAa,CAAC,gBAAgB;AAClB,CAAA,EAAA,YAAY,CA0DxB;;;;"}
@@ -13,20 +13,7 @@ const translation = {
13
13
  ratingLabelPlural: (rating, max) => `${rating} stelle su ${max}`,
14
14
  };
15
15
 
16
- var styles = css`/***************************** 1 ****************************************/
17
- /***************************** 2 ****************************************/
18
- /***************************** 1 ****************************************/
19
- /***************************** 2 ****************************************/
20
- /***************************** 1 ****************************************/
21
- /***************************** 2 ****************************************/
22
- /***************************** 3 ****************************************/
23
- /***************************** 1 ****************************************/
24
- /***************************** 2 ****************************************/
25
- /***************************** 3 ****************************************/
26
- /***************************** NEUTRAL 1 ****************************************/
27
- /***************************** NEUTRAL 2 ****************************************/
28
- /***************************** NEUTRAL 2 / 3 ****************************************/
29
- *,
16
+ var styles = css`*,
30
17
  *::before,
31
18
  *::after {
32
19
  box-sizing: border-box;
@@ -1 +1 @@
1
- {"version":3,"file":"it-rating.js","sources":["../../../src/locales/it.ts","../../../src/it-rating.ts"],"sourcesContent":["import type { DefaultTranslation } from '@italia/i18n';\n\nconst translation: DefaultTranslation = {\n $code: 'it',\n $name: 'Italiano',\n $dir: 'ltr',\n\n noRating: 'Nessuna valutazione',\n ratingLabelSingle: (rating: number, max: number) => `${rating} stella su ${max}`,\n ratingLabelPlural: (rating: number, max: number) => `${rating} stelle su ${max}`,\n};\n\nexport default translation;\n","import { type PropertyValues } from 'lit';\nimport { customElement, property, queryAssignedElements } from 'lit/decorators.js';\nimport { ItRadioGroup } from '@italia/radio'; // eslint-disable-line import/no-extraneous-dependencies\nimport { registerTranslation } from '@italia/i18n';\nimport { type ItRatingItem } from '@italia/rating';\nimport it from './locales/it.js';\n\nimport styles from './rating.scss';\n\nregisterTranslation(it);\n\n/**\n * Rating component - extends it-radio-group for star rating\n *\n * @element it-rating\n *\n * @slot - Contains the `<it-rating-item>` elements\n * @slot label - The label/legend text for the rating\n *\n * @fires {CustomEvent} change - Emitted when the rating value changes\n */\n@customElement('it-rating')\nexport class ItRating extends ItRadioGroup {\n static override styles = styles;\n\n /**\n * Get all slotted rating items\n */\n @queryAssignedElements()\n protected _radios!: ItRatingItem[];\n\n /**\n * Maximum number of stars (to calculate \"X out of Y\")\n */\n @property({ type: Number, attribute: 'max-elements', reflect: true })\n maxElements = 5;\n\n /**\n * Whether the rating is read-only (non-interactive)\n */\n @property({ type: Boolean, reflect: true, attribute: 'read-only' })\n readOnly = false;\n\n /**\n * The icon name to use for the rating item\n * @default 'it-star-outline'\n */\n @property({ type: String, reflect: true })\n icon = 'it-star-outline';\n\n /**\n * Sync read-only state to all rating items\n */\n private _syncReadOnlyToItems() {\n const items = this.querySelectorAll('it-rating-item');\n items.forEach((item) => {\n if (this.readOnly) {\n item.setAttribute('disabled', '');\n } else {\n item.removeAttribute('disabled');\n }\n });\n }\n\n /**\n * Get the localized rating announcement for screen readers\n */\n private _getRatingAnnouncement(): string {\n const currentValue = parseInt(this.value || '0', 10);\n\n if (!currentValue || currentValue === 0) {\n return this.localize.term('noRating');\n }\n // Use singular or plural form based on rating value\n const termKey = currentValue === 1 ? 'ratingLabelSingle' : 'ratingLabelPlural';\n\n // Pass parameters directly to the translation function\n return this.localize.term(termKey, currentValue, this.maxElements);\n }\n\n /**\n * Override updated to refresh the rating items and announcement when value changes\n */\n override updated(changedProperties: PropertyValues) {\n super.updated(changedProperties);\n\n // Sync disabled state to all rating items when readOnly changes\n if (changedProperties.has('readOnly')) {\n this._syncReadOnlyToItems();\n }\n\n // Update aria-readonly attribute\n if (this.readOnly) {\n this.setAttribute('aria-readonly', 'true');\n } else {\n this.removeAttribute('aria-readonly');\n }\n\n // When value changes, force re-render of all rating items AND update their display\n if (changedProperties.has('value')) {\n this._updateRadiosState();\n this._updateRatingItemsDisplay();\n this._ensureAnnouncement();\n }\n if (changedProperties.has('icon')) {\n this._updateRatingItemsDisplay();\n }\n\n // When maxElements changes, update the announcement\n if (changedProperties.has('maxElements')) {\n this._ensureAnnouncement();\n }\n }\n\n /**\n * Force re-render of all rating items to update star colors\n * This ensures star colors reflect the current value\n */\n private _updateRatingItemsDisplay() {\n const items = this.querySelectorAll('it-rating-item');\n items.forEach((item) => {\n item.requestUpdate();\n });\n }\n\n /**\n * Create or update the visually-hidden announcement element\n * Following BSI pattern: announcement placed directly in the label slot\n */\n private _ensureAnnouncement() {\n // Find the label slot elements (assigned nodes)\n const labelSlot = this.shadowRoot?.querySelector('slot[name=\"label\"]') as HTMLSlotElement;\n if (!labelSlot) return;\n\n // Get the first element in the label slot (the legend/label container)\n const labelElements = labelSlot.assignedElements();\n if (labelElements.length === 0) return;\n\n const labelContainer = labelElements[0];\n\n // Look for existing announcement span\n let announcement = labelContainer.querySelector('.rating-announcement') as HTMLElement;\n\n if (!announcement) {\n // Create the announcement element if it doesn't exist\n announcement = document.createElement('span');\n announcement.className = 'visually-hidden rating-announcement';\n\n // Append to the label container\n labelContainer.appendChild(announcement);\n }\n // Update the text content\n announcement.textContent = ` ${this._getRatingAnnouncement()}`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'it-rating': ItRating;\n }\n}\n"],"names":["it"],"mappings":";;;;;;AAEA,MAAM,WAAW,GAAuB;AACtC,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,KAAK,EAAE,UAAU;AACjB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A,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AACrD,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAMhB,UAAA,CAAA;AADC,IAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;;AAClD,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAOjB,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AACjB,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AA1Bd,QAAQ,GAAA,UAAA,CAAA;IADpB,aAAa,CAAC,WAAW;AACb,CAAA,EAAA,QAAQ,CAoIpB;;;;"}
1
+ {"version":3,"file":"it-rating.js","sources":["../../../src/locales/it.ts","../../../src/it-rating.ts"],"sourcesContent":["import type { DefaultTranslation } from '@italia/i18n';\n\nconst translation: DefaultTranslation = {\n $code: 'it',\n $name: 'Italiano',\n $dir: 'ltr',\n\n noRating: 'Nessuna valutazione',\n ratingLabelSingle: (rating: number, max: number) => `${rating} stella su ${max}`,\n ratingLabelPlural: (rating: number, max: number) => `${rating} stelle su ${max}`,\n};\n\nexport default translation;\n","import { type PropertyValues } from 'lit';\nimport { customElement, property, queryAssignedElements } from 'lit/decorators.js';\nimport { ItRadioGroup } from '@italia/radio'; // eslint-disable-line import/no-extraneous-dependencies\nimport { registerTranslation } from '@italia/i18n';\nimport { type ItRatingItem } from '@italia/rating';\nimport it from './locales/it.js';\n\nimport styles from './rating.scss';\n\nregisterTranslation(it);\n\n/**\n * Rating component - extends it-radio-group for star rating\n *\n * @element it-rating\n *\n * @slot - Contains the `<it-rating-item>` elements\n * @slot label - The label/legend text for the rating\n *\n * @fires {CustomEvent} change - Emitted when the rating value changes\n */\n@customElement('it-rating')\nexport class ItRating extends ItRadioGroup {\n static override styles = styles;\n\n /**\n * Get all slotted rating items\n */\n @queryAssignedElements()\n protected _radios!: ItRatingItem[];\n\n /**\n * Maximum number of stars (to calculate \"X out of Y\")\n */\n @property({ type: Number, attribute: 'max-elements', reflect: true })\n maxElements = 5;\n\n /**\n * Whether the rating is read-only (non-interactive)\n */\n @property({ type: Boolean, reflect: true, attribute: 'read-only' })\n readOnly = false;\n\n /**\n * The icon name to use for the rating item\n * @default 'it-star-outline'\n */\n @property({ type: String, reflect: true })\n icon = 'it-star-outline';\n\n /**\n * Sync read-only state to all rating items\n */\n private _syncReadOnlyToItems() {\n const items = this.querySelectorAll('it-rating-item');\n items.forEach((item) => {\n if (this.readOnly) {\n item.setAttribute('disabled', '');\n } else {\n item.removeAttribute('disabled');\n }\n });\n }\n\n /**\n * Get the localized rating announcement for screen readers\n */\n private _getRatingAnnouncement(): string {\n const currentValue = parseInt(this.value || '0', 10);\n\n if (!currentValue || currentValue === 0) {\n return this.localize.term('noRating');\n }\n // Use singular or plural form based on rating value\n const termKey = currentValue === 1 ? 'ratingLabelSingle' : 'ratingLabelPlural';\n\n // Pass parameters directly to the translation function\n return this.localize.term(termKey, currentValue, this.maxElements);\n }\n\n /**\n * Override updated to refresh the rating items and announcement when value changes\n */\n override updated(changedProperties: PropertyValues) {\n super.updated(changedProperties);\n\n // Sync disabled state to all rating items when readOnly changes\n if (changedProperties.has('readOnly')) {\n this._syncReadOnlyToItems();\n }\n\n // Update aria-readonly attribute\n if (this.readOnly) {\n this.setAttribute('aria-readonly', 'true');\n } else {\n this.removeAttribute('aria-readonly');\n }\n\n // When value changes, force re-render of all rating items AND update their display\n if (changedProperties.has('value')) {\n this._updateRadiosState();\n this._updateRatingItemsDisplay();\n this._ensureAnnouncement();\n }\n if (changedProperties.has('icon')) {\n this._updateRatingItemsDisplay();\n }\n\n // When maxElements changes, update the announcement\n if (changedProperties.has('maxElements')) {\n this._ensureAnnouncement();\n }\n }\n\n /**\n * Force re-render of all rating items to update star colors\n * This ensures star colors reflect the current value\n */\n private _updateRatingItemsDisplay() {\n const items = this.querySelectorAll('it-rating-item');\n items.forEach((item) => {\n item.requestUpdate();\n });\n }\n\n /**\n * Create or update the visually-hidden announcement element\n * Following BSI pattern: announcement placed directly in the label slot\n */\n private _ensureAnnouncement() {\n // Find the label slot elements (assigned nodes)\n const labelSlot = this.shadowRoot?.querySelector('slot[name=\"label\"]') as HTMLSlotElement;\n if (!labelSlot) return;\n\n // Get the first element in the label slot (the legend/label container)\n const labelElements = labelSlot.assignedElements();\n if (labelElements.length === 0) return;\n\n const labelContainer = labelElements[0];\n\n // Look for existing announcement span\n let announcement = labelContainer.querySelector('.rating-announcement') as HTMLElement;\n\n if (!announcement) {\n // Create the announcement element if it doesn't exist\n announcement = document.createElement('span');\n announcement.className = 'visually-hidden rating-announcement';\n\n // Append to the label container\n labelContainer.appendChild(announcement);\n }\n // Update the text content\n announcement.textContent = ` ${this._getRatingAnnouncement()}`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'it-rating': ItRating;\n }\n}\n"],"names":["it"],"mappings":";;;;;;AAEA,MAAM,WAAW,GAAuB;AACtC,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,KAAK,EAAE,UAAU;AACjB,IAAA,IAAI,EAAE,KAAK;AAEX,IAAA,QAAQ,EAAE,qBAAqB;AAC/B,IAAA,iBAAiB,EAAE,CAAC,MAAc,EAAE,GAAW,KAAK,CAAA,EAAG,MAAM,CAAA,WAAA,EAAc,GAAG,CAAA,CAAE;AAChF,IAAA,iBAAiB,EAAE,CAAC,MAAc,EAAE,GAAW,KAAK,CAAA,EAAG,MAAM,CAAA,WAAA,EAAc,GAAG,CAAA,CAAE;CACjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AACjB,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AA1Bd,QAAQ,GAAA,UAAA,CAAA;IADpB,aAAa,CAAC,WAAW;AACb,CAAA,EAAA,QAAQ,CAoIpB;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@italia/rating",
3
3
  "description": "Web component it-rating del Design system .italia",
4
- "version": "1.0.0-alpha.11",
4
+ "version": "1.0.0-alpha.13",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -34,12 +34,12 @@
34
34
  "custom-elements.json"
35
35
  ],
36
36
  "dependencies": {
37
- "bootstrap-italia": "3.0.0-alpha.9",
37
+ "bootstrap-italia": "3.0.0-beta.0",
38
38
  "lit": "^3.3.0",
39
- "@italia/globals": "^1.0.0-alpha.11",
40
- "@italia/i18n": "^1.0.0-alpha.11",
41
- "@italia/icon": "^1.0.0-alpha.11",
42
- "@italia/radio": "^1.0.0-alpha.11"
39
+ "@italia/globals": "^1.0.0-alpha.13",
40
+ "@italia/i18n": "^1.0.0-alpha.13",
41
+ "@italia/icon": "^1.0.0-alpha.13",
42
+ "@italia/radio": "^1.0.0-alpha.13"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@custom-elements-manifest/analyzer": "^0.10.3",
@@ -53,7 +53,7 @@
53
53
  "tslib": "^2.6.3",
54
54
  "typescript": "^5.5.3",
55
55
  "@italia/test-config": "^0.0.0",
56
- "@italia/input": "^1.0.0-alpha.11",
56
+ "@italia/input": "^1.0.0-alpha.13",
57
57
  "@italia/typescript-config": "^0.0.0"
58
58
  },
59
59
  "customElements": "custom-elements.json",