@quartzds/core 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/README.md +136 -0
  2. package/components/floating-ui.dom.esm.js +1402 -0
  3. package/components/floating-ui.dom.esm.js.map +1 -0
  4. package/components/helpers.js +174 -0
  5. package/components/helpers.js.map +1 -0
  6. package/components/icon.js +175 -0
  7. package/components/icon.js.map +1 -0
  8. package/components/index.d.ts +52 -0
  9. package/components/index.js +117 -0
  10. package/components/index.js.map +1 -0
  11. package/components/label.js +55 -0
  12. package/components/label.js.map +1 -0
  13. package/components/qds-button.d.ts +11 -0
  14. package/components/qds-button.js +148 -0
  15. package/components/qds-button.js.map +1 -0
  16. package/components/qds-checkbox.d.ts +11 -0
  17. package/components/qds-checkbox.js +156 -0
  18. package/components/qds-checkbox.js.map +1 -0
  19. package/components/qds-dropdown.d.ts +11 -0
  20. package/components/qds-dropdown.js +259 -0
  21. package/components/qds-dropdown.js.map +1 -0
  22. package/components/qds-icon.d.ts +11 -0
  23. package/components/qds-icon.js +13 -0
  24. package/components/qds-icon.js.map +1 -0
  25. package/components/qds-inline-link.d.ts +11 -0
  26. package/components/qds-inline-link.js +89 -0
  27. package/components/qds-inline-link.js.map +1 -0
  28. package/components/qds-input.d.ts +11 -0
  29. package/components/qds-input.js +244 -0
  30. package/components/qds-input.js.map +1 -0
  31. package/components/qds-label.d.ts +11 -0
  32. package/components/qds-label.js +13 -0
  33. package/components/qds-label.js.map +1 -0
  34. package/components/qds-radio.d.ts +11 -0
  35. package/components/qds-radio.js +109 -0
  36. package/components/qds-radio.js.map +1 -0
  37. package/components/qds-switch.d.ts +11 -0
  38. package/components/qds-switch.js +119 -0
  39. package/components/qds-switch.js.map +1 -0
  40. package/components/qds-title.d.ts +11 -0
  41. package/components/qds-title.js +94 -0
  42. package/components/qds-title.js.map +1 -0
  43. package/components/qds-tooltip.d.ts +11 -0
  44. package/components/qds-tooltip.js +325 -0
  45. package/components/qds-tooltip.js.map +1 -0
  46. package/dist/cjs/floating-ui.dom.esm-71fa96af.js +1410 -0
  47. package/dist/cjs/floating-ui.dom.esm-71fa96af.js.map +1 -0
  48. package/dist/cjs/helpers-0b23af3f.js +184 -0
  49. package/dist/cjs/helpers-0b23af3f.js.map +1 -0
  50. package/dist/cjs/index-f19b2823.js +2030 -0
  51. package/dist/cjs/index-f19b2823.js.map +1 -0
  52. package/dist/cjs/index.cjs.js +115 -0
  53. package/dist/cjs/index.cjs.js.map +1 -0
  54. package/dist/cjs/library-4803c801.js +62 -0
  55. package/dist/cjs/library-4803c801.js.map +1 -0
  56. package/dist/cjs/loader.cjs.js +29 -0
  57. package/dist/cjs/loader.cjs.js.map +1 -0
  58. package/dist/cjs/qds-button.cjs.entry.js +110 -0
  59. package/dist/cjs/qds-button.cjs.entry.js.map +1 -0
  60. package/dist/cjs/qds-checkbox.cjs.entry.js +116 -0
  61. package/dist/cjs/qds-checkbox.cjs.entry.js.map +1 -0
  62. package/dist/cjs/qds-dropdown.cjs.entry.js +227 -0
  63. package/dist/cjs/qds-dropdown.cjs.entry.js.map +1 -0
  64. package/dist/cjs/qds-icon.cjs.entry.js +113 -0
  65. package/dist/cjs/qds-icon.cjs.entry.js.map +1 -0
  66. package/dist/cjs/qds-inline-link.cjs.entry.js +61 -0
  67. package/dist/cjs/qds-inline-link.cjs.entry.js.map +1 -0
  68. package/dist/cjs/qds-input.cjs.entry.js +200 -0
  69. package/dist/cjs/qds-input.cjs.entry.js.map +1 -0
  70. package/dist/cjs/qds-label.cjs.entry.js +39 -0
  71. package/dist/cjs/qds-label.cjs.entry.js.map +1 -0
  72. package/dist/cjs/qds-radio.cjs.entry.js +74 -0
  73. package/dist/cjs/qds-radio.cjs.entry.js.map +1 -0
  74. package/dist/cjs/qds-switch.cjs.entry.js +79 -0
  75. package/dist/cjs/qds-switch.cjs.entry.js.map +1 -0
  76. package/dist/cjs/qds-title.cjs.entry.js +66 -0
  77. package/dist/cjs/qds-title.cjs.entry.js.map +1 -0
  78. package/dist/cjs/qds-tooltip.cjs.entry.js +284 -0
  79. package/dist/cjs/qds-tooltip.cjs.entry.js.map +1 -0
  80. package/dist/cjs/qds.cjs.js +33 -0
  81. package/dist/cjs/qds.cjs.js.map +1 -0
  82. package/dist/custom-elements.json +3976 -0
  83. package/dist/docs.d.ts +148 -0
  84. package/dist/docs.json +3918 -0
  85. package/dist/esm/floating-ui.dom.esm-f96ac766.js +1402 -0
  86. package/dist/esm/floating-ui.dom.esm-f96ac766.js.map +1 -0
  87. package/dist/esm/helpers-5c189a19.js +174 -0
  88. package/dist/esm/helpers-5c189a19.js.map +1 -0
  89. package/dist/esm/index-1bc8e218.js +2000 -0
  90. package/dist/esm/index-1bc8e218.js.map +1 -0
  91. package/dist/esm/index.js +106 -0
  92. package/dist/esm/index.js.map +1 -0
  93. package/dist/esm/library-aa6893c0.js +58 -0
  94. package/dist/esm/library-aa6893c0.js.map +1 -0
  95. package/dist/esm/loader.js +25 -0
  96. package/dist/esm/loader.js.map +1 -0
  97. package/dist/esm/polyfills/core-js.js +11 -0
  98. package/dist/esm/polyfills/css-shim.js +1 -0
  99. package/dist/esm/polyfills/dom.js +79 -0
  100. package/dist/esm/polyfills/es5-html-element.js +1 -0
  101. package/dist/esm/polyfills/index.js +34 -0
  102. package/dist/esm/polyfills/system.js +6 -0
  103. package/dist/esm/qds-button.entry.js +106 -0
  104. package/dist/esm/qds-button.entry.js.map +1 -0
  105. package/dist/esm/qds-checkbox.entry.js +112 -0
  106. package/dist/esm/qds-checkbox.entry.js.map +1 -0
  107. package/dist/esm/qds-dropdown.entry.js +223 -0
  108. package/dist/esm/qds-dropdown.entry.js.map +1 -0
  109. package/dist/esm/qds-icon.entry.js +109 -0
  110. package/dist/esm/qds-icon.entry.js.map +1 -0
  111. package/dist/esm/qds-inline-link.entry.js +57 -0
  112. package/dist/esm/qds-inline-link.entry.js.map +1 -0
  113. package/dist/esm/qds-input.entry.js +196 -0
  114. package/dist/esm/qds-input.entry.js.map +1 -0
  115. package/dist/esm/qds-label.entry.js +35 -0
  116. package/dist/esm/qds-label.entry.js.map +1 -0
  117. package/dist/esm/qds-radio.entry.js +70 -0
  118. package/dist/esm/qds-radio.entry.js.map +1 -0
  119. package/dist/esm/qds-switch.entry.js +75 -0
  120. package/dist/esm/qds-switch.entry.js.map +1 -0
  121. package/dist/esm/qds-title.entry.js +62 -0
  122. package/dist/esm/qds-title.entry.js.map +1 -0
  123. package/dist/esm/qds-tooltip.entry.js +280 -0
  124. package/dist/esm/qds-tooltip.entry.js.map +1 -0
  125. package/dist/esm/qds.js +28 -0
  126. package/dist/esm/qds.js.map +1 -0
  127. package/dist/types/components/button/button.d.ts +209 -0
  128. package/dist/types/components/checkbox/checkbox.d.ts +136 -0
  129. package/dist/types/components/create-story.d.ts +5 -0
  130. package/dist/types/components/dropdown/dropdown.d.ts +135 -0
  131. package/dist/types/components/icon/default-library.d.ts +4 -0
  132. package/dist/types/components/icon/icon.d.ts +31 -0
  133. package/dist/types/components/icon/library.d.ts +19 -0
  134. package/dist/types/components/icon/request.d.ts +12 -0
  135. package/dist/types/components/icon/system-library.d.ts +4 -0
  136. package/dist/types/components/inline-link/inline-link.d.ts +208 -0
  137. package/dist/types/components/input/input.d.ts +386 -0
  138. package/dist/types/components/label/label.d.ts +33 -0
  139. package/dist/types/components/radio/radio.d.ts +110 -0
  140. package/dist/types/components/switch/switch.d.ts +115 -0
  141. package/dist/types/components/title/title.d.ts +42 -0
  142. package/dist/types/components/tooltip/tooltip.d.ts +147 -0
  143. package/dist/types/components.d.ts +1692 -0
  144. package/dist/types/helpers.d.ts +49 -0
  145. package/dist/types/index.d.ts +4 -0
  146. package/dist/types/qds-test.d.ts +18 -0
  147. package/dist/types/stencil-public-runtime.d.ts +1638 -0
  148. package/dist/types/utils.d.ts +65 -0
  149. package/dist/vscode.html-custom-data.json +947 -0
  150. package/hydrate/index.d.ts +218 -0
  151. package/hydrate/index.js +9690 -0
  152. package/hydrate/package.json +6 -0
  153. package/loader/cdn.js +7 -0
  154. package/loader/index.cjs.js +7 -0
  155. package/loader/index.d.ts +21 -0
  156. package/loader/index.es2017.js +7 -0
  157. package/loader/index.js +8 -0
  158. package/loader/package.json +11 -0
  159. package/package.json +231 -0
  160. package/styles/core.css +379 -0
