@rogieking/figui3 9.1.0 → 9.1.2
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 +8 -1
- package/dist/components.css +1 -1
- package/dist/fig-editor.css +1 -1
- package/dist/fig.css +1 -1
- package/dist/fig.js +5 -5
- package/fig-editor.css +1 -1
- package/fig.js +72 -13
- package/package.json +1 -1
package/fig-editor.css
CHANGED
package/fig.js
CHANGED
|
@@ -14774,6 +14774,11 @@ class FigEasingCurve extends HTMLElement {
|
|
|
14774
14774
|
}
|
|
14775
14775
|
|
|
14776
14776
|
#createHandle(className, dataHandle, label) {
|
|
14777
|
+
const handle = figCreateElement("fig-handle", {
|
|
14778
|
+
size: "small",
|
|
14779
|
+
type: "minimal",
|
|
14780
|
+
"aria-label": label,
|
|
14781
|
+
});
|
|
14777
14782
|
return figCreateSvgElement(
|
|
14778
14783
|
"foreignObject",
|
|
14779
14784
|
{
|
|
@@ -14782,14 +14787,49 @@ class FigEasingCurve extends HTMLElement {
|
|
|
14782
14787
|
width: "20",
|
|
14783
14788
|
height: "20",
|
|
14784
14789
|
},
|
|
14785
|
-
figCreateElement(
|
|
14786
|
-
|
|
14787
|
-
|
|
14788
|
-
|
|
14789
|
-
|
|
14790
|
+
figCreateElement(
|
|
14791
|
+
"fig-tooltip",
|
|
14792
|
+
{ text: this.#handleTooltipText(dataHandle) },
|
|
14793
|
+
handle,
|
|
14794
|
+
),
|
|
14790
14795
|
);
|
|
14791
14796
|
}
|
|
14792
14797
|
|
|
14798
|
+
#formatHandleTooltipNumber(value) {
|
|
14799
|
+
if (!Number.isFinite(value)) return "0";
|
|
14800
|
+
return String(Number(value.toFixed(this.#precision)));
|
|
14801
|
+
}
|
|
14802
|
+
|
|
14803
|
+
#handleTooltipText(handle) {
|
|
14804
|
+
if (this.#mode === "spring") {
|
|
14805
|
+
if (handle === "bounce") {
|
|
14806
|
+
return `Bounce ${this.#formatHandleTooltipNumber(this.#springBounce())}`;
|
|
14807
|
+
}
|
|
14808
|
+
return `Duration ${Math.round(this.#springDuration * 100)}%`;
|
|
14809
|
+
}
|
|
14810
|
+
|
|
14811
|
+
const point = handle === "1" ? this.#cp1 : this.#cp2;
|
|
14812
|
+
const label = handle === "1" ? "Start" : "End";
|
|
14813
|
+
return `${label} ${this.#formatHandleTooltipNumber(point.x)}, ${this.#formatHandleTooltipNumber(point.y)}`;
|
|
14814
|
+
}
|
|
14815
|
+
|
|
14816
|
+
#syncHandleTooltips() {
|
|
14817
|
+
for (const [container, handle] of [
|
|
14818
|
+
[this.#handle1, this.#mode === "spring" ? "bounce" : "1"],
|
|
14819
|
+
[this.#handle2, this.#mode === "spring" ? "duration" : "2"],
|
|
14820
|
+
]) {
|
|
14821
|
+
const tooltip = container?.querySelector("fig-tooltip");
|
|
14822
|
+
if (tooltip) tooltip.text = this.#handleTooltipText(handle);
|
|
14823
|
+
}
|
|
14824
|
+
}
|
|
14825
|
+
|
|
14826
|
+
#toggleHandleTooltip(container, show) {
|
|
14827
|
+
const tooltip = container?.querySelector("fig-tooltip");
|
|
14828
|
+
if (!tooltip) return;
|
|
14829
|
+
if (show) tooltip.setAttribute("show", "true");
|
|
14830
|
+
else tooltip.removeAttribute("show");
|
|
14831
|
+
}
|
|
14832
|
+
|
|
14793
14833
|
#createContent() {
|
|
14794
14834
|
const size = 200;
|
|
14795
14835
|
const select = this.#isPresetsEnabled() ? this.#createSelect() : null;
|
|
@@ -15038,6 +15078,7 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15038
15078
|
} else {
|
|
15039
15079
|
this.#updateBezierPaths();
|
|
15040
15080
|
}
|
|
15081
|
+
this.#syncHandleTooltips();
|
|
15041
15082
|
}
|
|
15042
15083
|
|
|
15043
15084
|
#syncActiveBezierArm() {
|
|
@@ -15134,7 +15175,7 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15134
15175
|
totalTime,
|
|
15135
15176
|
};
|
|
15136
15177
|
|
|
15137
|
-
const durationNorm = Math.max(0.05, Math.min(
|
|
15178
|
+
const durationNorm = Math.max(0.05, Math.min(1, this.#springDuration));
|
|
15138
15179
|
let d = "";
|
|
15139
15180
|
for (let i = 0; i < points.length; i++) {
|
|
15140
15181
|
const nt = (points[i].t / totalTime) * durationNorm;
|
|
@@ -15173,10 +15214,21 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15173
15214
|
#findPeakOvershoot(points) {
|
|
15174
15215
|
let peak = { t: 0, value: 1 };
|
|
15175
15216
|
let passedTarget = false;
|
|
15176
|
-
for (
|
|
15177
|
-
|
|
15178
|
-
|
|
15179
|
-
|
|
15217
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
15218
|
+
const previous = points[i - 1];
|
|
15219
|
+
const current = points[i];
|
|
15220
|
+
const next = points[i + 1];
|
|
15221
|
+
if (current.value >= 0.99) passedTarget = true;
|
|
15222
|
+
if (passedTarget && current.value > peak.value) {
|
|
15223
|
+
peak = { t: current.t, value: current.value };
|
|
15224
|
+
}
|
|
15225
|
+
if (
|
|
15226
|
+
passedTarget &&
|
|
15227
|
+
current.value > 1 &&
|
|
15228
|
+
current.value >= previous.value &&
|
|
15229
|
+
current.value >= next.value
|
|
15230
|
+
) {
|
|
15231
|
+
return { t: current.t, value: current.value };
|
|
15180
15232
|
}
|
|
15181
15233
|
}
|
|
15182
15234
|
return peak;
|
|
@@ -15378,14 +15430,14 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15378
15430
|
this.#spring.stiffness = Math.max(10, Math.round(this.#spring.stiffness + dx * 1.5));
|
|
15379
15431
|
break;
|
|
15380
15432
|
case "ArrowRight":
|
|
15381
|
-
this.#springDuration = Math.min(
|
|
15433
|
+
this.#springDuration = Math.min(1, this.#springDuration + dx / 200);
|
|
15382
15434
|
this.#spring.stiffness = Math.max(10, Math.round(this.#spring.stiffness - dx * 1.5));
|
|
15383
15435
|
break;
|
|
15384
15436
|
case "Home":
|
|
15385
15437
|
this.#springDuration = 0.05;
|
|
15386
15438
|
break;
|
|
15387
15439
|
case "End":
|
|
15388
|
-
this.#springDuration =
|
|
15440
|
+
this.#springDuration = 1;
|
|
15389
15441
|
break;
|
|
15390
15442
|
default:
|
|
15391
15443
|
return false;
|
|
@@ -15587,6 +15639,8 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15587
15639
|
e.preventDefault();
|
|
15588
15640
|
this.#isDragging = handle;
|
|
15589
15641
|
this.#syncActiveBezierArm();
|
|
15642
|
+
const activeHandle = handle === 1 ? this.#handle1 : this.#handle2;
|
|
15643
|
+
this.#toggleHandleTooltip(activeHandle, true);
|
|
15590
15644
|
const svgRect = this.#svg.getBoundingClientRect();
|
|
15591
15645
|
const startClientX = e.clientX;
|
|
15592
15646
|
const startClientY = e.clientY;
|
|
@@ -15637,6 +15691,7 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15637
15691
|
const onUp = () => {
|
|
15638
15692
|
this.#isDragging = null;
|
|
15639
15693
|
this.#syncActiveBezierArm();
|
|
15694
|
+
this.#toggleHandleTooltip(activeHandle, false);
|
|
15640
15695
|
document.removeEventListener("pointermove", onMove);
|
|
15641
15696
|
document.removeEventListener("pointerup", onUp);
|
|
15642
15697
|
this.#emit("change");
|
|
@@ -15650,6 +15705,9 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15650
15705
|
e.preventDefault();
|
|
15651
15706
|
this.#isDragging = handleType;
|
|
15652
15707
|
this.classList.toggle("spring-bounce-dragging", handleType === "bounce");
|
|
15708
|
+
const activeHandle =
|
|
15709
|
+
handleType === "bounce" ? this.#handle1 : this.#handle2;
|
|
15710
|
+
this.#toggleHandleTooltip(activeHandle, true);
|
|
15653
15711
|
|
|
15654
15712
|
const startBounce = this.#springBounce();
|
|
15655
15713
|
const startStiffness = this.#spring.stiffness;
|
|
@@ -15667,7 +15725,7 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15667
15725
|
const dx = e.clientX - startX;
|
|
15668
15726
|
this.#springDuration = Math.max(
|
|
15669
15727
|
0.05,
|
|
15670
|
-
Math.min(
|
|
15728
|
+
Math.min(1, startDuration + dx / 200),
|
|
15671
15729
|
);
|
|
15672
15730
|
this.#spring.stiffness = Math.max(
|
|
15673
15731
|
10,
|
|
@@ -15685,6 +15743,7 @@ class FigEasingCurve extends HTMLElement {
|
|
|
15685
15743
|
const onUp = () => {
|
|
15686
15744
|
this.#isDragging = null;
|
|
15687
15745
|
this.classList.remove("spring-bounce-dragging");
|
|
15746
|
+
this.#toggleHandleTooltip(activeHandle, false);
|
|
15688
15747
|
document.removeEventListener("pointermove", onMove);
|
|
15689
15748
|
document.removeEventListener("pointerup", onUp);
|
|
15690
15749
|
this.#emit("change");
|
package/package.json
CHANGED