@kbach/react-native 1.0.0-beta.1 → 1.0.0-beta.11

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 (46) hide show
  1. package/README.md +87 -66
  2. package/android/build.gradle +36 -0
  3. package/android/src/main/AndroidManifest.xml +14 -0
  4. package/android/src/main/java/com/kbachnative/KbachModule.kt +83 -0
  5. package/android/src/main/java/com/kbachnative/KbachPackage.kt +54 -0
  6. package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
  7. package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
  8. package/dist/chunk-4DQXTAM3.mjs +63 -0
  9. package/dist/chunk-5MU6PEXV.mjs +14 -0
  10. package/dist/chunk-H5Z24XX5.mjs +192 -0
  11. package/dist/{chunk-YHF3QLRL.mjs → chunk-HK6PDJJK.mjs} +61 -68
  12. package/dist/chunk-RBJXE32L.mjs +73 -0
  13. package/dist/chunk-TDWBXJH5.mjs +186 -0
  14. package/dist/chunk-XHL653X2.mjs +1211 -0
  15. package/dist/chunk-YOC3SHF5.mjs +40 -0
  16. package/dist/index.d.mts +37 -102
  17. package/dist/index.d.ts +37 -102
  18. package/dist/index.js +1411 -38
  19. package/dist/index.mjs +19 -61
  20. package/dist/index.web.d.mts +15 -0
  21. package/dist/index.web.d.ts +15 -0
  22. package/dist/index.web.js +829 -0
  23. package/dist/index.web.mjs +38 -0
  24. package/dist/jsx-dev-runtime.d.mts +3 -12
  25. package/dist/jsx-dev-runtime.d.ts +3 -12
  26. package/dist/jsx-dev-runtime.js +1313 -36
  27. package/dist/jsx-dev-runtime.mjs +9 -11
  28. package/dist/jsx-dev-runtime.web.d.mts +10 -0
  29. package/dist/jsx-dev-runtime.web.d.ts +10 -0
  30. package/dist/jsx-dev-runtime.web.js +659 -0
  31. package/dist/jsx-dev-runtime.web.mjs +18 -0
  32. package/dist/jsx-runtime.d.mts +3 -23
  33. package/dist/jsx-runtime.d.ts +3 -23
  34. package/dist/jsx-runtime.js +1304 -28
  35. package/dist/jsx-runtime.mjs +7 -3
  36. package/dist/jsx-runtime.web.d.mts +7 -0
  37. package/dist/jsx-runtime.web.d.ts +7 -0
  38. package/dist/jsx-runtime.web.js +602 -0
  39. package/dist/jsx-runtime.web.mjs +12 -0
  40. package/dist/useColors-C6jyCLuG.d.mts +239 -0
  41. package/dist/useColors-C6jyCLuG.d.ts +239 -0
  42. package/package.json +57 -8
  43. package/react-native.config.js +29 -0
  44. package/specs/NativeKbachModule.ts +31 -0
  45. package/src/babel-plugin.js +74 -2
  46. package/dist/chunk-SVMYVXY6.mjs +0 -44
@@ -1,5 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const template = require('@babel/template').default;
6
+
3
7
  /**
4
8
  * Injects a per-file `@jsxImportSource @kbach/react-native` pragma comment
5
9
  * so Metro's JSX transform routes className resolution through
@@ -19,9 +23,67 @@
19
23
  * Deliberately NOT porting old-kbach's build-time class-resolution half
20
24
  * (the __kbachStyles fast path) — resolution happens at the (already
21
25
  * synchronous) native-bridge call inside the jsx-runtime instead (see
22
- * nativeBridge.ts), so this plugin's only job is the pragma injection.
26
+ * nativeBridge.ts), so this plugin's only job is the pragma injection —
27
+ * PLUS one more, added later: auto-applying `kbach.config.js` if one
28
+ * exists (see `getConfigStatement`'s own doc comment), so a project never
29
+ * needs its own explicit `applyKbachConfig(kbachConfig)` call at all. That
30
+ * addition deliberately still stops short of old-kbach's own version of
31
+ * this (an mtime-polling live-reload of the config, re-checked on every
32
+ * file) — a Babel-plugin-level change needs a dev-server restart to take
33
+ * effect either way, so a one-time check per (root, process) pair is
34
+ * enough, and much simpler to reason about.
35
+ */
36
+
37
+ // Keyed by the root directory checked — undefined = not checked yet for
38
+ // that root, null = checked, no kbach.config.js found there. A Babel/Metro
39
+ // worker process transforms many files over its lifetime — this makes the
40
+ // existsSync + template-build work happen ONCE per root, not on every
41
+ // single file `pre()` runs for.
42
+ const _configStatementCache = new Map();
43
+
44
+ /**
45
+ * Builds the (uncompiled) AST statement that applies `kbach.config.js`,
46
+ * cached per `root` after the first call — `null` if no such file exists
47
+ * there. `root` defaults to `process.cwd()` (how `metro start`/`expo
48
+ * start` are conventionally invoked) at the plugin's own call site below;
49
+ * pass `{ configRoot: '...' }` as this plugin's Babel options if your
50
+ * `kbach.config.js` lives somewhere else (a monorepo where Metro's actual
51
+ * working directory isn't the app's own root, for instance).
52
+ *
53
+ * The injected statement is a plain `require(...).applyKbachConfig(require(...))`
54
+ * — no try/catch around it. `kbach.config.js`'s own path is only ever
55
+ * baked in here after `existsSync` already confirmed it exists, so the
56
+ * only way this could still throw is a genuine bug in that file (a syntax
57
+ * error, a bad nested require) — letting that surface as a real, visible
58
+ * Metro bundling error is far better than silently swallowing it: a
59
+ * developer's real customization would otherwise go missing with zero
60
+ * indication why, exactly the kind of headache a good default should avoid.
61
+ *
62
+ * `@babel/template` builds this from a plain string with the absolute path
63
+ * JSON-escaped directly into it (correct on Windows too, backslashes and
64
+ * all) — simpler than building the equivalent `@babel/types` node graph by
65
+ * hand for one straightforward statement.
23
66
  */
