@vonage/vivid 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/accordion-item/definition.js +1 -1
  2. package/alert/definition.cjs +1 -1
  3. package/alert/definition.js +2 -2
  4. package/badge/definition.js +1 -1
  5. package/banner/definition.js +1 -1
  6. package/bundled/calendar-picker.template.cjs +7 -7
  7. package/bundled/calendar-picker.template.js +101 -101
  8. package/bundled/definition11.cjs +13 -13
  9. package/bundled/definition11.js +202 -50
  10. package/bundled/definition19.cjs +24 -25
  11. package/bundled/definition19.js +152 -164
  12. package/bundled/definition6.cjs +3 -3
  13. package/bundled/definition6.js +19 -19
  14. package/bundled/definition9.cjs +5 -5
  15. package/bundled/definition9.js +394 -392
  16. package/bundled/listbox.cjs +1 -1
  17. package/bundled/listbox.js +82 -102
  18. package/bundled/localized.cjs +1 -1
  19. package/bundled/localized.js +18 -14
  20. package/bundled/vivid-element.cjs +5 -1
  21. package/bundled/vivid-element.js +401 -358
  22. package/calendar/index.cjs +1 -1
  23. package/calendar/index.js +14 -14
  24. package/card/definition.cjs +1 -1
  25. package/card/definition.js +1 -1
  26. package/color-picker/definition.cjs +1 -1
  27. package/color-picker/definition.js +1 -1
  28. package/combobox/definition.cjs +7 -27
  29. package/combobox/definition.js +8 -28
  30. package/combobox/index.cjs +6 -6
  31. package/combobox/index.js +57 -71
  32. package/custom-elements.json +305 -2
  33. package/date-picker/definition.cjs +1 -1
  34. package/date-picker/definition.js +1 -1
  35. package/date-range-picker/definition.cjs +1 -1
  36. package/date-range-picker/definition.js +1 -1
  37. package/date-time-picker/definition.cjs +1 -1
  38. package/date-time-picker/definition.js +1 -1
  39. package/dialog/definition.cjs +2 -2
  40. package/dialog/definition.js +2 -2
  41. package/dialog/index.cjs +7 -7
  42. package/dialog/index.js +6 -6
  43. package/elevation/definition.cjs +1 -1
  44. package/elevation/definition.js +1 -1
  45. package/fab/definition.js +1 -1
  46. package/header/definition.cjs +1 -1
  47. package/header/definition.js +1 -1
  48. package/index.cjs +3 -4
  49. package/index.js +2 -3
  50. package/lib/accordion/accordion.d.ts +1 -1
  51. package/lib/accordion/definition.d.ts +1 -1
  52. package/lib/audio-player/audio-player.d.ts +1 -1
  53. package/lib/combobox/combobox.d.ts +1 -0
  54. package/lib/combobox/combobox.options.d.ts +1 -1
  55. package/lib/divider/divider.d.ts +1 -1
  56. package/lib/menu-item/menu-item-role.d.ts +1 -1
  57. package/lib/popup/popup.d.ts +1 -1
  58. package/lib/searchable-select/locale.d.ts +4 -0
  59. package/lib/searchable-select/searchable-select.d.ts +3 -0
  60. package/lib/select/select.d.ts +3 -1
  61. package/lib/slider/slider.d.ts +1 -1
  62. package/lib/tabs/tabs.d.ts +2 -2
  63. package/lib/text-area/text-area.d.ts +1 -1
  64. package/lib/text-field/text-field.d.ts +1 -1
  65. package/locales/de-DE.cjs +4 -0
  66. package/locales/de-DE.js +4 -0
  67. package/locales/en-GB.cjs +4 -0
  68. package/locales/en-GB.js +4 -0
  69. package/locales/en-US.cjs +4 -0
  70. package/locales/en-US.js +4 -0
  71. package/locales/ja-JP.cjs +4 -0
  72. package/locales/ja-JP.js +4 -0
  73. package/locales/zh-CN.cjs +4 -0
  74. package/locales/zh-CN.js +4 -0
  75. package/menu/definition.cjs +4 -4
  76. package/menu/definition.js +4 -4
  77. package/nav-disclosure/definition.js +1 -1
  78. package/nav-item/definition.js +1 -1
  79. package/note/definition.js +1 -1
  80. package/number-field/definition.js +1 -1
  81. package/option/definition.cjs +6 -77
  82. package/option/definition.js +3 -78
  83. package/package.json +31 -5
  84. package/popup/definition.cjs +2 -2
  85. package/popup/definition.js +2 -2
  86. package/range-slider/definition.cjs +1 -1
  87. package/range-slider/definition.js +1 -1
  88. package/rich-text-editor/definition.cjs +2 -3
  89. package/rich-text-editor/definition.js +1 -2
  90. package/rich-text-editor/index.cjs +27 -27
  91. package/rich-text-editor/index.js +1208 -1198
  92. package/searchable-select/definition.cjs +103 -11
  93. package/searchable-select/definition.js +103 -11
  94. package/searchable-select/index.cjs +81 -69
  95. package/searchable-select/index.js +359 -273
  96. package/select/definition.cjs +24 -41
  97. package/select/definition.js +24 -41
  98. package/selectable-box/definition.cjs +1 -1
  99. package/selectable-box/definition.js +1 -1
  100. package/selectable-box/index.cjs +1 -1
  101. package/selectable-box/index.js +1 -1
  102. package/shared/aria/aria-mixin.d.ts +1 -1
  103. package/shared/foundation/listbox/listbox.d.ts +4 -0
  104. package/simple-color-picker/definition.cjs +1 -1
  105. package/simple-color-picker/definition.js +1 -1
  106. package/slider/definition.cjs +1 -1
  107. package/slider/definition.js +1 -1
  108. package/split-button/definition.js +1 -1
  109. package/styles/core/all.css +1 -1
  110. package/styles/core/theme.css +1 -1
  111. package/styles/core/typography.css +1 -1
  112. package/styles/tokens/theme-dark.css +4 -4
  113. package/styles/tokens/theme-light.css +4 -4
  114. package/styles/tokens/vivid-2-compat.css +1 -1
  115. package/tab/definition.js +1 -1
  116. package/tag/definition.js +1 -1
  117. package/text-field/definition.js +1 -1
  118. package/time-picker/definition.cjs +1 -1
  119. package/time-picker/definition.js +1 -1
  120. package/toggletip/definition.cjs +1 -1
  121. package/toggletip/definition.js +1 -1
  122. package/tooltip/definition.cjs +1 -1
  123. package/tooltip/definition.js +1 -1
  124. package/tree-item/definition.cjs +1 -1
  125. package/tree-item/definition.js +1 -1
  126. package/tree-view/definition.cjs +1 -1
  127. package/tree-view/definition.js +1 -1
  128. package/unbundled/affix.js +1 -1
  129. package/unbundled/calendar-picker.template.cjs +1 -1
  130. package/unbundled/calendar-picker.template.js +1 -1
  131. package/unbundled/definition.js +1 -1
  132. package/unbundled/definition2.js +1 -1
  133. package/unbundled/definition3.cjs +222 -141
  134. package/unbundled/definition3.js +220 -139
  135. package/unbundled/definition4.cjs +145 -235
  136. package/unbundled/definition4.js +143 -233
  137. package/unbundled/definition5.cjs +269 -27
  138. package/unbundled/definition5.js +267 -26
  139. package/unbundled/definition6.cjs +56 -0
  140. package/unbundled/definition6.js +52 -0
  141. package/unbundled/listbox.cjs +41 -63
  142. package/unbundled/listbox.js +39 -61
  143. package/unbundled/picker-field.template.cjs +1 -1
  144. package/unbundled/picker-field.template.js +1 -1
  145. package/unbundled/slider.template.cjs +1 -1
  146. package/unbundled/slider.template.js +1 -1
  147. package/unbundled/vivid-element.cjs +1 -1
  148. package/unbundled/vivid-element.js +1 -1
  149. package/video-player/definition.cjs +56 -16
  150. package/video-player/definition.js +56 -16
  151. package/video-player/index.cjs +36 -36
  152. package/video-player/index.js +2461 -2445
  153. package/vivid.api.json +285 -38
  154. package/bundled/option.cjs +0 -1
  155. package/bundled/option.js +0 -158
  156. package/unbundled/option.cjs +0 -217
  157. package/unbundled/option.js +0 -214
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ const button_definition = require('./definition.cjs');
4
+ const elevation_definition = require('./definition6.cjs');
3
5
  const vividElement = require('./vivid-element.cjs');
