@nstudio/nativescript-effect-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/crash/index.d.ts +49 -0
- package/dist/crash/index.d.ts.map +1 -0
- package/dist/crash/index.js +199 -0
- package/dist/crash/index.js.map +1 -0
- package/dist/devtools/index.d.ts +77 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools/index.js +158 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard/index.d.ts +97 -0
- package/dist/keyboard/index.d.ts.map +1 -0
- package/dist/keyboard/index.js +226 -0
- package/dist/keyboard/index.js.map +1 -0
- package/dist/list/index.d.ts +91 -0
- package/dist/list/index.d.ts.map +1 -0
- package/dist/list/index.js +192 -0
- package/dist/list/index.js.map +1 -0
- package/dist/macos/MacosHost.d.ts +77 -0
- package/dist/macos/MacosHost.d.ts.map +1 -0
- package/dist/macos/MacosHost.js +878 -0
- package/dist/macos/MacosHost.js.map +1 -0
- package/dist/macos/index.d.ts +5 -0
- package/dist/macos/index.d.ts.map +1 -0
- package/dist/macos/index.js +5 -0
- package/dist/macos/index.js.map +1 -0
- package/dist/macos/layout.d.ts +39 -0
- package/dist/macos/layout.d.ts.map +1 -0
- package/dist/macos/layout.js +226 -0
- package/dist/macos/layout.js.map +1 -0
- package/dist/macos/platform.d.ts +12 -0
- package/dist/macos/platform.d.ts.map +1 -0
- package/dist/macos/platform.js +103 -0
- package/dist/macos/platform.js.map +1 -0
- package/dist/macos/styles.d.ts +66 -0
- package/dist/macos/styles.d.ts.map +1 -0
- package/dist/macos/styles.js +350 -0
- package/dist/macos/styles.js.map +1 -0
- package/dist/mason/MasonHost.d.ts +102 -0
- package/dist/mason/MasonHost.d.ts.map +1 -0
- package/dist/mason/MasonHost.js +413 -0
- package/dist/mason/MasonHost.js.map +1 -0
- package/dist/mason/dialog.d.ts +23 -0
- package/dist/mason/dialog.d.ts.map +1 -0
- package/dist/mason/dialog.js +186 -0
- package/dist/mason/dialog.js.map +1 -0
- package/dist/mason/elements.d.ts +50 -0
- package/dist/mason/elements.d.ts.map +1 -0
- package/dist/mason/elements.js +194 -0
- package/dist/mason/elements.js.map +1 -0
- package/dist/mason/events.d.ts +37 -0
- package/dist/mason/events.d.ts.map +1 -0
- package/dist/mason/events.js +304 -0
- package/dist/mason/events.js.map +1 -0
- package/dist/mason/index.d.ts +6 -0
- package/dist/mason/index.d.ts.map +1 -0
- package/dist/mason/index.js +6 -0
- package/dist/mason/index.js.map +1 -0
- package/dist/mason/services.d.ts +36 -0
- package/dist/mason/services.d.ts.map +1 -0
- package/dist/mason/services.js +268 -0
- package/dist/mason/services.js.map +1 -0
- package/dist/mason/styles.d.ts +20 -0
- package/dist/mason/styles.d.ts.map +1 -0
- package/dist/mason/styles.js +269 -0
- package/dist/mason/styles.js.map +1 -0
- package/dist/motion/index.d.ts +179 -0
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +332 -0
- package/dist/motion/index.js.map +1 -0
- package/dist/native/Native.d.ts +163 -0
- package/dist/native/Native.d.ts.map +1 -0
- package/dist/native/Native.js +144 -0
- package/dist/native/Native.js.map +1 -0
- package/dist/native/NativeCommand.d.ts +36 -0
- package/dist/native/NativeCommand.d.ts.map +1 -0
- package/dist/native/NativeCommand.js +38 -0
- package/dist/native/NativeCommand.js.map +1 -0
- package/dist/native/NativeHost.d.ts +46 -0
- package/dist/native/NativeHost.d.ts.map +1 -0
- package/dist/native/NativeHost.js +346 -0
- package/dist/native/NativeHost.js.map +1 -0
- package/dist/native/index.d.ts +4 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.js +4 -0
- package/dist/native/index.js.map +1 -0
- package/dist/platform/index.d.ts +86 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +131 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/native.d.ts +12 -0
- package/dist/platform/native.d.ts.map +1 -0
- package/dist/platform/native.js +127 -0
- package/dist/platform/native.js.map +1 -0
- package/dist/sheet/index.d.ts +113 -0
- package/dist/sheet/index.d.ts.map +1 -0
- package/dist/sheet/index.js +202 -0
- package/dist/sheet/index.js.map +1 -0
- package/dist/testing/MockMasonHost.d.ts +48 -0
- package/dist/testing/MockMasonHost.d.ts.map +1 -0
- package/dist/testing/MockMasonHost.js +142 -0
- package/dist/testing/MockMasonHost.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +116 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright OpenJS Foundation and other contributors, https://openjsf.org/
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nstudio/nativescript-effect-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
NativeScript and macOS AppKit rendering hosts, platform Effect Layers, and pure-TypeScript native primitives for [`@effect/ui`](https://github.com/Effect-TS/ui).
|
|
4
|
+
|
|
5
|
+
Mount standard `@effect/ui/html` (`Html.component`) trees directly onto native iOS, Android, and macOS views with zero WebViews, or compose native UIKit/AppKit/Android views directly via `NativeHost`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @nstudio/nativescript-effect-ui effect
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@effect/ui` is currently in public preview on `pkg.pr.new`:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install https://pkg.pr.new/Effect-TS/ui/@effect/ui@5cb34b2
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Install the optional platform peer dependencies for the targets you use:
|
|
20
|
+
|
|
21
|
+
- **iOS and Android (`MasonHost` / `NativeHost`)**: `@nativescript/core` and `@triniwiz/nativescript-masonkit`
|
|
22
|
+
- **macOS Desktop (`MacosHost`)**: `@nativescript/macos-node-api`
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### iOS and Android (`MasonHost`)
|
|
27
|
+
|
|
28
|
+
Mounts unmodified `@effect/ui/html` components onto native iOS and Android views backed by MasonKit's Rust/Taffy CSS Flexbox and Grid layout engine.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { MasonHost } from '@nstudio/nativescript-effect-ui/mason';
|
|
32
|
+
import { NativePlatformLayer } from '@nstudio/nativescript-effect-ui/platform/native';
|
|
33
|
+
import { App } from './App';
|
|
34
|
+
|
|
35
|
+
MasonHost.run(App, {}, {
|
|
36
|
+
title: 'Effect Pulse',
|
|
37
|
+
layer: NativePlatformLayer,
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### macOS Desktop (`MacosHost`)
|
|
42
|
+
|
|
43
|
+
Mounts the same `@effect/ui/html` components onto real AppKit views (`NSWindow`, `NSView`, `NSTextField`, `NSButton`, `NSScrollView`) with zero WebViews or Electron.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { MacosHost, MacosPlatformLayer } from '@nstudio/nativescript-effect-ui/macos';
|
|
47
|
+
import { App } from './App';
|
|
48
|
+
|
|
49
|
+
await MacosHost.run(App, {}, {
|
|
50
|
+
title: 'Effect Pulse',
|
|
51
|
+
width: 460,
|
|
52
|
+
height: 820,
|
|
53
|
+
layer: MacosPlatformLayer,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Subpath Exports
|
|
58
|
+
|
|
59
|
+
| Subpath | Description |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `@nstudio/nativescript-effect-ui` | Platform service contracts (`Haptics`, `Share`, `Storage`, `DeviceInfo`, `PlatformAppearance`) |
|
|
62
|
+
| `@nstudio/nativescript-effect-ui/mason` | `MasonHost` for standard `@effect/ui/html` on native iOS and Android |
|
|
63
|
+
| `@nstudio/nativescript-effect-ui/macos` | `MacosHost` and `MacosPlatformLayer` for native macOS AppKit |
|
|
64
|
+
| `@nstudio/nativescript-effect-ui/native` | `NativeHost`, `Native`, and `NativeCommand` for direct NativeScript view vocabularies |
|
|
65
|
+
| `@nstudio/nativescript-effect-ui/platform` | Shared platform service interfaces and Web/fallback layers |
|
|
66
|
+
| `@nstudio/nativescript-effect-ui/platform/native` | NativeScript `NativePlatformLayer` implementations for iOS and Android |
|
|
67
|
+
| `@nstudio/nativescript-effect-ui/motion` | UI-thread spring and timing motion (`UIViewPropertyAnimator` / Android `Animator`) |
|
|
68
|
+
| `@nstudio/nativescript-effect-ui/sheet` | Native bottom sheets (`UISheetPresentationController` / Android `BottomSheetDialog`) |
|
|
69
|
+
| `@nstudio/nativescript-effect-ui/list` | Virtualized recycled lists (`UITableView` / `RecyclerView`) |
|
|
70
|
+
| `@nstudio/nativescript-effect-ui/keyboard` | Keyboard-docked input accessories (`inputAccessoryView` / Android IME insets) |
|
|
71
|
+
| `@nstudio/nativescript-effect-ui/crash` | Unhandled fault boundary and recovery view |
|
|
72
|
+
| `@nstudio/nativescript-effect-ui/devtools` | Runtime inspector and `@effect/ui` devtools bridge |
|
|
73
|
+
| `@nstudio/nativescript-effect-ui/testing` | Host testing utilities and mock platform layers |
|
|
74
|
+
|
|
75
|
+
## Examples and Documentation
|
|
76
|
+
|
|
77
|
+
Full monorepo with shared Web, iOS, Android, and macOS apps: [github.com/nstudio/ns-effect-ui](https://github.com/nstudio/ns-effect-ui)
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT License. Copyright OpenJS Foundation and other contributors. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as Schema from 'effect/Schema';
|
|
2
|
+
export declare const CrashReport: Schema.Struct<{
|
|
3
|
+
readonly title: Schema.String;
|
|
4
|
+
readonly message: Schema.String;
|
|
5
|
+
readonly stack: Schema.String;
|
|
6
|
+
readonly componentName: Schema.String;
|
|
7
|
+
readonly timestamp: Schema.String;
|
|
8
|
+
}>;
|
|
9
|
+
export type CrashReport = typeof CrashReport.Type;
|
|
10
|
+
/**
|
|
11
|
+
* Builds a structured `CrashReport` from any Effect `AsyncResult.Failure`,
|
|
12
|
+
* `Cause`, or JS error value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildCrashReport(failure: unknown, componentName?: string, now?: () => Date): CrashReport;
|
|
15
|
+
/**
|
|
16
|
+
* Formats a `CrashReport` into a plain-text diagnostic block suitable for
|
|
17
|
+
* copying to the system clipboard or pasting into an issue tracker.
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatCrashText(report: CrashReport): string;
|
|
20
|
+
export interface CrashFallbackOptions {
|
|
21
|
+
readonly componentName?: string | undefined;
|
|
22
|
+
readonly onCopy?: ((text: string) => void) | undefined;
|
|
23
|
+
readonly onRestart?: (() => void) | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Drop-in `fallback` renderer for `MasonHost.mount(...)` / `BrowserHost.mount(...)`.
|
|
27
|
+
*
|
|
28
|
+
* Renders a high-contrast recovery card with diagnostic details, Copy button,
|
|
29
|
+
* and Start Again button using standard HTML elements.
|
|
30
|
+
*/
|
|
31
|
+
export declare function makeHtmlCrashFallback(options?: CrashFallbackOptions | undefined): (failure: unknown, h: any) => any;
|
|
32
|
+
/**
|
|
33
|
+
* Drop-in `fallback` renderer for `NativeHost.mount(...)` (Strategy A).
|
|
34
|
+
*/
|
|
35
|
+
export declare function makeNativeCrashFallback(options?: CrashFallbackOptions | undefined): (failure: unknown, h: any) => any;
|
|
36
|
+
export declare const NativeCrash: {
|
|
37
|
+
readonly CrashReport: Schema.Struct<{
|
|
38
|
+
readonly title: Schema.String;
|
|
39
|
+
readonly message: Schema.String;
|
|
40
|
+
readonly stack: Schema.String;
|
|
41
|
+
readonly componentName: Schema.String;
|
|
42
|
+
readonly timestamp: Schema.String;
|
|
43
|
+
}>;
|
|
44
|
+
readonly buildCrashReport: typeof buildCrashReport;
|
|
45
|
+
readonly formatCrashText: typeof formatCrashText;
|
|
46
|
+
readonly makeHtmlCrashFallback: typeof makeHtmlCrashFallback;
|
|
47
|
+
readonly makeNativeCrashFallback: typeof makeNativeCrashFallback;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crash/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,eAAO,MAAM,WAAW;;;;;;EAMtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAoClD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,EAChB,aAAa,SAAgB,EAC7B,GAAG,GAAE,MAAM,IAAuB,GACjC,WAAW,CASb;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAS3D;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CAC/C;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,IACtE,SAAS,OAAO,EAAE,GAAG,GAAG,KAAG,GAAG,CAsDvC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,IACxE,SAAS,OAAO,EAAE,GAAG,GAAG,KAAG,GAAG,CA0DvC;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;CAMd,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crash recovery boundary (`NativeCrash`) for `@nstudio/nativescript-effect-ui`.
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - Clean `CrashReport` extraction from Effect `Cause`, `AsyncResult.Failure`,
|
|
6
|
+
* or raw JS exceptions.
|
|
7
|
+
* - Drop-in `fallback` view factories for both `MasonHost` (`Html`) and
|
|
8
|
+
* `NativeHost` (`Native`) with one-tap diagnostics copy and instant restart.
|
|
9
|
+
* - Optional hook into NativeScript's `Application.uncaughtErrorEvent` so an
|
|
10
|
+
* unexpected runtime error surfaces a recovery UI rather than a blank screen.
|
|
11
|
+
*/
|
|
12
|
+
import * as Cause from 'effect/Cause';
|
|
13
|
+
import * as Schema from 'effect/Schema';
|
|
14
|
+
export const CrashReport = Schema.Struct({
|
|
15
|
+
title: Schema.String,
|
|
16
|
+
message: Schema.String,
|
|
17
|
+
stack: Schema.String,
|
|
18
|
+
componentName: Schema.String,
|
|
19
|
+
timestamp: Schema.String,
|
|
20
|
+
});
|
|
21
|
+
function extractErrorDetails(failure) {
|
|
22
|
+
if (failure && typeof failure === 'object') {
|
|
23
|
+
// Handle Effect AsyncResult.Failure ({ _tag: "Failure", cause })
|
|
24
|
+
const asFailure = failure;
|
|
25
|
+
if (asFailure._tag === 'Failure' && asFailure.cause !== undefined) {
|
|
26
|
+
try {
|
|
27
|
+
const pretty = Cause.pretty(asFailure.cause);
|
|
28
|
+
const lines = pretty.split('\n');
|
|
29
|
+
return {
|
|
30
|
+
message: lines[0] || 'Unhandled Effect failure',
|
|
31
|
+
stack: pretty,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Fall through
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (failure instanceof Error) {
|
|
39
|
+
return {
|
|
40
|
+
message: failure.message || failure.name || 'Unexpected error',
|
|
41
|
+
stack: failure.stack ?? String(failure),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const maybeMsg = failure.message;
|
|
45
|
+
if (typeof maybeMsg === 'string') {
|
|
46
|
+
return {
|
|
47
|
+
message: maybeMsg,
|
|
48
|
+
stack: String(failure.stack ?? maybeMsg),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const text = String(failure ?? 'Unknown error');
|
|
53
|
+
return { message: text, stack: text };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Builds a structured `CrashReport` from any Effect `AsyncResult.Failure`,
|
|
57
|
+
* `Cause`, or JS error value.
|
|
58
|
+
*/
|
|
59
|
+
export function buildCrashReport(failure, componentName = 'EffectUIApp', now = () => new Date()) {
|
|
60
|
+
const { message, stack } = extractErrorDetails(failure);
|
|
61
|
+
return {
|
|
62
|
+
title: `${componentName} encountered an error`,
|
|
63
|
+
message,
|
|
64
|
+
stack,
|
|
65
|
+
componentName,
|
|
66
|
+
timestamp: now().toISOString(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Formats a `CrashReport` into a plain-text diagnostic block suitable for
|
|
71
|
+
* copying to the system clipboard or pasting into an issue tracker.
|
|
72
|
+
*/
|
|
73
|
+
export function formatCrashText(report) {
|
|
74
|
+
return [
|
|
75
|
+
`[${report.componentName}] ${report.title}`,
|
|
76
|
+
`Time: ${report.timestamp}`,
|
|
77
|
+
`Message: ${report.message}`,
|
|
78
|
+
'',
|
|
79
|
+
'Stack / Cause:',
|
|
80
|
+
report.stack,
|
|
81
|
+
].join('\n');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Drop-in `fallback` renderer for `MasonHost.mount(...)` / `BrowserHost.mount(...)`.
|
|
85
|
+
*
|
|
86
|
+
* Renders a high-contrast recovery card with diagnostic details, Copy button,
|
|
87
|
+
* and Start Again button using standard HTML elements.
|
|
88
|
+
*/
|
|
89
|
+
export function makeHtmlCrashFallback(options) {
|
|
90
|
+
return (failure, h) => {
|
|
91
|
+
const report = buildCrashReport(failure, options?.componentName ?? 'EffectUIApp');
|
|
92
|
+
const text = formatCrashText(report);
|
|
93
|
+
return h.section
|
|
94
|
+
.class('flex flex-col gap-3 p-4 rounded-xl')
|
|
95
|
+
.style({
|
|
96
|
+
backgroundColor: '#1b1414',
|
|
97
|
+
borderColor: '#ef4444',
|
|
98
|
+
borderWidth: '1px',
|
|
99
|
+
color: '#fef2f2',
|
|
100
|
+
})
|
|
101
|
+
.children(h.h2.style({ fontSize: '18px', fontWeight: '700', color: '#fca5a5' }).children(report.title), h.p.style({ fontSize: '14px', color: '#fee2e2' }).children(report.message), h.pre
|
|
102
|
+
.style({
|
|
103
|
+
fontSize: '11px',
|
|
104
|
+
color: '#e5e7eb',
|
|
105
|
+
backgroundColor: '#0f0c0c',
|
|
106
|
+
padding: '10px',
|
|
107
|
+
borderRadius: '8px',
|
|
108
|
+
})
|
|
109
|
+
.children(report.stack.slice(0, 600)), h.div.class('flex flex-row gap-2').children(h.button
|
|
110
|
+
.attr('id', 'crash-copy-btn')
|
|
111
|
+
.style({
|
|
112
|
+
backgroundColor: '#27272a',
|
|
113
|
+
color: '#ffffff',
|
|
114
|
+
padding: '10px 14px',
|
|
115
|
+
borderRadius: '8px',
|
|
116
|
+
fontWeight: '600',
|
|
117
|
+
})
|
|
118
|
+
.prop('__onNativeAction', () => {
|
|
119
|
+
options?.onCopy?.(text);
|
|
120
|
+
})
|
|
121
|
+
.children('Copy Diagnostics'), h.button
|
|
122
|
+
.attr('id', 'crash-restart-btn')
|
|
123
|
+
.style({
|
|
124
|
+
backgroundColor: '#dc2626',
|
|
125
|
+
color: '#ffffff',
|
|
126
|
+
padding: '10px 14px',
|
|
127
|
+
borderRadius: '8px',
|
|
128
|
+
fontWeight: '600',
|
|
129
|
+
})
|
|
130
|
+
.prop('__onNativeAction', () => {
|
|
131
|
+
options?.onRestart?.();
|
|
132
|
+
})
|
|
133
|
+
.children('Start Again')));
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Drop-in `fallback` renderer for `NativeHost.mount(...)` (Strategy A).
|
|
138
|
+
*/
|
|
139
|
+
export function makeNativeCrashFallback(options) {
|
|
140
|
+
return (failure, h) => {
|
|
141
|
+
const report = buildCrashReport(failure, options?.componentName ?? 'NativeEffectApp');
|
|
142
|
+
const text = formatCrashText(report);
|
|
143
|
+
return h.stackLayout
|
|
144
|
+
.style({
|
|
145
|
+
padding: 20,
|
|
146
|
+
margin: 16,
|
|
147
|
+
borderRadius: 16,
|
|
148
|
+
backgroundColor: '#1b1414',
|
|
149
|
+
borderColor: '#ef4444',
|
|
150
|
+
borderWidth: 1,
|
|
151
|
+
})
|
|
152
|
+
.children(h.label
|
|
153
|
+
.text(report.title)
|
|
154
|
+
.textWrap(true)
|
|
155
|
+
.style({ fontSize: 18, fontWeight: '700', color: '#fca5a5', marginBottom: 8 }), h.label
|
|
156
|
+
.text(report.message)
|
|
157
|
+
.textWrap(true)
|
|
158
|
+
.style({ fontSize: 14, color: '#fee2e2', marginBottom: 12 }), h.label
|
|
159
|
+
.text(report.stack.slice(0, 400))
|
|
160
|
+
.textWrap(true)
|
|
161
|
+
.style({
|
|
162
|
+
fontSize: 11,
|
|
163
|
+
color: '#d4d4d8',
|
|
164
|
+
backgroundColor: '#0f0c0c',
|
|
165
|
+
padding: 10,
|
|
166
|
+
borderRadius: 8,
|
|
167
|
+
marginBottom: 14,
|
|
168
|
+
}), h.button
|
|
169
|
+
.text('Copy Diagnostics')
|
|
170
|
+
.style({
|
|
171
|
+
backgroundColor: '#27272a',
|
|
172
|
+
color: '#ffffff',
|
|
173
|
+
borderRadius: 10,
|
|
174
|
+
padding: 12,
|
|
175
|
+
marginBottom: 8,
|
|
176
|
+
})
|
|
177
|
+
.prop('__onNativeAction', () => {
|
|
178
|
+
options?.onCopy?.(text);
|
|
179
|
+
}), h.button
|
|
180
|
+
.text('Start Again')
|
|
181
|
+
.style({
|
|
182
|
+
backgroundColor: '#dc2626',
|
|
183
|
+
color: '#ffffff',
|
|
184
|
+
borderRadius: 10,
|
|
185
|
+
padding: 12,
|
|
186
|
+
})
|
|
187
|
+
.prop('__onNativeAction', () => {
|
|
188
|
+
options?.onRestart?.();
|
|
189
|
+
}));
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export const NativeCrash = {
|
|
193
|
+
CrashReport,
|
|
194
|
+
buildCrashReport,
|
|
195
|
+
formatCrashText,
|
|
196
|
+
makeHtmlCrashFallback,
|
|
197
|
+
makeNativeCrashFallback,
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crash/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,aAAa,EAAE,MAAM,CAAC,MAAM;IAC5B,SAAS,EAAE,MAAM,CAAC,MAAM;CACzB,CAAC,CAAC;AAGH,SAAS,mBAAmB,CAAC,OAAgB;IAC3C,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3C,iEAAiE;QACjE,MAAM,SAAS,GAAG,OAA+D,CAAC;QAClF,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAClE,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,KAA6B,CAAC,CAAC;gBACrE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACjC,OAAO;oBACL,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,0BAA0B;oBAC/C,KAAK,EAAE,MAAM;iBACd,CAAC;YACJ,CAAC;YAAC,MAAM,CAAC;gBACP,eAAe;YACjB,CAAC;QACH,CAAC;QACD,IAAI,OAAO,YAAY,KAAK,EAAE,CAAC;YAC7B,OAAO;gBACL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C;AAED,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,WAAW;IACX,gBAAgB;IAChB,eAAe;IACf,qBAAqB;IACrB,uBAAuB;CACf,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live DevTools bridge (`NativeDevTools`) for `@nstudio/nativescript-effect-ui`.
|
|
3
|
+
*
|
|
4
|
+
* Uses `@effect/ui`'s built-in `MessageLog.makeEncoded` to encode Wire frames
|
|
5
|
+
* off the app's hot update path, retains a bounded ring buffer for in-app or
|
|
6
|
+
* test inspection, and streams newline-free JSON Wire frames (`Hello` +
|
|
7
|
+
* `WireEntry`) over WebSocket to an `@effect/ui-devtools` server (auto-resolving
|
|
8
|
+
* `127.0.0.1` on iOS Simulator and `10.0.2.2` on Android Emulator).
|
|
9
|
+
*/
|
|
10
|
+
import * as MessageLog from '@effect/ui/MessageLog';
|
|
11
|
+
import * as Layer from 'effect/Layer';
|
|
12
|
+
export interface DevToolsWebSocketLike {
|
|
13
|
+
readonly readyState: number;
|
|
14
|
+
send(data: string): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
onopen: ((ev?: unknown) => void) | null;
|
|
17
|
+
onclose: ((ev?: unknown) => void) | null;
|
|
18
|
+
onerror: ((ev?: unknown) => void) | null;
|
|
19
|
+
}
|
|
20
|
+
export type DevToolsWebSocketCtor = new (url: string) => DevToolsWebSocketLike;
|
|
21
|
+
export interface DevToolsStats {
|
|
22
|
+
readonly connected: boolean;
|
|
23
|
+
readonly bufferedFrames: number;
|
|
24
|
+
readonly totalEncoded: number;
|
|
25
|
+
readonly totalSent: number;
|
|
26
|
+
readonly serverUrl: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface DevToolsBridgeHandle {
|
|
29
|
+
/** Provides `MessageLog.MessageLog` to any mounted Effect UI root. */
|
|
30
|
+
readonly layer: Layer.Layer<never>;
|
|
31
|
+
/** Snapshot of all buffered Wire frames (in chronological order). */
|
|
32
|
+
readonly getFrames: () => ReadonlyArray<MessageLog.WireEntry>;
|
|
33
|
+
/** Current connection & throughput metrics. */
|
|
34
|
+
readonly getStats: () => DevToolsStats;
|
|
35
|
+
/** Subscribe to newly encoded Wire frames (e.g. for an in-app HUD or test). */
|
|
36
|
+
readonly subscribe: (listener: (frames: ReadonlyArray<MessageLog.WireEntry>) => void) => () => void;
|
|
37
|
+
}
|
|
38
|
+
export interface DevToolsBridgeOptions {
|
|
39
|
+
/** WebSocket endpoint of an `@effect/ui-devtools` server (e.g. `ws://127.0.0.1:4774`). */
|
|
40
|
+
readonly serverUrl?: string | undefined;
|
|
41
|
+
/** Maximum number of encoded Wire frames kept in the ring buffer. Defaults to `500`. */
|
|
42
|
+
readonly bufferSize?: number | undefined;
|
|
43
|
+
/** Max serialized bytes per Wire entry. */
|
|
44
|
+
readonly maxEntryBytes?: number | undefined;
|
|
45
|
+
/** Host tag reported in the Wire `Hello` frame. Defaults to `"browser"` (valid WireHost). */
|
|
46
|
+
readonly host?: MessageLog.WireHost | undefined;
|
|
47
|
+
/** Reconnect delay in ms after a WebSocket close. Defaults to `1500`. */
|
|
48
|
+
readonly reconnectMs?: number | undefined;
|
|
49
|
+
/** Optional WebSocket constructor override (used in tests or custom runtimes). */
|
|
50
|
+
readonly WebSocketCtor?: DevToolsWebSocketCtor | undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolves the default local DevTools server URL for the current runtime:
|
|
54
|
+
* - Android Emulator maps host loopback to `10.0.2.2`
|
|
55
|
+
* - iOS Simulator / macOS / Web use `127.0.0.1`
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolveDevToolsUrl(port?: number, path?: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a live `NativeDevTools` bridge handle (`layer` + live `getFrames` /
|
|
60
|
+
* `getStats` / `subscribe`).
|
|
61
|
+
*
|
|
62
|
+
* Provide `bridge.layer` alongside `MasonHost.mount` or `NativeHost.mount` to
|
|
63
|
+
* stream every `Update`, `Mounted`, `QueryChanged`, `CommandStarted`, and
|
|
64
|
+
* `Failed` Wire frame with zero impact on production builds.
|
|
65
|
+
*/
|
|
66
|
+
export declare function makeBridge(options?: DevToolsBridgeOptions | undefined): DevToolsBridgeHandle;
|
|
67
|
+
/**
|
|
68
|
+
* Convenience Layer for dropping live DevTools streaming straight into a
|
|
69
|
+
* mounted NativeScript Effect UI tree.
|
|
70
|
+
*/
|
|
71
|
+
export declare const layer: (options?: DevToolsBridgeOptions | undefined) => Layer.Layer<never>;
|
|
72
|
+
export declare const NativeDevTools: {
|
|
73
|
+
readonly makeBridge: typeof makeBridge;
|
|
74
|
+
readonly layer: (options?: DevToolsBridgeOptions | undefined) => Layer.Layer<never>;
|
|
75
|
+
readonly resolveDevToolsUrl: typeof resolveDevToolsUrl;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACzC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,EAAE,M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5D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,SAAO,EAAE,IAAI,SAAK,GAAG,MAAM,CAKjE;AAID;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,SAAS,GAAG,oBAAoB,CAgI5F;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,UAAU,qBAAqB,GAAG,SAAS,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAC1D,CAAC;AAE5B,eAAO,MAAM,cAAc;;+BAHK,qBAAqB,GAAG,SAAS,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;;CAO5E,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live DevTools bridge (`NativeDevTools`) for `@nstudio/nativescript-effect-ui`.
|
|
3
|
+
*
|
|
4
|
+
* Uses `@effect/ui`'s built-in `MessageLog.makeEncoded` to encode Wire frames
|
|
5
|
+
* off the app's hot update path, retains a bounded ring buffer for in-app or
|
|
6
|
+
* test inspection, and streams newline-free JSON Wire frames (`Hello` +
|
|
7
|
+
* `WireEntry`) over WebSocket to an `@effect/ui-devtools` server (auto-resolving
|
|
8
|
+
* `127.0.0.1` on iOS Simulator and `10.0.2.2` on Android Emulator).
|
|
9
|
+
*/
|
|
10
|
+
import * as MessageLog from '@effect/ui/MessageLog';
|
|
11
|
+
import * as Effect from 'effect/Effect';
|
|
12
|
+
import * as Layer from 'effect/Layer';
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the default local DevTools server URL for the current runtime:
|
|
15
|
+
* - Android Emulator maps host loopback to `10.0.2.2`
|
|
16
|
+
* - iOS Simulator / macOS / Web use `127.0.0.1`
|
|
17
|
+
*/
|
|
18
|
+
export function resolveDevToolsUrl(port = 4774, path = '') {
|
|
19
|
+
const host = typeof __ANDROID__ !== 'undefined' && __ANDROID__ ? '10.0.2.2' : '127.0.0.1';
|
|
20
|
+
const suffix = path ? (path.startsWith('/') ? path : `/${path}`) : '';
|
|
21
|
+
return `ws://${host}:${port}${suffix}`;
|
|
22
|
+
}
|
|
23
|
+
const WS_OPEN = 1;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a live `NativeDevTools` bridge handle (`layer` + live `getFrames` /
|
|
26
|
+
* `getStats` / `subscribe`).
|
|
27
|
+
*
|
|
28
|
+
* Provide `bridge.layer` alongside `MasonHost.mount` or `NativeHost.mount` to
|
|
29
|
+
* stream every `Update`, `Mounted`, `QueryChanged`, `CommandStarted`, and
|
|
30
|
+
* `Failed` Wire frame with zero impact on production builds.
|
|
31
|
+
*/
|
|
32
|
+
export function makeBridge(options) {
|
|
33
|
+
const bufferSize = Math.max(1, options?.bufferSize ?? 500);
|
|
34
|
+
const serverUrl = options?.serverUrl;
|
|
35
|
+
const reconnectMs = options?.reconnectMs ?? 1500;
|
|
36
|
+
const host = options?.host ?? 'browser';
|
|
37
|
+
const buffer = [];
|
|
38
|
+
const listeners = new Set();
|
|
39
|
+
let ws = null;
|
|
40
|
+
let connected = false;
|
|
41
|
+
let disposed = false;
|
|
42
|
+
let reconnectTimer = null;
|
|
43
|
+
let totalEncoded = 0;
|
|
44
|
+
let totalSent = 0;
|
|
45
|
+
const helloFrame = JSON.stringify({
|
|
46
|
+
_tag: 'Hello',
|
|
47
|
+
version: MessageLog.wireVersion,
|
|
48
|
+
host,
|
|
49
|
+
});
|
|
50
|
+
const sendRaw = (payload) => {
|
|
51
|
+
if (!ws || ws.readyState !== WS_OPEN)
|
|
52
|
+
return false;
|
|
53
|
+
try {
|
|
54
|
+
ws.send(payload);
|
|
55
|
+
totalSent += 1;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const connect = () => {
|
|
63
|
+
if (disposed || !serverUrl)
|
|
64
|
+
return;
|
|
65
|
+
const Ctor = options?.WebSocketCtor ??
|
|
66
|
+
(globalThis.WebSocket);
|
|
67
|
+
if (!Ctor)
|
|
68
|
+
return;
|
|
69
|
+
try {
|
|
70
|
+
const socket = new Ctor(serverUrl);
|
|
71
|
+
ws = socket;
|
|
72
|
+
socket.onopen = () => {
|
|
73
|
+
if (disposed || ws !== socket)
|
|
74
|
+
return;
|
|
75
|
+
connected = true;
|
|
76
|
+
sendRaw(helloFrame);
|
|
77
|
+
for (const frame of buffer) {
|
|
78
|
+
sendRaw(JSON.stringify(frame));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
socket.onerror = () => {
|
|
82
|
+
connected = false;
|
|
83
|
+
};
|
|
84
|
+
socket.onclose = () => {
|
|
85
|
+
if (ws === socket) {
|
|
86
|
+
ws = null;
|
|
87
|
+
connected = false;
|
|
88
|
+
}
|
|
89
|
+
if (!disposed && serverUrl && reconnectMs > 0) {
|
|
90
|
+
reconnectTimer = setTimeout(connect, reconnectMs);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
connected = false;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const layer = Layer.effect(MessageLog.MessageLog, Effect.gen(function* () {
|
|
99
|
+
disposed = false;
|
|
100
|
+
connect();
|
|
101
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
102
|
+
disposed = true;
|
|
103
|
+
connected = false;
|
|
104
|
+
if (reconnectTimer !== null) {
|
|
105
|
+
clearTimeout(reconnectTimer);
|
|
106
|
+
reconnectTimer = null;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
ws?.close();
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Ignore close errors.
|
|
113
|
+
}
|
|
114
|
+
ws = null;
|
|
115
|
+
}));
|
|
116
|
+
return yield* MessageLog.makeEncoded((batch) => Effect.sync(() => {
|
|
117
|
+
totalEncoded += batch.length;
|
|
118
|
+
for (const frame of batch) {
|
|
119
|
+
buffer.push(frame);
|
|
120
|
+
if (buffer.length > bufferSize) {
|
|
121
|
+
buffer.shift();
|
|
122
|
+
}
|
|
123
|
+
sendRaw(JSON.stringify(frame));
|
|
124
|
+
}
|
|
125
|
+
for (const listener of listeners) {
|
|
126
|
+
listener(batch);
|
|
127
|
+
}
|
|
128
|
+
}), { maxEntryBytes: options?.maxEntryBytes });
|
|
129
|
+
}));
|
|
130
|
+
return {
|
|
131
|
+
layer,
|
|
132
|
+
getFrames: () => buffer.slice(),
|
|
133
|
+
getStats: () => ({
|
|
134
|
+
connected,
|
|
135
|
+
bufferedFrames: buffer.length,
|
|
136
|
+
totalEncoded,
|
|
137
|
+
totalSent,
|
|
138
|
+
serverUrl,
|
|
139
|
+
}),
|
|
140
|
+
subscribe: (listener) => {
|
|
141
|
+
listeners.add(listener);
|
|
142
|
+
return () => {
|
|
143
|
+
listeners.delete(listener);
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Convenience Layer for dropping live DevTools streaming straight into a
|
|
150
|
+
* mounted NativeScript Effect UI tree.
|
|
151
|
+
*/
|
|
152
|
+
export const layer = (options) => makeBridge(options).layer;
|
|
153
|
+
export const NativeDevTools = {
|
|
154
|
+
makeBridge,
|
|
155
|
+
layer,
|
|
156
|
+
resolveDevToolsUrl,
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AA+CtC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,EAAE;IACvD,MAAM,IAAI,GACR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YACD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CAAC,EACJ,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,CAC1C,CAAC;IACJ,CAAC,CAAC,CAC8B,CAAC;IAEnC,OAAO;QACL,KAAK;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;QAC/B,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;YACf,SAAS;YACT,cAAc,EAAE,MAAM,CAAC,MAAM;YAC7B,YAAY;YACZ,SAAS;YACT,SAAS;SACV,CAAC;QACF,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAA2C,EAAsB,EAAE,CACvF,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;AAE5B,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,KAAK;IACL,kBAAkB;CACV,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|