24
- module.exports = function kbachReactNativeBabelPlugin() {
67
+ function getConfigStatement(root) {
68
+ if (_configStatementCache.has(root)) return _configStatementCache.get(root);
69
+
70
+ const configPath = path.join(root, 'kbach.config.js');
71
+ if (!fs.existsSync(configPath)) {
72
+ _configStatementCache.set(root, null);
73
+ return null;
74
+ }
75
+
76
+ const buildStatement = template(
77
+ `require('@kbach/react-native').applyKbachConfig(require(${JSON.stringify(configPath)}));`,
78
+ );
79
+ const statement = buildStatement();
80
+ _configStatementCache.set(root, statement);
81
+ return statement;
82
+ }
83
+
84
+ module.exports = function kbachReactNativeBabelPlugin(_babel, options) {
85
+ const configRoot = (options && options.configRoot) || process.cwd();
86
+
25
87
  return {
26
88
  name: 'kbach-react-native',
27
89
  pre(file) {
@@ -33,7 +95,17 @@ module.exports = function kbachReactNativeBabelPlugin() {
33
95
  if (!alreadySet) {
34
96
  comments.unshift({ type: 'CommentLine', value: ' @jsxImportSource @kbach/react-native' });
35
97
  }
98
+
99
+ const configStatement = getConfigStatement(configRoot);
100
+ if (configStatement) {
101
+ file.ast.program.body.unshift(configStatement);
102
+ }
36
103
  },
37
104
  visitor: {},
38
105
  };
39
106
  };
107
+
108
+ /** Exported for tests only — clears the per-root config-file cache between test cases. */
109
+ module.exports._resetForTests = function resetForTests() {
110
+ _configStatementCache.clear();
111
+ };
@@ -1,44 +0,0 @@
1
- import {
2
- resolveStyle
3
- } from "./chunk-YHF3QLRL.mjs";
4
-
5
- // src/jsx-runtime.tsx
6
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
- import { Fragment } from "react";
8
- import { Pressable } from "react-native";
9
- function makeElement(isStaticChildren, type, props, key) {
10
- return (isStaticChildren ? _jsxs : _jsx)(type, props, key);
11
- }
12
- function resolvedStyleFor(classStrRaw, userStyle, pressed) {
13
- const resolved = resolveStyle(classStrRaw, pressed);
14
- if (userStyle === void 0) {
15
- return resolved;
16
- }
17
- if (typeof userStyle === "function") {
18
- return [resolved, userStyle({ pressed })];
19
- }
20
- return [resolved, userStyle];
21
- }
22
- function processElement(type, rawProps, key, isStaticChildren) {
23
- if (type === null || typeof type === "symbol" || !rawProps) {
24
- return makeElement(isStaticChildren, type, rawProps ?? {}, key);
25
- }
26
- const { className: classStrRaw, style: userStyle, ...rest } = rawProps;
27
- if (typeof classStrRaw !== "string") {
28
- return makeElement(isStaticChildren, type, rawProps, key);
29
- }
30
- const finalStyle = type === Pressable ? (state) => resolvedStyleFor(classStrRaw, userStyle, state.pressed) : resolvedStyleFor(classStrRaw, userStyle, false);
31
- return makeElement(isStaticChildren, type, { ...rest, style: finalStyle }, key);
32
- }
33
- function jsx(type, props, key) {
34
- return processElement(type, props, key, false);
35
- }
36
- function jsxs(type, props, key) {
37
- return processElement(type, props, key, true);
38
- }
39
-
40
- export {
41
- Fragment,
42
- jsx,
43
- jsxs
44
- };