4
6
  const fastElement = require('@microsoft/fast-element');
7
+ const dom = require('@floating-ui/dom');
5
8
  const fastWebUtilities = require('@microsoft/fast-web-utilities');
6
9
 
7
10
  var __defProp = Object.defineProperty;
@@ -13,44 +16,283 @@ var __decorateClass = (decorators, target, key, kind) => {
13
16
  if (result) __defProp(target, key, result);
14
17
  return result;
15
18
  };
16
- class Elevation extends vividElement.VividElement {
19
+ const PlacementStrategy = {
20
+ Flip: "flip",
21
+ AutoPlacementHorizontal: "auto-placement-horizontal",
22
+ AutoPlacementVertical: "auto-placement-vertical"
23
+ };
24
+ const placementStrategyMiddlewares = {
25
+ [PlacementStrategy.Flip]: dom.flip(),
26
+ [PlacementStrategy.AutoPlacementHorizontal]: dom.autoPlacement({
27
+ allowedPlacements: [
28
+ "bottom",
29
+ "top",
30
+ "bottom-start",
31
+ "bottom-end",
32
+ "top-start",
33
+ "top-end"
34
+ ]
35
+ }),
36
+ [PlacementStrategy.AutoPlacementVertical]: dom.autoPlacement({
37
+ allowedPlacements: [
38
+ "left",
39
+ "right",
40
+ "left-start",
41
+ "left-end",
42
+ "right-start",
43
+ "right-end"
44
+ ]
45
+ })
46
+ };
47
+ class Popup extends vividElement.VividElement {
48
+ constructor() {
49
+ super(...arguments);
50
+ this.open = false;
51
+ this.dismissible = false;
52
+ this.arrow = false;
53
+ this.alternate = false;
54
+ /**
55
+ * The placement strategy of the popup.
56
+ *
57
+ * @public
58
+ */
59
+ this.placementStrategy = PlacementStrategy.Flip;
60
+ this.animationFrame = false;
61
+ this.strategy = "fixed";
62
+ this.offset = null;
63
+ this.#autoUpdateCallback = () => {
64
+ this.#lastPositionUpdate = this.updatePosition();
65
+ return this.#lastPositionUpdate;
66
+ };
67
+ }
68
+ get #middleware() {
69
+ let middleware = [
70
+ dom.inline(),
71
+ placementStrategyMiddlewares[this.placementStrategy],
72
+ dom.hide(),
73
+ dom.size({
74
+ apply({ availableWidth, availableHeight, elements }) {
75
+ Object.assign(elements.floating.style, {
76
+ maxWidth: `${availableWidth}px`,
77
+ maxHeight: `${availableHeight}px`
78
+ });
79
+ }
80
+ })
81
+ ];
82
+ let offsetValue = this.offset ?? 0;
83
+ if (this.arrow) {
84
+ offsetValue += 12;
85
+ middleware = [
86
+ ...middleware,
87
+ dom.arrow({ element: this.arrowEl, padding: 10 })
88
+ ];
89
+ }
90
+ if (offsetValue > 0) {
91
+ middleware.unshift(dom.offset(offsetValue));
92
+ }
93
+ return middleware;
94
+ }
95
+ #cleanup;
96
+ openChanged(_, newValue) {
97
+ this.#togglePopover();
98
+ this.#updateAutoUpdate();
99
+ this.$emit(newValue ? "vwc-popup:open" : "vwc-popup:close");
100
+ }
101
+ /**
102
+ * @internal
103
+ */
104
+ animationFrameChanged() {
105
+ this.#updateAutoUpdate();
106
+ }
107
+ /**
108
+ * @internal
109
+ */
110
+ anchorChanged() {
111
+ this.#updateAutoUpdate();
112
+ }
113
+ /**
114
+ * @internal
115
+ */
116
+ strategyChanged() {
117
+ this.#togglePopover();
118
+ }
119
+ connectedCallback() {
120
+ super.connectedCallback();
121
+ this.#togglePopover();
122
+ this.#updateAutoUpdate();
123
+ }
124
+ disconnectedCallback() {
125
+ super.disconnectedCallback();
126
+ this.#updateAutoUpdate();
127
+ }
128
+ #updateAutoUpdate() {
129
+ this.#cleanup?.();
130
+ if (this.open && this.controlEl) {
131
+ this.controlEl.classList.add("open");
132
+ }
133
+ if (this.anchorEl && this.open && this.popupEl) {
134
+ this.#cleanup = dom.autoUpdate(
135
+ this.anchorEl,
136
+ this.popupEl,
137
+ this.#autoUpdateCallback,
138
+ {
139
+ animationFrame: this.animationFrame
140
+ }
141
+ );
142
+ }
143
+ }
144
+ #togglePopover() {
145
+ if (this.popupEl && this.strategy === "fixed") {
146
+ if (this.open) {
147
+ this.popupEl.showPopover();
148
+ } else {
149
+ this.popupEl.hidePopover();
150
+ }
151
+ }
152
+ }
153
+ #lastPositionUpdate;
154
+ #autoUpdateCallback;
155
+ /**
156
+ * Updates popup's position
157
+ *
158
+ * @public
159
+ */
160
+ async updatePosition() {
161
+ if (!this.open || !this.anchorEl) {
162
+ return;
163
+ }
164
+ const positionData = await dom.computePosition(this.anchorEl, this.popupEl, {
165
+ placement: this.placement,
166
+ strategy: this.strategy,
167
+ middleware: this.#middleware
168
+ });
169
+ this.#assignPopupPosition(positionData);
170
+ if (this.arrow) {
171
+ this.#assignArrowPosition(positionData);
172
+ }
173
+ }
174
+ #assignPopupPosition(data) {
175
+ const { x: popupX, y: popupY } = data;
176
+ const { referenceHidden } = data.middlewareData.hide;
177
+ Object.assign(this.popupEl.style, {
178
+ left: `${popupX}px`,
179
+ top: `${popupY}px`,
180
+ visibility: referenceHidden ? "hidden" : "visible"
181
+ });
182
+ }
183
+ #assignArrowPosition(data) {
184
+ const { x: arrowX, y: arrowY } = data.middlewareData.arrow;
185
+ const styles = {
186
+ left: "calc(100% - 4px)",
187
+ right: "-4px",
188
+ top: "calc(100% - 4px)",
189
+ bottom: "-4px"
190
+ };
191
+ const staticAxis = data.placement.split("-")[0];
192
+ Object.assign(this.arrowEl.style, {
193
+ left: arrowX ? `${arrowX}px` : styles[staticAxis],
194
+ top: arrowY ? `${arrowY}px` : styles[staticAxis]
195
+ });
196
+ }
197
+ get anchorEl() {
198
+ return this.anchor ?? null;
199
+ }
200
+ /**
201
+ * Shows the popup.
202
+ * Unlike toggling the `open` attribute, show() will wait for the popup to become visible and positioned correctly.
203
+ */
204
+ show() {
205
+ this.open = true;
206
+ return this.#lastPositionUpdate ?? Promise.resolve();
207
+ }
208
+ hide() {
209
+ this.open = false;
210
+ }
17
211
  }
