@spark-web/text 1.1.2 → 2.0.0-rc.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @spark-web/text
2
2
 
3
+ ## 2.0.0-rc.0
4
+
5
+ ### Major Changes
6
+
7
+ - rc versio
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies []:
12
+ - @spark-web/theme@4.0.0-rc.0
13
+ - @spark-web/box@2.0.0-rc.0
14
+ - @spark-web/utils@2.0.0-rc.0
15
+
16
+ ## 1.2.0
17
+
18
+ ### Minor Changes
19
+
20
+ - [#382](https://github.com/brighte-labs/spark-web/pull/382)
21
+ [`955bf5d`](https://github.com/brighte-labs/spark-web/commit/955bf5d7698bfdf45e7f317aa3e726c81d3444c0)
22
+ Thanks [@dilipt-brighte](https://github.com/dilipt-brighte)! - Updates React
23
+ version to latest (18.2.0)
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ [[`955bf5d`](https://github.com/brighte-labs/spark-web/commit/955bf5d7698bfdf45e7f317aa3e726c81d3444c0)]:
29
+ - @spark-web/box@1.2.0
30
+ - @spark-web/theme@3.2.0
31
+ - @spark-web/utils@1.3.0
32
+
3
33
  ## 1.1.2
4
34
 
5
35
  ### Patch Changes
@@ -1 +1,2 @@
1
- export * from "./declarations/src/index";
1
+ export * from "../src/index";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLXRleHQuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -1,7 +1,16 @@
1
- 'use strict';
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
2
9
 
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
- }
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-web/text",
3
- "version": "1.1.2",
3
+ "version": "2.0.0-rc.0",
4
4
  "homepage": "https://github.com/brighte-labs/spark-web#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,15 +15,15 @@
15
15
  "README.md"
16
16
  ],
17
17
  "dependencies": {
18
- "@babel/runtime": "^7.19.0",
19
- "@emotion/css": "^11.9.0",
20
- "@spark-web/box": "^1.1.0",
21
- "@spark-web/theme": "^3.1.0",
22
- "@spark-web/utils": "^1.2.3"
18
+ "@babel/runtime": "^7.25.0",
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"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/react": "^17.0.12",
26
- "react": "^17.0.2"
25
+ "@types/react": "^18.2.0",
26
+ "react": "^18.2.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": ">=17.0.2"
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const TextContext: import("react").Context<{
3
- size: "small" | "xsmall" | "standard" | "large";
4
- tone: "link" | "muted" | "disabled" | "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: "link" | "muted" | "disabled" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "placeholder" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
10
- weight: "regular" | "semibold";
11
- } | undefined;
@@ -1,16 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { UseTextProps } from './use-text';
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
- }): JSX.Element;
11
- export declare const useDefaultTextProps: ({ size: sizeProp, tone: toneProp, weight: weightProp, }: DefaultTextProps) => {
12
- size: "small" | "xsmall" | "standard" | "large";
13
- tone: "link" | "muted" | "disabled" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "placeholder" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
14
- weight: "regular" | "semibold";
15
- };
16
- export {};
@@ -1,11 +0,0 @@
1
- export { useTextContext } from './context';
2
- export { DefaultTextPropsProvider, useDefaultTextProps, } from './default-text-props';
3
- export { Strong } from './strong';
4
- export { Text } from './text';
5
- export { useForegroundTone } from './use-foreground-tone';
6
- export { useOverflowStrategy } from './use-overflow-strategy';
7
- export { createTextStyles, useText } from './use-text';
8
- export type { StrongProps } from './strong';
9
- export type { TextProps } from './text';
10
- export type { ForegroundTone } from './use-foreground-tone';
11
- export type { TextOverflowStrategy } from './use-overflow-strategy';
@@ -1,5 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- export declare type StrongProps = {
3
- children: ReactNode;
4
- };
5
- export declare const Strong: ({ children }: StrongProps) => JSX.Element;
@@ -1,35 +0,0 @@
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';
5
- import type { UseTextProps } from './use-text';
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> = "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" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | "set" | 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" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | "set">)[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 {};
@@ -1,3 +0,0 @@
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;
@@ -1,27 +0,0 @@
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 {};
@@ -1,29 +0,0 @@
1
- import type { BrighteTextDefinition, BrighteTheme } from '@spark-web/theme';
2
- import type { ForegroundTone } from './use-foreground-tone';
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): (import("@emotion/serialize").CSSObject | undefined)[];
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,263 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
- var jsxRuntime = require('react/jsx-runtime');
7
- var css = require('@emotion/css');
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 /*#__PURE__*/jsxRuntime.jsx(DefaultTextPropsContext.Provider, {
37
- value: defaultTextProps,
38
- children: children
39
- });
40
- }
41
- var useDefaultTextProps = function useDefaultTextProps(_ref2) {
42
- var _ref3, _ref4, _ref5;
43
-
44
- var sizeProp = _ref2.size,
45
- toneProp = _ref2.tone,
46
- weightProp = _ref2.weight;
47
-
48
- var _useContext = react.useContext(DefaultTextPropsContext),
49
- size = _useContext.size,
50
- tone = _useContext.tone,
51
- weight = _useContext.weight;
52
-
53
- return {
54
- size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
55
- tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
56
- weight: (_ref5 = weightProp !== null && weightProp !== void 0 ? weightProp : weight) !== null && _ref5 !== void 0 ? _ref5 : 'regular'
57
- };
58
- };
59
-
60
- var Strong = function Strong(_ref) {
61
- var children = _ref.children;
62
- var theme$1 = theme.useTheme();
63
- var styles = {
64
- fontWeight: theme$1.typography.fontWeight.semibold
65
- };
66
- return /*#__PURE__*/jsxRuntime.jsx("strong", {
67
- className: css.css(styles),
68
- children: children
69
- });
70
- };
71
-
72
- var strategyMap = {
73
- truncate: {
74
- display: 'block',
75
- overflow: 'hidden',
76
- textOverflow: 'ellipsis',
77
- whiteSpace: 'nowrap'
78
- },
79
- nowrap: {
80
- whiteSpace: 'nowrap'
81
- },
82
- // https://css-tricks.com/better-line-breaks-for-long-urls/
83
- breakword: {
84
- display: 'block',
85
- overflowWrap: 'break-word',
86
- wordBreak: 'break-word',
87
- wordWrap: 'break-word'
88
- }
89
- };
90
- function useOverflowStrategy(strategy) {
91
- if (!strategy) {
92
- return null;
93
- }
94
-
95
- return strategyMap[strategy];
96
- }
97
-
98
- var invertableTones = {
99
- neutral: {
100
- dark: 'neutralInverted',
101
- light: 'neutral'
102
- },
103
- muted: {
104
- dark: 'mutedInverted',
105
- light: 'muted'
106
- },
107
- link: {
108
- dark: 'neutralInverted',
109
- light: 'link'
110
- }
111
- };
112
- function useForegroundTone(tone) {
113
- var theme$1 = theme.useTheme();
114
- var backgroundLightness = box.useBackgroundLightness();
115
-
116
- if (tone in invertableTones) {
117
- return theme$1.color.foreground[invertableTones[tone][backgroundLightness]];
118
- }
119
-
120
- return theme$1.color.foreground[tone];
121
- }
122
-
123
- function useText(_ref) {
124
- var _ref$baseline = _ref.baseline,
125
- baseline = _ref$baseline === void 0 ? true : _ref$baseline,
126
- size = _ref.size,
127
- tone = _ref.tone,
128
- weight = _ref.weight;
129
- var theme$1 = theme.useTheme();
130
- var color = useForegroundTone(tone);
131
- var _theme$typography$tex = theme$1.typography.text[size],
132
- mobile = _theme$typography$tex.mobile,
133
- tablet = _theme$typography$tex.tablet;
134
- var responsiveStyles = theme$1.utils.responsiveStyles({
135
- mobile: createTextStyles(mobile, {
136
- includeTrims: baseline
137
- }),
138
- tablet: createTextStyles(tablet, {
139
- includeTrims: baseline
140
- })
141
- });
142
- var styles = [{
143
- color: color,
144
- fontFamily: theme$1.typography.fontFamily.sans.name,
145
- fontWeight: theme$1.typography.fontWeight[weight]
146
- }, responsiveStyles];
147
- return styles;
148
- }
149
- function createTextStyles(_ref2) {
150
- var fontSize = _ref2.fontSize,
151
- lineHeight = _ref2.lineHeight,
152
- trims = _ref2.trims;
153
-
154
- var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
155
- _ref3$includeTrims = _ref3.includeTrims,
156
- includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims;
157
-
158
- var pseudo = {
159
- content: '" "',
160
- display: 'table'
161
- };
162
- var leadingTrim = includeTrims ? {
163
- '::before': _objectSpread(_objectSpread({}, pseudo), {}, {
164
- marginBottom: trims.capHeightTrim
165
- }),
166
- '::after': _objectSpread(_objectSpread({}, pseudo), {}, {
167
- marginTop: trims.baselineTrim
168
- })
169
- } : null;
170
- return _objectSpread({
171
- fontSize: fontSize,
172
- lineHeight: lineHeight
173
- }, leadingTrim);
174
- }
175
-
176
- var _excluded = ["as", "children", "data", "id", "align", "baseline", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
177
- var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
178
- var as = _ref.as,
179
- children = _ref.children,
180
- data = _ref.data,
181
- id = _ref.id,
182
- align = _ref.align,
183
- baselineProp = _ref.baseline,
184
- inline = _ref.inline,
185
- overflowStrategy = _ref.overflowStrategy,
186
- sizeProp = _ref.size,
187
- tabularNumbers = _ref.tabularNumbers,
188
- toneProp = _ref.tone,
189
- transform = _ref.transform,
190
- weightProp = _ref.weight,
191
- consumerProps = _objectWithoutProperties(_ref, _excluded);
192
-
193
- var overflowStyles = useOverflowStrategy(overflowStrategy);
194
- var textContext = useTextContext();
195
-
196
- var _useDefaultTextProps = useDefaultTextProps({
197
- size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
198
- tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
199
- weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
200
- }),
201
- size = _useDefaultTextProps.size,
202
- tone = _useDefaultTextProps.tone,
203
- weight = _useDefaultTextProps.weight;
204
-
205
- var baseline = !inline && baselineProp;
206
- var textStyles = useText({
207
- baseline: baseline,
208
- size: size,
209
- tone: tone,
210
- weight: weight
211
- });
212
- var styles = [textStyles, {
213
- display: inline ? 'inline' : 'block',
214
- fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
215
- textAlign: align,
216
- textTransform: transform
217
- }]; // early exit for inline variant
218
-
219
- if (inline) {
220
- return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
221
- as: as !== null && as !== void 0 ? as : 'span',
222
- data: data,
223
- ref: forwardedRef,
224
- id: id,
225
- className: css.css(styles),
226
- children: children
227
- }));
228
- } // prepare block variant
229
-
230
-
231
- var content = overflowStrategy ? /*#__PURE__*/jsxRuntime.jsx("span", {
232
- className: css.css(overflowStyles),
233
- children: children
234
- }) : children;
235
- var textContextValue = react.useMemo(function () {
236
- return {
237
- size: size,
238
- tone: tone,
239
- weight: weight
240
- };
241
- }, [size, tone, weight]);
242
- return /*#__PURE__*/jsxRuntime.jsx(TextContext.Provider, {
243
- value: textContextValue,
244
- children: /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
245
- as: as,
246
- data: data,
247
- ref: forwardedRef,
248
- id: id,
249
- className: css.css(styles),
250
- children: content
251
- }))
252
- });
253
- });
254
-
255
- exports.DefaultTextPropsProvider = DefaultTextPropsProvider;
256
- exports.Strong = Strong;
257
- exports.Text = Text;
258
- exports.createTextStyles = createTextStyles;
259
- exports.useDefaultTextProps = useDefaultTextProps;
260
- exports.useForegroundTone = useForegroundTone;
261
- exports.useOverflowStrategy = useOverflowStrategy;
262
- exports.useText = useText;
263
- exports.useTextContext = useTextContext;
@@ -1,263 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var react = require('react');
6
- var jsxRuntime = require('react/jsx-runtime');
7
- var css = require('@emotion/css');
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 /*#__PURE__*/jsxRuntime.jsx(DefaultTextPropsContext.Provider, {
37
- value: defaultTextProps,
38
- children: children
39
- });
40
- }
41
- var useDefaultTextProps = function useDefaultTextProps(_ref2) {
42
- var _ref3, _ref4, _ref5;
43
-
44
- var sizeProp = _ref2.size,
45
- toneProp = _ref2.tone,
46
- weightProp = _ref2.weight;
47
-
48
- var _useContext = react.useContext(DefaultTextPropsContext),
49
- size = _useContext.size,
50
- tone = _useContext.tone,
51
- weight = _useContext.weight;
52
-
53
- return {
54
- size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
55
- tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
56
- weight: (_ref5 = weightProp !== null && weightProp !== void 0 ? weightProp : weight) !== null && _ref5 !== void 0 ? _ref5 : 'regular'
57
- };
58
- };
59
-
60
- var Strong = function Strong(_ref) {
61
- var children = _ref.children;
62
- var theme$1 = theme.useTheme();
63
- var styles = {
64
- fontWeight: theme$1.typography.fontWeight.semibold
65
- };
66
- return /*#__PURE__*/jsxRuntime.jsx("strong", {
67
- className: css.css(styles),
68
- children: children
69
- });
70
- };
71
-
72
- var strategyMap = {
73
- truncate: {
74
- display: 'block',
75
- overflow: 'hidden',
76
- textOverflow: 'ellipsis',
77
- whiteSpace: 'nowrap'
78
- },
79
- nowrap: {
80
- whiteSpace: 'nowrap'
81
- },
82
- // https://css-tricks.com/better-line-breaks-for-long-urls/
83
- breakword: {
84
- display: 'block',
85
- overflowWrap: 'break-word',
86
- wordBreak: 'break-word',
87
- wordWrap: 'break-word'
88
- }
89
- };
90
- function useOverflowStrategy(strategy) {
91
- if (!strategy) {
92
- return null;
93
- }
94
-
95
- return strategyMap[strategy];
96
- }
97
-
98
- var invertableTones = {
99
- neutral: {
100
- dark: 'neutralInverted',
101
- light: 'neutral'
102
- },
103
- muted: {
104
- dark: 'mutedInverted',
105
- light: 'muted'
106
- },
107
- link: {
108
- dark: 'neutralInverted',
109
- light: 'link'
110
- }
111
- };
112
- function useForegroundTone(tone) {
113
- var theme$1 = theme.useTheme();
114
- var backgroundLightness = box.useBackgroundLightness();
115
-
116
- if (tone in invertableTones) {
117
- return theme$1.color.foreground[invertableTones[tone][backgroundLightness]];
118
- }
119
-
120
- return theme$1.color.foreground[tone];
121
- }
122
-
123
- function useText(_ref) {
124
- var _ref$baseline = _ref.baseline,
125
- baseline = _ref$baseline === void 0 ? true : _ref$baseline,
126
- size = _ref.size,
127
- tone = _ref.tone,
128
- weight = _ref.weight;
129
- var theme$1 = theme.useTheme();
130
- var color = useForegroundTone(tone);
131
- var _theme$typography$tex = theme$1.typography.text[size],
132
- mobile = _theme$typography$tex.mobile,
133
- tablet = _theme$typography$tex.tablet;
134
- var responsiveStyles = theme$1.utils.responsiveStyles({
135
- mobile: createTextStyles(mobile, {
136
- includeTrims: baseline
137
- }),
138
- tablet: createTextStyles(tablet, {
139
- includeTrims: baseline
140
- })
141
- });
142
- var styles = [{
143
- color: color,
144
- fontFamily: theme$1.typography.fontFamily.sans.name,
145
- fontWeight: theme$1.typography.fontWeight[weight]
146
- }, responsiveStyles];
147
- return styles;
148
- }
149
- function createTextStyles(_ref2) {
150
- var fontSize = _ref2.fontSize,
151
- lineHeight = _ref2.lineHeight,
152
- trims = _ref2.trims;
153
-
154
- var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
155
- _ref3$includeTrims = _ref3.includeTrims,
156
- includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims;
157
-
158
- var pseudo = {
159
- content: '" "',
160
- display: 'table'
161
- };
162
- var leadingTrim = includeTrims ? {
163
- '::before': _objectSpread(_objectSpread({}, pseudo), {}, {
164
- marginBottom: trims.capHeightTrim
165
- }),
166
- '::after': _objectSpread(_objectSpread({}, pseudo), {}, {
167
- marginTop: trims.baselineTrim
168
- })
169
- } : null;
170
- return _objectSpread({
171
- fontSize: fontSize,
172
- lineHeight: lineHeight
173
- }, leadingTrim);
174
- }
175
-
176
- var _excluded = ["as", "children", "data", "id", "align", "baseline", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
177
- var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
178
- var as = _ref.as,
179
- children = _ref.children,
180
- data = _ref.data,
181
- id = _ref.id,
182
- align = _ref.align,
183
- baselineProp = _ref.baseline,
184
- inline = _ref.inline,
185
- overflowStrategy = _ref.overflowStrategy,
186
- sizeProp = _ref.size,
187
- tabularNumbers = _ref.tabularNumbers,
188
- toneProp = _ref.tone,
189
- transform = _ref.transform,
190
- weightProp = _ref.weight,
191
- consumerProps = _objectWithoutProperties(_ref, _excluded);
192
-
193
- var overflowStyles = useOverflowStrategy(overflowStrategy);
194
- var textContext = useTextContext();
195
-
196
- var _useDefaultTextProps = useDefaultTextProps({
197
- size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
198
- tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
199
- weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
200
- }),
201
- size = _useDefaultTextProps.size,
202
- tone = _useDefaultTextProps.tone,
203
- weight = _useDefaultTextProps.weight;
204
-
205
- var baseline = !inline && baselineProp;
206
- var textStyles = useText({
207
- baseline: baseline,
208
- size: size,
209
- tone: tone,
210
- weight: weight
211
- });
212
- var styles = [textStyles, {
213
- display: inline ? 'inline' : 'block',
214
- fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
215
- textAlign: align,
216
- textTransform: transform
217
- }]; // early exit for inline variant
218
-
219
- if (inline) {
220
- return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
221
- as: as !== null && as !== void 0 ? as : 'span',
222
- data: data,
223
- ref: forwardedRef,
224
- id: id,
225
- className: css.css(styles),
226
- children: children
227
- }));
228
- } // prepare block variant
229
-
230
-
231
- var content = overflowStrategy ? /*#__PURE__*/jsxRuntime.jsx("span", {
232
- className: css.css(overflowStyles),
233
- children: children
234
- }) : children;
235
- var textContextValue = react.useMemo(function () {
236
- return {
237
- size: size,
238
- tone: tone,
239
- weight: weight
240
- };
241
- }, [size, tone, weight]);
242
- return /*#__PURE__*/jsxRuntime.jsx(TextContext.Provider, {
243
- value: textContextValue,
244
- children: /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
245
- as: as,
246
- data: data,
247
- ref: forwardedRef,
248
- id: id,
249
- className: css.css(styles),
250
- children: content
251
- }))
252
- });
253
- });
254
-
255
- exports.DefaultTextPropsProvider = DefaultTextPropsProvider;
256
- exports.Strong = Strong;
257
- exports.Text = Text;
258
- exports.createTextStyles = createTextStyles;
259
- exports.useDefaultTextProps = useDefaultTextProps;
260
- exports.useForegroundTone = useForegroundTone;
261
- exports.useOverflowStrategy = useOverflowStrategy;
262
- exports.useText = useText;
263
- exports.useTextContext = useTextContext;
@@ -1,251 +0,0 @@
1
- import { useContext, createContext, useMemo } from 'react';
2
- import { jsx } from 'react/jsx-runtime';
3
- import { css } from '@emotion/css';
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 /*#__PURE__*/jsx(DefaultTextPropsContext.Provider, {
33
- value: defaultTextProps,
34
- children: children
35
- });
36
- }
37
- var useDefaultTextProps = function useDefaultTextProps(_ref2) {
38
- var _ref3, _ref4, _ref5;
39
-
40
- var sizeProp = _ref2.size,
41
- toneProp = _ref2.tone,
42
- weightProp = _ref2.weight;
43
-
44
- var _useContext = useContext(DefaultTextPropsContext),
45
- size = _useContext.size,
46
- tone = _useContext.tone,
47
- weight = _useContext.weight;
48
-
49
- return {
50
- size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
51
- tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
52
- weight: (_ref5 = weightProp !== null && weightProp !== void 0 ? weightProp : weight) !== null && _ref5 !== void 0 ? _ref5 : 'regular'
53
- };
54
- };
55
-
56
- var Strong = function Strong(_ref) {
57
- var children = _ref.children;
58
- var theme = useTheme();
59
- var styles = {
60
- fontWeight: theme.typography.fontWeight.semibold
61
- };
62
- return /*#__PURE__*/jsx("strong", {
63
- className: css(styles),
64
- children: children
65
- });
66
- };
67
-
68
- var strategyMap = {
69
- truncate: {
70
- display: 'block',
71
- overflow: 'hidden',
72
- textOverflow: 'ellipsis',
73
- whiteSpace: 'nowrap'
74
- },
75
- nowrap: {
76
- whiteSpace: 'nowrap'
77
- },
78
- // https://css-tricks.com/better-line-breaks-for-long-urls/
79
- breakword: {
80
- display: 'block',
81
- overflowWrap: 'break-word',
82
- wordBreak: 'break-word',
83
- wordWrap: 'break-word'
84
- }
85
- };
86
- function useOverflowStrategy(strategy) {
87
- if (!strategy) {
88
- return null;
89
- }
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 = useTheme();
110
- var backgroundLightness = useBackgroundLightness();
111
-
112
- if (tone in invertableTones) {
113
- return theme.color.foreground[invertableTones[tone][backgroundLightness]];
114
- }
115
-
116
- return theme.color.foreground[tone];
117
- }
118
-
119
- function useText(_ref) {
120
- var _ref$baseline = _ref.baseline,
121
- baseline = _ref$baseline === void 0 ? true : _ref$baseline,
122
- size = _ref.size,
123
- tone = _ref.tone,
124
- weight = _ref.weight;
125
- var theme = useTheme();
126
- var color = useForegroundTone(tone);
127
- var _theme$typography$tex = theme.typography.text[size],
128
- mobile = _theme$typography$tex.mobile,
129
- tablet = _theme$typography$tex.tablet;
130
- var responsiveStyles = theme.utils.responsiveStyles({
131
- mobile: createTextStyles(mobile, {
132
- includeTrims: baseline
133
- }),
134
- tablet: createTextStyles(tablet, {
135
- includeTrims: baseline
136
- })
137
- });
138
- var styles = [{
139
- color: color,
140
- fontFamily: theme.typography.fontFamily.sans.name,
141
- fontWeight: theme.typography.fontWeight[weight]
142
- }, responsiveStyles];
143
- return styles;
144
- }
145
- function createTextStyles(_ref2) {
146
- var fontSize = _ref2.fontSize,
147
- lineHeight = _ref2.lineHeight,
148
- trims = _ref2.trims;
149
-
150
- var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
151
- _ref3$includeTrims = _ref3.includeTrims,
152
- includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims;
153
-
154
- var pseudo = {
155
- content: '" "',
156
- display: 'table'
157
- };
158
- var leadingTrim = includeTrims ? {
159
- '::before': _objectSpread(_objectSpread({}, pseudo), {}, {
160
- marginBottom: trims.capHeightTrim
161
- }),
162
- '::after': _objectSpread(_objectSpread({}, pseudo), {}, {
163
- marginTop: trims.baselineTrim
164
- })
165
- } : null;
166
- return _objectSpread({
167
- fontSize: fontSize,
168
- lineHeight: lineHeight
169
- }, leadingTrim);
170
- }
171
-
172
- var _excluded = ["as", "children", "data", "id", "align", "baseline", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
173
- var Text = forwardRefWithAs(function (_ref, forwardedRef) {
174
- var as = _ref.as,
175
- children = _ref.children,
176
- data = _ref.data,
177
- id = _ref.id,
178
- align = _ref.align,
179
- baselineProp = _ref.baseline,
180
- inline = _ref.inline,
181
- overflowStrategy = _ref.overflowStrategy,
182
- sizeProp = _ref.size,
183
- tabularNumbers = _ref.tabularNumbers,
184
- toneProp = _ref.tone,
185
- transform = _ref.transform,
186
- weightProp = _ref.weight,
187
- consumerProps = _objectWithoutProperties(_ref, _excluded);
188
-
189
- var overflowStyles = useOverflowStrategy(overflowStrategy);
190
- var textContext = useTextContext();
191
-
192
- var _useDefaultTextProps = useDefaultTextProps({
193
- size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
194
- tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
195
- weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
196
- }),
197
- size = _useDefaultTextProps.size,
198
- tone = _useDefaultTextProps.tone,
199
- weight = _useDefaultTextProps.weight;
200
-
201
- var baseline = !inline && baselineProp;
202
- var textStyles = useText({
203
- baseline: baseline,
204
- size: size,
205
- tone: tone,
206
- weight: weight
207
- });
208
- var styles = [textStyles, {
209
- display: inline ? 'inline' : 'block',
210
- fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
211
- textAlign: align,
212
- textTransform: transform
213
- }]; // early exit for inline variant
214
-
215
- if (inline) {
216
- return /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
217
- as: as !== null && as !== void 0 ? as : 'span',
218
- data: data,
219
- ref: forwardedRef,
220
- id: id,
221
- className: css(styles),
222
- children: children
223
- }));
224
- } // prepare block variant
225
-
226
-
227
- var content = overflowStrategy ? /*#__PURE__*/jsx("span", {
228
- className: css(overflowStyles),
229
- children: children
230
- }) : children;
231
- var textContextValue = useMemo(function () {
232
- return {
233
- size: size,
234
- tone: tone,
235
- weight: weight
236
- };
237
- }, [size, tone, weight]);
238
- return /*#__PURE__*/jsx(TextContext.Provider, {
239
- value: textContextValue,
240
- children: /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
241
- as: as,
242
- data: data,
243
- ref: forwardedRef,
244
- id: id,
245
- className: css(styles),
246
- children: content
247
- }))
248
- });
249
- });
250
-
251
- export { DefaultTextPropsProvider, Strong, Text, createTextStyles, useDefaultTextProps, useForegroundTone, useOverflowStrategy, useText, useTextContext };