@widgetic/canvas 0.5.37 → 0.5.38

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.
@@ -198,7 +198,7 @@
198
198
  : []
199
199
  );
200
200
 
201
- // The size is shown at rest in the frame centre (same place as while resizing); while resizing or turning the readout in the middle says it instead.
201
+ // The size sits under the frame, at rest and while the frame is stretched, so it does not cover the widget.
202
202
  const sizeLabel = $derived.by(() => {
203
203
  if (!frame || gestureKind !== null) return null;
204
204
  const text = formatReadout({ kind: 'size', width: Math.round(frame.world.width), height: Math.round(frame.world.height) });
@@ -207,6 +207,14 @@
207
207
  return { x: at.x, y: at.y, text };
208
208
  });
209
209
 
210
+ const readoutPoint = $derived.by(() => {
211
+ if (!frame || !state.overlay.readout) return null;
212
+ if (state.overlay.readout.kind === 'size') {
213
+ return restingSizeLabelPoint(frame.screen, formatReadout(state.overlay.readout));
214
+ }
215
+ return { x: frame.screen.centerX, y: frame.screen.centerY };
216
+ });
217
+
210
218
  /** Where one handle sits on the frame, as the percentages of its width and height. */
211
219
  function handleStyle(handle: ResizeHandle): string {
212
220
  const direction = handleDirection(handle);
@@ -398,11 +406,11 @@
398
406
  </span>
399
407
  {/if}
400
408
 
401
- {#if frame && readoutText}
402
- <!-- The figure of the stretch or the turn, in the middle of the selection where the hand is not. -->
409
+ {#if readoutPoint && readoutText}
410
+ <!-- The size of a stretch sits under the frame. The angle of a turn stays in the middle. -->
403
411
  <span
404
412
  class="absolute -translate-x-1/2 -translate-y-1/2 whitespace-nowrap rounded-sm bg-inverse px-1.5 py-0.5 text-xs font-medium tabular-nums text-inverse-foreground"
405
- style={layerPointStyle({ x: frame.screen.centerX, y: frame.screen.centerY })}
413
+ style={layerPointStyle(readoutPoint)}
406
414
  dir="ltr"
407
415
  data-canvas-readout
408
416
  >
@@ -93,10 +93,10 @@ export declare function screenFrameStyle(frame: ScreenFrame): string;
93
93
  */
94
94
  export declare function formatReadout(readout: Readout): string;
95
95
  /**
96
- * Where the size label sits at rest: centred like the resize readout, or null when the frame is too small.
97
- * The label never sits outside the selection frame (rotation dot lives below).
96
+ * Where the size label sits at rest: centred under the bottom edge, clear of the frame
97
+ * and of the rotation dot (21px under that edge). A label in the middle covers the widget.
98
98
  */
99
- export declare function restingSizeLabelPoint(frame: ScreenFrame, text: string, margin?: number): Point | null;
99
+ export declare function restingSizeLabelPoint(frame: ScreenFrame, _text: string): Point | null;
100
100
  /** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the size label goes. */
101
101
  export declare function pointBelowFrame(frame: ScreenFrame, distance: number): Point;
102
102
  /**
@@ -119,19 +119,15 @@ export function screenFrameStyle(frame) {
119
119
  export function formatReadout(readout) {
120
120
  return readout.kind === 'size' ? `${readout.width} × ${readout.height}` : `${readout.degrees}°`;
121
121
  }
122
- /** Rough size of the centred size label (px-1.5 py-0.5 text-xs), used to keep it inside the frame. */
123
- const SIZE_LABEL_CHAR_PX = 7.5;
124
- const SIZE_LABEL_PAD_X = 12;
122
+ /** Height of the size label (text-xs + vertical padding), so it clears the rotation dot. */
125
123
  const SIZE_LABEL_HEIGHT = 22;
126
124
  /**
127
- * Where the size label sits at rest: centred like the resize readout, or null when the frame is too small.
128
- * The label never sits outside the selection frame (rotation dot lives below).
125
+ * Where the size label sits at rest: centred under the bottom edge, clear of the frame
126
+ * and of the rotation dot (21px under that edge). A label in the middle covers the widget.
129
127
  */
130
- export function restingSizeLabelPoint(frame, text, margin = 4) {
131
- const width = text.length * SIZE_LABEL_CHAR_PX + SIZE_LABEL_PAD_X;
132
- if (frame.width < width + margin * 2 || frame.height < SIZE_LABEL_HEIGHT + margin * 2)
133
- return null;
134
- return { x: frame.centerX, y: frame.centerY };
128
+ export function restingSizeLabelPoint(frame, _text) {
129
+ const belowRotationDot = 21 + 8 + SIZE_LABEL_HEIGHT / 2;
130
+ return pointBelowFrame(frame, belowRotationDot);
135
131
  }
136
132
  /** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the size label goes. */
137
133
  export function pointBelowFrame(frame, distance) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/canvas",
3
- "version": "0.5.37",
3
+ "version": "0.5.38",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",