18
212
  __decorateClass([
19
- fastElement.attr
20
- ], Elevation.prototype, "dp");
213
+ fastElement.attr({
214
+ mode: "boolean"
215
+ })
216
+ ], Popup.prototype, "open");
217
+ __decorateClass([
218
+ fastElement.attr({
219
+ mode: "boolean"
220
+ })
221
+ ], Popup.prototype, "dismissible");
222
+ __decorateClass([
223
+ fastElement.attr({
224
+ mode: "boolean"
225
+ })
226
+ ], Popup.prototype, "arrow");
21
227
  __decorateClass([
22
- fastElement.attr({ attribute: "no-shadow", mode: "boolean" })
23
- ], Elevation.prototype, "noShadow");
228
+ fastElement.attr({
229
+ mode: "boolean"
230
+ })
231
+ ], Popup.prototype, "alternate");
24
232
  __decorateClass([
25
- fastElement.attr({ attribute: "not-relative", mode: "boolean" })
26
- ], Elevation.prototype, "notRelative");
233
+ fastElement.attr({ mode: "fromView" })
234
+ ], Popup.prototype, "placement");
235
+ __decorateClass([
236
+ fastElement.attr({ mode: "boolean", attribute: "animation-frame" })
237
+ ], Popup.prototype, "animationFrame");
238
+ __decorateClass([
239
+ fastElement.attr({ mode: "fromView" })
240
+ ], Popup.prototype, "strategy");
241
+ __decorateClass([
242
+ fastElement.attr({ attribute: "offset", converter: fastElement.nullableNumberConverter })
243
+ ], Popup.prototype, "offset");
244
+ __decorateClass([
245
+ fastElement.observable
246
+ ], Popup.prototype, "anchor");
27
247
 
