@grahlnn/comps 0.1.5 → 0.1.6
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 +10 -141
- package/dist/torph/src/components/Torph.d.ts +0 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3692,18 +3692,6 @@ function getMeasurementLayerStyle(layoutContext, useContentInlineSize = false) {
|
|
|
3692
3692
|
function resolveFlowText(committedMeasurement, stateMeasurement, text) {
|
|
3693
3693
|
return committedMeasurement?.snapshot.text ?? stateMeasurement?.snapshot.text ?? text;
|
|
3694
3694
|
}
|
|
3695
|
-
function resolveVisibleFlowText(pendingBootstrapText, committedMeasurement, stateMeasurement, text) {
|
|
3696
|
-
return pendingBootstrapText ?? resolveFlowText(committedMeasurement, stateMeasurement, text);
|
|
3697
|
-
}
|
|
3698
|
-
function resolveActivationBootstrapText(isActivated, previousText, nextText) {
|
|
3699
|
-
if (!isActivated && nextText !== previousText) {
|
|
3700
|
-
return previousText;
|
|
3701
|
-
}
|
|
3702
|
-
return null;
|
|
3703
|
-
}
|
|
3704
|
-
function shouldDeferTargetMeasurement(committedMeasurement, pendingBootstrapText, text) {
|
|
3705
|
-
return committedMeasurement === null && pendingBootstrapText !== null && pendingBootstrapText !== text;
|
|
3706
|
-
}
|
|
3707
3695
|
function getOverlayStyle(plan) {
|
|
3708
3696
|
return {
|
|
3709
3697
|
...OVERLAY_STYLE,
|
|
@@ -3791,55 +3779,29 @@ function MeasurementLayer({
|
|
|
3791
3779
|
}, segment.key, false, undefined, this))
|
|
3792
3780
|
}, undefined, false, undefined, this);
|
|
3793
3781
|
}
|
|
3794
|
-
function useMorphTransition(text, className
|
|
3782
|
+
function useMorphTransition(text, className) {
|
|
3795
3783
|
const { ref, layoutContext } = useObservedLayoutContext([className]);
|
|
3796
3784
|
const measurementLayerRef = useRef(null);
|
|
3797
|
-
const bootstrapMeasurementLayerRef = useRef(null);
|
|
3798
3785
|
const completedDomMeasurementKeyRef = useRef(null);
|
|
3799
3786
|
const domMeasurementSnapshotCacheRef = useRef(new Map);
|
|
3800
|
-
const pendingBootstrapTextRef = useRef(bootstrapText);
|
|
3801
3787
|
const sessionRef = useRef({ ...EMPTY_SESSION });
|
|
3802
3788
|
const timelineRef = useRef({ ...EMPTY_TIMELINE });
|
|
3803
3789
|
const [domMeasurementRequestKey, setDomMeasurementRequestKey] = useState(null);
|
|
3804
3790
|
const [state, setState] = useState(EMPTY_STATE);
|
|
3805
|
-
if (pendingBootstrapTextRef.current === null && bootstrapText !== null && bootstrapText !== text && sessionRef.current.committed === null) {
|
|
3806
|
-
pendingBootstrapTextRef.current = bootstrapText;
|
|
3807
|
-
}
|
|
3808
3791
|
let measurementHint = sessionRef.current.committed;
|
|
3809
3792
|
if (sessionRef.current.animating) {
|
|
3810
3793
|
measurementHint = sessionRef.current.target ?? sessionRef.current.committed;
|
|
3811
3794
|
}
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
const measurementRequest = useMemo(() => {
|
|
3818
|
-
if (isBootstrapping) {
|
|
3819
|
-
return null;
|
|
3820
|
-
}
|
|
3821
|
-
return createMorphMeasurementRequest({
|
|
3822
|
-
text,
|
|
3823
|
-
layoutContext,
|
|
3824
|
-
layoutHint: measurementHint
|
|
3825
|
-
});
|
|
3826
|
-
}, [text, layoutContext, measurementHint, isBootstrapping]);
|
|
3827
|
-
const bootstrapMeasurementRequest = useMemo(() => {
|
|
3828
|
-
if (!isBootstrapping || pendingBootstrapText === null) {
|
|
3829
|
-
return null;
|
|
3830
|
-
}
|
|
3831
|
-
return createMorphMeasurementRequest({
|
|
3832
|
-
text: pendingBootstrapText,
|
|
3833
|
-
layoutContext,
|
|
3834
|
-
layoutHint: null
|
|
3835
|
-
});
|
|
3836
|
-
}, [pendingBootstrapText, layoutContext, isBootstrapping]);
|
|
3795
|
+
const measurementRequest = useMemo(() => createMorphMeasurementRequest({
|
|
3796
|
+
text,
|
|
3797
|
+
layoutContext,
|
|
3798
|
+
layoutHint: measurementHint
|
|
3799
|
+
}), [text, layoutContext, measurementHint]);
|
|
3837
3800
|
const renderText = measurementRequest?.renderText ?? text;
|
|
3838
3801
|
const useContentInlineSize = measurementRequest?.useContentInlineSize ?? false;
|
|
3839
3802
|
const measurementBackend = measurementRequest?.measurementBackend ?? null;
|
|
3840
3803
|
const segments = measurementRequest?.segments ?? EMPTY_SEGMENTS;
|
|
3841
3804
|
const domMeasurementKey = measurementRequest?.domMeasurementKey ?? null;
|
|
3842
|
-
const shouldRenderBootstrapSourceMeasurementLayer = bootstrapMeasurementRequest?.domMeasurementKey !== null;
|
|
3843
3805
|
useLayoutEffect(() => {
|
|
3844
3806
|
if (ref.current === null || layoutContext === null) {
|
|
3845
3807
|
completedDomMeasurementKeyRef.current = null;
|
|
@@ -3861,36 +3823,6 @@ function useMorphTransition(text, className, bootstrapText = null) {
|
|
|
3861
3823
|
});
|
|
3862
3824
|
return;
|
|
3863
3825
|
}
|
|
3864
|
-
if (isBootstrapping && bootstrapMeasurementRequest !== null) {
|
|
3865
|
-
let bootstrapDomSnapshot = null;
|
|
3866
|
-
if (bootstrapMeasurementRequest.domMeasurementKey !== null && canCacheMeasurementLayerSnapshot(bootstrapMeasurementRequest.measurementBackend)) {
|
|
3867
|
-
bootstrapDomSnapshot = readCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, bootstrapMeasurementRequest.domMeasurementKey);
|
|
3868
|
-
}
|
|
3869
|
-
if (bootstrapMeasurementRequest.domMeasurementKey !== null && bootstrapDomSnapshot === null && bootstrapMeasurementLayerRef.current === null) {
|
|
3870
|
-
return;
|
|
3871
|
-
}
|
|
3872
|
-
const bootstrapMeasurement = measureFromNodes({
|
|
3873
|
-
root: ref.current,
|
|
3874
|
-
layoutContext,
|
|
3875
|
-
layoutHint: null,
|
|
3876
|
-
layer: bootstrapMeasurementLayerRef.current,
|
|
3877
|
-
measurementBackend: bootstrapMeasurementRequest.measurementBackend,
|
|
3878
|
-
snapshotOverride: bootstrapDomSnapshot,
|
|
3879
|
-
text: bootstrapMeasurementRequest.text,
|
|
3880
|
-
renderText: bootstrapMeasurementRequest.renderText,
|
|
3881
|
-
segments: bootstrapMeasurementRequest.segments
|
|
3882
|
-
});
|
|
3883
|
-
if (bootstrapMeasurementRequest.domMeasurementKey !== null && bootstrapDomSnapshot === null && canCacheMeasurementLayerSnapshot(bootstrapMeasurementRequest.measurementBackend)) {
|
|
3884
|
-
rememberCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, bootstrapMeasurementRequest.domMeasurementKey, bootstrapMeasurement.snapshot);
|
|
3885
|
-
}
|
|
3886
|
-
completedDomMeasurementKeyRef.current = null;
|
|
3887
|
-
pendingBootstrapTextRef.current = null;
|
|
3888
|
-
if (domMeasurementRequestKey !== null) {
|
|
3889
|
-
setDomMeasurementRequestKey(null);
|
|
3890
|
-
}
|
|
3891
|
-
commitStaticMeasurement(sessionRef.current, bootstrapMeasurement, setState);
|
|
3892
|
-
return;
|
|
3893
|
-
}
|
|
3894
3826
|
if (domMeasurementKey !== null) {
|
|
3895
3827
|
let cachedSnapshot = null;
|
|
3896
3828
|
if (canCacheMeasurementLayerSnapshot(measurementBackend)) {
|
|
@@ -3977,9 +3909,6 @@ function useMorphTransition(text, className, bootstrapText = null) {
|
|
|
3977
3909
|
layoutContext,
|
|
3978
3910
|
measurementBackend,
|
|
3979
3911
|
measurementRequest,
|
|
3980
|
-
isBootstrapping,
|
|
3981
|
-
pendingBootstrapText,
|
|
3982
|
-
bootstrapMeasurementRequest,
|
|
3983
3912
|
domMeasurementKey,
|
|
3984
3913
|
domMeasurementRequestKey
|
|
3985
3914
|
]);
|
|
@@ -4000,70 +3929,33 @@ function useMorphTransition(text, className, bootstrapText = null) {
|
|
|
4000
3929
|
committedMeasurement: sessionRef.current.committed,
|
|
4001
3930
|
domMeasurementRequestKey,
|
|
4002
3931
|
ref,
|
|
4003
|
-
bootstrapMeasurementLayerRef,
|
|
4004
|
-
measurementBackend,
|
|
4005
3932
|
measurementLayerRef,
|
|
4006
3933
|
renderText,
|
|
4007
3934
|
segments,
|
|
4008
3935
|
layoutContext,
|
|
4009
3936
|
state,
|
|
4010
|
-
pendingBootstrapText,
|
|
4011
|
-
shouldRenderBootstrapSourceMeasurementLayer,
|
|
4012
|
-
bootstrapMeasurementRequest,
|
|
4013
3937
|
useContentInlineSize
|
|
4014
3938
|
};
|
|
4015
3939
|
}
|
|
4016
|
-
function StaticTorph({ text, className }) {
|
|
4017
|
-
return /* @__PURE__ */ jsxDEV("div", {
|
|
4018
|
-
className,
|
|
4019
|
-
children: [
|
|
4020
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
4021
|
-
style: SCREEN_READER_ONLY_STYLE,
|
|
4022
|
-
children: text
|
|
4023
|
-
}, undefined, false, undefined, this),
|
|
4024
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
4025
|
-
"aria-hidden": "true",
|
|
4026
|
-
style: FALLBACK_TEXT_STYLE,
|
|
4027
|
-
children: text
|
|
4028
|
-
}, undefined, false, undefined, this)
|
|
4029
|
-
]
|
|
4030
|
-
}, undefined, true, undefined, this);
|
|
4031
|
-
}
|
|
4032
3940
|
function ActiveTorph({
|
|
4033
3941
|
text,
|
|
4034
|
-
className
|
|
4035
|
-
bootstrapText
|
|
3942
|
+
className
|
|
4036
3943
|
}) {
|
|
4037
3944
|
const {
|
|
4038
3945
|
committedMeasurement,
|
|
4039
3946
|
domMeasurementRequestKey,
|
|
4040
3947
|
ref,
|
|
4041
|
-
bootstrapMeasurementLayerRef,
|
|
4042
|
-
measurementBackend,
|
|
4043
3948
|
measurementLayerRef,
|
|
4044
3949
|
renderText,
|
|
4045
3950
|
segments,
|
|
4046
3951
|
layoutContext,
|
|
4047
3952
|
state,
|
|
4048
|
-
pendingBootstrapText,
|
|
4049
|
-
shouldRenderBootstrapSourceMeasurementLayer,
|
|
4050
|
-
bootstrapMeasurementRequest,
|
|
4051
3953
|
useContentInlineSize
|
|
4052
|
-
} = useMorphTransition(text, className
|
|
3954
|
+
} = useMorphTransition(text, className);
|
|
4053
3955
|
const plan = state.plan;
|
|
4054
3956
|
const shouldRenderOverlay = state.stage !== "idle" && plan !== null;
|
|
4055
3957
|
const shouldRenderMeasurementLayer = domMeasurementRequestKey !== null;
|
|
4056
|
-
const flowText =
|
|
4057
|
-
let bootstrapMeasurementLayer = null;
|
|
4058
|
-
if (shouldRenderBootstrapSourceMeasurementLayer && bootstrapMeasurementRequest !== null) {
|
|
4059
|
-
bootstrapMeasurementLayer = /* @__PURE__ */ jsxDEV(MeasurementLayer, {
|
|
4060
|
-
layerRef: bootstrapMeasurementLayerRef,
|
|
4061
|
-
layoutContext,
|
|
4062
|
-
text: bootstrapMeasurementRequest.renderText,
|
|
4063
|
-
segments: bootstrapMeasurementRequest.segments,
|
|
4064
|
-
useContentInlineSize: bootstrapMeasurementRequest.useContentInlineSize
|
|
4065
|
-
}, undefined, false, undefined, this);
|
|
4066
|
-
}
|
|
3958
|
+
const flowText = resolveFlowText(committedMeasurement, state.measurement, text);
|
|
4067
3959
|
let measurementLayer = null;
|
|
4068
3960
|
if (shouldRenderMeasurementLayer) {
|
|
4069
3961
|
measurementLayer = /* @__PURE__ */ jsxDEV(MeasurementLayer, {
|
|
@@ -4095,7 +3987,6 @@ function ActiveTorph({
|
|
|
4095
3987
|
style: getFallbackTextStyle(shouldRenderOverlay),
|
|
4096
3988
|
children: flowText
|
|
4097
3989
|
}, undefined, false, undefined, this),
|
|
4098
|
-
bootstrapMeasurementLayer,
|
|
4099
3990
|
measurementLayer,
|
|
4100
3991
|
overlay
|
|
4101
3992
|
]
|
|
@@ -4105,37 +3996,15 @@ function Torph({
|
|
|
4105
3996
|
text,
|
|
4106
3997
|
className
|
|
4107
3998
|
}) {
|
|
4108
|
-
|
|
4109
|
-
const previousTextRef = useRef(text);
|
|
4110
|
-
const bootstrapText = resolveActivationBootstrapText(isActivated, previousTextRef.current, text);
|
|
4111
|
-
const shouldActivate = isActivated || bootstrapText !== null;
|
|
4112
|
-
useLayoutEffect(() => {
|
|
4113
|
-
if (!isActivated && text !== previousTextRef.current) {
|
|
4114
|
-
previousTextRef.current = text;
|
|
4115
|
-
setIsActivated(true);
|
|
4116
|
-
return;
|
|
4117
|
-
}
|
|
4118
|
-
previousTextRef.current = text;
|
|
4119
|
-
}, [isActivated, text]);
|
|
4120
|
-
if (shouldActivate) {
|
|
4121
|
-
return /* @__PURE__ */ jsxDEV(ActiveTorph, {
|
|
4122
|
-
text,
|
|
4123
|
-
className,
|
|
4124
|
-
bootstrapText
|
|
4125
|
-
}, undefined, false, undefined, this);
|
|
4126
|
-
}
|
|
4127
|
-
return /* @__PURE__ */ jsxDEV(StaticTorph, {
|
|
3999
|
+
return /* @__PURE__ */ jsxDEV(ActiveTorph, {
|
|
4128
4000
|
text,
|
|
4129
4001
|
className
|
|
4130
4002
|
}, undefined, false, undefined, this);
|
|
4131
4003
|
}
|
|
4132
4004
|
export {
|
|
4133
4005
|
supportsIntrinsicWidthLock,
|
|
4134
|
-
shouldDeferTargetMeasurement,
|
|
4135
|
-
resolveVisibleFlowText,
|
|
4136
4006
|
resolveMorphFrameBounds,
|
|
4137
4007
|
resolveFlowText,
|
|
4138
|
-
resolveActivationBootstrapText,
|
|
4139
4008
|
pairMorphCharacters,
|
|
4140
4009
|
needsMeasurementLayer,
|
|
4141
4010
|
measureMorphSnapshotFromLayer,
|
|
@@ -95,9 +95,6 @@ export declare function getRootDisplay(layoutContext: LayoutContext | null): "gr
|
|
|
95
95
|
export declare function getRootStyle(stage: MorphStage, plan: MorphRenderPlan | null, measurement: MorphMeasurement | null, layoutContext: LayoutContext | null): CSSProperties;
|
|
96
96
|
export declare function getMeasurementLayerStyle(layoutContext: LayoutContext | null, useContentInlineSize?: boolean): CSSProperties;
|
|
97
97
|
export declare function resolveFlowText(committedMeasurement: MorphMeasurement | null, stateMeasurement: MorphMeasurement | null, text: string): string;
|
|
98
|
-
export declare function resolveVisibleFlowText(pendingBootstrapText: string | null, committedMeasurement: MorphMeasurement | null, stateMeasurement: MorphMeasurement | null, text: string): string;
|
|
99
|
-
export declare function resolveActivationBootstrapText(isActivated: boolean, previousText: string, nextText: string): string | null;
|
|
100
|
-
export declare function shouldDeferTargetMeasurement(committedMeasurement: MorphMeasurement | null, pendingBootstrapText: string | null, text: string): boolean;
|
|
101
98
|
export declare function Torph({ text, className, }: {
|
|
102
99
|
text: string;
|
|
103
100
|
className?: string;
|