@spark-web/text 2.0.0-rc.0 → 2.0.0-rc.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @spark-web/text
2
2
 
3
+ ## 2.0.0-rc.2
4
+
5
+ ### Major Changes
6
+
7
+ - add parser
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies []:
12
+ - @spark-web/theme@4.0.0-rc.2
13
+ - @spark-web/utils@2.0.0-rc.2
14
+ - @spark-web/box@2.0.0-rc.2
15
+
16
+ ## 2.0.0-rc.1
17
+
18
+ ### Major Changes
19
+
20
+ - rc
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies []:
25
+ - @spark-web/theme@4.0.0-rc.1
26
+ - @spark-web/utils@2.0.0-rc.1
27
+ - @spark-web/box@2.0.0-rc.1
28
+
3
29
  ## 2.0.0-rc.0
4
30
 
5
31
  ### Major Changes
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ export declare const TextContext: import("react").Context<{
3
+ size: "small" | "xsmall" | "standard" | "large";
4
+ tone: "disabled" | "link" | "muted" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "placeholder" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
5
+ weight: "regular" | "semibold";
6
+ } | undefined>;
7
+ export declare function useTextContext(): {
8
+ size: "small" | "xsmall" | "standard" | "large";
9
+ tone: "disabled" | "link" | "muted" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "placeholder" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
10
+ weight: "regular" | "semibold";
11
+ } | undefined;
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { UseTextProps } from "./use-text.js";
3
+ declare type DefaultTextProps = {
4
+ size?: NonNullable<UseTextProps['size']>;
5
+ tone?: NonNullable<UseTextProps['tone']>;
6
+ weight?: NonNullable<UseTextProps['weight']>;
7
+ };
8
+ export declare function DefaultTextPropsProvider({ children, size, tone, weight, }: DefaultTextProps & {
9
+ children: ReactNode;
10
+ }): import("@emotion/react/jsx-runtime").JSX.Element;
11
+ export declare const useDefaultTextProps: ({ size: sizeProp, tone: toneProp, weight: weightProp, }: DefaultTextProps) => {
12
+ size: "small" | "xsmall" | "standard" | "large";
13
+ tone: "disabled" | "link" | "muted" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "placeholder" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
14
+ weight: "regular" | "semibold";
15
+ };
16
+ export {};
@@ -0,0 +1,11 @@
1
+ export { useTextContext } from "./context.js";
2
+ export { DefaultTextPropsProvider, useDefaultTextProps, } from "./default-text-props.js";
3
+ export { Strong } from "./strong.js";
4
+ export { Text } from "./text.js";
5
+ export { useForegroundTone } from "./use-foreground-tone.js";
6
+ export { useOverflowStrategy } from "./use-overflow-strategy.js";
7
+ export { createTextStyles, useText } from "./use-text.js";
8
+ export type { StrongProps } from "./strong.js";
9
+ export type { TextProps } from "./text.js";
10
+ export type { ForegroundTone } from "./use-foreground-tone.js";
11
+ export type { TextOverflowStrategy } from "./use-overflow-strategy.js";
@@ -0,0 +1,5 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare type StrongProps = {
3
+ children: ReactNode;
4
+ };
5
+ export declare const Strong: ({ children }: StrongProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,35 @@
1
+ import type { BoxProps } from '@spark-web/box';
2
+ import type { DataAttributeMap } from '@spark-web/utils/internal';
3
+ import type { CSSProperties, ReactNode } from 'react';
4
+ import type { TextOverflowStrategy } from "./use-overflow-strategy.js";
5
+ import type { UseTextProps } from "./use-text.js";
6
+ declare type InlineProps = {
7
+ align?: never;
8
+ /** Display as an inline element. */
9
+ inline?: boolean;
10
+ overflowStrategy?: never;
11
+ };
12
+ declare type BlockProps = {
13
+ /** The horizontal alignment. */
14
+ align?: 'left' | 'center' | 'right';
15
+ inline?: never;
16
+ /** Manage how text behaves with regard to overflow. */
17
+ overflowStrategy?: TextOverflowStrategy;
18
+ };
19
+ export declare type TextProps = Partial<UseTextProps> & {
20
+ /** The text content. */
21
+ children?: ReactNode;
22
+ /** Sets data attributes on the component. */
23
+ data?: DataAttributeMap;
24
+ /** An identifier which must be unique in the whole document. */
25
+ id?: BoxProps['id'];
26
+ /** When enabled, numbers will be the same width. Similar to a monospaced font. */
27
+ tabularNumbers?: boolean;
28
+ /** Transform the text casing. */
29
+ transform?: CSSProperties['textTransform'];
30
+ } & (InlineProps | BlockProps);
31
+ export declare const Text: <Comp extends import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> = "div">(props: {
32
+ as?: Comp | undefined;
33
+ ref?: import("react").Ref<Comp extends "symbol" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap ? (HTMLElementTagNameMap & Pick<SVGElementTagNameMap, "symbol" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view">)[Comp] : Comp extends new (...args: any) => any ? InstanceType<Comp> : undefined> | undefined;
34
+ } & Omit<import("react").PropsWithoutRef<import("react").ComponentProps<Comp>>, "as"> & TextProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
35
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { BrighteTheme } from '@spark-web/theme';
2
+ export declare type ForegroundTone = keyof Omit<BrighteTheme['color']['foreground'], 'neutralInverted' | 'mutedInverted'>;
3
+ export declare function useForegroundTone(tone: ForegroundTone): string;
@@ -0,0 +1,27 @@
1
+ declare const strategyMap: {
2
+ readonly truncate: {
3
+ readonly display: "block";
4
+ readonly overflow: "hidden";
5
+ readonly textOverflow: "ellipsis";
6
+ readonly whiteSpace: "nowrap";
7
+ };
8
+ readonly nowrap: {
9
+ readonly whiteSpace: "nowrap";
10
+ };
11
+ readonly breakword: {
12
+ readonly display: "block";
13
+ readonly overflowWrap: "break-word";
14
+ readonly wordBreak: "break-word";
15
+ readonly wordWrap: "break-word";
16
+ };
17
+ };
18
+ export declare type TextOverflowStrategy = keyof typeof strategyMap;
19
+ export declare function useOverflowStrategy(strategy?: TextOverflowStrategy): {
20
+ readonly whiteSpace: "nowrap";
21
+ } | {
22
+ readonly display: "block";
23
+ readonly overflowWrap: "break-word";
24
+ readonly wordBreak: "break-word";
25
+ readonly wordWrap: "break-word";
26
+ } | null;
27
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { BrighteTextDefinition, BrighteTheme } from '@spark-web/theme';
2
+ import type { ForegroundTone } from "./use-foreground-tone.js";
3
+ export declare type UseTextProps = {
4
+ /** Apply leading-trim styles. */
5
+ baseline?: boolean;
6
+ /** The size of the text. */
7
+ size: keyof BrighteTheme['typography']['text'];
8
+ /** The tone of the text. */
9
+ tone: ForegroundTone;
10
+ /** The weight of the text. */
11
+ weight: keyof BrighteTheme['typography']['fontWeight'];
12
+ };
13
+ export declare function useText({ baseline, size, tone, weight }: UseTextProps): any[];
14
+ export declare function createTextStyles({ fontSize, lineHeight, trims }: BrighteTextDefinition, { includeTrims }?: {
15
+ includeTrims?: boolean | undefined;
16
+ }): {
17
+ '::before'?: {
18
+ marginBottom: string;
19
+ content: string;
20
+ display: string;
21
+ } | undefined;
22
+ '::after'?: {
23
+ marginTop: string;
24
+ content: string;
25
+ display: string;
26
+ } | undefined;
27
+ fontSize: string;
28
+ lineHeight: string;
29
+ };
@@ -1,2 +1,2 @@
1
- export * from "../src/index";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLXRleHQuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
1
+ export * from "./declarations/src/index";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLXRleHQuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
@@ -0,0 +1,253 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
7
+ var react$1 = require('@emotion/react');
8
+ var theme = require('@spark-web/theme');
9
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
10
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
11
+ var box = require('@spark-web/box');
12
+ var ts = require('@spark-web/utils/ts');
13
+
14
+ var TextContext = /*#__PURE__*/react.createContext(undefined);
15
+ function useTextContext() {
16
+ return react.useContext(TextContext);
17
+ }
18
+
19
+ var DefaultTextPropsContext = /*#__PURE__*/react.createContext({
20
+ size: undefined,
21
+ tone: undefined,
22
+ weight: undefined
23
+ });
24
+ function DefaultTextPropsProvider(_ref) {
25
+ var children = _ref.children,
26
+ size = _ref.size,
27
+ tone = _ref.tone,
28
+ weight = _ref.weight;
29
+ var defaultTextProps = react.useMemo(function () {
30
+ return {
31
+ size: size,
32
+ tone: tone,
33
+ weight: weight
34
+ };
35
+ }, [size, tone, weight]);
36
+ return jsxRuntime.jsx(DefaultTextPropsContext.Provider, {
37
+ value: defaultTextProps,
38
+ children: children
39
+ });
40
+ }
41
+ var useDefaultTextProps = function useDefaultTextProps(_ref2) {
42
+ var _ref3, _ref4, _ref5;
43
+ var sizeProp = _ref2.size,
44
+ toneProp = _ref2.tone,
45
+ weightProp = _ref2.weight;
46
+ var _useContext = react.useContext(DefaultTextPropsContext),
47
+ size = _useContext.size,
48
+ tone = _useContext.tone,
49
+ weight = _useContext.weight;
50
+ return {
51
+ size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
52
+ tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
53
+ weight: (_ref5 = weightProp !== null && weightProp !== void 0 ? weightProp : weight) !== null && _ref5 !== void 0 ? _ref5 : 'regular'
54
+ };
55
+ };
56
+
57
+ var Strong = function Strong(_ref) {
58
+ var children = _ref.children;
59
+ var theme$1 = theme.useTheme();
60
+ var styles = {
61
+ fontWeight: theme$1.typography.fontWeight.semibold
62
+ };
63
+ return jsxRuntime.jsx("strong", {
64
+ css: react$1.css(styles),
65
+ children: children
66
+ });
67
+ };
68
+
69
+ var strategyMap = {
70
+ truncate: {
71
+ display: 'block',
72
+ overflow: 'hidden',
73
+ textOverflow: 'ellipsis',
74
+ whiteSpace: 'nowrap'
75
+ },
76
+ nowrap: {
77
+ whiteSpace: 'nowrap'
78
+ },
79
+ // https://css-tricks.com/better-line-breaks-for-long-urls/
80
+ breakword: {
81
+ display: 'block',
82
+ overflowWrap: 'break-word',
83
+ wordBreak: 'break-word',
84
+ wordWrap: 'break-word'
85
+ }
86
+ };
87
+ function useOverflowStrategy(strategy) {
88
+ if (!strategy) {
89
+ return null;
90
+ }
91
+ return strategyMap[strategy];
92
+ }
93
+
94
+ var invertableTones = {
95
+ neutral: {
96
+ dark: 'neutralInverted',
97
+ light: 'neutral'
98
+ },
99
+ muted: {
100
+ dark: 'mutedInverted',
101
+ light: 'muted'
102
+ },
103
+ link: {
104
+ dark: 'neutralInverted',
105
+ light: 'link'
106
+ }
107
+ };
108
+ function useForegroundTone(tone) {
109
+ var theme$1 = theme.useTheme();
110
+ var backgroundLightness = box.useBackgroundLightness();
111
+ if (tone in invertableTones) {
112
+ return theme$1.color.foreground[invertableTones[tone][backgroundLightness]];
113
+ }
114
+ return theme$1.color.foreground[tone];
115
+ }
116
+
117
+ function useText(_ref) {
118
+ var _ref$baseline = _ref.baseline,
119
+ baseline = _ref$baseline === void 0 ? true : _ref$baseline,
120
+ size = _ref.size,
121
+ tone = _ref.tone,
122
+ weight = _ref.weight;
123
+ var theme$1 = theme.useTheme();
124
+ var color = useForegroundTone(tone);
125
+ var _theme$typography$tex = theme$1.typography.text[size],
126
+ mobile = _theme$typography$tex.mobile,
127
+ tablet = _theme$typography$tex.tablet;
128
+ var responsiveStyles = theme$1.utils.responsiveStyles({
129
+ mobile: createTextStyles(mobile, {
130
+ includeTrims: baseline
131
+ }),
132
+ tablet: createTextStyles(tablet, {
133
+ includeTrims: baseline
134
+ })
135
+ });
136
+ var styles = [{
137
+ color: color,
138
+ fontFamily: theme$1.typography.fontFamily.sans.name,
139
+ fontWeight: theme$1.typography.fontWeight[weight]
140
+ }, responsiveStyles];
141
+ return styles;
142
+ }
143
+ function createTextStyles(_ref2) {
144
+ var fontSize = _ref2.fontSize,
145
+ lineHeight = _ref2.lineHeight,
146
+ trims = _ref2.trims;
147
+ var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
148
+ _ref3$includeTrims = _ref3.includeTrims,
149
+ includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims;
150
+ var pseudo = {
151
+ content: '" "',
152
+ display: 'table'
153
+ };
154
+ var leadingTrim = includeTrims ? {
155
+ '::before': _objectSpread(_objectSpread({}, pseudo), {}, {
156
+ marginBottom: trims.capHeightTrim
157
+ }),
158
+ '::after': _objectSpread(_objectSpread({}, pseudo), {}, {
159
+ marginTop: trims.baselineTrim
160
+ })
161
+ } : null;
162
+ return _objectSpread({
163
+ fontSize: fontSize,
164
+ lineHeight: lineHeight
165
+ }, leadingTrim);
166
+ }
167
+
168
+ var _excluded = ["as", "children", "data", "id", "align", "baseline", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
169
+ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
170
+ var as = _ref.as,
171
+ children = _ref.children,
172
+ data = _ref.data,
173
+ id = _ref.id,
174
+ align = _ref.align,
175
+ baselineProp = _ref.baseline,
176
+ inline = _ref.inline,
177
+ overflowStrategy = _ref.overflowStrategy,
178
+ sizeProp = _ref.size,
179
+ tabularNumbers = _ref.tabularNumbers,
180
+ toneProp = _ref.tone,
181
+ transform = _ref.transform,
182
+ weightProp = _ref.weight,
183
+ consumerProps = _objectWithoutProperties(_ref, _excluded);
184
+ var overflowStyles = useOverflowStrategy(overflowStrategy);
185
+ var textContext = useTextContext();
186
+ var _useDefaultTextProps = useDefaultTextProps({
187
+ size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
188
+ tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
189
+ weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
190
+ }),
191
+ size = _useDefaultTextProps.size,
192
+ tone = _useDefaultTextProps.tone,
193
+ weight = _useDefaultTextProps.weight;
194
+ var baseline = !inline && baselineProp;
195
+ var textStyles = useText({
196
+ baseline: baseline,
197
+ size: size,
198
+ tone: tone,
199
+ weight: weight
200
+ });
201
+ var styles = [textStyles, {
202
+ display: inline ? 'inline' : 'block',
203
+ fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
204
+ textAlign: align,
205
+ textTransform: transform
206
+ }];
207
+
208
+ // early exit for inline variant
209
+ if (inline) {
210
+ return jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
211
+ as: as !== null && as !== void 0 ? as : 'span',
212
+ data: data,
213
+ ref: forwardedRef,
214
+ id: id,
215
+ css: react$1.css(styles),
216
+ children: children
217
+ }));
218
+ }
219
+
220
+ // prepare block variant
221
+ var content = overflowStrategy ? jsxRuntime.jsx("span", {
222
+ css: react$1.css(overflowStyles),
223
+ children: children
224
+ }) : children;
225
+ var textContextValue = react.useMemo(function () {
226
+ return {
227
+ size: size,
228
+ tone: tone,
229
+ weight: weight
230
+ };
231
+ }, [size, tone, weight]);
232
+ return jsxRuntime.jsx(TextContext.Provider, {
233
+ value: textContextValue,
234
+ children: jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
235
+ as: as,
236
+ data: data,
237
+ ref: forwardedRef,
238
+ id: id,
239
+ css: react$1.css(styles),
240
+ children: content
241
+ }))
242
+ });
243
+ });
244
+
245
+ exports.DefaultTextPropsProvider = DefaultTextPropsProvider;
246
+ exports.Strong = Strong;
247
+ exports.Text = Text;
248
+ exports.createTextStyles = createTextStyles;
249
+ exports.useDefaultTextProps = useDefaultTextProps;
250
+ exports.useForegroundTone = useForegroundTone;
251
+ exports.useOverflowStrategy = useOverflowStrategy;
252
+ exports.useText = useText;
253
+ exports.useTextContext = useTextContext;
@@ -1,16 +1,7 @@
1
- "use strict";
2
- // this file might look strange and you might be wondering what it's for
3
- // it's lets you import your source files by importing this entrypoint
4
- // as you would import it if it was built with preconstruct build
5
- // this file is slightly different to some others though
6
- // it has a require hook which compiles your code with Babel
7
- // this means that you don't have to set up @babel/register or anything like that
8
- // but you can still require this module and it'll be compiled
1
+ 'use strict';
9
2
 