28
- const styles = ":host{display:contents}.control{display:contents}.control.dp-0{--_elevation-fill: var(--_vvd-tinted-color-surface-0dp, var(--vvd-color-surface-0dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-0dp, var(--vvd-shadow-surface-0dp))}.control.dp-4{--_elevation-fill: var(--_vvd-tinted-color-surface-4dp, var(--vvd-color-surface-4dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-4dp, var(--vvd-shadow-surface-4dp))}.control.dp-8{--_elevation-fill: var(--_vvd-tinted-color-surface-8dp, var(--vvd-color-surface-8dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-8dp, var(--vvd-shadow-surface-8dp))}.control.dp-12{--_elevation-fill: var(--_vvd-tinted-color-surface-12dp, var(--vvd-color-surface-12dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-12dp, var(--vvd-shadow-surface-12dp))}.control.dp-16{--_elevation-fill: var(--_vvd-tinted-color-surface-16dp, var(--vvd-color-surface-16dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-16dp, var(--vvd-shadow-surface-16dp))}.control.dp-24{--_elevation-fill: var(--_vvd-tinted-color-surface-24dp, var(--vvd-color-surface-24dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-24dp, var(--vvd-shadow-surface-24dp))}.control:not(.dp-0,.dp-4,.dp-8,.dp-12,.dp-16,.dp-24){--_elevation-fill: var(--_vvd-tinted-color-surface-2dp, var(--vvd-color-surface-2dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-2dp, var(--vvd-shadow-surface-2dp))}.control ::slotted(*){isolation:isolate}.control ::slotted(*):before{position:absolute;z-index:-1;border-radius:inherit;background:var(--_elevation-fill);block-size:100%;content:\"\";filter:var(--_elevation-shadow);inline-size:100%;inset-block-start:0;inset-inline-start:0;transition:background-color .15s linear,filter .15s linear}.control:not(.not-relative) ::slotted(*){position:relative}.control.no-shadow ::slotted(*):before{filter:none}";
248
+ const styles = ":host{display:var(--_popup-display, inline)}.control{border-radius:inherit;background:var(--vvd-color-surface-4dp);contain:layout}.control:not(.open){display:none}.popup-wrapper{white-space:initial;--scrollbar-track-color: transparent;--scrollbar-thumb-color: color-mix(in srgb, var(--vvd-color-neutral-950), transparent 70%)}.popup-wrapper{scrollbar-color:var(--scrollbar-thumb-color) var(--scrollbar-track-color);scrollbar-width:thin}.popup-wrapper ::-webkit-scrollbar{width:4px}.popup-wrapper ::-webkit-scrollbar-track{background:var(--scrollbar-track-color)}.popup-wrapper ::-webkit-scrollbar-thumb{border:0;border-radius:4px;background-color:var(--scrollbar-fallback-track-color, var(--scrollbar-thumb-color))}.popup-wrapper{z-index:var(--_popup-z-index, 10);overflow:visible;padding:0;border:none;border-radius:8px;margin:0;inline-size:max-content}.popup-wrapper:not(.absolute){position:fixed}.popup-wrapper.absolute{position:absolute;top:0;left:0}.popup-content{display:grid;color:var(--vvd-color-canvas-text)}.dismissible .popup-content{align-content:start;grid-template-columns:1fr auto}.arrow{position:absolute;z-index:-1;width:8px;height:8px;background:var(--vvd-color-surface-4dp);transform:rotate(45deg)}.dismissible-button{align-self:flex-start;margin-block-start:4px;margin-inline-end:4px}";
29
249
 
