@grahlnn/comps 0.1.9 → 0.1.11
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/dist/index.js
CHANGED
|
@@ -3275,6 +3275,19 @@ import { useLayoutEffect, useRef, useState } from "react";
|
|
|
3275
3275
|
var activeMorphMeasurementConsumers = 0;
|
|
3276
3276
|
var detachMorphMeasurementInvalidationListeners = null;
|
|
3277
3277
|
var morphMeasurementInvalidationSubscribers = new Set;
|
|
3278
|
+
var FONT_METRIC_TRANSITION_PROPERTIES = new Set([
|
|
3279
|
+
"font",
|
|
3280
|
+
"font-family",
|
|
3281
|
+
"font-size",
|
|
3282
|
+
"font-stretch",
|
|
3283
|
+
"font-style",
|
|
3284
|
+
"font-weight",
|
|
3285
|
+
"font-variation-settings",
|
|
3286
|
+
"letter-spacing",
|
|
3287
|
+
"line-height",
|
|
3288
|
+
"text-transform",
|
|
3289
|
+
"word-spacing"
|
|
3290
|
+
]);
|
|
3278
3291
|
function parsePx(value) {
|
|
3279
3292
|
const parsed = Number.parseFloat(value);
|
|
3280
3293
|
if (Number.isFinite(parsed)) {
|
|
@@ -3316,6 +3329,18 @@ function readContentWidth(node, styles) {
|
|
|
3316
3329
|
const borderRight = parsePx(styles.borderRightWidth) ?? 0;
|
|
3317
3330
|
return Math.max(0, rectWidth - paddingLeft - paddingRight - borderLeft - borderRight);
|
|
3318
3331
|
}
|
|
3332
|
+
function isFontMetricTransitionProperty(propertyName) {
|
|
3333
|
+
return FONT_METRIC_TRANSITION_PROPERTIES.has(propertyName);
|
|
3334
|
+
}
|
|
3335
|
+
function doesTransitionTargetAffectNode(node, target) {
|
|
3336
|
+
if (target === node) {
|
|
3337
|
+
return true;
|
|
3338
|
+
}
|
|
3339
|
+
if (typeof target !== "object" || target === null || !("contains" in target) || typeof target.contains !== "function") {
|
|
3340
|
+
return false;
|
|
3341
|
+
}
|
|
3342
|
+
return target.contains(node);
|
|
3343
|
+
}
|
|
3319
3344
|
function readLayoutContext(node, width) {
|
|
3320
3345
|
const styles = getComputedStyle(node);
|
|
3321
3346
|
const parentDisplay = (node.parentElement && getComputedStyle(node.parentElement).display) ?? "block";
|
|
@@ -3419,6 +3444,79 @@ function useObservedLayoutContext(deps) {
|
|
|
3419
3444
|
refreshMeasurements: true
|
|
3420
3445
|
});
|
|
3421
3446
|
});
|
|
3447
|
+
const activeFontMetricTransitions = new Map;
|
|
3448
|
+
const ownerDocument = node.ownerDocument;
|
|
3449
|
+
const ownerWindow = ownerDocument.defaultView ?? window;
|
|
3450
|
+
let fontMetricTransitionFrame = null;
|
|
3451
|
+
const stopFontMetricTransitionPolling = () => {
|
|
3452
|
+
if (fontMetricTransitionFrame === null) {
|
|
3453
|
+
return;
|
|
3454
|
+
}
|
|
3455
|
+
ownerWindow.cancelAnimationFrame(fontMetricTransitionFrame);
|
|
3456
|
+
fontMetricTransitionFrame = null;
|
|
3457
|
+
};
|
|
3458
|
+
const pollFontMetricTransition = () => {
|
|
3459
|
+
syncLayoutContext({
|
|
3460
|
+
refreshMeasurements: true
|
|
3461
|
+
});
|
|
3462
|
+
fontMetricTransitionFrame = ownerWindow.requestAnimationFrame(pollFontMetricTransition);
|
|
3463
|
+
};
|
|
3464
|
+
const startFontMetricTransitionPolling = () => {
|
|
3465
|
+
if (fontMetricTransitionFrame !== null) {
|
|
3466
|
+
return;
|
|
3467
|
+
}
|
|
3468
|
+
syncLayoutContext({
|
|
3469
|
+
refreshMeasurements: true
|
|
3470
|
+
});
|
|
3471
|
+
fontMetricTransitionFrame = ownerWindow.requestAnimationFrame(pollFontMetricTransition);
|
|
3472
|
+
};
|
|
3473
|
+
const handleFontMetricTransitionStart = (event) => {
|
|
3474
|
+
if (!isFontMetricTransitionProperty(event.propertyName)) {
|
|
3475
|
+
return;
|
|
3476
|
+
}
|
|
3477
|
+
if (!doesTransitionTargetAffectNode(node, event.target)) {
|
|
3478
|
+
return;
|
|
3479
|
+
}
|
|
3480
|
+
const transitionTarget = event.target;
|
|
3481
|
+
if (transitionTarget === null) {
|
|
3482
|
+
return;
|
|
3483
|
+
}
|
|
3484
|
+
let activeProperties = activeFontMetricTransitions.get(transitionTarget);
|
|
3485
|
+
if (activeProperties === undefined) {
|
|
3486
|
+
activeProperties = new Set;
|
|
3487
|
+
activeFontMetricTransitions.set(transitionTarget, activeProperties);
|
|
3488
|
+
}
|
|
3489
|
+
activeProperties.add(`${event.propertyName}\x00${event.pseudoElement}`);
|
|
3490
|
+
startFontMetricTransitionPolling();
|
|
3491
|
+
};
|
|
3492
|
+
const handleFontMetricTransitionStop = (event) => {
|
|
3493
|
+
if (!isFontMetricTransitionProperty(event.propertyName)) {
|
|
3494
|
+
return;
|
|
3495
|
+
}
|
|
3496
|
+
if (!doesTransitionTargetAffectNode(node, event.target)) {
|
|
3497
|
+
return;
|
|
3498
|
+
}
|
|
3499
|
+
const transitionTarget = event.target;
|
|
3500
|
+
if (transitionTarget === null) {
|
|
3501
|
+
return;
|
|
3502
|
+
}
|
|
3503
|
+
const activeProperties = activeFontMetricTransitions.get(transitionTarget);
|
|
3504
|
+
if (activeProperties === undefined) {
|
|
3505
|
+
return;
|
|
3506
|
+
}
|
|
3507
|
+
activeProperties.delete(`${event.propertyName}\x00${event.pseudoElement}`);
|
|
3508
|
+
if (activeProperties.size > 0) {
|
|
3509
|
+
return;
|
|
3510
|
+
}
|
|
3511
|
+
activeFontMetricTransitions.delete(transitionTarget);
|
|
3512
|
+
if (activeFontMetricTransitions.size > 0) {
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
stopFontMetricTransitionPolling();
|
|
3516
|
+
syncLayoutContext({
|
|
3517
|
+
refreshMeasurements: true
|
|
3518
|
+
});
|
|
3519
|
+
};
|
|
3422
3520
|
let resizeObserver = null;
|
|
3423
3521
|
if (shouldObserveWrappingWidth) {
|
|
3424
3522
|
resizeObserver = new ResizeObserver(([entry]) => {
|
|
@@ -3428,12 +3526,22 @@ function useObservedLayoutContext(deps) {
|
|
|
3428
3526
|
});
|
|
3429
3527
|
}
|
|
3430
3528
|
resizeObserver?.observe(node);
|
|
3529
|
+
ownerDocument.addEventListener("transitionrun", handleFontMetricTransitionStart, true);
|
|
3530
|
+
ownerDocument.addEventListener("transitionstart", handleFontMetricTransitionStart, true);
|
|
3531
|
+
ownerDocument.addEventListener("transitionend", handleFontMetricTransitionStop, true);
|
|
3532
|
+
ownerDocument.addEventListener("transitioncancel", handleFontMetricTransitionStop, true);
|
|
3431
3533
|
acquireMorphMeasurementInvalidationListeners();
|
|
3432
3534
|
return () => {
|
|
3433
3535
|
disposed = true;
|
|
3434
3536
|
syncLayoutContextRef.current = null;
|
|
3435
3537
|
unsubscribeInvalidation();
|
|
3436
3538
|
resizeObserver?.disconnect();
|
|
3539
|
+
stopFontMetricTransitionPolling();
|
|
3540
|
+
activeFontMetricTransitions.clear();
|
|
3541
|
+
ownerDocument.removeEventListener("transitionrun", handleFontMetricTransitionStart, true);
|
|
3542
|
+
ownerDocument.removeEventListener("transitionstart", handleFontMetricTransitionStart, true);
|
|
3543
|
+
ownerDocument.removeEventListener("transitionend", handleFontMetricTransitionStop, true);
|
|
3544
|
+
ownerDocument.removeEventListener("transitioncancel", handleFontMetricTransitionStop, true);
|
|
3437
3545
|
releaseMorphMeasurementInvalidationListeners();
|
|
3438
3546
|
};
|
|
3439
3547
|
}, deps);
|
|
@@ -4151,7 +4259,8 @@ var SCREEN_READER_ONLY_STYLE = {
|
|
|
4151
4259
|
};
|
|
4152
4260
|
var FALLBACK_TEXT_STYLE = {
|
|
4153
4261
|
display: "block",
|
|
4154
|
-
gridArea: "1 / 1"
|
|
4262
|
+
gridArea: "1 / 1",
|
|
4263
|
+
whiteSpace: "nowrap"
|
|
4155
4264
|
};
|
|
4156
4265
|
var SHARED_GLYPH_TYPOGRAPHY_STYLE = {
|
|
4157
4266
|
font: "inherit",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type LayoutContext } from "./types";
|
|
2
2
|
export declare function readFont(styles: CSSStyleDeclaration): string;
|
|
3
|
+
export declare function isFontMetricTransitionProperty(propertyName: string): boolean;
|
|
4
|
+
export declare function doesTransitionTargetAffectNode(node: Node, target: EventTarget | null): any;
|
|
3
5
|
export declare function notifyMorphMeasurementInvalidationSubscribers(): void;
|
|
4
6
|
export declare function subscribeMorphMeasurementInvalidation(subscriber: () => void): () => void;
|
|
5
7
|
export declare function useObservedLayoutContext<T extends HTMLElement>(deps: readonly unknown[]): {
|