boss-css 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +1 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  3. package/dist/_virtual/rolldown_runtime.mjs +20 -0
  4. package/dist/api/browser.cjs +54 -0
  5. package/dist/api/browser.mjs +48 -0
  6. package/dist/api/config.cjs +94 -0
  7. package/dist/api/config.mjs +91 -0
  8. package/dist/api/css.cjs +304 -0
  9. package/dist/api/css.mjs +303 -0
  10. package/dist/api/dictionary.cjs +218 -0
  11. package/dist/api/dictionary.mjs +215 -0
  12. package/dist/api/file/dts.cjs +21 -0
  13. package/dist/api/file/dts.mjs +21 -0
  14. package/dist/api/file/file.cjs +123 -0
  15. package/dist/api/file/file.mjs +120 -0
  16. package/dist/api/file/js.cjs +118 -0
  17. package/dist/api/file/js.mjs +116 -0
  18. package/dist/api/names.cjs +52 -0
  19. package/dist/api/names.mjs +46 -0
  20. package/dist/api/noopCss.cjs +37 -0
  21. package/dist/api/noopCss.mjs +36 -0
  22. package/dist/api/propTree.cjs +54 -0
  23. package/dist/api/propTree.mjs +48 -0
  24. package/dist/api/server.cjs +112 -0
  25. package/dist/api/server.mjs +106 -0
  26. package/dist/cli/build.cjs +1 -0
  27. package/dist/cli/build.mjs +3 -0
  28. package/dist/cli/index.cjs +30 -0
  29. package/dist/cli/index.mjs +29 -0
  30. package/dist/cli/tasks/build.cjs +24 -0
  31. package/dist/cli/tasks/build.mjs +23 -0
  32. package/dist/cli/tasks/choose.cjs +47 -0
  33. package/dist/cli/tasks/choose.mjs +46 -0
  34. package/dist/cli/tasks/compile.cjs +68 -0
  35. package/dist/cli/tasks/compile.mjs +67 -0
  36. package/dist/cli/tasks/dev.cjs +51 -0
  37. package/dist/cli/tasks/dev.mjs +48 -0
  38. package/dist/cli/tasks/init.cjs +1835 -0
  39. package/dist/cli/tasks/init.mjs +1831 -0
  40. package/dist/cli/tasks/watch.cjs +38 -0
  41. package/dist/cli/tasks/watch.mjs +37 -0
  42. package/dist/cli/templates/init.cjs +82 -0
  43. package/dist/cli/templates/init.mjs +78 -0
  44. package/dist/cli/types.cjs +13 -0
  45. package/dist/cli/types.mjs +13 -0
  46. package/dist/cli/utils.cjs +43 -0
  47. package/dist/cli/utils.mjs +41 -0
  48. package/dist/compile/classname-strategy.cjs +79 -0
  49. package/dist/compile/classname-strategy.mjs +77 -0
  50. package/dist/compile/classname.cjs +366 -0
  51. package/dist/compile/classname.mjs +360 -0
  52. package/dist/compile/index.cjs +238 -0
  53. package/dist/compile/index.mjs +235 -0
  54. package/dist/compile/jsx.cjs +803 -0
  55. package/dist/compile/jsx.mjs +800 -0
  56. package/dist/compile/prepared.cjs +88 -0
  57. package/dist/compile/prepared.mjs +87 -0
  58. package/dist/compile/runtime.cjs +33 -0
  59. package/dist/compile/runtime.mjs +32 -0
  60. package/dist/compile/transform.cjs +371 -0
  61. package/dist/compile/transform.mjs +369 -0
  62. package/dist/cx/index.cjs +93 -0
  63. package/dist/cx/index.mjs +85 -0
  64. package/dist/detect-fw/index.cjs +384 -0
  65. package/dist/detect-fw/index.mjs +379 -0
  66. package/dist/dev/client.cjs +39 -0
  67. package/dist/dev/client.mjs +38 -0
  68. package/dist/dev/plugin/browser.cjs +11 -0
  69. package/dist/dev/plugin/browser.mjs +9 -0
  70. package/dist/dev/plugin/server.cjs +86 -0
  71. package/dist/dev/plugin/server.mjs +78 -0
  72. package/dist/dev/port.cjs +46 -0
  73. package/dist/dev/port.mjs +43 -0
  74. package/dist/dev/runtime.cjs +28 -0
  75. package/dist/dev/runtime.mjs +29 -0
  76. package/dist/dev/server.cjs +808 -0
  77. package/dist/dev/server.mjs +805 -0
  78. package/dist/dev/shared.cjs +6 -0
  79. package/dist/dev/shared.mjs +5 -0
  80. package/dist/eslint-plugin/index.cjs +66 -0
  81. package/dist/eslint-plugin/index.mjs +66 -0
  82. package/dist/eslint-plugin/rules/classnames-only.cjs +68 -0
  83. package/dist/eslint-plugin/rules/classnames-only.mjs +68 -0
  84. package/dist/eslint-plugin/rules/format-classnames.cjs +137 -0
  85. package/dist/eslint-plugin/rules/format-classnames.mjs +136 -0
  86. package/dist/eslint-plugin/rules/no-unknown-classes.cjs +119 -0
  87. package/dist/eslint-plugin/rules/no-unknown-classes.mjs +119 -0
  88. package/dist/eslint-plugin/rules/prefer-classnames.cjs +69 -0
  89. package/dist/eslint-plugin/rules/prefer-classnames.mjs +69 -0
  90. package/dist/eslint-plugin/rules/prefer-token-values.cjs +197 -0
  91. package/dist/eslint-plugin/rules/prefer-token-values.mjs +197 -0
  92. package/dist/eslint-plugin/rules/props-only.cjs +115 -0
  93. package/dist/eslint-plugin/rules/props-only.mjs +115 -0
  94. package/dist/eslint-plugin/rules/redundant-cx.cjs +66 -0
  95. package/dist/eslint-plugin/rules/redundant-cx.mjs +66 -0
  96. package/dist/eslint-plugin/rules/require-prop-functions.cjs +130 -0
  97. package/dist/eslint-plugin/rules/require-prop-functions.mjs +130 -0
  98. package/dist/eslint-plugin/utils/api.cjs +30 -0
  99. package/dist/eslint-plugin/utils/api.mjs +29 -0
  100. package/dist/eslint-plugin/utils/ast.cjs +119 -0
  101. package/dist/eslint-plugin/utils/ast.mjs +112 -0
  102. package/dist/eslint-plugin/utils/boss-classes.cjs +185 -0
  103. package/dist/eslint-plugin/utils/boss-classes.mjs +175 -0
  104. package/dist/eslint-plugin/utils/defaults.cjs +99 -0
  105. package/dist/eslint-plugin/utils/defaults.mjs +93 -0
  106. package/dist/eslint-plugin/utils/format.cjs +20 -0
  107. package/dist/eslint-plugin/utils/format.mjs +19 -0
  108. package/dist/eslint-plugin/utils/order.cjs +76 -0
  109. package/dist/eslint-plugin/utils/order.mjs +76 -0
  110. package/dist/eslint-plugin/utils/property-order.cjs +449 -0
  111. package/dist/eslint-plugin/utils/property-order.mjs +448 -0
  112. package/dist/eslint-plugin/utils/static.cjs +36 -0
  113. package/dist/eslint-plugin/utils/static.mjs +35 -0
  114. package/dist/fontsource/directory.cjs +39588 -0
  115. package/dist/fontsource/directory.mjs +39587 -0
  116. package/dist/fontsource/server.cjs +291 -0
  117. package/dist/fontsource/server.mjs +282 -0
  118. package/dist/index.cjs +10 -0
  119. package/dist/index.mjs +6 -0
  120. package/dist/log/browser.cjs +28 -0
  121. package/dist/log/browser.mjs +28 -0
  122. package/dist/log/server.cjs +32 -0
  123. package/dist/log/server.mjs +30 -0
  124. package/dist/merge/index.cjs +590 -0
  125. package/dist/merge/index.mjs +586 -0
  126. package/dist/native/browser.cjs +78 -0
  127. package/dist/native/browser.mjs +77 -0
  128. package/dist/native/server.cjs +180 -0
  129. package/dist/native/server.mjs +176 -0
  130. package/dist/native/styleTypes.cjs +168 -0
  131. package/dist/native/styleTypes.mjs +164 -0
  132. package/dist/parser/classname/server.cjs +239 -0
  133. package/dist/parser/classname/server.mjs +232 -0
  134. package/dist/parser/jsx/browser.cjs +66 -0
  135. package/dist/parser/jsx/browser.mjs +63 -0
  136. package/dist/parser/jsx/extractCode.cjs +99 -0
  137. package/dist/parser/jsx/extractCode.mjs +98 -0
  138. package/dist/parser/jsx/extractPrepared.cjs +123 -0
  139. package/dist/parser/jsx/extractPrepared.mjs +122 -0
  140. package/dist/parser/jsx/extractProps.cjs +234 -0
  141. package/dist/parser/jsx/extractProps.mjs +232 -0
  142. package/dist/parser/jsx/isDOMProp.cjs +17 -0
  143. package/dist/parser/jsx/isDOMProp.mjs +15 -0
  144. package/dist/parser/jsx/native.cjs +110 -0
  145. package/dist/parser/jsx/native.mjs +108 -0
  146. package/dist/parser/jsx/runtime.cjs +4 -0
  147. package/dist/parser/jsx/runtime.mjs +3 -0
  148. package/dist/parser/jsx/server.cjs +278 -0
  149. package/dist/parser/jsx/server.mjs +268 -0
  150. package/dist/postcss/index.cjs +16 -0
  151. package/dist/postcss/index.mjs +16 -0
  152. package/dist/prop/at/runtime-only.cjs +90 -0
  153. package/dist/prop/at/runtime-only.mjs +88 -0
  154. package/dist/prop/at/server.cjs +282 -0
  155. package/dist/prop/at/server.mjs +268 -0
  156. package/dist/prop/at/shared.cjs +153 -0
  157. package/dist/prop/at/shared.mjs +144 -0
  158. package/dist/prop/bosswind/browser.cjs +18 -0
  159. package/dist/prop/bosswind/browser.mjs +16 -0
  160. package/dist/prop/bosswind/runtime-only.cjs +18 -0
  161. package/dist/prop/bosswind/runtime-only.mjs +16 -0
  162. package/dist/prop/bosswind/server.cjs +81 -0
  163. package/dist/prop/bosswind/server.mjs +72 -0
  164. package/dist/prop/bosswind/shared.cjs +861 -0
  165. package/dist/prop/bosswind/shared.mjs +855 -0
  166. package/dist/prop/bosswind/tailwind-theme.cjs +703 -0
  167. package/dist/prop/bosswind/tailwind-theme.mjs +702 -0
  168. package/dist/prop/child/runtime-only.cjs +18 -0
  169. package/dist/prop/child/runtime-only.mjs +15 -0
  170. package/dist/prop/child/server.cjs +81 -0
  171. package/dist/prop/child/server.mjs +72 -0
  172. package/dist/prop/css/getDtsTemplate.cjs +65 -0
  173. package/dist/prop/css/getDtsTemplate.mjs +63 -0
  174. package/dist/prop/css/runtime-only.cjs +14 -0
  175. package/dist/prop/css/runtime-only.mjs +13 -0
  176. package/dist/prop/css/server.cjs +99 -0
  177. package/dist/prop/css/server.mjs +90 -0
  178. package/dist/prop/pseudo/runtime-only.cjs +23 -0
  179. package/dist/prop/pseudo/runtime-only.mjs +21 -0
  180. package/dist/prop/pseudo/server.cjs +91 -0
  181. package/dist/prop/pseudo/server.mjs +82 -0
  182. package/dist/prop/pseudo/shared.cjs +61 -0
  183. package/dist/prop/pseudo/shared.mjs +60 -0
  184. package/dist/reset/server.cjs +34 -0
  185. package/dist/reset/server.mjs +26 -0
  186. package/dist/runtime/index.cjs +119 -0
  187. package/dist/runtime/index.mjs +118 -0
  188. package/dist/runtime/preact.cjs +4 -0
  189. package/dist/runtime/preact.mjs +3 -0
  190. package/dist/runtime/qwik.cjs +21 -0
  191. package/dist/runtime/qwik.mjs +18 -0
  192. package/dist/runtime/react.cjs +4 -0
  193. package/dist/runtime/react.mjs +3 -0
  194. package/dist/runtime/solid.cjs +15 -0
  195. package/dist/runtime/solid.mjs +14 -0
  196. package/dist/runtime/stencil.cjs +25 -0
  197. package/dist/runtime/stencil.mjs +21 -0
  198. package/dist/runtime/style.cjs +14 -0
  199. package/dist/runtime/style.mjs +13 -0
  200. package/dist/shared/boundaries.cjs +288 -0
  201. package/dist/shared/boundaries.mjs +285 -0
  202. package/dist/shared/customCss.cjs +212 -0
  203. package/dist/shared/customCss.mjs +211 -0
  204. package/dist/shared/debug.cjs +76 -0
  205. package/dist/shared/debug.mjs +74 -0
  206. package/dist/shared/file.cjs +21 -0
  207. package/dist/shared/file.mjs +19 -0
  208. package/dist/shared/framework.cjs +10 -0
  209. package/dist/shared/framework.mjs +9 -0
  210. package/dist/shared/json.cjs +58 -0
  211. package/dist/shared/json.mjs +57 -0
  212. package/dist/shared/types.cjs +11 -0
  213. package/dist/shared/types.mjs +10 -0
  214. package/dist/strategy/classic/runtime-only.cjs +190 -0
  215. package/dist/strategy/classic/runtime-only.mjs +186 -0
  216. package/dist/strategy/classname-first/runtime-only.cjs +138 -0
  217. package/dist/strategy/classname-first/runtime-only.mjs +134 -0
  218. package/dist/strategy/classname-first/server.cjs +139 -0
  219. package/dist/strategy/classname-first/server.mjs +133 -0
  220. package/dist/strategy/classname-only/server.cjs +43 -0
  221. package/dist/strategy/classname-only/server.mjs +35 -0
  222. package/dist/strategy/inline-first/browser.cjs +61 -0
  223. package/dist/strategy/inline-first/browser.mjs +58 -0
  224. package/dist/strategy/inline-first/runtime-only.cjs +159 -0
  225. package/dist/strategy/inline-first/runtime-only.mjs +155 -0
  226. package/dist/strategy/inline-first/server.cjs +92 -0
  227. package/dist/strategy/inline-first/server.mjs +83 -0
  228. package/dist/strategy/runtime/runtime-only.cjs +24 -0
  229. package/dist/strategy/runtime/runtime-only.mjs +22 -0
  230. package/dist/strategy/runtime/server.cjs +72 -0
  231. package/dist/strategy/runtime/server.mjs +63 -0
  232. package/dist/strategy/runtime-only/css.cjs +183 -0
  233. package/dist/strategy/runtime-only/css.mjs +181 -0
  234. package/dist/tasks/build.cjs +88 -0
  235. package/dist/tasks/build.mjs +84 -0
  236. package/dist/tasks/compile.cjs +12 -0
  237. package/dist/tasks/compile.mjs +12 -0
  238. package/dist/tasks/postcss.cjs +116 -0
  239. package/dist/tasks/postcss.mjs +113 -0
  240. package/dist/tasks/session.cjs +46 -0
  241. package/dist/tasks/session.mjs +42 -0
  242. package/dist/tasks/watch.cjs +102 -0
  243. package/dist/tasks/watch.mjs +99 -0
  244. package/dist/transform/cache.cjs +24 -0
  245. package/dist/transform/cache.mjs +21 -0
  246. package/dist/transform/processFile.cjs +26 -0
  247. package/dist/transform/processFile.mjs +24 -0
  248. package/dist/use/token/browser.cjs +65 -0
  249. package/dist/use/token/browser.mjs +61 -0
  250. package/dist/use/token/runtime-only.cjs +245 -0
  251. package/dist/use/token/runtime-only.mjs +239 -0
  252. package/dist/use/token/server.cjs +325 -0
  253. package/dist/use/token/server.mjs +313 -0
  254. package/dist/use/token/vars.cjs +47 -0
  255. package/dist/use/token/vars.mjs +46 -0
  256. package/package.json +300 -4
  257. package/src/api/config.d.ts +1 -0
  258. package/src/fontsource/types.d.ts +50 -0
  259. package/src/packages/document-create-element/createElement.browser.js +3 -0
  260. package/src/packages/document-create-element/createElement.js +7 -0
  261. package/src/packages/document-create-element/package.json +17 -0
  262. package/src/packages/is-css-prop/browser.js +13 -0
  263. package/src/packages/is-css-prop/index.js +13 -0
  264. package/src/packages/is-css-prop/package-lock.json +52 -0
  265. package/src/packages/is-css-prop/package.json +17 -0
  266. package/src/prop/css/csstype.json +4387 -0
  267. package/src/prop/css/package.json +3 -0
  268. package/src/reset/reset.css +259 -0