30
- const getClasses = ({ dp, noShadow, notRelative }) => fastWebUtilities.classNames(
250
+ const getClasses = ({ open, dismissible, alternate }) => fastWebUtilities.classNames(
31
251
  "control",
32
- [`dp-${dp}`, Boolean(dp)],
33
- ["no-shadow", Boolean(noShadow)],
34
- ["not-relative", Boolean(notRelative)]
252
+ ["open", Boolean(open)],
253
+ ["dismissible", Boolean(dismissible)],
254
+ ["alternate", Boolean(alternate)]
35
255
  );
36
- const elevationTemplate = fastElement.html` <div
37
- class="${getClasses}"
38
- part="base"
39
- >
40
- <slot></slot>
41
- </div>`;
256
+ function handlePopover(x) {
257
+ return x.strategy && x.strategy === "fixed" ? "manual" : null;
258
+ }
259
+ const popupTemplate = (context) => {
260
+ const elevationTag = context.tagFor(elevation_definition.Elevation);
261
+ const buttonTag = context.tagFor(button_definition.Button);
262
+ return fastElement.html`
263
+ <${elevationTag}>
264
+ <div popover="${handlePopover}" class="popup-wrapper ${(x) => x.strategy}" ${fastElement.ref("popupEl")} part="popup-base">
265
+ <div ${fastElement.ref("controlEl")} class="${getClasses}" aria-hidden="${(x) => x.open ? "false" : "true"}"
266
+ part="${(x) => x.alternate ? "vvd-theme-alternate" : ""}">
267
+ <div class="popup-content">
268
+ <slot></slot>
269
+ ${fastElement.when(
270
+ (x) => x.dismissible,
271
+ fastElement.html`<${buttonTag} size="condensed" @click="${(x) => x.open = false}"
272
+ class="dismissible-button" icon="close-small-solid" shape="pill"></${buttonTag}>`
273
+ )}
274
+ </div>
275
+ ${fastElement.when(
276
+ (x) => x.arrow,
277
+ fastElement.html`<div class="arrow" ${fastElement.ref("arrowEl")}></div>`
278
+ )}
279
+ </div>
280
+ </div>
281
+ </${elevationTag}>`;
282
+ };
42
283
 
43
- const elevationDefinition = vividElement.defineVividComponent(
44
- "elevation",
45
- Elevation,
46
- elevationTemplate,
47
- [],
284
+ const popupDefinition = vividElement.defineVividComponent(
285
+ "popup",
286
+ Popup,
287
+ popupTemplate,
288
+ [elevation_definition.elevationDefinition, button_definition.buttonDefinition],
48
289
  {
49
290
  styles
50
291
  }
51
292
  );
52
- const registerElevation = vividElement.createRegisterFunction(elevationDefinition);
293
+ const registerPopup = vividElement.createRegisterFunction(popupDefinition);
53
294
 
54
- exports.Elevation = Elevation;
55
- exports.elevationDefinition = elevationDefinition;
56
- exports.registerElevation = registerElevation;
295
+ exports.PlacementStrategy = PlacementStrategy;
296
+ exports.Popup = Popup;
297
+ exports.popupDefinition = popupDefinition;
298
+ exports.registerPopup = registerPopup;
@@ -1,5 +1,8 @@
1
+ import { B as Button, b as buttonDefinition } from './definition.js';
2
+ import { E as Elevation, e as elevationDefinition } from './definition6.js';
1
3
  import { V as VividElement, d as defineVividComponent, c as createRegisterFunction } from './vivid-element.js';
2
- import { attr, html } from '@microsoft/fast-element';
4
+ import { attr, nullableNumberConverter, observable, ref, when, html } from '@microsoft/fast-element';
5
+ import { inline, autoPlacement, flip, hide, size, arrow, offset, autoUpdate, computePosition } from '@floating-ui/dom';
3
6
  import { classNames } from '@microsoft/fast-web-utilities';
4
7
 
5
8
  var __defProp = Object.defineProperty;
@@ -11,42 +14,280 @@ var __decorateClass = (decorators, target, key, kind) => {
11
14
  if (result) __defProp(target, key, result);
12
15
  return result;
13
16
  };
14
- class Elevation extends VividElement {
17
+ const PlacementStrategy = {
18
+ Flip: "flip",
19
+ AutoPlacementHorizontal: "auto-placement-horizontal",
20
+ AutoPlacementVertical: "auto-placement-vertical"
21
+ };
22
+ const placementStrategyMiddlewares = {
23
+ [PlacementStrategy.Flip]: flip(),
24
+ [PlacementStrategy.AutoPlacementHorizontal]: autoPlacement({
25
+ allowedPlacements: [
26
+ "bottom",
27
+ "top",
28
+ "bottom-start",
29
+ "bottom-end",
30
+ "top-start",
31
+ "top-end"
32
+ ]
33
+ }),
34
+ [PlacementStrategy.AutoPlacementVertical]: autoPlacement({
35
+ allowedPlacements: [
36
+ "left",
37
+ "right",
38
+ "left-start",
39
+ "left-end",
40
+ "right-start",
41
+ "right-end"
42
+ ]
43
+ })
44
+ };
45
+ class Popup extends VividElement {
46
+ constructor() {
47
+ super(...arguments);
48
+ this.open = false;
49
+ this.dismissible = false;
50
+ this.arrow = false;
51
+ this.alternate = false;
52
+ /**
53
+ * The placement strategy of the popup.
54
+ *
55
+ * @public
56
+ */
57
+ this.placementStrategy = PlacementStrategy.Flip;
58
+ this.animationFrame = false;
59
+ this.strategy = "fixed";
60
+ this.offset = null;
61
+ this.#autoUpdateCallback = () => {
62
+ this.#lastPositionUpdate = this.updatePosition();
63
+ return this.#lastPositionUpdate;
64
+ };
65
+ }
66
+ get #middleware() {
67
+ let middleware = [
68
+ inline(),
69
+ placementStrategyMiddlewares[this.placementStrategy],
70
+ hide(),
71
+ size({
72
+ apply({ availableWidth, availableHeight, elements }) {
73
+ Object.assign(elements.floating.style, {
74
+ maxWidth: `${availableWidth}px`,
75
+ maxHeight: `${availableHeight}px`
76
+ });
77
+ }
78
+ })
79
+ ];
80
+ let offsetValue = this.offset ?? 0;
81
+ if (this.arrow) {
82
+ offsetValue += 12;
83
+ middleware = [
84
+ ...middleware,
85
+ arrow({ element: this.arrowEl, padding: 10 })
86
+ ];
87
+ }
88
+ if (offsetValue > 0) {
89
+ middleware.unshift(offset(offsetValue));
90
+ }
91
+ return middleware;
92
+ }
93
+ #cleanup;
94
+ openChanged(_, newValue) {
95
+ this.#togglePopover();
96
+ this.#updateAutoUpdate();
97
+ this.$emit(newValue ? "vwc-popup:open" : "vwc-popup:close");
98
+ }
99
+ /**
100
+ * @internal
101
+ */
102
+ animationFrameChanged() {
103
+ this.#updateAutoUpdate();
104
+ }
105
+ /**
106
+ * @internal
107
+ */
108
+ anchorChanged() {
109
+ this.#updateAutoUpdate();
110
+ }
111
+ /**
112
+ * @internal
113
+ */
114
+ strategyChanged() {
115
+ this.#togglePopover();
116
+ }
117
+ connectedCallback() {
118
+ super.connectedCallback();
119
+ this.#togglePopover();
120
+ this.#updateAutoUpdate();
121
+ }
122
+ disconnectedCallback() {
123
+ super.disconnectedCallback();
124
+ this.#updateAutoUpdate();
125
+ }
126
+ #updateAutoUpdate() {
127
+ this.#cleanup?.();
128
+ if (this.open && this.controlEl) {
129
+ this.controlEl.classList.add("open");
130
+ }
131
+ if (this.anchorEl && this.open && this.popupEl) {
132
+ this.#cleanup = autoUpdate(
133
+ this.anchorEl,
134
+ this.popupEl,
135
+ this.#autoUpdateCallback,
136
+ {
137
+ animationFrame: this.animationFrame
138
+ }
139
+ );
140
+ }
141
+ }
142
+ #togglePopover() {
143
+ if (this.popupEl && this.strategy === "fixed") {
144
+ if (this.open) {
145
+ this.popupEl.showPopover();
146
+ } else {
147
+ this.popupEl.hidePopover();
148
+ }
149
+ }
150
+ }
151
+ #lastPositionUpdate;
152
+ #autoUpdateCallback;
153
+ /**
154
+ * Updates popup's position
155
+ *
156
+ * @public
157
+ */
158
+ async updatePosition() {
159
+ if (!this.open || !this.anchorEl) {
160
+ return;
161
+ }
162
+ const positionData = await computePosition(this.anchorEl, this.popupEl, {
163
+ placement: this.placement,
164
+ strategy: this.strategy,
165
+ middleware: this.#middleware
166
+ });
167
+ this.#assignPopupPosition(positionData);
168
+ if (this.arrow) {
169
+ this.#assignArrowPosition(positionData);
170
+ }
171
+ }
172
+ #assignPopupPosition(data) {
173
+ const { x: popupX, y: popupY } = data;
174
+ const { referenceHidden } = data.middlewareData.hide;
175
+ Object.assign(this.popupEl.style, {
176
+ left: `${popupX}px`,
177
+ top: `${popupY}px`,
178
+ visibility: referenceHidden ? "hidden" : "visible"
179
+ });
180
+ }
181
+ #assignArrowPosition(data) {
182
+ const { x: arrowX, y: arrowY } = data.middlewareData.arrow;
183
+ const styles = {
184
+ left: "calc(100% - 4px)",
185
+ right: "-4px",
186
+ top: "calc(100% - 4px)",
187
+ bottom: "-4px"
188
+ };
189
+ const staticAxis = data.placement.split("-")[0];
190
+ Object.assign(this.arrowEl.style, {
191
+ left: arrowX ? `${arrowX}px` : styles[staticAxis],
192
+ top: arrowY ? `${arrowY}px` : styles[staticAxis]
193
+ });
194
+ }
195
+ get anchorEl() {
196
+ return this.anchor ?? null;
197
+ }
198
+ /**
199
+ * Shows the popup.
200
+ * Unlike toggling the `open` attribute, show() will wait for the popup to become visible and positioned correctly.
201
+ */
202
+ show() {
203
+ this.open = true;
204
+ return this.#lastPositionUpdate ?? Promise.resolve();
205
+ }
206
+ hide() {
207
+ this.open = false;
208
+ }
15
209
  }
