@mochi-inc-japan/react-native-stylex-sheet 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ja.md +608 -0
- package/README.md +599 -0
- package/lib/commonjs/index.js +65 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/tests/index.test.js +224 -0
- package/lib/commonjs/tests/index.test.js.map +1 -0
- package/lib/commonjs/tests/media.test.js +226 -0
- package/lib/commonjs/tests/media.test.js.map +1 -0
- package/lib/commonjs/tests/mock.test.js +54 -0
- package/lib/commonjs/tests/mock.test.js.map +1 -0
- package/lib/commonjs/tests/test-utils.js +60 -0
- package/lib/commonjs/tests/test-utils.js.map +1 -0
- package/lib/commonjs/utils/base.js +72 -0
- package/lib/commonjs/utils/base.js.map +1 -0
- package/lib/commonjs/utils/hooks.js +60 -0
- package/lib/commonjs/utils/hooks.js.map +1 -0
- package/lib/commonjs/utils/media.js +69 -0
- package/lib/commonjs/utils/media.js.map +1 -0
- package/lib/commonjs/utils/theme.js +25 -0
- package/lib/commonjs/utils/theme.js.map +1 -0
- package/lib/commonjs/utils/tokens.js +18 -0
- package/lib/commonjs/utils/tokens.js.map +1 -0
- package/lib/commonjs/utils/types.js +6 -0
- package/lib/commonjs/utils/types.js.map +1 -0
- package/lib/commonjs/utils/variant.js +75 -0
- package/lib/commonjs/utils/variant.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/tests/index.test.js +220 -0
- package/lib/module/tests/index.test.js.map +1 -0
- package/lib/module/tests/media.test.js +222 -0
- package/lib/module/tests/media.test.js.map +1 -0
- package/lib/module/tests/mock.test.js +49 -0
- package/lib/module/tests/mock.test.js.map +1 -0
- package/lib/module/tests/test-utils.js +52 -0
- package/lib/module/tests/test-utils.js.map +1 -0
- package/lib/module/utils/base.js +63 -0
- package/lib/module/utils/base.js.map +1 -0
- package/lib/module/utils/hooks.js +52 -0
- package/lib/module/utils/hooks.js.map +1 -0
- package/lib/module/utils/media.js +59 -0
- package/lib/module/utils/media.js.map +1 -0
- package/lib/module/utils/theme.js +16 -0
- package/lib/module/utils/theme.js.map +1 -0
- package/lib/module/utils/tokens.js +11 -0
- package/lib/module/utils/tokens.js.map +1 -0
- package/lib/module/utils/types.js +2 -0
- package/lib/module/utils/types.js.map +1 -0
- package/lib/module/utils/variant.js +65 -0
- package/lib/module/utils/variant.js.map +1 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/tests/check-descriptor.test.d.ts +0 -0
- package/lib/types/tests/index.test.d.ts +1 -0
- package/lib/types/tests/media.test.d.ts +1 -0
- package/lib/types/tests/mock.test.d.ts +1 -0
- package/lib/types/tests/test-utils.d.ts +7 -0
- package/lib/types/tests/utils.d.ts +6 -0
- package/lib/types/utils/base.d.ts +13 -0
- package/lib/types/utils/hooks.d.ts +16 -0
- package/lib/types/utils/index.d.ts +9 -0
- package/lib/types/utils/media.d.ts +5 -0
- package/lib/types/utils/theme.d.ts +14 -0
- package/lib/types/utils/tokens.d.ts +3 -0
- package/lib/types/utils/types.d.ts +28 -0
- package/lib/types/utils/utils.d.ts +4 -0
- package/lib/types/utils/variant.d.ts +50 -0
- package/package.json +132 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createVariantKey","getThemeKey","theme","resolveTheme","target","themeKey","createThemes","themes","Set","size","length","Error","themesObj","reduce","current"],"sources":["theme.ts"],"sourcesContent":["import { RNStyle, VariantStyleSheet } from './types';\nimport { createVariantKey } from './variant';\n\nexport const getThemeKey = (theme: string) => createVariantKey('@theme', theme);\n\nexport const resolveTheme = <\n T extends VariantStyleSheet<any, RNStyle> = VariantStyleSheet<any, any>\n>(\n target: T,\n themeKey: string\n) => target[themeKey];\n\ntype AllowNoKeyAccessObject<R extends Record<string, any>> = {\n [K in keyof R]: R[K];\n} & { [key: string]: undefined };\n\nexport function createThemes<\n const T extends string[]\n>(\n themes: T\n): {\n themes: AllowNoKeyAccessObject<{\n [K in T[number]]: string\n }>\n} {\n if (new Set(themes).size !== themes.length) {\n throw new Error('Themes must be unique');\n }\n const themesObj = themes.reduce((current, theme) => {\n current[theme as T[number]] = getThemeKey(theme);\n return current;\n }, {} as { [K in T[number]]: string });\n return {\n themes: themesObj as AllowNoKeyAccessObject<{\n [K in T[number]]: string\n }>,\n };\n}\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,WAAW;AAE5C,OAAO,MAAMC,WAAW,GAAIC,KAAa,IAAKF,gBAAgB,CAAC,QAAQ,EAAEE,KAAK,CAAC;AAE/E,OAAO,MAAMC,YAAY,GAAGA,CAG1BC,MAAS,EACTC,QAAgB,KACbD,MAAM,CAACC,QAAQ,CAAC;AAMrB,OAAO,SAASC,YAAYA,CAG1BC,MAAS,EAKT;EACA,IAAI,IAAIC,GAAG,CAACD,MAAM,CAAC,CAACE,IAAI,KAAKF,MAAM,CAACG,MAAM,EAAE;IAC1C,MAAM,IAAIC,KAAK,CAAC,uBAAuB,CAAC;EAC1C;EACA,MAAMC,SAAS,GAAGL,MAAM,CAACM,MAAM,CAAC,CAACC,OAAO,EAAEZ,KAAK,KAAK;IAClDY,OAAO,CAACZ,KAAK,CAAc,GAAGD,WAAW,CAACC,KAAK,CAAC;IAChD,OAAOY,OAAO;EAChB,CAAC,EAAE,CAAC,CAAiC,CAAC;EACtC,OAAO;IACLP,MAAM,EAAEK;EAGV,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function defineVars(defaults) {
|
|
2
|
+
return Object.freeze({
|
|
3
|
+
...defaults
|
|
4
|
+
});
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// NOTE: RNでは、build前compileがないので、defineConstsはdefineVarsのAliasとして扱う
|
|
8
|
+
export function defineConsts(consts) {
|
|
9
|
+
return defineVars(consts);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defineVars","defaults","Object","freeze","defineConsts","consts"],"sources":["tokens.ts"],"sourcesContent":["import { VariantStyle } from './types';\n\nexport function defineVars<\n T extends Record<string, string | number | VariantStyle<string | number>>\n>(defaults: T): Readonly<T> {\n return Object.freeze({ ...defaults });\n}\n\n// NOTE: RNでは、build前compileがないので、defineConstsはdefineVarsのAliasとして扱う\nexport function defineConsts<\n T extends Record<string, string | number | VariantStyle<string | number>>\n>(consts: T): Readonly<T> {\n return defineVars(consts);\n}\n"],"mappings":"AAEA,OAAO,SAASA,UAAUA,CAExBC,QAAW,EAAe;EAC1B,OAAOC,MAAM,CAACC,MAAM,CAAC;IAAE,GAAGF;EAAS,CAAC,CAAC;AACvC;;AAEA;AACA,OAAO,SAASG,YAAYA,CAE1BC,MAAS,EAAe;EACxB,OAAOL,UAAU,CAACK,MAAM,CAAC;AAC3B","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { StyleSheet } from 'react-native';\n\nexport type StyleObject = StyleSheet.NamedStyles<any>;\nexport type RNStyle = StyleObject[string];\n\nexport type VariantStyle<S> = { [key: string]: S };\nexport type VariantStyleSheet<Key extends string, S extends RNStyle> = {\n [key in Key]: S;\n};\n\nexport type XRNStyle<S extends RNStyle = RNStyle> = {\n [key in keyof S]: VariantStyle<S[key]> | S[key];\n};\n\ntype ExtractVariantKeys<\n X extends XRNStyle<S>,\n S extends RNStyle = RNStyle\n> = Extract<keyof Extract<X[keyof X], VariantStyle<any>>, string>;\n\nexport type NamedStyles<T = string, R extends RNStyle = RNStyle> = {\n [P in keyof T]: XRNStyle<R>;\n};\n\nexport type XRNStyleSheets<\n X extends NamedStyles<any, S>,\n S extends RNStyle = RNStyle\n> = {\n [key in keyof X]: VariantStyleSheet<ExtractVariantKeys<X[key]>, S>;\n};\n\ntype ExtractPostFix<T extends string> = T extends `@${string}_${infer PostFix}`\n ? PostFix\n : 'default';\n\n// NOTE: This map for keyof (X | Y) = (keyof X & keyof Y) != (keyof X | keyof Y).\n// different object value is composed to union type and keyof is applied later\n// without explicit individual object evaluation by this utility type.\ntype KeysOfUnion<T> = T extends T ? keyof T : never;\n\nexport type Variants<\n A extends Record<string, Record<string, Record<string, any>>>\n> = {\n [key in keyof A]?:\n | number\n | boolean\n | ExtractPostFix<Extract<KeysOfUnion<A[key][keyof A[key]]>, string>>;\n};\n\nexport type VariantValue<S extends RNStyle = RNStyle> = {\n [key in keyof S]: VariantStyle<S[key]>;\n}; // Style Fields\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const createVariantKey = (variantKey, key) => `@${variantKey}_${key}`;
|
|
2
|
+
export const createVariantValue = (variantKey, args) => {
|
|
3
|
+
return Object.entries(args).reduce((current, _ref) => {
|
|
4
|
+
let [key, value] = _ref;
|
|
5
|
+
if (key === 'default') {
|
|
6
|
+
current.default = value;
|
|
7
|
+
} else {
|
|
8
|
+
current[createVariantKey(variantKey, key)] = value;
|
|
9
|
+
}
|
|
10
|
+
return current;
|
|
11
|
+
}, {});
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* INPUT;
|
|
15
|
+
* {
|
|
16
|
+
* shape: {
|
|
17
|
+
* borderRadius: {
|
|
18
|
+
* default: 4,
|
|
19
|
+
* round: 8,
|
|
20
|
+
* square: 0,
|
|
21
|
+
* },
|
|
22
|
+
* fontSize: {
|
|
23
|
+
* default: 14,
|
|
24
|
+
* round: 16,
|
|
25
|
+
* square: 18,
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* OUTPUT;
|
|
30
|
+
* {
|
|
31
|
+
* shape: {
|
|
32
|
+
* borderRadius: {
|
|
33
|
+
* default: 4,
|
|
34
|
+
* @shape_round: 8,
|
|
35
|
+
* @shape_square: 0,
|
|
36
|
+
* },
|
|
37
|
+
* fontSize: {
|
|
38
|
+
* default: 14,
|
|
39
|
+
* @shape_round: 16,
|
|
40
|
+
* @shape_square: 18,
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
**/
|
|
45
|
+
export const createVariants = args => {
|
|
46
|
+
return Object.entries(args).reduce((current, _ref2) => {
|
|
47
|
+
let [variantKey, value] = _ref2;
|
|
48
|
+
current[variantKey] || (current[variantKey] = {});
|
|
49
|
+
Object.entries(value).forEach(_ref3 => {
|
|
50
|
+
let [styleField, variantValue] = _ref3;
|
|
51
|
+
current[variantKey][styleField] = createVariantValue(variantKey, variantValue);
|
|
52
|
+
});
|
|
53
|
+
return current;
|
|
54
|
+
}, {});
|
|
55
|
+
};
|
|
56
|
+
export const variants = (target, variants) => {
|
|
57
|
+
const results = [];
|
|
58
|
+
for (const [variantKey, variantValue] of Object.entries(variants)) {
|
|
59
|
+
if (variantValue === 'default') continue;
|
|
60
|
+
const nextStyle = target[`@${variantKey}_${variantValue}`];
|
|
61
|
+
nextStyle && results.push(nextStyle);
|
|
62
|
+
}
|
|
63
|
+
return results;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=variant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createVariantKey","variantKey","key","createVariantValue","args","Object","entries","reduce","current","_ref","value","default","createVariants","_ref2","forEach","_ref3","styleField","variantValue","variants","target","results","nextStyle","push"],"sources":["variant.ts"],"sourcesContent":["import type {\n RNStyle,\n VariantStyle,\n VariantStyleSheet,\n VariantValue,\n} from './types';\n\ntype CreateVariantValueOutput<\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n K extends string,\n A extends VariantStyle<any>\n> = {\n [key in keyof A as key extends 'default'\n ? 'default'\n : `@${K}_${key & string}`]: A[key];\n};\n\nexport const createVariantKey = (variantKey: string, key: string) =>\n `@${variantKey}_${key}`;\n\nexport const createVariantValue = <\n K extends string,\n A extends VariantStyle<any>\n>(\n variantKey: K,\n args: A\n): CreateVariantValueOutput<K, A> => {\n return Object.entries(args).reduce((current, [key, value]) => {\n if (key === 'default') {\n (current as any).default = value;\n } else {\n (current as any)[createVariantKey(variantKey, key)] = value;\n }\n return current;\n }, {} as CreateVariantValueOutput<K, A>);\n};\n\ntype VariantArg<S extends RNStyle = RNStyle> = Record<\n string, // variantKey\n VariantValue<S>\n>;\n\ntype VariantsOutput<\n A extends Record<string, Record<string, Record<string, any>>>\n> = {\n [key in Extract<keyof A, string>]: {\n [subKey in keyof A[key]]: CreateVariantValueOutput<key, A[key][subKey]>;\n };\n};\n\n/**\n * INPUT;\n * {\n * shape: {\n * borderRadius: {\n * default: 4,\n * round: 8,\n * square: 0,\n * },\n * fontSize: {\n * default: 14,\n * round: 16,\n * square: 18,\n * }\n * }\n * }\n * OUTPUT;\n * {\n * shape: {\n * borderRadius: {\n * default: 4,\n * @shape_round: 8,\n * @shape_square: 0,\n * },\n * fontSize: {\n * default: 14,\n * @shape_round: 16,\n * @shape_square: 18,\n * }\n * }\n * }\n **/\nexport const createVariants = <A extends VariantArg>(\n args: A\n): VariantsOutput<A> => {\n return Object.entries(args).reduce((current, [variantKey, value]) => {\n current[variantKey] ||= {};\n Object.entries(value).forEach(([styleField, variantValue]) => {\n current[variantKey][styleField] = createVariantValue(\n variantKey,\n variantValue\n );\n });\n return current;\n }, {} as Record<string, any>) as VariantsOutput<A>;\n};\n\nexport const variants = <\n V extends { [key: string]: string | number | boolean | undefined },\n T extends VariantStyleSheet<any, RNStyle> = VariantStyleSheet<any, any>\n>(\n target: T,\n variants: V\n): T[keyof T][] => {\n const results = [] as T[keyof T][];\n for (const [variantKey, variantValue] of Object.entries(variants)) {\n if (variantValue === 'default') continue;\n const nextStyle = target[`@${variantKey}_${variantValue}`];\n nextStyle && results.push(nextStyle as T[keyof T]);\n }\n return results;\n};\n"],"mappings":"AAiBA,OAAO,MAAMA,gBAAgB,GAAGA,CAACC,UAAkB,EAAEC,GAAW,KAC9D,IAAID,UAAU,IAAIC,GAAG,EAAE;AAEzB,OAAO,MAAMC,kBAAkB,GAAGA,CAIhCF,UAAa,EACbG,IAAO,KAC4B;EACnC,OAAOC,MAAM,CAACC,OAAO,CAACF,IAAI,CAAC,CAACG,MAAM,CAAC,CAACC,OAAO,EAAAC,IAAA,KAAmB;IAAA,IAAjB,CAACP,GAAG,EAAEQ,KAAK,CAAC,GAAAD,IAAA;IACvD,IAAIP,GAAG,KAAK,SAAS,EAAE;MACpBM,OAAO,CAASG,OAAO,GAAGD,KAAK;IAClC,CAAC,MAAM;MACJF,OAAO,CAASR,gBAAgB,CAACC,UAAU,EAAEC,GAAG,CAAC,CAAC,GAAGQ,KAAK;IAC7D;IACA,OAAOF,OAAO;EAChB,CAAC,EAAE,CAAC,CAAmC,CAAC;AAC1C,CAAC;AAeD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,cAAc,GACzBR,IAAO,IACe;EACtB,OAAOC,MAAM,CAACC,OAAO,CAACF,IAAI,CAAC,CAACG,MAAM,CAAC,CAACC,OAAO,EAAAK,KAAA,KAA0B;IAAA,IAAxB,CAACZ,UAAU,EAAES,KAAK,CAAC,GAAAG,KAAA;IAC9DL,OAAO,CAACP,UAAU,CAAC,KAAnBO,OAAO,CAACP,UAAU,CAAC,GAAK,CAAC,CAAC;IAC1BI,MAAM,CAACC,OAAO,CAACI,KAAK,CAAC,CAACI,OAAO,CAACC,KAAA,IAAgC;MAAA,IAA/B,CAACC,UAAU,EAAEC,YAAY,CAAC,GAAAF,KAAA;MACvDP,OAAO,CAACP,UAAU,CAAC,CAACe,UAAU,CAAC,GAAGb,kBAAkB,CAClDF,UAAU,EACVgB,YACF,CAAC;IACH,CAAC,CAAC;IACF,OAAOT,OAAO;EAChB,CAAC,EAAE,CAAC,CAAwB,CAAC;AAC/B,CAAC;AAED,OAAO,MAAMU,QAAQ,GAAGA,CAItBC,MAAS,EACTD,QAAW,KACM;EACjB,MAAME,OAAO,GAAG,EAAkB;EAClC,KAAK,MAAM,CAACnB,UAAU,EAAEgB,YAAY,CAAC,IAAIZ,MAAM,CAACC,OAAO,CAACY,QAAQ,CAAC,EAAE;IACjE,IAAID,YAAY,KAAK,SAAS,EAAE;IAChC,MAAMI,SAAS,GAAGF,MAAM,CAAC,IAAIlB,UAAU,IAAIgB,YAAY,EAAE,CAAC;IAC1DI,SAAS,IAAID,OAAO,CAACE,IAAI,CAACD,SAAuB,CAAC;EACpD;EACA,OAAOD,OAAO;AAChB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { create, props, mix } from './utils/base';
|
|
2
|
+
export { createVariants } from './utils/variant';
|
|
3
|
+
export { defineConsts, defineVars } from './utils/tokens';
|
|
4
|
+
export { useStylex, RNStyleXProvider } from './utils/hooks';
|
|
5
|
+
export { createThemes } from './utils/theme';
|
|
6
|
+
export type { Variants, XRNStyle, RNStyle, XRNStyleSheets, } from './utils/types';
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function mockDimensions({ width, height, pixelRatio, }: {
|
|
2
|
+
width?: number;
|
|
3
|
+
height?: number;
|
|
4
|
+
pixelRatio?: number;
|
|
5
|
+
}): void;
|
|
6
|
+
export declare function reduceStyles(s: any): any;
|
|
7
|
+
export declare function finalStyle(Component: React.ReactElement): any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { XRNStyleSheets, NamedStyles, RNStyle, VariantStyleSheet } from './types';
|
|
2
|
+
export declare const create: <T extends NamedStyles<any, R>, R extends RNStyle>(args: T) => XRNStyleSheets<T, R>;
|
|
3
|
+
export declare const mix: <Variants extends {
|
|
4
|
+
[key: string]: string | number | boolean | undefined;
|
|
5
|
+
}, Theme extends string = string, T extends VariantStyleSheet<string, RNStyle> = VariantStyleSheet<string, RNStyle>>(target?: T | [T, {
|
|
6
|
+
theme?: Theme;
|
|
7
|
+
media?: number | string;
|
|
8
|
+
}], variantArgs?: Variants) => RNStyle[];
|
|
9
|
+
type PropValue = VariantStyleSheet<string, RNStyle> | RNStyle;
|
|
10
|
+
export declare const props: <T extends RNStyle>(...args: (PropValue | RNStyle[] | false | null | undefined)[]) => {
|
|
11
|
+
style: T[];
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { mix, props } from './base';
|
|
2
|
+
type IApi = {
|
|
3
|
+
props: typeof props;
|
|
4
|
+
mix: typeof mix;
|
|
5
|
+
};
|
|
6
|
+
type UserConfig = {
|
|
7
|
+
windowWidth: number;
|
|
8
|
+
theme: string;
|
|
9
|
+
};
|
|
10
|
+
type ValueType = UserConfig & IApi;
|
|
11
|
+
export declare const RNStyleXProvider: (componentProps: Partial<Pick<ValueType, "windowWidth" | "theme">> & {
|
|
12
|
+
media?: Record<string, string>;
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}) => import("react").FunctionComponentElement<import("react").ProviderProps<ValueType | undefined>>;
|
|
15
|
+
export declare const useStylex: () => ValueType;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { XRNStyleSheets, NamedStyles, RNStyle, VariantStyleSheet } from './types';
|
|
2
|
+
export declare const create: <T extends NamedStyles<any, R>, R extends RNStyle>(args: T) => XRNStyleSheets<T, R>;
|
|
3
|
+
export declare const createVariants: <K extends string, A extends Record<string, RNStyle>>(variantKey: K, args: A) => Record<`@${K}_${keyof A & string}`, RNStyle>;
|
|
4
|
+
export declare const variants: <T extends VariantStyleSheet<any, RNStyle>, V extends Record<string, string>>(target: T, variants: V) => T[keyof T][];
|
|
5
|
+
type PropValue = VariantStyleSheet<string, RNStyle> | RNStyle;
|
|
6
|
+
export declare const props: <T extends RNStyle>(...args: (PropValue | RNStyle[])[]) => {
|
|
7
|
+
style: T[];
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RNStyle, VariantStyleSheet } from './types';
|
|
2
|
+
export type Media = Record<string, string | boolean>;
|
|
3
|
+
export declare const media: <T extends VariantStyleSheet<string, RNStyle>>(target: T, mediaParam: number | string) => T[keyof T][];
|
|
4
|
+
export declare const detectMedia: (mediaKeys: string[] | Record<string, string>, width: number) => string | undefined;
|
|
5
|
+
export declare function matchMediaRangeQuery(query: string, windowWidth: number): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RNStyle, VariantStyleSheet } from './types';
|
|
2
|
+
export declare const getThemeKey: (theme: string) => string;
|
|
3
|
+
export declare const resolveTheme: <T extends VariantStyleSheet<any, RNStyle> = VariantStyleSheet<any, any>>(target: T, themeKey: string) => import("react-native").ViewStyle | import("react-native").TextStyle | import("react-native").ImageStyle;
|
|
4
|
+
type AllowNoKeyAccessObject<R extends Record<string, any>> = {
|
|
5
|
+
[K in keyof R]: R[K];
|
|
6
|
+
} & {
|
|
7
|
+
[key: string]: undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function createThemes<const T extends string[]>(themes: T): {
|
|
10
|
+
themes: AllowNoKeyAccessObject<{
|
|
11
|
+
[K in T[number]]: string;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { VariantStyle } from './types';
|
|
2
|
+
export declare function defineVars<T extends Record<string, string | number | VariantStyle<string | number>>>(defaults: T): Readonly<T>;
|
|
3
|
+
export declare function defineConsts<T extends Record<string, string | number | VariantStyle<string | number>>>(consts: T): Readonly<T>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StyleSheet } from 'react-native';
|
|
2
|
+
export type StyleObject = StyleSheet.NamedStyles<any>;
|
|
3
|
+
export type RNStyle = StyleObject[string];
|
|
4
|
+
export type VariantStyle<S> = {
|
|
5
|
+
[key: string]: S;
|
|
6
|
+
};
|
|
7
|
+
export type VariantStyleSheet<Key extends string, S extends RNStyle> = {
|
|
8
|
+
[key in Key]: S;
|
|
9
|
+
};
|
|
10
|
+
export type XRNStyle<S extends RNStyle = RNStyle> = {
|
|
11
|
+
[key in keyof S]: VariantStyle<S[key]> | S[key];
|
|
12
|
+
};
|
|
13
|
+
type ExtractVariantKeys<X extends XRNStyle<S>, S extends RNStyle = RNStyle> = Extract<keyof Extract<X[keyof X], VariantStyle<any>>, string>;
|
|
14
|
+
export type NamedStyles<T = string, R extends RNStyle = RNStyle> = {
|
|
15
|
+
[P in keyof T]: XRNStyle<R>;
|
|
16
|
+
};
|
|
17
|
+
export type XRNStyleSheets<X extends NamedStyles<any, S>, S extends RNStyle = RNStyle> = {
|
|
18
|
+
[key in keyof X]: VariantStyleSheet<ExtractVariantKeys<X[key]>, S>;
|
|
19
|
+
};
|
|
20
|
+
type ExtractPostFix<T extends string> = T extends `@${string}_${infer PostFix}` ? PostFix : 'default';
|
|
21
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
22
|
+
export type Variants<A extends Record<string, Record<string, Record<string, any>>>> = {
|
|
23
|
+
[key in keyof A]?: number | boolean | ExtractPostFix<Extract<KeysOfUnion<A[key][keyof A[key]]>, string>>;
|
|
24
|
+
};
|
|
25
|
+
export type VariantValue<S extends RNStyle = RNStyle> = {
|
|
26
|
+
[key in keyof S]: VariantStyle<S[key]>;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RNStyle, VariantStyle, VariantStyleSheet, VariantValue } from './types';
|
|
2
|
+
type CreateVariantValueOutput<K extends string, A extends VariantStyle<any>> = {
|
|
3
|
+
[key in keyof A as key extends 'default' ? 'default' : `@${K}_${key & string}`]: A[key];
|
|
4
|
+
};
|
|
5
|
+
export declare const createVariantKey: (variantKey: string, key: string) => string;
|
|
6
|
+
export declare const createVariantValue: <K extends string, A extends VariantStyle<any>>(variantKey: K, args: A) => CreateVariantValueOutput<K, A>;
|
|
7
|
+
type VariantArg<S extends RNStyle = RNStyle> = Record<string, // variantKey
|
|
8
|
+
VariantValue<S>>;
|
|
9
|
+
type VariantsOutput<A extends Record<string, Record<string, Record<string, any>>>> = {
|
|
10
|
+
[key in Extract<keyof A, string>]: {
|
|
11
|
+
[subKey in keyof A[key]]: CreateVariantValueOutput<key, A[key][subKey]>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* INPUT;
|
|
16
|
+
* {
|
|
17
|
+
* shape: {
|
|
18
|
+
* borderRadius: {
|
|
19
|
+
* default: 4,
|
|
20
|
+
* round: 8,
|
|
21
|
+
* square: 0,
|
|
22
|
+
* },
|
|
23
|
+
* fontSize: {
|
|
24
|
+
* default: 14,
|
|
25
|
+
* round: 16,
|
|
26
|
+
* square: 18,
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* OUTPUT;
|
|
31
|
+
* {
|
|
32
|
+
* shape: {
|
|
33
|
+
* borderRadius: {
|
|
34
|
+
* default: 4,
|
|
35
|
+
* @shape_round: 8,
|
|
36
|
+
* @shape_square: 0,
|
|
37
|
+
* },
|
|
38
|
+
* fontSize: {
|
|
39
|
+
* default: 14,
|
|
40
|
+
* @shape_round: 16,
|
|
41
|
+
* @shape_square: 18,
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
**/
|
|
46
|
+
export declare const createVariants: <A extends VariantArg>(args: A) => VariantsOutput<A>;
|
|
47
|
+
export declare const variants: <V extends {
|
|
48
|
+
[key: string]: string | number | boolean | undefined;
|
|
49
|
+
}, T extends VariantStyleSheet<any, RNStyle> = VariantStyleSheet<any, any>>(target: T, variants: V) => T[keyof T][];
|
|
50
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mochi-inc-japan/react-native-stylex-sheet",
|
|
3
|
+
"description": "The modern CSS-in-JS library for React Native",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Tkow",
|
|
7
|
+
"repository": "https://github.com/MOCHI-inc-JAPAN/react-native-stylex-sheet",
|
|
8
|
+
"main": "lib/commonjs/index.js",
|
|
9
|
+
"module": "lib/module/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
".": {
|
|
14
|
+
"require": "./lib/commonjs/index.js",
|
|
15
|
+
"import": "./lib/module/index.js",
|
|
16
|
+
"types": "./lib/types/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=12"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@babel/core": "7.20.7",
|
|
27
|
+
"@babel/runtime": "7.20.7",
|
|
28
|
+
"@changesets/cli": "^2.31.0",
|
|
29
|
+
"@swc/core": "^1.15.33",
|
|
30
|
+
"@swc/jest": "^0.2.39",
|
|
31
|
+
"@testing-library/jest-native": "5.4.3",
|
|
32
|
+
"@testing-library/react-native": "13.3.3",
|
|
33
|
+
"@types/jest": "29.2.5",
|
|
34
|
+
"@types/node": "^18.19.130",
|
|
35
|
+
"@types/react": "^19.2.14",
|
|
36
|
+
"@types/react-native": "^0.70.6",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "4.6.1",
|
|
38
|
+
"@typescript-eslint/parser": "4.6.1",
|
|
39
|
+
"babel-jest": "29.3.1",
|
|
40
|
+
"eslint": "7.31.0",
|
|
41
|
+
"husky": "6.0.0",
|
|
42
|
+
"jest": "29.3.1",
|
|
43
|
+
"metro-react-native-babel-preset": "^0.73.3",
|
|
44
|
+
"npm-watch": "^0.11.0",
|
|
45
|
+
"prettier": "2.3.2",
|
|
46
|
+
"react": "19.2.0",
|
|
47
|
+
"react-native": "0.83.6",
|
|
48
|
+
"react-native-builder-bob": "0.18.1",
|
|
49
|
+
"react-test-renderer": "19.2.0",
|
|
50
|
+
"ts-jest": "^29.4.9",
|
|
51
|
+
"typescript": "6.0.3"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": ">=16",
|
|
55
|
+
"react-native": "*"
|
|
56
|
+
},
|
|
57
|
+
"husky": {
|
|
58
|
+
"hooks": {
|
|
59
|
+
"pre-commit": "npm run format:check"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"react-native-builder-bob": {
|
|
63
|
+
"source": "src",
|
|
64
|
+
"output": "lib",
|
|
65
|
+
"targets": [
|
|
66
|
+
"commonjs",
|
|
67
|
+
"module"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"watch": {
|
|
71
|
+
"build": {
|
|
72
|
+
"patterns": [
|
|
73
|
+
"src"
|
|
74
|
+
],
|
|
75
|
+
"extensions": "js,jsx,ts,tsx"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"eslintIgnore": [
|
|
79
|
+
"node_modules/",
|
|
80
|
+
"lib/"
|
|
81
|
+
],
|
|
82
|
+
"prettier": {
|
|
83
|
+
"printWidth": 80,
|
|
84
|
+
"semi": true,
|
|
85
|
+
"singleQuote": true,
|
|
86
|
+
"tabWidth": 2,
|
|
87
|
+
"trailingComma": "es5"
|
|
88
|
+
},
|
|
89
|
+
"keywords": [
|
|
90
|
+
"android",
|
|
91
|
+
"ios",
|
|
92
|
+
"react",
|
|
93
|
+
"react-native",
|
|
94
|
+
"native",
|
|
95
|
+
"component",
|
|
96
|
+
"components",
|
|
97
|
+
"create",
|
|
98
|
+
"css",
|
|
99
|
+
"css-in-js",
|
|
100
|
+
"javascript",
|
|
101
|
+
"js",
|
|
102
|
+
"object",
|
|
103
|
+
"object-oriented",
|
|
104
|
+
"oo",
|
|
105
|
+
"oocss",
|
|
106
|
+
"oriented",
|
|
107
|
+
"style",
|
|
108
|
+
"styled",
|
|
109
|
+
"styles",
|
|
110
|
+
"stylesheet",
|
|
111
|
+
"stylesheets",
|
|
112
|
+
"theme",
|
|
113
|
+
"themes",
|
|
114
|
+
"theming",
|
|
115
|
+
"token",
|
|
116
|
+
"tokens",
|
|
117
|
+
"type",
|
|
118
|
+
"typed",
|
|
119
|
+
"types",
|
|
120
|
+
"ts",
|
|
121
|
+
"jsx",
|
|
122
|
+
"tsx"
|
|
123
|
+
],
|
|
124
|
+
"scripts": {
|
|
125
|
+
"build": "bob build && tsc -p tsconfig.build.json",
|
|
126
|
+
"release": "np --any-branch",
|
|
127
|
+
"watch": "npm-watch",
|
|
128
|
+
"test": "jest",
|
|
129
|
+
"format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
130
|
+
"format:write": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\""
|
|
131
|
+
}
|
|
132
|
+
}
|