@@ -0,0 +1,77 @@
1
+ import { resolveRuntimeToken } from "../use/token/runtime-only.mjs";
2
+
3
+ //#region src/native/browser.ts
4
+ const ignoredProps = new Set([
5
+ "ref",
6
+ "children",
7
+ "as",
8
+ "className",
9
+ "css",
10
+ "child",
11
+ "at",
12
+ "pseudo"
13
+ ]);
14
+ const isNumericValue = (value) => {
15
+ if (typeof value === "number") return true;
16
+ if (typeof value !== "string") return false;
17
+ return /^-?\d+(?:\.\d+)?$/.test(value);
18
+ };
19
+ const normalizeValue = (value) => {
20
+ if (Array.isArray(value)) return value.map((entry) => normalizeValue(entry));
21
+ if (isNumericValue(value)) return typeof value === "string" ? Number(value) : value;
22
+ return value;
23
+ };
24
+ const getStyleProps = (api) => {
25
+ if (!api.nativeStyleProps) return /* @__PURE__ */ new Set();
26
+ api.nativeStylePropSet ??= new Set(api.nativeStyleProps);
27
+ return api.nativeStylePropSet;
28
+ };
29
+ const name = "native";
30
+ const onBrowserObjectStart = (api, { input, output = {} }) => {
31
+ const styleProps = getStyleProps(api);
32
+ const bossStyle = {};
33
+ let hasBossStyle = false;
34
+ for (const prop in input) {
35
+ if (ignoredProps.has(prop)) {
36
+ delete input[prop];
37
+ continue;
38
+ }
39
+ if (prop === "style") {
40
+ output.style = input[prop];
41
+ delete input[prop];
42
+ continue;
43
+ }
44
+ if (!styleProps.has(prop)) {
45
+ output[prop] = input[prop];
46
+ delete input[prop];
47
+ continue;
48
+ }
49
+ let value = input[prop];
50
+ if (typeof value === "function") value = value();
51
+ const token = resolveRuntimeToken(api, prop, value);
52
+ if (token) value = token.value;
53
+ bossStyle[prop] = normalizeValue(value);
54
+ hasBossStyle = true;
55
+ delete input[prop];
56
+ }
57
+ if (!hasBossStyle) return;
58
+ if (!output.style) {
59
+ output.style = bossStyle;
60
+ return;
61
+ }
62
+ if (Array.isArray(output.style)) {
63
+ output.style = [...output.style, bossStyle];
64
+ return;
65
+ }
66
+ if (typeof output.style === "object") {
67
+ output.style = {
68
+ ...output.style,
69
+ ...bossStyle
70
+ };
71
+ return;
72
+ }
73
+ output.style = [output.style, bossStyle];
74
+ };
75
+
76
+ //#endregion
77
+ export { name, onBrowserObjectStart };
@@ -0,0 +1,180 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_extractCode = require('../parser/jsx/extractCode.cjs');
3
+ const require_extractPrepared = require('../parser/jsx/extractPrepared.cjs');
4
+ const require_extractProps = require('../parser/jsx/extractProps.cjs');
5
+ const require_styleTypes = require('./styleTypes.cjs');
6
+ let ts_deepmerge = require("ts-deepmerge");
7
+
8
+ //#region src/native/server.ts
9
+ const name = "native";
10
+ const settings = new Map([
11
+ ["name", "$$"],
12
+ ["globals", true],
13
+ ["emitRuntime", false]
14
+ ]);
15
+ const nativeComponentNames = [
16
+ "ActivityIndicator",
17
+ "FlatList",
18
+ "Image",
19
+ "Modal",
20
+ "Pressable",
21
+ "SafeAreaView",
22
+ "ScrollView",
23
+ "SectionList",
24
+ "Switch",
25
+ "Text",
26
+ "TextInput",
27
+ "TouchableHighlight",
28
+ "TouchableOpacity",
29
+ "TouchableWithoutFeedback",
30
+ "View"
31
+ ];
32
+ const defaultTokens = { color: {
33
+ black: "#000",
34
+ white: "#fff"
35
+ } };
36
+ let needsRuntime = false;
37
+ const preparedComponents = /* @__PURE__ */ new Map();
38
+ const syncPreparedDts = (api) => {
39
+ const entries = Array.from(preparedComponents.entries()).sort(([a], [b]) => a.localeCompare(b));
40
+ const lines = ["interface $$Prepared {"];
41
+ for (const [name] of entries) {
42
+ const baseType = "DefaultNativeElement";
43
+ const getterType = `BaseFn<${baseType}>`;
44
+ const setterType = `$$PreparedDefinitionForSet<${baseType}>`;
45
+ lines.push(` get ${name}(): ${getterType};`);
46
+ lines.push(` set ${name}(value: ${setterType});`);
47
+ }
48
+ lines.push("}");
49
+ api.file.native.dts.set("body", "jsx:prepared-interface", lines.join("\n"));
50
+ };
51
+ const onBoot = async (api) => {
52
+ preparedComponents.clear();
53
+ needsRuntime = false;
54
+ const needsRuntimeTest = () => needsRuntime || settings.get("emitRuntime") === true;
55
+ const proxyVar = api.file.native.import({
56
+ name: "proxy",
57
+ from: "boss-css/parser/jsx/native"
58
+ }, needsRuntimeTest);
59
+ api.file.native.importAndConfig({
60
+ name: "onBrowserObjectStart",
61
+ from: "boss-css/native/browser"
62
+ }, needsRuntimeTest);
63
+ settings.get("globals") && api.file.native.set("body", "jsx:globalThis", `globalThis.${settings.get("name")} = ${proxyVar}`, needsRuntimeTest);
64
+ api.file.native.set("body", "jsx:export-const", `export const ${settings.get("name")} = ${proxyVar}`, needsRuntimeTest);
65
+ api.file.native.set("foot", "jsx:export-default", `export default ${proxyVar}`, needsRuntimeTest);
66
+ const tokenCreatorVar = api.file.native.import({
67
+ name: "create",
68
+ from: "boss-css/use/token/runtime-only"
69
+ }, needsRuntimeTest);
70
+ api.file.native.set("foot", "token:$$.token", `$$.token = ${tokenCreatorVar}()`, needsRuntimeTest);
71
+ const { props } = await require_styleTypes.loadReactNativeStyleProps();
72
+ const nativeStyleProps = Array.from(props.keys()).sort();
73
+ const mergedTokens = (0, ts_deepmerge.merge)(defaultTokens, api.tokens ?? {});
74
+ api.file.native.config({
75
+ from: "boss-css/native",
76
+ config: {
77
+ nativeStyleProps,
78
+ tokens: mergedTokens,
79
+ runtime: { only: true }
80
+ }
81
+ }, needsRuntimeTest);
82
+ api.file.native.dts.set("head", "jsx:runtime", `import type React from 'react'`);
83
+ api.file.native.dts.set("head", "jsx:native-components", `import type { ${nativeComponentNames.join(", ")} } from 'react-native'`);
84
+ api.file.native.dts.set("body", "jsx:utils", `type AsProp<C extends React.ElementType> = {
85
+ as?: C
86
+ }
87
+ type PropsToOmit<C extends React.ElementType, P> = keyof (AsProp<C> & P)
88
+ type PolymorphicComponentProp<C extends React.ElementType, Props = {}> = React.PropsWithChildren<Props & AsProp<C>> &
89
+ Omit<React.ComponentPropsWithoutRef<C>, PropsToOmit<C, Props>>
90
+ type PolymorphicComponentPropWithRef<C extends React.ElementType, Props = {}> = PolymorphicComponentProp<C, Props> & {
91
+ ref?: PolymorphicRef<C>
92
+ }
93
+ type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref']
94
+
95
+ type DefaultNativeElement = typeof View
96
+ type $$JSXFinalProps<C extends React.ElementType> = PolymorphicComponentPropWithRef<C, $$FinalProps>
97
+ declare const $$PreparedBrand: unique symbol
98
+ type $$PreparedProps<Base extends React.ElementType = DefaultNativeElement, C extends React.ElementType = Base> = Omit<
99
+ $$JSXFinalProps<C>,
100
+ 'children' | 'ref'
101
+ > &
102
+ (C extends Base ? { as?: C } : { as: C })
103
+ type $$PreparedDefinition<Base extends React.ElementType = DefaultNativeElement, C extends React.ElementType = Base> =
104
+ $$PreparedProps<Base, C> & { readonly [typeof $$PreparedBrand]: true }
105
+ type $$PreparedDefinitionForSet<Base extends React.ElementType = DefaultNativeElement> =
106
+ | $$PreparedDefinition<Base, Base>
107
+ | {
108
+ [K in keyof JSX.IntrinsicElements]: $$PreparedDefinition<Base, K> & { as: K }
109
+ }[keyof JSX.IntrinsicElements]
110
+ type $$NoopFn = {
111
+ (props: $$PreparedProps<DefaultNativeElement, DefaultNativeElement>): $$PreparedDefinition<DefaultNativeElement, DefaultNativeElement>
112
+ <C extends React.ElementType>(props: $$PreparedProps<DefaultNativeElement, C> & { as: C }): $$PreparedDefinition<DefaultNativeElement, C>
113
+ (input: string): string
114
+ }
115
+ type StyleFn = {
116
+ (...inputs: $$FinalProps[]): BossComponentProps<DefaultNativeElement>
117
+ }
118
+ type CssFn = {
119
+ (input: TemplateStringsArray, ...exprs: unknown[]): void
120
+ (input: string | Record<string, unknown>): void
121
+ }
122
+
123
+ type NativeComponentMap = {
124
+ ${nativeComponentNames.map((name) => ` ${name}: typeof ${name};`).join("\n")}
125
+ }
126
+
127
+ type BaseFn<T extends React.ElementType = DefaultNativeElement> = {
128
+ <C extends React.ElementType = T, L extends React.LegacyRef>(
129
+ props: $$JSXFinalProps<C>,
130
+ contexts?: L,
131
+ ): L extends React.LegacyRef ? React.ReactNode : $$FinalProps
132
+ }`);
133
+ syncPreparedDts(api);
134
+ api.file.native.dts.set("body", "jsx:proxy-start", `type ProxyCustomMembers = {
135
+ `).set("body", "jsx:proxy-utils", ` $: $$NoopFn
136
+ merge: (...inputs: import('boss-css/merge').MergeInput[]) => import('boss-css/merge').MergeOutput
137
+ cx: (...inputs: import('boss-css/cx').CxValue[]) => string
138
+ cv: typeof import('boss-css/cx').cv
139
+ scv: typeof import('boss-css/cx').scv
140
+ sv: typeof import('boss-css/cx').sv
141
+ css: CssFn
142
+ style: StyleFn
143
+ `).set("body", "jsx:proxy-custom-members", ``).set("body", "jsx:proxy-custom-members-end", `}`).set("body", "jsx:proxy-type", `type Proxy = BaseFn & {
144
+ [T in keyof NativeComponentMap]: BaseFn<NativeComponentMap[T]>
145
+ } & $$Prepared & ProxyCustomMembers`);
146
+ api.file.native.dts.set("foot", "jsx:export", `export declare const $$: Proxy`);
147
+ if (settings.get("globals")) api.file.native.dts.set("foot", "jsx:globals", `declare global {
148
+ const $$: Proxy
149
+ }`);
150
+ api.file.native.dts.set("foot", "$$:default-export", `export default $$`);
151
+ api.file.native.dts.set("body", "native:StylePropsInterfaceStart", `export interface $$NativeStyleProps {`);
152
+ for (const [name, prop] of props.entries()) {
153
+ if (prop.description) api.file.native.dts.set("body", `native:${name}:description`, ` /**\n * ${prop.description}\n */`);
154
+ api.file.native.dts.set("body", `native:${name}:declaration`, ` ${name}?: $$PropValues | ${prop.type};\n`);
155
+ }
156
+ api.file.native.dts.set("body", "native:StylePropsInterfaceEnd", `}`);
157
+ api.file.native.dts.replace("body", `$$:FinalProps`, (v) => `${v} & $$NativeStyleProps`);
158
+ api.file.native.dts.prepend("body", "jsx:proxy-custom-members", ` token: ${JSON.stringify(mergedTokens, null, 4)}\n`);
159
+ };
160
+ const onParse = async (api, input) => {
161
+ const { content } = input;
162
+ const results = await require_extractProps.extractPropTrees(require_extractCode.extractCode(content));
163
+ needsRuntime ||= !!Object.keys(results).length;
164
+ const prepared = require_extractPrepared.extractPreparedComponents(content, input.path || input.file);
165
+ let preparedDirty = false;
166
+ for (const entry of prepared) {
167
+ const existing = preparedComponents.get(entry.name);
168
+ if (!existing || existing.asTag !== entry.asTag || existing.asDynamic !== entry.asDynamic) {
169
+ preparedComponents.set(entry.name, entry);
170
+ preparedDirty = true;
171
+ }
172
+ }
173
+ if (preparedDirty) syncPreparedDts(api);
174
+ };
175
+
176
+ //#endregion
177
+ exports.name = name;
178
+ exports.onBoot = onBoot;
179
+ exports.onParse = onParse;
180
+ exports.settings = settings;
@@ -0,0 +1,176 @@
1
+ import { extractCode } from "../parser/jsx/extractCode.mjs";
2
+ import { extractPreparedComponents } from "../parser/jsx/extractPrepared.mjs";
3
+ import { extractPropTrees } from "../parser/jsx/extractProps.mjs";
4
+ import { loadReactNativeStyleProps } from "./styleTypes.mjs";
5
+ import { merge } from "ts-deepmerge";
6
+
7
+ //#region src/native/server.ts
8
+ const name = "native";
9
+ const settings = new Map([
10
+ ["name", "$$"],
11
+ ["globals", true],
12
+ ["emitRuntime", false]
13
+ ]);
14
+ const nativeComponentNames = [
15
+ "ActivityIndicator",
16
+ "FlatList",
17
+ "Image",
18
+ "Modal",
19
+ "Pressable",
20
+ "SafeAreaView",
21
+ "ScrollView",
22
+ "SectionList",
23
+ "Switch",
24
+ "Text",
25
+ "TextInput",
26
+ "TouchableHighlight",
27
+ "TouchableOpacity",
28
+ "TouchableWithoutFeedback",
29
+ "View"
30
+ ];
31
+ const defaultTokens = { color: {
32
+ black: "#000",
33
+ white: "#fff"
34
+ } };
35
+ let needsRuntime = false;
36
+ const preparedComponents = /* @__PURE__ */ new Map();
37
+ const syncPreparedDts = (api) => {
38
+ const entries = Array.from(preparedComponents.entries()).sort(([a], [b]) => a.localeCompare(b));
39
+ const lines = ["interface $$Prepared {"];
40
+ for (const [name] of entries) {
41
+ const baseType = "DefaultNativeElement";
42
+ const getterType = `BaseFn<${baseType}>`;
43
+ const setterType = `$$PreparedDefinitionForSet<${baseType}>`;
44
+ lines.push(` get ${name}(): ${getterType};`);
45
+ lines.push(` set ${name}(value: ${setterType});`);
46
+ }
47
+ lines.push("}");
48
+ api.file.native.dts.set("body", "jsx:prepared-interface", lines.join("\n"));
49
+ };
50
+ const onBoot = async (api) => {
51
+ preparedComponents.clear();
52
+ needsRuntime = false;
53
+ const needsRuntimeTest = () => needsRuntime || settings.get("emitRuntime") === true;
54
+ const proxyVar = api.file.native.import({
55
+ name: "proxy",
56
+ from: "boss-css/parser/jsx/native"
57
+ }, needsRuntimeTest);
58
+ api.file.native.importAndConfig({
59
+ name: "onBrowserObjectStart",
60
+ from: "boss-css/native/browser"
61
+ }, needsRuntimeTest);
62
+ settings.get("globals") && api.file.native.set("body", "jsx:globalThis", `globalThis.${settings.get("name")} = ${proxyVar}`, needsRuntimeTest);
63
+ api.file.native.set("body", "jsx:export-const", `export const ${settings.get("name")} = ${proxyVar}`, needsRuntimeTest);
64
+ api.file.native.set("foot", "jsx:export-default", `export default ${proxyVar}`, needsRuntimeTest);
65
+ const tokenCreatorVar = api.file.native.import({
66
+ name: "create",
67
+ from: "boss-css/use/token/runtime-only"
68
+ }, needsRuntimeTest);
69
+ api.file.native.set("foot", "token:$$.token", `$$.token = ${tokenCreatorVar}()`, needsRuntimeTest);
70
+ const { props } = await loadReactNativeStyleProps();
71
+ const nativeStyleProps = Array.from(props.keys()).sort();
72
+ const mergedTokens = merge(defaultTokens, api.tokens ?? {});
73
+ api.file.native.config({
74
+ from: "boss-css/native",
75
+ config: {
76
+ nativeStyleProps,
77
+ tokens: mergedTokens,
78
+ runtime: { only: true }
79
+ }
80
+ }, needsRuntimeTest);
81
+ api.file.native.dts.set("head", "jsx:runtime", `import type React from 'react'`);
82
+ api.file.native.dts.set("head", "jsx:native-components", `import type { ${nativeComponentNames.join(", ")} } from 'react-native'`);
83
+ api.file.native.dts.set("body", "jsx:utils", `type AsProp<C extends React.ElementType> = {
84
+ as?: C
85
+ }
86
+ type PropsToOmit<C extends React.ElementType, P> = keyof (AsProp<C> & P)
87
+ type PolymorphicComponentProp<C extends React.ElementType, Props = {}> = React.PropsWithChildren<Props & AsProp<C>> &
88
+ Omit<React.ComponentPropsWithoutRef<C>, PropsToOmit<C, Props>>
89
+ type PolymorphicComponentPropWithRef<C extends React.ElementType, Props = {}> = PolymorphicComponentProp<C, Props> & {
90
+ ref?: PolymorphicRef<C>
91
+ }
92
+ type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref']
93
+
94
+ type DefaultNativeElement = typeof View
95
+ type $$JSXFinalProps<C extends React.ElementType> = PolymorphicComponentPropWithRef<C, $$FinalProps>
96
+ declare const $$PreparedBrand: unique symbol
97
+ type $$PreparedProps<Base extends React.ElementType = DefaultNativeElement, C extends React.ElementType = Base> = Omit<
98
+ $$JSXFinalProps<C>,
99
+ 'children' | 'ref'
100
+ > &
101
+ (C extends Base ? { as?: C } : { as: C })
102
+ type $$PreparedDefinition<Base extends React.ElementType = DefaultNativeElement, C extends React.ElementType = Base> =
103
+ $$PreparedProps<Base, C> & { readonly [typeof $$PreparedBrand]: true }
104
+ type $$PreparedDefinitionForSet<Base extends React.ElementType = DefaultNativeElement> =
105
+ | $$PreparedDefinition<Base, Base>
106
+ | {
107
+ [K in keyof JSX.IntrinsicElements]: $$PreparedDefinition<Base, K> & { as: K }
108
+ }[keyof JSX.IntrinsicElements]
109
+ type $$NoopFn = {
110
+ (props: $$PreparedProps<DefaultNativeElement, DefaultNativeElement>): $$PreparedDefinition<DefaultNativeElement, DefaultNativeElement>
111
+ <C extends React.ElementType>(props: $$PreparedProps<DefaultNativeElement, C> & { as: C }): $$PreparedDefinition<DefaultNativeElement, C>
112
+ (input: string): string
113
+ }
114
+ type StyleFn = {
115
+ (...inputs: $$FinalProps[]): BossComponentProps<DefaultNativeElement>
116
+ }
117
+ type CssFn = {
118
+ (input: TemplateStringsArray, ...exprs: unknown[]): void
119
+ (input: string | Record<string, unknown>): void
120
+ }
121
+
122
+ type NativeComponentMap = {
123
+ ${nativeComponentNames.map((name) => ` ${name}: typeof ${name};`).join("\n")}
124
+ }
125
+
126
+ type BaseFn<T extends React.ElementType = DefaultNativeElement> = {
127
+ <C extends React.ElementType = T, L extends React.LegacyRef>(
128
+ props: $$JSXFinalProps<C>,
129
+ contexts?: L,
130
+ ): L extends React.LegacyRef ? React.ReactNode : $$FinalProps
131
+ }`);
132
+ syncPreparedDts(api);
133
+ api.file.native.dts.set("body", "jsx:proxy-start", `type ProxyCustomMembers = {
134
+ `).set("body", "jsx:proxy-utils", ` $: $$NoopFn
135
+ merge: (...inputs: import('boss-css/merge').MergeInput[]) => import('boss-css/merge').MergeOutput
136
+ cx: (...inputs: import('boss-css/cx').CxValue[]) => string
137
+ cv: typeof import('boss-css/cx').cv
138
+ scv: typeof import('boss-css/cx').scv
139
+ sv: typeof import('boss-css/cx').sv
140
+ css: CssFn
141
+ style: StyleFn
142
+ `).set("body", "jsx:proxy-custom-members", ``).set("body", "jsx:proxy-custom-members-end", `}`).set("body", "jsx:proxy-type", `type Proxy = BaseFn & {
143
+ [T in keyof NativeComponentMap]: BaseFn<NativeComponentMap[T]>
144
+ } & $$Prepared & ProxyCustomMembers`);
145
+ api.file.native.dts.set("foot", "jsx:export", `export declare const $$: Proxy`);
146
+ if (settings.get("globals")) api.file.native.dts.set("foot", "jsx:globals", `declare global {
147
+ const $$: Proxy
148
+ }`);
149
+ api.file.native.dts.set("foot", "$$:default-export", `export default $$`);
150
+ api.file.native.dts.set("body", "native:StylePropsInterfaceStart", `export interface $$NativeStyleProps {`);
151
+ for (const [name, prop] of props.entries()) {
152
+ if (prop.description) api.file.native.dts.set("body", `native:${name}:description`, ` /**\n * ${prop.description}\n */`);
153
+ api.file.native.dts.set("body", `native:${name}:declaration`, ` ${name}?: $$PropValues | ${prop.type};\n`);
154
+ }
155
+ api.file.native.dts.set("body", "native:StylePropsInterfaceEnd", `}`);
156
+ api.file.native.dts.replace("body", `$$:FinalProps`, (v) => `${v} & $$NativeStyleProps`);
157
+ api.file.native.dts.prepend("body", "jsx:proxy-custom-members", ` token: ${JSON.stringify(mergedTokens, null, 4)}\n`);
158
+ };
159
+ const onParse = async (api, input) => {
160
+ const { content } = input;
161
+ const results = await extractPropTrees(extractCode(content));
162
+ needsRuntime ||= !!Object.keys(results).length;
163
+ const prepared = extractPreparedComponents(content, input.path || input.file);
164
+ let preparedDirty = false;
165
+ for (const entry of prepared) {
166
+ const existing = preparedComponents.get(entry.name);
167
+ if (!existing || existing.asTag !== entry.asTag || existing.asDynamic !== entry.asDynamic) {
168
+ preparedComponents.set(entry.name, entry);
169
+ preparedDirty = true;
170
+ }
171
+ }
172
+ if (preparedDirty) syncPreparedDts(api);
173
+ };
174
+
175
+ //#endregion
176
+ export { name, onBoot, onParse, settings };
@@ -0,0 +1,168 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let node_fs_promises = require("node:fs/promises");
3
+ node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
4
+ let node_path = require("node:path");
5
+ node_path = require_rolldown_runtime.__toESM(node_path);
6
+ let fast_glob = require("fast-glob");
7
+ fast_glob = require_rolldown_runtime.__toESM(fast_glob);
8
+ let node_module = require("node:module");
9
+
10
+ //#region src/native/styleTypes.ts
11
+ const interfaceNames = new Set([
12
+ "ViewStyle",
13
+ "TextStyle",
14
+ "ImageStyle"
15
+ ]);
16
+ const normalizeType = (value) => value.replace(/\s+/g, " ").replace(/;$/, "").trim();
17
+ const parseInterfaces = (source) => {
18
+ const interfaces = /* @__PURE__ */ new Map();
19
+ const lines = source.split("\n");
20
+ let current = null;
21
+ let comment = [];
22
+ let pendingProp = null;
23
+ const interfaceRegexp = /^\s*(?:export\s+)?interface\s+([A-Za-z0-9_]+)(?:\s+extends\s+([^ {]+(?:\s*,\s*[^ {]+)*))?\s*\{/;
24
+ const propRegexp = /^\s+(?:readonly\s+)?["']?([A-Za-z0-9_]+)["']?\??:\s*(.+)$/;
25
+ for (const line of lines) {
26
+ const interfaceMatch = line.match(interfaceRegexp);
27
+ if (interfaceMatch) {
28
+ const [, name, extendsRaw] = interfaceMatch;
29
+ const entry = {
30
+ name,
31
+ extends: extendsRaw ? extendsRaw.split(",").map((value) => value.trim()) : [],
32
+ props: /* @__PURE__ */ new Map()
33
+ };
34
+ interfaces.set(name, entry);
35
+ current = entry;
36
+ comment = [];
37
+ pendingProp = null;
38
+ continue;
39
+ }
40
+ if (current && line.trim() === "}") {
41
+ current = null;
42
+ comment = [];
43
+ pendingProp = null;
44
+ continue;
45
+ }
46
+ if (!current) continue;
47
+ if (line.trim().startsWith("/**")) {
48
+ const trimmed = line.trim().replace(/^\/\*\* ?/, "");
49
+ if (trimmed.includes("*/")) comment = [trimmed.replace(/\*\/$/, "").trim()];
50
+ else comment = [trimmed];
51
+ continue;
52
+ }
53
+ if (comment.length && line.trim().startsWith("*")) {
54
+ const trimmed = line.trim().replace(/^\* ?/, "");
55
+ if (!trimmed.endsWith("*/")) {
56
+ comment.push(trimmed);
57
+ continue;
58
+ }
59
+ comment.push(trimmed.replace(/\*\/$/, "").trim());
60
+ continue;
61
+ }
62
+ if (pendingProp) {
63
+ pendingProp.type += ` ${line.trim()}`;
64
+ if (line.includes(";")) {
65
+ const propType = normalizeType(pendingProp.type);
66
+ current.props.set(pendingProp.name, {
67
+ name: pendingProp.name,
68
+ type: propType,
69
+ description: comment.join("\n").trim() || void 0
70
+ });
71
+ pendingProp = null;
72
+ comment = [];
73
+ }
74
+ continue;
75
+ }
76
+ const propMatch = line.match(propRegexp);
77
+ if (!propMatch) continue;
78
+ const [, rawName, typeRaw] = propMatch;
79
+ if (rawName.startsWith("[")) continue;
80
+ const typeValue = typeRaw.trim();
81
+ if (!line.includes(";")) {
82
+ pendingProp = {
83
+ name: rawName,
84
+ type: typeValue
85
+ };
86
+ continue;
87
+ }
88
+ current.props.set(rawName, {
89
+ name: rawName,
90
+ type: normalizeType(typeValue),
91
+ description: comment.join("\n").trim() || void 0
92
+ });
93
+ comment = [];
94
+ }
95
+ return interfaces;
96
+ };
97
+ const mergeProps = (target, source) => {
98
+ for (const [name, prop] of source.entries()) {
99
+ const existing = target.get(name);
100
+ if (!existing) {
101
+ target.set(name, { ...prop });
102
+ continue;
103
+ }
104
+ if (existing.type !== prop.type) {
105
+ const types = new Set([existing.type, prop.type]);
106
+ existing.type = Array.from(types).join(" | ");
107
+ }
108
+ if (!existing.description && prop.description) existing.description = prop.description;
109
+ }
110
+ };
111
+ const collectProps = (name, interfaces, visited = /* @__PURE__ */ new Set()) => {
112
+ if (visited.has(name)) return /* @__PURE__ */ new Map();
113
+ visited.add(name);
114
+ const entry = interfaces.get(name);
115
+ if (!entry) return /* @__PURE__ */ new Map();
116
+ const merged = /* @__PURE__ */ new Map();
117
+ for (const parent of entry.extends) mergeProps(merged, collectProps(parent, interfaces, visited));
118
+ mergeProps(merged, entry.props);
119
+ return merged;
120
+ };
121
+ const resolveReactNativeRoot = async () => {
122
+ const require = (0, node_module.createRequire)(process.cwd() + "/package.json");
123
+ let packageJsonPath;
124
+ try {
125
+ packageJsonPath = require.resolve("react-native/package.json");
126
+ } catch (error) {
127
+ throw new Error("native: react-native is not installed in this project.");
128
+ }
129
+ const packageJson = JSON.parse(await node_fs_promises.default.readFile(packageJsonPath, "utf-8"));
130
+ return {
131
+ root: node_path.default.dirname(packageJsonPath),
132
+ typesEntry: packageJson.types || packageJson.typings
133
+ };
134
+ };
135
+ const findStyleSheetTypesFile = async (root, typesEntry) => {
136
+ const candidates = await (0, fast_glob.default)(["**/StyleSheetTypes.d.ts", "**/StyleSheetTypes.ts"], {
137
+ cwd: root,
138
+ absolute: true,
139
+ suppressErrors: true
140
+ });
141
+ if (candidates.length) return candidates[0];
142
+ if (typesEntry) {
143
+ const entryPath = node_path.default.join(root, typesEntry);
144
+ if ((await node_fs_promises.default.readFile(entryPath, "utf-8").catch(() => "")).includes("interface ViewStyle")) return entryPath;
145
+ }
146
+ const fallback = await (0, fast_glob.default)(["**/*.d.ts"], {
147
+ cwd: root,
148
+ absolute: true,
149
+ suppressErrors: true
150
+ });
151
+ for (const file of fallback) if ((await node_fs_promises.default.readFile(file, "utf-8").catch(() => "")).includes("interface ViewStyle")) return file;
152
+ return null;
153
+ };
154
+ const loadReactNativeStyleProps = async () => {
155
+ const { root, typesEntry } = await resolveReactNativeRoot();
156
+ const typesFile = await findStyleSheetTypesFile(root, typesEntry);
157
+ if (!typesFile) throw new Error("native: unable to locate React Native style type definitions.");
158
+ const interfaces = parseInterfaces(await node_fs_promises.default.readFile(typesFile, "utf-8"));
159
+ const merged = /* @__PURE__ */ new Map();
160
+ for (const name of interfaceNames) mergeProps(merged, collectProps(name, interfaces));
161
+ return {
162
+ props: merged,
163
+ sourcePath: typesFile
164
+ };
165
+ };
166
+
167
+ //#endregion
168
+ exports.loadReactNativeStyleProps = loadReactNativeStyleProps;