@universal-material/web 3.0.53 → 3.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"field.styles.d.ts","sourceRoot":"","sources":["../../src/field/field.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,yBA+SlB,CAAC"}
1
+ {"version":3,"file":"field.styles.d.ts","sourceRoot":"","sources":["../../src/field/field.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,yBAgTlB,CAAC"}
@@ -103,6 +103,7 @@ export const styles = css `
103
103
  display: flex;
104
104
  align-items: center;
105
105
  flex: 1;
106
+ padding-block: var(--_vertical-padding);
106
107
  padding-inline: var(--_field-control-inline-padding);
107
108
  min-height: var(--_field-min-height);
108
109
  transition: opacity 150ms;
@@ -244,16 +245,16 @@ export const styles = css `
244
245
  :host([variant=filled]) .field::after {
245
246
  border-bottom-style: solid;
246
247
  }
248
+ :host([variant=filled]) .field:not(.no-label) .input-wrapper {
249
+ padding-top: calc(var(--_vertical-padding) + var(--_label-line-height));
250
+ padding-bottom: var(--_vertical-padding);
251
+ }
247
252
  :host([variant=filled]) .label {
248
253
  top: var(--_vertical-padding);
249
254
  }
250
255
  :host([variant=filled]) .input::slotted(:is(input, textarea, select, button)) {
251
256
  display: block;
252
257
  }
253
- :host([variant=filled]) .input-wrapper {
254
- padding-top: calc(var(--_vertical-padding) + var(--_label-line-height));
255
- padding-bottom: var(--_vertical-padding);
256
- }
257
258
 
258
259
  :host([variant=filled][disabled]) .field {
259
260
  background-color: var(--u-filled-field-disabled-background-color, rgba(var(--u-color-on-surface-rgb, 29, 27, 32), var(--u-filled-field-background-disabled-opacity, 0.04)));
@@ -1 +1 @@
1
- {"version":3,"file":"field.styles.js","sourceRoot":"","sources":["../../src/field/field.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+SzB,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const styles = css `\n :host {\n --_control-line-height: var(--u-field-control-line-height, 1.5rem);\n --_label-line-height: var(--u-field-label-line-height, 1rem);\n --_field-icon-size: var(--u-field-icon-size, 1.5rem);\n --_field-control-padding: var(--u-field-control-padding, 16px);\n --_field-control-inline-padding: var(--u-field-control-inline-padding, var(--_field-control-padding));\n --_field-control-block-padding: var(--u-field-control-block-padding, var(--_field-control-padding));\n --_field-min-height: var(--u-field-min-height, 56px);\n --_field-placeholder-color: var(--u-field-placeholder-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n --_disabled-color: var(--u-field-disabled-color, rgba(var(--u-color-on-surface-rgb, 29, 27, 32), var(--u-field-disabled-opacity, .38)));\n --_disabled-background-color: var(--u-filled-field-disabled-background-color, rgba(var(--u-color-on-surface-rgb, ), var(--u-filled-field-background-disabled-opacity, .12)));\n --_color-primary: var(--u-color-primary, rgb(103, 80, 164));\n --_color-error: var(--u-field-error-color, var(--u-color-error, rgb(179, 38, 30)));\n --_active-indicator-opacity: 1;\n --_vertical-padding: var(--u-field-vertical-padding, 8px);\n --_icon-size: var(--u-field-icon-size, 1.5rem);\n --_icon-padding: var(--u-field-icon-padding, 12px);\n --_icon-color: var(--u-icon-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n --_focus-border-width: var(--u-text-field-focus-border-width, 2px);\n --_field-control-leading-padding: var(--_field-control-inline-padding);\n --_outlined-label-margin: var(--u-outlined-field-label-margin, 12px);\n --_outlined-label-padding: var(--u-outlined-field-label-padding, 4px);\n --u-label-input-start: auto;\n --u-label-input-span-leading-offset: 0;\n --u-label-input-span-trailing-offset: 0;\n --u-text-field-horizontal-padding: 12px;\n }\n\n .field {\n display: flex;\n align-items: center;\n position: relative;\n }\n .field::before, .field::after {\n content: \"\";\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n pointer-events: none;\n }\n .field::before {\n background: var(--u-color-on-surface, rgb(29, 27, 32));\n transition: opacity 150ms;\n opacity: 0;\n }\n .field::after {\n border-width: var(--u-field-border-width, 1px);\n border-color: var(--u-field-border-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n }\n\n @media (hover: hover) {\n :host([variant=filled]:not([disabled]):not([invalid]):hover) .field::before {\n opacity: var(--u-state-hover-opacity, 0.08);\n }\n :host(:not([disabled]):not([invalid]):not(:focus-within):hover) .field::after {\n border-color: var(--u-field-hover-border-color, var(--u-color-on-surface, rgb(29, 27, 32)));\n }\n }\n .icon {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n width: var(--_icon-size);\n color: var(--_icon-color);\n font-size: var(--_icon-size);\n line-height: var(--_icon-size);\n }\n .icon::slotted(*) {\n flex-shrink: 0;\n }\n\n .leading-icon {\n margin-inline-start: var(--_icon-padding);\n }\n\n .trailing-icon {\n margin-inline-end: var(--_icon-padding);\n }\n\n .label {\n font-family: var(--u-font-family, var(--u-font-family, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", \"Noto Sans\", \"Liberation Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"));\n line-height: var(--u-field-label-line-height, var(--u-body-l-line-height, 1.5rem));\n font-size: var(--u-field-label-font-size, var(--u-body-l-font-size, 1rem));\n letter-spacing: var(--u-field-label-letter-spacing, var(--u-body-l-letter-spacing, 0.03125rem));\n font-weight: var(--u-field-label-font-weight, var(--u-body-l-font-weight, var(--u-font-weight-regular, 400)));\n font-size: var(--u-field-label-font-size, var(--u-body-s-font-size, 0.75rem));\n display: block;\n position: absolute;\n inset-inline-start: var(--_field-control-leading-padding);\n margin-bottom: 0;\n line-height: var(--_label-line-height);\n color: var(--u-field-label-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n transition: inset 200ms, font-size 200ms;\n }\n\n .input-wrapper {\n display: flex;\n align-items: center;\n flex: 1;\n padding-inline: var(--_field-control-inline-padding);\n min-height: var(--_field-min-height);\n transition: opacity 150ms;\n }\n\n .input {\n color: var(--u-field-input-text-color, var(--u-color-on-surface, rgb(29, 27, 32)));\n }\n .input:focus {\n outline: 0;\n }\n .input::slotted(*) {\n font-family: var(--u-font-family, var(--u-font-family, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", \"Noto Sans\", \"Liberation Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"));\n line-height: var(--u-field-control-line-height, var(--u-body-l-line-height, 1.5rem));\n font-size: var(--u-field-control-font-size, var(--u-body-l-font-size, 1rem));\n letter-spacing: var(--u-field-control-letter-spacing, var(--u-body-l-letter-spacing, 0.03125rem));\n font-weight: var(--u-field-control-font-weight, var(--u-body-l-font-weight, var(--u-font-weight-regular, 400)));\n width: 100%;\n color: var(--u-field-input-text-color, var(--u-color-on-surface, rgb(29, 27, 32)));\n min-height: var(--_control-line-height);\n line-height: var(--_control-line-height);\n padding: 0;\n margin: 0;\n appearance: none;\n background: transparent;\n border: none;\n outline: 0 !important;\n }\n .input, .input::slotted(select), .input::slotted(:is(input, textarea))::placeholder {\n transition: color 150ms 100ms;\n }\n .input::slotted(:is(input, textarea))::placeholder {\n color: var(--_field-placeholder-color);\n }\n\n .supporting-text {\n font-family: var(--u-font-family, var(--u-font-family, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", \"Noto Sans\", \"Liberation Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"));\n line-height: var(--u-field-supporting-text-line-height, var(--u-body-s-line-height, 1rem));\n font-size: var(--u-field-supporting-text-font-size, var(--u-body-s-font-size, 0.75rem));\n letter-spacing: var(--u-field-supporting-text-letter-spacing, var(--u-body-s-letter-spacing, 0.0333333333rem));\n font-weight: var(--u-field-supporting-text-font-weight, var(--u-body-s-font-weight, var(--u-font-weight-regular, 400)));\n display: flex;\n color: var(--u-field-supporting-text, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n padding-inline: 16px;\n gap: 16px;\n }\n .supporting-text .supporting-text-slot {\n display: block;\n }\n .supporting-text ::slotted(*) {\n display: inline-block;\n margin-top: 4px;\n }\n\n .error-text {\n display: none;\n }\n\n .counter {\n display: none;\n margin-inline-start: auto;\n }\n\n :host([has-counter]) .counter {\n display: block;\n }\n\n :host([has-leading-icon]) {\n --_field-control-leading-padding: calc(var(--_icon-padding) + var(--_icon-size) + var(--_field-control-inline-padding)) ;\n }\n\n :host(:not([has-leading-icon])) .leading-icon {\n display: none;\n }\n\n :host(:not([has-trailing-icon])) .trailing-icon {\n display: none;\n }\n\n :host(:focus-within) {\n --u-field-border-width: var(--_focus-border-width);\n }\n :host(:focus-within) .field::after {\n border-color: var(--u-field-focused-border-color, var(--_color-primary));\n }\n :host(:focus-within) .label {\n color: var(--u-field-label-focused-color, var(--_color-primary));\n }\n\n :host([invalid]) .field::after {\n border-color: var(--u-field-error-border-color, var(--_color-error));\n }\n :host([invalid]) .label {\n color: var(--u-field-label-error-color, var(--_color-error));\n }\n :host([invalid]) .supporting-text {\n color: var(--u-field-supporting-text-error-color, var(--_color-error));\n }\n :host([invalid]) .trailing-icon {\n color: var(--u-field-trailing-icon-error-color, var(--_color-error));\n }\n :host([invalid]) .leading-icon {\n color: var(--u-field-leading-icon-error-color, var(--_icon-color));\n }\n\n :host([invalid][has-error-text]) .error-text {\n display: block;\n }\n :host([invalid][has-error-text]) .supporting-text-slot {\n display: none;\n }\n\n :host([disabled]) .field::after {\n border-color: var(--u-field-disabled-border-color, var(--_disabled-color));\n }\n :host([disabled]) .supporting-text {\n color: var(--u-field-supporting-text-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .label {\n color: var(--u-field-label-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .input::slotted(*) {\n color: var(--u-field-input-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .input::slotted(:is(input, textarea))::placeholder {\n color: var(--u-field-input-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .trailing-icon {\n color: var(--u-field-trailing-icon-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .leading-icon {\n color: var(--u-field-leading-icon-disabled-color, var(--_disabled-color));\n }\n\n :host([variant=filled]) .field {\n border-radius: var(--u-field-filled-border-radius, 4px 4px 0 0);\n background-color: var(--u-color-surface-container-highest, rgb(230, 224, 233));\n }\n :host([variant=filled]) .field::after {\n border-bottom-style: solid;\n }\n :host([variant=filled]) .label {\n top: var(--_vertical-padding);\n }\n :host([variant=filled]) .input::slotted(:is(input, textarea, select, button)) {\n display: block;\n }\n :host([variant=filled]) .input-wrapper {\n padding-top: calc(var(--_vertical-padding) + var(--_label-line-height));\n padding-bottom: var(--_vertical-padding);\n }\n\n :host([variant=filled][disabled]) .field {\n background-color: var(--u-filled-field-disabled-background-color, rgba(var(--u-color-on-surface-rgb, 29, 27, 32), var(--u-filled-field-background-disabled-opacity, 0.04)));\n }\n\n :host([variant=outlined]) .field::after {\n --_mid-point: calc(var(--u-field-label-half-width) + var(--_outlined-label-margin) + var(--_outlined-label-padding));\n border-radius: var(--u-outlined-field-shape-corder, var(--u-shape-corner-small, 8px));\n border-style: solid;\n clip-path: polygon(0 0, var(--_mid-point) 0, var(--_mid-point) var(--_focus-border-width), var(--_mid-point) var(--_focus-border-width), var(--_mid-point) 0, 100% 0, 100% 100%, 0 100%);\n transition: clip-path 100ms;\n }\n :host([variant=outlined]) .label {\n top: calc(var(--_label-line-height) / -2);\n }\n\n :host([variant=outlined]:focus-within) .field::after,\n :host([variant=outlined]:not([empty])) .field::after {\n --_end-point: calc(var(--u-field-label-width) + var(--_outlined-label-margin) + (var(--_outlined-label-padding) * 2));\n clip-path: polygon(0 0, var(--_outlined-label-margin) 0, var(--_outlined-label-margin) var(--_focus-border-width), var(--_end-point) var(--_focus-border-width), var(--_end-point) 0, 100% 0, 100% 100%, 0 100%);\n }\n :host([variant=outlined]:focus-within) .label,\n :host([variant=outlined]:not([empty])) .label {\n inset-inline-start: calc(var(--_outlined-label-margin) + var(--_outlined-label-padding));\n }\n\n :host([empty]) ::slotted(select) {\n color: var(--_field-placeholder-color);\n }\n\n :host([empty]:not(:focus-within)) .label {\n font-size: var(--u-field-label-font-size, var(--u-body-l-font-size, 1rem));\n pointer-events: none;\n top: calc(var(--_field-min-height) / 2 - var(--_label-line-height) / 2);\n }\n :host([empty]:not(:focus-within)) .input-wrapper {\n opacity: 0;\n }\n :host([empty]:not(:focus-within)) .input,\n :host([empty]:not(:focus-within)) ::slotted(:is(input, textarea))::placeholder,\n :host([empty]:not(:focus-within)) ::slotted(select) {\n color: transparent;\n transition: color 150ms;\n }\n\n .field.no-label::after {\n clip-path: none !important;\n }\n`;\n"]}
1
+ {"version":3,"file":"field.styles.js","sourceRoot":"","sources":["../../src/field/field.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgTzB,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const styles = css `\n :host {\n --_control-line-height: var(--u-field-control-line-height, 1.5rem);\n --_label-line-height: var(--u-field-label-line-height, 1rem);\n --_field-icon-size: var(--u-field-icon-size, 1.5rem);\n --_field-control-padding: var(--u-field-control-padding, 16px);\n --_field-control-inline-padding: var(--u-field-control-inline-padding, var(--_field-control-padding));\n --_field-control-block-padding: var(--u-field-control-block-padding, var(--_field-control-padding));\n --_field-min-height: var(--u-field-min-height, 56px);\n --_field-placeholder-color: var(--u-field-placeholder-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n --_disabled-color: var(--u-field-disabled-color, rgba(var(--u-color-on-surface-rgb, 29, 27, 32), var(--u-field-disabled-opacity, .38)));\n --_disabled-background-color: var(--u-filled-field-disabled-background-color, rgba(var(--u-color-on-surface-rgb, ), var(--u-filled-field-background-disabled-opacity, .12)));\n --_color-primary: var(--u-color-primary, rgb(103, 80, 164));\n --_color-error: var(--u-field-error-color, var(--u-color-error, rgb(179, 38, 30)));\n --_active-indicator-opacity: 1;\n --_vertical-padding: var(--u-field-vertical-padding, 8px);\n --_icon-size: var(--u-field-icon-size, 1.5rem);\n --_icon-padding: var(--u-field-icon-padding, 12px);\n --_icon-color: var(--u-icon-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n --_focus-border-width: var(--u-text-field-focus-border-width, 2px);\n --_field-control-leading-padding: var(--_field-control-inline-padding);\n --_outlined-label-margin: var(--u-outlined-field-label-margin, 12px);\n --_outlined-label-padding: var(--u-outlined-field-label-padding, 4px);\n --u-label-input-start: auto;\n --u-label-input-span-leading-offset: 0;\n --u-label-input-span-trailing-offset: 0;\n --u-text-field-horizontal-padding: 12px;\n }\n\n .field {\n display: flex;\n align-items: center;\n position: relative;\n }\n .field::before, .field::after {\n content: \"\";\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n pointer-events: none;\n }\n .field::before {\n background: var(--u-color-on-surface, rgb(29, 27, 32));\n transition: opacity 150ms;\n opacity: 0;\n }\n .field::after {\n border-width: var(--u-field-border-width, 1px);\n border-color: var(--u-field-border-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n }\n\n @media (hover: hover) {\n :host([variant=filled]:not([disabled]):not([invalid]):hover) .field::before {\n opacity: var(--u-state-hover-opacity, 0.08);\n }\n :host(:not([disabled]):not([invalid]):not(:focus-within):hover) .field::after {\n border-color: var(--u-field-hover-border-color, var(--u-color-on-surface, rgb(29, 27, 32)));\n }\n }\n .icon {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n width: var(--_icon-size);\n color: var(--_icon-color);\n font-size: var(--_icon-size);\n line-height: var(--_icon-size);\n }\n .icon::slotted(*) {\n flex-shrink: 0;\n }\n\n .leading-icon {\n margin-inline-start: var(--_icon-padding);\n }\n\n .trailing-icon {\n margin-inline-end: var(--_icon-padding);\n }\n\n .label {\n font-family: var(--u-font-family, var(--u-font-family, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", \"Noto Sans\", \"Liberation Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"));\n line-height: var(--u-field-label-line-height, var(--u-body-l-line-height, 1.5rem));\n font-size: var(--u-field-label-font-size, var(--u-body-l-font-size, 1rem));\n letter-spacing: var(--u-field-label-letter-spacing, var(--u-body-l-letter-spacing, 0.03125rem));\n font-weight: var(--u-field-label-font-weight, var(--u-body-l-font-weight, var(--u-font-weight-regular, 400)));\n font-size: var(--u-field-label-font-size, var(--u-body-s-font-size, 0.75rem));\n display: block;\n position: absolute;\n inset-inline-start: var(--_field-control-leading-padding);\n margin-bottom: 0;\n line-height: var(--_label-line-height);\n color: var(--u-field-label-color, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n transition: inset 200ms, font-size 200ms;\n }\n\n .input-wrapper {\n display: flex;\n align-items: center;\n flex: 1;\n padding-block: var(--_vertical-padding);\n padding-inline: var(--_field-control-inline-padding);\n min-height: var(--_field-min-height);\n transition: opacity 150ms;\n }\n\n .input {\n color: var(--u-field-input-text-color, var(--u-color-on-surface, rgb(29, 27, 32)));\n }\n .input:focus {\n outline: 0;\n }\n .input::slotted(*) {\n font-family: var(--u-font-family, var(--u-font-family, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", \"Noto Sans\", \"Liberation Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"));\n line-height: var(--u-field-control-line-height, var(--u-body-l-line-height, 1.5rem));\n font-size: var(--u-field-control-font-size, var(--u-body-l-font-size, 1rem));\n letter-spacing: var(--u-field-control-letter-spacing, var(--u-body-l-letter-spacing, 0.03125rem));\n font-weight: var(--u-field-control-font-weight, var(--u-body-l-font-weight, var(--u-font-weight-regular, 400)));\n width: 100%;\n color: var(--u-field-input-text-color, var(--u-color-on-surface, rgb(29, 27, 32)));\n min-height: var(--_control-line-height);\n line-height: var(--_control-line-height);\n padding: 0;\n margin: 0;\n appearance: none;\n background: transparent;\n border: none;\n outline: 0 !important;\n }\n .input, .input::slotted(select), .input::slotted(:is(input, textarea))::placeholder {\n transition: color 150ms 100ms;\n }\n .input::slotted(:is(input, textarea))::placeholder {\n color: var(--_field-placeholder-color);\n }\n\n .supporting-text {\n font-family: var(--u-font-family, var(--u-font-family, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", \"Noto Sans\", \"Liberation Sans\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"));\n line-height: var(--u-field-supporting-text-line-height, var(--u-body-s-line-height, 1rem));\n font-size: var(--u-field-supporting-text-font-size, var(--u-body-s-font-size, 0.75rem));\n letter-spacing: var(--u-field-supporting-text-letter-spacing, var(--u-body-s-letter-spacing, 0.0333333333rem));\n font-weight: var(--u-field-supporting-text-font-weight, var(--u-body-s-font-weight, var(--u-font-weight-regular, 400)));\n display: flex;\n color: var(--u-field-supporting-text, var(--u-color-on-surface-variant, rgb(73, 69, 79)));\n padding-inline: 16px;\n gap: 16px;\n }\n .supporting-text .supporting-text-slot {\n display: block;\n }\n .supporting-text ::slotted(*) {\n display: inline-block;\n margin-top: 4px;\n }\n\n .error-text {\n display: none;\n }\n\n .counter {\n display: none;\n margin-inline-start: auto;\n }\n\n :host([has-counter]) .counter {\n display: block;\n }\n\n :host([has-leading-icon]) {\n --_field-control-leading-padding: calc(var(--_icon-padding) + var(--_icon-size) + var(--_field-control-inline-padding)) ;\n }\n\n :host(:not([has-leading-icon])) .leading-icon {\n display: none;\n }\n\n :host(:not([has-trailing-icon])) .trailing-icon {\n display: none;\n }\n\n :host(:focus-within) {\n --u-field-border-width: var(--_focus-border-width);\n }\n :host(:focus-within) .field::after {\n border-color: var(--u-field-focused-border-color, var(--_color-primary));\n }\n :host(:focus-within) .label {\n color: var(--u-field-label-focused-color, var(--_color-primary));\n }\n\n :host([invalid]) .field::after {\n border-color: var(--u-field-error-border-color, var(--_color-error));\n }\n :host([invalid]) .label {\n color: var(--u-field-label-error-color, var(--_color-error));\n }\n :host([invalid]) .supporting-text {\n color: var(--u-field-supporting-text-error-color, var(--_color-error));\n }\n :host([invalid]) .trailing-icon {\n color: var(--u-field-trailing-icon-error-color, var(--_color-error));\n }\n :host([invalid]) .leading-icon {\n color: var(--u-field-leading-icon-error-color, var(--_icon-color));\n }\n\n :host([invalid][has-error-text]) .error-text {\n display: block;\n }\n :host([invalid][has-error-text]) .supporting-text-slot {\n display: none;\n }\n\n :host([disabled]) .field::after {\n border-color: var(--u-field-disabled-border-color, var(--_disabled-color));\n }\n :host([disabled]) .supporting-text {\n color: var(--u-field-supporting-text-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .label {\n color: var(--u-field-label-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .input::slotted(*) {\n color: var(--u-field-input-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .input::slotted(:is(input, textarea))::placeholder {\n color: var(--u-field-input-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .trailing-icon {\n color: var(--u-field-trailing-icon-disabled-color, var(--_disabled-color));\n }\n :host([disabled]) .leading-icon {\n color: var(--u-field-leading-icon-disabled-color, var(--_disabled-color));\n }\n\n :host([variant=filled]) .field {\n border-radius: var(--u-field-filled-border-radius, 4px 4px 0 0);\n background-color: var(--u-color-surface-container-highest, rgb(230, 224, 233));\n }\n :host([variant=filled]) .field::after {\n border-bottom-style: solid;\n }\n :host([variant=filled]) .field:not(.no-label) .input-wrapper {\n padding-top: calc(var(--_vertical-padding) + var(--_label-line-height));\n padding-bottom: var(--_vertical-padding);\n }\n :host([variant=filled]) .label {\n top: var(--_vertical-padding);\n }\n :host([variant=filled]) .input::slotted(:is(input, textarea, select, button)) {\n display: block;\n }\n\n :host([variant=filled][disabled]) .field {\n background-color: var(--u-filled-field-disabled-background-color, rgba(var(--u-color-on-surface-rgb, 29, 27, 32), var(--u-filled-field-background-disabled-opacity, 0.04)));\n }\n\n :host([variant=outlined]) .field::after {\n --_mid-point: calc(var(--u-field-label-half-width) + var(--_outlined-label-margin) + var(--_outlined-label-padding));\n border-radius: var(--u-outlined-field-shape-corder, var(--u-shape-corner-small, 8px));\n border-style: solid;\n clip-path: polygon(0 0, var(--_mid-point) 0, var(--_mid-point) var(--_focus-border-width), var(--_mid-point) var(--_focus-border-width), var(--_mid-point) 0, 100% 0, 100% 100%, 0 100%);\n transition: clip-path 100ms;\n }\n :host([variant=outlined]) .label {\n top: calc(var(--_label-line-height) / -2);\n }\n\n :host([variant=outlined]:focus-within) .field::after,\n :host([variant=outlined]:not([empty])) .field::after {\n --_end-point: calc(var(--u-field-label-width) + var(--_outlined-label-margin) + (var(--_outlined-label-padding) * 2));\n clip-path: polygon(0 0, var(--_outlined-label-margin) 0, var(--_outlined-label-margin) var(--_focus-border-width), var(--_end-point) var(--_focus-border-width), var(--_end-point) 0, 100% 0, 100% 100%, 0 100%);\n }\n :host([variant=outlined]:focus-within) .label,\n :host([variant=outlined]:not([empty])) .label {\n inset-inline-start: calc(var(--_outlined-label-margin) + var(--_outlined-label-padding));\n }\n\n :host([empty]) ::slotted(select) {\n color: var(--_field-placeholder-color);\n }\n\n :host([empty]:not(:focus-within)) .label {\n font-size: var(--u-field-label-font-size, var(--u-body-l-font-size, 1rem));\n pointer-events: none;\n top: calc(var(--_field-min-height) / 2 - var(--_label-line-height) / 2);\n }\n :host([empty]:not(:focus-within)) .input-wrapper {\n opacity: 0;\n }\n :host([empty]:not(:focus-within)) .input,\n :host([empty]:not(:focus-within)) ::slotted(:is(input, textarea))::placeholder,\n :host([empty]:not(:focus-within)) ::slotted(select) {\n color: transparent;\n transition: color 150ms;\n }\n\n .field.no-label::after {\n clip-path: none !important;\n }\n`;\n"]}
package/menu/menu.d.ts CHANGED
@@ -8,31 +8,28 @@ export declare class UmMenu extends LitElement {
8
8
  */
9
9
  get open(): boolean;
10
10
  set open(open: boolean);
11
+ positioning: 'relative' | 'fixed';
11
12
  manualFocus: boolean;
12
13
  /**
13
14
  * The corner of the anchor which to align the menu in the standard logical
14
15
  * property style of <block>-<inline> e.g. `'end-start'`.
15
16
  */
16
- anchorCorner: 'start-start' | 'start-end' | 'end-start' | 'end-end';
17
+ anchorCorner: 'auto-start' | 'auto-end' | 'start-start' | 'start-end' | 'end-start' | 'end-end';
17
18
  /**
18
- * The direction of the menu. e.g. `'end'`.
19
+ * The direction of the menu. e.g. `'down-end'`.
19
20
  *
20
21
  * NOTE: This value may not be respected by the menu positioning algorithm
21
22
  * if the menu would render outside the viewport.
22
23
  */
23
- direction: 'start' | 'end';
24
+ direction: 'up-start' | 'up-end' | 'down-start' | 'down-end';
24
25
  /**
25
- * Limit the height of the menu to not overflow the viewport
26
+ * Don't limit the height of the menu
26
27
  */
27
- autoScrollBlock: boolean;
28
- /**
29
- * Set a selector to auto attach to a toggle element
30
- */
31
- get toggleSelector(): string | undefined;
32
- set toggleSelector(selector: string | undefined);
28
+ allowOverflow: boolean;
33
29
  menu: HTMLElement;
34
- get anchorElement(): HTMLElement;
35
- private toggleElement;
30
+ ref: HTMLElement;
31
+ get anchorElement(): HTMLElement | null | undefined;
32
+ set anchorElement(anchorElement: HTMLElement | null | undefined);
36
33
  protected render(): HTMLTemplateResult;
37
34
  connectedCallback(): void;
38
35
  disconnectedCallback(): void;
@@ -40,13 +37,8 @@ export declare class UmMenu extends LitElement {
40
37
  show(): void;
41
38
  close: () => void;
42
39
  private calcDropdownPositioning;
43
- private resetMenu;
44
- private setToOpenUpOrDown;
45
- private setToOpenToStartOrEnd;
46
- private ensureMenuCanOpenToStart;
47
- private ensureMenuCanOpenToEnd;
48
- private getAnchorRect;
49
- private getMenuRect;
40
+ private getMenuPosition;
41
+ private getMenuSize;
50
42
  }
51
43
  declare global {
52
44
  interface HTMLElementTagNameMap {
@@ -1 +1 @@
1
- {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/menu/menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,kBAAkB,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAM3D,OAAO,2BAA2B,CAAC;AASnC,qBACa,MAAO,SAAQ,UAAU;;IAEpC,OAAgB,MAAM,4BAAwB;IAK9C;;OAEG;IACH,IACI,IAAI,IAAI,OAAO,CAAsB;IACzC,IAAI,IAAI,CAAC,IAAI,EAAE,OAAO,EAYrB;IAE0B,WAAW,UAAS;IAE/C;;;OAGG;IACoD,YAAY,EAAE,aAAa,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,CAAe;IAEzI;;;;;O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e;IAE9G;;;;;OAKG;IACwB,SAAS,EAAE,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,UAAU,CAAc;IAErG;;OAEG;IACoE,aAAa,UAAS;IAE7E,IAAI,EAAG,WAAW,CAAC;IACpB,GAAG,EAAG,WAAW,CAAC;IAIjC,IAAI,aAAa,IAAI,WAAW,GAAG,IAAI,GAAG,SAAS,CAElD;IACD,IAAI,aAAa,CAAC,aAAa,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,EAE9D;cAEkB,MAAM,IAAI,kBAAkB;IAYtC,iBAAiB;IAQjB,oBAAoB;IAK7B,MAAM,aAOJ;IAEF,IAAI,IAAI,IAAI;IASZ,KAAK,aAOJ;IAED,OAAO,CAAC,uBAAuB;IA0J/B,OAAO,CAAC,eAAe;IAqDvB,OAAO,CAAC,WAAW;CAWpB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,QAAQ,EAAE,MAAM,CAAC;KAClB;CACF"}
package/menu/menu.js CHANGED
@@ -15,7 +15,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
15
15
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
16
16
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
17
  };
18
- var _UmMenu_open, _UmMenu_justShow;
18
+ var _UmMenu_instances, _UmMenu_open, _UmMenu_justShow, _UmMenu_anchorElement, _UmMenu_resetMenu, _UmMenu_setToOpenUpOrDown, _UmMenu_openBlockAuto, _UmMenu_tryOpenUp, _UmMenu_tryOpenDown, _UmMenu_openToLargestBlockSide, _UmMenu_setToOpenToStartOrEnd, _UmMenu_tryOpenLeft, _UmMenu_tryOpenRight, _UmMenu_openToLargestInlineSide, _UmMenu_openUp, _UmMenu_openDown;
19
19
  import { html, LitElement } from 'lit';
20
20
  import { customElement, property, query } from 'lit/decorators.js';
21
21
  import { styles as baseStyles } from '../shared/base.styles.js';
@@ -24,8 +24,10 @@ import '../elevation/elevation.js';
24
24
  let UmMenu = class UmMenu extends LitElement {
25
25
  constructor() {
26
26
  super(...arguments);
27
+ _UmMenu_instances.add(this);
27
28
  _UmMenu_open.set(this, false);
28
29
  _UmMenu_justShow.set(this, false);
30
+ this.positioning = 'relative';
29
31
  this.manualFocus = false;
30
32
  /**
31
33
  * The corner of the anchor which to align the menu in the standard logical
@@ -33,17 +35,17 @@ let UmMenu = class UmMenu extends LitElement {
33
35
  */
34
36
  this.anchorCorner = 'end-start';
35
37
  /**
36
- * The direction of the menu. e.g. `'end'`.
38
+ * The direction of the menu. e.g. `'down-end'`.
37
39
  *
38
40
  * NOTE: This value may not be respected by the menu positioning algorithm
39
41
  * if the menu would render outside the viewport.
40
42
  */
41
- this.direction = 'end';
43
+ this.direction = 'down-end';
42
44
  /**
43
- * Limit the height of the menu to not overflow the viewport
45
+ * Don't limit the height of the menu
44
46
  */
45
- this.autoScrollBlock = true;
46
- this.toggleElement = null;
47
+ this.allowOverflow = false;
48
+ _UmMenu_anchorElement.set(this, void 0);
47
49
  this.toggle = () => {
48
50
  if (this.open) {
49
51
  this.close();
@@ -74,25 +76,15 @@ let UmMenu = class UmMenu extends LitElement {
74
76
  setTimeout(() => this.querySelector('u-menu-item:not([disabled])')?.focus());
75
77
  }
76
78
  }
77
- /**
78
- * Set a selector to auto attach to a toggle element
79
- */
80
- get toggleSelector() {
81
- return this.attributes.getNamedItem('toggle-selector')?.value;
82
- }
83
- set toggleSelector(selector) {
84
- this.toggleElement?.removeEventListener('click', this.toggle);
85
- if (!selector) {
86
- return;
87
- }
88
- this.toggleElement = document.querySelector(selector);
89
- this.toggleElement?.addEventListener('click', this.toggle);
90
- }
91
79
  get anchorElement() {
92
- return this.parentElement;
80
+ return __classPrivateFieldGet(this, _UmMenu_anchorElement, "f") ?? this.parentElement ?? this.getRootNode().host;
81
+ }
82
+ set anchorElement(anchorElement) {
83
+ __classPrivateFieldSet(this, _UmMenu_anchorElement, anchorElement, "f");
93
84
  }
94
85
  render() {
95
86
  return html `
87
+ <div class="ref"></div>
96
88
  <div class="menu" part="menu" ?inert=${!this.open}>
97
89
  <u-elevation></u-elevation>
98
90
  <div role="menu" class="content" part="content">
@@ -120,75 +112,60 @@ let UmMenu = class UmMenu extends LitElement {
120
112
  this.open = true;
121
113
  }
122
114
  calcDropdownPositioning() {
123
- if (!this.parentElement) {
115
+ if (!this.anchorElement) {
124
116
  return;
125
117
  }
126
- const anchorRect = this.getAnchorRect();
127
- const menuRect = this.getMenuRect();
128
- this.resetMenu();
129
- this.setToOpenUpOrDown(anchorRect, menuRect);
130
- this.setToOpenToStartOrEnd(anchorRect, menuRect);
131
- }
132
- resetMenu() {
133
- this.menu.className = 'menu';
134
- this.menu.style.maxHeight = '';
118
+ const menuPosition = this.getMenuPosition();
119
+ const menuSize = this.getMenuSize();
120
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_resetMenu).call(this);
121
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_setToOpenUpOrDown).call(this, menuPosition, menuSize);
122
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_setToOpenToStartOrEnd).call(this, menuPosition, menuSize);
135
123
  }
136
- setToOpenUpOrDown(anchorRect, menuRect) {
137
- const viewPortHeight = window.innerHeight;
138
- if (viewPortHeight - (anchorRect.y + menuRect.height) >= 0) {
139
- return;
140
- }
141
- if (anchorRect.y <= viewPortHeight / 2) {
142
- this.menu.style.maxHeight = this.autoScrollBlock
143
- ? `${viewPortHeight - anchorRect.y}px`
144
- : '';
145
- return;
146
- }
147
- this.menu.classList.add('up');
148
- this.menu.style.maxHeight = this.autoScrollBlock
149
- ? `${anchorRect.y}px`
150
- : '';
151
- }
152
- setToOpenToStartOrEnd(anchorRect, menuRect) {
153
- if (this.direction === 'start') {
154
- this.ensureMenuCanOpenToStart(anchorRect, menuRect);
155
- return;
156
- }
157
- this.ensureMenuCanOpenToEnd(anchorRect, menuRect);
158
- }
159
- ensureMenuCanOpenToStart(anchorRect, menuRect) {
160
- const viewPortWidth = window.innerWidth;
161
- if (viewPortWidth - (anchorRect.x - menuRect.width) >= 0) {
162
- this.menu.classList.add('start');
163
- }
164
- }
165
- ensureMenuCanOpenToEnd(anchorRect, menuRect) {
124
+ getMenuPosition() {
166
125
  const viewPortWidth = window.innerWidth;
167
- if (viewPortWidth - (anchorRect.x + menuRect.width) >= 0) {
168
- return;
169
- }
170
- this.menu.classList.add('start');
171
- }
172
- getAnchorRect() {
126
+ const viewPortHeight = window.innerHeight;
173
127
  const anchorElement = this.anchorElement;
174
- const rect = anchorElement.getBoundingClientRect();
175
- const styles = getComputedStyle(anchorElement);
176
- const width = parseInt(styles.width, 10);
177
- const height = parseInt(styles.height, 10);
178
- const xOffset = this.anchorCorner.endsWith('-end')
179
- ? width
180
- : 0;
181
- const yOffset = this.anchorCorner.startsWith('end-')
182
- ? height
183
- : 0;
128
+ const anchorRect = anchorElement.getBoundingClientRect();
129
+ const refRect = this.ref.getBoundingClientRect();
130
+ const anchorStyles = getComputedStyle(anchorElement);
131
+ const isRtl = anchorStyles.direction === 'rtl';
132
+ const width = parseInt(anchorStyles.width, 10);
133
+ const height = parseInt(anchorStyles.height, 10);
134
+ const rectX = refRect.left;
135
+ const rectY = refRect.top;
136
+ const leftPoint = {
137
+ left: anchorRect.left,
138
+ right: viewPortWidth - anchorRect.left,
139
+ relativeX: anchorRect.left - rectX
140
+ };
141
+ const rightPoint = {
142
+ left: anchorRect.right,
143
+ right: viewPortWidth - anchorRect.right,
144
+ relativeX: leftPoint.relativeX + width
145
+ };
146
+ const topPoint = {
147
+ top: anchorRect.top,
148
+ relativeY: anchorRect.top - rectY,
149
+ bottom: viewPortHeight - anchorRect.top
150
+ };
151
+ const anchorBounds = {
152
+ top: topPoint,
153
+ bottom: {
154
+ top: anchorRect.bottom,
155
+ relativeY: topPoint.relativeY + height,
156
+ bottom: viewPortHeight - anchorRect.bottom
157
+ },
158
+ start: isRtl ? rightPoint : leftPoint,
159
+ end: isRtl ? leftPoint : rightPoint,
160
+ width,
161
+ height
162
+ };
184
163
  return {
185
- y: rect.y + yOffset,
186
- x: rect.x + xOffset,
187
- width: width,
188
- height: height
164
+ isRtl: isRtl,
165
+ bounds: anchorBounds
189
166
  };
190
167
  }
191
- getMenuRect() {
168
+ getMenuSize() {
192
169
  const menu = this.menu;
193
170
  const styles = getComputedStyle(menu);
194
171
  const width = parseInt(styles.width, 10);
@@ -201,10 +178,122 @@ let UmMenu = class UmMenu extends LitElement {
201
178
  };
202
179
  _UmMenu_open = new WeakMap();
203
180
  _UmMenu_justShow = new WeakMap();
181
+ _UmMenu_anchorElement = new WeakMap();
182
+ _UmMenu_instances = new WeakSet();
183
+ _UmMenu_resetMenu = function _UmMenu_resetMenu() {
184
+ this.menu.className = 'menu';
185
+ this.menu.style.top = '';
186
+ this.menu.style.bottom = '';
187
+ this.menu.style.left = '';
188
+ this.menu.style.right = '';
189
+ this.menu.style.maxHeight = '';
190
+ };
191
+ _UmMenu_setToOpenUpOrDown = function _UmMenu_setToOpenUpOrDown(menuPosition, menuSize) {
192
+ if (this.anchorCorner.startsWith('auto-')) {
193
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openBlockAuto).call(this, menuPosition, menuSize);
194
+ return;
195
+ }
196
+ const side = this.anchorCorner.startsWith('start-')
197
+ ? menuPosition.bounds.top
198
+ : menuPosition.bounds.bottom;
199
+ if (this.direction.startsWith('up-')) {
200
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_tryOpenUp).call(this, side, menuSize);
201
+ return;
202
+ }
203
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_tryOpenDown).call(this, side, menuSize);
204
+ };
205
+ _UmMenu_openBlockAuto = function _UmMenu_openBlockAuto(menuPosition, menuSize) {
206
+ const topSide = menuPosition.bounds.top;
207
+ const bottomSide = menuPosition.bounds.bottom;
208
+ const viewPortHeight = window.innerHeight;
209
+ if (bottomSide.bottom >= topSide.top || viewPortHeight - (bottomSide.top + menuSize.height) >= 0) {
210
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openDown).call(this, bottomSide);
211
+ return;
212
+ }
213
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openUp).call(this, topSide);
214
+ };
215
+ _UmMenu_tryOpenUp = function _UmMenu_tryOpenUp(side, menuSize) {
216
+ if (side.top === side.bottom || side.top - menuSize.height >= 0) {
217
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openUp).call(this, side);
218
+ return;
219
+ }
220
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openToLargestBlockSide).call(this, side);
221
+ };
222
+ _UmMenu_tryOpenDown = function _UmMenu_tryOpenDown(side, menuSize) {
223
+ const viewPortHeight = window.innerHeight;
224
+ if (side.top === side.bottom || viewPortHeight - (side.top + menuSize.height) >= 0) {
225
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openDown).call(this, side);
226
+ return;
227
+ }
228
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openToLargestBlockSide).call(this, side);
229
+ };
230
+ _UmMenu_openToLargestBlockSide = function _UmMenu_openToLargestBlockSide(side) {
231
+ if (side.top > side.bottom) {
232
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openUp).call(this, side);
233
+ return;
234
+ }
235
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openDown).call(this, side);
236
+ };
237
+ _UmMenu_setToOpenToStartOrEnd = function _UmMenu_setToOpenToStartOrEnd(menuPosition, menuSize) {
238
+ const openStart = menuPosition.isRtl
239
+ ? __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_tryOpenRight).bind(this)
240
+ : __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_tryOpenLeft).bind(this);
241
+ const openEnd = menuPosition.isRtl
242
+ ? __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_tryOpenLeft).bind(this)
243
+ : __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_tryOpenRight).bind(this);
244
+ const side = this.anchorCorner.endsWith('-start')
245
+ ? menuPosition.bounds.start
246
+ : menuPosition.bounds.end;
247
+ if (this.direction.endsWith('-start')) {
248
+ openStart(side, menuSize);
249
+ return;
250
+ }
251
+ openEnd(side, menuSize);
252
+ };
253
+ _UmMenu_tryOpenLeft = function _UmMenu_tryOpenLeft(side, menuSize) {
254
+ if (side.left === side.right || side.left - menuSize.width >= 0) {
255
+ this.menu.style.right = `${side.relativeX * -1}px`;
256
+ return;
257
+ }
258
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openToLargestInlineSide).call(this, side);
259
+ };
260
+ _UmMenu_tryOpenRight = function _UmMenu_tryOpenRight(side, menuSize) {
261
+ const viewPortWidth = window.innerWidth;
262
+ if (side.left === side.right || viewPortWidth - (side.left + menuSize.width) >= 0) {
263
+ this.menu.style.left = `${side.relativeX}px`;
264
+ return;
265
+ }
266
+ __classPrivateFieldGet(this, _UmMenu_instances, "m", _UmMenu_openToLargestInlineSide).call(this, side);
267
+ };
268
+ _UmMenu_openToLargestInlineSide = function _UmMenu_openToLargestInlineSide(side) {
269
+ if (side.left > side.right) {
270
+ this.menu.style.right = `${side.relativeX * -1}px`;
271
+ return;
272
+ }
273
+ this.menu.style.left = `${side.relativeX}px`;
274
+ };
275
+ _UmMenu_openUp = function _UmMenu_openUp(side) {
276
+ const viewPortHeight = window.innerHeight;
277
+ this.menu.style.bottom = `${side.relativeY * -1}px`;
278
+ this.menu.classList.add('up');
279
+ this.menu.style.maxHeight = this.allowOverflow
280
+ ? ''
281
+ : `${viewPortHeight - side.bottom}px`;
282
+ };
283
+ _UmMenu_openDown = function _UmMenu_openDown(side) {
284
+ const viewPortHeight = window.innerHeight;
285
+ this.menu.style.top = `${side.relativeY}px`;
286
+ this.menu.style.maxHeight = this.allowOverflow
287
+ ? ''
288
+ : `${viewPortHeight - side.top}px`;
289
+ };
204
290
  UmMenu.styles = [baseStyles, styles];
205
291
  __decorate([
206
292
  property({ type: Boolean, reflect: true })
207
293
  ], UmMenu.prototype, "open", null);
294
+ __decorate([
295
+ property({ reflect: true })
296
+ ], UmMenu.prototype, "positioning", void 0);
208
297
  __decorate([
209
298
  property({ type: Boolean })
210
299
  ], UmMenu.prototype, "manualFocus", void 0);
@@ -215,14 +304,14 @@ __decorate([
215
304
  property({ reflect: true })
216
305
  ], UmMenu.prototype, "direction", void 0);
217
306
  __decorate([
218
- property({ type: Boolean, attribute: 'auto-scroll-block', reflect: true })
219
- ], UmMenu.prototype, "autoScrollBlock", void 0);
220
- __decorate([
221
- property({ attribute: 'toggle-selector', reflect: true })
222
- ], UmMenu.prototype, "toggleSelector", null);
307
+ property({ type: Boolean, attribute: 'allow-overflow', reflect: true })
308
+ ], UmMenu.prototype, "allowOverflow", void 0);
223
309
  __decorate([
224
310
  query('.menu')
225
311
  ], UmMenu.prototype, "menu", void 0);
312
+ __decorate([
313
+ query('.ref')
314
+ ], UmMenu.prototype, "ref", void 0);
226
315
  UmMenu = __decorate([
227
316
  customElement('u-menu')
228
317
  ], UmMenu);
package/menu/menu.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/menu/menu.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAsB,UAAU,EAAE,MAAM,KAAK,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,2BAA2B,CAAC;AAU5B,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,UAAU;IAA/B;;QAIL,uBAAQ,KAA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C;4CAGvD;AAYe;IAAf,KAAK,CAAC,OAAO,CAAC;oCAAoB;AAjExB,MAAM;IADlB,aAAa,CAAC,QAAQ,CAAC;GACX,MAAM,CA8NlB","sourcesContent":["import { html, HTMLTemplateResult, LitElement } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\n\nimport { styles as baseStyles } from '../shared/base.styles.js';\nimport { styles } from './menu.styles.js';\n\nimport '../elevation/elevation.js';\n\ninterface MenuRect {\n x?: number;\n y?: number;\n width: number;\n height: number;\n}\n\n@customElement('u-menu')\nexport class UmMenu extends LitElement {\n\n static override styles = [baseStyles, styles];\n\n #open = false;\n #justShow = false;\n\n /**\n * Opens the menu and makes it visible. Alternative to the `.show()`, `.close()` and `.toggle()` methods\n */\n @property({type: Boolean, reflect: true})\n get open(): boolean { return this.#open }\n set open(open: boolean) {\n if (!open) {\n this.#open = open;\n return;\n }\n \n this.calcDropdownPositioning();\n this.#open = open;\n\n if (!this.manualFocus) {\n setTimeout(() => this.querySelector<HTMLElement>('u-menu-item:not([disabled])')?.focus());\n }\n }\n\n @property({type: Boolean}) manualFocus = false;\n\n /**\n * The corner of the anchor which to align the menu in the standard logical\n * property style of <block>-<inline> e.g. `'end-start'`.\n */\n @property({attribute: 'anchor-corner', reflect: true}) anchorCorner: 'start-start' | 'start-end' | 'end-start' | 'end-end' = 'end-start';\n\n /**\n * The direction of the menu. e.g. `'end'`.\n *\n * NOTE: This value may not be respected by the menu positioning algorithm\n * if the menu would render outside the viewport.\n */\n @property({reflect: true}) direction: 'start' | 'end' = 'end';\n\n /**\n * Limit the height of the menu to not overflow the viewport\n */\n @property({type: Boolean, attribute: 'auto-scroll-block', reflect: true}) autoScrollBlock = true;\n\n /**\n * Set a selector to auto attach to a toggle element\n */\n @property({attribute: 'toggle-selector', reflect: true})\n get toggleSelector(): string | undefined {\n return this.attributes.getNamedItem('toggle-selector')?.value;\n }\n set toggleSelector(selector: string | undefined) {\n this.toggleElement?.removeEventListener('click', this.toggle);\n\n if (!selector) {\n return;\n }\n\n this.toggleElement = document.querySelector(selector);\n this.toggleElement?.addEventListener('click', this.toggle);\n }\n\n @query('.menu') menu!: HTMLElement;\n\n get anchorElement(): HTMLElement {\n return this.parentElement!;\n }\n\n private toggleElement: HTMLElement | null = null;\n\n protected override render(): HTMLTemplateResult {\n return html`\n <div class=\"menu\" part=\"menu\" ?inert=${!this.open}>\n <u-elevation></u-elevation>\n <div role=\"menu\" class=\"content\" part=\"content\">\n <slot></slot>\n </div>\n </div>\n `;\n }\n\n override connectedCallback() {\n super.connectedCallback();\n window.addEventListener('click', this.close);\n this.role = \"listbox\";\n // eslint-disable-next-line no-self-assign\n this.open = this.open;\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n window.removeEventListener('click', this.close);\n }\n\n toggle = () => {\n if (this.open) {\n this.close();\n return;\n }\n\n this.show();\n };\n\n show(): void {\n if (this.open) {\n return;\n }\n\n this.#justShow = true;\n this.open = true;\n }\n\n close = () => {\n if (this.open && !this.#justShow) {\n this.open = false;\n return;\n }\n\n this.#justShow = false;\n }\n\n private calcDropdownPositioning() {\n if (!this.parentElement) {\n return;\n }\n\n const anchorRect = this.getAnchorRect();\n const menuRect = this.getMenuRect()\n\n this.resetMenu();\n this.setToOpenUpOrDown(anchorRect, menuRect);\n this.setToOpenToStartOrEnd(anchorRect, menuRect);\n }\n\n private resetMenu() {\n this.menu.className = 'menu';\n this.menu.style.maxHeight = '';\n }\n\n private setToOpenUpOrDown(anchorRect: MenuRect, menuRect: MenuRect): void {\n const viewPortHeight = window.innerHeight;\n\n if (viewPortHeight - (anchorRect.y! + menuRect.height) >= 0) {\n return;\n }\n\n if (anchorRect.y! <= viewPortHeight / 2) {\n this.menu.style.maxHeight = this.autoScrollBlock\n ? `${viewPortHeight - anchorRect.y!}px`\n : '';\n return;\n }\n\n this.menu.classList.add('up');\n this.menu.style.maxHeight = this.autoScrollBlock\n ? `${anchorRect.y!}px`\n : '';\n }\n\n private setToOpenToStartOrEnd(anchorRect: MenuRect, menuRect: MenuRect): void {\n if (this.direction === 'start') {\n this.ensureMenuCanOpenToStart(anchorRect, menuRect);\n return;\n }\n\n this.ensureMenuCanOpenToEnd(anchorRect, menuRect);\n }\n\n private ensureMenuCanOpenToStart(anchorRect: MenuRect, menuRect: MenuRect): void {\n const viewPortWidth = window.innerWidth;\n\n if (viewPortWidth - (anchorRect.x! - menuRect.width) >= 0) {\n this.menu.classList.add('start');\n }\n }\n\n private ensureMenuCanOpenToEnd(anchorRect: MenuRect, menuRect: MenuRect): void {\n const viewPortWidth = window.innerWidth;\n\n if (viewPortWidth - (anchorRect.x! + menuRect.width) >= 0) {\n return;\n }\n\n this.menu.classList.add('start');\n }\n\n private getAnchorRect(): MenuRect {\n const anchorElement = this.anchorElement;\n const rect = anchorElement.getBoundingClientRect() as DOMRect\n const styles = getComputedStyle(anchorElement);\n const width = parseInt(styles.width, 10);\n const height = parseInt(styles.height, 10);\n const xOffset = this.anchorCorner.endsWith('-end')\n ? width\n : 0;\n\n const yOffset = this.anchorCorner.startsWith('end-')\n ? height\n : 0;\n\n return {\n y: rect.y + yOffset,\n x: rect.x + xOffset,\n width: width,\n height: height\n };\n }\n\n private getMenuRect(): MenuRect {\n const menu = this.menu;\n const styles = getComputedStyle(menu);\n const width = parseInt(styles.width, 10);\n const height = parseInt(styles.height, 10);\n\n return {\n width: width,\n height: height\n };\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'u-menu': UmMenu;\n }\n}\n"]}
1
+ {"version":3,"file":"menu.js","sourceRoot":"","sources":["../../src/menu/menu.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAsB,UAAU,EAAE,MAAM,KAAK,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,MA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ADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;kCACA;AAed;IAA1B,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;2CAAgD;AAE/C;IAA1B,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;2CAAqB;AAO/C;IADC,QAAQ,CAAC,EAAC,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;4CACwD;AAQnF;IAA1B,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;yCAA2E;AAK9B;IAAtE,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CAAuB;AAE7E;IAAf,KAAK,CAAC,OAAO,CAAC;oCAAoB;AACpB;IAAd,KAAK,CAAC,MAAM,CAAC;mCAAmB;AAnDtB,MAAM;IADlB,aAAa,CAAC,QAAQ,CAAC;GACX,MAAM,CA4UlB","sourcesContent":["import { html, HTMLTemplateResult, LitElement } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\n\nimport { styles as baseStyles } from '../shared/base.styles.js';\nimport { styles } from './menu.styles.js';\n\nimport '../elevation/elevation.js';\n\ninterface AnchorCornerBlockSide {\n top: number;\n bottom: number;\n relativeY: number;\n}\n\ninterface AnchorCornerInlineSide {\n left: number;\n right: number;\n relativeX: number;\n}\n\ninterface AnchorBounds {\n top: AnchorCornerBlockSide;\n bottom: AnchorCornerBlockSide;\n start: AnchorCornerInlineSide;\n end: AnchorCornerInlineSide;\n width: number;\n height: number;\n}\n\ninterface MenuPosition {\n bounds: AnchorBounds;\n isRtl: boolean;\n}\n\ninterface MenuSize {\n width: number;\n height: number;\n}\n\n@customElement('u-menu')\nexport class UmMenu extends LitElement {\n\n static override styles = [baseStyles, styles];\n\n #open = false;\n #justShow = false;\n\n /**\n * Opens the menu and makes it visible. Alternative to the `.show()`, `.close()` and `.toggle()` methods\n */\n @property({type: Boolean, reflect: true})\n get open(): boolean { return this.#open }\n set open(open: boolean) {\n if (!open) {\n this.#open = open;\n return;\n }\n \n this.calcDropdownPositioning();\n this.#open = open;\n\n if (!this.manualFocus) {\n setTimeout(() => this.querySelector<HTMLElement>('u-menu-item:not([disabled])')?.focus());\n }\n }\n\n @property({reflect: true}) positioning: 'relative' | 'fixed' = 'relative';\n\n @property({type: Boolean}) manualFocus = false;\n\n /**\n * The corner of the anchor which to align the menu in the standard logical\n * property style of <block>-<inline> e.g. `'end-start'`.\n */\n @property({attribute: 'anchor-corner', reflect: true})\n anchorCorner: 'auto-start' | 'auto-end' | 'start-start' | 'start-end' | 'end-start' | 'end-end' = 'end-start';\n\n /**\n * The direction of the menu. e.g. `'down-end'`.\n *\n * NOTE: This value may not be respected by the menu positioning algorithm\n * if the menu would render outside the viewport.\n */\n @property({reflect: true}) direction: 'up-start' | 'up-end' | 'down-start' | 'down-end' = 'down-end';\n\n /**\n * Don't limit the height of the menu\n */\n @property({type: Boolean, attribute: 'allow-overflow', reflect: true}) allowOverflow = false;\n\n @query('.menu') menu!: HTMLElement;\n @query('.ref') ref!: HTMLElement;\n\n #anchorElement: HTMLElement | null | undefined;\n\n get anchorElement(): HTMLElement | null | undefined {\n return this.#anchorElement ?? this.parentElement! ?? (<ShadowRoot>this.getRootNode()).host;\n }\n set anchorElement(anchorElement: HTMLElement | null | undefined) {\n this.#anchorElement = anchorElement;\n }\n\n protected override render(): HTMLTemplateResult {\n return html`\n <div class=\"ref\"></div>\n <div class=\"menu\" part=\"menu\" ?inert=${!this.open}>\n <u-elevation></u-elevation>\n <div role=\"menu\" class=\"content\" part=\"content\">\n <slot></slot>\n </div>\n </div>\n `;\n }\n\n override connectedCallback() {\n super.connectedCallback();\n window.addEventListener('click', this.close);\n this.role = \"listbox\";\n // eslint-disable-next-line no-self-assign\n this.open = this.open;\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n window.removeEventListener('click', this.close);\n }\n\n toggle = () => {\n if (this.open) {\n this.close();\n return;\n }\n\n this.show();\n };\n\n show(): void {\n if (this.open) {\n return;\n }\n\n this.#justShow = true;\n this.open = true;\n }\n\n close = () => {\n if (this.open && !this.#justShow) {\n this.open = false;\n return;\n }\n\n this.#justShow = false;\n }\n\n private calcDropdownPositioning() {\n if (!this.anchorElement) {\n return;\n }\n\n const menuPosition = this.getMenuPosition();\n const menuSize = this.getMenuSize()\n\n this.#resetMenu();\n this.#setToOpenUpOrDown(menuPosition, menuSize);\n this.#setToOpenToStartOrEnd(menuPosition, menuSize);\n }\n\n #resetMenu() {\n this.menu.className = 'menu';\n this.menu.style.top = '';\n this.menu.style.bottom = '';\n this.menu.style.left = '';\n this.menu.style.right = '';\n this.menu.style.maxHeight = '';\n }\n\n #setToOpenUpOrDown(menuPosition: MenuPosition, menuSize: MenuSize): void {\n if (this.anchorCorner.startsWith('auto-')) {\n this.#openBlockAuto(menuPosition, menuSize);\n return;\n }\n\n const side = this.anchorCorner.startsWith('start-')\n ? menuPosition.bounds.top\n : menuPosition.bounds.bottom;\n\n if (this.direction.startsWith('up-')) {\n this.#tryOpenUp(side, menuSize);\n return;\n }\n\n this.#tryOpenDown(side, menuSize);\n }\n\n #openBlockAuto(menuPosition: MenuPosition, menuSize: MenuSize): void {\n const topSide = menuPosition.bounds.top;\n const bottomSide = menuPosition.bounds.bottom;\n\n const viewPortHeight = window.innerHeight;\n\n if (bottomSide.bottom >= topSide.top || viewPortHeight - (bottomSide.top + menuSize.height) >= 0) {\n this.#openDown(bottomSide);\n return;\n }\n\n this.#openUp(topSide);\n }\n\n #tryOpenUp(side: AnchorCornerBlockSide, menuSize: MenuSize): void {\n\n if (side.top === side.bottom || side.top - menuSize.height >= 0) {\n this.#openUp(side);\n return;\n }\n\n this.#openToLargestBlockSide(side);\n }\n\n #tryOpenDown(side: AnchorCornerBlockSide, menuSize: MenuSize): void {\n\n const viewPortHeight = window.innerHeight;\n\n if (side.top === side.bottom || viewPortHeight - (side.top + menuSize.height) >= 0) {\n this.#openDown(side);\n return;\n }\n\n this.#openToLargestBlockSide(side);\n }\n\n #openToLargestBlockSide(side: AnchorCornerBlockSide) {\n if (side.top > side.bottom) {\n this.#openUp(side);\n return;\n }\n\n this.#openDown(side);\n }\n\n #setToOpenToStartOrEnd(menuPosition: MenuPosition, menuSize: MenuSize): void {\n const openStart = menuPosition.isRtl\n ? this.#tryOpenRight.bind(this)\n : this.#tryOpenLeft.bind(this);\n const openEnd = menuPosition.isRtl\n ? this.#tryOpenLeft.bind(this)\n : this.#tryOpenRight.bind(this);\n\n const side = this.anchorCorner.endsWith('-start')\n ? menuPosition.bounds.start\n : menuPosition.bounds.end;\n\n if (this.direction.endsWith('-start')) {\n openStart(side, menuSize);\n return;\n }\n\n openEnd(side, menuSize);\n }\n\n #tryOpenLeft(side: AnchorCornerInlineSide, menuSize: MenuSize): void {\n\n if (side.left === side.right || side.left - menuSize.width >= 0) {\n this.menu.style.right = `${side.relativeX * -1}px`;\n return;\n }\n\n this.#openToLargestInlineSide(side);\n }\n\n #tryOpenRight(side: AnchorCornerInlineSide, menuSize: MenuSize): void {\n\n const viewPortWidth = window.innerWidth;\n\n if (side.left === side.right || viewPortWidth - (side.left + menuSize.width) >= 0) {\n this.menu.style.left = `${side.relativeX}px`;\n return;\n }\n\n this.#openToLargestInlineSide(side);\n }\n\n #openToLargestInlineSide(side: AnchorCornerInlineSide) {\n if (side.left > side.right) {\n this.menu.style.right = `${side.relativeX * -1}px`;\n return;\n }\n\n this.menu.style.left = `${side.relativeX}px`;\n }\n\n #openUp(side: AnchorCornerBlockSide) {\n const viewPortHeight = window.innerHeight;\n\n this.menu.style.bottom = `${side.relativeY * -1}px`;\n this.menu.classList.add('up');\n this.menu.style.maxHeight = this.allowOverflow\n ? ''\n : `${viewPortHeight - side.bottom}px`;\n }\n\n #openDown(side: AnchorCornerBlockSide) {\n const viewPortHeight = window.innerHeight;\n this.menu.style.top = `${side.relativeY}px`;\n this.menu.style.maxHeight = this.allowOverflow\n ? ''\n : `${viewPortHeight - side.top}px`;\n }\n\n private getMenuPosition(): MenuPosition {\n const viewPortWidth = window.innerWidth;\n const viewPortHeight = window.innerHeight;\n\n const anchorElement = this.anchorElement!;\n const anchorRect = anchorElement.getBoundingClientRect() as DOMRect\n const refRect = this.ref.getBoundingClientRect() as DOMRect\n const anchorStyles = getComputedStyle(anchorElement);\n const isRtl = anchorStyles.direction === 'rtl';\n\n const width = parseInt(anchorStyles.width, 10);\n const height = parseInt(anchorStyles.height, 10);\n\n const rectX = refRect.left;\n const rectY = refRect.top;\n\n const leftPoint: AnchorCornerInlineSide = {\n left: anchorRect.left,\n right: viewPortWidth - anchorRect.left,\n relativeX: anchorRect.left - rectX\n };\n\n const rightPoint: AnchorCornerInlineSide = {\n left: anchorRect.right,\n right: viewPortWidth - anchorRect.right,\n relativeX: leftPoint.relativeX + width\n };\n\n const topPoint: AnchorCornerBlockSide = {\n top: anchorRect.top,\n relativeY: anchorRect.top - rectY,\n bottom: viewPortHeight - anchorRect.top\n };\n\n const anchorBounds: AnchorBounds = {\n top: topPoint,\n bottom: {\n top: anchorRect.bottom,\n relativeY: topPoint.relativeY + height,\n bottom: viewPortHeight - anchorRect.bottom\n },\n start: isRtl ? rightPoint : leftPoint,\n end: isRtl ? leftPoint : rightPoint,\n width,\n height\n }\n\n return {\n isRtl: isRtl,\n bounds: anchorBounds\n };\n }\n\n private getMenuSize(): MenuSize {\n const menu = this.menu;\n const styles = getComputedStyle(menu);\n const width = parseInt(styles.width, 10);\n const height = parseInt(styles.height, 10);\n\n return {\n width: width,\n height: height\n };\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'u-menu': UmMenu;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"menu.styles.d.ts","sourceRoot":"","sources":["../../src/menu/menu.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,yBA4FlB,CAAC"}
1
+ {"version":3,"file":"menu.styles.d.ts","sourceRoot":"","sources":["../../src/menu/menu.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,yBAwDlB,CAAC"}