@grahlnn/comps 0.1.6 → 0.1.7
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
|
@@ -3077,6 +3077,12 @@ function readRootOrigin(node) {
|
|
|
3077
3077
|
const rect = node.getBoundingClientRect();
|
|
3078
3078
|
return { left: rect.left, top: rect.top };
|
|
3079
3079
|
}
|
|
3080
|
+
function readFlowInlineSize(node) {
|
|
3081
|
+
if (node === null) {
|
|
3082
|
+
return null;
|
|
3083
|
+
}
|
|
3084
|
+
return node.getBoundingClientRect().width;
|
|
3085
|
+
}
|
|
3080
3086
|
function getTrustedPretextMeasurementBackend(text, renderText, layoutContext, useContentInlineSize) {
|
|
3081
3087
|
const backend = getPretextMorphMeasurementBackend(text, layoutContext);
|
|
3082
3088
|
if (backend !== "probe") {
|
|
@@ -3099,6 +3105,12 @@ function getTrustedPretextMeasurementBackend(text, renderText, layoutContext, us
|
|
|
3099
3105
|
}
|
|
3100
3106
|
return "dom";
|
|
3101
3107
|
}
|
|
3108
|
+
function resolveContentWidthLockInlineSize(layoutHint) {
|
|
3109
|
+
if (layoutHint.flowInlineSize !== null) {
|
|
3110
|
+
return layoutHint.flowInlineSize;
|
|
3111
|
+
}
|
|
3112
|
+
return layoutHint.snapshot.width;
|
|
3113
|
+
}
|
|
3102
3114
|
function shouldMeasureUsingContentInlineSize(layoutContext, layoutHint) {
|
|
3103
3115
|
if (supportsIntrinsicWidthLock(layoutContext.display, layoutContext.parentDisplay)) {
|
|
3104
3116
|
return true;
|
|
@@ -3109,7 +3121,7 @@ function shouldMeasureUsingContentInlineSize(layoutContext, layoutHint) {
|
|
|
3109
3121
|
if (layoutHint === null || !isSingleLineSnapshot(layoutHint.snapshot)) {
|
|
3110
3122
|
return false;
|
|
3111
3123
|
}
|
|
3112
|
-
return nearlyEqual(layoutHint.layoutInlineSize, layoutHint
|
|
3124
|
+
return nearlyEqual(layoutHint.layoutInlineSize, resolveContentWidthLockInlineSize(layoutHint), MORPH.contentWidthLockEpsilon);
|
|
3113
3125
|
}
|
|
3114
3126
|
function createMorphMeasurementRequest({
|
|
3115
3127
|
text,
|
|
@@ -3244,6 +3256,7 @@ function measureFromNodes({
|
|
|
3244
3256
|
snapshot,
|
|
3245
3257
|
layoutInlineSize,
|
|
3246
3258
|
reservedInlineSize,
|
|
3259
|
+
flowInlineSize: null,
|
|
3247
3260
|
rootOrigin: readRootOrigin(root)
|
|
3248
3261
|
};
|
|
3249
3262
|
}
|
|
@@ -3255,6 +3268,7 @@ function pinMeasurementToCurrentOrigin(measurement, origin) {
|
|
|
3255
3268
|
snapshot: measurement.snapshot,
|
|
3256
3269
|
layoutInlineSize: measurement.layoutInlineSize,
|
|
3257
3270
|
reservedInlineSize: measurement.reservedInlineSize,
|
|
3271
|
+
flowInlineSize: measurement.flowInlineSize,
|
|
3258
3272
|
rootOrigin: origin
|
|
3259
3273
|
};
|
|
3260
3274
|
}
|
|
@@ -3384,7 +3398,7 @@ function sameMeasurement(a, b) {
|
|
|
3384
3398
|
if (a === b) {
|
|
3385
3399
|
return true;
|
|
3386
3400
|
}
|
|
3387
|
-
return sameSnapshot(a.snapshot, b.snapshot) && nearlyEqual(a.layoutInlineSize, b.layoutInlineSize) && (a.reservedInlineSize === null && b.reservedInlineSize === null || a.reservedInlineSize !== null && b.reservedInlineSize !== null && nearlyEqual(a.reservedInlineSize, b.reservedInlineSize)) && nearlyEqual(a.rootOrigin.left, b.rootOrigin.left) && nearlyEqual(a.rootOrigin.top, b.rootOrigin.top);
|
|
3401
|
+
return sameSnapshot(a.snapshot, b.snapshot) && nearlyEqual(a.layoutInlineSize, b.layoutInlineSize) && (a.reservedInlineSize === null && b.reservedInlineSize === null || a.reservedInlineSize !== null && b.reservedInlineSize !== null && nearlyEqual(a.reservedInlineSize, b.reservedInlineSize)) && (a.flowInlineSize === null && b.flowInlineSize === null || a.flowInlineSize !== null && b.flowInlineSize !== null && nearlyEqual(a.flowInlineSize, b.flowInlineSize)) && nearlyEqual(a.rootOrigin.left, b.rootOrigin.left) && nearlyEqual(a.rootOrigin.top, b.rootOrigin.top);
|
|
3388
3402
|
}
|
|
3389
3403
|
function refreshAnimatingTarget(activeTarget, measurement) {
|
|
3390
3404
|
if (sameMeasurement(activeTarget, measurement)) {
|
|
@@ -3394,6 +3408,7 @@ function refreshAnimatingTarget(activeTarget, measurement) {
|
|
|
3394
3408
|
snapshot: activeTarget.snapshot,
|
|
3395
3409
|
layoutInlineSize: measurement.layoutInlineSize,
|
|
3396
3410
|
reservedInlineSize: measurement.reservedInlineSize,
|
|
3411
|
+
flowInlineSize: activeTarget.flowInlineSize,
|
|
3397
3412
|
rootOrigin: measurement.rootOrigin
|
|
3398
3413
|
};
|
|
3399
3414
|
}
|
|
@@ -3572,6 +3587,7 @@ function reconcileMorphChange({
|
|
|
3572
3587
|
}
|
|
3573
3588
|
function syncCommittedRootOriginWhenIdle({
|
|
3574
3589
|
root,
|
|
3590
|
+
flowTextRef,
|
|
3575
3591
|
layoutContext,
|
|
3576
3592
|
state,
|
|
3577
3593
|
session
|
|
@@ -3583,8 +3599,9 @@ function syncCommittedRootOriginWhenIdle({
|
|
|
3583
3599
|
return;
|
|
3584
3600
|
}
|
|
3585
3601
|
const nextRootOrigin = readRootOrigin(root);
|
|
3602
|
+
const nextFlowInlineSize = readFlowInlineSize(flowTextRef.current);
|
|
3586
3603
|
const committedMeasurement = state.measurement;
|
|
3587
|
-
if (nearlyEqual(committedMeasurement.rootOrigin.left, nextRootOrigin.left) && nearlyEqual(committedMeasurement.rootOrigin.top, nextRootOrigin.top)) {
|
|
3604
|
+
if (nearlyEqual(committedMeasurement.rootOrigin.left, nextRootOrigin.left) && nearlyEqual(committedMeasurement.rootOrigin.top, nextRootOrigin.top) && (committedMeasurement.flowInlineSize === null && nextFlowInlineSize === null || committedMeasurement.flowInlineSize !== null && nextFlowInlineSize !== null && nearlyEqual(committedMeasurement.flowInlineSize, nextFlowInlineSize))) {
|
|
3588
3605
|
session.committed = committedMeasurement;
|
|
3589
3606
|
return;
|
|
3590
3607
|
}
|
|
@@ -3592,6 +3609,7 @@ function syncCommittedRootOriginWhenIdle({
|
|
|
3592
3609
|
snapshot: committedMeasurement.snapshot,
|
|
3593
3610
|
layoutInlineSize: committedMeasurement.layoutInlineSize,
|
|
3594
3611
|
reservedInlineSize: committedMeasurement.reservedInlineSize,
|
|
3612
|
+
flowInlineSize: nextFlowInlineSize,
|
|
3595
3613
|
rootOrigin: nextRootOrigin
|
|
3596
3614
|
};
|
|
3597
3615
|
}
|
|
@@ -3781,6 +3799,7 @@ function MeasurementLayer({
|
|
|
3781
3799
|
}
|
|
3782
3800
|
function useMorphTransition(text, className) {
|
|
3783
3801
|
const { ref, layoutContext } = useObservedLayoutContext([className]);
|
|
3802
|
+
const flowTextRef = useRef(null);
|
|
3784
3803
|
const measurementLayerRef = useRef(null);
|
|
3785
3804
|
const completedDomMeasurementKeyRef = useRef(null);
|
|
3786
3805
|
const domMeasurementSnapshotCacheRef = useRef(new Map);
|
|
@@ -3915,6 +3934,7 @@ function useMorphTransition(text, className) {
|
|
|
3915
3934
|
useLayoutEffect(() => {
|
|
3916
3935
|
syncCommittedRootOriginWhenIdle({
|
|
3917
3936
|
root: ref.current,
|
|
3937
|
+
flowTextRef,
|
|
3918
3938
|
layoutContext,
|
|
3919
3939
|
state,
|
|
3920
3940
|
session: sessionRef.current
|
|
@@ -3928,6 +3948,7 @@ function useMorphTransition(text, className) {
|
|
|
3928
3948
|
return {
|
|
3929
3949
|
committedMeasurement: sessionRef.current.committed,
|
|
3930
3950
|
domMeasurementRequestKey,
|
|
3951
|
+
flowTextRef,
|
|
3931
3952
|
ref,
|
|
3932
3953
|
measurementLayerRef,
|
|
3933
3954
|
renderText,
|
|
@@ -3944,6 +3965,7 @@ function ActiveTorph({
|
|
|
3944
3965
|
const {
|
|
3945
3966
|
committedMeasurement,
|
|
3946
3967
|
domMeasurementRequestKey,
|
|
3968
|
+
flowTextRef,
|
|
3947
3969
|
ref,
|
|
3948
3970
|
measurementLayerRef,
|
|
3949
3971
|
renderText,
|
|
@@ -3985,7 +4007,10 @@ function ActiveTorph({
|
|
|
3985
4007
|
/* @__PURE__ */ jsxDEV("span", {
|
|
3986
4008
|
"aria-hidden": "true",
|
|
3987
4009
|
style: getFallbackTextStyle(shouldRenderOverlay),
|
|
3988
|
-
children:
|
|
4010
|
+
children: /* @__PURE__ */ jsxDEV("span", {
|
|
4011
|
+
ref: flowTextRef,
|
|
4012
|
+
children: flowText
|
|
4013
|
+
}, undefined, false, undefined, this)
|
|
3989
4014
|
}, undefined, false, undefined, this),
|
|
3990
4015
|
measurementLayer,
|
|
3991
4016
|
overlay
|
|
@@ -4005,6 +4030,7 @@ export {
|
|
|
4005
4030
|
supportsIntrinsicWidthLock,
|
|
4006
4031
|
resolveMorphFrameBounds,
|
|
4007
4032
|
resolveFlowText,
|
|
4033
|
+
resolveContentWidthLockInlineSize,
|
|
4008
4034
|
pairMorphCharacters,
|
|
4009
4035
|
needsMeasurementLayer,
|
|
4010
4036
|
measureMorphSnapshotFromLayer,
|
|
@@ -20,6 +20,7 @@ export type MorphMeasurement = {
|
|
|
20
20
|
snapshot: MorphSnapshot;
|
|
21
21
|
layoutInlineSize: number;
|
|
22
22
|
reservedInlineSize: number | null;
|
|
23
|
+
flowInlineSize: number | null;
|
|
23
24
|
rootOrigin: {
|
|
24
25
|
left: number;
|
|
25
26
|
top: number;
|
|
@@ -79,6 +80,7 @@ type GlyphExit = {
|
|
|
79
80
|
type GlyphPairing = GlyphMove | GlyphEnter | GlyphExit;
|
|
80
81
|
export declare function needsMeasurementLayer(measurementBackend: PretextMorphMeasurementBackend, renderText: string): boolean;
|
|
81
82
|
export declare function measureMorphSnapshotFromLayer(text: string, renderText: string, segments: readonly MorphSegment[], layer: HTMLElement | null): MorphSnapshot;
|
|
83
|
+
export declare function resolveContentWidthLockInlineSize(layoutHint: MorphMeasurement): number;
|
|
82
84
|
export declare function pairMorphCharacters(previous: MorphCharacterLayout[], next: MorphCharacterLayout[]): GlyphPairing[];
|
|
83
85
|
export declare function resolveMorphFrameBounds(previous: MorphSnapshot, next: MorphSnapshot): {
|
|
84
86
|
width: number;
|