objcjs-types 0.2.1 → 0.4.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.
Files changed (106) hide show
  1. package/bin/objcjs-types.ts +31 -0
  2. package/dist/AVFoundation/functions.d.ts +21 -0
  3. package/dist/AVFoundation/functions.js +32 -0
  4. package/dist/Accessibility/functions.d.ts +16 -0
  5. package/dist/Accessibility/functions.js +35 -0
  6. package/dist/AddressBook/functions.d.ts +98 -0
  7. package/dist/AddressBook/functions.js +290 -0
  8. package/dist/AppKit/functions.d.ts +112 -0
  9. package/dist/AppKit/functions.js +272 -0
  10. package/dist/AudioToolbox/functions.d.ts +377 -0
  11. package/dist/AudioToolbox/functions.js +1124 -0
  12. package/dist/AuthenticationServices/functions.d.ts +2 -0
  13. package/dist/AuthenticationServices/functions.js +5 -0
  14. package/dist/BrowserEngineCore/functions.d.ts +3 -0
  15. package/dist/BrowserEngineCore/functions.js +11 -0
  16. package/dist/CoreAudio/functions.d.ts +60 -0
  17. package/dist/CoreAudio/functions.js +173 -0
  18. package/dist/CoreMIDI/functions.d.ts +96 -0
  19. package/dist/CoreMIDI/functions.js +287 -0
  20. package/dist/CoreML/functions.d.ts +2 -0
  21. package/dist/CoreML/functions.js +5 -0
  22. package/dist/CoreMediaIO/functions.d.ts +38 -0
  23. package/dist/CoreMediaIO/functions.js +107 -0
  24. package/dist/CoreText/functions.d.ts +209 -0
  25. package/dist/CoreText/functions.js +611 -0
  26. package/dist/CoreWLAN/functions.d.ts +23 -0
  27. package/dist/CoreWLAN/functions.js +56 -0
  28. package/dist/DeviceDiscoveryExtension/functions.d.ts +11 -0
  29. package/dist/DeviceDiscoveryExtension/functions.js +17 -0
  30. package/dist/DiscRecording/functions.d.ts +97 -0
  31. package/dist/DiscRecording/functions.js +290 -0
  32. package/dist/DiscRecordingUI/functions.d.ts +13 -0
  33. package/dist/DiscRecordingUI/functions.js +38 -0
  34. package/dist/ExceptionHandling/functions.d.ts +1 -0
  35. package/dist/ExceptionHandling/functions.js +5 -0
  36. package/dist/FSKit/functions.d.ts +4 -0
  37. package/dist/FSKit/functions.js +11 -0
  38. package/dist/Foundation/functions.d.ts +145 -0
  39. package/dist/Foundation/functions.js +386 -0
  40. package/dist/GLKit/functions.d.ts +51 -0
  41. package/dist/GLKit/functions.js +146 -0
  42. package/dist/GameController/functions.d.ts +18 -0
  43. package/dist/GameController/functions.js +44 -0
  44. package/dist/HealthKit/functions.d.ts +19 -0
  45. package/dist/HealthKit/functions.js +35 -0
  46. package/dist/IOSurface/functions.d.ts +53 -0
  47. package/dist/IOSurface/functions.js +155 -0
  48. package/dist/IOUSBHost/functions.d.ts +44 -0
  49. package/dist/IOUSBHost/functions.js +131 -0
  50. package/dist/InstantMessage/functions.d.ts +1 -0
  51. package/dist/InstantMessage/functions.js +5 -0
  52. package/dist/JavaRuntimeSupport/functions.d.ts +40 -0
  53. package/dist/JavaRuntimeSupport/functions.js +113 -0
  54. package/dist/JavaScriptCore/functions.d.ts +120 -0
  55. package/dist/JavaScriptCore/functions.js +359 -0
  56. package/dist/MLCompute/functions.d.ts +27 -0
  57. package/dist/MLCompute/functions.js +41 -0
  58. package/dist/MapKit/functions.d.ts +23 -0
  59. package/dist/MapKit/functions.js +56 -0
  60. package/dist/Matter/functions.d.ts +17 -0
  61. package/dist/Matter/functions.js +26 -0
  62. package/dist/MediaAccessibility/functions.d.ts +28 -0
  63. package/dist/MediaAccessibility/functions.js +83 -0
  64. package/dist/MediaPlayer/functions.d.ts +3 -0
  65. package/dist/MediaPlayer/functions.js +11 -0
  66. package/dist/Metal/functions.d.ts +14 -0
  67. package/dist/Metal/functions.js +26 -0
  68. package/dist/MetalKit/functions.d.ts +11 -0
  69. package/dist/MetalKit/functions.js +20 -0
  70. package/dist/MetalPerformanceShaders/functions.d.ts +7 -0
  71. package/dist/MetalPerformanceShaders/functions.js +14 -0
  72. package/dist/NearbyInteraction/functions.d.ts +3 -0
  73. package/dist/NearbyInteraction/functions.js +5 -0
  74. package/dist/ParavirtualizedGraphics/functions.d.ts +7 -0
  75. package/dist/ParavirtualizedGraphics/functions.js +14 -0
  76. package/dist/QuartzCore/functions.d.ts +19 -0
  77. package/dist/QuartzCore/functions.js +50 -0
  78. package/dist/SceneKit/functions.d.ts +17 -0
  79. package/dist/SceneKit/functions.js +38 -0
  80. package/dist/SensorKit/functions.d.ts +4 -0
  81. package/dist/SensorKit/functions.js +14 -0
  82. package/dist/ServiceManagement/functions.d.ts +7 -0
  83. package/dist/ServiceManagement/functions.js +20 -0
  84. package/dist/StoreKit/functions.d.ts +1 -0
  85. package/dist/StoreKit/functions.js +5 -0
  86. package/dist/VideoToolbox/functions.d.ts +81 -0
  87. package/dist/VideoToolbox/functions.js +236 -0
  88. package/dist/Vision/functions.d.ts +16 -0
  89. package/dist/Vision/functions.js +38 -0
  90. package/generator/ast-parser.ts +1368 -0
  91. package/generator/clang.ts +167 -0
  92. package/generator/custom.ts +936 -0
  93. package/generator/discover.ts +111 -0
  94. package/generator/emitter.ts +2020 -0
  95. package/generator/frameworks.ts +135 -0
  96. package/generator/index.ts +1334 -0
  97. package/generator/parse-worker.ts +263 -0
  98. package/generator/resolve-strings.ts +121 -0
  99. package/generator/struct-fields.ts +46 -0
  100. package/generator/templates/bind.ts +100 -0
  101. package/generator/templates/helpers.ts +70 -0
  102. package/generator/templates/nsdata.ts +97 -0
  103. package/generator/templates/osversion.ts +91 -0
  104. package/generator/type-mapper.ts +615 -0
  105. package/generator/worker-pool.ts +309 -0
  106. package/package.json +17 -4
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Auto-discovers ObjC classes and protocols by scanning framework header files.
3
+ * Eliminates the need for manually maintaining class/protocol lists and header mappings.
4
+ */
5
+
6
+ import { readdir } from "fs/promises";
7
+ import { join } from "path";
8
+
9
+ export interface DiscoveryResult {
10
+ /** Maps class name → header file name (without .h extension) */
11
+ classes: Map<string, string>;
12
+ /** Maps protocol name → header file name (without .h extension) */
13
+ protocols: Map<string, string>;
14
+ /** Maps integer enum name → header file name (without .h extension) */
15
+ integerEnums: Map<string, string>;
16
+ /** Maps string enum name → header file name (without .h extension) */
17
+ stringEnums: Map<string, string>;
18
+ }
19
+
20
+ /** Matches `@interface ClassName` — captures class name */
21
+ const INTERFACE_RE = /@interface\s+(\w+)/;
22
+
23
+ /** Matches category or extension: `@interface ClassName (` or `@interface ClassName<Type> (` */
24
+ const CATEGORY_RE = /@interface\s+\w+(?:<[^>]*>)?\s*\(/;
25
+
26
+ /** Matches `@protocol ProtocolName` — captures protocol name */
27
+ const PROTOCOL_RE = /@protocol\s+(\w+)/;
28
+
29
+ /**
30
+ * Matches NS_ENUM / NS_OPTIONS integer enum declarations.
31
+ * e.g., `typedef NS_ENUM(NSInteger, NSWindowStyleMask) {`
32
+ * e.g., `typedef NS_OPTIONS(NSUInteger, NSWindowStyleMask) {`
33
+ */
34
+ const NS_ENUM_RE = /typedef\s+NS_(?:ENUM|OPTIONS)\s*\(\s*\w+\s*,\s*(\w+)\s*\)/;
35
+
36
+ /**
37
+ * Matches NS_TYPED_EXTENSIBLE_ENUM / NS_STRING_ENUM / NS_TYPED_ENUM string enum declarations.
38
+ * These are NSString * typedefs whose values are extern constants.
39
+ * e.g., `typedef NSString * ASAuthorizationPublicKeyCredentialUserVerificationPreference NS_TYPED_EXTENSIBLE_ENUM;`
40
+ * Also matches the multi-line form where the macro is on the typedef.
41
+ */
42
+ const NS_STRING_ENUM_RE = /typedef\s+NSString\s*\*\s*(\w+)\s+NS_(?:TYPED_EXTENSIBLE_ENUM|STRING_ENUM|TYPED_ENUM)/;
43
+
44
+ /**
45
+ * Scan all .h files in a framework's Headers directory and discover
46
+ * every ObjC class and protocol declaration, mapping each to its header file.
47
+ *
48
+ * Class declarations: `@interface Foo : Bar` or `@interface Foo <Protocol>`
49
+ * Protocol declarations: `@protocol Foo <Bar>` (not forward decls like `@protocol Foo;`)
50
+ * Skipped: categories (`@interface Foo (Cat)`), extensions (`@interface Foo ()`)
51
+ */
52
+ export async function discoverFramework(headersPath: string): Promise<DiscoveryResult> {
53
+ const classes = new Map<string, string>();
54
+ const protocols = new Map<string, string>();
55
+ const integerEnums = new Map<string, string>();
56
+ const stringEnums = new Map<string, string>();
57
+
58
+ const entries = await readdir(headersPath);
59
+ const headerFiles = entries.filter((f) => f.endsWith(".h")).sort();
60
+
61
+ for (const file of headerFiles) {
62
+ const headerName = file.slice(0, -2); // strip .h
63
+ const content = await Bun.file(join(headersPath, file)).text();
64
+ const lines = content.split("\n");
65
+
66
+ for (const line of lines) {
67
+ // --- Class declarations ---
68
+ // Match @interface Foo : Bar, @interface Foo <Protocol>, etc.
69
+ // Skip categories: @interface Foo (Category) or extensions: @interface Foo ()
70
+ const ifaceMatch = INTERFACE_RE.exec(line);
71
+ if (ifaceMatch && !CATEGORY_RE.test(line)) {
72
+ const name = ifaceMatch[1]!;
73
+ // Only record first occurrence — handles redeclarations in other headers
74
+ if (!classes.has(name)) {
75
+ classes.set(name, headerName);
76
+ }
77
+ }
78
+
79
+ // --- Protocol declarations ---
80
+ // Match @protocol Foo <Bar> or @protocol Foo (followed by newline/methods)
81
+ // Skip forward declarations: @protocol Foo; or @protocol Foo, Bar;
82
+ const protoMatch = PROTOCOL_RE.exec(line);
83
+ if (protoMatch && !line.includes(";")) {
84
+ const name = protoMatch[1]!;
85
+ if (!protocols.has(name)) {
86
+ protocols.set(name, headerName);
87
+ }
88
+ }
89
+
90
+ // --- Integer enum declarations (NS_ENUM / NS_OPTIONS) ---
91
+ const enumMatch = NS_ENUM_RE.exec(line);
92
+ if (enumMatch) {
93
+ const name = enumMatch[1]!;
94
+ if (!integerEnums.has(name)) {
95
+ integerEnums.set(name, headerName);
96
+ }
97
+ }
98
+
99
+ // --- String enum declarations (NS_TYPED_EXTENSIBLE_ENUM etc.) ---
100
+ const stringEnumMatch = NS_STRING_ENUM_RE.exec(line);
101
+ if (stringEnumMatch) {
102
+ const name = stringEnumMatch[1]!;
103
+ if (!stringEnums.has(name)) {
104
+ stringEnums.set(name, headerName);
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ return { classes, protocols, integerEnums, stringEnums };
111
+ }