@tamagui/core 1.0.0-beta.4 → 1.0.0-beta.7
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/README.md +1 -0
- package/dist/cjs/createComponent.js +13 -5
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/helpers/addStylesUsingClassname.js +17 -12
- package/dist/cjs/helpers/addStylesUsingClassname.js.map +2 -2
- package/dist/cjs/helpers/createPropMapper.js +33 -3
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/fixNativeShadow.native.js +16 -12
- package/dist/cjs/helpers/fixNativeShadow.native.js.map +2 -2
- package/dist/cjs/helpers/getButtonSize.js +48 -0
- package/dist/cjs/helpers/getButtonSize.js.map +7 -0
- package/dist/cjs/helpers/getSplitStyles.js +0 -40
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getTextSize.js +56 -0
- package/dist/cjs/helpers/getTextSize.js.map +7 -0
- package/dist/cjs/helpers/insertStyleRule.js +1 -0
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/hooks/useId.js +59 -0
- package/dist/cjs/hooks/useId.js.map +7 -0
- package/dist/cjs/index.js +9 -6
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/views/Slot.js +115 -0
- package/dist/cjs/views/Slot.js.map +7 -0
- package/dist/esm/createComponent.js +12 -5
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/helpers/addStylesUsingClassname.js +18 -13
- package/dist/esm/helpers/addStylesUsingClassname.js.map +2 -2
- package/dist/esm/helpers/createPropMapper.js +34 -3
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/fixNativeShadow.native.js +16 -12
- package/dist/esm/helpers/fixNativeShadow.native.js.map +2 -2
- package/dist/esm/helpers/getButtonSize.js +27 -0
- package/dist/esm/helpers/getButtonSize.js.map +7 -0
- package/dist/esm/helpers/getSplitStyles.js +0 -41
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getTextSize.js +34 -0
- package/dist/esm/helpers/getTextSize.js.map +7 -0
- package/dist/esm/helpers/insertStyleRule.js +1 -0
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/hooks/useId.js +35 -0
- package/dist/esm/hooks/useId.js.map +7 -0
- package/dist/esm/index.js +9 -6
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/views/Slot.js +63 -0
- package/dist/esm/views/Slot.js.map +7 -0
- package/dist/jsx/createComponent.js +12 -5
- package/dist/jsx/helpers/addStylesUsingClassname.js +18 -13
- package/dist/jsx/helpers/createPropMapper.js +34 -3
- package/dist/jsx/helpers/fixNativeShadow.native.js +16 -12
- package/dist/jsx/helpers/getButtonSize.js +26 -0
- package/dist/jsx/helpers/getSplitStyles.js +0 -41
- package/dist/jsx/helpers/getTextSize.js +33 -0
- package/dist/jsx/helpers/insertStyleRule.js +1 -0
- package/dist/jsx/hooks/useId.js +34 -0
- package/dist/jsx/index.js +9 -6
- package/dist/jsx/views/Slot.js +56 -0
- package/package.json +5 -5
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/addStylesUsingClassname.d.ts.map +1 -1
- package/types/helpers/createPropMapper.d.ts +1 -1
- package/types/helpers/createPropMapper.d.ts.map +1 -1
- package/types/helpers/fixNativeShadow.native.d.ts +1 -1
- package/types/helpers/fixNativeShadow.native.d.ts.map +1 -1
- package/types/helpers/getButtonSize.d.ts +8 -0
- package/types/helpers/getButtonSize.d.ts.map +1 -0
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getTextSize.d.ts +3 -0
- package/types/helpers/getTextSize.d.ts.map +1 -0
- package/types/helpers/insertStyleRule.d.ts.map +1 -1
- package/types/hooks/useId.d.ts +9 -0
- package/types/hooks/useId.d.ts.map +1 -0
- package/types/index.d.ts +9 -6
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +19 -5
- package/types/types.d.ts.map +1 -1
- package/types/views/Slot.d.ts +9 -0
- package/types/views/Slot.d.ts.map +1 -0
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
const matchRgbaHsla = /(rgba|hsla)\(\s*([\d\.]{1,}%?)\s*,\s*([\d\.]{1,}%?)\s*,\s*([\d\.]{1,}%?)\s*,\s*([\d\.]{1,})\s*\)$/;
|
|
4
|
-
function fixNativeShadow(
|
|
5
|
-
|
|
4
|
+
function fixNativeShadow(styles) {
|
|
5
|
+
const color = styles.find((x) => x[0] === "shadowColor");
|
|
6
|
+
if (!color) {
|
|
6
7
|
return;
|
|
7
8
|
}
|
|
8
|
-
if (!
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
if (!styles.find((x) => x[0] === "shadowOffset")) {
|
|
10
|
+
styles.push([
|
|
11
|
+
"shadowOffset",
|
|
12
|
+
{
|
|
13
|
+
width: 0,
|
|
14
|
+
height: 0
|
|
15
|
+
}
|
|
16
|
+
]);
|
|
13
17
|
}
|
|
14
|
-
if ("shadowOpacity"
|
|
18
|
+
if (styles.find((x) => x[0] === "shadowOpacity")) {
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
17
|
-
const c = `${
|
|
21
|
+
const c = `${color[1]}`;
|
|
18
22
|
if ((c[0] === "r" || c[0] === "h") && c[3] === "a") {
|
|
19
23
|
const [_, type, _1, _2, _3, a] = c.match(matchRgbaHsla) || [];
|
|
20
24
|
if (typeof a !== "string") {
|
|
21
25
|
console.trace("invalid", c, type);
|
|
22
26
|
throw new Error(`invalid style`);
|
|
23
27
|
}
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
styles.push(["shadowColor", `${type.replace("a", "")}(${_1},${_2},${_3})`]);
|
|
29
|
+
styles.push(["shadowOpacity", +a]);
|
|
26
30
|
} else {
|
|
27
|
-
|
|
31
|
+
styles.push(["shadowOpacity", 1]);
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
__name(fixNativeShadow, "fixNativeShadow");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/fixNativeShadow.native.tsx"],
|
|
4
|
-
"sourcesContent": ["const matchRgbaHsla =\n /(rgba|hsla)\\(\\s*([\\d\\.]{1,}%?)\\s*,\\s*([\\d\\.]{1,}%?)\\s*,\\s*([\\d\\.]{1,}%?)\\s*,\\s*([\\d\\.]{1,})\\s*\\)$/\n\nexport function fixNativeShadow(
|
|
5
|
-
"mappings": ";;AAAA,MAAM,gBACJ;AAEK,yBAAyB,
|
|
4
|
+
"sourcesContent": ["const matchRgbaHsla =\n /(rgba|hsla)\\(\\s*([\\d\\.]{1,}%?)\\s*,\\s*([\\d\\.]{1,}%?)\\s*,\\s*([\\d\\.]{1,}%?)\\s*,\\s*([\\d\\.]{1,})\\s*\\)$/\n\nexport function fixNativeShadow(styles: [string, any][]) {\n const color = styles.find((x) => x[0] === 'shadowColor')\n if (!color) {\n return\n }\n if (!styles.find((x) => x[0] === 'shadowOffset')) {\n // fixes some broken shadows\n styles.push([\n 'shadowOffset',\n {\n width: 0,\n height: 0,\n },\n ])\n }\n if (styles.find((x) => x[0] === 'shadowOpacity')) {\n return\n }\n const c = `${color[1]}`\n // react native has issues sometimes with rgba()\n // supports rgba + hsla\n if ((c[0] === 'r' || c[0] === 'h') && c[3] === 'a') {\n const [_, type, _1, _2, _3, a] = c.match(matchRgbaHsla) || []\n if (typeof a !== 'string') {\n console.trace('invalid', c, type)\n throw new Error(`invalid style`)\n }\n styles.push(['shadowColor', `${type.replace('a', '')}(${_1},${_2},${_3})`])\n styles.push(['shadowOpacity', +a])\n } else {\n styles.push(['shadowOpacity', 1])\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,MAAM,gBACJ;AAEK,yBAAyB,QAAyB;AACvD,QAAM,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,OAAO,aAAa;AACvD,MAAI,CAAC,OAAO;AACV;AAAA,EACF;AACA,MAAI,CAAC,OAAO,KAAK,CAAC,MAAM,EAAE,OAAO,cAAc,GAAG;AAEhD,WAAO,KAAK;AAAA,MACV;AAAA,MACA;AAAA,QACE,OAAO;AAAA,QACP,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH;AACA,MAAI,OAAO,KAAK,CAAC,MAAM,EAAE,OAAO,eAAe,GAAG;AAChD;AAAA,EACF;AACA,QAAM,IAAI,GAAG,MAAM;AAGnB,MAAK,GAAE,OAAO,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO,KAAK;AAClD,UAAM,CAAC,GAAG,MAAM,IAAI,IAAI,IAAI,KAAK,EAAE,MAAM,aAAa,KAAK,CAAC;AAC5D,QAAI,OAAO,MAAM,UAAU;AACzB,cAAQ,MAAM,WAAW,GAAG,IAAI;AAChC,YAAM,IAAI,MAAM,eAAe;AAAA,IACjC;AACA,WAAO,KAAK,CAAC,eAAe,GAAG,KAAK,QAAQ,KAAK,EAAE,KAAK,MAAM,MAAM,KAAK,CAAC;AAC1E,WAAO,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAAA,EACnC,OAAO;AACL,WAAO,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAAA,EAClC;AACF;AAhCgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { getVariableValue, isVariable } from "@tamagui/core";
|
|
4
|
+
const getButtonSize = /* @__PURE__ */ __name((sizeX = 0.9, sizeY = 0.333) => (val, { tokens, props, fonts }) => {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6
|
+
const size = (_c = (_b = (_a = tokens.size[val]) != null ? _a : tokens.size["$4"]) != null ? _b : val) != null ? _c : 14;
|
|
7
|
+
const radius = (_e = (_d = tokens.radius[val]) != null ? _d : tokens.radius["$4"]) != null ? _e : size;
|
|
8
|
+
const px = Math.round(+(isVariable(size) ? size.val : size) * sizeX);
|
|
9
|
+
const py = Math.round(+(isVariable(size) ? size.val : size) * sizeY);
|
|
10
|
+
const font = fonts[props.fontFamily] || fonts["$body"];
|
|
11
|
+
const lineHeights = font.lineHeight;
|
|
12
|
+
const lineHeight = (_f = lineHeights[val]) != null ? _f : lineHeights["$4"];
|
|
13
|
+
const minHeight = Math.round(getVariableValue(lineHeight) + py * 2);
|
|
14
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
15
|
+
console.log("getButtonSize", props.fontFamily, { size, py, val, lineHeight, minHeight });
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
minHeight,
|
|
19
|
+
paddingHorizontal: props.circular ? 0 : px,
|
|
20
|
+
paddingVertical: props.circular ? 0 : py,
|
|
21
|
+
borderRadius: props.circular ? 1e5 : (_g = props.borderRadius) != null ? _g : radius
|
|
22
|
+
};
|
|
23
|
+
}, "getButtonSize");
|
|
24
|
+
export {
|
|
25
|
+
getButtonSize
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=getButtonSize.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/getButtonSize.ts"],
|
|
4
|
+
"sourcesContent": ["import { VariantSpreadExtras, getVariableValue, isVariable } from '@tamagui/core'\n\n// for use in button-like things\n\nexport const getButtonSize =\n (sizeX = 0.9, sizeY = 0.333) =>\n (val: any, { tokens, props, fonts }: VariantSpreadExtras<any>) => {\n const size = tokens.size[val] ?? tokens.size['$4'] ?? val ?? 14\n const radius = tokens.radius[val] ?? tokens.radius['$4'] ?? size\n const px = Math.round(+(isVariable(size) ? size.val : size) * sizeX)\n const py = Math.round(+(isVariable(size) ? size.val : size) * sizeY)\n // keep buttons height aligned to the font used\n const font = fonts[props.fontFamily] || fonts['$body']\n const lineHeights = font.lineHeight\n const lineHeight = lineHeights[val] ?? lineHeights['$4']\n const minHeight = Math.round(getVariableValue(lineHeight) + py * 2)\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log('getButtonSize', props.fontFamily, { size, py, val, lineHeight, minHeight })\n }\n return {\n minHeight,\n paddingHorizontal: props.circular ? 0 : px,\n paddingVertical: props.circular ? 0 : py,\n borderRadius: props.circular ? 100_000 : props.borderRadius ?? radius,\n }\n }\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAIO,MAAM,gBACX,wBAAC,QAAQ,KAAK,QAAQ,UACtB,CAAC,KAAU,EAAE,QAAQ,OAAO,YAAsC;AANpE;AAOI,QAAM,OAAO,yBAAO,KAAK,SAAZ,YAAoB,OAAO,KAAK,UAAhC,YAAyC,QAAzC,YAAgD;AAC7D,QAAM,SAAS,mBAAO,OAAO,SAAd,YAAsB,OAAO,OAAO,UAApC,YAA6C;AAC5D,QAAM,KAAK,KAAK,MAAM,CAAE,YAAW,IAAI,IAAI,KAAK,MAAM,QAAQ,KAAK;AACnE,QAAM,KAAK,KAAK,MAAM,CAAE,YAAW,IAAI,IAAI,KAAK,MAAM,QAAQ,KAAK;AAEnE,QAAM,OAAO,MAAM,MAAM,eAAe,MAAM;AAC9C,QAAM,cAAc,KAAK;AACzB,QAAM,aAAa,kBAAY,SAAZ,YAAoB,YAAY;AACnD,QAAM,YAAY,KAAK,MAAM,iBAAiB,UAAU,IAAI,KAAK,CAAC;AAClE,MAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAC5D,YAAQ,IAAI,iBAAiB,MAAM,YAAY,EAAE,MAAM,IAAI,KAAK,YAAY,UAAU,CAAC;AAAA,EACzF;AACA,SAAO;AAAA,IACL;AAAA,IACA,mBAAmB,MAAM,WAAW,IAAI;AAAA,IACxC,iBAAiB,MAAM,WAAW,IAAI;AAAA,IACtC,cAAc,MAAM,WAAW,MAAU,YAAM,iBAAN,YAAsB;AAAA,EACjE;AACF,GApBA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -288,47 +288,6 @@ const getSubStyle = /* @__PURE__ */ __name((styleIn, staticConfig, theme, props,
|
|
|
288
288
|
return styleOut;
|
|
289
289
|
}, "getSubStyle");
|
|
290
290
|
function normalizeStyleObject(style) {
|
|
291
|
-
var _a, _b;
|
|
292
|
-
if (style.padding) {
|
|
293
|
-
style.paddingLeft = style.padding;
|
|
294
|
-
style.paddingTop = style.padding;
|
|
295
|
-
style.paddingRight = style.padding;
|
|
296
|
-
style.paddingBottom = style.padding;
|
|
297
|
-
delete style.padding;
|
|
298
|
-
}
|
|
299
|
-
if (style.paddingHorizontal) {
|
|
300
|
-
style.paddingLeft = style.paddingHorizontal;
|
|
301
|
-
style.paddingRight = style.paddingHorizontal;
|
|
302
|
-
delete style.paddingHorizontal;
|
|
303
|
-
}
|
|
304
|
-
if (style.paddingVertical) {
|
|
305
|
-
style.paddingLeft = style.paddingVertical;
|
|
306
|
-
style.paddingRight = style.paddingVertical;
|
|
307
|
-
delete style.paddingVertical;
|
|
308
|
-
}
|
|
309
|
-
if (style.margin) {
|
|
310
|
-
style.marginLeft = style.margin;
|
|
311
|
-
style.marginTop = style.margin;
|
|
312
|
-
style.marginRight = style.margin;
|
|
313
|
-
style.marginBottom = style.margin;
|
|
314
|
-
delete style.margin;
|
|
315
|
-
}
|
|
316
|
-
if (style.marginHorizontal) {
|
|
317
|
-
style.marginLeft = style.marginHorizontal;
|
|
318
|
-
style.marginRight = style.marginHorizontal;
|
|
319
|
-
delete style.marginHorizontal;
|
|
320
|
-
}
|
|
321
|
-
if (style.marginVertical) {
|
|
322
|
-
style.marginLeft = style.marginVertical;
|
|
323
|
-
style.marginRight = style.marginVertical;
|
|
324
|
-
delete style.marginVertical;
|
|
325
|
-
}
|
|
326
|
-
if (typeof style.flex === "number") {
|
|
327
|
-
const val = style.flex;
|
|
328
|
-
delete style.flex;
|
|
329
|
-
style.flexGrow = (_a = style.flexGrow) != null ? _a : val;
|
|
330
|
-
style.flexShrink = (_b = style.flexShrink) != null ? _b : 1;
|
|
331
|
-
}
|
|
332
291
|
if (!isWeb) {
|
|
333
292
|
fixNativeShadow(style);
|
|
334
293
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/getSplitStyles.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n mergeTransform,\n stylePropsText,\n stylePropsTransform,\n validPseudoKeys,\n validStyles,\n} from '@tamagui/helpers'\n// @ts-ignore\nimport { useInsertionEffect } from 'react'\nimport { ViewStyle } from 'react-native'\n\nimport { getConfig } from '../conf'\nimport { isClient, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { mediaQueryConfig, mediaState } from '../hooks/useMedia'\nimport {\n MediaKeys,\n MediaQueryKey,\n PseudoStyles,\n PsuedoPropKeys,\n SplitStyleState,\n StackProps,\n StaticConfigParsed,\n TamaguiInternalConfig,\n ThemeObject,\n} from '../types'\nimport { createMediaStyle } from './createMediaStyle'\nimport { fixNativeShadow } from './fixNativeShadow'\nimport { ViewStyleWithPseudos, getStylesAtomic } from './getStylesAtomic'\nimport {\n insertStyleRule,\n insertedTransforms,\n updateInserted,\n updateInsertedCache,\n} from './insertStyleRule'\n\nexport type SplitStyles = ReturnType<typeof getSplitStyles>\nexport type ClassNamesObject = Record<string, string>\nexport type SplitStyleResult = ReturnType<typeof getSplitStyles>\n\nconst skipProps = {\n animation: true,\n animateOnly: true,\n debug: true,\n}\n\ntype TransformNamespaceKey = 'transform' | PsuedoPropKeys | MediaQueryKey\n\n// TODO can make a few of these objects lazy if profiling seems slow\n\nlet conf: TamaguiInternalConfig\n\ntype StyleSplitter = (\n props: { [key: string]: any },\n staticConfig: StaticConfigParsed,\n theme: ThemeObject,\n state: SplitStyleState & {\n keepVariantsAsProps?: boolean\n },\n defaultClassNames?: any\n) => {\n pseudos: PseudoStyles\n medias: Record<MediaKeys, ViewStyle>\n style: ViewStyle\n classNames: ClassNamesObject\n rulesToInsert: [string, string][]\n viewProps: StackProps\n}\n\nexport const getSplitStyles: StyleSplitter = (\n props,\n staticConfig,\n theme,\n state,\n defaultClassNames\n) => {\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles', { props, state, defaultClassNames })\n }\n\n conf = conf || getConfig()\n const validStyleProps = staticConfig.isText ? stylePropsText : validStyles\n const viewProps: StackProps = {}\n const style: ViewStyle = {}\n const classNames: ClassNamesObject = {\n ...defaultClassNames,\n }\n const pseudos: PseudoStyles = {}\n const medias: Record<MediaKeys, ViewStyle> = {}\n\n const rulesToInsert: [string, string][] = []\n function addStyle(prop: string, rule: string) {\n rulesToInsert.push([prop, rule])\n updateInsertedCache(prop, rule)\n }\n\n let cur: ViewStyleWithPseudos | null = null\n\n // we need to gather these specific to each media query / pseudo\n // value is [hash, val], so [\"-jnjad-asdnjk\", \"scaleX(1) rotate(10deg)\"]\n let transforms: Record<TransformNamespaceKey, [string, string]> = {}\n\n function mergeClassName(key: string, val: string) {\n if (!val) {\n // empty classnames passed by compiler sometimes\n return\n }\n if (val.startsWith('_transform-')) {\n const isMediaOrPseudo = key !== 'transform'\n const isMedia = isMediaOrPseudo && key[11] === '_'\n const isPsuedo = (isMediaOrPseudo && key[11] === '0') || key.endsWith('Style')\n const namespace: TransformNamespaceKey = isMedia\n ? key.split('_')[2]\n : isPsuedo\n ? key.split('-')[1]\n : 'transform'\n\n let transform = insertedTransforms[val]\n if (isClient) {\n if (!transform) {\n // HMR or loaded a new chunk\n updateInserted()\n transform = insertedTransforms[val]\n }\n if (!transform) {\n if (isWeb && val[0] !== '_') {\n // runtime insert\n transform = val\n } else {\n // error\n console.trace('?', key, val, cur, props, state)\n }\n }\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n // prettier-ignore\n console.log(' \u00BB getSplitStyles mergeClassName transform', { key, val, namespace, transform, insertedTransforms })\n }\n if (process.env.NODE_ENV === 'development') {\n if (!transform) {\n console.trace('NO TRANSFORM?', { key, val, transform })\n }\n }\n }\n transforms[namespace] = transforms[namespace] || ['', '']\n const identifier = val.replace('_transform', '')\n transforms[namespace][0] += identifier\n // ssr doesn't need to do anything just make the right classname\n if (transform) {\n transforms[namespace][1] += transform\n }\n } else {\n classNames[key] = val\n }\n }\n\n function push() {\n if (!cur) return\n normalizeStyleObject(cur)\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles push', cur, state)\n }\n\n if (isWeb && !state.noClassNames) {\n const atomic = getStylesAtomic(cur)\n for (const atomicStyle of atomic) {\n if (!state.noClassNames) {\n addStyle(atomicStyle.identifier, atomicStyle.rules[0])\n mergeClassName(atomicStyle.property, atomicStyle.identifier)\n } else {\n style[atomicStyle.property] = atomicStyle.value\n }\n }\n }\n\n if (\n !isWeb ||\n state.noClassNames ||\n state.resolveVariablesAs === 'value' ||\n state.resolveVariablesAs === 'both'\n ) {\n for (const key in cur) {\n if (key in stylePropsTransform) {\n mergeTransform(style, key, cur[key])\n } else {\n style[key] = cur[key]\n }\n }\n }\n\n // reset it for next group of styles\n cur = null\n }\n\n for (const keyInit in props) {\n if (skipProps[keyInit]) {\n continue\n }\n\n const valInit = props[keyInit]\n\n // TODO\n if (keyInit === 'style' || keyInit.startsWith('_style')) {\n push()\n cur = valInit\n push()\n continue\n }\n\n if (keyInit === 'className' || (validStyleProps[keyInit] && valInit && valInit[0] === '_')) {\n push()\n mergeClassName(keyInit, valInit)\n continue\n }\n\n if (\n state.keepVariantsAsProps &&\n staticConfig.defaultVariants &&\n keyInit in staticConfig.defaultVariants\n ) {\n viewProps[keyInit] = valInit\n }\n\n let isMedia = keyInit[0] === '$'\n let isPseudo = validPseudoKeys[keyInit]\n\n if (\n !isMedia &&\n !isPseudo &&\n !staticConfig.variants?.[keyInit] &&\n !validStyleProps[keyInit] &&\n !conf.shorthands[keyInit]\n ) {\n viewProps[keyInit] = valInit\n continue\n }\n\n const out =\n isMedia || isPseudo\n ? true\n : staticConfig.propMapper(\n keyInit,\n valInit,\n theme,\n state.fallbackProps || props,\n state.resolveVariablesAs\n )\n\n const expanded = out === true || !out ? [[keyInit, valInit]] : Object.entries(out)\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles', keyInit, expanded)\n }\n\n for (const [key, val] of expanded) {\n if (val === undefined) {\n continue\n }\n\n if (key !== 'target' && val && val[0] === '_') {\n mergeClassName(key, val)\n continue\n }\n\n isMedia = key[0] === '$'\n isPseudo = validPseudoKeys[key]\n\n if (\n (staticConfig.deoptProps && staticConfig.deoptProps.has(key)) ||\n (staticConfig.inlineProps && staticConfig.inlineProps.has(key))\n ) {\n viewProps[key] = val\n }\n\n // pseudo\n if (isPseudo) {\n if (!val) continue\n if (key === 'enterStyle' && state.mounted) {\n // once mounted we can ignore enterStyle\n continue\n }\n pseudos[key] = pseudos[key] || {}\n pseudos[key] = getSubStyle(val, staticConfig, theme, props, state, true)\n if (isWeb && !state.noClassNames) {\n const pseudoStyles = getStylesAtomic({ [key]: pseudos[key] })\n for (const style of pseudoStyles) {\n addStyle(style.identifier, style.rules[0])\n mergeClassName(`${style.property}-${key}`, style.identifier)\n }\n }\n continue\n }\n\n // media\n if (isMedia) {\n const mediaKey = key\n const mediaKeyShort = mediaKey.slice(1)\n\n if (!mediaQueryConfig[mediaKeyShort]) {\n // this isn't a media key, pass through\n viewProps[key] = val\n continue\n }\n\n // dont check if media is active, we just apply *all* media styles\n // we combine the media props on top regular props, could proxy this\n // TODO test proxy here instead of merge\n // THIS USED TO PROXY BACK TO REGULAR PROPS BUT THAT IS THE WRONG BEHAVIOR\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n const mediaStyle = getSubStyle(val, staticConfig, theme, props, state)\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles mediaStyle', mediaKey, mediaStyle, props)\n }\n\n const shouldDoClasses = isWeb && !state.noClassNames\n if (shouldDoClasses) {\n const mediaStyles = getStylesAtomic(mediaStyle)\n for (const style of mediaStyles) {\n const out = createMediaStyle(style, mediaKeyShort, mediaQueryConfig)\n addStyle(out.identifier, out.styleRule)\n mergeClassName(`${out.identifier}-${mediaKey}`, out.identifier)\n }\n } else {\n if (mediaState[mediaKey]) {\n push()\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log('apply media style', mediaKey, mediaState)\n }\n Object.assign(shouldDoClasses ? medias : style, mediaStyle)\n }\n }\n continue\n }\n\n if (!isWeb && key === 'pointerEvents') {\n viewProps[key] = val\n continue\n }\n\n if (validStyleProps[key]) {\n cur = cur || {}\n cur[key] = val\n continue\n }\n\n // pass to view props\n if (!staticConfig.variants || !(key in staticConfig.variants)) {\n if (key !== 'animation' && key !== 'debug') {\n push()\n viewProps[key] = val\n }\n }\n }\n }\n\n push()\n\n if (transforms) {\n for (const namespace in transforms) {\n const [hash, val] = transforms[namespace]\n const identifier = `_transform${hash}`\n if (isClient) {\n if (!insertedTransforms[identifier]) {\n const rule = `.${identifier} { transform: ${val}; }`\n addStyle(identifier, rule)\n }\n }\n classNames[namespace] = identifier\n }\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles out', { style, pseudos, medias, classNames, viewProps, state })\n }\n\n return {\n viewProps,\n style,\n medias,\n pseudos,\n classNames,\n rulesToInsert,\n }\n}\n\nexport const insertSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n for (const [prop, rule] of res.rulesToInsert) {\n insertStyleRule(prop, rule)\n }\n return res\n}\n\nconst effect = useInsertionEffect || useIsomorphicLayoutEffect\nexport const useSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n effect(() => {\n for (const [prop, rule] of res.rulesToInsert) {\n insertStyleRule(prop, rule)\n }\n })\n return res\n}\n\nexport const getSubStyle = (\n styleIn: Object,\n staticConfig: StaticConfigParsed,\n theme: ThemeObject,\n props: any,\n state: SplitStyleState,\n avoidDefaultProps?: boolean\n): ViewStyle => {\n const styleOut: ViewStyle = {}\n for (const key in styleIn) {\n const val = styleIn[key]\n const out = staticConfig.propMapper(\n key,\n val,\n theme,\n state.fallbackProps || props,\n state.resolveVariablesAs,\n avoidDefaultProps\n )\n const expanded = out === true || !out ? [[key, val]] : Object.entries(out)\n for (const [skey, sval] of expanded) {\n if (skey in stylePropsTransform) {\n mergeTransform(styleOut, skey, sval)\n } else {\n styleOut[skey] = sval\n }\n }\n }\n normalizeStyleObject(styleOut)\n return styleOut\n}\n\nexport function normalizeStyleObject(style: any) {\n // TODO move to our own atomic css generation and remove this along with getStylesAtomic\n // fix padding expand i know this exists in rnw but it doesnt expand base padding\n if (style.padding) {\n style.paddingLeft = style.padding\n style.paddingTop = style.padding\n style.paddingRight = style.padding\n style.paddingBottom = style.padding\n delete style.padding\n }\n\n if (style.paddingHorizontal) {\n style.paddingLeft = style.paddingHorizontal\n style.paddingRight = style.paddingHorizontal\n delete style.paddingHorizontal\n }\n\n if (style.paddingVertical) {\n style.paddingLeft = style.paddingVertical\n style.paddingRight = style.paddingVertical\n delete style.paddingVertical\n }\n\n if (style.margin) {\n style.marginLeft = style.margin\n style.marginTop = style.margin\n style.marginRight = style.margin\n style.marginBottom = style.margin\n delete style.margin\n }\n\n if (style.marginHorizontal) {\n style.marginLeft = style.marginHorizontal\n style.marginRight = style.marginHorizontal\n delete style.marginHorizontal\n }\n\n if (style.marginVertical) {\n style.marginLeft = style.marginVertical\n style.marginRight = style.marginVertical\n delete style.marginVertical\n }\n\n // fix flex to match web\n // see spec for flex shorthand https://developer.mozilla.org/en-US/docs/Web/CSS/flex\n if (typeof style.flex === 'number') {\n const val = style.flex\n delete style.flex\n style.flexGrow = style.flexGrow ?? val\n style.flexShrink = style.flexShr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A6TtC,MAAM,oBAAmC,2BAAI,SAAS;AAC3D,QAAM,MAAM,eAAe,GAAG,IAAI;AAClC,aAAW,CAAC,MAAM,SAAS,IAAI,eAAe;AAC5C,oBAAgB,MAAM,IAAI;AAAA,EAC5B;AACA,SAAO;AACT,GANgD;AAQhD,MAAM,SAAS,sBAAsB;AAC9B,MAAM,iBAAgC,2BAAI,SAAS;AACxD,QAAM,MAAM,eAAe,GAAG,IAAI;AAClC,SAAO,MAAM;AACX,eAAW,CAAC,MAAM,SAAS,IAAI,eAAe;AAC5C,sBAAgB,MAAM,IAAI;AAAA,IAC5B;AAAA,EACF,CAAC;AACD,SAAO;AACT,GAR6C;AAUtC,MAAM,cAAc,wBACzB,SACA,cACA,OACA,OACA,OACA,sBACc;AACd,QAAM,WAAsB,CAAC;AAC7B,aAAW,OAAO,SAAS;AACzB,UAAM,MAAM,QAAQ;AACpB,UAAM,MAAM,aAAa,WACvB,KACA,KACA,OACA,MAAM,iBAAiB,OACvB,MAAM,oBACN,iBACF;AACA,UAAM,WAAW,QAAQ,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,OAAO,QAAQ,GAAG;AACzE,eAAW,CAAC,MAAM,SAAS,UAAU;AACnC,UAAI,QAAQ,qBAAqB;AAC/B,uBAAe,UAAU,MAAM,IAAI;AAAA,MACrC,OAAO;AACL,iBAAS,QAAQ;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACA,uBAAqB,QAAQ;AAC7B,SAAO;AACT,GA9B2B;AAgCpB,8BAA8B,OAAY;
|
|
4
|
+
"sourcesContent": ["import {\n mergeTransform,\n stylePropsText,\n stylePropsTransform,\n validPseudoKeys,\n validStyles,\n} from '@tamagui/helpers'\n// @ts-ignore\nimport { useInsertionEffect } from 'react'\nimport { ViewStyle } from 'react-native'\n\nimport { getConfig } from '../conf'\nimport { isClient, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { mediaQueryConfig, mediaState } from '../hooks/useMedia'\nimport {\n MediaKeys,\n MediaQueryKey,\n PseudoStyles,\n PsuedoPropKeys,\n SplitStyleState,\n StackProps,\n StaticConfigParsed,\n TamaguiInternalConfig,\n ThemeObject,\n} from '../types'\nimport { createMediaStyle } from './createMediaStyle'\nimport { fixNativeShadow } from './fixNativeShadow'\nimport { ViewStyleWithPseudos, getStylesAtomic } from './getStylesAtomic'\nimport {\n insertStyleRule,\n insertedTransforms,\n updateInserted,\n updateInsertedCache,\n} from './insertStyleRule'\n\nexport type SplitStyles = ReturnType<typeof getSplitStyles>\nexport type ClassNamesObject = Record<string, string>\nexport type SplitStyleResult = ReturnType<typeof getSplitStyles>\n\nconst skipProps = {\n animation: true,\n animateOnly: true,\n debug: true,\n}\n\ntype TransformNamespaceKey = 'transform' | PsuedoPropKeys | MediaQueryKey\n\n// TODO can make a few of these objects lazy if profiling seems slow\n\nlet conf: TamaguiInternalConfig\n\ntype StyleSplitter = (\n props: { [key: string]: any },\n staticConfig: StaticConfigParsed,\n theme: ThemeObject,\n state: SplitStyleState & {\n keepVariantsAsProps?: boolean\n },\n defaultClassNames?: any\n) => {\n pseudos: PseudoStyles\n medias: Record<MediaKeys, ViewStyle>\n style: ViewStyle\n classNames: ClassNamesObject\n rulesToInsert: [string, string][]\n viewProps: StackProps\n}\n\nexport const getSplitStyles: StyleSplitter = (\n props,\n staticConfig,\n theme,\n state,\n defaultClassNames\n) => {\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles', { props, state, defaultClassNames })\n }\n\n conf = conf || getConfig()\n const validStyleProps = staticConfig.isText ? stylePropsText : validStyles\n const viewProps: StackProps = {}\n const style: ViewStyle = {}\n const classNames: ClassNamesObject = {\n ...defaultClassNames,\n }\n const pseudos: PseudoStyles = {}\n const medias: Record<MediaKeys, ViewStyle> = {}\n\n const rulesToInsert: [string, string][] = []\n function addStyle(prop: string, rule: string) {\n rulesToInsert.push([prop, rule])\n updateInsertedCache(prop, rule)\n }\n\n let cur: ViewStyleWithPseudos | null = null\n\n // we need to gather these specific to each media query / pseudo\n // value is [hash, val], so [\"-jnjad-asdnjk\", \"scaleX(1) rotate(10deg)\"]\n let transforms: Record<TransformNamespaceKey, [string, string]> = {}\n\n function mergeClassName(key: string, val: string) {\n if (!val) {\n // empty classnames passed by compiler sometimes\n return\n }\n if (val.startsWith('_transform-')) {\n const isMediaOrPseudo = key !== 'transform'\n const isMedia = isMediaOrPseudo && key[11] === '_'\n const isPsuedo = (isMediaOrPseudo && key[11] === '0') || key.endsWith('Style')\n const namespace: TransformNamespaceKey = isMedia\n ? key.split('_')[2]\n : isPsuedo\n ? key.split('-')[1]\n : 'transform'\n\n let transform = insertedTransforms[val]\n if (isClient) {\n if (!transform) {\n // HMR or loaded a new chunk\n updateInserted()\n transform = insertedTransforms[val]\n }\n if (!transform) {\n if (isWeb && val[0] !== '_') {\n // runtime insert\n transform = val\n } else {\n // error\n console.trace('?', key, val, cur, props, state)\n }\n }\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n // prettier-ignore\n console.log(' \u00BB getSplitStyles mergeClassName transform', { key, val, namespace, transform, insertedTransforms })\n }\n if (process.env.NODE_ENV === 'development') {\n if (!transform) {\n console.trace('NO TRANSFORM?', { key, val, transform })\n }\n }\n }\n transforms[namespace] = transforms[namespace] || ['', '']\n const identifier = val.replace('_transform', '')\n transforms[namespace][0] += identifier\n // ssr doesn't need to do anything just make the right classname\n if (transform) {\n transforms[namespace][1] += transform\n }\n } else {\n classNames[key] = val\n }\n }\n\n function push() {\n if (!cur) return\n normalizeStyleObject(cur)\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles push', cur, state)\n }\n\n if (isWeb && !state.noClassNames) {\n const atomic = getStylesAtomic(cur)\n for (const atomicStyle of atomic) {\n if (!state.noClassNames) {\n addStyle(atomicStyle.identifier, atomicStyle.rules[0])\n mergeClassName(atomicStyle.property, atomicStyle.identifier)\n } else {\n style[atomicStyle.property] = atomicStyle.value\n }\n }\n }\n\n if (\n !isWeb ||\n state.noClassNames ||\n state.resolveVariablesAs === 'value' ||\n state.resolveVariablesAs === 'both'\n ) {\n for (const key in cur) {\n if (key in stylePropsTransform) {\n mergeTransform(style, key, cur[key])\n } else {\n style[key] = cur[key]\n }\n }\n }\n\n // reset it for next group of styles\n cur = null\n }\n\n for (const keyInit in props) {\n if (skipProps[keyInit]) {\n continue\n }\n\n const valInit = props[keyInit]\n\n // TODO\n if (keyInit === 'style' || keyInit.startsWith('_style')) {\n push()\n cur = valInit\n push()\n continue\n }\n\n if (keyInit === 'className' || (validStyleProps[keyInit] && valInit && valInit[0] === '_')) {\n push()\n mergeClassName(keyInit, valInit)\n continue\n }\n\n if (\n state.keepVariantsAsProps &&\n staticConfig.defaultVariants &&\n keyInit in staticConfig.defaultVariants\n ) {\n viewProps[keyInit] = valInit\n }\n\n let isMedia = keyInit[0] === '$'\n let isPseudo = validPseudoKeys[keyInit]\n\n if (\n !isMedia &&\n !isPseudo &&\n !staticConfig.variants?.[keyInit] &&\n !validStyleProps[keyInit] &&\n !conf.shorthands[keyInit]\n ) {\n viewProps[keyInit] = valInit\n continue\n }\n\n const out =\n isMedia || isPseudo\n ? true\n : staticConfig.propMapper(\n keyInit,\n valInit,\n theme,\n state.fallbackProps || props,\n state.resolveVariablesAs\n )\n\n const expanded = out === true || !out ? [[keyInit, valInit]] : Object.entries(out)\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles', keyInit, expanded)\n }\n\n for (const [key, val] of expanded) {\n if (val === undefined) {\n continue\n }\n\n if (key !== 'target' && val && val[0] === '_') {\n mergeClassName(key, val)\n continue\n }\n\n isMedia = key[0] === '$'\n isPseudo = validPseudoKeys[key]\n\n if (\n (staticConfig.deoptProps && staticConfig.deoptProps.has(key)) ||\n (staticConfig.inlineProps && staticConfig.inlineProps.has(key))\n ) {\n viewProps[key] = val\n }\n\n // pseudo\n if (isPseudo) {\n if (!val) continue\n if (key === 'enterStyle' && state.mounted) {\n // once mounted we can ignore enterStyle\n continue\n }\n pseudos[key] = pseudos[key] || {}\n pseudos[key] = getSubStyle(val, staticConfig, theme, props, state, true)\n if (isWeb && !state.noClassNames) {\n const pseudoStyles = getStylesAtomic({ [key]: pseudos[key] })\n for (const style of pseudoStyles) {\n addStyle(style.identifier, style.rules[0])\n mergeClassName(`${style.property}-${key}`, style.identifier)\n }\n }\n continue\n }\n\n // media\n if (isMedia) {\n const mediaKey = key\n const mediaKeyShort = mediaKey.slice(1)\n\n if (!mediaQueryConfig[mediaKeyShort]) {\n // this isn't a media key, pass through\n viewProps[key] = val\n continue\n }\n\n // dont check if media is active, we just apply *all* media styles\n // we combine the media props on top regular props, could proxy this\n // TODO test proxy here instead of merge\n // THIS USED TO PROXY BACK TO REGULAR PROPS BUT THAT IS THE WRONG BEHAVIOR\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n const mediaStyle = getSubStyle(val, staticConfig, theme, props, state)\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles mediaStyle', mediaKey, mediaStyle, props)\n }\n\n const shouldDoClasses = isWeb && !state.noClassNames\n if (shouldDoClasses) {\n const mediaStyles = getStylesAtomic(mediaStyle)\n for (const style of mediaStyles) {\n const out = createMediaStyle(style, mediaKeyShort, mediaQueryConfig)\n addStyle(out.identifier, out.styleRule)\n mergeClassName(`${out.identifier}-${mediaKey}`, out.identifier)\n }\n } else {\n if (mediaState[mediaKey]) {\n push()\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log('apply media style', mediaKey, mediaState)\n }\n Object.assign(shouldDoClasses ? medias : style, mediaStyle)\n }\n }\n continue\n }\n\n if (!isWeb && key === 'pointerEvents') {\n viewProps[key] = val\n continue\n }\n\n if (validStyleProps[key]) {\n cur = cur || {}\n cur[key] = val\n continue\n }\n\n // pass to view props\n if (!staticConfig.variants || !(key in staticConfig.variants)) {\n if (key !== 'animation' && key !== 'debug') {\n push()\n viewProps[key] = val\n }\n }\n }\n }\n\n push()\n\n if (transforms) {\n for (const namespace in transforms) {\n const [hash, val] = transforms[namespace]\n const identifier = `_transform${hash}`\n if (isClient) {\n if (!insertedTransforms[identifier]) {\n const rule = `.${identifier} { transform: ${val}; }`\n addStyle(identifier, rule)\n }\n }\n classNames[namespace] = identifier\n }\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug'] === 'verbose') {\n console.log(' \u00BB getSplitStyles out', { style, pseudos, medias, classNames, viewProps, state })\n }\n\n return {\n viewProps,\n style,\n medias,\n pseudos,\n classNames,\n rulesToInsert,\n }\n}\n\nexport const insertSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n for (const [prop, rule] of res.rulesToInsert) {\n insertStyleRule(prop, rule)\n }\n return res\n}\n\nconst effect = useInsertionEffect || useIsomorphicLayoutEffect\nexport const useSplitStyles: StyleSplitter = (...args) => {\n const res = getSplitStyles(...args)\n effect(() => {\n for (const [prop, rule] of res.rulesToInsert) {\n insertStyleRule(prop, rule)\n }\n })\n return res\n}\n\nexport const getSubStyle = (\n styleIn: Object,\n staticConfig: StaticConfigParsed,\n theme: ThemeObject,\n props: any,\n state: SplitStyleState,\n avoidDefaultProps?: boolean\n): ViewStyle => {\n const styleOut: ViewStyle = {}\n for (const key in styleIn) {\n const val = styleIn[key]\n const out = staticConfig.propMapper(\n key,\n val,\n theme,\n state.fallbackProps || props,\n state.resolveVariablesAs,\n avoidDefaultProps\n )\n const expanded = out === true || !out ? [[key, val]] : Object.entries(out)\n for (const [skey, sval] of expanded) {\n if (skey in stylePropsTransform) {\n mergeTransform(styleOut, skey, sval)\n } else {\n styleOut[skey] = sval\n }\n }\n }\n normalizeStyleObject(styleOut)\n return styleOut\n}\n\nexport function normalizeStyleObject(style: any) {\n if (!isWeb) {\n fixNativeShadow(style)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AAe;AAC5C,oBAAgB,MAAM,IAAI;AAAA,EAC5B;AACA,SAAO;AACT,GANgD;AAQhD,MAAM,SAAS,sBAAsB;AAC9B,MAAM,iBAAgC,2BAAI,SAAS;AACxD,QAAM,MAAM,eAAe,GAAG,IAAI;AAClC,SAAO,MAAM;AACX,eAAW,CAAC,MAAM,SAAS,IAAI,eAAe;AAC5C,sBAAgB,MAAM,IAAI;AAAA,IAC5B;AAAA,EACF,CAAC;AACD,SAAO;AACT,GAR6C;AAUtC,MAAM,cAAc,wBACzB,SACA,cACA,OACA,OACA,OACA,sBACc;AACd,QAAM,WAAsB,CAAC;AAC7B,aAAW,OAAO,SAAS;AACzB,UAAM,MAAM,QAAQ;AACpB,UAAM,MAAM,aAAa,WACvB,KACA,KACA,OACA,MAAM,iBAAiB,OACvB,MAAM,oBACN,iBACF;AACA,UAAM,WAAW,QAAQ,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,OAAO,QAAQ,GAAG;AACzE,eAAW,CAAC,MAAM,SAAS,UAAU;AACnC,UAAI,QAAQ,qBAAqB;AAC/B,uBAAe,UAAU,MAAM,IAAI;AAAA,MACrC,OAAO;AACL,iBAAS,QAAQ;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACA,uBAAqB,QAAQ;AAC7B,SAAO;AACT,GA9B2B;AAgCpB,8BAA8B,OAAY;AAC/C,MAAI,CAAC,OAAO;AACV,oBAAgB,KAAK;AAAA,EACvB;AACF;AAJgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { getVariableValue } from "../createVariable";
|
|
4
|
+
const getTextSize = /* @__PURE__ */ __name((val = "$4", { fonts, theme, props }) => {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
const family = getVariableValue(props.fontFamily) || "$body";
|
|
7
|
+
const font = fonts[family] || fonts["$body"];
|
|
8
|
+
if (!font) {
|
|
9
|
+
console.warn("\u26A0\uFE0F no font found", { family, fontTokens: Object.keys(fonts), val });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const fontFamily = font.family;
|
|
13
|
+
const fontSize = props.fontSize || font.size[val];
|
|
14
|
+
const lineHeight = props.lineHeight || font.lineHeight[val];
|
|
15
|
+
const fontWeight = props.fontWeight || font.weight[val];
|
|
16
|
+
const letterSpacing = props.letterSpacing || font.letterSpacing[val];
|
|
17
|
+
const fontStyle = props.fontStyle || ((_a = font.style) == null ? void 0 : _a[val]);
|
|
18
|
+
const textTransform = props.textTransform || ((_b = font.transform) == null ? void 0 : _b[val]);
|
|
19
|
+
const color = props.color || ((_c = font.color) == null ? void 0 : _c[val]) || theme.color;
|
|
20
|
+
return {
|
|
21
|
+
color,
|
|
22
|
+
fontStyle,
|
|
23
|
+
textTransform,
|
|
24
|
+
fontFamily,
|
|
25
|
+
fontWeight,
|
|
26
|
+
letterSpacing,
|
|
27
|
+
fontSize,
|
|
28
|
+
lineHeight
|
|
29
|
+
};
|
|
30
|
+
}, "getTextSize");
|
|
31
|
+
export {
|
|
32
|
+
getTextSize
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=getTextSize.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/helpers/getTextSize.tsx"],
|
|
4
|
+
"sourcesContent": ["import { getVariableValue } from '../createVariable'\nimport { FontSizeTokens, TextProps, VariantSpreadFunction } from '../types'\n\nexport const getTextSize: VariantSpreadFunction<TextProps, FontSizeTokens> = (\n val = '$4',\n { fonts, theme, props }\n) => {\n const family = getVariableValue(props.fontFamily) || '$body'\n const font = fonts[family] || fonts['$body']\n if (!font) {\n console.warn('\u26A0\uFE0F no font found', { family, fontTokens: Object.keys(fonts), val })\n return\n }\n const fontFamily = font.family\n const fontSize = props.fontSize || font.size[val]\n const lineHeight = props.lineHeight || font.lineHeight[val]\n const fontWeight = props.fontWeight || font.weight[val]\n const letterSpacing = props.letterSpacing || font.letterSpacing[val]\n const fontStyle = props.fontStyle || font.style?.[val]\n const textTransform = props.textTransform || font.transform?.[val]\n const color = props.color || font.color?.[val] || theme.color\n return {\n color,\n fontStyle,\n textTransform,\n fontFamily,\n fontWeight,\n letterSpacing,\n fontSize,\n lineHeight,\n } as any\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAGO,MAAM,cAAgE,wBAC3E,MAAM,MACN,EAAE,OAAO,OAAO,YACb;AANL;AAOE,QAAM,SAAS,iBAAiB,MAAM,UAAU,KAAK;AACrD,QAAM,OAAO,MAAM,WAAW,MAAM;AACpC,MAAI,CAAC,MAAM;AACT,YAAQ,KAAK,8BAAoB,EAAE,QAAQ,YAAY,OAAO,KAAK,KAAK,GAAG,IAAI,CAAC;AAChF;AAAA,EACF;AACA,QAAM,aAAa,KAAK;AACxB,QAAM,WAAW,MAAM,YAAY,KAAK,KAAK;AAC7C,QAAM,aAAa,MAAM,cAAc,KAAK,WAAW;AACvD,QAAM,aAAa,MAAM,cAAc,KAAK,OAAO;AACnD,QAAM,gBAAgB,MAAM,iBAAiB,KAAK,cAAc;AAChE,QAAM,YAAY,MAAM,aAAa,YAAK,UAAL,mBAAa;AAClD,QAAM,gBAAgB,MAAM,iBAAiB,YAAK,cAAL,mBAAiB;AAC9D,QAAM,QAAQ,MAAM,SAAS,YAAK,UAAL,mBAAa,SAAQ,MAAM;AACxD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF,GA5B6E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -79,6 +79,7 @@ function insertStyleRule(identifier, rule) {
|
|
|
79
79
|
return;
|
|
80
80
|
hasInsertedSinceUpdate = true;
|
|
81
81
|
updateInsertedCache(identifier, rule);
|
|
82
|
+
allSelectors[identifier] = process.env.NODE_ENV === "development" ? rule : true;
|
|
82
83
|
sheet == null ? void 0 : sheet.insertRule(rule, sheet.cssRules.length);
|
|
83
84
|
}
|
|
84
85
|
__name(insertStyleRule, "insertStyleRule");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/insertStyleRule.tsx"],
|
|
4
|
-
"sourcesContent": ["// this needs to check if its inserted already? 99% of the time it is\n// this should avoid re-inserts, but need to test the perf trade-offs\n// i tested with the site itself and the initial insert was trivial\n\nconst allSelectors = {}\nconst insertedSelectors = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getInsertedRules = () => Object.values(insertedSelectors)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n console.groupCollapsed(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n console.log('rule:', rule)\n console.trace()\n console.groupEnd()\n } else {\n console.error(`Missing transform`, identifier, css, rule)\n }\n return\n }\n const startI = s + 'transform:'.length\n const endI = css.indexOf(';')\n const value = css.slice(startI, endI)\n insertedTransforms[identifier] = value\n}\n\nconst isClient = typeof document !== 'undefined'\n\n// gets existing ones (client side)\n// takes ~0.1ms for a fairly large page\n// used now for three things:\n// 1. debugging at dev time\n// 2. avoid duplicate insert styles at runtime\n// 3. used now for merging transforms atomically\nlet hasInsertedSinceUpdate = true\n\nexport function updateInserted() {\n if (!isClient) return\n if (!hasInsertedSinceUpdate) {\n console.warn('hasnt inserted since')\n return\n }\n const sheets = document.styleSheets\n if (!sheets) return\n for (let i = 0; i < sheets.length; i++) {\n const rules = sheets[i].cssRules\n const firstRule = rules[0]\n if (!(firstRule instanceof CSSStyleRule)) continue\n const firstSelector = firstRule.selectorText\n if (!firstSelector) continue\n if (firstSelector === ':root' || firstSelector.startsWith('._')) {\n for (let i = 0; i < rules.length; i++) {\n const rule = rules.item(i)\n if (!(rule instanceof CSSStyleRule)) continue\n const identifier = rule.selectorText.slice(1)\n if (!allSelectors[identifier]) {\n allSelectors[identifier] = process.env.NODE_ENV === 'development' ? rule.cssText : true\n if (identifier.startsWith('_transform')) {\n addTransform(identifier, rule.cssText, rule)\n }\n }\n }\n }\n }\n hasInsertedSinceUpdate = false\n}\n\nupdateInserted()\n\nconst sheet = isClient ? document.head.appendChild(document.createElement('style')).sheet : null\n\nexport function updateInsertedCache(identifier: string, rule: string) {\n if (insertedSelectors[identifier]) return\n insertedSelectors[identifier] = rule\n if (identifier.startsWith('_transform')) {\n addTransform(identifier, rule)\n }\n}\n\nexport function insertStyleRule(identifier: string, rule: string) {\n if (allSelectors[identifier]) return\n hasInsertedSinceUpdate = true\n updateInsertedCache(identifier, rule)\n sheet?.insertRule(rule, sheet.cssRules.length)\n}\n"],
|
|
5
|
-
"mappings": ";;AAIA,MAAM,eAAe,CAAC;AACtB,MAAM,oBAAoB,CAAC;AACpB,MAAM,qBAAqB,CAAC;AAE5B,MAAM,kBAAkB,6BAAM,cAAN;AACxB,MAAM,mBAAmB,6BAAM,OAAO,OAAO,iBAAiB,GAArC;AACzB,MAAM,mBAAmB,6BAAM,oBAAN;AAGhC,sBAAsB,YAAoB,KAAa,MAAgB;AACrE,QAAM,IAAI,IAAI,QAAQ,YAAY;AAClC,MAAI,MAAM,IAAI;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,eAAe,0DAAqD,YAAY;AACxF,cAAQ,IAAI,SAAS,IAAI;AACzB,cAAQ,MAAM;AACd,cAAQ,SAAS;AAAA,IACnB,OAAO;AACL,cAAQ,MAAM,qBAAqB,YAAY,KAAK,IAAI;AAAA,IAC1D;AACA;AAAA,EACF;AACA,QAAM,SAAS,IAAI,aAAa;AAChC,QAAM,OAAO,IAAI,QAAQ,GAAG;AAC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,aAAa;AAAa;AAC9B,2BAAyB;AACzB,sBAAoB,YAAY,IAAI;AACpC,iCAAO,WAAW,MAAM,MAAM,SAAS;AACzC;
|
|
4
|
+
"sourcesContent": ["// this needs to check if its inserted already? 99% of the time it is\n// this should avoid re-inserts, but need to test the perf trade-offs\n// i tested with the site itself and the initial insert was trivial\n\nconst allSelectors = {}\nconst insertedSelectors = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getInsertedRules = () => Object.values(insertedSelectors)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n console.groupCollapsed(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n console.log('rule:', rule)\n console.trace()\n console.groupEnd()\n } else {\n console.error(`Missing transform`, identifier, css, rule)\n }\n return\n }\n const startI = s + 'transform:'.length\n const endI = css.indexOf(';')\n const value = css.slice(startI, endI)\n insertedTransforms[identifier] = value\n}\n\nconst isClient = typeof document !== 'undefined'\n\n// gets existing ones (client side)\n// takes ~0.1ms for a fairly large page\n// used now for three things:\n// 1. debugging at dev time\n// 2. avoid duplicate insert styles at runtime\n// 3. used now for merging transforms atomically\nlet hasInsertedSinceUpdate = true\n\nexport function updateInserted() {\n if (!isClient) return\n if (!hasInsertedSinceUpdate) {\n console.warn('hasnt inserted since')\n return\n }\n const sheets = document.styleSheets\n if (!sheets) return\n for (let i = 0; i < sheets.length; i++) {\n const rules = sheets[i].cssRules\n const firstRule = rules[0]\n if (!(firstRule instanceof CSSStyleRule)) continue\n const firstSelector = firstRule.selectorText\n if (!firstSelector) continue\n if (firstSelector === ':root' || firstSelector.startsWith('._')) {\n for (let i = 0; i < rules.length; i++) {\n const rule = rules.item(i)\n if (!(rule instanceof CSSStyleRule)) continue\n const identifier = rule.selectorText.slice(1)\n if (!allSelectors[identifier]) {\n allSelectors[identifier] = process.env.NODE_ENV === 'development' ? rule.cssText : true\n if (identifier.startsWith('_transform')) {\n addTransform(identifier, rule.cssText, rule)\n }\n }\n }\n }\n }\n hasInsertedSinceUpdate = false\n}\n\nupdateInserted()\n\nconst sheet = isClient ? document.head.appendChild(document.createElement('style')).sheet : null\n\nexport function updateInsertedCache(identifier: string, rule: string) {\n if (insertedSelectors[identifier]) return\n insertedSelectors[identifier] = rule\n if (identifier.startsWith('_transform')) {\n addTransform(identifier, rule)\n }\n}\n\nexport function insertStyleRule(identifier: string, rule: string) {\n if (allSelectors[identifier]) return\n hasInsertedSinceUpdate = true\n updateInsertedCache(identifier, rule)\n allSelectors[identifier] = process.env.NODE_ENV === 'development' ? rule : true\n sheet?.insertRule(rule, sheet.cssRules.length)\n}\n"],
|
|
5
|
+
"mappings": ";;AAIA,MAAM,eAAe,CAAC;AACtB,MAAM,oBAAoB,CAAC;AACpB,MAAM,qBAAqB,CAAC;AAE5B,MAAM,kBAAkB,6BAAM,cAAN;AACxB,MAAM,mBAAmB,6BAAM,OAAO,OAAO,iBAAiB,GAArC;AACzB,MAAM,mBAAmB,6BAAM,oBAAN;AAGhC,sBAAsB,YAAoB,KAAa,MAAgB;AACrE,QAAM,IAAI,IAAI,QAAQ,YAAY;AAClC,MAAI,MAAM,IAAI;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,eAAe,0DAAqD,YAAY;AACxF,cAAQ,IAAI,SAAS,IAAI;AACzB,cAAQ,MAAM;AACd,cAAQ,SAAS;AAAA,IACnB,OAAO;AACL,cAAQ,MAAM,qBAAqB,YAAY,KAAK,IAAI;AAAA,IAC1D;AACA;AAAA,EACF;AACA,QAAM,SAAS,IAAI,aAAa;AAChC,QAAM,OAAO,IAAI,QAAQ,GAAG;AAC5B,QAAM,QAAQ,IAAI,MAAM,QAAQ,IAAI;AACpC,qBAAmB,cAAc;AACnC;AAjBS;AAmBT,MAAM,WAAW,OAAO,aAAa;AAQrC,IAAI,yBAAyB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MAAM,MAAM,SAAS;AACzC;AANgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useIsomorphicLayoutEffect } from "../constants/platform";
|
|
5
|
+
let serverHandoffComplete = false;
|
|
6
|
+
let id = 0;
|
|
7
|
+
function genId() {
|
|
8
|
+
return ++id;
|
|
9
|
+
}
|
|
10
|
+
__name(genId, "genId");
|
|
11
|
+
function useId(providedId) {
|
|
12
|
+
var _a;
|
|
13
|
+
if (typeof React.useId === "function") {
|
|
14
|
+
let id3 = React.useId(providedId);
|
|
15
|
+
return providedId != null ? providedId : id3;
|
|
16
|
+
}
|
|
17
|
+
let initialId = providedId != null ? providedId : serverHandoffComplete ? genId() : null;
|
|
18
|
+
let [id2, setId] = React.useState(initialId);
|
|
19
|
+
useIsomorphicLayoutEffect(() => {
|
|
20
|
+
if (id2 === null) {
|
|
21
|
+
setId(genId());
|
|
22
|
+
}
|
|
23
|
+
}, []);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
if (serverHandoffComplete === false) {
|
|
26
|
+
serverHandoffComplete = true;
|
|
27
|
+
}
|
|
28
|
+
}, []);
|
|
29
|
+
return (_a = providedId != null ? providedId : id2) != null ? _a : void 0;
|
|
30
|
+
}
|
|
31
|
+
__name(useId, "useId");
|
|
32
|
+
export {
|
|
33
|
+
useId
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=useId.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useId.tsx"],
|
|
4
|
+
"sourcesContent": ["/*\n * Welcome to @reach/auto-id!\n\n * Let's see if we can make sense of why this hook exists and its\n * implementation.\n *\n * Some background:\n * 1. Accessibility APIs rely heavily on element IDs\n * 2. Requiring developers to put IDs on every element in Reach UI is both\n * cumbersome and error-prone\n * 3. With a component model, we can generate IDs for them!\n *\n * Solution 1: Generate random IDs.\n *\n * This works great as long as you don't server render your app. When React (in\n * the client) tries to reuse the markup from the server, the IDs won't match\n * and React will then recreate the entire DOM tree.\n *\n * Solution 2: Increment an integer\n *\n * This sounds great. Since we're rendering the exact same tree on the server\n * and client, we can increment a counter and get a deterministic result between\n * client and server. Also, JS integers can go up to nine-quadrillion. I'm\n * pretty sure the tab will be closed before an app never needs\n * 10 quadrillion IDs!\n *\n * Problem solved, right?\n *\n * Ah, but there's a catch! React's concurrent rendering makes this approach\n * non-deterministic. While the client and server will end up with the same\n * elements in the end, depending on suspense boundaries (and possibly some user\n * input during the initial render) the incrementing integers won't always match\n * up.\n *\n * Solution 3: Don't use IDs at all on the server; patch after first render.\n *\n * What we've done here is solution 2 with some tricks. With this approach, the\n * ID returned is an empty string on the first render. This way the server and\n * client have the same markup no matter how wild the concurrent rendering may\n * have gotten.\n *\n * After the render, we patch up the components with an incremented ID. This\n * causes a double render on any components with `useId`. Shouldn't be a problem\n * since the components using this hook should be small, and we're only updating\n * the ID attribute on the DOM, nothing big is happening.\n *\n * It doesn't have to be an incremented number, though--we could do generate\n * random strings instead, but incrementing a number is probably the cheapest\n * thing we can do.\n *\n * Additionally, we only do this patchup on the very first client render ever.\n * Any calls to `useId` that happen dynamically in the client will be\n * populated immediately with a value. So, we only get the double render after\n * server hydration and never again, SO BACK OFF ALRIGHT?\n */\n\nimport * as React from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\n\nlet serverHandoffComplete = false\nlet id = 0\nfunction genId() {\n return ++id\n}\n\n/* eslint-disable react-hooks/rules-of-hooks */\n\n/**\n * useId\n *\n * Autogenerate IDs to facilitate WAI-ARIA and server rendering.\n *\n * Note: The returned ID will initially be `null` and will update after a\n * component mounts. Users may need to supply their own ID if they need\n * consistent values for SSR.\n *\n * @see Docs https://reach.tech/auto-id\n */\nfunction useId(idFromProps: string): string\nfunction useId(idFromProps: number): number\nfunction useId(idFromProps: string | number): string | number\nfunction useId(idFromProps: string | undefined | null): string | undefined\nfunction useId(idFromProps: number | undefined | null): number | undefined\nfunction useId(idFromProps: string | number | undefined | null): string | number | undefined\nfunction useId(): string | undefined\n\nfunction useId(providedId?: number | string | undefined | null) {\n // TODO: Remove error flag when updating internal deps to React 18. None of\n // our tricks will play well with concurrent rendering anyway.\n // @ts-expect-error\n if (typeof React.useId === 'function') {\n // @ts-expect-error\n let id = React.useId(providedId)\n return providedId != null ? providedId : id\n }\n\n // If this instance isn't part of the initial render, we don't have to do the\n // double render/patch-up dance. We can just generate the ID and return it.\n let initialId = providedId ?? (serverHandoffComplete ? genId() : null)\n let [id, setId] = React.useState(initialId)\n\n useIsomorphicLayoutEffect(() => {\n if (id === null) {\n // Patch the ID after render. We do this in `useLayoutEffect` to avoid any\n // rendering flicker, though it'll make the first render slower (unlikely\n // to matter, but you're welcome to measure your app and let us know if\n // it's a problem).\n setId(genId())\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n React.useEffect(() => {\n if (serverHandoffComplete === false) {\n // Flag all future uses of `useId` to skip the update dance. This is in\n // `useEffect` because it goes after `useLayoutEffect`, ensuring we don't\n // accidentally bail out of the patch-up dance prematurely.\n serverHandoffComplete = true\n }\n }, [])\n\n return providedId ?? id ?? undefined\n}\n\nexport { useId }\n"],
|
|
5
|
+
"mappings": ";;AAwDA;AAEA;AAEA,IAAI,wBAAwB;AAC5B,IAAI,KAAK;AACT,iBAAiB;AACf,SAAO,EAAE;AACX;AAFS;AAyBT,eAAe,YAAiD;AAvFhE;AA2FE,MAAI,OAAO,MAAM,UAAU,YAAY;AAErC,QAAI,MAAK,MAAM,MAAM,UAAU;AAC/B,WAAO,cAAc,OAAO,aAAa;AAAA,EAC3C;AAIA,MAAI,YAAY,kCAAe,wBAAwB,MAAM,IAAI;AACjE,MAAI,CAAC,KAAI,SAAS,MAAM,SAAS,SAAS;AAE1C,4BAA0B,MAAM;AAC9B,QAAI,QAAO,MAAM;AAKf,YAAM,MAAM,CAAC;AAAA,IACf;AAAA,EAEF,GAAG,CAAC,CAAC;AAEL,QAAM,UAAU,MAAM;AACpB,QAAI,0BAA0B,OAAO;AAInC,8BAAwB;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,wCAAc,QAAd,YAAoB;AAC7B;AApCS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -13,31 +13,34 @@ import { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } f
|
|
|
13
13
|
export * from "./constants/constants";
|
|
14
14
|
export * from "./constants/platform";
|
|
15
15
|
export * from "./constants/rnw";
|
|
16
|
+
export * from "./helpers/getButtonSize";
|
|
16
17
|
export * from "./helpers/getExpandedShorthands";
|
|
17
18
|
export * from "./helpers/getSize";
|
|
18
19
|
export * from "./helpers/getSplitStyles";
|
|
19
20
|
export * from "./helpers/getStylesAtomic";
|
|
21
|
+
export * from "./helpers/getTextSize";
|
|
20
22
|
export * from "./helpers/isObj";
|
|
21
23
|
export * from "./helpers/isTamaguiElement";
|
|
22
24
|
export * from "./helpers/matchMedia";
|
|
23
25
|
export * from "./helpers/themeable";
|
|
24
26
|
export * from "./helpers/withStaticProperties";
|
|
25
27
|
export * from "./contexts/ButtonInsideButtonContext";
|
|
26
|
-
export * from "./hooks/useIsTouchDevice";
|
|
27
28
|
export * from "./hooks/useConstant";
|
|
28
|
-
export * from "./hooks/
|
|
29
|
+
export * from "./hooks/useId";
|
|
30
|
+
export * from "./hooks/useIsMounted";
|
|
31
|
+
export * from "./hooks/useIsTouchDevice";
|
|
29
32
|
export * from "./hooks/useMedia";
|
|
33
|
+
export * from "./hooks/usePressable";
|
|
30
34
|
export * from "./hooks/useTheme";
|
|
31
|
-
export * from "./hooks/useIsMounted";
|
|
32
35
|
export * from "./hooks/useUnmountEffect";
|
|
33
|
-
export * from "@tamagui/use-force-update";
|
|
34
36
|
export * from "./views/Stack";
|
|
35
37
|
export * from "./views/Text";
|
|
38
|
+
export * from "./views/TextAncestorContext";
|
|
36
39
|
export * from "./views/Theme";
|
|
37
|
-
export * from "./views/ThemeReset";
|
|
38
40
|
export * from "./views/ThemeInverse";
|
|
39
41
|
export * from "./views/ThemeProvider";
|
|
40
|
-
export * from "./views/
|
|
42
|
+
export * from "./views/ThemeReset";
|
|
43
|
+
export * from "@tamagui/use-force-update";
|
|
41
44
|
export * from "@tamagui/helpers";
|
|
42
45
|
export {
|
|
43
46
|
RNWTextProps,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport { createTokens } from './createTokens'\nexport * from './createVariable'\nexport * from './styled'\nexport * from './types'\n// for type portability\nexport { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './conf'\n\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport * from './constants/rnw'\n\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSize'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/isObj'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonInsideButtonContext'\n\nexport * from './hooks/
|
|
5
|
-
"mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;",
|
|
4
|
+
"sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport { createTokens } from './createTokens'\nexport * from './createVariable'\nexport * from './styled'\nexport * from './types'\n// for type portability\nexport { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './conf'\n\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport * from './constants/rnw'\n\nexport * from './helpers/getButtonSize'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSize'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/getTextSize'\nexport * from './helpers/isObj'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonInsideButtonContext'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useId'\nexport * from './hooks/useIsMounted'\nexport * from './hooks/useIsTouchDevice'\nexport * from './hooks/useMedia'\nexport * from './hooks/usePressable'\nexport * from './hooks/useTheme'\nexport * from './hooks/useUnmountEffect'\n\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './views/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/ThemeReset'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/helpers'\n"],
|
|
5
|
+
"mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { composeRefs } from "@tamagui/compose-refs";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
const Slot = React.forwardRef((props, forwardedRef) => {
|
|
6
|
+
const { children, ...slotProps } = props;
|
|
7
|
+
if (React.Children.toArray(children).some(isSlottable)) {
|
|
8
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, React.Children.map(children, (child) => {
|
|
9
|
+
return isSlottable(child) ? /* @__PURE__ */ React.createElement(SlotClone, {
|
|
10
|
+
...slotProps,
|
|
11
|
+
ref: forwardedRef
|
|
12
|
+
}, child.props.children) : child;
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
return /* @__PURE__ */ React.createElement(SlotClone, {
|
|
16
|
+
...slotProps,
|
|
17
|
+
ref: forwardedRef
|
|
18
|
+
}, children);
|
|
19
|
+
});
|
|
20
|
+
Slot.displayName = "Slot";
|
|
21
|
+
const SlotClone = React.forwardRef((props, forwardedRef) => {
|
|
22
|
+
const { children, ...slotProps } = props;
|
|
23
|
+
if (React.isValidElement(children)) {
|
|
24
|
+
return React.cloneElement(children, {
|
|
25
|
+
...mergeProps(slotProps, children.props),
|
|
26
|
+
ref: composeRefs(forwardedRef, children.ref)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
|
|
30
|
+
});
|
|
31
|
+
SlotClone.displayName = "SlotClone";
|
|
32
|
+
const Slottable = /* @__PURE__ */ __name(({ children }) => {
|
|
33
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
34
|
+
}, "Slottable");
|
|
35
|
+
function isSlottable(child) {
|
|
36
|
+
return React.isValidElement(child);
|
|
37
|
+
}
|
|
38
|
+
__name(isSlottable, "isSlottable");
|
|
39
|
+
function mergeProps(slotProps, childProps) {
|
|
40
|
+
const overrideProps = { ...childProps };
|
|
41
|
+
for (const propName in childProps) {
|
|
42
|
+
const slotPropValue = slotProps[propName];
|
|
43
|
+
const childPropValue = childProps[propName];
|
|
44
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
45
|
+
if (isHandler) {
|
|
46
|
+
overrideProps[propName] = (...args) => {
|
|
47
|
+
childPropValue == null ? void 0 : childPropValue(...args);
|
|
48
|
+
slotPropValue == null ? void 0 : slotPropValue(...args);
|
|
49
|
+
};
|
|
50
|
+
} else if (propName === "style") {
|
|
51
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
52
|
+
} else if (propName === "className") {
|
|
53
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { ...slotProps, ...overrideProps };
|
|
57
|
+
}
|
|
58
|
+
__name(mergeProps, "mergeProps");
|
|
59
|
+
export {
|
|
60
|
+
Slot,
|
|
61
|
+
Slottable
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=Slot.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/views/Slot.tsx"],
|
|
4
|
+
"sourcesContent": ["// via radix\n\nimport { composeRefs } from '@tamagui/compose-refs'\nimport * as React from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type SlotProps = {\n children?: React.ReactNode\n}\n\nexport const Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n\n if (React.Children.toArray(children).some(isSlottable)) {\n return (\n <>\n {React.Children.map(children, (child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n )\n })}\n </>\n )\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n )\n})\n\nSlot.displayName = 'Slot'\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n\n if (React.isValidElement(children)) {\n return React.cloneElement(children, {\n ...mergeProps(slotProps, children.props),\n ref: composeRefs(forwardedRef, (children as any).ref),\n })\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null\n})\n\nSlotClone.displayName = 'SlotClone'\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nexport const Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child)\n}\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps }\n\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName]\n const childPropValue = childProps[propName]\n\n const isHandler = /^on[A-Z]/.test(propName)\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = (...args: unknown[]) => {\n childPropValue?.(...args)\n slotPropValue?.(...args)\n }\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue }\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ')\n }\n }\n\n return { ...slotProps, ...overrideProps }\n}\n"],
|
|
5
|
+
"mappings": ";;AAEA;AACA;AAUO,MAAM,OAAO,MAAM,WAAmC,CAAC,OAAO,iBAAiB;AACpF,QAAM,EAAE,aAAa,cAAc;AAEnC,MAAI,MAAM,SAAS,QAAQ,QAAQ,EAAE,KAAK,WAAW,GAAG;A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,OAAO,EAAE,KAAK,GAAG;AAAA,IACpF;AAAA,EACF;AAEA,SAAO,KAAK,cAAc,cAAc;AAC1C;AAzBS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -29,6 +29,7 @@ import { useFeatures } from "./hooks/useFeatures";
|
|
|
29
29
|
import { useIsTouchDevice } from "./hooks/useIsTouchDevice";
|
|
30
30
|
import { usePressable } from "./hooks/usePressable";
|
|
31
31
|
import { getThemeManagerIfChanged, useTheme } from "./hooks/useTheme";
|
|
32
|
+
import { Slot } from "./views/Slot";
|
|
32
33
|
import { TextAncestorContext } from "./views/TextAncestorContext";
|
|
33
34
|
React["keep"];
|
|
34
35
|
const defaultComponentState = {
|
|
@@ -93,7 +94,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
93
94
|
__name(addPseudoToStyles, "addPseudoToStyles");
|
|
94
95
|
const component = forwardRef((props, forwardedRef) => {
|
|
95
96
|
var _a, _b, _c, _d;
|
|
96
|
-
props = tamaguiDefaultProps ? { ...tamaguiDefaultProps, ...props } : props;
|
|
97
|
+
props = tamaguiDefaultProps && !props.asChild ? { ...tamaguiDefaultProps, ...props } : props;
|
|
97
98
|
const { Component, componentName, isText, isZStack } = staticConfig;
|
|
98
99
|
if (process.env.NODE_ENV === "development") {
|
|
99
100
|
if (props["debug"]) {
|
|
@@ -108,7 +109,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
108
109
|
const [state, set_] = useState(defaultComponentState);
|
|
109
110
|
const setStateShallow = createShallowUpdate(set_);
|
|
110
111
|
const shouldAvoidClasses = !!(props.animation && avoidClasses);
|
|
111
|
-
const splitStyles = useSplitStyles(props, staticConfig, theme, shouldAvoidClasses ? { ...state, noClassNames: true, resolveVariablesAs: "value" } : state, shouldAvoidClasses ? null : initialSplitStyles.classNames);
|
|
112
|
+
const splitStyles = useSplitStyles(props, staticConfig, theme, shouldAvoidClasses ? { ...state, noClassNames: true, resolveVariablesAs: "value" } : state, shouldAvoidClasses || props.asChild ? null : initialSplitStyles.classNames);
|
|
112
113
|
const { viewProps: viewPropsIn, pseudos, medias, style, classNames } = splitStyles;
|
|
113
114
|
const useAnimations = (_a = tamaguiConfig.animations) == null ? void 0 : _a.useAnimations;
|
|
114
115
|
const isAnimated = !!(useAnimations && props.animation);
|
|
@@ -127,6 +128,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
127
128
|
const {
|
|
128
129
|
tag,
|
|
129
130
|
hitSlop,
|
|
131
|
+
asChild,
|
|
130
132
|
children,
|
|
131
133
|
pointerEvents,
|
|
132
134
|
onPress,
|
|
@@ -210,7 +212,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
210
212
|
if (accessibilityRole)
|
|
211
213
|
viewProps.accessibilityRole = accessibilityRole;
|
|
212
214
|
}
|
|
213
|
-
if (isWeb) {
|
|
215
|
+
if (isWeb && !asChild) {
|
|
214
216
|
rnw.useResponderEvents(hostRef, {
|
|
215
217
|
onMoveShouldSetResponder,
|
|
216
218
|
onMoveShouldSetResponderCapture,
|
|
@@ -318,7 +320,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
318
320
|
const isHoverable = isWeb && !isTouch;
|
|
319
321
|
const attachHover = isHoverable && !!(pseudos && pseudos.hoverStyle || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);
|
|
320
322
|
const pressEventKey = isStringElement ? "onClick" : "onPress";
|
|
321
|
-
const shouldAttach = attachPress || attachHover || "pressStyle" in props || "onPress" in props || "onPressIn" in props || "onPressOut" in props || isWeb && ("hoverStyle" in props || "onHoverIn" in props || "onHoverOut" in props || "onMouseEnter" in props || "onMouseLeave" in props);
|
|
323
|
+
const shouldAttach = !asChild && (attachPress || attachHover || "pressStyle" in props || "onPress" in props || "onPressIn" in props || "onPressOut" in props || isWeb && ("hoverStyle" in props || "onHoverIn" in props || "onHoverOut" in props || "onMouseEnter" in props || "onMouseLeave" in props));
|
|
322
324
|
const unPress = useCallback(() => {
|
|
323
325
|
if (!internal.current.isMounted)
|
|
324
326
|
return;
|
|
@@ -384,7 +386,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
384
386
|
onPressOut == null ? void 0 : onPressOut(e);
|
|
385
387
|
} : null
|
|
386
388
|
} : null;
|
|
387
|
-
|
|
389
|
+
const childEls = !children || asChild ? children : wrapThemeManagerContext(spacedChildren({
|
|
388
390
|
children,
|
|
389
391
|
space,
|
|
390
392
|
flexDirection: props.flexDirection || ((_b = staticConfig.defaultProps) == null ? void 0 : _b.flexDirection),
|
|
@@ -424,6 +426,11 @@ function createComponent(configIn, ParentComponent) {
|
|
|
424
426
|
Object.assign(viewProps, events);
|
|
425
427
|
}
|
|
426
428
|
}
|
|
429
|
+
if (asChild) {
|
|
430
|
+
ViewComponent = Slot;
|
|
431
|
+
const onlyChild = React.Children.only(children);
|
|
432
|
+
Object.assign(viewProps, onlyChild.props);
|
|
433
|
+
}
|
|
427
434
|
content = createElement(ViewComponent, viewProps, childEls);
|
|
428
435
|
if (isWeb && events && attachHover) {
|
|
429
436
|
content = <span className="tui_Hoverable" style={{
|