@swiftbrowser/native 0.0.0-stage → 0.10.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 (107) hide show
  1. package/README.md +143 -2
  2. package/bin/swiftbrowser-native.mjs +49 -0
  3. package/dist/bridge.d.ts +50 -0
  4. package/dist/bridge.d.ts.map +1 -0
  5. package/dist/bridge.js +10 -0
  6. package/dist/bridge.js.map +1 -0
  7. package/dist/build.d.ts +47 -0
  8. package/dist/build.d.ts.map +1 -0
  9. package/dist/build.js +156 -0
  10. package/dist/build.js.map +1 -0
  11. package/dist/devBuild.d.ts +34 -0
  12. package/dist/devBuild.d.ts.map +1 -0
  13. package/dist/devBuild.js +133 -0
  14. package/dist/devBuild.js.map +1 -0
  15. package/dist/encoding.d.ts +32 -0
  16. package/dist/encoding.d.ts.map +1 -0
  17. package/dist/encoding.js +136 -0
  18. package/dist/encoding.js.map +1 -0
  19. package/dist/fetch.d.ts +117 -0
  20. package/dist/fetch.d.ts.map +1 -0
  21. package/dist/fetch.js +272 -0
  22. package/dist/fetch.js.map +1 -0
  23. package/dist/index.d.ts +20 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +20 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/native.d.ts +19 -0
  28. package/dist/native.d.ts.map +1 -0
  29. package/dist/native.js +17 -0
  30. package/dist/native.js.map +1 -0
  31. package/dist/refresh.d.ts +18 -0
  32. package/dist/refresh.d.ts.map +1 -0
  33. package/dist/refresh.js +18 -0
  34. package/dist/refresh.js.map +1 -0
  35. package/dist/run.d.ts +27 -0
  36. package/dist/run.d.ts.map +1 -0
  37. package/dist/run.js +76 -0
  38. package/dist/run.js.map +1 -0
  39. package/dist/runtime.d.ts +30 -0
  40. package/dist/runtime.d.ts.map +1 -0
  41. package/dist/runtime.js +193 -0
  42. package/dist/runtime.js.map +1 -0
  43. package/dist/stubs/react-dom-client.d.ts +8 -0
  44. package/dist/stubs/react-dom-client.d.ts.map +1 -0
  45. package/dist/stubs/react-dom-client.js +11 -0
  46. package/dist/stubs/react-dom-client.js.map +1 -0
  47. package/dist/stubs/react-dom.d.ts +9 -0
  48. package/dist/stubs/react-dom.d.ts.map +1 -0
  49. package/dist/stubs/react-dom.js +13 -0
  50. package/dist/stubs/react-dom.js.map +1 -0
  51. package/dist/url.d.ts +48 -0
  52. package/dist/url.d.ts.map +1 -0
  53. package/dist/url.js +213 -0
  54. package/dist/url.js.map +1 -0
  55. package/dist/vendor.d.ts +11 -0
  56. package/dist/vendor.d.ts.map +1 -0
  57. package/dist/vendor.js +27 -0
  58. package/dist/vendor.js.map +1 -0
  59. package/dist/wasmHost.d.ts +35 -0
  60. package/dist/wasmHost.d.ts.map +1 -0
  61. package/dist/wasmHost.js +120 -0
  62. package/dist/wasmHost.js.map +1 -0
  63. package/package.json +73 -4
  64. package/src/bridge.ts +58 -0
  65. package/src/build.ts +185 -0
  66. package/src/devBuild.ts +152 -0
  67. package/src/encoding.ts +130 -0
  68. package/src/fetch.ts +305 -0
  69. package/src/index.ts +20 -0
  70. package/src/native.ts +35 -0
  71. package/src/refresh.ts +29 -0
  72. package/src/run.ts +98 -0
  73. package/src/runtime.ts +208 -0
  74. package/src/stubs/react-dom-client.ts +17 -0
  75. package/src/stubs/react-dom.ts +15 -0
  76. package/src/types/react-refresh.d.ts +38 -0
  77. package/src/url.ts +202 -0
  78. package/src/vendor.ts +30 -0
  79. package/src/wasmHost.ts +147 -0
  80. package/swift/Package.swift +31 -0
  81. package/swift/Sources/SwiftBrowserNative/Host/HostBridge.swift +228 -0
  82. package/swift/Sources/SwiftBrowserNative/Host/JSHost.swift +42 -0
  83. package/swift/Sources/SwiftBrowserNative/Host/JavaScriptCoreHost.swift +102 -0
  84. package/swift/Sources/SwiftBrowserNative/Host/ShimAliases.swift +25 -0
  85. package/swift/Sources/SwiftBrowserNative/Host/WebHost.swift +138 -0
  86. package/swift/Sources/SwiftBrowserNative/Runtime/NativeApp.swift +251 -0
  87. package/swift/Sources/SwiftBrowserNative/Runtime/NativeRegistry.swift +53 -0
  88. package/swift/Sources/SwiftBrowserNative/SwiftBrowserNative.swift +6 -0
  89. package/swift/Sources/SwiftBrowserNative/Views/Conversions.swift +361 -0
  90. package/swift/Sources/SwiftBrowserNative/Views/ElementView.swift +169 -0
  91. package/swift/Sources/SwiftBrowserNative/Views/Kinds/Controls.swift +268 -0
  92. package/swift/Sources/SwiftBrowserNative/Views/Kinds/Lists.swift +175 -0
  93. package/swift/Sources/SwiftBrowserNative/Views/Kinds/More.swift +196 -0
  94. package/swift/Sources/SwiftBrowserNative/Views/Kinds/Navigation.swift +246 -0
  95. package/swift/Sources/SwiftBrowserNative/Views/Kinds/Shapes.swift +108 -0
  96. package/swift/Sources/SwiftBrowserNative/Views/Kinds/Stacks.swift +189 -0
  97. package/swift/Sources/SwiftBrowserNative/Views/Kinds/TextAndImages.swift +102 -0
  98. package/swift/Sources/SwiftBrowserNative/Views/NativeRootView.swift +190 -0
  99. package/swift/Sources/SwiftBrowserNative/Views/StyleModifier.swift +182 -0
  100. package/swift/Sources/SwiftBrowserProtocol/JSONValue.swift +268 -0
  101. package/swift/Sources/SwiftBrowserProtocol/Op.swift +100 -0
  102. package/swift/Sources/SwiftBrowserProtocol/Props.swift +469 -0
  103. package/swift/Sources/SwiftBrowserProtocol/RendererEvent.swift +117 -0
  104. package/swift/Sources/SwiftBrowserProtocol/Style.swift +148 -0
  105. package/swift/Sources/SwiftBrowserProtocol/Values.swift +279 -0
  106. package/swift/Sources/SwiftBrowserTree/ElementNode.swift +65 -0
  107. package/swift/Sources/SwiftBrowserTree/OpTree.swift +168 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,GAAG,EAAiC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAoB,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,cAAc,EAAuB,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAsE,MAAM,UAAU,CAAC;AAC7H,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC9H,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `<Native name props onEvent>`: the escape hatch (docs/native.md). The