@@ -0,0 +1,325 @@
1
+ /*!
2
+ * SPDX-FileCopyrightText: © 2023 Schneider Electric
3
+ *
4
+ * SPDX-License-Identifier: LGPL-2.1-only
5
+ */
6
+ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
7
+ import { o as offset, f as flip, s as shift, l as limitShift, b as arrow, c as computePosition, a as autoUpdate } from './floating-ui.dom.esm.js';
8
+ import { c as ignorePromise, d as propertyToPx, a as invariant, r as roundByDPR, f as isTouchDevice } from './helpers.js';
9
+
10
+ const tooltipCss = ":host{box-sizing:border-box}:host([hidden]){display:none !important}:host([hidden]){}:host *,:host *::before,:host *::after{box-sizing:inherit}:host{align-items:flex-start;background-color:var(--qds-theme-accessory-background);border-radius:var(--qds-accessory-border-radius);box-shadow:var(--qds-theme-accessory-elevation);color:var(--qds-theme-text-standard);display:flex;flex-direction:column;gap:var(--qds-accessory-gap-children-unrelated);left:0;padding:var(--qds-accessory-padding);top:0}:host([aria-hidden='true']){display:none}:host::before{content:'';height:100%;left:0;position:absolute;top:0;width:100%}::slotted(blockquote),::slotted(button),::slotted(dd),::slotted(dl),::slotted(fieldset),::slotted(figure),::slotted(h1),::slotted(h2),::slotted(h3),::slotted(h4),::slotted(h5),::slotted(h6),::slotted(hr),::slotted(input),::slotted(menu),::slotted(ol),::slotted(p),::slotted(pre),::slotted(select),::slotted(textarea),::slotted(ul){margin:0}:host([data-side='top'])::before,:host([data-side='bottom'])::before{height:calc(\n 0px +\n 0px\n );height:calc(\n var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px)\n );top:100%}:host([data-side='bottom'])::before{top:calc(\n -1 * (0px +\n 0px)\n );top:calc(\n -1 * (var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px))\n )}:host([data-side='left'])::before,:host([data-side='right'])::before{width:calc(\n 0px +\n 0px\n );width:calc(\n var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px)\n );left:100%}:host([data-side='right'])::before{left:calc(\n -1 * (0px +\n 0px)\n );left:calc(\n -1 * (var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px))\n )}.arrow-container{height:var(--qds-signature-triangle-pointer-size-width);position:absolute;width:var(--qds-signature-triangle-pointer-size-width)}.arrow-container[data-side='bottom']{bottom:100%;transform:rotate(180deg)}.arrow-container[data-side='left']{left:100%;transform:rotate(-90deg)}.arrow-container[data-side='right']{right:100%;transform:rotate(90deg)}.arrow-container[data-side='top']{top:100%}.arrow{fill:var(--qds-theme-accessory-background)}";
11
+
12
+ let autoIncrementingId = 1;
13
+ const Tooltip = /*@__PURE__*/ proxyCustomElement(class Tooltip extends HTMLElement {
14
+ constructor() {
15
+ super();
16
+ this.__registerHost();
17
+ this.__attachShadow();
18
+ this.closeEmitter = createEvent(this, "qdsClose", 2);
19
+ this.clickedTooltip = false;
20
+ this.isTouchDevice = false;
21
+ this.arrowContainerRef = (svg) => {
22
+ this.arrowContainerElement = svg;
23
+ };
24
+ this.boundTooltipMouseDown = () => {
25
+ this.clickedTooltip = true;
26
+ };
27
+ this.boundFocus = () => {
28
+ ignorePromise(this.handleFocus());
29
+ };
30
+ this.boundMouseEnter = () => {
31
+ ignorePromise(this.handleMouseEnter());
32
+ };
33
+ this.boundMouseLeave = (event) => {
34
+ ignorePromise(this.handleMouseLeave(event));
35
+ };
36
+ this.boundFocusout = (event) => {
37
+ ignorePromise(this.handleFocusOut(event));
38
+ };
39
+ this.boundReferenceClick = () => {
40
+ ignorePromise(this.handleReferenceClick());
41
+ };
42
+ this.autoUpdateOptions = undefined;
43
+ this.disabled = false;
44
+ this.flipOptions = undefined;
45
+ this.noFlip = false;
46
+ this.noShift = false;
47
+ this.offsetOptions = undefined;
48
+ this.placement = 'top';
49
+ this.shiftOptions = undefined;
50
+ this.strategy = undefined;
51
+ this.target = undefined;
52
+ this.hostPosition = undefined;
53
+ this.hostTransform = undefined;
54
+ this.open = false;
55
+ this.middleware = undefined;
56
+ this.aDisplay = undefined;
57
+ this.side = 'top';
58
+ this.aShape = '';
59
+ this.aViewbox = '';
60
+ this.aHeight = 0;
61
+ this.aWidth = 0;
62
+ this.aGap = 0;
63
+ this.aX = '';
64
+ this.aY = '';
65
+ }
66
+ /**
67
+ * Show the tooltip.
68
+ */
69
+ async show() {
70
+ if (this.open)
71
+ return;
72
+ if (this.referenceElement instanceof globalThis.Element)
73
+ this.referenceElement.addEventListener('focusout', this.boundFocusout);
74
+ this.open = true;
75
+ this.element.setAttribute('aria-hidden', 'false');
76
+ this.startAutoUpdate();
77
+ }
78
+ /**
79
+ * Close the tooltip.
80
+ */
81
+ async close() {
82
+ if (!this.open)
83
+ return;
84
+ this.closeEmitter.emit();
85
+ if (this.referenceElement instanceof globalThis.Element)
86
+ this.referenceElement.removeEventListener('focusout', this.boundFocusout);
87
+ this.open = false;
88
+ this.clickedTooltip = false;
89
+ this.element.setAttribute('aria-hidden', 'true');
90
+ if (this.cleanup)
91
+ this.cleanup();
92
+ }
93
+ /**
94
+ * Update the tooltip's arrow.
95
+ *
96
+ * This method should typically be called when the Quartz platform was
97
+ * changed.
98
+ */
99
+ async updateArrow() {
100
+ this.aGap = propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0;
101
+ this.aHeight =
102
+ propertyToPx(this.element, `--qds-signature-triangle-pointer-size-height`) ?? 0;
103
+ this.aWidth =
104
+ propertyToPx(this.element, `--qds-signature-triangle-pointer-size-width`) ?? 0;
105
+ this.aViewbox = `0 0 ${this.aWidth} ${Math.max(this.aHeight, this.aWidth)}`;
106
+ const aTipRadius = propertyToPx(this.element, `--qds-signature-triangle-pointer-tip-radius`) ?? 0;
107
+ const svgX = (this.aWidth / 2) * (aTipRadius / -8 + 1);
108
+ const svgY = ((this.aHeight / 2) * aTipRadius) / 4;
109
+ this.aShape =
110
+ 'M0,0' +
111
+ ` H${this.aWidth}` +
112
+ ` L${this.aWidth - svgX},${this.aHeight - svgY}` +
113
+ ` Q${this.aWidth / 2},${this.aHeight} ${svgX},${this.aHeight - svgY}` +
114
+ ' Z';
115
+ }
116
+ async handleMouseDown(event) {
117
+ const composedPath = event.composedPath();
118
+ const withinBounds = composedPath.includes(this.element) ||
119
+ (this.referenceElement instanceof globalThis.Element &&
120
+ composedPath.includes(this.referenceElement));
121
+ if (!withinBounds)
122
+ await this.close();
123
+ }
124
+ async updateMiddleware() {
125
+ invariant(this.arrowContainerElement);
126
+ this.middleware = [
127
+ offset({
128
+ ...this.offsetOptions,
129
+ mainAxis: this.aGap + this.aHeight,
130
+ }),
131
+ !this.noFlip &&
132
+ flip({
133
+ crossAxis: this.noShift,
134
+ ...this.flipOptions,
135
+ }),
136
+ !this.noShift &&
137
+ shift({
138
+ limiter: limitShift(),
139
+ ...this.shiftOptions,
140
+ }),
141
+ arrow({
142
+ element: this.arrowContainerElement,
143
+ }),
144
+ ].filter((middleware) => middleware !== false);
145
+ }
146
+ async updateReferenceElement() {
147
+ var _a;
148
+ this.disconnectReferenceElement();
149
+ const resolvedTarget = typeof this.target === 'function' ? this.target() : this.target;
150
+ if (typeof resolvedTarget === 'string') {
151
+ const element = document.querySelector(resolvedTarget);
152
+ if (element === null)
153
+ throw new Error('String `target` must resolve to an Element.');
154
+ this.referenceElement = element;
155
+ }
156
+ else
157
+ this.referenceElement = resolvedTarget;
158
+ if (!(this.referenceElement instanceof globalThis.Element))
159
+ return;
160
+ if (this.isTouchDevice)
161
+ this.referenceElement.addEventListener('click', this.boundReferenceClick);
162
+ this.referenceElement.addEventListener('focus', this.boundFocus);
163
+ this.referenceElement.addEventListener('mouseenter', this.boundMouseEnter);
164
+ this.referenceElement.addEventListener('mouseleave', this.boundMouseLeave);
165
+ (_a = this.element).id || (_a.id = `qds-tooltip-${autoIncrementingId}`);
166
+ this.referenceElement.setAttribute('aria-describedby', this.element.id);
167
+ }
168
+ async updatePosition() {
169
+ invariant(this.referenceElement);
170
+ const { x, y, middlewareData, placement, strategy } = await computePosition(this.referenceElement, this.element, {
171
+ middleware: this.middleware,
172
+ placement: this.placement,
173
+ strategy: this.strategy,
174
+ });
175
+ this.hostPosition = strategy;
176
+ this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`;
177
+ if (!middlewareData.arrow)
178
+ return;
179
+ invariant(this.arrowContainerElement);
180
+ if (middlewareData.arrow.centerOffset !== 0) {
181
+ this.aDisplay = 'none';
182
+ return;
183
+ }
184
+ this.aDisplay = undefined;
185
+ const [side] = placement.split('-');
186
+ this.side = side;
187
+ const { x: aX, y: aY } = middlewareData.arrow;
188
+ this.aX = aX === undefined ? '' : `${aX}px`;
189
+ this.aY = aY === undefined ? '' : `${aY}px`;
190
+ }
191
+ startAutoUpdate() {
192
+ invariant(this.referenceElement);
193
+ if (this.cleanup)
194
+ this.cleanup();
195
+ this.cleanup = autoUpdate(this.referenceElement, this.element, () => {
196
+ ignorePromise(this.updatePosition());
197
+ }, this.autoUpdateOptions);
198
+ }
199
+ async componentWillLoad() {
200
+ this.isTouchDevice = isTouchDevice();
201
+ this.element.setAttribute('aria-hidden', 'true');
202
+ await this.updateReferenceElement();
203
+ autoIncrementingId += 1;
204
+ }
205
+ async componentDidLoad() {
206
+ await this.updateArrow();
207
+ }
208
+ disconnectedCallback() {
209
+ this.disconnectReferenceElement();
210
+ }
211
+ render() {
212
+ return (h(Host, { "data-side": this.side, onFocusout: this.boundFocusout, onMouseDown: this.boundTooltipMouseDown, onMouseLeave: this.boundMouseLeave, role: this.element.role ?? 'tooltip', style: {
213
+ position: this.hostPosition,
214
+ transform: this.hostTransform,
215
+ } }, h("slot", null), h("svg", { "aria-hidden": true, "data-side": this.side, class: "arrow-container", ref: this.arrowContainerRef, viewBox: this.aViewbox, style: {
216
+ left: this.aX,
217
+ top: this.aY,
218
+ display: this.aDisplay,
219
+ } }, h("path", { class: "arrow", d: this.aShape }))));
220
+ }
221
+ async handleFocus() {
222
+ if (!this.disabled)
223
+ await this.show();
224
+ }
225
+ async handleMouseEnter() {
226
+ if (!this.disabled)
227
+ await this.show();
228
+ }
229
+ async handleMouseLeave(event) {
230
+ if (!this.clickedTooltip &&
231
+ document.activeElement !== this.referenceElement &&
232
+ document.activeElement?.closest('qds-tooltip') !== this.element &&
233
+ event instanceof MouseEvent &&
234
+ event.relatedTarget !== this.referenceElement &&
235
+ event.relatedTarget !== this.element)
236
+ await this.close();
237
+ }
238
+ async handleFocusOut(event) {
239
+ if (!(event instanceof FocusEvent))
240
+ return;
241
+ const { relatedTarget } = event;
242
+ if (relatedTarget instanceof globalThis.Element &&
243
+ !this.element.contains(relatedTarget) &&
244
+ this.referenceElement !== relatedTarget)
245
+ await this.close();
246
+ }
247
+ async handleReferenceClick() {
248
+ if (!this.disabled)
249
+ await (this.open ? this.close() : this.show());
250
+ }
251
+ disconnectReferenceElement() {
252
+ if (!(this.referenceElement instanceof globalThis.Element))
253
+ return;
254
+ if (this.isTouchDevice)
255
+ this.referenceElement.removeEventListener('click', this.boundReferenceClick);
256
+ this.referenceElement.removeEventListener('focus', this.boundFocus);
257
+ this.referenceElement.removeEventListener('focusout', this.boundFocusout);
258
+ this.referenceElement.removeEventListener('mouseenter', this.boundMouseEnter);
259
+ this.referenceElement.removeEventListener('mouseleave', this.boundMouseLeave);
260
+ this.referenceElement.removeAttribute('aria-describedby');
261
+ }
262
+ get element() { return this; }
263
+ static get watchers() { return {
264
+ "aGap": ["updateMiddleware"],
265
+ "aHeight": ["updateMiddleware"],
266
+ "flipOptions": ["updateMiddleware"],
267
+ "noFlip": ["updateMiddleware"],
268
+ "noShift": ["updateMiddleware"],
269
+ "offsetOptions": ["updateMiddleware"],
270
+ "shiftOptions": ["updateMiddleware"],
271
+ "target": ["updateReferenceElement"],
272
+ "middleware": ["updatePosition"],
273
+ "placement": ["updatePosition"],
274
+ "strategy": ["updatePosition"],
275
+ "autoUpdateOptions": ["startAutoUpdate"]
276
+ }; }
277
+ static get style() { return tooltipCss; }
278
+ }, [1, "qds-tooltip", {
279
+ "autoUpdateOptions": [16],
280
+ "disabled": [1028],
281
+ "flipOptions": [16],
282
+ "noFlip": [4, "no-flip"],
283
+ "noShift": [4, "no-shift"],
284
+ "offsetOptions": [16],
285
+ "placement": [1],
286
+ "shiftOptions": [16],
287
+ "strategy": [1],
288
+ "target": [1],
289
+ "hostPosition": [32],
290
+ "hostTransform": [32],
291
+ "open": [32],
292
+ "middleware": [32],
293
+ "aDisplay": [32],
294
+ "side": [32],
295
+ "aShape": [32],
296
+ "aViewbox": [32],
297
+ "aHeight": [32],
298
+ "aWidth": [32],
299
+ "aGap": [32],
300
+ "aX": [32],
301
+ "aY": [32],
302
+ "show": [64],
303
+ "close": [64],
304
+ "updateArrow": [64]
305
+ }, [[5, "mousedown", "handleMouseDown"]]]);
306
+ function defineCustomElement$1() {
307
+ if (typeof customElements === "undefined") {
308
+ return;
309
+ }
310
+ const components = ["qds-tooltip"];
311
+ components.forEach(tagName => { switch (tagName) {
312
+ case "qds-tooltip":
313
+ if (!customElements.get(tagName)) {
314
+ customElements.define(tagName, Tooltip);
315
+ }
316
+ break;
317
+ } });
318
+ }
319
+
320
+ const QdsTooltip = Tooltip;
321
+ const defineCustomElement = defineCustomElement$1;
322
+
323
+ export { QdsTooltip, defineCustomElement };
324
+
325
+ //# sourceMappingURL=qds-tooltip.js.map
@@ -0,0 +1 @@
1
+ {"file":"qds-tooltip.js","mappings":";;;;;;;;;AAAA,MAAM,UAAU,GAAG,8xEAA8xE;;AC+CjzE,IAAI,kBAAkB,GAAG,CAAC,CAAA;MAYb,OAAO;;;;;;IAoIV,mBAAc,GAAG,KAAK,CAAA;IAEtB,kBAAa,GAAG,KAAK,CAAA;IAiPZ,sBAAiB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,CAAC,gBAAgB,CAAC,mBAAmB,CACvC,OAAO,EACP,IAAI,CAAC,mBAAmB,CACzB,CAAA;IACH,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IACnE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACzE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CACvC,YAAY,EACZ,IAAI,CAAC,eAAe,CACrB,CAAA;IACD,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CACvC,YAAY,EACZ,IAAI,CAAC,eAAe,CACrB,CAAA;IACD,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAA;GAC1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["./src/components/tooltip/tooltip.css?tag=qds-tooltip&encapsulation=shadow","./src/components/tooltip/tooltip.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n align-items: flex-start;\n background-color: var(--qds-theme-accessory-background);\n border-radius: var(--qds-accessory-border-radius);\n box-shadow: var(--qds-theme-accessory-elevation);\n color: var(--qds-theme-text-standard);\n display: flex;\n flex-direction: column;\n gap: var(--qds-accessory-gap-children-unrelated);\n left: 0;\n padding: var(--qds-accessory-padding);\n top: 0;\n}\n\n:host([aria-hidden='true']) {\n display: none;\n}\n\n:host::before {\n content: '';\n height: 100%;\n left: 0;\n position: absolute;\n top: 0;\n width: 100%;\n}\n\n::slotted(blockquote),\n::slotted(button),\n::slotted(dd),\n::slotted(dl),\n::slotted(fieldset),\n::slotted(figure),\n::slotted(h1),\n::slotted(h2),\n::slotted(h3),\n::slotted(h4),\n::slotted(h5),\n::slotted(h6),\n::slotted(hr),\n::slotted(input),\n::slotted(menu),\n::slotted(ol),\n::slotted(p),\n::slotted(pre),\n::slotted(select),\n::slotted(textarea),\n::slotted(ul) {\n margin: 0;\n}\n\n:host([data-side='top'])::before,\n:host([data-side='bottom'])::before {\n height: calc(\n var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px)\n );\n top: 100%;\n}\n\n:host([data-side='bottom'])::before {\n top: calc(\n -1 * (var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px))\n );\n}\n\n:host([data-side='left'])::before,\n:host([data-side='right'])::before {\n width: calc(\n var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px)\n );\n left: 100%;\n}\n\n:host([data-side='right'])::before {\n left: calc(\n -1 * (var(--qds-accessory-gap-floating, 0px) +\n var(--qds-signature-triangle-pointer-size-height, 0px))\n );\n}\n\n.arrow-container {\n height: var(--qds-signature-triangle-pointer-size-width);\n position: absolute;\n width: var(--qds-signature-triangle-pointer-size-width);\n\n &[data-side='bottom'] {\n bottom: 100%;\n transform: rotate(180deg);\n }\n\n &[data-side='left'] {\n left: 100%;\n transform: rotate(-90deg);\n }\n\n &[data-side='right'] {\n right: 100%;\n transform: rotate(90deg);\n }\n\n &[data-side='top'] {\n top: 100%;\n }\n}\n\n.arrow {\n fill: var(--qds-theme-accessory-background);\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type {\n AutoUpdateOptions,\n DetectOverflowOptions,\n FlipOptions,\n Middleware,\n Placement,\n ReferenceElement,\n ShiftOptions,\n Side,\n Strategy,\n} from '@floating-ui/dom'\nimport {\n arrow,\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n} from '@floating-ui/dom'\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Listen,\n Method,\n Prop,\n State,\n Watch,\n} from '@stencil/core'\n\nimport type { OffsetOptions } from '../../helpers'\nimport {\n ignorePromise,\n invariant,\n isTouchDevice,\n propertyToPx,\n roundByDPR,\n} from '../../helpers'\n\nlet autoIncrementingId = 1\n\n/**\n * @experimental\n * @slot Content to display in the dropdown.\n * @see https://quartz.se.com/build/components/tooltip\n */\n@Component({\n tag: 'qds-tooltip',\n shadow: true,\n styleUrl: 'tooltip.css',\n})\nexport class Tooltip implements ComponentInterface {\n /**\n * Options to pass to Floating UI's\n * [`autoUpdate()` function](https://floating-ui.com/docs/autoUpdate).\n *\n * @see https://floating-ui.com/docs/autoupdate#options\n */\n @Prop() public readonly autoUpdateOptions?: AutoUpdateOptions\n\n /**\n * Prevents the tooltip from being shown by user interaction. The tooltip can\n * still be displayed by calling the `show()` method.\n */\n @Prop({ mutable: true }) public disabled = false\n\n /**\n * Options to pass to Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n *\n * The [`crossAxis` option](https://floating-ui.com/docs/flip#crossaxis) is\n * set to the value of the `noShift` property by default for interoperability\n * with the [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/flip#options\n */\n @Prop() public readonly flipOptions?: Partial<\n DetectOverflowOptions & FlipOptions\n >\n\n /**\n * Disable Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n */\n @Prop() public readonly noFlip: boolean = false\n\n /**\n * Disable Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n */\n @Prop() public readonly noShift: boolean = false\n\n /**\n * Options to pass to Floating UI's\n * [`offset` middleware](https://floating-ui.com/docs/offset).\n *\n * The [`mainAxis` option](https://floating-ui.com/docs/offset#mainaxis) is\n * not supported.\n *\n * @see https://floating-ui.com/docs/offset#options\n */\n @Prop() public readonly offsetOptions?: OffsetOptions\n\n /**\n * Where to place the tooltip relative to the `target`.\n *\n * @see https://floating-ui.com/docs/tutorial#placements\n */\n @Prop() public readonly placement: Placement = 'top'\n\n /**\n * Options to pass to Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/shift#options\n */\n @Prop() public readonly shiftOptions?: Partial<\n DetectOverflowOptions & ShiftOptions\n >\n\n /**\n * The CSS position strategy to use.\n *\n * @see https://floating-ui.com/docs/computeposition#strategy\n */\n @Prop() public readonly strategy?: Strategy\n\n /**\n * The trigger element that will trigger the tooltip. The target specified\n * can be any of the follow:\n *\n * - A CSS selector string\n * - A reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element) or\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements)\n * - A function returning a reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element),\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements),\n * or a CSS selector string\n */\n @Prop() public readonly target!:\n | ReferenceElement\n | string\n | (() => ReferenceElement | string)\n\n /**\n * Emitted when the tooltip is closed.\n */\n @Event({ eventName: 'qdsClose', bubbles: false, cancelable: false })\n private readonly closeEmitter!: EventEmitter<void>\n\n @Element() private readonly element!: HTMLQdsTooltipElement\n\n @State() private hostPosition?: string\n\n @State() private hostTransform?: string\n\n @State() private open = false\n\n @State() private middleware?: Middleware[]\n\n @State() private aDisplay?: string\n\n @State() private side: Side = 'top'\n\n @State() private aShape = ''\n\n @State() private aViewbox = ''\n\n @State() private aHeight = 0\n\n @State() private aWidth = 0\n\n @State() private aGap = 0\n\n @State() private aX = ''\n\n @State() private aY = ''\n\n private arrowContainerElement?: SVGElement\n\n private cleanup?: () => void\n\n private clickedTooltip = false\n\n private isTouchDevice = false\n\n private referenceElement?: ReferenceElement\n\n /**\n * Show the tooltip.\n */\n @Method()\n public async show(): Promise<void> {\n if (this.open) return\n\n if (this.referenceElement instanceof globalThis.Element)\n this.referenceElement.addEventListener('focusout', this.boundFocusout)\n\n this.open = true\n this.element.setAttribute('aria-hidden', 'false')\n this.startAutoUpdate()\n }\n\n /**\n * Close the tooltip.\n */\n @Method()\n public async close(): Promise<void> {\n if (!this.open) return\n\n this.closeEmitter.emit()\n if (this.referenceElement instanceof globalThis.Element)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n\n this.open = false\n this.clickedTooltip = false\n this.element.setAttribute('aria-hidden', 'true')\n if (this.cleanup) this.cleanup()\n }\n\n /**\n * Update the tooltip's arrow.\n *\n * This method should typically be called when the Quartz platform was\n * changed.\n */\n @Method()\n public async updateArrow(): Promise<void> {\n this.aGap = propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0\n\n this.aHeight =\n propertyToPx(\n this.element,\n `--qds-signature-triangle-pointer-size-height`,\n ) ?? 0\n\n this.aWidth =\n propertyToPx(\n this.element,\n `--qds-signature-triangle-pointer-size-width`,\n ) ?? 0\n\n this.aViewbox = `0 0 ${this.aWidth} ${Math.max(this.aHeight, this.aWidth)}`\n\n const aTipRadius =\n propertyToPx(\n this.element,\n `--qds-signature-triangle-pointer-tip-radius`,\n ) ?? 0\n\n const svgX = (this.aWidth / 2) * (aTipRadius / -8 + 1)\n const svgY = ((this.aHeight / 2) * aTipRadius) / 4\n\n this.aShape =\n 'M0,0' +\n ` H${this.aWidth}` +\n ` L${this.aWidth - svgX},${this.aHeight - svgY}` +\n ` Q${this.aWidth / 2},${this.aHeight} ${svgX},${this.aHeight - svgY}` +\n ' Z'\n }\n\n @Listen('mousedown', { target: 'document' })\n protected async handleMouseDown(event: MouseEvent): Promise<void> {\n const composedPath = event.composedPath()\n const withinBounds =\n composedPath.includes(this.element) ||\n (this.referenceElement instanceof globalThis.Element &&\n composedPath.includes(this.referenceElement))\n if (!withinBounds) await this.close()\n }\n\n @Watch('aGap')\n @Watch('aHeight')\n @Watch('flipOptions')\n @Watch('noFlip')\n @Watch('noShift')\n @Watch('offsetOptions')\n @Watch('shiftOptions')\n protected async updateMiddleware(): Promise<void> {\n invariant(this.arrowContainerElement)\n\n this.middleware = [\n offset({\n ...this.offsetOptions,\n mainAxis: this.aGap + this.aHeight,\n }),\n !this.noFlip &&\n flip({\n crossAxis: this.noShift,\n ...this.flipOptions,\n }),\n !this.noShift &&\n shift({\n limiter: limitShift(),\n ...this.shiftOptions,\n }),\n arrow({\n element: this.arrowContainerElement,\n }),\n ].filter((middleware): middleware is Middleware => middleware !== false)\n }\n\n @Watch('target')\n private async updateReferenceElement(): Promise<void> {\n this.disconnectReferenceElement()\n\n const resolvedTarget =\n typeof this.target === 'function' ? this.target() : this.target\n if (typeof resolvedTarget === 'string') {\n const element = document.querySelector(resolvedTarget)\n if (element === null)\n throw new Error('String `target` must resolve to an Element.')\n this.referenceElement = element\n } else this.referenceElement = resolvedTarget\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n if (this.isTouchDevice)\n this.referenceElement.addEventListener('click', this.boundReferenceClick)\n this.referenceElement.addEventListener('focus', this.boundFocus)\n this.referenceElement.addEventListener('mouseenter', this.boundMouseEnter)\n this.referenceElement.addEventListener('mouseleave', this.boundMouseLeave)\n this.element.id ||= `qds-tooltip-${autoIncrementingId}`\n this.referenceElement.setAttribute('aria-describedby', this.element.id)\n }\n\n @Watch('middleware')\n @Watch('placement')\n @Watch('strategy')\n private async updatePosition(): Promise<void> {\n invariant(this.referenceElement)\n\n const { x, y, middlewareData, placement, strategy } = await computePosition(\n this.referenceElement,\n this.element,\n {\n middleware: this.middleware,\n placement: this.placement,\n strategy: this.strategy,\n },\n )\n this.hostPosition = strategy\n this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`\n\n if (!middlewareData.arrow) return\n\n invariant(this.arrowContainerElement)\n\n if (middlewareData.arrow.centerOffset !== 0) {\n this.aDisplay = 'none'\n return\n }\n this.aDisplay = undefined\n\n const [side] = placement.split('-') as [Side]\n this.side = side\n\n const { x: aX, y: aY } = middlewareData.arrow\n\n this.aX = aX === undefined ? '' : `${aX}px`\n this.aY = aY === undefined ? '' : `${aY}px`\n }\n\n @Watch('autoUpdateOptions')\n private startAutoUpdate(): void {\n invariant(this.referenceElement)\n\n if (this.cleanup) this.cleanup()\n this.cleanup = autoUpdate(\n this.referenceElement,\n this.element,\n () => {\n ignorePromise(this.updatePosition())\n },\n this.autoUpdateOptions,\n )\n }\n\n public async componentWillLoad(): Promise<void> {\n this.isTouchDevice = isTouchDevice()\n this.element.setAttribute('aria-hidden', 'true')\n await this.updateReferenceElement()\n autoIncrementingId += 1\n }\n\n public async componentDidLoad(): Promise<void> {\n await this.updateArrow()\n }\n\n public disconnectedCallback(): void {\n this.disconnectReferenceElement()\n }\n\n public render() {\n return (\n <Host\n data-side={this.side}\n onFocusout={this.boundFocusout}\n onMouseDown={this.boundTooltipMouseDown}\n onMouseLeave={this.boundMouseLeave}\n role={this.element.role ?? 'tooltip'}\n style={{\n position: this.hostPosition,\n transform: this.hostTransform,\n }}\n >\n <slot />\n <svg\n aria-hidden\n data-side={this.side}\n class=\"arrow-container\"\n ref={this.arrowContainerRef}\n viewBox={this.aViewbox}\n style={{\n left: this.aX,\n top: this.aY,\n display: this.aDisplay,\n }}\n >\n <path class=\"arrow\" d={this.aShape} />\n </svg>\n </Host>\n )\n }\n\n private readonly arrowContainerRef = (svg?: SVGElement): void => {\n this.arrowContainerElement = svg\n }\n\n private readonly boundTooltipMouseDown = (): void => {\n this.clickedTooltip = true\n }\n\n private async handleFocus(): Promise<void> {\n if (!this.disabled) await this.show()\n }\n\n private readonly boundFocus = (): void => {\n ignorePromise(this.handleFocus())\n }\n\n private async handleMouseEnter(): Promise<void> {\n if (!this.disabled) await this.show()\n }\n\n private readonly boundMouseEnter = (): void => {\n ignorePromise(this.handleMouseEnter())\n }\n\n private async handleMouseLeave(event: Event): Promise<void> {\n if (\n !this.clickedTooltip &&\n document.activeElement !== this.referenceElement &&\n document.activeElement?.closest('qds-tooltip') !== this.element &&\n event instanceof MouseEvent &&\n event.relatedTarget !== this.referenceElement &&\n event.relatedTarget !== this.element\n )\n await this.close()\n }\n\n private readonly boundMouseLeave = (event: Event): void => {\n ignorePromise(this.handleMouseLeave(event))\n }\n\n private async handleFocusOut(event: Event): Promise<void> {\n if (!(event instanceof FocusEvent)) return\n const { relatedTarget } = event\n\n if (\n relatedTarget instanceof globalThis.Element &&\n !this.element.contains(relatedTarget) &&\n this.referenceElement !== relatedTarget\n )\n await this.close()\n }\n\n private readonly boundFocusout = (event: Event): void => {\n ignorePromise(this.handleFocusOut(event))\n }\n\n private async handleReferenceClick(): Promise<void> {\n if (!this.disabled) await (this.open ? this.close() : this.show())\n }\n\n private readonly boundReferenceClick = (): void => {\n ignorePromise(this.handleReferenceClick())\n }\n\n private disconnectReferenceElement(): void {\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n if (this.isTouchDevice)\n this.referenceElement.removeEventListener(\n 'click',\n this.boundReferenceClick,\n )\n this.referenceElement.removeEventListener('focus', this.boundFocus)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n this.referenceElement.removeEventListener(\n 'mouseenter',\n this.boundMouseEnter,\n )\n this.referenceElement.removeEventListener(\n 'mouseleave',\n this.boundMouseLeave,\n )\n this.referenceElement.removeAttribute('aria-describedby')\n }\n}\n"],"version":3}