@grahlnn/comps 0.1.3 → 0.1.4

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
@@ -2931,6 +2931,15 @@ function getDomMeasurementRequestKey(text, renderText, layoutContext, useContent
2931
2931
  }
2932
2932
  return `dom\x00${inlineSizeMode}\x00${text}\x00${renderText}\x00${layoutContext.measurementVersion}\x00${getMorphMeasurementEpoch()}`;
2933
2933
  }
2934
+ function needsMeasurementLayer(measurementBackend, renderText) {
2935
+ if (measurementBackend === "pretext") {
2936
+ return false;
2937
+ }
2938
+ return renderText.length > 0;
2939
+ }
2940
+ function canCacheMeasurementLayerSnapshot(measurementBackend) {
2941
+ return measurementBackend === "dom";
2942
+ }
2934
2943
  function readCachedMorphSnapshot(cache, cacheKey) {
2935
2944
  const cached = cache.get(cacheKey);
2936
2945
  if (cached === undefined) {
@@ -3118,7 +3127,7 @@ function createMorphMeasurementRequest({
3118
3127
  segments = EMPTY_SEGMENTS;
3119
3128
  }
3120
3129
  let domMeasurementKey = null;
3121
- if (measurementBackend === "dom" && renderText.length > 0) {
3130
+ if (needsMeasurementLayer(measurementBackend, renderText)) {
3122
3131
  domMeasurementKey = getDomMeasurementRequestKey(text, renderText, layoutContext, useContentInlineSize);
3123
3132
  }
3124
3133
  return {
@@ -3190,17 +3199,19 @@ function measureFromNodes({
3190
3199
  pretextSnapshot = measureMorphSnapshotWithPretext(text, measurementLayoutContext);
3191
3200
  }
3192
3201
  let domSnapshot = null;
3193
- if (measurementBackend === "dom") {
3194
- domSnapshot = measureMorphSnapshotFromLayer(text, renderText, segments, layer);
3195
- } else if (measurementBackend !== "pretext") {
3196
- domSnapshot = measureMorphSnapshotWithDomService({
3197
- root,
3198
- layoutContext,
3199
- text,
3200
- renderText,
3201
- segments,
3202
- useContentInlineSize
3203
- });
3202
+ if (measurementBackend !== "pretext") {
3203
+ if (layer !== null) {
3204
+ domSnapshot = measureMorphSnapshotFromLayer(text, renderText, segments, layer);
3205
+ } else {
3206
+ domSnapshot = measureMorphSnapshotWithDomService({
3207
+ root,
3208
+ layoutContext,
3209
+ text,
3210
+ renderText,
3211
+ segments,
3212
+ useContentInlineSize
3213
+ });
3214
+ }
3204
3215
  }
3205
3216
  if (measurementBackend === "probe" && pretextSnapshot !== null && domSnapshot !== null) {
3206
3217
  const trusted = areSnapshotsEquivalentForPretextTrust(pretextSnapshot, domSnapshot);
@@ -3819,7 +3830,7 @@ function useMorphTransition(text, className, bootstrapText = null) {
3819
3830
  const measurementBackend = measurementRequest?.measurementBackend ?? null;
3820
3831
  const segments = measurementRequest?.segments ?? EMPTY_SEGMENTS;
3821
3832
  const domMeasurementKey = measurementRequest?.domMeasurementKey ?? null;
3822
- const shouldRenderBootstrapSourceMeasurementLayer = bootstrapMeasurementRequest?.measurementBackend === "dom" && bootstrapMeasurementRequest.renderText.length > 0;
3833
+ const shouldRenderBootstrapSourceMeasurementLayer = bootstrapMeasurementRequest?.domMeasurementKey !== null;
3823
3834
  useLayoutEffect(() => {
3824
3835
  if (ref.current === null || layoutContext === null) {
3825
3836
  completedDomMeasurementKeyRef.current = null;
@@ -3843,7 +3854,7 @@ function useMorphTransition(text, className, bootstrapText = null) {
3843
3854
  }
3844
3855
  if (pendingBootstrapText !== null && pendingBootstrapText !== text && bootstrapMeasurementRequest !== null && measurementRequest !== null) {
3845
3856
  let bootstrapDomSnapshot = null;
3846
- if (bootstrapMeasurementRequest.domMeasurementKey !== null) {
3857
+ if (bootstrapMeasurementRequest.domMeasurementKey !== null && canCacheMeasurementLayerSnapshot(bootstrapMeasurementRequest.measurementBackend)) {
3847
3858
  bootstrapDomSnapshot = readCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, bootstrapMeasurementRequest.domMeasurementKey);
3848
3859
  }
3849
3860
  if (bootstrapMeasurementRequest.domMeasurementKey !== null && bootstrapDomSnapshot === null && bootstrapMeasurementLayerRef.current === null) {
@@ -3860,7 +3871,7 @@ function useMorphTransition(text, className, bootstrapText = null) {
3860
3871
  renderText: bootstrapMeasurementRequest.renderText,
3861
3872
  segments: bootstrapMeasurementRequest.segments
3862
3873
  });
3863
- if (bootstrapMeasurementRequest.domMeasurementKey !== null && bootstrapDomSnapshot === null) {
3874
+ if (bootstrapMeasurementRequest.domMeasurementKey !== null && bootstrapDomSnapshot === null && canCacheMeasurementLayerSnapshot(bootstrapMeasurementRequest.measurementBackend)) {
3864
3875
  rememberCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, bootstrapMeasurementRequest.domMeasurementKey, bootstrapMeasurement.snapshot);
3865
3876
  }
3866
3877
  completedDomMeasurementKeyRef.current = null;
@@ -3872,7 +3883,10 @@ function useMorphTransition(text, className, bootstrapText = null) {
3872
3883
  return;
3873
3884
  }
3874
3885
  if (domMeasurementKey !== null) {
3875
- const cachedSnapshot = readCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, domMeasurementKey);
3886
+ let cachedSnapshot = null;
3887
+ if (canCacheMeasurementLayerSnapshot(measurementBackend)) {
3888
+ cachedSnapshot = readCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, domMeasurementKey);
3889
+ }
3876
3890
  if (cachedSnapshot !== null) {
3877
3891
  completedDomMeasurementKeyRef.current = domMeasurementKey;
3878
3892
  if (domMeasurementRequestKey !== null) {
@@ -3915,7 +3929,9 @@ function useMorphTransition(text, className, bootstrapText = null) {
3915
3929
  setState
3916
3930
  });
3917
3931
  if (nextMeasurement !== null) {
3918
- rememberCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, domMeasurementKey, nextMeasurement.snapshot);
3932
+ if (canCacheMeasurementLayerSnapshot(measurementBackend)) {
3933
+ rememberCachedMorphSnapshot(domMeasurementSnapshotCacheRef.current, domMeasurementKey, nextMeasurement.snapshot);
3934
+ }
3919
3935
  }
3920
3936
  completedDomMeasurementKeyRef.current = domMeasurementKey;
3921
3937
  if (domMeasurementRequestKey !== null) {
@@ -4026,7 +4042,7 @@ function ActiveTorph({
4026
4042
  } = useMorphTransition(text, className, bootstrapText);
4027
4043
  const plan = state.plan;
4028
4044
  const shouldRenderOverlay = state.stage !== "idle" && plan !== null;
4029
- const shouldRenderMeasurementLayer = measurementBackend === "dom" && domMeasurementRequestKey !== null;
4045
+ const shouldRenderMeasurementLayer = domMeasurementRequestKey !== null;
4030
4046
  const flowText = resolveVisibleFlowText(pendingBootstrapText, committedMeasurement, state.measurement, text);
4031
4047
  let bootstrapMeasurementLayer = null;
4032
4048
  if (shouldRenderBootstrapSourceMeasurementLayer && bootstrapMeasurementRequest !== null) {
@@ -4110,6 +4126,7 @@ export {
4110
4126
  resolveFlowText,
4111
4127
  resolveActivationBootstrapText,
4112
4128
  pairMorphCharacters,
4129
+ needsMeasurementLayer,
4113
4130
  measureMorphSnapshotFromLayer,
4114
4131
  getRootStyle,
4115
4132
  getRootDisplay,
@@ -1,4 +1,5 @@
1
1
  import { type CSSProperties } from "react";
2
+ import { type PretextMorphMeasurementBackend } from "../utils/text-layout/pretextMorph";
2
3
  export type SupportedWhiteSpace = "normal" | "nowrap" | "pre-wrap";
3
4
  export type MorphCharacterLayout = {
4
5
  glyph: string;
@@ -76,6 +77,7 @@ type GlyphExit = {
76
77
  from: MorphCharacterLayout;
77
78
  };
78
79
  type GlyphPairing = GlyphMove | GlyphEnter | GlyphExit;
80
+ export declare function needsMeasurementLayer(measurementBackend: PretextMorphMeasurementBackend, renderText: string): boolean;
79
81
  export declare function measureMorphSnapshotFromLayer(text: string, renderText: string, segments: readonly MorphSegment[], layer: HTMLElement | null): MorphSnapshot;
80
82
  export declare function pairMorphCharacters(previous: MorphCharacterLayout[], next: MorphCharacterLayout[]): GlyphPairing[];
81
83
  export declare function resolveMorphFrameBounds(previous: MorphSnapshot, next: MorphSnapshot): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grahlnn/comps",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "React components from grahlnn/comps.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",