@redvars/peacock 3.5.0 → 3.5.1
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.
- package/dist/BaseButton-DuASuVth.js +219 -0
- package/dist/BaseButton-DuASuVth.js.map +1 -0
- package/dist/BaseHyperlinkMixin-BNuwbiEf.js +65 -0
- package/dist/BaseHyperlinkMixin-BNuwbiEf.js.map +1 -0
- package/dist/assets/components.css +1 -1
- package/dist/assets/components.css.map +1 -1
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/banner.js +12 -27
- package/dist/banner.js.map +1 -1
- package/dist/{button-DMN1dPAg.js → button-DouvOfEU.js} +77 -251
- package/dist/button-DouvOfEU.js.map +1 -0
- package/dist/{button-group-CX9CUUXk.js → button-group-CEdMwvJJ.js} +71 -42
- package/dist/button-group-CEdMwvJJ.js.map +1 -0
- package/dist/button-group.js +5 -5
- package/dist/button.js +3 -3
- package/dist/card.js +18 -73
- package/dist/card.js.map +1 -1
- package/dist/chart-bar.js.map +1 -1
- package/dist/chart-doughnut.js +2 -2
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-pie.js +2 -2
- package/dist/chart-pie.js.map +1 -1
- package/dist/chart-stacked-bar.js.map +1 -1
- package/dist/code-highlighter.js +2 -1
- package/dist/code-highlighter.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +3105 -1494
- package/dist/custom-elements.json +9244 -7829
- package/dist/fab.js +421 -9
- package/dist/fab.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/{select-4pl4XBj7.js → navigation-rail-Lxetd5-Z.js} +2214 -1090
- package/dist/navigation-rail-Lxetd5-Z.js.map +1 -0
- package/dist/notification.js +3 -2
- package/dist/notification.js.map +1 -1
- package/dist/peacock-loader.js +22 -10
- package/dist/peacock-loader.js.map +1 -1
- package/dist/search.js +4 -0
- package/dist/search.js.map +1 -1
- package/dist/src/__mixins/BaseButtonMixin.d.ts +20 -0
- package/dist/src/__mixins/BaseHyperlinkMixin.d.ts +18 -0
- package/dist/src/__mixins/MixinConstructor.d.ts +1 -0
- package/dist/src/banner/banner.d.ts +0 -4
- package/dist/src/button/BaseButton.d.ts +4 -47
- package/dist/src/button/button/button.d.ts +32 -3
- package/dist/src/button/button-group/button-group.d.ts +2 -2
- package/dist/src/button/icon-button/icon-button.d.ts +33 -8
- package/dist/src/card/card.d.ts +4 -15
- package/dist/src/fab/fab.d.ts +4 -35
- package/dist/src/focus-ring/focus-ring.d.ts +11 -5
- package/dist/src/index.d.ts +3 -1
- package/dist/src/link/link.d.ts +1 -1
- package/dist/src/navigation-rail/index.d.ts +2 -0
- package/dist/src/navigation-rail/navigation-rail-item.d.ts +55 -0
- package/dist/src/navigation-rail/navigation-rail.d.ts +71 -0
- package/dist/src/sidebar-menu/index.d.ts +3 -0
- package/dist/src/sidebar-menu/sidebar-menu-item.d.ts +58 -0
- package/dist/src/sidebar-menu/sidebar-menu.d.ts +38 -0
- package/dist/src/sidebar-menu/sidebar-sub-menu.d.ts +35 -0
- package/dist/src/toolbar/toolbar.d.ts +10 -10
- package/dist/src/tooltip/tooltip.d.ts +3 -0
- package/dist/src/url-field/index.d.ts +1 -0
- package/dist/src/url-field/url-field.d.ts +48 -0
- package/dist/test/sidebar-menu.test.d.ts +1 -0
- package/dist/toolbar.js +10 -10
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/readme.md +73 -65
- package/scss/mixin.scss +16 -0
- package/src/__mixins/BaseButtonMixin.ts +83 -0
- package/src/__mixins/BaseHyperlinkMixin.ts +68 -0
- package/src/__mixins/MixinConstructor.ts +1 -0
- package/src/{__base_element → __mixins}/README.md +2 -2
- package/src/banner/banner.scss +18 -22
- package/src/banner/banner.ts +1 -7
- package/src/button/BaseButton.ts +11 -100
- package/src/button/button/button-sizes.scss +4 -2
- package/src/button/button/button.ts +76 -23
- package/src/button/button-group/button-group.ts +2 -2
- package/src/button/icon-button/icon-button.ts +75 -33
- package/src/card/card.ts +11 -71
- package/src/chart-bar/chart-bar.ts +9 -14
- package/src/chart-bar/chart-stacked-bar.ts +12 -18
- package/src/chart-doughnut/chart-doughnut.ts +23 -27
- package/src/chart-pie/chart-pie.ts +19 -23
- package/src/checkbox/checkbox.scss +17 -34
- package/src/checkbox/checkbox.ts +3 -1
- package/src/code-highlighter/code-highlighter.scss +1 -0
- package/src/code-highlighter/code-highlighter.ts +1 -1
- package/src/date-picker/date-picker.ts +1 -1
- package/src/elevation/elevation.scss +5 -5
- package/src/fab/fab.ts +29 -100
- package/src/focus-ring/focus-ring.ts +47 -40
- package/src/index.ts +3 -1
- package/src/input/input.ts +3 -1
- package/src/link/link.ts +2 -2
- package/src/menu/menu-item/menu-item.ts +3 -1
- package/src/navigation-rail/index.ts +2 -0
- package/src/navigation-rail/navigation-rail-item.scss +216 -0
- package/src/navigation-rail/navigation-rail-item.ts +223 -0
- package/src/navigation-rail/navigation-rail.scss +72 -0
- package/src/navigation-rail/navigation-rail.ts +149 -0
- package/src/notification/notification.ts +3 -2
- package/src/number-field/number-field.ts +6 -4
- package/src/pagination/pagination.ts +6 -4
- package/src/peacock-loader.ts +22 -5
- package/src/search/search.ts +4 -0
- package/src/sidebar-menu/demo/index.html +68 -0
- package/src/sidebar-menu/index.ts +3 -0
- package/src/sidebar-menu/sidebar-menu-item.scss +102 -0
- package/src/sidebar-menu/sidebar-menu-item.ts +151 -0
- package/src/{tree-view/tree-view.scss → sidebar-menu/sidebar-menu.scss} +1 -1
- package/src/sidebar-menu/sidebar-menu.ts +182 -0
- package/src/sidebar-menu/sidebar-sub-menu.scss +130 -0
- package/src/sidebar-menu/sidebar-sub-menu.ts +160 -0
- package/src/skeleton/skeleton.scss +18 -24
- package/src/snackbar/snackbar.ts +1 -1
- package/src/tabs/tab.ts +4 -3
- package/src/text/text.css-component.scss +7 -1
- package/src/time-picker/time-picker.ts +1 -1
- package/src/toolbar/toolbar.ts +10 -10
- package/src/tooltip/tooltip.ts +24 -0
- package/src/url-field/index.ts +1 -0
- package/src/url-field/url-field.scss +50 -0
- package/src/url-field/url-field.ts +239 -0
- package/dist/button-DMN1dPAg.js.map +0 -1
- package/dist/button-group-CX9CUUXk.js.map +0 -1
- package/dist/fab-C5Nzxk0E.js +0 -497
- package/dist/fab-C5Nzxk0E.js.map +0 -1
- package/dist/select-4pl4XBj7.js.map +0 -1
- package/dist/spread-B5cgadZl.js +0 -32
- package/dist/spread-B5cgadZl.js.map +0 -1
- package/dist/src/__base_element/BaseHyperlink.d.ts +0 -20
- package/dist/src/tree-view/index.d.ts +0 -2
- package/dist/src/tree-view/tree-node.d.ts +0 -69
- package/dist/src/tree-view/tree-view.d.ts +0 -40
- package/dist/src/tree-view/wc-tree-view.d.ts +0 -6
- package/dist/test/tree-view.test.d.ts +0 -1
- package/dist/throttle-C7ZAPqtu.js +0 -24
- package/dist/throttle-C7ZAPqtu.js.map +0 -1
- package/src/__base_element/BaseHyperlink.ts +0 -42
- package/src/tree-view/demo/index.html +0 -57
- package/src/tree-view/index.ts +0 -2
- package/src/tree-view/tree-node.scss +0 -101
- package/src/tree-view/tree-node.ts +0 -268
- package/src/tree-view/tree-view.ts +0 -182
- package/src/tree-view/wc-tree-view.ts +0 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button-group-CEdMwvJJ.js","sources":["../../src/button/icon-button/icon-button.ts","../../src/button/button-group/button-group.ts"],"sourcesContent":["import { html } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport styles from '../button/button.scss';\nimport colorStyles from '../button/button-colors.scss';\nimport sizeStyles from './icon-button-sizes.scss';\nimport { spread } from '@/__directive/spread.js';\nimport { throttle } from '@/__utils/throttle.js';\nimport { BaseButton } from '../BaseButton.js';\n\n/**\n * @label Icon Button\n * @tag wc-icon-button\n * @rawTag icon-button\n *\n * @summary Icon buttons allow users to take actions, and make choices, with a single tap.\n *\n * @overview\n * <p>Icon buttons are clickable elements that are used to trigger actions. They communicate calls to action to the user and allow users to interact with pages in a variety of ways. IconButton labels express what action will occur when the user interacts with it.</p>\n *\n * @cssprop --button-container-shape: Defines the border radius of the button container shape.\n *\n * @cssprop --button-container-shape-start-start: Defines the start position of the button container shape.\n * @cssprop --button-container-shape-start-end: Defines the end position of the button container shape.\n * @cssprop --button-container-shape-end-start: Defines the start position of the button container shape.\n * @cssprop --button-container-shape-end-end: Defines the end position of the button container shape.\n *\n *\n * @cssprop --filled-button-container-color: Color of the filled button container.\n * @cssprop --filled-button-label-text-color: Text color of the filled button label.\n *\n * @cssprop --outlined-button-container-color: Color of the outlined button container.\n * @cssprop --outlined-button-label-text-color: Text color of the outlined button label.\n *\n * @cssprop --text-button-label-text-color: Text color of the text button label.\n *\n * @cssprop --tonal-button-container-color: Color of the tonal button container.\n * @cssprop --tonal-button-label-text-color: Text color of the tonal button label.\n *\n * @cssprop --elevated-button-container-color: Color of the elevated button container.\n * @cssprop --elevated-button-label-text-color: Text color of the elevated button label.\n *\n * @cssprop --neo-button-container-color: Color of the neo button container.\n * @cssprop --neo-button-label-text-color: Text color of the neo button label.\n *\n * @fires {CustomEvent} button:click - Dispatched when the button is clicked.\n *\n * @example\n * ```html\n * <wc-icon-button><wc-icon name=\"home\"></wc-icon></wc-icon-button>\n * ```\n * @tags display\n */\nexport class IconButton extends BaseButton {\n static override styles = [styles, colorStyles, sizeStyles];\n\n /**\n * Button size.\n * Possible values are `\"xs\"`, `\"sm\"`, `\"md\"`, `\"lg\"`, `\"xl\"`. Defaults to `\"sm\"`.\n */\n @property({ reflect: true }) size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'sm';\n\n /**\n * Type is preset of color and variant. Type will be only applied.\n *\n */\n @property({ type: String }) type?: 'primary' | 'secondary' | 'tertiary';\n \n /**\n * The visual style of the button.\n *\n * Possible variant values:\n * `\"filled\"` is a filled button.\n * `\"outlined\"` is an outlined button.\n * `\"text\"` is a transparent button.\n * `\"tonal\"` is a light color button.\n * `\"elevated\"` is elevated button\n */\n @property() variant:\n | 'elevated'\n | 'filled'\n | 'tonal'\n | 'outlined'\n | 'text'\n | 'neo' = 'filled';\n \n /**\n * Defines the primary color of the button. This can be set to predefined color names to apply specific color themes.\n */\n @property({ reflect: true }) color:\n | 'primary'\n | 'success'\n | 'danger'\n | 'warning'\n | 'surface'\n | 'on-surface' = 'primary';\n\n /**\n * Additional ARIA attributes to pass to the inner button/anchor element.\n */\n @property({ reflect: true })\n configAria?: { [key: string]: any };\n\n override focus() {\n this.buttonElement?.focus();\n }\n\n override blur() {\n this.buttonElement?.blur();\n }\n \n override firstUpdated() {\n this.__dispatchClickWithThrottle = throttle(\n this.__dispatchClick,\n this.throttleDelay,\n );\n this.__convertTypeToVariantAndColor();\n }\n\n __convertTypeToVariantAndColor() {\n if (this.type === 'primary') {\n this.color = 'primary';\n this.variant = 'filled';\n } else if (this.type === 'secondary') {\n this.color = 'surface';\n this.variant = 'filled';\n } else if (this.type === 'tertiary') {\n this.color = 'primary';\n this.variant = 'text';\n } else if (this.type === 'danger') {\n this.color = 'danger';\n this.variant = 'filled';\n }\n }\n\n override render() {\n const isLink = this.__isLink();\n\n const cssClasses = {\n button: true,\n 'button-element': true,\n [`size-${this.size}`]: true,\n [`variant-${this.variant}`]: true,\n [`color-${this.color}`]: true,\n disabled: this.disabled || this.softDisabled,\n pressed: this.isPressed,\n skeleton: this.skeleton,\n };\n\n if (!isLink) {\n return html`<button\n class=${classMap(cssClasses)}\n id=\"button\"\n type=${this.htmlType}\n @click=${this.__dispatchClickWithThrottle}\n @mousedown=${this.__handlePress}\n @keydown=${this.__handlePress}\n @keyup=${this.__handlePress}\n \n aria-describedby=${ifDefined(this.softDisabled ? BaseButton.DISABLED_REASON_ID : undefined)}\n ?aria-disabled=${this.softDisabled}\n\n ?disabled=${this.disabled}\n ${spread(this.configAria)}\n >\n ${this.renderButtonContent()}\n </button>\n ${this.__renderTooltip()}`;\n }\n return html`<a\n class=${classMap(cssClasses)}\n id=\"button\"\n href=${this.href}\n target=${this.target}\n tabindex=${this.disabled ? '-1' : '0'}\n @click=${this.__dispatchClick}\n @mousedown=${this.__handlePress}\n @keydown=${this.__handlePress}\n @keyup=${this.__handlePress}\n role=\"button\"\n \n aria-describedby=${ifDefined(this.softDisabled ? BaseButton.DISABLED_REASON_ID : undefined)}\n ?aria-disabled=${this.softDisabled}\n\n ${spread(this.configAria)}\n >\n ${this.renderButtonContent()}\n </a>\n ${this.__renderTooltip()}`;\n }\n\n renderButtonContent() {\n return html`\n <wc-focus-ring class=\"focus-ring\" for='button'></wc-focus-ring>\n <wc-elevation class=\"elevation\"></wc-elevation>\n <div class=\"neo-background\"></div>\n <div class=\"background\"></div>\n <div class=\"outline\"></div>\n <wc-ripple class=\"ripple\"></wc-ripple>\n <wc-skeleton class=\"skeleton\"></wc-skeleton>\n\n <div class=\"button-content\">\n <slot></slot>\n </div>\n\n ${this.__renderDisabledReason(this.softDisabled)}\n `;\n }\n}\n","import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './button-group.scss';\nimport { Button } from '../button/button.js';\nimport { IconButton } from '../icon-button/icon-button.js';\nimport { BaseButton } from '../BaseButton.js';\n\n/**\n * @label Button Group\n * @tag wc-button-group\n * @rawTag button-group\n *\n * @summary Group a series of buttons together on a single line with the button group, and super-power.\n\n * @example\n * ```html\n * <wc-button-group variant=\"connected\">\n * <wc-icon-button toggle selected><wc-icon name=\"home\"></wc-icon></wc-icon-button>\n * <wc-icon-button toggle><wc-icon name=\"alarm\"></wc-icon></wc-icon-button>\n * </wc-button-group>\n * ```\n *\n * @tags controls\n */\n@IndividualComponent\nexport class ButtonGroup extends LitElement {\n // Lit prefers CSS-in-JS for better performance and scoping.\n // If you prefer keeping the SCSS file, you'll need a build tool (like Vite or Webpack)\n // that can import .scss files as lit-css.\n static styles = [styles];\n\n static Button = Button;\n\n static IconButton = IconButton;\n\n /**\n * Button size.\n * Possible values are `\"sm\"`, `\"md\"`, `\"lg\"`. Defaults to `\"md\"`.\n */\n @property() size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'sm';\n\n /**\n * Layout variant of the button group.\n * `\"standard\"` shows buttons with a small gap between them.\n * `\"connected\"` places buttons with a 2px gap; in horizontal orientation outer buttons have fully\n * rounded outer corners and middle buttons keep standard rounded corners. In vertical orientation\n * all buttons keep their default corner shape.\n * Defaults to `\"standard\"`.\n */\n @property({ reflect: true }) variant: 'standard' | 'connected' = 'standard';\n\n /**\n * Orientation of the button group.\n * `\"horizontal\"` lays buttons out in a row.\n * `\"vertical\"` stacks buttons in a column.\n * Defaults to `\"horizontal\"`.\n */\n @property({ reflect: true }) orientation: 'horizontal' | 'vertical' = 'horizontal';\n\n /**\n * Color applied to all buttons in the group.\n * Possible values are `\"primary\"`, `\"success\"`, `\"danger\"`, `\"warning\"`, `\"surface\"`, `\"on-surface\"`.\n */\n @property({ reflect: true }) color?: 'primary' | 'success' | 'danger' | 'warning' | 'surface' | 'on-surface';\n\n /**\n * Visual style applied to all buttons in the group.\n * Possible values are `\"filled\"`, `\"tonal\"`, `\"outlined\"`.\n */\n @property({ attribute: 'button-variant', reflect: true }) buttonVariant?: 'filled' | 'tonal' | 'outlined';\n\n override updated() {\n this._syncChildren();\n }\n\n private _getSlottedElements(): HTMLElement[] {\n const slot = this.shadowRoot?.querySelector('slot');\n return (slot?.assignedElements({ flatten: true }) ?? []) as HTMLElement[];\n }\n\n private _syncChildren() {\n const children = this._getSlottedElements();\n const isVertical = this.orientation === 'vertical';\n\n children.forEach((child, index) => {\n const isFirst = index === 0;\n const isLast = index === children.length - 1;\n const isOnly = children.length === 1;\n\n if (this.color && 'color' in child) {\n (child as BaseButton).color = this.color;\n }\n\n if (this.buttonVariant && 'variant' in child) {\n (child as BaseButton).variant = this.buttonVariant;\n }\n\n if (this.variant === 'connected') {\n child.style.setProperty('--button-container-shape-variant', 'round');\n\n if (isOnly) {\n child.style.setProperty('--button-container-shape', 'var(--shape-corner-full)');\n child.style.removeProperty('--button-container-shape-start-start');\n child.style.removeProperty('--button-container-shape-end-start');\n child.style.removeProperty('--button-container-shape-start-end');\n child.style.removeProperty('--button-container-shape-end-end');\n } else if (isFirst) {\n child.style.removeProperty('--button-container-shape');\n if (isVertical) {\n // Top button in vertical group: leave default corner shape\n child.style.removeProperty('--button-container-shape-start-start');\n child.style.removeProperty('--button-container-shape-start-end');\n child.style.removeProperty('--button-container-shape-end-start');\n child.style.removeProperty('--button-container-shape-end-end');\n } else {\n // Left button in horizontal group: round left corners, standard right corners\n child.style.setProperty('--button-container-shape-start-start', 'calc(var(--button-height) / 2)');\n child.style.setProperty('--button-container-shape-end-start', 'calc(var(--button-height) / 2)');\n child.style.setProperty('--button-container-shape-start-end', 'var(--shape-corner-medium)');\n child.style.setProperty('--button-container-shape-end-end', 'var(--shape-corner-medium)');\n }\n } else if (isLast) {\n child.style.removeProperty('--button-container-shape');\n if (isVertical) {\n // Bottom button in vertical group: leave default corner shape\n child.style.removeProperty('--button-container-shape-start-start');\n child.style.removeProperty('--button-container-shape-start-end');\n child.style.removeProperty('--button-container-shape-end-start');\n child.style.removeProperty('--button-container-shape-end-end');\n } else {\n // Right button in horizontal group: standard left corners, round right corners\n child.style.setProperty('--button-container-shape-start-start', 'var(--shape-corner-medium)');\n child.style.setProperty('--button-container-shape-end-start', 'var(--shape-corner-medium)');\n child.style.setProperty('--button-container-shape-start-end', 'calc(var(--button-height) / 2)');\n child.style.setProperty('--button-container-shape-end-end', 'calc(var(--button-height) / 2)');\n }\n } else {\n // Middle buttons: standard rounded corners on all sides\n child.style.setProperty('--button-container-shape', 'var(--shape-corner-medium)');\n child.style.removeProperty('--button-container-shape-start-start');\n child.style.removeProperty('--button-container-shape-end-start');\n child.style.removeProperty('--button-container-shape-start-end');\n child.style.removeProperty('--button-container-shape-end-end');\n }\n } else {\n child.style.removeProperty('--button-container-shape');\n child.style.removeProperty('--button-container-shape-start-start');\n child.style.removeProperty('--button-container-shape-end-start');\n child.style.removeProperty('--button-container-shape-start-end');\n child.style.removeProperty('--button-container-shape-end-end');\n child.style.removeProperty('--button-container-shape-variant');\n }\n });\n }\n\n render() {\n const cssClasses = {\n 'button-group': true,\n [`size-${this.size}`]: true,\n [`variant-${this.variant}`]: true,\n [`orientation-${this.orientation}`]: true,\n };\n return html`\n <div class=${classMap(cssClasses)}>\n <slot @slotchange=${() => this._syncChildren()}></slot>\n </div>\n `;\n }\n}\n"],"names":["html","classMap","ifDefined","styles","colorStyles","sizeStyles","property","LitElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CG;AACG,MAAO,UAAW,SAAQ,UAAU,CAAA;AAA1C,IAAA,WAAA,GAAA;;AAGE;;;AAGG;QAC0B,IAAA,CAAA,IAAI,GAAqC,IAAI;AAQxE;;;;;;;;;AASG;QACS,IAAA,CAAA,OAAO,GAMP,QAAQ;AAEpB;;AAEG;QAC0B,IAAA,CAAA,KAAK,GAMf,SAAS;IAiHhC;IAzGW,KAAK,GAAA;AACZ,QAAA,IAAI,CAAC,aAAa,EAAE,KAAK,EAAE;IAC7B;IAES,IAAI,GAAA;AACX,QAAA,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE;IAC5B;IAES,YAAY,GAAA;AACnB,QAAA,IAAI,CAAC,2BAA2B,GAAG,QAAQ,CACzC,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,aAAa,CACnB;QACD,IAAI,CAAC,8BAA8B,EAAE;IACvC;IAEA,8BAA8B,GAAA;AAC5B,QAAA,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;A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AC,aAAa,EAAE,CAAA;;KAEjD;IACH;;AA7IA;AACA;AACA;AACO,WAAA,CAAA,MAAM,GAAG,CAACE,UAAM,CAAC;AAEjB,WAAA,CAAA,MAAM,GAAG,MAAH;AAEN,WAAA,CAAA,UAAU,GAAG,UAAH;AAML,UAAA,CAAA;AAAX,IAAAG,CAAQ;AAAiD,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAU7B,UAAA,CAAA;AAA5B,IAAAA,CAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;AAAiD,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAQ/C,UAAA,CAAA;AAA5B,IAAAA,CAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;AAAwD,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAMtD,UAAA,CAAA;AAA5B,IAAAA,CAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;AAAkF,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAMnD,UAAA,CAAA;IAAzDA,CAAQ,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE;AAAkD,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;AA5C/F,WAAW,GAAA,UAAA,CAAA;IADvB;AACY,CAAA,EAAA,WAAW,CA+IvB;;;;"}
|
package/dist/button-group.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import './IndividualComponent-DUINtMGK.js';
|
|
2
2
|
import './property-1psGvXOq.js';
|
|
3
3
|
import './class-map-YU7g0o3B.js';
|
|
4
|
-
export { B as ButtonGroup } from './button-group-
|
|
5
|
-
import './button-
|
|
4
|
+
export { B as ButtonGroup } from './button-group-CEdMwvJJ.js';
|
|
5
|
+
import './button-DouvOfEU.js';
|
|
6
6
|
import './directive-ZPhl09Yt.js';
|
|
7
|
-
import './
|
|
8
|
-
import './throttle-C7ZAPqtu.js';
|
|
7
|
+
import './BaseButton-DuASuVth.js';
|
|
9
8
|
import './state-DwbEjqVk.js';
|
|
10
|
-
import './observe-slot-change-BGJfgg2E.js';
|
|
11
9
|
import './query-QBcUV-L_.js';
|
|
12
10
|
import './dispatch-event-utils-CuEqjlPT.js';
|
|
11
|
+
import './BaseHyperlinkMixin-BNuwbiEf.js';
|
|
12
|
+
import './observe-slot-change-BGJfgg2E.js';
|
|
13
13
|
//# sourceMappingURL=button-group.js.map
|
package/dist/button.js
CHANGED
|
@@ -2,10 +2,10 @@ import './IndividualComponent-DUINtMGK.js';
|
|
|
2
2
|
import './property-1psGvXOq.js';
|
|
3
3
|
import './state-DwbEjqVk.js';
|
|
4
4
|
import './class-map-YU7g0o3B.js';
|
|
5
|
-
|
|
5
|
+
import './BaseButton-DuASuVth.js';
|
|
6
|
+
export { B as Button } from './button-DouvOfEU.js';
|
|
6
7
|
import './observe-slot-change-BGJfgg2E.js';
|
|
7
|
-
import './
|
|
8
|
-
import './spread-B5cgadZl.js';
|
|
8
|
+
import './BaseHyperlinkMixin-BNuwbiEf.js';
|
|
9
9
|
import './directive-ZPhl09Yt.js';
|
|
10
10
|
import './query-QBcUV-L_.js';
|
|
11
11
|
import './dispatch-event-utils-CuEqjlPT.js';
|
package/dist/card.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as i,
|
|
1
|
+
import { a as i, i as i$1, A, c as __classPrivateFieldGet, b, _ as __decorate, I as IndividualComponent } from './IndividualComponent-DUINtMGK.js';
|
|
2
2
|
import { n } from './property-1psGvXOq.js';
|
|
3
3
|
import { r } from './state-DwbEjqVk.js';
|
|
4
|
-
import { e } from './query-QBcUV-L_.js';
|
|
5
|
-
import { e
|
|
4
|
+
import { e as e$1 } from './query-QBcUV-L_.js';
|
|
5
|
+
import { e } from './class-map-YU7g0o3B.js';
|
|
6
6
|
import { i as isActivationClick, d as dispatchActivationClick } from './dispatch-event-utils-CuEqjlPT.js';
|
|
7
7
|
import { o as observerSlotChangesWithCallback } from './observe-slot-change-BGJfgg2E.js';
|
|
8
|
-
import { t as throttle } from './
|
|
8
|
+
import { B as BaseHyperlinkMixin, t as throttle } from './BaseHyperlinkMixin-BNuwbiEf.js';
|
|
9
9
|
import './directive-ZPhl09Yt.js';
|
|
10
10
|
|
|
11
11
|
var css_248z$1 = i`* {
|
|
@@ -229,7 +229,7 @@ var css_248z = i`:host {
|
|
|
229
229
|
--outlined-card-label-text-color: var(--color-on-surface);
|
|
230
230
|
}`;
|
|
231
231
|
|
|
232
|
-
var _Card_id, _Card_tabindex
|
|
232
|
+
var _Card_id, _Card_tabindex;
|
|
233
233
|
/**
|
|
234
234
|
* @label Card
|
|
235
235
|
* @tag wc-card
|
|
@@ -247,7 +247,7 @@ var _Card_id, _Card_tabindex, _Card_slottedTabIndexMap;
|
|
|
247
247
|
* </wc-card>
|
|
248
248
|
* ```
|
|
249
249
|
*/
|
|
250
|
-
let Card = class Card extends i$1 {
|
|
250
|
+
let Card = class Card extends BaseHyperlinkMixin(i$1) {
|
|
251
251
|
constructor() {
|
|
252
252
|
super(...arguments);
|
|
253
253
|
_Card_id.set(this, crypto.randomUUID());
|
|
@@ -258,10 +258,6 @@ let Card = class Card extends i$1 {
|
|
|
258
258
|
* If button is disabled, the reason why it is disabled.
|
|
259
259
|
*/
|
|
260
260
|
this.disabledReason = '';
|
|
261
|
-
/**
|
|
262
|
-
* Sets or retrieves the window or frame at which to target content.
|
|
263
|
-
*/
|
|
264
|
-
this.target = '_self';
|
|
265
261
|
/**
|
|
266
262
|
* Sets the delay for throttle in milliseconds. Defaults to 200 milliseconds.
|
|
267
263
|
*/
|
|
@@ -272,7 +268,6 @@ let Card = class Card extends i$1 {
|
|
|
272
268
|
this.isPressed = false;
|
|
273
269
|
this.slotHasContent = false;
|
|
274
270
|
_Card_tabindex.set(this, 0);
|
|
275
|
-
_Card_slottedTabIndexMap.set(this, new WeakMap());
|
|
276
271
|
this.__dispatchClickWithThrottle = event => {
|
|
277
272
|
this.__dispatchClick(event);
|
|
278
273
|
};
|
|
@@ -311,49 +306,8 @@ let Card = class Card extends i$1 {
|
|
|
311
306
|
this.__dispatchClickWithThrottle = throttle(this.__dispatchClick, this.throttleDelay);
|
|
312
307
|
observerSlotChangesWithCallback(this.renderRoot.querySelector('slot'), hasContent => {
|
|
313
308
|
this.slotHasContent = hasContent;
|
|
314
|
-
this.__syncSlottedChildrenTabIndex();
|
|
315
309
|
this.requestUpdate();
|
|
316
310
|
});
|
|
317
|
-
this.__syncSlottedChildrenTabIndex();
|
|
318
|
-
}
|
|
319
|
-
updated(changedProperties) {
|
|
320
|
-
if (changedProperties.has('actionable') || changedProperties.has('href')) {
|
|
321
|
-
this.__syncSlottedChildrenTabIndex();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
__syncSlottedChildrenTabIndex() {
|
|
325
|
-
if (!this.contentSlot)
|
|
326
|
-
return;
|
|
327
|
-
const shouldDisableTabbing = this.actionable || this.__isLink();
|
|
328
|
-
const assignedChildren = this.contentSlot.assignedElements({ flatten: true });
|
|
329
|
-
assignedChildren.forEach(node => {
|
|
330
|
-
if (!(node instanceof HTMLElement))
|
|
331
|
-
return;
|
|
332
|
-
if (shouldDisableTabbing) {
|
|
333
|
-
if (!__classPrivateFieldGet(this, _Card_slottedTabIndexMap, "f").has(node)) {
|
|
334
|
-
__classPrivateFieldGet(this, _Card_slottedTabIndexMap, "f").set(node, node.getAttribute('tabindex'));
|
|
335
|
-
}
|
|
336
|
-
if (node.getAttribute('tabindex') !== '-1') {
|
|
337
|
-
node.setAttribute('tabindex', '-1');
|
|
338
|
-
}
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
const originalTabIndex = __classPrivateFieldGet(this, _Card_slottedTabIndexMap, "f").get(node);
|
|
342
|
-
if (originalTabIndex === null) {
|
|
343
|
-
if (node.hasAttribute('tabindex')) {
|
|
344
|
-
node.removeAttribute('tabindex');
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
else if (originalTabIndex !== undefined) {
|
|
348
|
-
if (node.getAttribute('tabindex') !== originalTabIndex) {
|
|
349
|
-
node.setAttribute('tabindex', originalTabIndex);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
__classPrivateFieldGet(this, _Card_slottedTabIndexMap, "f").delete(node);
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
__isLink() {
|
|
356
|
-
return !!this.href;
|
|
357
311
|
}
|
|
358
312
|
__getDisabledReasonID() {
|
|
359
313
|
return this.disabled && this.disabledReason
|
|
@@ -375,6 +329,7 @@ let Card = class Card extends i$1 {
|
|
|
375
329
|
}
|
|
376
330
|
render() {
|
|
377
331
|
const isLink = this.__isLink();
|
|
332
|
+
const disableSlotTabbing = this.actionable || isLink;
|
|
378
333
|
const cssClasses = {
|
|
379
334
|
card: true,
|
|
380
335
|
'card-element': true,
|
|
@@ -386,15 +341,15 @@ let Card = class Card extends i$1 {
|
|
|
386
341
|
};
|
|
387
342
|
if (!this.actionable && !isLink) {
|
|
388
343
|
return b `<div
|
|
389
|
-
class=${e
|
|
344
|
+
class=${e(cssClasses)}
|
|
390
345
|
id="card"
|
|
391
346
|
>
|
|
392
|
-
${this.renderCardContent()}
|
|
347
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
393
348
|
</div>`;
|
|
394
349
|
}
|
|
395
350
|
if (!isLink) {
|
|
396
351
|
return b `<button
|
|
397
|
-
class=${e
|
|
352
|
+
class=${e(cssClasses)}
|
|
398
353
|
id="card"
|
|
399
354
|
tabindex=${__classPrivateFieldGet(this, _Card_tabindex, "f")}
|
|
400
355
|
@click=${this.__dispatchClickWithThrottle}
|
|
@@ -405,11 +360,11 @@ let Card = class Card extends i$1 {
|
|
|
405
360
|
aria-disabled=${`${this.disabled}`}
|
|
406
361
|
?disabled=${this.disabled}
|
|
407
362
|
>
|
|
408
|
-
${this.renderCardContent()}
|
|
363
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
409
364
|
</button>`;
|
|
410
365
|
}
|
|
411
366
|
return b `<a
|
|
412
|
-
class=${e
|
|
367
|
+
class=${e(cssClasses)}
|
|
413
368
|
id="card"
|
|
414
369
|
tabindex=${__classPrivateFieldGet(this, _Card_tabindex, "f")}
|
|
415
370
|
href=${this.href}
|
|
@@ -422,12 +377,12 @@ let Card = class Card extends i$1 {
|
|
|
422
377
|
?aria-describedby=${this.__getDisabledReasonID()}
|
|
423
378
|
aria-disabled=${`${this.disabled}`}
|
|
424
379
|
>
|
|
425
|
-
${this.renderCardContent()}
|
|
380
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
426
381
|
</a>`;
|
|
427
382
|
}
|
|
428
|
-
renderCardContent() {
|
|
383
|
+
renderCardContent(disableSlotTabbing) {
|
|
429
384
|
return b `
|
|
430
|
-
|
|
385
|
+
<wc-focus-ring class="focus-ring" for='card'></wc-focus-ring>
|
|
431
386
|
<wc-elevation class="elevation"></wc-elevation>
|
|
432
387
|
<div class="background"></div>
|
|
433
388
|
<div class="outline"></div>
|
|
@@ -435,8 +390,8 @@ let Card = class Card extends i$1 {
|
|
|
435
390
|
|
|
436
391
|
<div class="card-content">
|
|
437
392
|
|
|
438
|
-
<div class="slot-container">
|
|
439
|
-
<slot
|
|
393
|
+
<div class="slot-container" ?inert=${disableSlotTabbing}>
|
|
394
|
+
<slot></slot>
|
|
440
395
|
</div>
|
|
441
396
|
|
|
442
397
|
</div>
|
|
@@ -445,7 +400,6 @@ let Card = class Card extends i$1 {
|
|
|
445
400
|
};
|
|
446
401
|
_Card_id = new WeakMap();
|
|
447
402
|
_Card_tabindex = new WeakMap();
|
|
448
|
-
_Card_slottedTabIndexMap = new WeakMap();
|
|
449
403
|
Card.styles = [css_248z$1, css_248z];
|
|
450
404
|
__decorate([
|
|
451
405
|
n({ type: String, reflect: true })
|
|
@@ -459,12 +413,6 @@ __decorate([
|
|
|
459
413
|
__decorate([
|
|
460
414
|
n({ attribute: 'disabled-reason' })
|
|
461
415
|
], Card.prototype, "disabledReason", void 0);
|
|
462
|
-
__decorate([
|
|
463
|
-
n({ reflect: true })
|
|
464
|
-
], Card.prototype, "href", void 0);
|
|
465
|
-
__decorate([
|
|
466
|
-
n()
|
|
467
|
-
], Card.prototype, "target", void 0);
|
|
468
416
|
__decorate([
|
|
469
417
|
n()
|
|
470
418
|
], Card.prototype, "throttleDelay", void 0);
|
|
@@ -475,11 +423,8 @@ __decorate([
|
|
|
475
423
|
r()
|
|
476
424
|
], Card.prototype, "slotHasContent", void 0);
|
|
477
425
|
__decorate([
|
|
478
|
-
e('.card')
|
|
426
|
+
e$1('.card')
|
|
479
427
|
], Card.prototype, "cardElement", void 0);
|
|
480
|
-
__decorate([
|
|
481
|
-
e('slot')
|
|
482
|
-
], Card.prototype, "contentSlot", void 0);
|
|
483
428
|
Card = __decorate([
|
|
484
429
|
IndividualComponent
|
|
485
430
|
], Card);
|
package/dist/card.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card.js","sources":["../../src/card/card.ts"],"sourcesContent":["import { LitElement, html, nothing, PropertyValues } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { dispatchActivationClick, isActivationClick } from '../__utils/dispatch-event-utils.js';\nimport { observerSlotChangesWithCallback } from '@/__utils/observe-slot-change.js';\nimport { throttle } from '@/__utils/throttle.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './card.scss';\nimport colorStyles from './card-colors.scss';\n\ntype CardVariant = 'elevated' | 'filled' | 'outlined';\n\n/**\n * @label Card\n * @tag wc-card\n * @rawTag card\n * @summary A Material 3 inspired card surface for grouping related content.\n * @cssprop --card-padding - Inner padding for the card container. Defaults to 1rem.\n * @cssprop --card-shape - Corner radius for the card container. Defaults to a large radius.\n * @cssprop --card-gap - Gap between slotted children.\n *\n * @example\n * ```html\n * <wc-card variant=\"outlined\">\n * <h3>Title</h3>\n * <p>Supportive text</p>\n * </wc-card>\n * ```\n */\n@IndividualComponent\nexport class Card extends LitElement {\n static styles = [styles, colorStyles];\n\n #id = crypto.randomUUID();\n\n @property({ type: String, reflect: true })\n variant: CardVariant = 'elevated';\n\n @property({ type: Boolean, reflect: true })\n disabled: boolean = false;\n\n @property({ type: Boolean, reflect: true })\n actionable: boolean = false;\n\n /**\n * If button is disabled, the reason why it is disabled.\n */\n @property({ attribute: 'disabled-reason' })\n disabledReason: string = '';\n\n /**\n * Hyperlink to navigate to on click.\n */\n @property({ reflect: true }) href?: string;\n\n /**\n * Sets or retrieves the window or frame at which to target content.\n */\n @property() target: string = '_self';\n\n\n /**\n * Sets the delay for throttle in milliseconds. Defaults to 200 milliseconds.\n */\n @property() throttleDelay = 200;\n\n /**\n * States\n */\n @state()\n isPressed = false;\n\n @state()\n private slotHasContent = false;\n\n\n @query('.card') readonly cardElement!: HTMLElement | null;\n\n @query('slot') readonly contentSlot!: HTMLSlotElement | null;\n\n #tabindex?: number = 0;\n\n #slottedTabIndexMap = new WeakMap<HTMLElement, string | null>();\n\n override firstUpdated() {\n this.__dispatchClickWithThrottle = throttle(\n this.__dispatchClick,\n this.throttleDelay,\n );\n observerSlotChangesWithCallback(\n this.renderRoot.querySelector('slot'),\n hasContent => {\n this.slotHasContent = hasContent;\n this.__syncSlottedChildrenTabIndex();\n this.requestUpdate();\n },\n );\n this.__syncSlottedChildrenTabIndex();\n }\n\n override updated(changedProperties: PropertyValues<this>) {\n if (changedProperties.has('actionable') || changedProperties.has('href')) {\n this.__syncSlottedChildrenTabIndex();\n }\n }\n\n __syncSlottedChildrenTabIndex() {\n if (!this.contentSlot) return;\n\n const shouldDisableTabbing = this.actionable || this.__isLink();\n const assignedChildren = this.contentSlot.assignedElements({ flatten: true });\n\n assignedChildren.forEach(node => {\n if (!(node instanceof HTMLElement)) return;\n\n if (shouldDisableTabbing) {\n if (!this.#slottedTabIndexMap.has(node)) {\n this.#slottedTabIndexMap.set(node, node.getAttribute('tabindex'));\n }\n\n if (node.getAttribute('tabindex') !== '-1') {\n node.setAttribute('tabindex', '-1');\n }\n return;\n }\n\n const originalTabIndex = this.#slottedTabIndexMap.get(node);\n if (originalTabIndex === null) {\n if (node.hasAttribute('tabindex')) {\n node.removeAttribute('tabindex');\n }\n } else if (originalTabIndex !== undefined) {\n if (node.getAttribute('tabindex') !== originalTabIndex) {\n node.setAttribute('tabindex', originalTabIndex);\n }\n }\n\n this.#slottedTabIndexMap.delete(node);\n });\n }\n\n __dispatchClickWithThrottle: (event: MouseEvent | KeyboardEvent) => void =\n event => {\n this.__dispatchClick(event);\n };\n\n __dispatchClick = (event: MouseEvent | KeyboardEvent) => {\n // If the button is soft-disabled or a disabled link, we need to explicitly\n // prevent the click from propagating to other event listeners as well as\n // prevent the default action.\n if (this.disabled && this.href) {\n event.stopImmediatePropagation();\n event.preventDefault();\n return;\n }\n\n if (!isActivationClick(event) || !this.cardElement) {\n return;\n }\n\n this.focus();\n dispatchActivationClick(this.cardElement);\n };\n\n __isLink() {\n return !!this.href;\n }\n\n __getDisabledReasonID() {\n return this.disabled && this.disabledReason\n ? `disabled-reason-${this.#id}`\n : nothing;\n }\n\n __renderDisabledReason() {\n const disabledReasonID = this.__getDisabledReasonID();\n if (disabledReasonID)\n return html`<div\n id=\"disabled-reason-${this.#id}\"\n role=\"tooltip\"\n aria-label=${this.disabledReason}\n class=\"screen-reader-only\"\n >\n ${this.disabledReason}\n </div>`;\n return nothing;\n }\n\n __handlePress = (event: KeyboardEvent | MouseEvent) => {\n if (this.disabled) return;\n if (\n event instanceof KeyboardEvent &&\n event.type === 'keydown' &&\n (event.key === 'Enter' || event.key === ' ')\n ) {\n this.isPressed = true;\n } else if (event.type === 'mousedown') {\n this.isPressed = true;\n } else {\n this.isPressed = false;\n }\n };\n\n\n\n\n render() {\n\n const isLink = this.__isLink();\n\n const cssClasses = {\n card: true,\n 'card-element': true,\n [`variant-${this.variant}`]: true,\n actionable: (this.actionable && !this.disabled) || isLink,\n disabled: this.disabled,\n pressed: this.isPressed,\n 'has-content': this.slotHasContent,\n };\n\n if (!this.actionable && !isLink) {\n return html`<div\n class=${classMap(cssClasses)}\n id=\"card\"\n >\n ${this.renderCardContent()}\n </div>`;\n }\n\n if (!isLink) {\n return html`<button\n class=${classMap(cssClasses)}\n id=\"card\"\n tabindex=${this.#tabindex}\n @click=${this.__dispatchClickWithThrottle}\n @mousedown=${this.__handlePress}\n @keydown=${this.__handlePress}\n @keyup=${this.__handlePress}\n ?aria-describedby=${this.__getDisabledReasonID()}\n aria-disabled=${`${this.disabled}`}\n ?disabled=${this.disabled}\n >\n ${this.renderCardContent()}\n </button>`;\n }\n return html`<a\n class=${classMap(cssClasses)}\n id=\"card\"\n tabindex=${this.#tabindex}\n href=${this.href}\n target=${this.target}\n @click=${this.__dispatchClickWithThrottle}\n @mousedown=${this.__handlePress}\n @keydown=${this.__handlePress}\n @keyup=${this.__handlePress}\n role=\"button\"\n ?aria-describedby=${this.__getDisabledReasonID()}\n aria-disabled=${`${this.disabled}`}\n >\n ${this.renderCardContent()}\n </a>`;\n }\n\n renderCardContent() {\n return html`\n <wc-focus-ring class=\"focus-ring\" .control=${this} .forElement=${this.cardElement}></wc-focus-ring>\n <wc-elevation class=\"elevation\"></wc-elevation>\n <div class=\"background\"></div>\n <div class=\"outline\"></div>\n <wc-ripple class=\"ripple\"></wc-ripple> \n\n <div class=\"card-content\">\n\n <div class=\"slot-container\">\n <slot @slotchange=${this.__syncSlottedChildrenTabIndex}></slot>\n </div>\n\n </div>\n `;\n }\n}\n"],"names":["LitElement","nothing","html","classMap","styles","colorStyles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AA,aAAA,EAAA,MAAA,CAAA;AAElC,UAAA,CAAA;IAAvBA,CAAK,CAAC,MAAM;AAAgD,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAhDlD,IAAI,GAAA,UAAA,CAAA;IADhB;AACY,CAAA,EAAA,IAAI,CA0PhB;;;;"}
|
|
1
|
+
{"version":3,"file":"card.js","sources":["../../src/card/card.ts"],"sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { dispatchActivationClick, isActivationClick } from '../__utils/dispatch-event-utils.js';\nimport { observerSlotChangesWithCallback } from '@/__utils/observe-slot-change.js';\nimport { throttle } from '@/__utils/throttle.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './card.scss';\nimport colorStyles from './card-colors.scss';\nimport BaseHyperlinkMixin from '@/__mixins/BaseHyperlinkMixin.js';\n\ntype CardVariant = 'elevated' | 'filled' | 'outlined';\n\n/**\n * @label Card\n * @tag wc-card\n * @rawTag card\n * @summary A Material 3 inspired card surface for grouping related content.\n * @cssprop --card-padding - Inner padding for the card container. Defaults to 1rem.\n * @cssprop --card-shape - Corner radius for the card container. Defaults to a large radius.\n * @cssprop --card-gap - Gap between slotted children.\n *\n * @example\n * ```html\n * <wc-card variant=\"outlined\">\n * <h3>Title</h3>\n * <p>Supportive text</p>\n * </wc-card>\n * ```\n */\n@IndividualComponent\nexport class Card extends BaseHyperlinkMixin(LitElement) {\n static styles = [styles, colorStyles];\n\n #id = crypto.randomUUID();\n\n @property({ type: String, reflect: true })\n variant: CardVariant = 'elevated';\n\n @property({ type: Boolean, reflect: true })\n disabled: boolean = false;\n\n @property({ type: Boolean, reflect: true })\n actionable: boolean = false;\n\n /**\n * If button is disabled, the reason why it is disabled.\n */\n @property({ attribute: 'disabled-reason' })\n disabledReason: string = '';\n\n /**\n * Sets the delay for throttle in milliseconds. Defaults to 200 milliseconds.\n */\n @property() throttleDelay = 200;\n\n /**\n * States\n */\n @state()\n isPressed = false;\n\n @state()\n private slotHasContent = false;\n\n\n @query('.card') readonly cardElement!: HTMLElement | null;\n\n #tabindex?: number = 0;\n\n override firstUpdated() {\n this.__dispatchClickWithThrottle = throttle(\n this.__dispatchClick,\n this.throttleDelay,\n );\n observerSlotChangesWithCallback(\n this.renderRoot.querySelector('slot'),\n hasContent => {\n this.slotHasContent = hasContent;\n this.requestUpdate();\n },\n );\n }\n\n __dispatchClickWithThrottle: (event: MouseEvent | KeyboardEvent) => void =\n event => {\n this.__dispatchClick(event);\n };\n\n __dispatchClick = (event: MouseEvent | KeyboardEvent) => {\n // If the button is soft-disabled or a disabled link, we need to explicitly\n // prevent the click from propagating to other event listeners as well as\n // prevent the default action.\n if (this.disabled && this.href) {\n event.stopImmediatePropagation();\n event.preventDefault();\n return;\n }\n\n if (!isActivationClick(event) || !this.cardElement) {\n return;\n }\n\n this.focus();\n dispatchActivationClick(this.cardElement);\n };\n\n __getDisabledReasonID() {\n return this.disabled && this.disabledReason\n ? `disabled-reason-${this.#id}`\n : nothing;\n }\n\n __renderDisabledReason() {\n const disabledReasonID = this.__getDisabledReasonID();\n if (disabledReasonID)\n return html`<div\n id=\"disabled-reason-${this.#id}\"\n role=\"tooltip\"\n aria-label=${this.disabledReason}\n class=\"screen-reader-only\"\n >\n ${this.disabledReason}\n </div>`;\n return nothing;\n }\n\n __handlePress = (event: KeyboardEvent | MouseEvent) => {\n if (this.disabled) return;\n if (\n event instanceof KeyboardEvent &&\n event.type === 'keydown' &&\n (event.key === 'Enter' || event.key === ' ')\n ) {\n this.isPressed = true;\n } else if (event.type === 'mousedown') {\n this.isPressed = true;\n } else {\n this.isPressed = false;\n }\n };\n\n\n\n\n render() {\n\n const isLink = this.__isLink();\n const disableSlotTabbing = this.actionable || isLink;\n\n const cssClasses = {\n card: true,\n 'card-element': true,\n [`variant-${this.variant}`]: true,\n actionable: (this.actionable && !this.disabled) || isLink,\n disabled: this.disabled,\n pressed: this.isPressed,\n 'has-content': this.slotHasContent,\n };\n\n if (!this.actionable && !isLink) {\n return html`<div\n class=${classMap(cssClasses)}\n id=\"card\"\n >\n ${this.renderCardContent(disableSlotTabbing)}\n </div>`;\n }\n\n if (!isLink) {\n return html`<button\n class=${classMap(cssClasses)}\n id=\"card\"\n tabindex=${this.#tabindex}\n @click=${this.__dispatchClickWithThrottle}\n @mousedown=${this.__handlePress}\n @keydown=${this.__handlePress}\n @keyup=${this.__handlePress}\n ?aria-describedby=${this.__getDisabledReasonID()}\n aria-disabled=${`${this.disabled}`}\n ?disabled=${this.disabled}\n >\n ${this.renderCardContent(disableSlotTabbing)}\n </button>`;\n }\n return html`<a\n class=${classMap(cssClasses)}\n id=\"card\"\n tabindex=${this.#tabindex}\n href=${this.href}\n target=${this.target}\n @click=${this.__dispatchClickWithThrottle}\n @mousedown=${this.__handlePress}\n @keydown=${this.__handlePress}\n @keyup=${this.__handlePress}\n role=\"button\"\n ?aria-describedby=${this.__getDisabledReasonID()}\n aria-disabled=${`${this.disabled}`}\n >\n ${this.renderCardContent(disableSlotTabbing)}\n </a>`;\n }\n\n renderCardContent(disableSlotTabbing: boolean) {\n return html`\n <wc-focus-ring class=\"focus-ring\" for='card'></wc-focus-ring>\n <wc-elevation class=\"elevation\"></wc-elevation>\n <div class=\"background\"></div>\n <div class=\"outline\"></div>\n <wc-ripple class=\"ripple\"></wc-ripple> \n\n <div class=\"card-content\">\n\n <div class=\"slot-container\" ?inert=${disableSlotTabbing}>\n <slot></slot>\n </div>\n\n </div>\n `;\n }\n}\n"],"names":["LitElement","nothing","html","classMap","styles","colorStyles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE;AACd,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,gBAAA,EAAA,MAAA,CAAA;AAKhB,UAAA,CAAA;AAAX,IAAAA,CAAQ;AAAuB,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;AAMhC,UAAA,CAAA;AADC,IAAAC,CAAK;AACY,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAGV,UAAA,CAAA;AADP,IAAAA,CAAK;AACyB,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,gBAAA,EAAA,MAAA,CAAA;AAGN,UAAA,CAAA;IAAxBC,GAAK,CAAC,OAAO;AAA4C,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAnC/C,IAAI,GAAA,UAAA,CAAA;IADhB;AACY,CAAA,EAAA,IAAI,CA6LhB;;;;"}
|
package/dist/chart-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-bar.js","sources":["../../src/chart-bar/chart-bar.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport * as d3 from 'd3';\nimport styles from './chart-bar.scss';\n\nexport type ChartBarItem = {\n name: string;\n value: number;\n label?: string;\n color?: string;\n};\n\nconst chartColors: string[] = [];\n['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {\n chartColors.push(`var(--color-${colorName})`);\n});\n\nconst DEFAULT_WIDTH = 480;\nconst DEFAULT_HEIGHT = 320;\nconst BAR_RADIUS = 10;\nconst DURATION = 450;\n\nfunction debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T {\n let timer: ReturnType<typeof setTimeout>;\n return ((...args: any[]) => {\n clearTimeout(timer);\n timer = setTimeout(() => fn(...args), wait);\n }) as T;\n}\n\n/**\n * @label Chart Bar\n * @tag wc-chart-bar\n * @rawTag chart-bar\n * @summary A vertical bar chart that follows Material Design 3 color and spacing tokens.\n * @tags charts\n *\n * @example\n * ```html\n * <wc-chart-bar width=\"520\" height=\"320\"></wc-chart-bar>\n * <script>\n * document.querySelector('wc-chart-bar').data = [\n * { name: 'apples', label: 'Apples', value: 20 },\n * { name: 'bananas', label: 'Bananas', value: 35 },\n * { name: 'cherries', label: 'Cherries', value: 15 },\n * ];\n * </script>\n * ```\n */\n@IndividualComponent\nexport class ChartBar extends LitElement {\n static styles = [styles];\n\n @query('svg')\n private svgElement?: SVGElement;\n\n /** Width of the chart in pixels. */\n @property({ type: Number, reflect: true }) width: number = 0;\n\n /** Height of the chart in pixels. */\n @property({ type: Number, reflect: true }) height: number = DEFAULT_HEIGHT;\n\n /** Margin around the chart drawing area. */\n @property({ type: Number }) margin: number = 24;\n\n /** Chart data array. Each item should have name, value, and optional label and color. */\n @property({ type: Array }) data: ChartBarItem[] = [];\n\n /** Whether to render value labels above bars. */\n @property({ type: Boolean, attribute: 'show-values' }) showValues: boolean = true;\n\n private _initialized = false;\n\n private _debouncedRenderChart = debounce(() => {\n this._renderChart(true);\n }, 200);\n\n firstUpdated() {\n this._renderChart(false);\n }\n\n updated(changedProperties: PropertyValues) {\n if (!this._initialized) {\n this._initialized = true;\n return;\n }\n const watchedProps = ['width', 'height', 'margin', 'data', 'showValues'];\n const hasChanged = watchedProps.some(prop => changedProperties.has(prop));\n if (hasChanged) {\n this._debouncedRenderChart();\n }\n }\n\n private _getPaletteScale() {\n return d3\n .scaleOrdinal<string, string>()\n .domain(this.data.map(d => d.name))\n .range(chartColors);\n }\n\n private _resolveColor(\n name: string,\n override: string | undefined,\n scale: d3.ScaleOrdinal<string, string>,\n ) {\n return override || scale(name);\n }\n\n private _renderChart(animate: boolean) {\n if (!this.svgElement) return;\n\n const width = this.width > 0 ? this.width : DEFAULT_WIDTH;\n const height = this.height > 0 ? this.height : DEFAULT_HEIGHT;\n const margin = Math.max(this.margin, 12);\n const data = this.data ?? [];\n\n const svg = d3.select(this.svgElement);\n svg.attr('width', width).attr('height', height);\n\n const innerWidth = Math.max(width - margin * 2, 0);\n const innerHeight = Math.max(height - margin * 2, 0);\n const colorScale = this._getPaletteScale();\n\n const container = svg.select<SVGGElement>('.chart-container');\n container.attr('transform', `translate(${margin},${margin})`);\n\n if (!data.length || innerWidth === 0 || innerHeight === 0) {\n container.select('.bars').selectAll('*').remove();\n container.select('.x-axis').selectAll('*').remove();\n container.select('.y-grid').selectAll('*').remove();\n container.select('.value-labels').selectAll('*').remove();\n return;\n }\n\n const xScale = d3\n .scaleBand<string>()\n .domain(data.map(d => d.name))\n .range([0, innerWidth])\n .padding(0.28);\n\n const maxValue = d3.max(data, d => d.value) ?? 0;\n const yScale = d3\n .scaleLinear()\n .domain([0, maxValue || 1])\n .nice()\n .range([innerHeight, 0]);\n\n const yGrid = container.select<SVGGElement>('.y-grid');\n yGrid\n .call(\n d3\n .axisLeft(yScale)\n .ticks(5)\n .tickSize(-innerWidth)\n .tickFormat(() => ''),\n )\n .selectAll('.tick text')\n .remove();\n yGrid.select('.domain').remove();\n yGrid.selectAll('.tick line').attr('class', 'gridline');\n\n const xAxis = container.select<SVGGElement>('.x-axis');\n xAxis\n .attr('transform', `translate(0,${innerHeight})`)\n .call(\n d3\n .axisBottom(xScale)\n .tickSizeOuter(0)\n .tickFormat(name => {\n const entry = data.find(d => d.name === name);\n return entry?.label ?? name;\n }),\n );\n xAxis.select('.domain').attr('stroke', 'var(--color-outline-variant)');\n xAxis.selectAll('.tick line').remove();\n xAxis\n .selectAll('.tick text')\n .attr('class', 'axis-label')\n .attr('dy', '1.1em');\n\n const bars = container\n .select('.bars')\n .selectAll<SVGRectElement, ChartBarItem>('rect')\n .data(data, d => d.name)\n .join(\n enter =>\n enter\n .append('rect')\n .attr('class', 'bar')\n .attr('x', d => xScale(d.name) ?? 0)\n .attr('width', xScale.bandwidth())\n .attr('y', innerHeight)\n .attr('height', 0)\n .attr('rx', BAR_RADIUS)\n .attr('ry', BAR_RADIUS)\n .style('fill', d =>\n this._resolveColor(d.name, d.color, colorScale),\n ),\n update => update,\n exit =>\n exit\n .transition()\n .duration(DURATION)\n .attr('height', 0)\n .attr('y', innerHeight)\n .remove(),\n );\n\n bars\n .attr('x', d => xScale(d.name) ?? 0)\n .attr('width', xScale.bandwidth())\n .attr('rx', BAR_RADIUS)\n .attr('ry', BAR_RADIUS)\n .style('fill', d => this._resolveColor(d.name, d.color, colorScale));\n\n if (animate) {\n bars\n .transition()\n .duration(DURATION)\n .attr('y', d => yScale(d.value))\n .attr('height', d => innerHeight - yScale(d.value));\n } else {\n bars\n .attr('y', d => yScale(d.value))\n .attr('height', d => innerHeight - yScale(d.value));\n }\n\n const valueLabels = container\n .select('.value-labels')\n .selectAll<SVGTextElement, ChartBarItem>('text')\n .data(this.showValues ? data : [], d => d.name)\n .join(\n enter =>\n enter\n .append('text')\n .attr('class', 'value-label')\n .attr('text-anchor', 'middle')\n .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)\n .attr('y', innerHeight - 6)\n .text(d => d.value.toLocaleString()),\n update => update,\n exit => exit.remove(),\n );\n\n const resolveLabelY = (value: number) => {\n const offset = yScale(value) - 8;\n return Math.min(offset, innerHeight - 8);\n };\n\n if (animate) {\n valueLabels\n .transition()\n .duration(DURATION)\n .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)\n .attr('y', d => resolveLabelY(d.value))\n .text(d => d.value.toLocaleString());\n } else {\n valueLabels\n .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)\n .attr('y', d => resolveLabelY(d.value))\n .text(d => d.value.toLocaleString());\n }\n }\n\n render() {\n const paletteScale = this._getPaletteScale();\n const legendItems = this.data.map(item => ({\n name: item.label ?? item.name,\n color: this._resolveColor(item.name, item.color, paletteScale),\n }));\n\n return html`\n <div class=\"chart-frame\">\n <svg role=\"img\" aria-label=\"Bar chart\">\n <g class=\"chart-container\">\n <g class=\"y-grid\"></g>\n <g class=\"bars\"></g>\n <g class=\"x-axis\"></g>\n <g class=\"value-labels\"></g>\n </g>\n </svg>\n ${legendItems.length\n ? html`<div class=\"legend\" role=\"list\">\n ${legendItems.map(\n item => html`<span class=\"legend-item\" role=\"listitem\">\n <span\n class=\"swatch\"\n style=${styleMap({ background: item.color })}\n ></span>\n <span>${item.name}</span>\n </span>`,\n )}\n </div>`\n : null}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'wc-chart-bar': ChartBar;\n }\n}\n"],"names":["LitElement","d3\n .scaleOrdinal","d3.select","d3\n .scaleBand","d3.max","d3\n .scaleLinear","d3\n .axisLeft","d3\n .axisBottom","html","styleMap","styles","query","property"],"mappings":";;;;;;;;AAcA,MAAM,WAAW,GAAa,EAAE;AAChC,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,IAAG;AACzE,IAAA,WAAW,CAAC,IAAI,CAAC,eAAe,SAAS,CAAA,CAAA,CAAG,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,GAAG;AACzB,MAAM,cAAc,GAAG,GAAG;AAC1B,MAAM,UAAU,GAAG,EAAE;AACrB,MAAM,QAAQ,GAAG,GAAG;AAEpB,SAAS,QAAQ,CAAqC,EAAK,EAAE,IAAY,EAAA;AACvE,IAAA,IAAI,KAAoC;AACxC,IAAA,QAAQ,CAAC,GAAG,IAAW,KAAI;QACzB,YAAY,CAAC,KAAK,CAAC;AACnB,QAAA,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC;AAC7C,IAAA,CAAC;AACH;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQA,CAAU,CAAA;AAAjC,IAAA,WAAA,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AAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAkC,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAG/C,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAsB,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAGrB,UAAA,CAAA;AAA1B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;AAA4B,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAGE,UAAA,CAAA;IAAtDA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE;AAA6B,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAnBvE,QAAQ,GAAA,UAAA,CAAA;IADpB;AACY,CAAA,EAAA,QAAQ,CAuPpB;;;;"}
|
|
1
|
+
{"version":3,"file":"chart-bar.js","sources":["../../src/chart-bar/chart-bar.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { select, max, scaleBand, scaleLinear, scaleOrdinal, axisLeft, axisBottom, ScaleOrdinal } from 'd3';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './chart-bar.scss';\n\nexport type ChartBarItem = {\n name: string;\n value: number;\n label?: string;\n color?: string;\n};\n\nconst chartColors: string[] = [];\n['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {\n chartColors.push(`var(--color-${colorName})`);\n});\n\nconst DEFAULT_WIDTH = 480;\nconst DEFAULT_HEIGHT = 320;\nconst BAR_RADIUS = 10;\nconst DURATION = 450;\n\nfunction debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T {\n let timer: ReturnType<typeof setTimeout>;\n return ((...args: any[]) => {\n clearTimeout(timer);\n timer = setTimeout(() => fn(...args), wait);\n }) as T;\n}\n\n/**\n * @label Chart Bar\n * @tag wc-chart-bar\n * @rawTag chart-bar\n * @summary A vertical bar chart that follows Material Design 3 color and spacing tokens.\n * @tags charts\n *\n * @example\n * ```html\n * <wc-chart-bar width=\"520\" height=\"320\"></wc-chart-bar>\n * <script>\n * document.querySelector('wc-chart-bar').data = [\n * { name: 'apples', label: 'Apples', value: 20 },\n * { name: 'bananas', label: 'Bananas', value: 35 },\n * { name: 'cherries', label: 'Cherries', value: 15 },\n * ];\n * </script>\n * ```\n */\n@IndividualComponent\nexport class ChartBar extends LitElement {\n static styles = [styles];\n\n @query('svg')\n private svgElement?: SVGElement;\n\n /** Width of the chart in pixels. */\n @property({ type: Number, reflect: true }) width: number = 0;\n\n /** Height of the chart in pixels. */\n @property({ type: Number, reflect: true }) height: number = DEFAULT_HEIGHT;\n\n /** Margin around the chart drawing area. */\n @property({ type: Number }) margin: number = 24;\n\n /** Chart data array. Each item should have name, value, and optional label and color. */\n @property({ type: Array }) data: ChartBarItem[] = [];\n\n /** Whether to render value labels above bars. */\n @property({ type: Boolean, attribute: 'show-values' }) showValues: boolean = true;\n\n private _initialized = false;\n\n private _debouncedRenderChart = debounce(() => {\n this._renderChart(true);\n }, 200);\n\n firstUpdated() {\n this._renderChart(false);\n }\n\n updated(changedProperties: PropertyValues) {\n if (!this._initialized) {\n this._initialized = true;\n return;\n }\n const watchedProps = ['width', 'height', 'margin', 'data', 'showValues'];\n const hasChanged = watchedProps.some(prop => changedProperties.has(prop));\n if (hasChanged) {\n this._debouncedRenderChart();\n }\n }\n\n private _getPaletteScale() {\n return scaleOrdinal<string, string>()\n .domain(this.data.map(d => d.name))\n .range(chartColors);\n }\n\n private _resolveColor(\n name: string,\n override: string | undefined,\n scale: ScaleOrdinal<string, string>,\n ) {\n return override || scale(name);\n }\n\n private _renderChart(animate: boolean) {\n if (!this.svgElement) return;\n\n const width = this.width > 0 ? this.width : DEFAULT_WIDTH;\n const height = this.height > 0 ? this.height : DEFAULT_HEIGHT;\n const margin = Math.max(this.margin, 12);\n const data = this.data ?? [];\n\n const svg = select(this.svgElement);\n svg.attr('width', width).attr('height', height);\n\n const innerWidth = Math.max(width - margin * 2, 0);\n const innerHeight = Math.max(height - margin * 2, 0);\n const colorScale = this._getPaletteScale();\n\n const container = svg.select<SVGGElement>('.chart-container');\n container.attr('transform', `translate(${margin},${margin})`);\n\n if (!data.length || innerWidth === 0 || innerHeight === 0) {\n container.select('.bars').selectAll('*').remove();\n container.select('.x-axis').selectAll('*').remove();\n container.select('.y-grid').selectAll('*').remove();\n container.select('.value-labels').selectAll('*').remove();\n return;\n }\n\n const xScale = scaleBand<string>()\n .domain(data.map(d => d.name))\n .range([0, innerWidth])\n .padding(0.28);\n\n const maxValue = max(data, d => d.value) ?? 0;\n const yScale = scaleLinear()\n .domain([0, maxValue || 1])\n .nice()\n .range([innerHeight, 0]);\n\n const yGrid = container.select<SVGGElement>('.y-grid');\n yGrid\n .call(\n axisLeft(yScale)\n .ticks(5)\n .tickSize(-innerWidth)\n .tickFormat(() => ''),\n )\n .selectAll('.tick text')\n .remove();\n yGrid.select('.domain').remove();\n yGrid.selectAll('.tick line').attr('class', 'gridline');\n\n const xAxis = container.select<SVGGElement>('.x-axis');\n xAxis\n .attr('transform', `translate(0,${innerHeight})`)\n .call(\n axisBottom(xScale)\n .tickSizeOuter(0)\n .tickFormat(name => {\n const entry = data.find(d => d.name === name);\n return entry?.label ?? name;\n }),\n );\n xAxis.select('.domain').attr('stroke', 'var(--color-outline-variant)');\n xAxis.selectAll('.tick line').remove();\n xAxis\n .selectAll('.tick text')\n .attr('class', 'axis-label')\n .attr('dy', '1.1em');\n\n const bars = container\n .select('.bars')\n .selectAll<SVGRectElement, ChartBarItem>('rect')\n .data(data, d => d.name)\n .join(\n enter =>\n enter\n .append('rect')\n .attr('class', 'bar')\n .attr('x', d => xScale(d.name) ?? 0)\n .attr('width', xScale.bandwidth())\n .attr('y', innerHeight)\n .attr('height', 0)\n .attr('rx', BAR_RADIUS)\n .attr('ry', BAR_RADIUS)\n .style('fill', d =>\n this._resolveColor(d.name, d.color, colorScale),\n ),\n update => update,\n exit =>\n exit\n .transition()\n .duration(DURATION)\n .attr('height', 0)\n .attr('y', innerHeight)\n .remove(),\n );\n\n bars\n .attr('x', d => xScale(d.name) ?? 0)\n .attr('width', xScale.bandwidth())\n .attr('rx', BAR_RADIUS)\n .attr('ry', BAR_RADIUS)\n .style('fill', d => this._resolveColor(d.name, d.color, colorScale));\n\n if (animate) {\n bars\n .transition()\n .duration(DURATION)\n .attr('y', d => yScale(d.value))\n .attr('height', d => innerHeight - yScale(d.value));\n } else {\n bars\n .attr('y', d => yScale(d.value))\n .attr('height', d => innerHeight - yScale(d.value));\n }\n\n const valueLabels = container\n .select('.value-labels')\n .selectAll<SVGTextElement, ChartBarItem>('text')\n .data(this.showValues ? data : [], d => d.name)\n .join(\n enter =>\n enter\n .append('text')\n .attr('class', 'value-label')\n .attr('text-anchor', 'middle')\n .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)\n .attr('y', innerHeight - 6)\n .text(d => d.value.toLocaleString()),\n update => update,\n exit => exit.remove(),\n );\n\n const resolveLabelY = (value: number) => {\n const offset = yScale(value) - 8;\n return Math.min(offset, innerHeight - 8);\n };\n\n if (animate) {\n valueLabels\n .transition()\n .duration(DURATION)\n .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)\n .attr('y', d => resolveLabelY(d.value))\n .text(d => d.value.toLocaleString());\n } else {\n valueLabels\n .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)\n .attr('y', d => resolveLabelY(d.value))\n .text(d => d.value.toLocaleString());\n }\n }\n\n render() {\n const paletteScale = this._getPaletteScale();\n const legendItems = this.data.map(item => ({\n name: item.label ?? item.name,\n color: this._resolveColor(item.name, item.color, paletteScale),\n }));\n\n return html`\n <div class=\"chart-frame\">\n <svg role=\"img\" aria-label=\"Bar chart\">\n <g class=\"chart-container\">\n <g class=\"y-grid\"></g>\n <g class=\"bars\"></g>\n <g class=\"x-axis\"></g>\n <g class=\"value-labels\"></g>\n </g>\n </svg>\n ${legendItems.length\n ? html`<div class=\"legend\" role=\"list\">\n ${legendItems.map(\n item => html`<span class=\"legend-item\" role=\"listitem\">\n <span\n class=\"swatch\"\n style=${styleMap({ background: item.color })}\n ></span>\n <span>${item.name}</span>\n </span>`,\n )}\n </div>`\n : null}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'wc-chart-bar': ChartBar;\n }\n}\n"],"names":["LitElement","scaleOrdinal","scaleBand","scaleLinear","html","styleMap","styles","query","property"],"mappings":";;;;;;;;AAcA,MAAM,WAAW,GAAa,EAAE;AAChC,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,IAAG;AACzE,IAAA,WAAW,CAAC,IAAI,CAAC,eAAe,SAAS,CAAA,CAAA,CAAG,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,GAAG;AACzB,MAAM,cAAc,GAAG,GAAG;AAC1B,MAAM,UAAU,GAAG,EAAE;AACrB,MAAM,QAAQ,GAAG,GAAG;AAEpB,SAAS,QAAQ,CAAqC,EAAK,EAAE,IAAY,EAAA;AACvE,IAAA,IAAI,KAAoC;AACxC,IAAA,QAAQ,CAAC,GAAG,IAAW,KAAI;QACzB,YAAY,CAAC,KAAK,CAAC;AACnB,QAAA,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC;AAC7C,IAAA,CAAC;AACH;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQA,CAAU,CAAA;AAAjC,IAAA,WAAA,GAAA;;;QAOsC,IAAA,CAAA,KAAK,G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EAAE;AAAkC,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAG/C,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAsB,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAGrB,UAAA,CAAA;AAA1B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;AAA4B,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAGE,UAAA,CAAA;IAAtDA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE;AAA6B,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAnBvE,QAAQ,GAAA,UAAA,CAAA;IADpB;AACY,CAAA,EAAA,QAAQ,CAkPpB;;;;"}
|
package/dist/chart-doughnut.js
CHANGED
|
@@ -127,10 +127,10 @@ let ChartDoughnut = class ChartDoughnut extends i$1 {
|
|
|
127
127
|
return this.data.reduce((total, d) => total + d.value, 0);
|
|
128
128
|
}
|
|
129
129
|
_getPieData() {
|
|
130
|
-
const
|
|
130
|
+
const pieGenerator = pie()
|
|
131
131
|
.sort(null)
|
|
132
132
|
.value(d => d.value);
|
|
133
|
-
return
|
|
133
|
+
return pieGenerator(this.data);
|
|
134
134
|
}
|
|
135
135
|
_getColorScale() {
|
|
136
136
|
return ordinal()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-doughnut.js","sources":["../../src/chart-doughnut/chart-doughnut.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport * as d3 from 'd3';\nimport styles from './chart-donut.scss';\n\nexport type ChartDoughnutColor = {\n color: string;\n};\n\nexport type ChartDoughnutItem = {\n name: string;\n value: number;\n label?: string;\n color?: string;\n};\n\nconst chartColors: ChartDoughnutColor[] = [];\n['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {\n chartColors.push({\n color: `var(--color-${colorName})`,\n });\n});\n\n/** SVGPathElement augmented with the last rendered arc datum for smooth tween interpolation. */\ninterface ArcPathElement extends SVGPathElement {\n _prevDatum?: d3.PieArcDatum<ChartDoughnutItem>;\n}\n\nfunction debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T {\n let timer: ReturnType<typeof setTimeout>;\n return ((...args: any[]) => {\n clearTimeout(timer);\n timer = setTimeout(() => fn(...args), wait);\n }) as T;\n}\n\n/**\n * @label Chart Doughnut\n * @tag wc-chart-doughnut\n * @rawTag chart-doughnut\n * @summary A doughnut chart is a circular chart with a blank center. The area in the center can be used to display information.\n * @tags charts\n *\n * @example\n * ```html\n * <wc-chart-doughnut width=\"400\" label=\"Total\"></wc-chart-doughnut>\n * <script>\n * document.querySelector('wc-chart-doughnut').data = [\n * { name: 'A', value: 30, label: 'Category A' },\n * { name: 'B', value: 50, label: 'Category B' },\n * { name: 'C', value: 20, label: 'Category C' },\n * ];\n * </script>\n * ```\n */\n@IndividualComponent\nexport class ChartDoughnut extends LitElement {\n static styles = [styles];\n\n @query('svg')\n private svgElement?: SVGElement;\n\n /** Width (and height) of the chart in pixels. */\n @property({ type: Number, reflect: true }) width: number = 0;\n\n /** Margin around the chart. */\n @property({ type: Number, reflect: true }) margin: number = 10;\n\n /** Whether to show labels outside the chart. */\n @property({ type: Boolean, reflect: true, attribute: 'show-labels' })\n showLabels: boolean = true;\n\n /** Chart data array. Each item should have name, value, and optional label and color. */\n @property({ type: Array }) data: ChartDoughnutItem[] = [];\n\n /** Label displayed in the center of the doughnut. */\n @property({ type: String }) label?: string;\n\n private _initialized = false;\n\n private _debouncedRenderChart = debounce(() => {\n this._renderChart(true);\n }, 300);\n\n firstUpdated() {\n this._renderChart(false);\n }\n\n updated(changedProperties: PropertyValues) {\n if (!this._initialized) {\n this._initialized = true;\n return;\n }\n const watchedProps = ['width', 'margin', 'showLabels', 'data'];\n const hasChanged = watchedProps.some(prop => changedProperties.has(prop));\n if (hasChanged) {\n this._debouncedRenderChart();\n }\n }\n\n private _getRadius(): number {\n return this.width / 2 - this.margin - 100;\n }\n\n private _getTotal(): number {\n return this.data.reduce((total, d) => total + d.value, 0);\n }\n\n private _getPieData() {\n const pie = d3\n .pie<ChartDoughnutItem>()\n .sort(null)\n .value(d => d.value);\n return pie(this.data);\n }\n\n private _getColorScale() {\n return d3\n .scaleOrdinal<string, ChartDoughnutColor>()\n .domain(this.data.map(d => d.name))\n .range(chartColors);\n }\n\n private _renderChart(animate: boolean) {\n if (!this.svgElement) return;\n\n const DURATION = 500;\n const radius = this._getRadius();\n const pieData = this._getPieData();\n const colorScale = this._getColorScale();\n const total = this._getTotal();\n\n const svg = d3.select(this.svgElement);\n\n const doughnutArc = d3\n .arc<d3.PieArcDatum<ChartDoughnutItem>>()\n .innerRadius(radius * 0.72)\n .outerRadius(radius);\n\n const labelsArc = d3\n .arc<d3.PieArcDatum<ChartDoughnutItem>>()\n .innerRadius(radius + 10)\n .outerRadius(radius + 10);\n\n // Update SVG dimensions and center transform\n svg.attr('width', this.width).attr('height', this.width);\n svg\n .select('.chart-container')\n .attr('transform', `translate(${this.width / 2},${this.width / 2})`);\n\n // Arc paths — keyed by name so D3 matches elements across updates\n const $paths = svg\n .select('.arc-container')\n .selectAll<SVGPathElement, d3.PieArcDatum<ChartDoughnutItem>>('.arc')\n .data(pieData, d => d.data.name)\n .join('path')\n .attr('class', 'arc')\n .style('fill', d => d.data.color || colorScale(d.data.name).color);\n\n if (animate) {\n $paths\n .transition()\n .duration(DURATION)\n .ease(d3.easeCubicInOut)\n .attrTween('d', function (this: SVGPathElement, d) {\n const self = this as ArcPathElement;\n // Interpolate from the last rendered angles to the new ones.\n // New (entering) arcs start collapsed at their startAngle.\n const prev: { startAngle: number; endAngle: number } =\n self._prevDatum ?? {\n startAngle: d.startAngle,\n endAngle: d.startAngle,\n };\n self._prevDatum = d;\n const iStart = d3.interpolateNumber(prev.startAngle, d.startAngle);\n const iEnd = d3.interpolateNumber(prev.endAngle, d.endAngle);\n return (t: number) =>\n doughnutArc({ ...d, startAngle: iStart(t), endAngle: iEnd(t) }) ??\n '';\n });\n } else {\n // Initial render: draw immediately and seed previous-datum for later tweens\n $paths\n .each(function (this: SVGPathElement, d) {\n (this as ArcPathElement)._prevDatum = d;\n })\n .attr('d', d => doughnutArc(d) ?? '');\n }\n\n // Animate the central total counter\n const $title = svg.select('.title');\n if (animate) {\n $title\n .transition()\n .duration(DURATION)\n .ease(d3.easeCubicInOut)\n .tween('text', function (this: d3.BaseType) {\n const sel = d3.select(this as SVGTextElement);\n const start = parseFloat(sel.text()) || 0;\n const interp = d3.interpolateNumber(start, total);\n return function (t: number) {\n sel.text(Math.round(interp(t)));\n };\n });\n } else {\n $title.text(total);\n }\n\n // Label polylines and text\n const $chartContainer = svg.select('.chart-container');\n\n if (this.showLabels) {\n const pointsFn = (d: d3.PieArcDatum<ChartDoughnutItem>) => {\n const posA = doughnutArc.centroid(d);\n const posB = labelsArc.centroid(d);\n const posC = posB.slice() as [number, number];\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n posC[0] = radius * (midAngle < Math.PI ? 1 : -1);\n return [posA, posB, posC].map(p => p.join(',')).join(' ');\n };\n\n const transformFn = (d: d3.PieArcDatum<ChartDoughnutItem>) => {\n const pos = labelsArc.centroid(d);\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n pos[0] = radius * (midAngle < Math.PI ? 1 : -1);\n return `translate(${pos})`;\n };\n\n const anchorFn = (d: d3.PieArcDatum<ChartDoughnutItem>) => {\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n return midAngle < Math.PI ? 'start' : 'end';\n };\n\n const $polylines = $chartContainer\n .selectAll<SVGPolylineElement, d3.PieArcDatum<ChartDoughnutItem>>(\n '.item-polyline',\n )\n .data(pieData, d => d.data.name)\n .join('polyline')\n .attr('class', 'item-polyline');\n\n const $labels = $chartContainer\n .selectAll<SVGTextElement, d3.PieArcDatum<ChartDoughnutItem>>('.item-label')\n .data(pieData, d => d.data.name)\n .join('text')\n .attr('class', 'item-label')\n .text(d => d.data.label ?? '');\n\n if (animate) {\n $polylines\n .transition()\n .duration(DURATION)\n .ease(d3.easeCubicInOut)\n .attr('points', pointsFn);\n $labels\n .transition()\n .duration(DURATION)\n .ease(d3.easeCubicInOut)\n .attr('transform', transformFn)\n .style('text-anchor', anchorFn);\n } else {\n $polylines.attr('points', pointsFn);\n $labels.attr('transform', transformFn).style('text-anchor', anchorFn);\n }\n } else {\n $chartContainer.selectAll('.item-polyline').remove();\n $chartContainer.selectAll('.item-label').remove();\n }\n }\n\n render() {\n return html`\n <div class=\"chart\">\n <svg>\n <g class=\"chart-container\">\n <g class=\"arc-container\"></g>\n <text class=\"title\" text-anchor=\"middle\"></text>\n <text class=\"label\" text-anchor=\"middle\" y=\"16\">\n ${this.label}\n </text>\n </g>\n </svg>\n </div>\n `;\n }\n}\n"],"names":["LitElement","pie","d3\n .pie","d3\n .scaleOrdinal","d3.select","d3\n .arc","d3.easeCubicInOut","d3.interpolateNumber","html","styles","query","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,WAAW,GAAyB,EAAE;AAC5C,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,IAAG;IACzE,WAAW,CAAC,IAAI,CAAC;QACf,KAAK,EAAE,CAAA,YAAA,EAAe,SAAS,CAAA,CAAA,CAAG;AACnC,KAAA,CAAC;AACJ,CAAC,CAAC;AAOF,SAAS,QAAQ,CAAqC,EAAK,EAAE,IAAY,EAAA;AACvE,IAAA,IAAI,KAAoC;AACxC,IAAA,QAAQ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;AAGhB,UAAA,CAAA;IADPC,CAAK,CAAC,KAAK;AACoB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAGW,UAAA,CAAA;IAA1CC,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAoB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAGlB,UAAA,CAAA;IAA1CA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAsB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAI/D,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE;AACzC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAGA,UAAA,CAAA;AAA1B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;AAAiC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAG9B,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAiB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AApBhC,aAAa,GAAA,UAAA,CAAA;IADzB;AACY,CAAA,EAAA,aAAa,CAqOzB;;;;"}
|
|
1
|
+
{"version":3,"file":"chart-doughnut.js","sources":["../../src/chart-doughnut/chart-doughnut.ts"],"sourcesContent":["import { html, LitElement, PropertyValues } from 'lit';\nimport { property, query } from 'lit/decorators.js';\nimport { select, arc, pie, scaleOrdinal, easeCubicInOut, interpolateNumber, PieArcDatum, BaseType } from 'd3';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './chart-donut.scss';\n\nexport type ChartDoughnutColor = {\n color: string;\n};\n\nexport type ChartDoughnutItem = {\n name: string;\n value: number;\n label?: string;\n color?: string;\n};\n\nconst chartColors: ChartDoughnutColor[] = [];\n['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {\n chartColors.push({\n color: `var(--color-${colorName})`,\n });\n});\n\n/** SVGPathElement augmented with the last rendered arc datum for smooth tween interpolation. */\ninterface ArcPathElement extends SVGPathElement {\n _prevDatum?: PieArcDatum<ChartDoughnutItem>;\n}\n\nfunction debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T {\n let timer: ReturnType<typeof setTimeout>;\n return ((...args: any[]) => {\n clearTimeout(timer);\n timer = setTimeout(() => fn(...args), wait);\n }) as T;\n}\n\n/**\n * @label Chart Doughnut\n * @tag wc-chart-doughnut\n * @rawTag chart-doughnut\n * @summary A doughnut chart is a circular chart with a blank center. The area in the center can be used to display information.\n * @tags charts\n *\n * @example\n * ```html\n * <wc-chart-doughnut width=\"400\" label=\"Total\"></wc-chart-doughnut>\n * <script>\n * document.querySelector('wc-chart-doughnut').data = [\n * { name: 'A', value: 30, label: 'Category A' },\n * { name: 'B', value: 50, label: 'Category B' },\n * { name: 'C', value: 20, label: 'Category C' },\n * ];\n * </script>\n * ```\n */\n@IndividualComponent\nexport class ChartDoughnut extends LitElement {\n static styles = [styles];\n\n @query('svg')\n private svgElement?: SVGElement;\n\n /** Width (and height) of the chart in pixels. */\n @property({ type: Number, reflect: true }) width: number = 0;\n\n /** Margin around the chart. */\n @property({ type: Number, reflect: true }) margin: number = 10;\n\n /** Whether to show labels outside the chart. */\n @property({ type: Boolean, reflect: true, attribute: 'show-labels' })\n showLabels: boolean = true;\n\n /** Chart data array. Each item should have name, value, and optional label and color. */\n @property({ type: Array }) data: ChartDoughnutItem[] = [];\n\n /** Label displayed in the center of the doughnut. */\n @property({ type: String }) label?: string;\n\n private _initialized = false;\n\n private _debouncedRenderChart = debounce(() => {\n this._renderChart(true);\n }, 300);\n\n firstUpdated() {\n this._renderChart(false);\n }\n\n updated(changedProperties: PropertyValues) {\n if (!this._initialized) {\n this._initialized = true;\n return;\n }\n const watchedProps = ['width', 'margin', 'showLabels', 'data'];\n const hasChanged = watchedProps.some(prop => changedProperties.has(prop));\n if (hasChanged) {\n this._debouncedRenderChart();\n }\n }\n\n private _getRadius(): number {\n return this.width / 2 - this.margin - 100;\n }\n\n private _getTotal(): number {\n return this.data.reduce((total, d) => total + d.value, 0);\n }\n\n private _getPieData() {\n const pieGenerator = pie<ChartDoughnutItem>()\n .sort(null)\n .value(d => d.value);\n return pieGenerator(this.data);\n }\n\n private _getColorScale() {\n return scaleOrdinal<string, ChartDoughnutColor>()\n .domain(this.data.map(d => d.name))\n .range(chartColors);\n }\n\n private _renderChart(animate: boolean) {\n if (!this.svgElement) return;\n\n const DURATION = 500;\n const radius = this._getRadius();\n const pieData = this._getPieData();\n const colorScale = this._getColorScale();\n const total = this._getTotal();\n\n const svg = select(this.svgElement);\n\n const doughnutArc = arc<PieArcDatum<ChartDoughnutItem>>()\n .innerRadius(radius * 0.72)\n .outerRadius(radius);\n\n const labelsArc = arc<PieArcDatum<ChartDoughnutItem>>()\n .innerRadius(radius + 10)\n .outerRadius(radius + 10);\n\n // Update SVG dimensions and center transform\n svg.attr('width', this.width).attr('height', this.width);\n svg\n .select('.chart-container')\n .attr('transform', `translate(${this.width / 2},${this.width / 2})`);\n\n // Arc paths — keyed by name so D3 matches elements across updates\n const $paths = svg\n .select('.arc-container')\n .selectAll<SVGPathElement, PieArcDatum<ChartDoughnutItem>>('.arc')\n .data(pieData, d => d.data.name)\n .join('path')\n .attr('class', 'arc')\n .style('fill', d => d.data.color || colorScale(d.data.name).color);\n\n if (animate) {\n $paths\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .attrTween('d', function (this: SVGPathElement, d) {\n const self = this as ArcPathElement;\n // Interpolate from the last rendered angles to the new ones.\n // New (entering) arcs start collapsed at their startAngle.\n const prev: { startAngle: number; endAngle: number } =\n self._prevDatum ?? {\n startAngle: d.startAngle,\n endAngle: d.startAngle,\n };\n self._prevDatum = d;\n const iStart = interpolateNumber(prev.startAngle, d.startAngle);\n const iEnd = interpolateNumber(prev.endAngle, d.endAngle);\n return (t: number) =>\n doughnutArc({ ...d, startAngle: iStart(t), endAngle: iEnd(t) }) ??\n '';\n });\n } else {\n // Initial render: draw immediately and seed previous-datum for later tweens\n $paths\n .each(function (this: SVGPathElement, d) {\n (this as ArcPathElement)._prevDatum = d;\n })\n .attr('d', d => doughnutArc(d) ?? '');\n }\n\n // Animate the central total counter\n const $title = svg.select('.title');\n if (animate) {\n $title\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .tween('text', function (this: BaseType) {\n const sel = select(this as SVGTextElement);\n const start = parseFloat(sel.text()) || 0;\n const interp = interpolateNumber(start, total);\n return function (t: number) {\n sel.text(Math.round(interp(t)));\n };\n });\n } else {\n $title.text(total);\n }\n\n // Label polylines and text\n const $chartContainer = svg.select('.chart-container');\n\n if (this.showLabels) {\n const pointsFn = (d: PieArcDatum<ChartDoughnutItem>) => {\n const posA = doughnutArc.centroid(d);\n const posB = labelsArc.centroid(d);\n const posC = posB.slice() as [number, number];\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n posC[0] = radius * (midAngle < Math.PI ? 1 : -1);\n return [posA, posB, posC].map(p => p.join(',')).join(' ');\n };\n\n const transformFn = (d: PieArcDatum<ChartDoughnutItem>) => {\n const pos = labelsArc.centroid(d);\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n pos[0] = radius * (midAngle < Math.PI ? 1 : -1);\n return `translate(${pos})`;\n };\n\n const anchorFn = (d: PieArcDatum<ChartDoughnutItem>) => {\n const midAngle = d.startAngle + (d.endAngle - d.startAngle) / 2;\n return midAngle < Math.PI ? 'start' : 'end';\n };\n\n const $polylines = $chartContainer\n .selectAll<SVGPolylineElement, PieArcDatum<ChartDoughnutItem>>(\n '.item-polyline',\n )\n .data(pieData, d => d.data.name)\n .join('polyline')\n .attr('class', 'item-polyline');\n\n const $labels = $chartContainer\n .selectAll<SVGTextElement, PieArcDatum<ChartDoughnutItem>>('.item-label')\n .data(pieData, d => d.data.name)\n .join('text')\n .attr('class', 'item-label')\n .text(d => d.data.label ?? '');\n\n if (animate) {\n $polylines\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .attr('points', pointsFn);\n $labels\n .transition()\n .duration(DURATION)\n .ease(easeCubicInOut)\n .attr('transform', transformFn)\n .style('text-anchor', anchorFn);\n } else {\n $polylines.attr('points', pointsFn);\n $labels.attr('transform', transformFn).style('text-anchor', anchorFn);\n }\n } else {\n $chartContainer.selectAll('.item-polyline').remove();\n $chartContainer.selectAll('.item-label').remove();\n }\n }\n\n render() {\n return html`\n <div class=\"chart\">\n <svg>\n <g class=\"chart-container\">\n <g class=\"arc-container\"></g>\n <text class=\"title\" text-anchor=\"middle\"></text>\n <text class=\"label\" text-anchor=\"middle\" y=\"16\">\n ${this.label}\n </text>\n </g>\n </svg>\n </div>\n `;\n }\n}\n"],"names":["LitElement","scaleOrdinal","easeCubicInOut","html","styles","query","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,WAAW,GAAyB,EAAE;AAC5C,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,IAAG;IACzE,WAAW,CAAC,IAAI,CAAC;QACf,KAAK,EAAE,CAAA,YAAA,EAAe,SAAS,CAAA,CAAA,CAAG;AACnC,KAAA,CAAC;AACJ,CAAC,CAAC;AAOF,SAAS,QAAQ,CAAqC,EAAK,EAAE,IAAY,EAAA;AACvE,IAAA,IAAI,KAAoC;AACxC,IAAA,QAAQ,CAAC,GAAG,IAAW,KAAI;QACzB,YAAY,CAAC,KAAK,CAAC;AACnB,QAAA,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MAAA,CAAA;AAGW,UAAA,CAAA;IAA1CC,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAoB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAGlB,UAAA,CAAA;IAA1CA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAsB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAI/D,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE;AACzC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAGA,UAAA,CAAA;AAA1B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;AAAiC,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAG9B,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAiB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AApBhC,aAAa,GAAA,UAAA,CAAA;IADzB;AACY,CAAA,EAAA,aAAa,CAiOzB;;;;"}
|
package/dist/chart-pie.js
CHANGED
|
@@ -107,10 +107,10 @@ let ChartPie = class ChartPie extends i$1 {
|
|
|
107
107
|
return this.width / 2 - this.margin - 100;
|
|
108
108
|
}
|
|
109
109
|
_getPieData() {
|
|
110
|
-
const
|
|
110
|
+
const pieGenerator = pie()
|
|
111
111
|
.sort(null)
|
|
112
112
|
.value(d => d.value);
|
|
113
|
-
return
|
|
113
|
+
return pieGenerator(this.data);
|
|
114
114
|
}
|
|
115
115
|
_getColorScale() {
|
|
116
116
|
return ordinal()
|