16
210
  __decorateClass([
17
- attr
18
- ], Elevation.prototype, "dp");
211
+ attr({
212
+ mode: "boolean"
213
+ })
214
+ ], Popup.prototype, "open");
215
+ __decorateClass([
216
+ attr({
217
+ mode: "boolean"
218
+ })
219
+ ], Popup.prototype, "dismissible");
220
+ __decorateClass([
221
+ attr({
222
+ mode: "boolean"
223
+ })
224
+ ], Popup.prototype, "arrow");
19
225
  __decorateClass([
20
- attr({ attribute: "no-shadow", mode: "boolean" })
21
- ], Elevation.prototype, "noShadow");
226
+ attr({
227
+ mode: "boolean"
228
+ })
229
+ ], Popup.prototype, "alternate");
22
230
  __decorateClass([
23
- attr({ attribute: "not-relative", mode: "boolean" })
24
- ], Elevation.prototype, "notRelative");
231
+ attr({ mode: "fromView" })
232
+ ], Popup.prototype, "placement");
233
+ __decorateClass([
234
+ attr({ mode: "boolean", attribute: "animation-frame" })
235
+ ], Popup.prototype, "animationFrame");
236
+ __decorateClass([
237
+ attr({ mode: "fromView" })
238
+ ], Popup.prototype, "strategy");
239
+ __decorateClass([
240
+ attr({ attribute: "offset", converter: nullableNumberConverter })
241
+ ], Popup.prototype, "offset");
242
+ __decorateClass([
243
+ observable
244
+ ], Popup.prototype, "anchor");
25
245
 
