@tamagui/core 1.0.0-alpha.12 → 1.0.0-alpha.13
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/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createTamagui.js +2 -0
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createVariable.js +1 -1
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/views/Text.js +2 -2
- package/dist/cjs/views/Text.js.map +2 -2
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTamagui.js +2 -0
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createVariable.js +1 -1
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/views/Text.js +1 -1
- package/dist/esm/views/Text.js.map +2 -2
- package/dist/jsx/createTamagui.js +2 -0
- package/dist/jsx/createVariable.js +1 -1
- package/dist/jsx/views/Text.js +1 -1
- package/package.json +3 -3
- package/src/createTamagui.ts +1 -0
- package/src/createVariable.ts +1 -1
- package/types/createTamagui.d.ts +16 -0
- package/types/createTamagui.d.ts.map +1 -1
- package/types/createVariable.d.ts +1 -1
- package/types/helpers/createMediaStyle.d.ts +0 -1
- package/types/helpers/createMediaStyle.d.ts.map +1 -1
- package/types/helpers/getStylesAtomic.d.ts +0 -1
- package/types/helpers/getStylesAtomic.d.ts.map +1 -1
- package/types/views/Text.d.ts.map +1 -1
- package/dist/constants/constants.js +0 -14
- package/dist/constants/constants.js.map +0 -7
- package/dist/constants/platform.js +0 -19
- package/dist/constants/platform.js.map +0 -7
- package/dist/constants/pseudos.js +0 -18
- package/dist/constants/pseudos.js.map +0 -7
- package/dist/constants/rnw.js +0 -22
- package/dist/constants/rnw.js.map +0 -7
- package/dist/constants/styleConstants.js +0 -46
- package/dist/constants/styleConstants.js.map +0 -7
- package/dist/createComponent.js +0 -464
- package/dist/createComponent.js.map +0 -7
- package/dist/createFont.js +0 -28
- package/dist/createFont.js.map +0 -7
- package/dist/createShorthands.js +0 -10
- package/dist/createShorthands.js.map +0 -7
- package/dist/createTamagui.js +0 -168
- package/dist/createTamagui.js.map +0 -7
- package/dist/createTheme.js +0 -20
- package/dist/createTheme.js.map +0 -7
- package/dist/createTokens.js +0 -33
- package/dist/createTokens.js.map +0 -7
- package/dist/createVariable.js +0 -25
- package/dist/createVariable.js.map +0 -7
- package/dist/helpers/addStylesUsingClassname.js +0 -57
- package/dist/helpers/addStylesUsingClassname.js.map +0 -7
- package/dist/helpers/createMediaStyle.js +0 -34
- package/dist/helpers/createMediaStyle.js.map +0 -7
- package/dist/helpers/createPropMapper.js +0 -160
- package/dist/helpers/createPropMapper.js.map +0 -7
- package/dist/helpers/createTamaguiProvider.js +0 -25
- package/dist/helpers/createTamaguiProvider.js.map +0 -7
- package/dist/helpers/extendStaticConfig.js +0 -59
- package/dist/helpers/extendStaticConfig.js.map +0 -7
- package/dist/helpers/fixNativeShadow.js +0 -8
- package/dist/helpers/fixNativeShadow.js.map +0 -7
- package/dist/helpers/fixNativeShadow.native.js +0 -30
- package/dist/helpers/fixNativeShadow.native.js.map +0 -7
- package/dist/helpers/getSplitStyles.js +0 -150
- package/dist/helpers/getSplitStyles.js.map +0 -7
- package/dist/helpers/getStylesAtomic.js +0 -83
- package/dist/helpers/getStylesAtomic.js.map +0 -7
- package/dist/helpers/getStylesAtomic.native.js +0 -10
- package/dist/helpers/getStylesAtomic.native.js.map +0 -7
- package/dist/helpers/insertStyleRule.js +0 -24
- package/dist/helpers/insertStyleRule.js.map +0 -7
- package/dist/helpers/isComponent.js +0 -10
- package/dist/helpers/isComponent.js.map +0 -7
- package/dist/helpers/isObj.js +0 -7
- package/dist/helpers/isObj.js.map +0 -7
- package/dist/helpers/isTamaguiComponent.js +0 -10
- package/dist/helpers/isTamaguiComponent.js.map +0 -7
- package/dist/helpers/isTamaguiElement.js +0 -10
- package/dist/helpers/isTamaguiElement.js.map +0 -7
- package/dist/helpers/matchMedia.js +0 -18
- package/dist/helpers/matchMedia.js.map +0 -7
- package/dist/helpers/matchMedia.native.js +0 -9
- package/dist/helpers/matchMedia.native.js.map +0 -7
- package/dist/helpers/pseudos.js +0 -1
- package/dist/helpers/pseudos.js.map +0 -7
- package/dist/helpers/themeable.js +0 -26
- package/dist/helpers/themeable.js.map +0 -7
- package/dist/helpers/validate.js +0 -60
- package/dist/helpers/validate.js.map +0 -7
- package/dist/helpers/validateConfig.js +0 -46
- package/dist/helpers/validateConfig.js.map +0 -7
- package/dist/helpers/validateTokens.js +0 -29
- package/dist/helpers/validateTokens.js.map +0 -7
- package/dist/hooks/useConstant.js +0 -15
- package/dist/hooks/useConstant.js.map +0 -7
- package/dist/hooks/useFeatures.js +0 -63
- package/dist/hooks/useFeatures.js.map +0 -7
- package/dist/hooks/useForceUpdate.js +0 -28
- package/dist/hooks/useForceUpdate.js.map +0 -7
- package/dist/hooks/useMedia.js +0 -173
- package/dist/hooks/useMedia.js.map +0 -7
- package/dist/hooks/usePressable.js +0 -13
- package/dist/hooks/usePressable.js.map +0 -7
- package/dist/hooks/useTheme.js +0 -89
- package/dist/hooks/useTheme.js.map +0 -7
- package/dist/index.cjs +0 -2202
- package/dist/index.cjs.map +0 -7
- package/dist/index.js +0 -32
- package/dist/index.js.map +0 -7
- package/dist/packages/core/src/constants/constants.d.ts +0 -8
- package/dist/packages/core/src/constants/constants.d.ts.map +0 -1
- package/dist/packages/core/src/constants/platform.d.ts +0 -9
- package/dist/packages/core/src/constants/platform.d.ts.map +0 -1
- package/dist/packages/core/src/constants/pseudos.d.ts +0 -15
- package/dist/packages/core/src/constants/pseudos.d.ts.map +0 -1
- package/dist/packages/core/src/constants/rnw.d.ts +0 -2
- package/dist/packages/core/src/constants/rnw.d.ts.map +0 -1
- package/dist/packages/core/src/createComponent.d.ts +0 -16
- package/dist/packages/core/src/createComponent.d.ts.map +0 -1
- package/dist/packages/core/src/createShorthands.d.ts +0 -2
- package/dist/packages/core/src/createShorthands.d.ts.map +0 -1
- package/dist/packages/core/src/createTamagui.d.ts +0 -37
- package/dist/packages/core/src/createTamagui.d.ts.map +0 -1
- package/dist/packages/core/src/createTheme.d.ts +0 -5
- package/dist/packages/core/src/createTheme.d.ts.map +0 -1
- package/dist/packages/core/src/createTokens.d.ts +0 -45
- package/dist/packages/core/src/createTokens.d.ts.map +0 -1
- package/dist/packages/core/src/createVariable.d.ts +0 -14
- package/dist/packages/core/src/createVariable.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts +0 -2
- package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/createMediaStyle.d.ts +0 -8
- package/dist/packages/core/src/helpers/createMediaStyle.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts +0 -5
- package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/extendStaticConfig.d.ts +0 -5
- package/dist/packages/core/src/helpers/extendStaticConfig.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/fixNativeShadow.d.ts +0 -2
- package/dist/packages/core/src/helpers/fixNativeShadow.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts +0 -2
- package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/getSplitStyles.d.ts +0 -15
- package/dist/packages/core/src/helpers/getSplitStyles.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/getStylesAtomic.d.ts +0 -3
- package/dist/packages/core/src/helpers/getStylesAtomic.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts +0 -2
- package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/insertStyleRule.d.ts +0 -2
- package/dist/packages/core/src/helpers/insertStyleRule.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/matchMedia.d.ts +0 -2
- package/dist/packages/core/src/helpers/matchMedia.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/matchMedia.native.d.ts +0 -3
- package/dist/packages/core/src/helpers/matchMedia.native.d.ts.map +0 -1
- package/dist/packages/core/src/helpers/themeable.d.ts +0 -10
- package/dist/packages/core/src/helpers/themeable.d.ts.map +0 -1
- package/dist/packages/core/src/hooks/useConstant.d.ts +0 -2
- package/dist/packages/core/src/hooks/useConstant.d.ts.map +0 -1
- package/dist/packages/core/src/hooks/useFeatures.d.ts +0 -5
- package/dist/packages/core/src/hooks/useFeatures.d.ts.map +0 -1
- package/dist/packages/core/src/hooks/useForceUpdate.d.ts +0 -2
- package/dist/packages/core/src/hooks/useForceUpdate.d.ts.map +0 -1
- package/dist/packages/core/src/hooks/useMedia.d.ts +0 -16
- package/dist/packages/core/src/hooks/useMedia.d.ts.map +0 -1
- package/dist/packages/core/src/hooks/usePressable.d.ts +0 -3
- package/dist/packages/core/src/hooks/usePressable.d.ts.map +0 -1
- package/dist/packages/core/src/hooks/useTheme.d.ts +0 -18
- package/dist/packages/core/src/hooks/useTheme.d.ts.map +0 -1
- package/dist/packages/core/src/index.d.ts +0 -27
- package/dist/packages/core/src/index.d.ts.map +0 -1
- package/dist/packages/core/src/static/postProcessStyles.d.ts +0 -7
- package/dist/packages/core/src/static/postProcessStyles.d.ts.map +0 -1
- package/dist/packages/core/src/static.d.ts +0 -12
- package/dist/packages/core/src/static.d.ts.map +0 -1
- package/dist/packages/core/src/styled.d.ts +0 -16
- package/dist/packages/core/src/styled.d.ts.map +0 -1
- package/dist/packages/core/src/types.d.ts +0 -305
- package/dist/packages/core/src/types.d.ts.map +0 -1
- package/dist/packages/core/src/views/Animated.d.ts +0 -15
- package/dist/packages/core/src/views/Animated.d.ts.map +0 -1
- package/dist/packages/core/src/views/Stack.d.ts +0 -3
- package/dist/packages/core/src/views/Stack.d.ts.map +0 -1
- package/dist/packages/core/src/views/Text.d.ts +0 -3
- package/dist/packages/core/src/views/Text.d.ts.map +0 -1
- package/dist/packages/core/src/views/TextAncestorContext.d.ts +0 -3
- package/dist/packages/core/src/views/TextAncestorContext.d.ts.map +0 -1
- package/dist/packages/core/src/views/Theme.d.ts +0 -8
- package/dist/packages/core/src/views/Theme.d.ts.map +0 -1
- package/dist/packages/core/src/views/ThemeContext.d.ts +0 -18
- package/dist/packages/core/src/views/ThemeContext.d.ts.map +0 -1
- package/dist/packages/core/src/views/ThemeInverse.d.ts +0 -10
- package/dist/packages/core/src/views/ThemeInverse.d.ts.map +0 -1
- package/dist/packages/core/src/views/ThemeManagerContext.d.ts +0 -15
- package/dist/packages/core/src/views/ThemeManagerContext.d.ts.map +0 -1
- package/dist/packages/core/src/views/ThemeProvider.d.ts +0 -10
- package/dist/packages/core/src/views/ThemeProvider.d.ts.map +0 -1
- package/dist/packages/helpers/src/AllRules.d.ts +0 -3
- package/dist/packages/helpers/src/AllRules.d.ts.map +0 -1
- package/dist/packages/helpers/src/concatClassName.d.ts +0 -2
- package/dist/packages/helpers/src/concatClassName.d.ts.map +0 -1
- package/dist/packages/helpers/src/index.d.ts +0 -5
- package/dist/packages/helpers/src/index.d.ts.map +0 -1
- package/dist/packages/helpers/src/types.d.ts +0 -8
- package/dist/packages/helpers/src/types.d.ts.map +0 -1
- package/dist/packages/helpers/src/validStyleProps.d.ts +0 -475
- package/dist/packages/helpers/src/validStyleProps.d.ts.map +0 -1
- package/dist/static/postProcessStyles.js +0 -18
- package/dist/static/postProcessStyles.js.map +0 -7
- package/dist/static.js +0 -15
- package/dist/static.js.map +0 -7
- package/dist/styled.js +0 -21
- package/dist/styled.js.map +0 -7
- package/dist/types.js +0 -1
- package/dist/types.js.map +0 -7
- package/dist/views/Animated.js +0 -79
- package/dist/views/Animated.js.map +0 -7
- package/dist/views/SafeAreaProvider.js +0 -30
- package/dist/views/SafeAreaProvider.js.map +0 -7
- package/dist/views/Stack.js +0 -12
- package/dist/views/Stack.js.map +0 -7
- package/dist/views/Text.js +0 -60
- package/dist/views/Text.js.map +0 -7
- package/dist/views/TextAncestorContext.js +0 -18
- package/dist/views/TextAncestorContext.js.map +0 -7
- package/dist/views/Theme.js +0 -68
- package/dist/views/Theme.js.map +0 -7
- package/dist/views/ThemeContext.js +0 -6
- package/dist/views/ThemeContext.js.map +0 -7
- package/dist/views/ThemeInverse.js +0 -26
- package/dist/views/ThemeInverse.js.map +0 -7
- package/dist/views/ThemeManagerContext.js +0 -61
- package/dist/views/ThemeManagerContext.js.map +0 -7
- package/dist/views/ThemeProvider.js +0 -45
- package/dist/views/ThemeProvider.js.map +0 -7
package/dist/helpers/validate.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import ow from "@tamagui/ow";
|
|
4
|
-
const validateConfig = /* @__PURE__ */ __name((conf) => {
|
|
5
|
-
if (!conf) {
|
|
6
|
-
console.warn("no conf?");
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
ow(conf, validConfig);
|
|
11
|
-
} catch (err) {
|
|
12
|
-
console.log("Given config:\n", JSON.stringify(conf, null, 2));
|
|
13
|
-
throw err;
|
|
14
|
-
}
|
|
15
|
-
}, "validateConfig");
|
|
16
|
-
const validConfig = ow.object.exactShape({
|
|
17
|
-
defaultTheme: ow.optional.string,
|
|
18
|
-
disableRootThemeClass: ow.optional.boolean,
|
|
19
|
-
shorthands: ow.optional.object.valuesOfType(ow.string),
|
|
20
|
-
themes: ow.object.valuesOfType(ow.object),
|
|
21
|
-
tokens: ow.object.valuesOfType(ow.object),
|
|
22
|
-
media: ow.object.valuesOfType(ow.object)
|
|
23
|
-
});
|
|
24
|
-
const validFont = ow.object.exactShape({
|
|
25
|
-
family: ow.string,
|
|
26
|
-
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
27
|
-
lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
28
|
-
weight: ow.object.nonEmpty.valuesOfType(ow.string),
|
|
29
|
-
letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number)
|
|
30
|
-
});
|
|
31
|
-
const validTokens = ow.object.exactShape({
|
|
32
|
-
font: ow.object.valuesOfType(validFont),
|
|
33
|
-
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
34
|
-
space: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
35
|
-
zIndex: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
36
|
-
radius: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
37
|
-
color: ow.object.nonEmpty.valuesOfType(ow.string)
|
|
38
|
-
});
|
|
39
|
-
const validateTokens = /* @__PURE__ */ __name((tokens) => {
|
|
40
|
-
try {
|
|
41
|
-
ow(tokens, validTokens);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
console.log("Given tokens:\n", JSON.stringify(tokens, null, 2));
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
}, "validateTokens");
|
|
47
|
-
const validateFont = /* @__PURE__ */ __name((font) => {
|
|
48
|
-
try {
|
|
49
|
-
ow(font, validFont);
|
|
50
|
-
} catch (err) {
|
|
51
|
-
console.log("Given font:\n", JSON.stringify(font, null, 2));
|
|
52
|
-
throw err;
|
|
53
|
-
}
|
|
54
|
-
}, "validateFont");
|
|
55
|
-
export {
|
|
56
|
-
validateConfig,
|
|
57
|
-
validateFont,
|
|
58
|
-
validateTokens
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=validate.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/validate.ts"],
|
|
4
|
-
"sourcesContent": ["// published a patched version that works on native\nimport ow from '@tamagui/ow'\n\nexport const validateConfig = (conf: any) => {\n if (!conf) {\n console.warn('no conf?')\n return\n }\n try {\n ow(conf, validConfig)\n } catch (err: any) {\n console.log('Given config:\\n', JSON.stringify(conf, null, 2))\n throw err\n }\n}\n\nconst validConfig = ow.object.exactShape({\n defaultTheme: ow.optional.string,\n disableRootThemeClass: ow.optional.boolean,\n shorthands: ow.optional.object.valuesOfType(ow.string),\n themes: ow.object.valuesOfType(ow.object),\n tokens: ow.object.valuesOfType(ow.object),\n media: ow.object.valuesOfType(ow.object),\n})\n\nconst validFont = ow.object.exactShape({\n family: ow.string,\n size: ow.object.nonEmpty.valuesOfType(ow.number),\n lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),\n weight: ow.object.nonEmpty.valuesOfType(ow.string),\n letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number),\n})\n\nconst validTokens = ow.object.exactShape({\n font: ow.object.valuesOfType(validFont),\n size: ow.object.nonEmpty.valuesOfType(ow.number),\n space: ow.object.nonEmpty.valuesOfType(ow.number),\n zIndex: ow.object.nonEmpty.valuesOfType(ow.number),\n radius: ow.object.nonEmpty.valuesOfType(ow.number),\n color: ow.object.nonEmpty.valuesOfType(ow.string),\n})\n\nexport const validateTokens = (tokens: any) => {\n try {\n ow(tokens, validTokens)\n } catch (err: any) {\n console.log('Given tokens:\\n', JSON.stringify(tokens, null, 2))\n throw err\n }\n}\n\nexport const validateFont = (font: any) => {\n try {\n ow(font, validFont)\n } catch (err: any) {\n console.log('Given font:\\n', JSON.stringify(font, null, 2))\n throw err\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AACA;AAEO,MAAM,iBAAiB,wBAAC,SAAc;AAC3C,MAAI,CAAC,MAAM;AACT,YAAQ,KAAK;AACb;AAAA;AAEF,MAAI;AACF,OAAG,MAAM;AAAA,WACF,KAAP;AACA,YAAQ,IAAI,mBAAmB,KAAK,UAAU,MAAM,MAAM;AAC1D,UAAM;AAAA;AAAA,GAToB;AAa9B,MAAM,cAAc,GAAG,OAAO,WAAW;AAAA,EACvC,cAAc,GAAG,SAAS;AAAA,EAC1B,uBAAuB,GAAG,SAAS;AAAA,EACnC,YAAY,GAAG,SAAS,OAAO,aAAa,GAAG;AAAA,EAC/C,QAAQ,GAAG,OAAO,aAAa,GAAG;AAAA,EAClC,QAAQ,GAAG,OAAO,aAAa,GAAG;AAAA,EAClC,OAAO,GAAG,OAAO,aAAa,GAAG;AAAA;AAGnC,MAAM,YAAY,GAAG,OAAO,WAAW;AAAA,EACrC,QAAQ,GAAG;AAAA,EACX,MAAM,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EACzC,YAAY,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC/C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC3C,eAAe,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA;AAGpD,MAAM,cAAc,GAAG,OAAO,WAAW;AAAA,EACvC,MAAM,GAAG,OAAO,aAAa;AAAA,EAC7B,MAAM,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EACzC,OAAO,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC1C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC3C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC3C,OAAO,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA;AAGrC,MAAM,iBAAiB,wBAAC,WAAgB;AAC7C,MAAI;AACF,OAAG,QAAQ;AAAA,WACJ,KAAP;AACA,YAAQ,IAAI,mBAAmB,KAAK,UAAU,QAAQ,MAAM;AAC5D,UAAM;AAAA;AAAA,GALoB;AASvB,MAAM,eAAe,wBAAC,SAAc;AACzC,MAAI;AACF,OAAG,MAAM;AAAA,WACF,KAAP;AACA,YAAQ,IAAI,iBAAiB,KAAK,UAAU,MAAM,MAAM;AACxD,UAAM;AAAA;AAAA,GALkB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import ow from "ow";
|
|
4
|
-
const validateConfig = /* @__PURE__ */ __name((tokens) => {
|
|
5
|
-
try {
|
|
6
|
-
ow(tokens, validConfig);
|
|
7
|
-
} catch (err) {
|
|
8
|
-
console.error(err.message);
|
|
9
|
-
console.log("Given config:\n", JSON.stringify(tokens, null, 2));
|
|
10
|
-
}
|
|
11
|
-
}, "validateConfig");
|
|
12
|
-
const validConfig = ow.object.exactShape({
|
|
13
|
-
defaultTheme: ow.optional.string,
|
|
14
|
-
disableRootThemeClass: ow.optional.string,
|
|
15
|
-
shorthands: ow.optional.object.valuesOfType(ow.string),
|
|
16
|
-
themes: ow.object.valuesOfType(ow.object),
|
|
17
|
-
tokens: ow.object.valuesOfType(ow.object),
|
|
18
|
-
media: ow.object.valuesOfType(ow.object)
|
|
19
|
-
});
|
|
20
|
-
const validateTokens = /* @__PURE__ */ __name((tokens) => {
|
|
21
|
-
try {
|
|
22
|
-
ow(tokens, validTokens);
|
|
23
|
-
} catch (err) {
|
|
24
|
-
console.error(err.message);
|
|
25
|
-
console.log("Given tokens:\n", JSON.stringify(tokens, null, 2));
|
|
26
|
-
}
|
|
27
|
-
}, "validateTokens");
|
|
28
|
-
const validTokens = ow.object.exactShape({
|
|
29
|
-
font: ow.object.valuesOfType(ow.object.exactShape({
|
|
30
|
-
family: ow.string,
|
|
31
|
-
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
32
|
-
lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
33
|
-
weight: ow.object.nonEmpty.valuesOfType(ow.string),
|
|
34
|
-
letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number)
|
|
35
|
-
})),
|
|
36
|
-
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
37
|
-
space: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
38
|
-
zIndex: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
39
|
-
radius: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
40
|
-
color: ow.object.nonEmpty.valuesOfType(ow.string)
|
|
41
|
-
});
|
|
42
|
-
export {
|
|
43
|
-
validateConfig,
|
|
44
|
-
validateTokens
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=validateConfig.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/validateConfig.ts"],
|
|
4
|
-
"sourcesContent": ["import ow from 'ow'\n\nexport const validateConfig = (tokens: any) => {\n try {\n ow(tokens, validConfig)\n } catch (err: any) {\n console.error(err.message)\n console.log('Given config:\\n', JSON.stringify(tokens, null, 2))\n }\n}\n\nconst validConfig = ow.object.exactShape({\n defaultTheme: ow.optional.string,\n disableRootThemeClass: ow.optional.string,\n shorthands: ow.optional.object.valuesOfType(ow.string),\n themes: ow.object.valuesOfType(ow.object),\n tokens: ow.object.valuesOfType(ow.object),\n media: ow.object.valuesOfType(ow.object),\n})\n\nexport const validateTokens = (tokens: any) => {\n try {\n ow(tokens, validTokens)\n } catch (err: any) {\n console.error(err.message)\n console.log('Given tokens:\\n', JSON.stringify(tokens, null, 2))\n }\n}\n\nconst validTokens = ow.object.exactShape({\n font: ow.object.valuesOfType(\n ow.object.exactShape({\n family: ow.string,\n size: ow.object.nonEmpty.valuesOfType(ow.number),\n lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),\n weight: ow.object.nonEmpty.valuesOfType(ow.string),\n letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number),\n })\n ),\n size: ow.object.nonEmpty.valuesOfType(ow.number),\n space: ow.object.nonEmpty.valuesOfType(ow.number),\n zIndex: ow.object.nonEmpty.valuesOfType(ow.number),\n radius: ow.object.nonEmpty.valuesOfType(ow.number),\n color: ow.object.nonEmpty.valuesOfType(ow.string),\n})\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEO,MAAM,iBAAiB,wBAAC,WAAgB;AAC7C,MAAI;AACF,OAAG,QAAQ;AAAA,WACJ,KAAP;AACA,YAAQ,MAAM,IAAI;AAClB,YAAQ,IAAI,mBAAmB,KAAK,UAAU,QAAQ,MAAM;AAAA;AAAA,GALlC;AAS9B,MAAM,cAAc,GAAG,OAAO,WAAW;AAAA,EACvC,cAAc,GAAG,SAAS;AAAA,EAC1B,uBAAuB,GAAG,SAAS;AAAA,EACnC,YAAY,GAAG,SAAS,OAAO,aAAa,GAAG;AAAA,EAC/C,QAAQ,GAAG,OAAO,aAAa,GAAG;AAAA,EAClC,QAAQ,GAAG,OAAO,aAAa,GAAG;AAAA,EAClC,OAAO,GAAG,OAAO,aAAa,GAAG;AAAA;AAG5B,MAAM,iBAAiB,wBAAC,WAAgB;AAC7C,MAAI;AACF,OAAG,QAAQ;AAAA,WACJ,KAAP;AACA,YAAQ,MAAM,IAAI;AAClB,YAAQ,IAAI,mBAAmB,KAAK,UAAU,QAAQ,MAAM;AAAA;AAAA,GALlC;AAS9B,MAAM,cAAc,GAAG,OAAO,WAAW;AAAA,EACvC,MAAM,GAAG,OAAO,aACd,GAAG,OAAO,WAAW;AAAA,IACnB,QAAQ,GAAG;AAAA,IACX,MAAM,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,IACzC,YAAY,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,IAC/C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,IAC3C,eAAe,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA;AAAA,EAGtD,MAAM,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EACzC,OAAO,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC1C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC3C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC3C,OAAO,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import ow from "ow";
|
|
4
|
-
const validateTokens = /* @__PURE__ */ __name((tokens) => {
|
|
5
|
-
try {
|
|
6
|
-
ow(tokens, validTokens);
|
|
7
|
-
} catch (err) {
|
|
8
|
-
console.error(err.message);
|
|
9
|
-
console.log("Got tokens:\n", JSON.stringify(tokens, null, 2));
|
|
10
|
-
}
|
|
11
|
-
}, "validateTokens");
|
|
12
|
-
const validTokens = ow.object.exactShape({
|
|
13
|
-
font: ow.object.valuesOfType(ow.object.exactShape({
|
|
14
|
-
family: ow.string,
|
|
15
|
-
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
16
|
-
lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
17
|
-
weight: ow.object.nonEmpty.valuesOfType(ow.string),
|
|
18
|
-
letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number)
|
|
19
|
-
})),
|
|
20
|
-
size: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
21
|
-
space: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
22
|
-
zIndex: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
23
|
-
radius: ow.object.nonEmpty.valuesOfType(ow.number),
|
|
24
|
-
color: ow.object.nonEmpty.valuesOfType(ow.string)
|
|
25
|
-
});
|
|
26
|
-
export {
|
|
27
|
-
validateTokens
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=validateTokens.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/validateTokens.ts"],
|
|
4
|
-
"sourcesContent": ["import ow from 'ow'\n\nexport const validateTokens = (tokens: any) => {\n try {\n ow(tokens, validTokens)\n } catch (err: any) {\n console.error(err.message)\n console.log('Got tokens:\\n', JSON.stringify(tokens, null, 2))\n }\n}\n\nconst validTokens = ow.object.exactShape({\n font: ow.object.valuesOfType(\n ow.object.exactShape({\n family: ow.string,\n size: ow.object.nonEmpty.valuesOfType(ow.number),\n lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),\n weight: ow.object.nonEmpty.valuesOfType(ow.string),\n letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number),\n })\n ),\n size: ow.object.nonEmpty.valuesOfType(ow.number),\n space: ow.object.nonEmpty.valuesOfType(ow.number),\n zIndex: ow.object.nonEmpty.valuesOfType(ow.number),\n radius: ow.object.nonEmpty.valuesOfType(ow.number),\n color: ow.object.nonEmpty.valuesOfType(ow.string),\n})\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEO,MAAM,iBAAiB,wBAAC,WAAgB;AAC7C,MAAI;AACF,OAAG,QAAQ;AAAA,WACJ,KAAP;AACA,YAAQ,MAAM,IAAI;AAClB,YAAQ,IAAI,iBAAiB,KAAK,UAAU,QAAQ,MAAM;AAAA;AAAA,GALhC;AAS9B,MAAM,cAAc,GAAG,OAAO,WAAW;AAAA,EACvC,MAAM,GAAG,OAAO,aACd,GAAG,OAAO,WAAW;AAAA,IACnB,QAAQ,GAAG;AAAA,IACX,MAAM,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,IACzC,YAAY,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,IAC/C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,IAC3C,eAAe,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA;AAAA,EAGtD,MAAM,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EACzC,OAAO,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC1C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC3C,QAAQ,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA,EAC3C,OAAO,GAAG,OAAO,SAAS,aAAa,GAAG;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useRef } from "react";
|
|
4
|
-
function useConstant(fn) {
|
|
5
|
-
const ref = useRef();
|
|
6
|
-
if (!ref.current) {
|
|
7
|
-
ref.current = { v: fn() };
|
|
8
|
-
}
|
|
9
|
-
return ref.current.v;
|
|
10
|
-
}
|
|
11
|
-
__name(useConstant, "useConstant");
|
|
12
|
-
export {
|
|
13
|
-
useConstant
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=useConstant.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/useConstant.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useRef } from 'react'\n\ntype ResultBox<T> = { v: T }\nexport function useConstant<T>(fn: () => T): T {\n const ref = useRef<ResultBox<T>>()\n if (!ref.current) {\n ref.current = { v: fn() }\n }\n return ref.current.v\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAGO,qBAAwB,IAAgB;AAC7C,QAAM,MAAM;AACZ,MAAI,CAAC,IAAI,SAAS;AAChB,QAAI,UAAU,EAAE,GAAG;AAAA;AAErB,SAAO,IAAI,QAAQ;AAAA;AALL;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { isWeb, useIsomorphicLayoutEffect } from "../constants/platform";
|
|
5
|
-
import { addMediaQueryListener, mediaState, removeMediaQueryListener } from "./useMedia";
|
|
6
|
-
const createDefinition = /* @__PURE__ */ __name(({
|
|
7
|
-
Component,
|
|
8
|
-
propNames
|
|
9
|
-
}) => ({
|
|
10
|
-
isEnabled: (props) => propNames.some((name) => !!props[name]),
|
|
11
|
-
Component
|
|
12
|
-
}), "createDefinition");
|
|
13
|
-
let featureDefinitions = null;
|
|
14
|
-
const useFeatures = /* @__PURE__ */ __name((props, utils) => {
|
|
15
|
-
if (!featureDefinitions) {
|
|
16
|
-
featureDefinitions = loadFeatures();
|
|
17
|
-
}
|
|
18
|
-
const features = [];
|
|
19
|
-
for (const name in featureDefinitions) {
|
|
20
|
-
const { isEnabled, Component } = featureDefinitions[name];
|
|
21
|
-
if (isEnabled(props) && Component) {
|
|
22
|
-
features.push(/* @__PURE__ */ React.createElement(Component, {
|
|
23
|
-
key: name,
|
|
24
|
-
...props,
|
|
25
|
-
_utils: utils
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return features;
|
|
30
|
-
}, "useFeatures");
|
|
31
|
-
function loadFeatures() {
|
|
32
|
-
return {
|
|
33
|
-
...!isWeb && {
|
|
34
|
-
mediaQuery: loadMediaQueryFeature()
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
__name(loadFeatures, "loadFeatures");
|
|
39
|
-
function loadMediaQueryFeature() {
|
|
40
|
-
const mediaPropNames = Object.keys(mediaState);
|
|
41
|
-
return createDefinition({
|
|
42
|
-
Component: (props) => {
|
|
43
|
-
const keys = mediaPropNames.flatMap((x) => x in props ? x.slice(1) : []);
|
|
44
|
-
useIsomorphicLayoutEffect(() => {
|
|
45
|
-
for (const key of keys) {
|
|
46
|
-
addMediaQueryListener(key, props._utils.forceUpdate);
|
|
47
|
-
}
|
|
48
|
-
return () => {
|
|
49
|
-
for (const key of keys) {
|
|
50
|
-
removeMediaQueryListener(key, props._utils.forceUpdate);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}, [keys.join(",")]);
|
|
54
|
-
return null;
|
|
55
|
-
},
|
|
56
|
-
propNames: mediaPropNames
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
__name(loadMediaQueryFeature, "loadMediaQueryFeature");
|
|
60
|
-
export {
|
|
61
|
-
useFeatures
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=useFeatures.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/useFeatures.tsx"],
|
|
4
|
-
"sourcesContent": ["import React from 'react'\n\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { addMediaQueryListener, mediaState, removeMediaQueryListener } from './useMedia'\n\ntype FeatureDefinition = {\n isEnabled: (props: any) => boolean\n Component: any\n}\n\nconst createDefinition = ({\n Component,\n propNames,\n}: {\n Component: any\n propNames: string[]\n}): FeatureDefinition => ({\n isEnabled: (props: any) => propNames.some((name) => !!props[name]),\n Component,\n})\n\nlet featureDefinitions: Record<string, FeatureDefinition> | null = null\n\nexport const useFeatures = (props: any, utils?: { forceUpdate?: Function }) => {\n if (!featureDefinitions) {\n featureDefinitions = loadFeatures()\n }\n const features: JSX.Element[] = []\n for (const name in featureDefinitions) {\n const { isEnabled, Component } = featureDefinitions[name]\n if (isEnabled(props) && Component) {\n features.push(<Component key={name} {...props} _utils={utils} />)\n }\n }\n return features\n}\n\nfunction loadFeatures(): Record<string, FeatureDefinition> {\n return {\n // TODO\n // measureLayout: createDefinition({\n // Component: (props) => {\n // console.log('measure', props)\n // return null\n // },\n // propNames: ['onLayout'],\n // }),\n\n // will update the parent whenever media query changes\n // no need on web, media queries are inserted and run in css\n ...(!isWeb && {\n mediaQuery: loadMediaQueryFeature(),\n }),\n }\n}\n\nfunction loadMediaQueryFeature() {\n const mediaPropNames = Object.keys(mediaState)\n\n return createDefinition({\n Component: (props: any) => {\n const keys = mediaPropNames.flatMap((x) => (x in props ? x.slice(1) : []))\n\n useIsomorphicLayoutEffect(() => {\n for (const key of keys) {\n addMediaQueryListener(key, props._utils.forceUpdate)\n }\n return () => {\n for (const key of keys) {\n removeMediaQueryListener(key, props._utils.forceUpdate)\n }\n }\n }, [keys.join(',')])\n\n return null\n },\n propNames: mediaPropNames,\n })\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEA;AACA;AAOA,MAAM,mBAAmB,wBAAC;AAAA,EACxB;AAAA,EACA;AAAA,MAIwB;AAAA,EACxB,WAAW,CAAC,UAAe,UAAU,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM;AAAA,EAC5D;AAAA,IARuB;AAWzB,IAAI,qBAA+D;AAE5D,MAAM,cAAc,wBAAC,OAAY,UAAuC;AAC7E,MAAI,CAAC,oBAAoB;AACvB,yBAAqB;AAAA;AAEvB,QAAM,WAA0B;AAChC,aAAW,QAAQ,oBAAoB;AACrC,UAAM,EAAE,WAAW,cAAc,mBAAmB;AACpD,QAAI,UAAU,UAAU,WAAW;AACjC,eAAS,KAAK,oCAAC,WAAD;AAAA,QAAW,KAAK;AAAA,WAAU;AAAA,QAAO,QAAQ;AAAA;AAAA;AAAA;AAG3D,SAAO;AAAA,GAXkB;AAc3B,wBAA2D;AACzD,SAAO;AAAA,OAYD,CAAC,SAAS;AAAA,MACZ,YAAY;AAAA;AAAA;AAAA;AAdT;AAmBT,iCAAiC;AAC/B,QAAM,iBAAiB,OAAO,KAAK;AAEnC,SAAO,iBAAiB;AAAA,IACtB,WAAW,CAAC,UAAe;AACzB,YAAM,OAAO,eAAe,QAAQ,CAAC,MAAO,KAAK,QAAQ,EAAE,MAAM,KAAK;AAEtE,gCAA0B,MAAM;AAC9B,mBAAW,OAAO,MAAM;AACtB,gCAAsB,KAAK,MAAM,OAAO;AAAA;AAE1C,eAAO,MAAM;AACX,qBAAW,OAAO,MAAM;AACtB,qCAAyB,KAAK,MAAM,OAAO;AAAA;AAAA;AAAA,SAG9C,CAAC,KAAK,KAAK;AAEd,aAAO;AAAA;AAAA,IAET,WAAW;AAAA;AAAA;AApBN;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useEffect, useRef, useState } from "react";
|
|
4
|
-
function useForceUpdate() {
|
|
5
|
-
const setState = useState(0)[1];
|
|
6
|
-
const internal = useRef();
|
|
7
|
-
if (!internal.current) {
|
|
8
|
-
internal.current = {
|
|
9
|
-
isMounted: true,
|
|
10
|
-
update: () => {
|
|
11
|
-
if (internal.current.isMounted) {
|
|
12
|
-
setState(Math.random());
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
return () => {
|
|
19
|
-
internal.current.isMounted = false;
|
|
20
|
-
};
|
|
21
|
-
}, []);
|
|
22
|
-
return internal.current.update;
|
|
23
|
-
}
|
|
24
|
-
__name(useForceUpdate, "useForceUpdate");
|
|
25
|
-
export {
|
|
26
|
-
useForceUpdate
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=useForceUpdate.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/useForceUpdate.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useRef, useState } from 'react'\n\n// ensures no updates after unmount\n\nexport function useForceUpdate() {\n const setState = useState(0)[1]\n const internal = useRef<{ update: Function; isMounted: boolean }>()\n if (!internal.current) {\n internal.current = {\n isMounted: true,\n update: () => {\n if (internal.current!.isMounted) {\n setState(Math.random())\n }\n },\n }\n }\n\n useEffect(() => {\n return () => {\n internal.current!.isMounted = false\n }\n }, [])\n\n return internal.current.update\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAIO,0BAA0B;AAC/B,QAAM,WAAW,SAAS,GAAG;AAC7B,QAAM,WAAW;AACjB,MAAI,CAAC,SAAS,SAAS;AACrB,aAAS,UAAU;AAAA,MACjB,WAAW;AAAA,MACX,QAAQ,MAAM;AACZ,YAAI,SAAS,QAAS,WAAW;AAC/B,mBAAS,KAAK;AAAA;AAAA;AAAA;AAAA;AAMtB,YAAU,MAAM;AACd,WAAO,MAAM;AACX,eAAS,QAAS,YAAY;AAAA;AAAA,KAE/B;AAEH,SAAO,SAAS,QAAQ;AAAA;AApBV;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/hooks/useMedia.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useForceUpdate } from "@tamagui/use-force-update";
|
|
4
|
-
import { useRef } from "react";
|
|
5
|
-
import { useIsomorphicLayoutEffect } from "../constants/platform";
|
|
6
|
-
import { matchMedia } from "../helpers/matchMedia";
|
|
7
|
-
import { useConstant } from "./useConstant";
|
|
8
|
-
const mediaState = {};
|
|
9
|
-
const mediaQueryListeners = {};
|
|
10
|
-
const addMediaQueryListener = /* @__PURE__ */ __name((key, cb) => {
|
|
11
|
-
mediaQueryListeners[key] = mediaQueryListeners[key] || new Set();
|
|
12
|
-
mediaQueryListeners[key].add(cb);
|
|
13
|
-
}, "addMediaQueryListener");
|
|
14
|
-
const removeMediaQueryListener = /* @__PURE__ */ __name((key, cb) => {
|
|
15
|
-
mediaQueryListeners[key].delete(cb);
|
|
16
|
-
}, "removeMediaQueryListener");
|
|
17
|
-
let conf = null;
|
|
18
|
-
const mediaQueryConfig = new Proxy({}, {
|
|
19
|
-
get(target, key) {
|
|
20
|
-
if (!conf) {
|
|
21
|
-
console.warn("Warning: accessing media query before init");
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
return Reflect.get(conf, key);
|
|
25
|
-
},
|
|
26
|
-
ownKeys() {
|
|
27
|
-
if (!conf) {
|
|
28
|
-
console.warn("Warning: accessing media query before init");
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
return Object.keys(conf);
|
|
32
|
-
},
|
|
33
|
-
getOwnPropertyDescriptor() {
|
|
34
|
-
return {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
const getMedia = /* @__PURE__ */ __name(() => {
|
|
41
|
-
if (!conf) {
|
|
42
|
-
throw new Error(`not configured yet`);
|
|
43
|
-
}
|
|
44
|
-
return mediaState;
|
|
45
|
-
}, "getMedia");
|
|
46
|
-
const configureMedia = /* @__PURE__ */ __name(({
|
|
47
|
-
queries,
|
|
48
|
-
defaultActive = ["sm", "xs"]
|
|
49
|
-
} = {}) => {
|
|
50
|
-
if (conf) {
|
|
51
|
-
console.warn(`Already configured mediaQueries once (you may have called getMedia() before configureMedia())`);
|
|
52
|
-
}
|
|
53
|
-
if (queries) {
|
|
54
|
-
conf = queries;
|
|
55
|
-
}
|
|
56
|
-
for (const key in queries) {
|
|
57
|
-
const str = mediaObjectToString(queries[key]);
|
|
58
|
-
try {
|
|
59
|
-
const getMatch = /* @__PURE__ */ __name(() => matchMedia(str), "getMatch");
|
|
60
|
-
const match = getMatch();
|
|
61
|
-
if (!match || typeof match.addListener !== "function") {
|
|
62
|
-
throw new Error("\u26A0\uFE0F No match (seeing this in RN sometimes)");
|
|
63
|
-
}
|
|
64
|
-
mediaState[key] = !!match.matches;
|
|
65
|
-
match.addListener(() => {
|
|
66
|
-
const next = !!getMatch().matches;
|
|
67
|
-
if (next === mediaState[key])
|
|
68
|
-
return;
|
|
69
|
-
mediaState[key] = next;
|
|
70
|
-
const listeners = mediaQueryListeners[key];
|
|
71
|
-
if (listeners?.size) {
|
|
72
|
-
for (const cb of [...listeners]) {
|
|
73
|
-
cb();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
} catch (err) {
|
|
78
|
-
console.error("Error running media query", str, err.message, err.stack);
|
|
79
|
-
const isDefaultActive = defaultActive?.includes(key) ?? true;
|
|
80
|
-
mediaState[key] = isDefaultActive;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, "configureMedia");
|
|
84
|
-
const useMedia = /* @__PURE__ */ __name(() => {
|
|
85
|
-
const forceUpdate = useForceUpdate();
|
|
86
|
-
const state = useRef();
|
|
87
|
-
if (!state.current) {
|
|
88
|
-
state.current = {
|
|
89
|
-
selections: {},
|
|
90
|
-
nextSelections: {},
|
|
91
|
-
isUnmounted: false,
|
|
92
|
-
isRendering: true
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
state.current.isRendering = true;
|
|
96
|
-
useIsomorphicLayoutEffect(() => {
|
|
97
|
-
const st = state.current;
|
|
98
|
-
st.isRendering = false;
|
|
99
|
-
for (const key in st.selections) {
|
|
100
|
-
if (!(key in st.nextSelections)) {
|
|
101
|
-
removeMediaQueryListener(key, forceUpdate);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
for (const key in st.nextSelections) {
|
|
105
|
-
if (!(key in st.selections)) {
|
|
106
|
-
addMediaQueryListener(key, forceUpdate);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
useIsomorphicLayoutEffect(() => {
|
|
111
|
-
return () => {
|
|
112
|
-
const st = state.current;
|
|
113
|
-
st.isUnmounted = true;
|
|
114
|
-
const allKeys = {
|
|
115
|
-
...st.selections,
|
|
116
|
-
...st.nextSelections
|
|
117
|
-
};
|
|
118
|
-
for (const key in allKeys) {
|
|
119
|
-
removeMediaQueryListener(key, forceUpdate);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}, []);
|
|
123
|
-
return useConstant(() => {
|
|
124
|
-
const st = state.current;
|
|
125
|
-
return new Proxy(mediaState, {
|
|
126
|
-
get(target, key) {
|
|
127
|
-
if (!(key in mediaState)) {
|
|
128
|
-
return Reflect.get(target, key);
|
|
129
|
-
}
|
|
130
|
-
if (!st.isUnmounted) {
|
|
131
|
-
if (st.isRendering) {
|
|
132
|
-
st.nextSelections[key] = true;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (key in mediaState) {
|
|
136
|
-
return mediaState[key];
|
|
137
|
-
}
|
|
138
|
-
return Reflect.get(mediaState, key);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}, "useMedia");
|
|
143
|
-
function camelToHyphen(str) {
|
|
144
|
-
return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase();
|
|
145
|
-
}
|
|
146
|
-
__name(camelToHyphen, "camelToHyphen");
|
|
147
|
-
function mediaObjectToString(query) {
|
|
148
|
-
if (typeof query === "string") {
|
|
149
|
-
return query;
|
|
150
|
-
}
|
|
151
|
-
return Object.entries(query).map(([feature, value]) => {
|
|
152
|
-
feature = camelToHyphen(feature);
|
|
153
|
-
if (typeof value === "string") {
|
|
154
|
-
return `(${feature}: ${value})`;
|
|
155
|
-
}
|
|
156
|
-
if (typeof value === "number" && /[height|width]$/.test(feature)) {
|
|
157
|
-
value = `${value}px`;
|
|
158
|
-
}
|
|
159
|
-
return `(${feature}: ${value})`;
|
|
160
|
-
}).join(" and ");
|
|
161
|
-
}
|
|
162
|
-
__name(mediaObjectToString, "mediaObjectToString");
|
|
163
|
-
export {
|
|
164
|
-
addMediaQueryListener,
|
|
165
|
-
configureMedia,
|
|
166
|
-
getMedia,
|
|
167
|
-
mediaObjectToString,
|
|
168
|
-
mediaQueryConfig,
|
|
169
|
-
mediaState,
|
|
170
|
-
removeMediaQueryListener,
|
|
171
|
-
useMedia
|
|
172
|
-
};
|
|
173
|
-
//# sourceMappingURL=useMedia.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/useMedia.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useRef } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n ConfigureMediaQueryOptions,\n MediaQueries,\n MediaQueryObject,\n MediaQueryState,\n} from '../types'\nimport { useConstant } from './useConstant'\n\nexport const mediaState: { [key in keyof MediaQueryState]: boolean } = {} as any\nconst mediaQueryListeners: { [key: string]: Set<Function> } = {}\n\nexport const addMediaQueryListener = (key: string, cb: any) => {\n mediaQueryListeners[key] = mediaQueryListeners[key] || new Set()\n mediaQueryListeners[key].add(cb)\n}\n\nexport const removeMediaQueryListener = (key: string, cb: any) => {\n mediaQueryListeners[key].delete(cb)\n}\n\nlet conf: MediaQueries | null = null\n\nexport const mediaQueryConfig = new Proxy<MediaQueries>({} as any, {\n get(target, key) {\n if (!conf) {\n console.warn('Warning: accessing media query before init')\n return null\n }\n return Reflect.get(conf, key)\n },\n ownKeys() {\n if (!conf) {\n console.warn('Warning: accessing media query before init')\n return []\n }\n return Object.keys(conf)\n },\n getOwnPropertyDescriptor() {\n return {\n enumerable: true,\n configurable: true,\n }\n },\n})\n\nexport const getMedia = () => {\n if (!conf) {\n throw new Error(`not configured yet`)\n }\n return mediaState\n}\n\nexport const configureMedia = ({\n queries,\n defaultActive = ['sm', 'xs'],\n}: ConfigureMediaQueryOptions = {}) => {\n if (conf) {\n console.warn(\n `Already configured mediaQueries once (you may have called getMedia() before configureMedia())`\n )\n }\n\n if (queries) {\n conf = queries\n }\n\n // setup\n for (const key in queries) {\n const str = mediaObjectToString(queries[key])\n try {\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match || typeof match.addListener !== 'function') {\n // caught below\n throw new Error('\u26A0\uFE0F No match (seeing this in RN sometimes)')\n }\n mediaState[key] = !!match.matches\n match.addListener(() => {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n const listeners = mediaQueryListeners[key]\n if (listeners?.size) {\n for (const cb of [...listeners]) {\n cb()\n }\n }\n })\n } catch (err: any) {\n console.error('Error running media query', str, err.message, err.stack)\n const isDefaultActive = defaultActive?.includes(key as any) ?? true\n mediaState[key] = isDefaultActive\n }\n }\n}\n\ntype UseMediaState = {\n selections: { [key: string]: boolean }\n nextSelections: { [key: string]: boolean }\n isRendering: boolean\n isUnmounted: boolean\n}\n\nexport const useMedia = () => {\n const forceUpdate = useForceUpdate()\n const state = useRef() as React.MutableRefObject<UseMediaState>\n if (!state.current) {\n state.current = {\n selections: {},\n nextSelections: {},\n isUnmounted: false,\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n // delete old\n for (const key in st.selections) {\n if (!(key in st.nextSelections)) {\n removeMediaQueryListener(key, forceUpdate)\n }\n }\n // add new\n for (const key in st.nextSelections) {\n if (!(key in st.selections)) {\n addMediaQueryListener(key, forceUpdate)\n }\n }\n })\n\n // unmount\n useIsomorphicLayoutEffect(() => {\n return () => {\n const st = state.current\n st.isUnmounted = true\n const allKeys = {\n ...st.selections,\n ...st.nextSelections,\n }\n for (const key in allKeys) {\n removeMediaQueryListener(key, forceUpdate)\n }\n }\n }, [])\n\n return useConstant(() => {\n const st = state.current\n return new Proxy(mediaState, {\n get(target, key: string) {\n if (!(key in mediaState)) {\n return Reflect.get(target, key)\n }\n if (!st.isUnmounted) {\n if (st.isRendering) {\n st.nextSelections[key] = true\n }\n }\n if (key in mediaState) {\n return mediaState[key]\n }\n return Reflect.get(mediaState, key)\n },\n })\n })\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join(' and ')\n}\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { Pressable } from "react-native";
|
|
4
|
-
const getPressable = Pressable?.["type"]?.["render"];
|
|
5
|
-
const usePressable = /* @__PURE__ */ __name((props) => {
|
|
6
|
-
const out = getPressable(props);
|
|
7
|
-
const { children, style, ...pressableProps } = out.props;
|
|
8
|
-
return [pressableProps, style];
|
|
9
|
-
}, "usePressable");
|
|
10
|
-
export {
|
|
11
|
-
usePressable
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=usePressable.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/usePressable.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Pressable, PressableProps } from 'react-native'\n\nconst getPressable = Pressable?.['type']?.['render']\n\nexport const usePressable = (props: PressableProps) => {\n const out = getPressable(props)\n const { children, style, ...pressableProps } = out.props\n return [pressableProps, style] as const\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEA,MAAM,eAAe,YAAY,UAAU;AAEpC,MAAM,eAAe,wBAAC,UAA0B;AACrD,QAAM,MAAM,aAAa;AACzB,QAAM,EAAE,UAAU,UAAU,mBAAmB,IAAI;AACnD,SAAO,CAAC,gBAAgB;AAAA,GAHE;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/hooks/useTheme.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useForceUpdate } from "@tamagui/use-force-update";
|
|
4
|
-
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
-
import { useIsomorphicLayoutEffect } from "../constants/platform";
|
|
6
|
-
import { Variable } from "../createVariable";
|
|
7
|
-
import { ThemeContext } from "../views/ThemeContext";
|
|
8
|
-
import { ThemeManagerContext } from "../views/ThemeManagerContext";
|
|
9
|
-
import { GET_DEFAULT_THEME } from "../views/ThemeProvider";
|
|
10
|
-
const areEqualSets = /* @__PURE__ */ __name((a, b) => {
|
|
11
|
-
if (a.size !== b.size)
|
|
12
|
-
return false;
|
|
13
|
-
for (const val in a) {
|
|
14
|
-
if (!b.has(val)) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}, "areEqualSets");
|
|
20
|
-
const useThemeName = /* @__PURE__ */ __name((opts) => {
|
|
21
|
-
const parent = useContext(ThemeManagerContext);
|
|
22
|
-
const [name, setName] = useState(parent.name);
|
|
23
|
-
useIsomorphicLayoutEffect(() => {
|
|
24
|
-
return parent.onChangeTheme((next, manager) => {
|
|
25
|
-
setName(opts?.parent ? manager.parentName : next);
|
|
26
|
-
});
|
|
27
|
-
}, [parent]);
|
|
28
|
-
return name || "light";
|
|
29
|
-
}, "useThemeName");
|
|
30
|
-
const useDefaultThemeName = /* @__PURE__ */ __name(() => {
|
|
31
|
-
return useContext(ThemeContext)[GET_DEFAULT_THEME];
|
|
32
|
-
}, "useDefaultThemeName");
|
|
33
|
-
const useTheme = /* @__PURE__ */ __name(() => {
|
|
34
|
-
const forceUpdate = useForceUpdate();
|
|
35
|
-
const manager = useContext(ThemeManagerContext);
|
|
36
|
-
const themes = useContext(ThemeContext);
|
|
37
|
-
const state = useRef();
|
|
38
|
-
if (!state.current) {
|
|
39
|
-
state.current = {
|
|
40
|
-
uuid: {},
|
|
41
|
-
keys: new Set(),
|
|
42
|
-
isRendering: true
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
state.current.isRendering = true;
|
|
46
|
-
useIsomorphicLayoutEffect(() => {
|
|
47
|
-
const st = state.current;
|
|
48
|
-
st.isRendering = false;
|
|
49
|
-
const cur = manager.keys.get(st.uuid);
|
|
50
|
-
if (!cur || !areEqualSets(st.keys, cur)) {
|
|
51
|
-
manager.track(st.uuid, st.keys);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
return manager.onUpdate(state.current.uuid, forceUpdate);
|
|
56
|
-
}, []);
|
|
57
|
-
const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light;
|
|
58
|
-
return useMemo(() => {
|
|
59
|
-
return new Proxy(theme, {
|
|
60
|
-
get(_, key) {
|
|
61
|
-
const name = manager.name;
|
|
62
|
-
if (!name) {
|
|
63
|
-
return Reflect.get(_, key);
|
|
64
|
-
}
|
|
65
|
-
let activeTheme = themes[name];
|
|
66
|
-
if (!activeTheme) {
|
|
67
|
-
console.error("No theme by name", name, "only:", themes, "keeping current theme");
|
|
68
|
-
activeTheme = theme;
|
|
69
|
-
}
|
|
70
|
-
const val = activeTheme[key];
|
|
71
|
-
if (process.env.NODE_ENV === "development") {
|
|
72
|
-
if (typeof val === "undefined") {
|
|
73
|
-
throw new Error(`No theme value "${String(key)}" in: ${Object.keys(activeTheme)}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (state.current.isRendering) {
|
|
77
|
-
state.current.keys.add(key);
|
|
78
|
-
}
|
|
79
|
-
return new Variable({ val: val.val, name: key });
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}, []);
|
|
83
|
-
}, "useTheme");
|
|
84
|
-
export {
|
|
85
|
-
useDefaultThemeName,
|
|
86
|
-
useTheme,
|
|
87
|
-
useThemeName
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=useTheme.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { Variable } from '../createVariable'\nimport { ThemeName } from '../types'\nimport { ThemeContext } from '../views/ThemeContext'\nimport { ThemeManagerContext } from '../views/ThemeManagerContext'\nimport { GET_DEFAULT_THEME } from '../views/ThemeProvider'\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nconst areEqualSets = (a: Set<string>, b: Set<string>) => {\n if (a.size !== b.size) return false\n for (const val in a) {\n if (!b.has(val)) {\n return false\n }\n }\n return true\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent.name)\n\n useIsomorphicLayoutEffect(() => {\n return parent.onChangeTheme((next, manager) => {\n setName(opts?.parent ? manager.parentName : next)\n })\n }, [parent])\n\n return name || 'light'\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)[GET_DEFAULT_THEME] as any as ThemeName\n}\n\nexport const useTheme = () => {\n const forceUpdate = useForceUpdate()\n const manager = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext)\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = manager.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n manager.track(st.uuid, st.keys)\n }\n })\n\n useEffect(() => {\n return manager.onUpdate(state.current.uuid, forceUpdate)\n }, [])\n\n const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light\n\n return useMemo(\n () => {\n return new Proxy(theme, {\n get(_, key: string) {\n const name = manager.name\n if (!name) {\n return Reflect.get(_, key)\n }\n let activeTheme = themes[name]\n if (!activeTheme) {\n console.error('No theme by name', name, 'only:', themes, 'keeping current theme')\n activeTheme = theme\n }\n const val = activeTheme[key]\n if (process.env.NODE_ENV === 'development') {\n if (typeof val === 'undefined') {\n throw new Error(`No theme value \"${String(key)}\" in: ${Object.keys(activeTheme)}`)\n }\n }\n if (state.current.isRendering) {\n state.current.keys.add(key)\n }\n // TODO costly, can make faster (we need name mapping to og name, but val pointing to new val)\n // console.log('returning new variable', val, key)\n return new Variable({ val: val.val, name: key })\n },\n })\n },\n [\n /* if concurrent mode wanted put manager.name here */\n ]\n )\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAQA,MAAM,eAAe,wBAAC,GAAgB,MAAmB;AACvD,MAAI,EAAE,SAAS,EAAE;AAAM,WAAO;AAC9B,aAAW,OAAO,GAAG;AACnB,QAAI,CAAC,EAAE,IAAI,MAAM;AACf,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA,GAPY;AAUd,MAAM,eAAe,wBAAC,SAA6B;AACxD,QAAM,SAAS,WAAW;AAC1B,QAAM,CAAC,MAAM,WAAW,SAAS,OAAO;AAExC,4BAA0B,MAAM;AAC9B,WAAO,OAAO,cAAc,CAAC,MAAM,YAAY;AAC7C,cAAQ,MAAM,SAAS,QAAQ,aAAa;AAAA;AAAA,KAE7C,CAAC;AAEJ,SAAO,QAAQ;AAAA,GAVW;AAarB,MAAM,sBAAsB,6BAAM;AACvC,SAAO,WAAW,cAAc;AAAA,GADC;AAI5B,MAAM,WAAW,6BAAM;AAC5B,QAAM,cAAc;AACpB,QAAM,UAAU,WAAW;AAC3B,QAAM,SAAS,WAAW;AAC1B,QAAM,QAAQ;AACd,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM;AAAA,MACN,MAAM,IAAI;AAAA,MACV,aAAa;AAAA;AAAA;AAGjB,QAAM,QAAQ,cAAc;AAG5B,4BAA0B,MAAM;AAC9B,UAAM,KAAK,MAAM;AACjB,OAAG,cAAc;AACjB,UAAM,MAAM,QAAQ,KAAK,IAAI,GAAG;AAChC,QAAI,CAAC,OAAO,CAAC,aAAa,GAAG,MAAM,MAAM;AACvC,cAAQ,MAAM,GAAG,MAAM,GAAG;AAAA;AAAA;AAI9B,YAAU,MAAM;AACd,WAAO,QAAQ,SAAS,MAAM,QAAQ,MAAM;AAAA,KAC3C;AAEH,QAAM,QAAS,SAAQ,OAAO,OAAO,QAAQ,QAAQ,OAAO,UAAU,OAAO;AAE7E,SAAO,QACL,MAAM;AACJ,WAAO,IAAI,MAAM,OAAO;AAAA,MACtB,IAAI,GAAG,KAAa;AAClB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,MAAM;AACT,iBAAO,QAAQ,IAAI,GAAG;AAAA;AAExB,YAAI,cAAc,OAAO;AACzB,YAAI,CAAC,aAAa;AAChB,kBAAQ,MAAM,oBAAoB,MAAM,SAAS,QAAQ;AACzD,wBAAc;AAAA;AAEhB,cAAM,MAAM,YAAY;AACxB,YAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAI,OAAO,QAAQ,aAAa;AAC9B,kBAAM,IAAI,MAAM,mBAAmB,OAAO,aAAa,OAAO,KAAK;AAAA;AAAA;AAGvE,YAAI,MAAM,QAAQ,aAAa;AAC7B,gBAAM,QAAQ,KAAK,IAAI;AAAA;AAIzB,eAAO,IAAI,SAAS,EAAE,KAAK,IAAI,KAAK,MAAM;AAAA;AAAA;AAAA,KAIhD;AAAA,GA1DoB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|