10
- // this bit of code imports the require hook and registers it
11
- let unregister = require("../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
12
-
13
- // this re-exports the source file
14
- module.exports = require("../src/index.ts");
15
-
16
- unregister();
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./spark-web-text.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./spark-web-text.cjs.dev.js");
7
+ }
@@ -0,0 +1,253 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
7
+ var react$1 = require('@emotion/react');
8
+ var theme = require('@spark-web/theme');
9
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
10
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
11
+ var box = require('@spark-web/box');
12
+ var ts = require('@spark-web/utils/ts');
13
+
14
+ var TextContext = /*#__PURE__*/react.createContext(undefined);
15
+ function useTextContext() {
16
+ return react.useContext(TextContext);
17
+ }
18
+
19
+ var DefaultTextPropsContext = /*#__PURE__*/react.createContext({
20
+ size: undefined,
21
+ tone: undefined,
22
+ weight: undefined
23
+ });
24
+ function DefaultTextPropsProvider(_ref) {
25
+ var children = _ref.children,
26
+ size = _ref.size,
27
+ tone = _ref.tone,
28
+ weight = _ref.weight;
29
+ var defaultTextProps = react.useMemo(function () {
30
+ return {
31
+ size: size,
32
+ tone: tone,
33
+ weight: weight
34
+ };
35
+ }, [size, tone, weight]);
36
+ return jsxRuntime.jsx(DefaultTextPropsContext.Provider, {
37
+ value: defaultTextProps,
38
+ children: children
39
+ });
40
+ }
41
+ var useDefaultTextProps = function useDefaultTextProps(_ref2) {
42
+ var _ref3, _ref4, _ref5;
43
+ var sizeProp = _ref2.size,
44
+ toneProp = _ref2.tone,
45
+ weightProp = _ref2.weight;
46
+ var _useContext = react.useContext(DefaultTextPropsContext),
47
+ size = _useContext.size,
48
+ tone = _useContext.tone,
49
+ weight = _useContext.weight;
50
+ return {
51
+ size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
52
+ tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
53
+ weight: (_ref5 = weightProp !== null && weightProp !== void 0 ? weightProp : weight) !== null && _ref5 !== void 0 ? _ref5 : 'regular'
54
+ };
55
+ };
56
+
57
+ var Strong = function Strong(_ref) {
58
+ var children = _ref.children;
59
+ var theme$1 = theme.useTheme();
60
+ var styles = {
61
+ fontWeight: theme$1.typography.fontWeight.semibold
62
+ };
63
+ return jsxRuntime.jsx("strong", {
64
+ css: react$1.css(styles),
65
+ children: children
66
+ });
67
+ };
68
+
69
+ var strategyMap = {
70
+ truncate: {
71
+ display: 'block',
72
+ overflow: 'hidden',
73
+ textOverflow: 'ellipsis',
74
+ whiteSpace: 'nowrap'
75
+ },
76
+ nowrap: {
77
+ whiteSpace: 'nowrap'
78
+ },
79
+ // https://css-tricks.com/better-line-breaks-for-long-urls/
80
+ breakword: {
81
+ display: 'block',
82
+ overflowWrap: 'break-word',
83
+ wordBreak: 'break-word',
84
+ wordWrap: 'break-word'
85
+ }
86
+ };
87
+ function useOverflowStrategy(strategy) {
88
+ if (!strategy) {
89
+ return null;
90
+ }
91
+ return strategyMap[strategy];
92
+ }
93
+
94
+ var invertableTones = {
95
+ neutral: {
96
+ dark: 'neutralInverted',
97
+ light: 'neutral'
98
+ },
99
+ muted: {
100
+ dark: 'mutedInverted',
101
+ light: 'muted'
102
+ },
103
+ link: {
104
+ dark: 'neutralInverted',
105
+ light: 'link'
106
+ }
107
+ };
108
+ function useForegroundTone(tone) {
109
+ var theme$1 = theme.useTheme();
110
+ var backgroundLightness = box.useBackgroundLightness();
111
+ if (tone in invertableTones) {
112
+ return theme$1.color.foreground[invertableTones[tone][backgroundLightness]];
113
+ }
114
+ return theme$1.color.foreground[tone];
115
+ }
116
+
117
+ function useText(_ref) {
118
+ var _ref$baseline = _ref.baseline,
119
+ baseline = _ref$baseline === void 0 ? true : _ref$baseline,
120
+ size = _ref.size,
121
+ tone = _ref.tone,
122
+ weight = _ref.weight;
123
+ var theme$1 = theme.useTheme();
124
+ var color = useForegroundTone(tone);
125
+ var _theme$typography$tex = theme$1.typography.text[size],
126
+ mobile = _theme$typography$tex.mobile,
127
+ tablet = _theme$typography$tex.tablet;
128
+ var responsiveStyles = theme$1.utils.responsiveStyles({
129
+ mobile: createTextStyles(mobile, {
130
+ includeTrims: baseline
131
+ }),
132
+ tablet: createTextStyles(tablet, {
133
+ includeTrims: baseline
134
+ })
135
+ });
136
+ var styles = [{
137
+ color: color,
138
+ fontFamily: theme$1.typography.fontFamily.sans.name,
139
+ fontWeight: theme$1.typography.fontWeight[weight]
140
+ }, responsiveStyles];
141
+ return styles;
142
+ }
143
+ function createTextStyles(_ref2) {
144
+ var fontSize = _ref2.fontSize,
145
+ lineHeight = _ref2.lineHeight,
146
+ trims = _ref2.trims;
147
+ var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
148
+ _ref3$includeTrims = _ref3.includeTrims,
149
+ includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims;
150
+ var pseudo = {
151
+ content: '" "',
152
+ display: 'table'
153
+ };
154
+ var leadingTrim = includeTrims ? {
155
+ '::before': _objectSpread(_objectSpread({}, pseudo), {}, {
156
+ marginBottom: trims.capHeightTrim
157
+ }),
158
+ '::after': _objectSpread(_objectSpread({}, pseudo), {}, {
159
+ marginTop: trims.baselineTrim
160
+ })
161
+ } : null;
162
+ return _objectSpread({
163
+ fontSize: fontSize,
164
+ lineHeight: lineHeight
165
+ }, leadingTrim);
166
+ }
167
+
168
+ var _excluded = ["as", "children", "data", "id", "align", "baseline", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
169
+ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
170
+ var as = _ref.as,
171
+ children = _ref.children,
172
+ data = _ref.data,
173
+ id = _ref.id,
174
+ align = _ref.align,
175
+ baselineProp = _ref.baseline,
176
+ inline = _ref.inline,
177
+ overflowStrategy = _ref.overflowStrategy,
178
+ sizeProp = _ref.size,
179
+ tabularNumbers = _ref.tabularNumbers,
180
+ toneProp = _ref.tone,
181
+ transform = _ref.transform,
182
+ weightProp = _ref.weight,
183
+ consumerProps = _objectWithoutProperties(_ref, _excluded);
184
+ var overflowStyles = useOverflowStrategy(overflowStrategy);
185
+ var textContext = useTextContext();
186
+ var _useDefaultTextProps = useDefaultTextProps({
187
+ size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
188
+ tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
189
+ weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
190
+ }),
191
+ size = _useDefaultTextProps.size,
192
+ tone = _useDefaultTextProps.tone,
193
+ weight = _useDefaultTextProps.weight;
194
+ var baseline = !inline && baselineProp;
195
+ var textStyles = useText({
196
+ baseline: baseline,
197
+ size: size,
198
+ tone: tone,
199
+ weight: weight
200
+ });
201
+ var styles = [textStyles, {
202
+ display: inline ? 'inline' : 'block',
203
+ fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
204
+ textAlign: align,
205
+ textTransform: transform
206
+ }];
207
+
208
+ // early exit for inline variant
209
+ if (inline) {
210
+ return jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
211
+ as: as !== null && as !== void 0 ? as : 'span',
212
+ data: data,
213
+ ref: forwardedRef,
214
+ id: id,
215
+ css: react$1.css(styles),
216
+ children: children
217
+ }));
218
+ }
219
+
220
+ // prepare block variant
221
+ var content = overflowStrategy ? jsxRuntime.jsx("span", {
222
+ css: react$1.css(overflowStyles),
223
+ children: children
224
+ }) : children;
225
+ var textContextValue = react.useMemo(function () {
226
+ return {
227
+ size: size,
228
+ tone: tone,
229
+ weight: weight
230
+ };
231
+ }, [size, tone, weight]);
232
+ return jsxRuntime.jsx(TextContext.Provider, {
233
+ value: textContextValue,
234
+ children: jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
235
+ as: as,
236
+ data: data,
237
+ ref: forwardedRef,
238
+ id: id,
239
+ css: react$1.css(styles),
240
+ children: content
241
+ }))
242
+ });
243
+ });
244
+
245
+ exports.DefaultTextPropsProvider = DefaultTextPropsProvider;
246
+ exports.Strong = Strong;
247
+ exports.Text = Text;
248
+ exports.createTextStyles = createTextStyles;
249
+ exports.useDefaultTextProps = useDefaultTextProps;
250
+ exports.useForegroundTone = useForegroundTone;
251
+ exports.useOverflowStrategy = useOverflowStrategy;
252
+ exports.useText = useText;
253
+ exports.useTextContext = useTextContext;
@@ -0,0 +1,241 @@
1
+ import { createContext, useContext, useMemo } from 'react';
2
+ import { jsx } from '@emotion/react/jsx-runtime';
3
+ import { css } from '@emotion/react';
4
+ import { useTheme } from '@spark-web/theme';
5
+ import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
6
+ import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
7
+ import { useBackgroundLightness, Box } from '@spark-web/box';
8
+ import { forwardRefWithAs } from '@spark-web/utils/ts';
9
+
10
+ var TextContext = /*#__PURE__*/createContext(undefined);
11
+ function useTextContext() {
12
+ return useContext(TextContext);
13
+ }
14
+
15
+ var DefaultTextPropsContext = /*#__PURE__*/createContext({
16
+ size: undefined,
17
+ tone: undefined,
18
+ weight: undefined
19
+ });
20
+ function DefaultTextPropsProvider(_ref) {
21
+ var children = _ref.children,
22
+ size = _ref.size,
23
+ tone = _ref.tone,
24
+ weight = _ref.weight;
25
+ var defaultTextProps = useMemo(function () {
26
+ return {
27
+ size: size,
28
+ tone: tone,
29
+ weight: weight
30
+ };
31
+ }, [size, tone, weight]);
32
+ return jsx(DefaultTextPropsContext.Provider, {
33
+ value: defaultTextProps,
34
+ children: children
35
+ });
36
+ }
37
+ var useDefaultTextProps = function useDefaultTextProps(_ref2) {
38
+ var _ref3, _ref4, _ref5;
39
+ var sizeProp = _ref2.size,
40
+ toneProp = _ref2.tone,
41
+ weightProp = _ref2.weight;
42
+ var _useContext = useContext(DefaultTextPropsContext),
43
+ size = _useContext.size,
44
+ tone = _useContext.tone,
45
+ weight = _useContext.weight;
46
+ return {
47
+ size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
48
+ tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
49
+ weight: (_ref5 = weightProp !== null && weightProp !== void 0 ? weightProp : weight) !== null && _ref5 !== void 0 ? _ref5 : 'regular'
50
+ };
51
+ };
52
+
53
+ var Strong = function Strong(_ref) {
54
+ var children = _ref.children;
55
+ var theme = useTheme();
56
+ var styles = {
57
+ fontWeight: theme.typography.fontWeight.semibold
58
+ };
59
+ return jsx("strong", {
60
+ css: css(styles),
61
+ children: children
62
+ });
63
+ };
64
+
65
+ var strategyMap = {
66
+ truncate: {
67
+ display: 'block',
68
+ overflow: 'hidden',
69
+ textOverflow: 'ellipsis',
70
+ whiteSpace: 'nowrap'
71
+ },
72
+ nowrap: {
73
+ whiteSpace: 'nowrap'
74
+ },
75
+ // https://css-tricks.com/better-line-breaks-for-long-urls/
76
+ breakword: {
77
+ display: 'block',
78
+ overflowWrap: 'break-word',
79
+ wordBreak: 'break-word',
80
+ wordWrap: 'break-word'
81
+ }
82
+ };
83
+ function useOverflowStrategy(strategy) {
84
+ if (!strategy) {
85
+ return null;
86
+ }
87
+ return strategyMap[strategy];
88
+ }
89
+
90
+ var invertableTones = {
91
+ neutral: {
92
+ dark: 'neutralInverted',
93
+ light: 'neutral'
94
+ },
95
+ muted: {
96
+ dark: 'mutedInverted',
97
+ light: 'muted'
98
+ },
99
+ link: {
100
+ dark: 'neutralInverted',
101
+ light: 'link'
102
+ }
103
+ };
104
+ function useForegroundTone(tone) {
105
+ var theme = useTheme();
106
+ var backgroundLightness = useBackgroundLightness();
107
+ if (tone in invertableTones) {
108
+ return theme.color.foreground[invertableTones[tone][backgroundLightness]];
109
+ }
110
+ return theme.color.foreground[tone];
111
+ }
112
+
113
+ function useText(_ref) {
114
+ var _ref$baseline = _ref.baseline,
115
+ baseline = _ref$baseline === void 0 ? true : _ref$baseline,
116
+ size = _ref.size,
117
+ tone = _ref.tone,
118
+ weight = _ref.weight;
119
+ var theme = useTheme();
120
+ var color = useForegroundTone(tone);
121
+ var _theme$typography$tex = theme.typography.text[size],
122
+ mobile = _theme$typography$tex.mobile,
123
+ tablet = _theme$typography$tex.tablet;
124
+ var responsiveStyles = theme.utils.responsiveStyles({
125
+ mobile: createTextStyles(mobile, {
126
+ includeTrims: baseline
127
+ }),
128
+ tablet: createTextStyles(tablet, {
129
+ includeTrims: baseline
130
+ })
131
+ });
132
+ var styles = [{
133
+ color: color,
134
+ fontFamily: theme.typography.fontFamily.sans.name,
135
+ fontWeight: theme.typography.fontWeight[weight]
136
+ }, responsiveStyles];
137
+ return styles;
138
+ }
139
+ function createTextStyles(_ref2) {
140
+ var fontSize = _ref2.fontSize,
141
+ lineHeight = _ref2.lineHeight,
142
+ trims = _ref2.trims;
143
+ var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
144
+ _ref3$includeTrims = _ref3.includeTrims,
145
+ includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims;
146
+ var pseudo = {
147
+ content: '" "',
148
+ display: 'table'
149
+ };
150
+ var leadingTrim = includeTrims ? {
151
+ '::before': _objectSpread(_objectSpread({}, pseudo), {}, {
152
+ marginBottom: trims.capHeightTrim
153
+ }),
154
+ '::after': _objectSpread(_objectSpread({}, pseudo), {}, {
155
+ marginTop: trims.baselineTrim
156
+ })
157
+ } : null;
158
+ return _objectSpread({
159
+ fontSize: fontSize,
160
+ lineHeight: lineHeight
161
+ }, leadingTrim);
162
+ }
163
+
164
+ var _excluded = ["as", "children", "data", "id", "align", "baseline", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
165
+ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
166
+ var as = _ref.as,
167
+ children = _ref.children,
168
+ data = _ref.data,
169
+ id = _ref.id,
170
+ align = _ref.align,
171
+ baselineProp = _ref.baseline,
172
+ inline = _ref.inline,
173
+ overflowStrategy = _ref.overflowStrategy,
174
+ sizeProp = _ref.size,
175
+ tabularNumbers = _ref.tabularNumbers,
176
+ toneProp = _ref.tone,
177
+ transform = _ref.transform,
178
+ weightProp = _ref.weight,
179
+ consumerProps = _objectWithoutProperties(_ref, _excluded);
180
+ var overflowStyles = useOverflowStrategy(overflowStrategy);
181
+ var textContext = useTextContext();
182
+ var _useDefaultTextProps = useDefaultTextProps({
183
+ size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
184
+ tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
185
+ weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
186
+ }),
187
+ size = _useDefaultTextProps.size,
188
+ tone = _useDefaultTextProps.tone,
189
+ weight = _useDefaultTextProps.weight;
190
+ var baseline = !inline && baselineProp;
191
+ var textStyles = useText({
192
+ baseline: baseline,
193
+ size: size,
194
+ tone: tone,
195
+ weight: weight
196
+ });
197
+ var styles = [textStyles, {
198
+ display: inline ? 'inline' : 'block',
199
+ fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
200
+ textAlign: align,
201
+ textTransform: transform
202
+ }];
203
+
204
+ // early exit for inline variant
205
+ if (inline) {
206
+ return jsx(Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
207
+ as: as !== null && as !== void 0 ? as : 'span',
208
+ data: data,
209
+ ref: forwardedRef,
210
+ id: id,
211
+ css: css(styles),
212
+ children: children
213
+ }));
214
+ }
215
+
216
+ // prepare block variant
217
+ var content = overflowStrategy ? jsx("span", {
218
+ css: css(overflowStyles),
219
+ children: children
220
+ }) : children;
221
+ var textContextValue = useMemo(function () {
222
+ return {
223
+ size: size,
224
+ tone: tone,
225
+ weight: weight
226
+ };
227
+ }, [size, tone, weight]);
228
+ return jsx(TextContext.Provider, {
229
+ value: textContextValue,
230
+ children: jsx(Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
231
+ as: as,
232
+ data: data,
233
+ ref: forwardedRef,
234
+ id: id,
235
+ css: css(styles),
236
+ children: content
237
+ }))
238
+ });
239
+ });
240
+
241
+ export { DefaultTextPropsProvider, Strong, Text, createTextStyles, useDefaultTextProps, useForegroundTone, useOverflowStrategy, useText, useTextContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-web/text",
3
- "version": "2.0.0-rc.0",
3
+ "version": "2.0.0-rc.2",
4
4
  "homepage": "https://github.com/brighte-labs/spark-web#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,9 +17,9 @@
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.25.0",
19
19
  "@emotion/react": "^11.13.5",
20
- "@spark-web/box": "^2.0.0-rc.0",
21
- "@spark-web/theme": "^4.0.0-rc.0",
22
- "@spark-web/utils": "^2.0.0-rc.0"
20
+ "@spark-web/box": "^2.0.0-rc.2",
21
+ "@spark-web/theme": "^4.0.0-rc.2",
22
+ "@spark-web/utils": "^2.0.0-rc.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/react": "^18.2.0",