26
- const styles = ":host{display:contents}.control{display:contents}.control.dp-0{--_elevation-fill: var(--_vvd-tinted-color-surface-0dp, var(--vvd-color-surface-0dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-0dp, var(--vvd-shadow-surface-0dp))}.control.dp-4{--_elevation-fill: var(--_vvd-tinted-color-surface-4dp, var(--vvd-color-surface-4dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-4dp, var(--vvd-shadow-surface-4dp))}.control.dp-8{--_elevation-fill: var(--_vvd-tinted-color-surface-8dp, var(--vvd-color-surface-8dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-8dp, var(--vvd-shadow-surface-8dp))}.control.dp-12{--_elevation-fill: var(--_vvd-tinted-color-surface-12dp, var(--vvd-color-surface-12dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-12dp, var(--vvd-shadow-surface-12dp))}.control.dp-16{--_elevation-fill: var(--_vvd-tinted-color-surface-16dp, var(--vvd-color-surface-16dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-16dp, var(--vvd-shadow-surface-16dp))}.control.dp-24{--_elevation-fill: var(--_vvd-tinted-color-surface-24dp, var(--vvd-color-surface-24dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-24dp, var(--vvd-shadow-surface-24dp))}.control:not(.dp-0,.dp-4,.dp-8,.dp-12,.dp-16,.dp-24){--_elevation-fill: var(--_vvd-tinted-color-surface-2dp, var(--vvd-color-surface-2dp));--_elevation-shadow: var(--_vvd-tinted-shadow-surface-2dp, var(--vvd-shadow-surface-2dp))}.control ::slotted(*){isolation:isolate}.control ::slotted(*):before{position:absolute;z-index:-1;border-radius:inherit;background:var(--_elevation-fill);block-size:100%;content:\"\";filter:var(--_elevation-shadow);inline-size:100%;inset-block-start:0;inset-inline-start:0;transition:background-color .15s linear,filter .15s linear}.control:not(.not-relative) ::slotted(*){position:relative}.control.no-shadow ::slotted(*):before{filter:none}";
246
+ const styles = ":host{display:var(--_popup-display, inline)}.control{border-radius:inherit;background:var(--vvd-color-surface-4dp);contain:layout}.control:not(.open){display:none}.popup-wrapper{white-space:initial;--scrollbar-track-color: transparent;--scrollbar-thumb-color: color-mix(in srgb, var(--vvd-color-neutral-950), transparent 70%)}.popup-wrapper{scrollbar-color:var(--scrollbar-thumb-color) var(--scrollbar-track-color);scrollbar-width:thin}.popup-wrapper ::-webkit-scrollbar{width:4px}.popup-wrapper ::-webkit-scrollbar-track{background:var(--scrollbar-track-color)}.popup-wrapper ::-webkit-scrollbar-thumb{border:0;border-radius:4px;background-color:var(--scrollbar-fallback-track-color, var(--scrollbar-thumb-color))}.popup-wrapper{z-index:var(--_popup-z-index, 10);overflow:visible;padding:0;border:none;border-radius:8px;margin:0;inline-size:max-content}.popup-wrapper:not(.absolute){position:fixed}.popup-wrapper.absolute{position:absolute;top:0;left:0}.popup-content{display:grid;color:var(--vvd-color-canvas-text)}.dismissible .popup-content{align-content:start;grid-template-columns:1fr auto}.arrow{position:absolute;z-index:-1;width:8px;height:8px;background:var(--vvd-color-surface-4dp);transform:rotate(45deg)}.dismissible-button{align-self:flex-start;margin-block-start:4px;margin-inline-end:4px}";
27
247
 
