@nstudio/nativescript-compiler-effect-ui 9.2.0-alpha.13 → 9.2.0-alpha.21

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 (2) hide show
  1. package/dist/transform.js +51 -7
  2. package/package.json +2 -2
package/dist/transform.js CHANGED
@@ -39,14 +39,26 @@ export function transformEffectSource(code, fileName) {
39
39
  // Windows-only dead code inside shared masonkit common.ts (`_windowsCreateAnonymousText`, `windowsBreakRun`)
40
40
  out = out.replace(/\bnew NativeScript\.Mason\.\w+\([^)]*\)/g, '(undefined as any)').replace(/\bNativeScript\.Mason\.\w+/g, 'any');
41
41
  }
42
- if (norm.endsWith('/nativescript-masonkit/common.ts') && out.includes('setMeasureForViewBlock')) {
43
- // `objc!Mason.d.ts` omits `setMeasureForViewBlock` even though `Mason.swiftinterface` exports `@objc(setMeasureForView:block:)`;
44
- // typing `mason` as `NSCMason` lets Swift emit a direct typed ObjC-block call instead of dynamic `objc_msgSend`.
45
- out =
46
- `declare global { interface NSCMason { setMeasureForViewBlock(view: any, block: (knownW: number, knownH: number, availW: number, availH: number) => any): void; } }\n` +
47
- out.replace(/const mason = native\?\.mason \?\? native\?\.node\?\.mason;\s*if \(typeof mason\?\.setMeasureForViewBlock !== 'function'\) return;/, 'const mason = (native?.mason ?? native?.node?.mason) as NSCMason | undefined;\n if (!mason) return;');
42
+ if (/\/nativescript-masonkit\/common\.(?:ts|js)$/.test(norm)) {
43
+ // `objc!Mason.d.ts` omits `setMeasureForViewBlock`, `mason_addEventListener`, and `mason_removeEventListenerId`
44
+ // even though `Mason-Swift.h` exports them with ObjC block parameters; typing the receivers lets Swift emit
45
+ // direct typed ObjC-block calls instead of dynamic `objc_msgSend` (which skips `@?` block arguments).
46
+ const decls = [];
47
+ if (out.includes('setMeasureForViewBlock')) {
48
+ decls.push('interface NSCMason { setMeasureForViewBlock(view: any, block: (knownW: number, knownH: number, availW: number, availH: number) => any): void; }');
49
+ out = out.replace(/const mason = native\?\.mason \?\? native\?\.node\?\.mason;\s*if \(typeof mason\?\.setMeasureForViewBlock !== 'function'\) return;/, 'const mason = (native?.mason ?? native?.node?.mason) as NSCMason | undefined;\n if (!mason) return;');
50
+ }
51
+ if (out.includes('mason_addEventListener')) {
52
+ decls.push('interface NSObject { mason_addEventListener(event: string, listener: (event: any) => void): any; mason_removeEventListenerId(event: string, id: any): boolean; }');
53
+ out = out
54
+ .replace(/this\._view\.mason_addEventListener\(/g, '(this._view as NSObject).mason_addEventListener(')
55
+ .replace(/this\._view\.mason_removeEventListenerId\(/g, '(this._view as NSObject).mason_removeEventListenerId(');
56
+ }
57
+ if (decls.length) {
58
+ out = `declare global { ${decls.join(' ')} }\n` + out;
59
+ }
48
60
  }
49
- if (norm.endsWith('/nativescript-masonkit/style.ts')) {
61
+ if (/\/nativescript-masonkit\/style\.(?:ts|js)$/.test(norm)) {
50
62
  out = out
51
63
  .replace(/private view_: View;/, 'private view_: any;')
52
64
  .replace(/static fromView\(view: View, nativeView\)/, 'static fromView(view: any, nativeView)')
@@ -67,6 +79,38 @@ export function transformEffectSource(code, fileName) {
67
79
  if (norm.endsWith('/native/Native.ts')) {
68
80
  out = out.replace(/Record<string,\s*NativeElement<any,\s*any,\s*any,\s*any,\s*any>>/g, 'Record<string, any>');
69
81
  }
82
+ if (norm.endsWith('/platform/intl.ts')) {
83
+ // V8-without-ICU polyfill (`Date.prototype` / `Number.prototype` monkey-patching) is unnecessary under native Swift/Kotlin compilation.
84
+ return `export interface IntlBackend {}\nexport interface IntlPolyfillTarget {}\nexport interface IntlPolyfillReport { readonly dateTimeFormat: boolean; readonly numberFormat: boolean; readonly dateToLocale: boolean; readonly numberToLocale: boolean; }\nexport function createIntlPolyfill(_backend: IntlBackend): any { return {}; }\nexport function installIntlPolyfillWith(_backend: IntlBackend, _options?: any): IntlPolyfillReport { return { dateTimeFormat: false, numberFormat: false, dateToLocale: false, numberToLocale: false }; }\nexport function installIntlPolyfill(): void {}\n`;
85
+ }
86
+ if (norm.endsWith('/platform/intl-mapping.ts')) {
87
+ out = out.replace(/\bObject\(options\)/g, '(typeof options === "object" && options !== null ? options : {})');
88
+ }
89
+ if (norm.endsWith('/mason/svg.ts')) {
90
+ const cut = out.indexOf('\nconst isApple = (): boolean =>');
91
+ if (cut >= 0) {
92
+ out =
93
+ out.slice(0, cut) +
94
+ `\n@CSSType('svg')\nclass MasonSvgElement extends Div {\n _svgTree: SvgNode | undefined;\n setSvgTree(root: SvgNode): void {\n this._svgTree = root;\n }\n}\nexport function createSvgElementClass(): ElementConstructor {\n return MasonSvgElement as unknown as ElementConstructor;\n}\n`;
95
+ }
96
+ }
97
+ if (norm.endsWith('/mason/video.ts')) {
98
+ const cut = out.indexOf('\nconst isApple = (): boolean =>');
99
+ if (cut >= 0) {
100
+ out =
101
+ out.slice(0, cut) +
102
+ `\n@CSSType('video')\nclass MasonVideoElement extends Div {\n setSources(_sources: ReadonlyArray<VideoSource>): void {}\n play(): void {}\n pause(): void {}\n}\nexport function createVideoElementClass(): ElementConstructor {\n return MasonVideoElement as unknown as ElementConstructor;\n}\n`;
103
+ }
104
+ }
105
+ if (norm.endsWith('/mason/elements.ts')) {
106
+ out = out
107
+ .replace(/class MasonAnchor extends \(A as unknown as new \(\) => NSView & \{ followHref: \(\) => void \}\) \{/, 'class MasonAnchor extends A {')
108
+ .replace(/CSSType\('a'\)\(MasonAnchor\);/, '')
109
+ .replace(/function makeBlockElement\(tag: string\): ElementConstructor \{\s*class MasonBlockElement extends Div \{\}\s*CSSType\(tag\)\(MasonBlockElement\);\s*return MasonBlockElement as unknown as ElementConstructor;\s*\}/, `function makeBlockElement(_tag: string): ElementConstructor {\n return Div as unknown as ElementConstructor;\n}`);
110
+ }
111
+ if (norm.endsWith('/mason/input-native.ts')) {
112
+ return `import type { View as NSView } from '@nativescript/core';\nexport interface NativeInputHooks { readonly onEdit: () => void; readonly onReturn: () => void; }\nexport function syncNativeInput(_view: NSView, _tag: string): void {}\nexport function setNativeInputHooks(_view: NSView, _tag: string, _hooks: NativeInputHooks): void {}\nexport function dismissKeyboard(): void {}\nexport function installTapToDismissKeyboard(_view: NSView): () => void { return () => {}; }\n`;
113
+ }
70
114
  }
71
115
  if (/\bclass\b/.test(out)) {
72
116
  out = transformEffectClasses(out, fileName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nstudio/nativescript-compiler-effect-ui",
3
- "version": "9.2.0-alpha.13",
3
+ "version": "9.2.0-alpha.21",
4
4
  "description": "The Effect UI adapter of @nstudio/nativescript-compiler: compiles a NativeScript app written with @effect/ui and Effect v4 into a native iOS or Android app with no JavaScript runtime.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -24,7 +24,7 @@
24
24
  "directory": "packages/effect-ui"
25
25
  },
26
26
  "peerDependencies": {
27
- "@nstudio/nativescript-compiler": "9.2.0-alpha.13"
27
+ "@nstudio/nativescript-compiler": "9.2.0-alpha.21"
28
28
  },
29
29
  "nativescript": {
30
30
  "compilerAdapter": {