@schukai/monster 4.129.3 → 4.129.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/source/components/content/copy.mjs +2 -2
- package/source/components/form/button-bar.mjs +1 -1
- package/source/components/form/util/floating-ui.mjs +50 -621
- package/source/components/layout/popper.mjs +2 -2
- package/test/cases/components/content/image-editor.mjs +12 -17
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.129.
|
|
1
|
+
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.129.5"}
|
|
@@ -163,7 +163,7 @@ class Copy extends CustomElement {
|
|
|
163
163
|
* @property {boolean} features.preventOpenEventSent=false Prevent open event from being sent
|
|
164
164
|
* @property {Object} popper Popper configuration
|
|
165
165
|
* @property {string} popper.placement="top" Popper placement
|
|
166
|
-
* @property {string[]} popper.middleware=["
|
|
166
|
+
* @property {string[]} popper.middleware=["flip", "shift", "offset:-1", "arrow"] Popper middleware
|
|
167
167
|
* @property {boolean} disabled=false Disabled state
|
|
168
168
|
*/
|
|
169
169
|
get defaults() {
|
|
@@ -178,7 +178,7 @@ class Copy extends CustomElement {
|
|
|
178
178
|
},
|
|
179
179
|
popper: {
|
|
180
180
|
placement: "top",
|
|
181
|
-
middleware: ["
|
|
181
|
+
middleware: ["flip", "shift", "offset:-1", "arrow"],
|
|
182
182
|
},
|
|
183
183
|
});
|
|
184
184
|
}
|
|
@@ -22,12 +22,11 @@ import {
|
|
|
22
22
|
size,
|
|
23
23
|
shift,
|
|
24
24
|
} from "@floating-ui/dom";
|
|
25
|
-
import { Processing } from "../../../util/processing.mjs";
|
|
26
|
-
import { isString, isArray, isObject, isFunction } from "../../../types/is.mjs";
|
|
27
25
|
import { hide } from "@popperjs/core";
|
|
26
|
+
import { isArray, isFunction, isObject, isString } from "../../../types/is.mjs";
|
|
27
|
+
import { Processing } from "../../../util/processing.mjs";
|
|
28
28
|
|
|
29
29
|
export {
|
|
30
|
-
canUseNativePositionedPopper,
|
|
31
30
|
closePositionedPopper,
|
|
32
31
|
isPositionedPopperOpen,
|
|
33
32
|
openPositionedPopper,
|
|
@@ -35,9 +34,6 @@ export {
|
|
|
35
34
|
};
|
|
36
35
|
|
|
37
36
|
const autoUpdateCleanupMap = new WeakMap();
|
|
38
|
-
const nativeArrowSyncFrameMap = new WeakMap();
|
|
39
|
-
const anchorNameMap = new WeakMap();
|
|
40
|
-
let anchorNameCounter = 0;
|
|
41
37
|
|
|
42
38
|
/**
|
|
43
39
|
* @private
|
|
@@ -50,123 +46,71 @@ function positionPopper(controlElement, popperElement, options) {
|
|
|
50
46
|
const config = normalizePopperConfig(options);
|
|
51
47
|
|
|
52
48
|
return new Processing(() => {
|
|
53
|
-
|
|
54
|
-
prepareNativePopover(controlElement, popperElement, config);
|
|
55
|
-
startAutoUpdate(controlElement, popperElement, () => {
|
|
56
|
-
syncNativePopover(controlElement, popperElement, config);
|
|
57
|
-
});
|
|
58
|
-
syncNativePopover(controlElement, popperElement, config);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
teardownNativePopover(popperElement);
|
|
63
|
-
popperElement.style.removeProperty("visibility");
|
|
64
|
-
popperElement.style.display = "block";
|
|
65
|
-
|
|
66
|
-
const arrowElement = popperElement.querySelector(
|
|
67
|
-
"[data-monster-role=arrow]",
|
|
68
|
-
);
|
|
69
|
-
const floatingMiddleware = [...config.floatingMiddleware];
|
|
70
|
-
if (
|
|
71
|
-
arrowElement instanceof HTMLElement &&
|
|
72
|
-
config.middlewareTokens.includes("arrow")
|
|
73
|
-
) {
|
|
74
|
-
floatingMiddleware.push(arrow({ element: arrowElement }));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
startAutoUpdate(controlElement, popperElement, () => {
|
|
78
|
-
computePosition(
|
|
79
|
-
controlElement,
|
|
80
|
-
popperElement,
|
|
81
|
-
Object.assign({}, config, {
|
|
82
|
-
middleware: floatingMiddleware,
|
|
83
|
-
}),
|
|
84
|
-
).then(({ x, y, placement, middlewareData }) => {
|
|
85
|
-
Object.assign(popperElement.style, {
|
|
86
|
-
top: "0",
|
|
87
|
-
left: "0",
|
|
88
|
-
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
if (middlewareData.arrow) {
|
|
92
|
-
applyFloatingArrowStyles(
|
|
93
|
-
arrowElement,
|
|
94
|
-
placement,
|
|
95
|
-
middlewareData.arrow,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
49
|
+
enableFloatingPositioning(controlElement, popperElement, config);
|
|
100
50
|
}).run();
|
|
101
51
|
}
|
|
102
52
|
|
|
103
53
|
function openPositionedPopper(controlElement, popperElement, options) {
|
|
104
54
|
const config = normalizePopperConfig(options);
|
|
105
55
|
|
|
106
|
-
if (canUseNativePositionedPopper(controlElement, popperElement, config)) {
|
|
107
|
-
prepareNativePopover(controlElement, popperElement, config);
|
|
108
|
-
popperElement.style.removeProperty("transform");
|
|
109
|
-
if (!matchesPopoverOpen(popperElement)) {
|
|
110
|
-
popperElement.showPopover();
|
|
111
|
-
}
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
teardownNativePopover(popperElement);
|
|
116
|
-
popperElement.style.display = "block";
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function closePositionedPopper(popperElement) {
|
|
120
56
|
stopAutoUpdate(popperElement);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (isNativePopoverElement(popperElement)) {
|
|
124
|
-
if (matchesPopoverOpen(popperElement)) {
|
|
125
|
-
popperElement.hidePopover();
|
|
126
|
-
}
|
|
127
|
-
popperElement.style.display = "none";
|
|
128
|
-
popperElement.style.removeProperty("visibility");
|
|
129
|
-
popperElement.style.removeProperty("transform");
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
57
|
+
popperElement.style.display = "block";
|
|
58
|
+
popperElement.style.removeProperty("transform");
|
|
132
59
|
|
|
133
|
-
|
|
60
|
+
// Keep the call signature stable even though only Floating UI is used now.
|
|
61
|
+
void controlElement;
|
|
62
|
+
void config;
|
|
134
63
|
}
|
|
135
64
|
|
|
136
|
-
function
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
65
|
+
function enableFloatingPositioning(controlElement, popperElement, config) {
|
|
66
|
+
popperElement.style.removeProperty("visibility");
|
|
67
|
+
popperElement.style.display = "block";
|
|
140
68
|
|
|
141
|
-
|
|
69
|
+
startAutoUpdate(controlElement, popperElement, () => {
|
|
70
|
+
syncFloatingPopover(controlElement, popperElement, config);
|
|
71
|
+
});
|
|
72
|
+
syncFloatingPopover(controlElement, popperElement, config);
|
|
142
73
|
}
|
|
143
74
|
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
75
|
+
function syncFloatingPopover(controlElement, popperElement, config) {
|
|
76
|
+
const arrowElement = popperElement.querySelector("[data-monster-role=arrow]");
|
|
77
|
+
const floatingMiddleware = [...config.floatingMiddleware];
|
|
148
78
|
|
|
149
|
-
if (
|
|
150
|
-
|
|
79
|
+
if (
|
|
80
|
+
arrowElement instanceof HTMLElement &&
|
|
81
|
+
config.middlewareTokens.includes("arrow")
|
|
82
|
+
) {
|
|
83
|
+
floatingMiddleware.push(arrow({ element: arrowElement }));
|
|
151
84
|
}
|
|
152
85
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
86
|
+
computePosition(
|
|
87
|
+
controlElement,
|
|
88
|
+
popperElement,
|
|
89
|
+
Object.assign({}, config, {
|
|
90
|
+
middleware: floatingMiddleware,
|
|
91
|
+
}),
|
|
92
|
+
).then(({ x, y, placement, middlewareData }) => {
|
|
93
|
+
Object.assign(popperElement.style, {
|
|
94
|
+
top: "0",
|
|
95
|
+
left: "0",
|
|
96
|
+
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
|
|
97
|
+
});
|
|
156
98
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
99
|
+
if (middlewareData.arrow) {
|
|
100
|
+
applyFloatingArrowStyles(arrowElement, placement, middlewareData.arrow);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
160
104
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
105
|
+
function closePositionedPopper(popperElement) {
|
|
106
|
+
stopAutoUpdate(popperElement);
|
|
107
|
+
popperElement.style.display = "none";
|
|
108
|
+
popperElement.style.removeProperty("visibility");
|
|
109
|
+
popperElement.style.removeProperty("transform");
|
|
110
|
+
}
|
|
164
111
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
CSS.supports("position-anchor: --monster-popper-anchor") &&
|
|
168
|
-
CSS.supports("top: anchor(bottom)")
|
|
169
|
-
);
|
|
112
|
+
function isPositionedPopperOpen(popperElement) {
|
|
113
|
+
return popperElement.style.display === "block";
|
|
170
114
|
}
|
|
171
115
|
|
|
172
116
|
function normalizePopperConfig(options) {
|
|
@@ -174,7 +118,7 @@ function normalizePopperConfig(options) {
|
|
|
174
118
|
{},
|
|
175
119
|
{
|
|
176
120
|
placement: "top",
|
|
177
|
-
engine: "
|
|
121
|
+
engine: "floating",
|
|
178
122
|
},
|
|
179
123
|
options,
|
|
180
124
|
);
|
|
@@ -190,7 +134,7 @@ function normalizePopperConfig(options) {
|
|
|
190
134
|
}
|
|
191
135
|
|
|
192
136
|
function normalizeMiddleware(config) {
|
|
193
|
-
const middleware = config?.
|
|
137
|
+
const middleware = config?.middleware;
|
|
194
138
|
if (isArray(middleware)) {
|
|
195
139
|
return [...middleware];
|
|
196
140
|
}
|
|
@@ -295,493 +239,6 @@ function stopAutoUpdate(popperElement) {
|
|
|
295
239
|
autoUpdateCleanupMap.delete(popperElement);
|
|
296
240
|
}
|
|
297
241
|
|
|
298
|
-
function scheduleNativeArrowSync(controlElement, popperElement) {
|
|
299
|
-
cancelScheduledNativeArrowSync(popperElement);
|
|
300
|
-
|
|
301
|
-
const frameState = {
|
|
302
|
-
outer: 0,
|
|
303
|
-
inner: 0,
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
frameState.outer = requestAnimationFrame(() => {
|
|
307
|
-
frameState.inner = requestAnimationFrame(() => {
|
|
308
|
-
nativeArrowSyncFrameMap.delete(popperElement);
|
|
309
|
-
|
|
310
|
-
if (
|
|
311
|
-
!(controlElement instanceof HTMLElement) ||
|
|
312
|
-
!(popperElement instanceof HTMLElement) ||
|
|
313
|
-
!isNativePopoverElement(popperElement)
|
|
314
|
-
) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (
|
|
319
|
-
!matchesPopoverOpen(popperElement) &&
|
|
320
|
-
popperElement.style.display !== "block"
|
|
321
|
-
) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
syncNativeArrow(controlElement, popperElement);
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
nativeArrowSyncFrameMap.set(popperElement, frameState);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
function cancelScheduledNativeArrowSync(popperElement) {
|
|
333
|
-
const frameState = nativeArrowSyncFrameMap.get(popperElement);
|
|
334
|
-
if (!frameState) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (frameState.outer) {
|
|
339
|
-
cancelAnimationFrame(frameState.outer);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (frameState.inner) {
|
|
343
|
-
cancelAnimationFrame(frameState.inner);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
nativeArrowSyncFrameMap.delete(popperElement);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function prepareNativePopover(controlElement, popperElement, config) {
|
|
350
|
-
const anchorName = getAnchorName(controlElement);
|
|
351
|
-
popperElement.dataset.monsterPopperEngine = "native";
|
|
352
|
-
popperElement.setAttribute("popover", "manual");
|
|
353
|
-
controlElement.style.setProperty("anchor-name", anchorName);
|
|
354
|
-
popperElement.style.setProperty("position-anchor", anchorName);
|
|
355
|
-
popperElement.style.setProperty("inset", "auto");
|
|
356
|
-
popperElement.style.setProperty("margin", "0");
|
|
357
|
-
popperElement.style.setProperty("overflow", "visible");
|
|
358
|
-
popperElement.style.display = "block";
|
|
359
|
-
popperElement.style.removeProperty("transform");
|
|
360
|
-
applyNativeTryFallbacks(popperElement, config);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function teardownNativePopover(popperElement) {
|
|
364
|
-
if (!isNativePopoverElement(popperElement)) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (matchesPopoverOpen(popperElement)) {
|
|
369
|
-
popperElement.hidePopover();
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
cancelScheduledNativeArrowSync(popperElement);
|
|
373
|
-
delete popperElement.dataset.monsterPopperEngine;
|
|
374
|
-
popperElement.removeAttribute("popover");
|
|
375
|
-
popperElement.style.removeProperty("position-anchor");
|
|
376
|
-
popperElement.style.removeProperty("position-area");
|
|
377
|
-
popperElement.style.removeProperty("inset-area");
|
|
378
|
-
popperElement.style.removeProperty("position-try");
|
|
379
|
-
popperElement.style.removeProperty("position-try-fallbacks");
|
|
380
|
-
popperElement.style.removeProperty("margin");
|
|
381
|
-
popperElement.style.removeProperty("margin-top");
|
|
382
|
-
popperElement.style.removeProperty("margin-right");
|
|
383
|
-
popperElement.style.removeProperty("margin-bottom");
|
|
384
|
-
popperElement.style.removeProperty("margin-left");
|
|
385
|
-
popperElement.style.removeProperty("inset");
|
|
386
|
-
popperElement.style.removeProperty("overflow");
|
|
387
|
-
popperElement.style.removeProperty("--monster-popper-control-width");
|
|
388
|
-
popperElement.style.removeProperty("--monster-popper-control-height");
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
function syncNativePopover(controlElement, popperElement, config) {
|
|
392
|
-
const controlRect = controlElement.getBoundingClientRect();
|
|
393
|
-
const placement = resolvePlacement(config.placement);
|
|
394
|
-
const offsetValue = resolveOffset(config.middlewareTokens);
|
|
395
|
-
|
|
396
|
-
popperElement.style.setProperty(
|
|
397
|
-
"--monster-popper-control-width",
|
|
398
|
-
`${Math.round(controlRect.width)}px`,
|
|
399
|
-
);
|
|
400
|
-
popperElement.style.setProperty(
|
|
401
|
-
"--monster-popper-control-height",
|
|
402
|
-
`${Math.round(controlRect.height)}px`,
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
applyNativePlacementStyles(popperElement, placement, offsetValue);
|
|
406
|
-
popperElement.style.removeProperty("visibility");
|
|
407
|
-
syncNativeArrow(controlElement, popperElement);
|
|
408
|
-
scheduleNativeArrowSync(controlElement, popperElement);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
function resolvePlacement(value) {
|
|
412
|
-
if (!isString(value) || value.trim().length === 0) {
|
|
413
|
-
return { side: "top", align: "center" };
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
const [rawSide, rawAlign] = value.split("-");
|
|
417
|
-
const side = rawSide === "auto" ? "top" : rawSide;
|
|
418
|
-
const align =
|
|
419
|
-
rawAlign === "start" || rawAlign === "end" ? rawAlign : "center";
|
|
420
|
-
|
|
421
|
-
if (!["top", "bottom", "left", "right"].includes(side)) {
|
|
422
|
-
return { side: "top", align: "center" };
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return { side, align };
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
function resolveOffset(middleware) {
|
|
429
|
-
if (!isArray(middleware)) {
|
|
430
|
-
return 10;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
for (const entry of middleware) {
|
|
434
|
-
if (!isString(entry) || !entry.startsWith("offset")) {
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
const [, rawValue] = entry.split(":");
|
|
439
|
-
const parsed = parseInt(rawValue);
|
|
440
|
-
if (Number.isFinite(parsed)) {
|
|
441
|
-
return parsed;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
return 10;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function applyNativePlacementStyles(
|
|
449
|
-
popperElement,
|
|
450
|
-
{ side, align },
|
|
451
|
-
offsetValue,
|
|
452
|
-
) {
|
|
453
|
-
if (supportsNativePositionArea()) {
|
|
454
|
-
applyNativePositionAreaStyles(popperElement, { side, align }, offsetValue);
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
popperElement.style.removeProperty("position-area");
|
|
459
|
-
popperElement.style.removeProperty("inset-area");
|
|
460
|
-
popperElement.style.removeProperty("margin-top");
|
|
461
|
-
popperElement.style.removeProperty("margin-right");
|
|
462
|
-
popperElement.style.removeProperty("margin-bottom");
|
|
463
|
-
popperElement.style.removeProperty("margin-left");
|
|
464
|
-
popperElement.style.removeProperty("top");
|
|
465
|
-
popperElement.style.removeProperty("right");
|
|
466
|
-
popperElement.style.removeProperty("bottom");
|
|
467
|
-
popperElement.style.removeProperty("left");
|
|
468
|
-
|
|
469
|
-
switch (side) {
|
|
470
|
-
case "bottom":
|
|
471
|
-
popperElement.style.setProperty(
|
|
472
|
-
"top",
|
|
473
|
-
`calc(anchor(bottom) + ${offsetValue}px)`,
|
|
474
|
-
);
|
|
475
|
-
applyHorizontalAlignment(popperElement, align);
|
|
476
|
-
break;
|
|
477
|
-
case "left":
|
|
478
|
-
popperElement.style.setProperty(
|
|
479
|
-
"left",
|
|
480
|
-
`calc(anchor(left) - 100% - ${offsetValue}px)`,
|
|
481
|
-
);
|
|
482
|
-
applyVerticalAlignment(popperElement, align);
|
|
483
|
-
break;
|
|
484
|
-
case "right":
|
|
485
|
-
popperElement.style.setProperty(
|
|
486
|
-
"left",
|
|
487
|
-
`calc(anchor(right) + ${offsetValue}px)`,
|
|
488
|
-
);
|
|
489
|
-
applyVerticalAlignment(popperElement, align);
|
|
490
|
-
break;
|
|
491
|
-
case "top":
|
|
492
|
-
default:
|
|
493
|
-
popperElement.style.setProperty(
|
|
494
|
-
"top",
|
|
495
|
-
`calc(anchor(top) - 100% - ${offsetValue}px)`,
|
|
496
|
-
);
|
|
497
|
-
applyHorizontalAlignment(popperElement, align);
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
function applyNativePositionAreaStyles(
|
|
503
|
-
popperElement,
|
|
504
|
-
{ side, align },
|
|
505
|
-
offsetValue,
|
|
506
|
-
) {
|
|
507
|
-
const positionArea = resolveNativePositionArea({ side, align });
|
|
508
|
-
|
|
509
|
-
popperElement.style.removeProperty("top");
|
|
510
|
-
popperElement.style.removeProperty("right");
|
|
511
|
-
popperElement.style.removeProperty("bottom");
|
|
512
|
-
popperElement.style.removeProperty("left");
|
|
513
|
-
popperElement.style.setProperty("position-area", positionArea);
|
|
514
|
-
popperElement.style.setProperty("inset-area", positionArea);
|
|
515
|
-
popperElement.style.setProperty("margin-top", "0px");
|
|
516
|
-
popperElement.style.setProperty("margin-right", "0px");
|
|
517
|
-
popperElement.style.setProperty("margin-bottom", "0px");
|
|
518
|
-
popperElement.style.setProperty("margin-left", "0px");
|
|
519
|
-
|
|
520
|
-
switch (side) {
|
|
521
|
-
case "bottom":
|
|
522
|
-
popperElement.style.setProperty("margin-top", `${offsetValue}px`);
|
|
523
|
-
break;
|
|
524
|
-
case "left":
|
|
525
|
-
popperElement.style.setProperty("margin-right", `${offsetValue}px`);
|
|
526
|
-
break;
|
|
527
|
-
case "right":
|
|
528
|
-
popperElement.style.setProperty("margin-left", `${offsetValue}px`);
|
|
529
|
-
break;
|
|
530
|
-
case "top":
|
|
531
|
-
default:
|
|
532
|
-
popperElement.style.setProperty("margin-bottom", `${offsetValue}px`);
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
function resolveNativePositionArea({ side, align }) {
|
|
538
|
-
switch (side) {
|
|
539
|
-
case "bottom":
|
|
540
|
-
switch (align) {
|
|
541
|
-
case "end":
|
|
542
|
-
return "bottom span-left";
|
|
543
|
-
case "center":
|
|
544
|
-
return "bottom center";
|
|
545
|
-
case "start":
|
|
546
|
-
default:
|
|
547
|
-
return "bottom span-right";
|
|
548
|
-
}
|
|
549
|
-
case "left":
|
|
550
|
-
switch (align) {
|
|
551
|
-
case "end":
|
|
552
|
-
return "left span-top";
|
|
553
|
-
case "center":
|
|
554
|
-
return "left center";
|
|
555
|
-
case "start":
|
|
556
|
-
default:
|
|
557
|
-
return "left span-bottom";
|
|
558
|
-
}
|
|
559
|
-
case "right":
|
|
560
|
-
switch (align) {
|
|
561
|
-
case "end":
|
|
562
|
-
return "right span-top";
|
|
563
|
-
case "center":
|
|
564
|
-
return "right center";
|
|
565
|
-
case "start":
|
|
566
|
-
default:
|
|
567
|
-
return "right span-bottom";
|
|
568
|
-
}
|
|
569
|
-
case "top":
|
|
570
|
-
default:
|
|
571
|
-
switch (align) {
|
|
572
|
-
case "end":
|
|
573
|
-
return "top span-left";
|
|
574
|
-
case "center":
|
|
575
|
-
return "top center";
|
|
576
|
-
case "start":
|
|
577
|
-
default:
|
|
578
|
-
return "top span-right";
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function supportsNativePositionArea() {
|
|
584
|
-
if (typeof CSS === "undefined") {
|
|
585
|
-
return false;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
return (
|
|
589
|
-
CSS.supports("position-area: bottom center") ||
|
|
590
|
-
CSS.supports("inset-area: bottom center")
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
function applyHorizontalAlignment(popperElement, align) {
|
|
595
|
-
switch (align) {
|
|
596
|
-
case "end":
|
|
597
|
-
popperElement.style.setProperty("left", "calc(anchor(right) - 100%)");
|
|
598
|
-
break;
|
|
599
|
-
case "center":
|
|
600
|
-
popperElement.style.setProperty(
|
|
601
|
-
"left",
|
|
602
|
-
"calc(anchor(left) + (var(--monster-popper-control-width) - 100%) / 2)",
|
|
603
|
-
);
|
|
604
|
-
break;
|
|
605
|
-
case "start":
|
|
606
|
-
default:
|
|
607
|
-
popperElement.style.setProperty("left", "anchor(left)");
|
|
608
|
-
break;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
function applyVerticalAlignment(popperElement, align) {
|
|
613
|
-
switch (align) {
|
|
614
|
-
case "end":
|
|
615
|
-
popperElement.style.setProperty("top", "calc(anchor(bottom) - 100%)");
|
|
616
|
-
break;
|
|
617
|
-
case "center":
|
|
618
|
-
popperElement.style.setProperty(
|
|
619
|
-
"top",
|
|
620
|
-
"calc(anchor(top) + (var(--monster-popper-control-height) - 100%) / 2)",
|
|
621
|
-
);
|
|
622
|
-
break;
|
|
623
|
-
case "start":
|
|
624
|
-
default:
|
|
625
|
-
popperElement.style.setProperty("top", "anchor(top)");
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
function applyNativeTryFallbacks(popperElement, config) {
|
|
631
|
-
const middleware = config.middlewareTokens || [];
|
|
632
|
-
const placement = resolvePlacement(config.placement);
|
|
633
|
-
let fallbacks = "";
|
|
634
|
-
|
|
635
|
-
if (
|
|
636
|
-
middleware.some(
|
|
637
|
-
(entry) => isString(entry) && entry.startsWith("autoPlacement"),
|
|
638
|
-
)
|
|
639
|
-
) {
|
|
640
|
-
fallbacks =
|
|
641
|
-
placement.side === "left" || placement.side === "right"
|
|
642
|
-
? "flip-inline, flip-block"
|
|
643
|
-
: "flip-block, flip-inline";
|
|
644
|
-
} else if (middleware.includes("flip")) {
|
|
645
|
-
fallbacks =
|
|
646
|
-
placement.side === "left" || placement.side === "right"
|
|
647
|
-
? "flip-inline"
|
|
648
|
-
: "flip-block";
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
if (fallbacks.length === 0) {
|
|
652
|
-
popperElement.style.removeProperty("position-try");
|
|
653
|
-
popperElement.style.removeProperty("position-try-fallbacks");
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
popperElement.style.setProperty("position-try", fallbacks);
|
|
658
|
-
popperElement.style.setProperty("position-try-fallbacks", fallbacks);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function syncNativeArrow(controlElement, popperElement) {
|
|
662
|
-
const arrowElement = popperElement.querySelector("[data-monster-role=arrow]");
|
|
663
|
-
|
|
664
|
-
if (!(arrowElement instanceof HTMLElement)) {
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
const controlRect = controlElement.getBoundingClientRect();
|
|
669
|
-
const popperRect = popperElement.getBoundingClientRect();
|
|
670
|
-
const arrowHalf = arrowElement.offsetWidth / 2;
|
|
671
|
-
|
|
672
|
-
if (arrowHalf === 0) {
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
const side = resolveArrowSide(controlRect, popperRect);
|
|
677
|
-
const staticSide = side;
|
|
678
|
-
const defaultBorder =
|
|
679
|
-
"var(--monster-border-width) var(--monster-border-style) var(--monster-bg-color-primary-4)";
|
|
680
|
-
const borderStyle = {
|
|
681
|
-
borderLeft: "transparent",
|
|
682
|
-
borderRight: "transparent",
|
|
683
|
-
borderBottom: "transparent",
|
|
684
|
-
borderTop: "transparent",
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
switch (side) {
|
|
688
|
-
case "top":
|
|
689
|
-
borderStyle.borderTop = defaultBorder;
|
|
690
|
-
borderStyle.borderLeft = defaultBorder;
|
|
691
|
-
break;
|
|
692
|
-
case "bottom":
|
|
693
|
-
borderStyle.borderRight = defaultBorder;
|
|
694
|
-
borderStyle.borderBottom = defaultBorder;
|
|
695
|
-
break;
|
|
696
|
-
case "left":
|
|
697
|
-
borderStyle.borderLeft = defaultBorder;
|
|
698
|
-
borderStyle.borderBottom = defaultBorder;
|
|
699
|
-
break;
|
|
700
|
-
case "right":
|
|
701
|
-
borderStyle.borderTop = defaultBorder;
|
|
702
|
-
borderStyle.borderRight = defaultBorder;
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
const arrowOffset = resolveArrowOffset(
|
|
707
|
-
side,
|
|
708
|
-
controlRect,
|
|
709
|
-
popperRect,
|
|
710
|
-
arrowHalf,
|
|
711
|
-
);
|
|
712
|
-
const arrowLen = arrowElement.offsetWidth + 4;
|
|
713
|
-
|
|
714
|
-
Object.assign(
|
|
715
|
-
arrowElement.style,
|
|
716
|
-
{
|
|
717
|
-
left: side === "top" || side === "bottom" ? `${arrowOffset}px` : "",
|
|
718
|
-
top: side === "left" || side === "right" ? `${arrowOffset}px` : "",
|
|
719
|
-
right: "",
|
|
720
|
-
bottom: "",
|
|
721
|
-
[staticSide]: `${-arrowLen / 2}px`,
|
|
722
|
-
transform: "rotate(45deg)",
|
|
723
|
-
},
|
|
724
|
-
borderStyle,
|
|
725
|
-
);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function resolveArrowSide(controlRect, popperRect) {
|
|
729
|
-
const triggerCenterX = controlRect.left + controlRect.width / 2;
|
|
730
|
-
const triggerCenterY = controlRect.top + controlRect.height / 2;
|
|
731
|
-
const candidates = [];
|
|
732
|
-
|
|
733
|
-
if (triggerCenterY <= popperRect.top) {
|
|
734
|
-
candidates.push({
|
|
735
|
-
side: "top",
|
|
736
|
-
distance: popperRect.top - triggerCenterY,
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
if (triggerCenterY >= popperRect.bottom) {
|
|
741
|
-
candidates.push({
|
|
742
|
-
side: "bottom",
|
|
743
|
-
distance: triggerCenterY - popperRect.bottom,
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
if (triggerCenterX <= popperRect.left) {
|
|
748
|
-
candidates.push({
|
|
749
|
-
side: "left",
|
|
750
|
-
distance: popperRect.left - triggerCenterX,
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
if (triggerCenterX >= popperRect.right) {
|
|
755
|
-
candidates.push({
|
|
756
|
-
side: "right",
|
|
757
|
-
distance: triggerCenterX - popperRect.right,
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
if (candidates.length === 0) {
|
|
762
|
-
return "top";
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
candidates.sort((a, b) => a.distance - b.distance);
|
|
766
|
-
return candidates[0].side;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
function resolveArrowOffset(side, controlRect, popperRect, arrowHalf) {
|
|
770
|
-
if (side === "top" || side === "bottom") {
|
|
771
|
-
return clamp(
|
|
772
|
-
controlRect.left + controlRect.width / 2 - popperRect.left - arrowHalf,
|
|
773
|
-
0,
|
|
774
|
-
Math.max(0, popperRect.width - arrowHalf * 2),
|
|
775
|
-
);
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
return clamp(
|
|
779
|
-
controlRect.top + controlRect.height / 2 - popperRect.top - arrowHalf,
|
|
780
|
-
0,
|
|
781
|
-
Math.max(0, popperRect.height - arrowHalf * 2),
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
242
|
function applyFloatingArrowStyles(arrowElement, placement, arrowData) {
|
|
786
243
|
if (!(arrowElement instanceof HTMLElement)) {
|
|
787
244
|
return;
|
|
@@ -837,34 +294,6 @@ function applyFloatingArrowStyles(arrowElement, placement, arrowData) {
|
|
|
837
294
|
);
|
|
838
295
|
}
|
|
839
296
|
|
|
840
|
-
function getAnchorName(controlElement) {
|
|
841
|
-
if (!anchorNameMap.has(controlElement)) {
|
|
842
|
-
anchorNameCounter += 1;
|
|
843
|
-
anchorNameMap.set(
|
|
844
|
-
controlElement,
|
|
845
|
-
`--monster-popper-anchor-${anchorNameCounter}`,
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
return anchorNameMap.get(controlElement);
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
function isNativePopoverElement(popperElement) {
|
|
853
|
-
return popperElement?.dataset?.monsterPopperEngine === "native";
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
function matchesPopoverOpen(popperElement) {
|
|
857
|
-
try {
|
|
858
|
-
return popperElement.matches(":popover-open");
|
|
859
|
-
} catch (e) {
|
|
860
|
-
return false;
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
function clamp(value, min, max) {
|
|
865
|
-
return Math.min(Math.max(value, min), max);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
297
|
function roundByDPR(value) {
|
|
869
298
|
const dpr = window.devicePixelRatio || 1;
|
|
870
299
|
return Math.round(value * dpr) / dpr;
|
|
@@ -169,8 +169,8 @@ class Popper extends CustomElement {
|
|
|
169
169
|
content: "<slot></slot>",
|
|
170
170
|
popper: {
|
|
171
171
|
placement: "top",
|
|
172
|
-
engine: "
|
|
173
|
-
middleware: ["
|
|
172
|
+
engine: "floating",
|
|
173
|
+
middleware: ["flip", "shift", "offset:15", "arrow"],
|
|
174
174
|
contentOverflow: "both",
|
|
175
175
|
},
|
|
176
176
|
features: {
|
|
@@ -9,29 +9,24 @@ let expect = chai.expect;
|
|
|
9
9
|
chai.use(chaiDom);
|
|
10
10
|
|
|
11
11
|
describe('ImageEditor', function () {
|
|
12
|
+
this.timeout(10000);
|
|
12
13
|
|
|
13
14
|
let ImageEditor, document;
|
|
14
15
|
let registerCustomElement;
|
|
15
16
|
let CustomElement;
|
|
16
17
|
let assembleMethodSymbol;
|
|
17
18
|
|
|
18
|
-
before(function (
|
|
19
|
-
initJSDOM({})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
done();
|
|
30
|
-
} catch (e) {
|
|
31
|
-
done(e);
|
|
32
|
-
}
|
|
33
|
-
}).catch((e) => done(e));
|
|
34
|
-
});
|
|
19
|
+
before(async function () {
|
|
20
|
+
await initJSDOM({});
|
|
21
|
+
|
|
22
|
+
const domModule = await import("../../../../source/dom/customelement.mjs");
|
|
23
|
+
registerCustomElement = domModule['registerCustomElement'];
|
|
24
|
+
CustomElement = domModule['CustomElement'];
|
|
25
|
+
assembleMethodSymbol = domModule['assembleMethodSymbol'];
|
|
26
|
+
|
|
27
|
+
const componentModule = await import("../../../../source/components/content/image-editor.mjs");
|
|
28
|
+
ImageEditor = componentModule['ImageEditor'];
|
|
29
|
+
document = getDocument();
|
|
35
30
|
});
|
|
36
31
|
|
|
37
32
|
beforeEach(() => {
|