28
- const getClasses = ({ dp, noShadow, notRelative }) => classNames(
248
+ const getClasses = ({ open, dismissible, alternate }) => classNames(
29
249
  "control",
30
- [`dp-${dp}`, Boolean(dp)],
31
- ["no-shadow", Boolean(noShadow)],
32
- ["not-relative", Boolean(notRelative)]
250
+ ["open", Boolean(open)],
251
+ ["dismissible", Boolean(dismissible)],
252
+ ["alternate", Boolean(alternate)]
33
253
  );
34
- const elevationTemplate = html` <div
35
- class="${getClasses}"
36
- part="base"
37
- >
38
- <slot></slot>
39
- </div>`;
254
+ function handlePopover(x) {
255
+ return x.strategy && x.strategy === "fixed" ? "manual" : null;
256
+ }
257
+ const popupTemplate = (context) => {
258
+ const elevationTag = context.tagFor(Elevation);
259
+ const buttonTag = context.tagFor(Button);
260
+ return html`
261
+ <${elevationTag}>
262
+ <div popover="${handlePopover}" class="popup-wrapper ${(x) => x.strategy}" ${ref("popupEl")} part="popup-base">
263
+ <div ${ref("controlEl")} class="${getClasses}" aria-hidden="${(x) => x.open ? "false" : "true"}"
264
+ part="${(x) => x.alternate ? "vvd-theme-alternate" : ""}">
265
+ <div class="popup-content">
266
+ <slot></slot>
267
+ ${when(
268
+ (x) => x.dismissible,
269
+ html`<${buttonTag} size="condensed" @click="${(x) => x.open = false}"
270
+ class="dismissible-button" icon="close-small-solid" shape="pill"></${buttonTag}>`
271
+ )}
272
+ </div>
273
+ ${when(
274
+ (x) => x.arrow,
275
+ html`<div class="arrow" ${ref("arrowEl")}></div>`
276
+ )}
277
+ </div>
278
+ </div>
279
+ </${elevationTag}>`;
280
+ };
40
281
 
41
- const elevationDefinition = defineVividComponent(
42
- "elevation",
43
- Elevation,
44
- elevationTemplate,
45
- [],
282
+ const popupDefinition = defineVividComponent(
283
+ "popup",
284
+ Popup,
285
+ popupTemplate,
286
+ [elevationDefinition, buttonDefinition],
46
287
  {
47
288
  styles
48
289
  }
49
290
  );
50
- const registerElevation = createRegisterFunction(elevationDefinition);
291
+ const registerPopup = createRegisterFunction(popupDefinition);
51
292
 
52
- export { Elevation as E, elevationDefinition as e, registerElevation as r };
293
+ export { Popup as P, PlacementStrategy as a, popupDefinition as p, registerPopup as r };