narraleaf-react 0.33.1 → 0.34.0

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.
@@ -36,6 +36,22 @@ export type TextAppearanceProps = {
36
36
  * @default true
37
37
  */
38
38
  tateChuYoko?: TateChuYoko;
39
+ /**
40
+ * Set the line down until the whole of it fits the box it is placed in.
41
+ *
42
+ * `fontSize` becomes a ceiling rather than a fixed size: the line is set at it whenever the
43
+ * finished line fits, and smaller when it does not, down to {@link autoFitMinFontSize}. Sizes
44
+ * carried by the sentence or by a single word scale with it, so their relative weights hold.
45
+ *
46
+ * The box is the container's parent, which needs a size of its own for anything to be fitted to.
47
+ * @default false
48
+ */
49
+ autoFit?: boolean;
50
+ /**
51
+ * The smallest size auto fit sets, in px. A line that still overflows at it is left overflowing.
52
+ * @default 12
53
+ */
54
+ autoFitMinFontSize?: number;
39
55
  };
40
56
  export type BaseTextsProps = TextAppearanceProps & {
41
57
  className?: string;
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ /** Smallest size auto fit sets when the line does not say otherwise. */
3
+ export declare const DEFAULT_AUTO_FIT_MIN_FONT_SIZE = 12;
4
+ /** Set on the measuring copy so every explicit word size scales with one write. */
5
+ export declare const AUTO_FIT_SCALE_VAR = "--nl-auto-fit-scale";
6
+ /**
7
+ * The same length, scaled, whatever unit it was written in.
8
+ *
9
+ * The multiplier is a number for the line on screen and the scale custom property for the copy
10
+ * being measured, where one write has to resize every word at once.
11
+ */
12
+ export declare function scaledFontSize(value: React.CSSProperties["fontSize"], scale: number | string): React.CSSProperties["fontSize"];
13
+ /** The multiplier the measuring copy scales by, readable from every word inside it. */
14
+ export declare const AUTO_FIT_SCALE_MULTIPLIER = "var(--nl-auto-fit-scale, 1)";
15
+ /** What the line is set at when it inherits its size: a share of the size it inherits. */
16
+ export declare function inheritedScaledFontSize(scale: number): React.CSSProperties["fontSize"] | undefined;
17
+ export type AutoFitOptions = {
18
+ enabled: boolean;
19
+ /** The floor, in px. A line that overflows at this size is left overflowing rather than set smaller. */
20
+ minFontSize: number;
21
+ /** Vertical writing swaps the axes: the columns advance across the box, not down it. */
22
+ vertical: boolean;
23
+ /** Everything that changes the laid-out result without changing the box. */
24
+ signature: string;
25
+ };
26
+ export type AutoFitState = {
27
+ containerRef: React.MutableRefObject<HTMLDivElement | null>;
28
+ mirrorRef: React.MutableRefObject<HTMLDivElement | null>;
29
+ /** The share of the authored size the line is set at. */
30
+ scale: number;
31
+ };
32
+ /**
33
+ * Finds the largest size at which a whole line still fits the box it is placed in.
34
+ *
35
+ * The line being typed is not what has to fit - the finished line is - so the search runs against a
36
+ * hidden copy holding every word, laid out under the same box, the same typeface and the same
37
+ * wrapping rules. The copy is what the bisection resizes; the visible line is set once, when the
38
+ * answer is known, and stays there for the rest of the line.
39
+ *
40
+ * The box is the container's parent: a dialog box has a size of its own, and the line is what has
41
+ * to live inside it. A parent with no height of its own leaves the scale at 1.
42
+ */
43
+ export declare function useAutoFitScale({ enabled, minFontSize, vertical, signature }: AutoFitOptions): AutoFitState;