@rogieking/figui3 2.0.3 → 2.0.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/components.css +181 -1
- package/example.html +855 -227
- package/fig.js +172 -2
- package/package.json +1 -1
package/fig.js
CHANGED
|
@@ -5,6 +5,25 @@
|
|
|
5
5
|
function figUniqueId() {
|
|
6
6
|
return Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Gets the highest z-index currently in use on the page
|
|
11
|
+
* @returns {number} The highest z-index found, minimum of 1000
|
|
12
|
+
*/
|
|
13
|
+
function figGetHighestZIndex() {
|
|
14
|
+
let highest = 1000; // Baseline minimum
|
|
15
|
+
|
|
16
|
+
// Check all elements with inline z-index or computed z-index
|
|
17
|
+
const elements = document.querySelectorAll("*");
|
|
18
|
+
for (const el of elements) {
|
|
19
|
+
const zIndex = parseInt(getComputedStyle(el).zIndex, 10);
|
|
20
|
+
if (!isNaN(zIndex) && zIndex > highest) {
|
|
21
|
+
highest = zIndex;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return highest;
|
|
26
|
+
}
|
|
8
27
|
/**
|
|
9
28
|
* Checks if the browser supports the native popover API
|
|
10
29
|
* @returns {boolean} True if popover is supported
|
|
@@ -326,7 +345,15 @@ class FigTooltip extends HTMLElement {
|
|
|
326
345
|
this.popup.style.pointerEvents = "none";
|
|
327
346
|
this.popup.append(content);
|
|
328
347
|
content.innerText = this.getAttribute("text");
|
|
329
|
-
|
|
348
|
+
|
|
349
|
+
// If tooltip is inside a dialog, append to dialog to stay in top layer
|
|
350
|
+
const parentDialog = this.closest("dialog");
|
|
351
|
+
if (parentDialog && parentDialog.open) {
|
|
352
|
+
parentDialog.append(this.popup);
|
|
353
|
+
} else {
|
|
354
|
+
document.body.append(this.popup);
|
|
355
|
+
}
|
|
356
|
+
|
|
330
357
|
const text = content.childNodes[0];
|
|
331
358
|
if (text) {
|
|
332
359
|
const range = document.createRange();
|
|
@@ -451,7 +478,7 @@ class FigTooltip extends HTMLElement {
|
|
|
451
478
|
this.popup.style.visibility = "visible";
|
|
452
479
|
this.popup.style.display = "block";
|
|
453
480
|
this.popup.style.pointerEvents = "all";
|
|
454
|
-
this.popup.style.zIndex =
|
|
481
|
+
this.popup.style.zIndex = figGetHighestZIndex() + 1;
|
|
455
482
|
|
|
456
483
|
this.isOpen = true;
|
|
457
484
|
}
|
|
@@ -2695,6 +2722,9 @@ class FigChit extends HTMLElement {
|
|
|
2695
2722
|
this.#src = value;
|
|
2696
2723
|
this.setAttribute("src", value);
|
|
2697
2724
|
}
|
|
2725
|
+
focus() {
|
|
2726
|
+
this.input?.focus();
|
|
2727
|
+
}
|
|
2698
2728
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
2699
2729
|
switch (name) {
|
|
2700
2730
|
case "src":
|
|
@@ -3173,6 +3203,10 @@ class FigInputJoystick extends HTMLElement {
|
|
|
3173
3203
|
#handleKeyUp(e) {
|
|
3174
3204
|
if (e.key === "Shift") this.isShiftHeld = false;
|
|
3175
3205
|
}
|
|
3206
|
+
focus() {
|
|
3207
|
+
const container = this.querySelector(".fig-input-joystick-plane-container");
|
|
3208
|
+
container?.focus();
|
|
3209
|
+
}
|
|
3176
3210
|
static get observedAttributes() {
|
|
3177
3211
|
return ["value", "precision", "transform", "text", "coordinates"];
|
|
3178
3212
|
}
|
|
@@ -3444,6 +3478,10 @@ class FigInputAngle extends HTMLElement {
|
|
|
3444
3478
|
if (e.key === "Shift") this.isShiftHeld = false;
|
|
3445
3479
|
}
|
|
3446
3480
|
|
|
3481
|
+
focus() {
|
|
3482
|
+
this.plane?.focus();
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3447
3485
|
static get observedAttributes() {
|
|
3448
3486
|
return ["value", "precision", "text"];
|
|
3449
3487
|
}
|
|
@@ -3484,3 +3522,135 @@ class FigInputAngle extends HTMLElement {
|
|
|
3484
3522
|
}
|
|
3485
3523
|
}
|
|
3486
3524
|
customElements.define("fig-input-angle", FigInputAngle);
|
|
3525
|
+
|
|
3526
|
+
// FigShimmer
|
|
3527
|
+
class FigShimmer extends HTMLElement {
|
|
3528
|
+
connectedCallback() {
|
|
3529
|
+
const duration = this.getAttribute("duration");
|
|
3530
|
+
if (duration) {
|
|
3531
|
+
this.style.setProperty("--shimmer-duration", duration);
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3535
|
+
static get observedAttributes() {
|
|
3536
|
+
return ["duration", "playing"];
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
get playing() {
|
|
3540
|
+
return this.getAttribute("playing") !== "false";
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
set playing(value) {
|
|
3544
|
+
if (value) {
|
|
3545
|
+
this.removeAttribute("playing"); // Default is playing
|
|
3546
|
+
} else {
|
|
3547
|
+
this.setAttribute("playing", "false");
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
|
|
3551
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
3552
|
+
if (name === "duration") {
|
|
3553
|
+
this.style.setProperty("--shimmer-duration", newValue || "1.5s");
|
|
3554
|
+
}
|
|
3555
|
+
// playing is handled purely by CSS attribute selectors
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
customElements.define("fig-shimmer", FigShimmer);
|
|
3559
|
+
|
|
3560
|
+
// FigLayer
|
|
3561
|
+
class FigLayer extends HTMLElement {
|
|
3562
|
+
static get observedAttributes() {
|
|
3563
|
+
return ["open", "visible"];
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
connectedCallback() {
|
|
3567
|
+
// Add click listener for chevron toggle
|
|
3568
|
+
this.addEventListener("click", this.#handleClick.bind(this));
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3571
|
+
disconnectedCallback() {
|
|
3572
|
+
this.removeEventListener("click", this.#handleClick.bind(this));
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3575
|
+
#handleClick(e) {
|
|
3576
|
+
// Toggle when clicking on the row (but not on actions or interactive elements)
|
|
3577
|
+
const row = e.target.closest(".fig-layer-row");
|
|
3578
|
+
if (row && row.parentElement === this) {
|
|
3579
|
+
// Don't toggle if clicking on actions or buttons
|
|
3580
|
+
if (e.target.closest(".fig-layer-actions") || e.target.closest("fig-button")) {
|
|
3581
|
+
return;
|
|
3582
|
+
}
|
|
3583
|
+
e.stopPropagation();
|
|
3584
|
+
this.open = !this.open;
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
get open() {
|
|
3589
|
+
const attr = this.getAttribute("open");
|
|
3590
|
+
return attr !== null && attr !== "false";
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
set open(value) {
|
|
3594
|
+
const oldValue = this.open;
|
|
3595
|
+
if (value) {
|
|
3596
|
+
this.setAttribute("open", "true");
|
|
3597
|
+
} else {
|
|
3598
|
+
this.setAttribute("open", "false");
|
|
3599
|
+
}
|
|
3600
|
+
if (oldValue !== value) {
|
|
3601
|
+
this.dispatchEvent(
|
|
3602
|
+
new CustomEvent("openchange", {
|
|
3603
|
+
detail: { open: value },
|
|
3604
|
+
bubbles: true,
|
|
3605
|
+
})
|
|
3606
|
+
);
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
get visible() {
|
|
3611
|
+
const attr = this.getAttribute("visible");
|
|
3612
|
+
return attr !== "false";
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
set visible(value) {
|
|
3616
|
+
const oldValue = this.visible;
|
|
3617
|
+
if (value) {
|
|
3618
|
+
this.setAttribute("visible", "true");
|
|
3619
|
+
} else {
|
|
3620
|
+
this.setAttribute("visible", "false");
|
|
3621
|
+
}
|
|
3622
|
+
if (oldValue !== value) {
|
|
3623
|
+
this.dispatchEvent(
|
|
3624
|
+
new CustomEvent("visibilitychange", {
|
|
3625
|
+
detail: { visible: value },
|
|
3626
|
+
bubbles: true,
|
|
3627
|
+
})
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
|
|
3632
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
3633
|
+
if (oldValue === newValue) return;
|
|
3634
|
+
|
|
3635
|
+
if (name === "open") {
|
|
3636
|
+
const isOpen = newValue !== null && newValue !== "false";
|
|
3637
|
+
this.dispatchEvent(
|
|
3638
|
+
new CustomEvent("openchange", {
|
|
3639
|
+
detail: { open: isOpen },
|
|
3640
|
+
bubbles: true,
|
|
3641
|
+
})
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
|
|
3645
|
+
if (name === "visible") {
|
|
3646
|
+
const isVisible = newValue !== "false";
|
|
3647
|
+
this.dispatchEvent(
|
|
3648
|
+
new CustomEvent("visibilitychange", {
|
|
3649
|
+
detail: { visible: isVisible },
|
|
3650
|
+
bubbles: true,
|
|
3651
|
+
})
|
|
3652
|
+
);
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
customElements.define("fig-layer", FigLayer);
|