3
+ * element kind `native`, which only this producer emits, names a SwiftUI view
4
+ * the app registered with `NativeRegistry.register(name)`; `props` reach it
5
+ * as JSON, its children as SwiftUI views, and what it sends back arrives at
6
+ * `onEvent`.
7
+ */
8
+ import { type ReactElement, type ReactNode } from 'react';
9
+ export interface NativeProps {
10
+ /** The name registered on the Swift side. */
11
+ name: string;
12
+ /** JSON-serializable props for the view. */
13
+ props?: Record<string, unknown>;
14
+ /** A value the native view sent (`context.send(value)`). */
15
+ onEvent?: (value: unknown) => void;
16
+ children?: ReactNode;
17
+ }
18
+ export declare function Native({ name, props, onEvent, children }: NativeProps): ReactElement;
19
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzE,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,4DAA4D;IAC5D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAUD,wBAAgB,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,WAAW,GAAG,YAAY,CAMpF"}
package/dist/native.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `<Native name props onEvent>`: the escape hatch (docs/native.md). The
3
+ * element kind `native`, which only this producer emits, names a SwiftUI view
4
+ * the app registered with `NativeRegistry.register(name)`; `props` reach it
5
+ * as JSON, its children as SwiftUI views, and what it sends back arrives at
6
+ * `onEvent`.
7
+ */
8
+ import { createElement } from 'react';
9
+ export function Native({ name, props, onEvent, children }) {
10
+ // The host element of @swiftbrowser/react: `sb` with the protocol kind and
11
+ // props, and the handlers by event type (packages/react/src/host/instance.ts).
12
+ const hostProps = { kind: 'native', props: { name, props: props ?? {} } };
13
+ if (onEvent)
14
+ hostProps['on'] = { native: (event) => onEvent(event.value) };
15
+ return children === undefined ? createElement('sb', hostProps) : createElement('sb', hostProps, children);
16
+ }
17
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAqC,MAAM,OAAO,CAAC;AAoBzE,MAAM,UAAU,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAe;IACpE,2EAA2E;IAC3E,+EAA+E;IAC/E,MAAM,SAAS,GAA4B,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,CAAC;IACnG,IAAI,OAAO;QAAE,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,KAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;IACxF,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAC5G,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * React Fast Refresh for the dev loop (docs/native.md, "Development loop").
3
+ * The refresh runtime must install its hook before React's reconciler loads,
4
+ * so the vendor bundle imports this module first. The app bundle's modules,
5
+ * transformed by `react-refresh/babel` (devBuild.ts), register their
6
+ * components through `__sbRefresh`; `run` performs the refresh when the app
7
+ * bundle is evaluated again.
8
+ */
9
+ import RefreshRuntime from 'react-refresh/runtime';
10
+ export interface RefreshGlobal {
11
+ register: (type: unknown, id: string) => void;
12
+ createSignatureFunctionForTransform: typeof RefreshRuntime.createSignatureFunctionForTransform;
13
+ /** Applies the registered updates to the mounted roots; true when something was refreshed. */
14
+ perform: () => boolean;
15
+ }
16
+ declare const refresh: RefreshGlobal;
17
+ export { refresh };
18
+ //# sourceMappingURL=refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,mCAAmC,EAAE,OAAO,cAAc,CAAC,mCAAmC,CAAC;IAC/F,8FAA8F;IAC9F,OAAO,EAAE,MAAM,OAAO,CAAC;CACxB;AAID,QAAA,MAAM,OAAO,EAAE,aAId,CAAC;AAIF,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * React Fast Refresh for the dev loop (docs/native.md, "Development loop").
3
+ * The refresh runtime must install its hook before React's reconciler loads,
4
+ * so the vendor bundle imports this module first. The app bundle's modules,
5
+ * transformed by `react-refresh/babel` (devBuild.ts), register their
6
+ * components through `__sbRefresh`; `run` performs the refresh when the app
7
+ * bundle is evaluated again.
8
+ */
9
+ import RefreshRuntime from 'react-refresh/runtime';
10
+ RefreshRuntime.injectIntoGlobalHook(globalThis);
11
+ const refresh = {
12
+ register: (type, id) => RefreshRuntime.register(type, id),
13
+ createSignatureFunctionForTransform: RefreshRuntime.createSignatureFunctionForTransform,
14
+ perform: () => RefreshRuntime.performReactRefresh() !== null,
15
+ };
16
+ globalThis.__sbRefresh = refresh;
17
+ export { refresh };
18
+ //# sourceMappingURL=refresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh.js","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,cAAc,MAAM,uBAAuB,CAAC;AASnD,cAAc,CAAC,oBAAoB,CAAC,UAA+B,CAAC,CAAC;AAErE,MAAM,OAAO,GAAkB;IAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;IACzD,mCAAmC,EAAE,cAAc,CAAC,mCAAmC;IACvF,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,mBAAmB,EAAE,KAAK,IAAI;CAC7D,CAAC;AAED,UAAwD,CAAC,WAAW,GAAG,OAAO,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `run(element)`: a `@swiftbrowser/react` root whose ops go to the native
3
+ * renderer over the bridge, and whose events come back from it. The native
4
+ * counterpart of `mount` in @swiftbrowser/react, without the DOM.
5
+ *
6
+ * The bridge is synchronous both ways: `__sbApplyOps` returns when the tree
7
+ * has the pass, and Swift's `__sbDispatch(json)` returns when the handler
8
+ * ran and its pass was applied (docs/native.md, "Synchronous calls").
9
+ */
10
+ import { type SwiftUIRoot } from '@swiftbrowser/react';
11
+ import type { RendererEvent } from '@swiftbrowser/web/src/protocol';
12
+ import type { ReactNode } from 'react';
13
+ import { type NativeBridge } from './bridge';
14
+ export interface RunOptions {
15
+ /** The bridge to render through; the global `__sbNative` by default. */
16
+ native?: NativeBridge;
17
+ /** Called with an error applying ops threw on the native side, or a handler threw. */
18
+ onError?: (error: unknown) => void;
19
+ }
20
+ export interface Running {
21
+ root: SwiftUIRoot;
22
+ /** Deliver an event as the native side does (tests). */
23
+ dispatch(event: RendererEvent | string): void;
24
+ unmount(): void;
25
+ }
26
+ export declare function run(element: ReactNode, options?: RunOptions): Running;
27
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,EAAM,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,sFAAsF;IACtF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9C,OAAO,IAAI,IAAI,CAAC;CACjB;AAYD,wBAAgB,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CA0DzE"}
package/dist/run.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `run(element)`: a `@swiftbrowser/react` root whose ops go to the native
3
+ * renderer over the bridge, and whose events come back from it. The native
4
+ * counterpart of `mount` in @swiftbrowser/react, without the DOM.
5
+ *
6
+ * The bridge is synchronous both ways: `__sbApplyOps` returns when the tree
7
+ * has the pass, and Swift's `__sbDispatch(json)` returns when the handler
8
+ * ran and its pass was applied (docs/native.md, "Synchronous calls").
9
+ */
10
+ import { createSwiftUIRoot } from '@swiftbrowser/react';
11
+ import { nativeBridge } from './bridge';
12
+ /** The running app, when `run` was called (the dev loop calls it again on every save). */
13
+ let current = null;
14
+ export function run(element, options = {}) {
15
+ const native = options.native ?? nativeBridge();
16
+ if (!native)
17
+ throw new Error('run(): no native bridge (__sbNative); this entry runs inside a SwiftBrowser Native app');
18
+ const report = options.onError ?? ((error) => native.log('error', error instanceof Error ? (error.stack ?? error.message) : String(error)));
19
+ if (current) {
20
+ // Fast Refresh (devBuild.ts): the app bundle was evaluated again. Its
21
+ // modules re-registered their components; the refresh runtime updates
22
+ // the mounted ones in place (state kept where the hooks are unchanged),
23
+ // and the new tree renders into the same root.
24
+ const refresh = globalThis.__sbRefresh;
25
+ try {
26
+ refresh?.perform();
27
+ current.root.render(element);
28
+ }
29
+ catch (error) {
30
+ report(error);
31
+ }
32
+ return current;
33
+ }
34
+ const root = createSwiftUIRoot((ops) => {
35
+ const failure = native.applyOps(JSON.stringify(ops));
36
+ if (failure)
37
+ report(new Error(`applyOps: ${failure}`));
38
+ });
39
+ const dispatch = (event) => {
40
+ const parsed = typeof event === 'string' ? JSON.parse(event) : event;
41
+ try {
42
+ if (parsed.type === 'environment') {
43
+ const fields = parsed;
44
+ const next = {};
45
+ if (fields.colorScheme)
46
+ next.colorScheme = fields.colorScheme;
47
+ if (fields.dynamicTypeSize)
48
+ next['dynamicTypeSize'] = fields.dynamicTypeSize;
49
+ if (fields.horizontalSizeClass)
50
+ next.horizontalSizeClass = fields.horizontalSizeClass;
51
+ if (Object.keys(next).length > 0)
52
+ root.setEnvironment(next);
53
+ return;
54
+ }
55
+ root.dispatch(parsed);
56
+ }
57
+ catch (error) {
58
+ report(error);
59
+ }
60
+ };
61
+ const g = globalThis;
62
+ g['__sbDispatch'] = (json) => dispatch(json);
63
+ root.render(element);
64
+ current = {
65
+ root,
66
+ dispatch,
67
+ unmount() {
68
+ root.unmount();
69
+ if (g['__sbDispatch'])
70
+ delete g['__sbDispatch'];
71
+ current = null;
72
+ },
73
+ };
74
+ return current;
75
+ }
76
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAoB,MAAM,qBAAqB,CAAC;AAG1E,OAAO,EAAE,YAAY,EAAqB,MAAM,UAAU,CAAC;AAuB3D,0FAA0F;AAC1F,IAAI,OAAO,GAAmB,IAAI,CAAC;AAEnC,MAAM,UAAU,GAAG,CAAC,OAAkB,EAAE,UAAsB,EAAE;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC;IAChD,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAC;IACvH,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAErJ,IAAI,OAAO,EAAE,CAAC;QACZ,sEAAsE;QACtE,sEAAsE;QACtE,wEAAwE;QACxE,+CAA+C;QAC/C,MAAM,OAAO,GA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AAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAC5D,OAAO;YACT,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,GAAG,UAAgD,CAAC;IAC3D,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAErD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAErB,OAAO,GAAG;QACR,IAAI;QACJ,QAAQ;QACR,OAAO;YACL,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,cAAc,CAAC;gBAAE,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC;YAChD,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The web globals a JavaScriptCore app expects, built on the bridge's
3
+ * primitives (`__sbNative`, see bridge.ts). React's scheduler reads
4
+ * `setTimeout` and `performance.now` when its module loads, so this module
5
+ * installs everything at import time and the bundler (build.ts) puts it
6
+ * first in `app.js`.
7
+ *
8
+ * What is installed when missing: `setTimeout`, `setInterval`, `clearTimeout`,
9
+ * `clearInterval`, `requestAnimationFrame`, `cancelAnimationFrame`,
10
+ * `queueMicrotask`, `console`, `performance`, `TextEncoder`, `TextDecoder`,
11
+ * `atob`, `btoa`, `fetch` with `Headers`, `Request`, `Response`,
12
+ * `AbortController` and `AbortSignal`, `URL`, `URLSearchParams`, `crypto`
13
+ * (`getRandomValues`, `randomUUID`), `localStorage`, `structuredClone`,
14
+ * `navigator`, and the bridge's callbacks `__sbTimerFired` and
15
+ * `__sbFetchResult`. `window` and `document` are not defined: code that
16
+ * checks for them takes its headless path, as it should here.
17
+ */
18
+ import { type NativeBridge } from './bridge';
19
+ type AnyGlobal = Record<string, unknown>;
20
+ export interface InstallOptions {
21
+ /** Install over globals that exist already (tests). */
22
+ force?: boolean;
23
+ }
24
+ /**
25
+ * Installs the runtime on `target` (the global object) over `native`.
26
+ * Returns what it installed, by name.
27
+ */
28
+ export declare function installRuntime(native: NativeBridge, target?: AnyGlobal, options?: InstallOptions): string[];
29
+ export {};
30
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAK3D,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAQzC,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,GAAE,SAA8C,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,EAAE,CAkKnJ"}
@@ -0,0 +1,193 @@
1
+ /**
2
+ * The web globals a JavaScriptCore app expects, built on the bridge's
3
+ * primitives (`__sbNative`, see bridge.ts). React's scheduler reads
4
+ * `setTimeout` and `performance.now` when its module loads, so this module
5
+ * installs everything at import time and the bundler (build.ts) puts it
6
+ * first in `app.js`.
7
+ *
8
+ * What is installed when missing: `setTimeout`, `setInterval`, `clearTimeout`,
9
+ * `clearInterval`, `requestAnimationFrame`, `cancelAnimationFrame`,
10
+ * `queueMicrotask`, `console`, `performance`, `TextEncoder`, `TextDecoder`,
11
+ * `atob`, `btoa`, `fetch` with `Headers`, `Request`, `Response`,
12
+ * `AbortController` and `AbortSignal`, `URL`, `URLSearchParams`, `crypto`
13
+ * (`getRandomValues`, `randomUUID`), `localStorage`, `structuredClone`,
14
+ * `navigator`, and the bridge's callbacks `__sbTimerFired` and
15
+ * `__sbFetchResult`. `window` and `document` are not defined: code that
16
+ * checks for them takes its headless path, as it should here.
17
+ */
18
+ import { nativeBridge } from './bridge';
19
+ import { atobPolyfill, base64Decode, btoaPolyfill, SimpleTextDecoder, SimpleTextEncoder } from './encoding';
20
+ import { createFetch } from './fetch';
21
+ import { SimpleURL, SimpleURLSearchParams } from './url';
22
+ /**
23
+ * Installs the runtime on `target` (the global object) over `native`.
24
+ * Returns what it installed, by name.
25
+ */
26
+ export function installRuntime(native, target = globalThis, options = {}) {
27
+ const installed = [];
28
+ const define = (name, value) => {
29
+ if (!options.force && target[name] !== undefined)
30
+ return;
31
+ Object.defineProperty(target, name, { value, writable: true, configurable: true, enumerable: false });
32
+ installed.push(name);
33
+ };
34
+ // Timers: one native timer per JavaScript timer, by id.
35
+ const timers = new Map();
36
+ let nextTimer = 1;
37
+ const schedule = (callback, delay, args, repeats) => {
38
+ const id = nextTimer++;
39
+ const fn = typeof callback === 'function' ? callback : () => { };
40
+ timers.set(id, { callback: fn, args, repeats });
41
+ native.setTimer(id, Math.max(0, Number(delay) || 0), repeats);
42
+ return id;
43
+ };
44
+ const cancel = (id) => {
45
+ const key = Number(id);
46
+ if (!timers.delete(key))
47
+ return;
48
+ native.clearTimer(key);
49
+ };
50
+ const fired = (id) => {
51
+ const entry = timers.get(id);
52
+ if (!entry)
53
+ return;
54
+ if (!entry.repeats)
55
+ timers.delete(id);
56
+ entry.callback(...entry.args);
57
+ };
58
+ define('setTimeout', (callback, delay, ...args) => schedule(callback, delay, args, false));
59
+ define('setInterval', (callback, delay, ...args) => schedule(callback, delay, args, true));
60
+ define('clearTimeout', cancel);
61
+ define('clearInterval', cancel);
62
+ define('__sbTimerFired', fired);
63
+ // Animation frames: a 60 Hz timer; the callback gets the time.
64
+ const now = () => native.now();
65
+ define('requestAnimationFrame', (callback) => schedule(() => callback(now()), 16, [], false));
66
+ define('cancelAnimationFrame', cancel);
67
+ define('queueMicrotask', (callback) => {
68
+ Promise.resolve().then(callback);
69
+ });
70
+ // The console: one line per call, formatted here.
71
+ const format = (value) => {
72
+ if (typeof value === 'string')
73
+ return value;
74
+ if (value instanceof Error)
75
+ return value.stack ? String(value.stack) : `${value.name}: ${value.message}`;
76
+ if (typeof value === 'function')
77
+ return `[Function ${value.name || 'anonymous'}]`;
78
+ if (typeof value === 'symbol' || typeof value === 'bigint')
79
+ return value.toString();
80
+ try {
81
+ const json = JSON.stringify(value, (_key, inner) => (inner instanceof Error ? `${inner.name}: ${inner.message}` : inner), 2);
82
+ return json === undefined ? String(value) : json;
83
+ }
84
+ catch {
85
+ return String(value);
86
+ }
87
+ };
88
+ const log = (level) => (...args) => native.log(level, args.map(format).join(' '));
89
+ const timersByLabel = new Map();
90
+ const counts = new Map();
91
+ define('console', {
92
+ log: log('log'),
93
+ info: log('info'),
94
+ warn: log('warn'),
95
+ error: log('error'),
96
+ debug: log('debug'),
97
+ trace: log('debug'),
98
+ dir: log('log'),
99
+ table: log('log'),
100
+ group: log('log'),
101
+ groupCollapsed: log('log'),
102
+ groupEnd: () => { },
103
+ assert: (condition, ...args) => {
104
+ if (!condition)
105
+ native.log('error', `Assertion failed${args.length ? `: ${args.map(format).join(' ')}` : ''}`);
106
+ },
107
+ count: (label = 'default') => {
108
+ const count = (counts.get(label) ?? 0) + 1;
109
+ counts.set(label, count);
110
+ native.log('log', `${label}: ${count}`);
111
+ },
112
+ countReset: (label = 'default') => counts.delete(label),
113
+ time: (label = 'default') => timersByLabel.set(label, now()),
114
+ timeEnd: (label = 'default') => {
115
+ const start = timersByLabel.get(label);
116
+ if (start !== undefined)
117
+ native.log('log', `${label}: ${(now() - start).toFixed(3)} ms`);
118
+ timersByLabel.delete(label);
119
+ },
120
+ timeLog: (label = 'default') => {
121
+ const start = timersByLabel.get(label);
122
+ if (start !== undefined)
123
+ native.log('log', `${label}: ${(now() - start).toFixed(3)} ms`);
124
+ },
125
+ });
126
+ const origin = Date.now() - now();
127
+ define('performance', {
128
+ now,
129
+ timeOrigin: origin,
130
+ mark: () => { },
131
+ measure: () => { },
132
+ getEntries: () => [],
133
+ getEntriesByName: () => [],
134
+ getEntriesByType: () => [],
135
+ clearMarks: () => { },
136
+ clearMeasures: () => { },
137
+ });
138
+ define('TextEncoder', SimpleTextEncoder);
139
+ define('TextDecoder', SimpleTextDecoder);
140
+ define('atob', atobPolyfill);
141
+ define('btoa', btoaPolyfill);
142
+ const fetchGlobals = createFetch(native);
143
+ define('fetch', fetchGlobals.fetch);
144
+ define('Headers', fetchGlobals.Headers);
145
+ define('Request', fetchGlobals.Request);
146
+ define('Response', fetchGlobals.Response);
147
+ define('AbortController', fetchGlobals.AbortController);
148
+ define('AbortSignal', fetchGlobals.AbortSignal);
149
+ define('__sbFetchResult', fetchGlobals.__sbFetchResult);
150
+ define('URL', SimpleURL);
151
+ define('URLSearchParams', SimpleURLSearchParams);
152
+ define('crypto', {
153
+ getRandomValues: (array) => {
154
+ const bytes = base64Decode(native.randomBytes(array.byteLength));
155
+ new Uint8Array(array.buffer, array.byteOffset, array.byteLength).set(bytes.subarray(0, array.byteLength));
156
+ return array;
157
+ },
158
+ randomUUID: () => {
159
+ const bytes = base64Decode(native.randomBytes(16));
160
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
161
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
162
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
163
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
164
+ },
165
+ });
166
+ const storage = {
167
+ getItem: (key) => native.storageGet(String(key)),
168
+ setItem: (key, value) => native.storageSet(String(key), String(value)),
169
+ removeItem: (key) => native.storageRemove(String(key)),
170
+ clear: () => native.storageClear(),
171
+ key: (index) => native.storageKeys()[index] ?? null,
172
+ get length() {
173
+ return native.storageKeys().length;
174
+ },
175
+ };
176
+ define('localStorage', storage);
177
+ define('structuredClone', (value) => (value === undefined ? value : JSON.parse(JSON.stringify(value))));
178
+ define('navigator', {
179
+ userAgent: 'SwiftBrowserNative',
180
+ language: native.locale().replace('_', '-'),
181
+ languages: [native.locale().replace('_', '-')],
182
+ onLine: true,
183
+ platform: 'iOS',
184
+ hardwareConcurrency: 1,
185
+ });
186
+ return installed;
187
+ }
188
+ // Installed at import, over the bridge the app runs in. Outside it (a test,
189
+ // a bundler's dry run) nothing happens until `installRuntime` is called.
190
+ const bridge = nativeBridge();
191
+ if (bridge)
192
+ installRuntime(bridge);
193
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAqB,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAezD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAoB,EAAE,SAAoB,UAAkC,EAAE,UAA0B,EAAE;IACvI,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAc,EAAQ,EAAE;QACpD,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,OAAO;QACzD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QACtG,SA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AAC;KACF,CAAC;IACF,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IAEhC,MAAM,CAAC,iBAAiB,EAAE,CAAI,KAAQ,EAAK,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAO,CAAC,CAAC,CAAC;IAExH,MAAM,CAAC,WAAW,EAAE;QAClB,SAAS,EAAE,oBAAoB;QAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;QAC3C,SAAS,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC9C,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,KAAK;QACf,mBAAmB,EAAE,CAAC;KACvB,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,4EAA4E;AAC5E,yEAAyE;AACzE,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;AAC9B,IAAI,MAAM;IAAE,cAAc,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** `react-dom/client` for the native bundle: no DOM, so no roots (see react-dom.ts). */
2
+ export interface Root {
3
+ render(children: unknown): void;
4
+ unmount(): void;
5
+ }
6
+ export declare function createRoot(): Root;
7
+ export declare function hydrateRoot(): Root;
8
+ //# sourceMappingURL=react-dom-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-dom-client.d.ts","sourceRoot":"","sources":["../../src/stubs/react-dom-client.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAExF,MAAM,WAAW,IAAI;IACnB,MAAM,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,wBAAgB,UAAU,IAAI,IAAI,CAKjC;AAED,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
@@ -0,0 +1,11 @@
1
+ /** `react-dom/client` for the native bundle: no DOM, so no roots (see react-dom.ts). */
2
+ export function createRoot() {
3
+ return {
4
+ render() { },
5
+ unmount() { },
6
+ };
7
+ }
8
+ export function hydrateRoot() {
9
+ return createRoot();
10
+ }
11
+ //# sourceMappingURL=react-dom-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-dom-client.js","sourceRoot":"","sources":["../../src/stubs/react-dom-client.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAOxF,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,MAAM,KAAI,CAAC;QACX,OAAO,KAAI,CAAC;KACb,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `react-dom` as the native bundle sees it. @swiftbrowser/react's `Host`
3
+ * component (React DOM inside a SwiftUI tree) imports it; there is no DOM
4
+ * here, so a `Host` renders nothing and `flushSync` just runs its function.
5
+ */
6
+ export declare function flushSync<R>(fn?: () => R): R | undefined;
7
+ export declare function createPortal(): null;
8
+ export declare const version = "0.0.0-swiftbrowser-native";
9
+ //# sourceMappingURL=react-dom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-dom.d.ts","sourceRoot":"","sources":["../../src/stubs/react-dom.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wBAAgB,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAExD;AAED,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED,eAAO,MAAM,OAAO,8BAA8B,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `react-dom` as the native bundle sees it. @swiftbrowser/react's `Host`
3
+ * component (React DOM inside a SwiftUI tree) imports it; there is no DOM
4
+ * here, so a `Host` renders nothing and `flushSync` just runs its function.
5
+ */
6
+ export function flushSync(fn) {
7
+ return fn?.();
8
+ }
9
+ export function createPortal() {
10
+ return null;
11
+ }
12
+ export const version = '0.0.0-swiftbrowser-native';
13
+ //# sourceMappingURL=react-dom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-dom.js","sourceRoot":"","sources":["../../src/stubs/react-dom.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,UAAU,SAAS,CAAI,EAAY;IACvC,OAAO,EAAE,EAAE,EAAE,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,2BAA2B,CAAC"}
package/dist/url.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `URL` and `URLSearchParams` for an engine without them. Enough for what
3
+ * apps and libraries do with them (build and read absolute URLs, query
4
+ * strings); not the whole WHATWG parser: no IDNA, no percent-encoding
5
+ * normalization beyond `encodeURIComponent` in the search params.
6
+ */
7
+ export declare class SimpleURLSearchParams {
8
+ private entries;
9
+ /** Called when the params change, so an owning URL updates its `search`. */
10
+ onChange: (() => void) | null;
11
+ constructor(init?: string | Record<string, string> | [string, string][] | SimpleURLSearchParams);
12
+ get size(): number;
13
+ append(name: string, value: string): void;
14
+ delete(name: string): void;
15
+ get(name: string): string | null;
16
+ getAll(name: string): string[];
17
+ has(name: string): boolean;
18
+ set(name: string, value: string): void;
19
+ sort(): void;
20
+ forEach(callback: (value: string, key: string, parent: SimpleURLSearchParams) => void): void;
21
+ keys(): IterableIterator<string>;
22
+ values(): IterableIterator<string>;
23
+ [Symbol.iterator](): IterableIterator<[string, string]>;
24
+ toString(): string;
25
+ }
26
+ export declare class SimpleURL {
27
+ protocol: string;
28
+ username: string;
29
+ password: string;
30
+ hostname: string;
31
+ port: string;
32
+ pathname: string;
33
+ hash: string;
34
+ readonly searchParams: SimpleURLSearchParams;
35
+ private _search;
36
+ constructor(url: string, base?: string | SimpleURL);
37
+ get search(): string;
38
+ set search(value: string);
39
+ get host(): string;
40
+ set host(value: string);
41
+ get origin(): string;
42
+ get href(): string;
43
+ set href(value: string);
44
+ toString(): string;
45
+ toJSON(): string;
46
+ static canParse(url: string, base?: string): boolean;
47
+ }
48
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,OAAO,CAA0B;IACzC,4EAA4E;IAC5E,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;gBAEzB,IAAI,GAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,qBAA0B;IAmBnG,IAAI,IAAI,IAAI,MAAM,CAEjB;IACD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAGhC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAG9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAG1B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAStC,IAAI,IAAI,IAAI;IAIZ,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,KAAK,IAAI,GAAG,IAAI;IAG5F,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAGhC,MAAM,IAAI,gBAAgB,CAAC,MAAM,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