diff --git a/App_Resources/iOS/Info.plist b/App_Resources/iOS/Info.plist
index 98cc8471..4be2ce2c 100644
--- a/App_Resources/iOS/Info.plist
+++ b/App_Resources/iOS/Info.plist
@@ -23,6 +23,8 @@
UISupportedInterfaceOrientations
UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
UIRequiresFullScreen
diff --git a/App_Resources/iOS/Podfile b/App_Resources/iOS/Podfile
new file mode 100644
index 00000000..c643ad84
--- /dev/null
+++ b/App_Resources/iOS/Podfile
@@ -0,0 +1,13 @@
+platform :ios, '15.1'
+pod 'SVGKit', '3.0.0'
+
+# SVGKit 3's physical-DPI lookup asserts on arm64 simulators. Our icons use
+# only viewBox/pixel units, so that lookup is irrelevant to their rendering.
+post_install do |installer|
+ installer.pods_project.targets.each do |target|
+ next unless target.name == 'SVGKit'
+ target.build_configurations.each do |config|
+ config.build_settings['ENABLE_NS_ASSERTIONS'] = 'NO'
+ end
+ end
+end
diff --git a/App_Resources/iOS/src/FaceclawGraphics.h b/App_Resources/iOS/src/FaceclawGraphics.h
new file mode 100644
index 00000000..3dc2e7d5
--- /dev/null
+++ b/App_Resources/iOS/src/FaceclawGraphics.h
@@ -0,0 +1,6 @@
+#import
+
+@interface FaceclawGraphics : NSObject
++ (UIImage *)preview:(NSData *)gray width:(NSInteger)width height:(NSInteger)height green:(BOOL)green;
++ (NSData *)renderSVG:(NSString *)svg size:(NSInteger)size;
+@end
diff --git a/App_Resources/iOS/src/FaceclawGraphics.m b/App_Resources/iOS/src/FaceclawGraphics.m
new file mode 100644
index 00000000..96a5e25e
--- /dev/null
+++ b/App_Resources/iOS/src/FaceclawGraphics.m
@@ -0,0 +1,56 @@
+#import "FaceclawGraphics.h"
+#import
+
+@implementation FaceclawGraphics
++ (UIImage *)preview:(NSData *)gray width:(NSInteger)width height:(NSInteger)height green:(BOOL)green {
+ if (width <= 0 || height <= 0 || gray.length != width * height) return nil;
+ NSMutableData *rgba = [NSMutableData dataWithLength:width * height * 4];
+ const uint8_t *src = gray.bytes;
+ uint8_t *dst = rgba.mutableBytes;
+ uint8_t lut[256];
+ for (int i = 0; i < 256; i++) lut[i] = (uint8_t)round(pow(i / 255.0, 0.7) * 255.0);
+ for (NSInteger i = 0; i < width * height; i++) {
+ uint8_t value = lut[src[i]];
+ dst[i * 4] = green ? 0 : value;
+ dst[i * 4 + 1] = value;
+ dst[i * 4 + 2] = green ? 0 : value;
+ dst[i * 4 + 3] = 255;
+ }
+ CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
+ CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)rgba);
+ CGImageRef image = CGImageCreate(width, height, 8, 32, width * 4, space,
+ kCGBitmapByteOrder32Big | (CGBitmapInfo)kCGImageAlphaPremultipliedLast, provider, NULL, false, kCGRenderingIntentDefault);
+ UIImage *result = image ? [UIImage imageWithCGImage:image scale:1 orientation:UIImageOrientationUp] : nil;
+ if (image) CGImageRelease(image);
+ CGDataProviderRelease(provider);
+ CGColorSpaceRelease(space);
+ return result;
+}
++ (NSData *)renderSVG:(NSString *)svg size:(NSInteger)size {
+ if (size <= 0 || size > 1024) return nil;
+ SVGKImage *image = [SVGKImage imageWithData:[svg dataUsingEncoding:NSUTF8StringEncoding]];
+ if (!image) return nil;
+ image.size = CGSizeMake(size, size);
+ UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat defaultFormat];
+ format.scale = 1;
+ format.opaque = NO;
+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:image.size format:format];
+ UIImage *raster = [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
+ [image.CALayerTree renderInContext:context.CGContext];
+ }];
+ NSMutableData *rgba = [NSMutableData dataWithLength:size * size * 4];
+ CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
+ CGContextRef context = CGBitmapContextCreate(rgba.mutableBytes, size, size, 8, size * 4, space,
+ kCGBitmapByteOrder32Big | (CGBitmapInfo)kCGImageAlphaPremultipliedLast);
+ CGContextDrawImage(context, CGRectMake(0, 0, size, size), raster.CGImage);
+ NSMutableData *gray = [NSMutableData dataWithLength:size * size];
+ const uint8_t *src = rgba.bytes;
+ uint8_t *dst = gray.mutableBytes;
+ for (NSInteger i = 0; i < size * size; i++) {
+ dst[i] = (uint8_t)round(0.2126 * src[i * 4] + 0.7152 * src[i * 4 + 1] + 0.0722 * src[i * 4 + 2]);
+ }
+ CGContextRelease(context);
+ CGColorSpaceRelease(space);
+ return gray;
+}
+@end
diff --git a/App_Resources/iOS/src/module.modulemap b/App_Resources/iOS/src/module.modulemap
new file mode 100644
index 00000000..560d5493
--- /dev/null
+++ b/App_Resources/iOS/src/module.modulemap
@@ -0,0 +1,4 @@
+module FaceclawGraphics {
+ header "FaceclawGraphics.h"
+ export *
+}
diff --git a/app/apps/calculator/calculator.ts b/app/apps/calculator/calculator.ts
index 5f47d785..1a02dfed 100644
--- a/app/apps/calculator/calculator.ts
+++ b/app/apps/calculator/calculator.ts
@@ -82,10 +82,11 @@ export class CalculatorLayer implements Layer {
constructor(
private readonly coordinator: MathCoordinator,
private readonly actions: LayerActions,
+ private readonly textInput?: () => Promise,
) {
this.coordinator.setUsesDegrees(calculatorDegreesSetting.get());
this.coordinator.onChanged = () => this.handleCoordinatorChanged();
- this.unsubscribeTranscript = voiceControlBridge.onTranscript((event) => this.onTranscript(event));
+ if (!this.textInput) this.unsubscribeTranscript = voiceControlBridge.onTranscript((event) => this.onTranscript(event));
}
private get mode(): CalculatorMode {
@@ -125,6 +126,7 @@ export class CalculatorLayer implements Layer {
}
private refreshListening(): void {
+ if (this.textInput) return;
if (!this.foreground) return;
if (this.listening === "continuous") {
if (!this.continuousActive) {
@@ -244,6 +246,7 @@ export class CalculatorLayer implements Layer {
* that did not.
*/
beginDictation(): void {
+ if (this.textInput) { void this.textInput(); return; }
if (this.dictating) return;
this.dictating = true;
void this.actions.startVoiceCapture(true);
@@ -513,7 +516,8 @@ export class CalculatorLayer implements Layer {
bodyBottom: number,
): void {
const prompt =
- this.listening === "continuous"
+ this.textInput ? "Tap to type a problem on your phone"
+ : this.listening === "continuous"
? `Say a problem, then "${modeLabel(this.mode).toLowerCase()} it"`
: "Tap to say a problem — or use Voice input to type one";
const lines = wrapText(font, prompt, width - 96);
@@ -527,7 +531,7 @@ export class CalculatorLayer implements Layer {
private paintHeardLine(image: GrayImage, font: UiFont, width: number, y: number): void {
if (!this.lastInput) return;
- const label = "Heard";
+ const label = this.textInput ? "Entered" : "Heard";
image.drawText(font, 24, y, label, 110);
const x = 24 + font.measureText(label) + 10;
image.drawText(font, x, y, truncateText(font, this.lastInput, width - x - 24), 160);
@@ -579,7 +583,7 @@ export class CalculatorLayer implements Layer {
this.mode === "explain" && this.coordinator.stepPosition !== null ? "steps" : "mode";
return gestureHints([
[GESTURE_SCROLL, scrollTarget],
- [GESTURE_CLICK, "mic"],
+ [GESTURE_CLICK, this.textInput ? "type" : "mic"],
[GESTURE_DOUBLE_CLICK, "back"],
]);
}
diff --git a/app/bootstrap.ios.ts b/app/bootstrap.ios.ts
index c2a43d2c..977ab199 100644
--- a/app/bootstrap.ios.ts
+++ b/app/bootstrap.ios.ts
@@ -1,47 +1,4 @@
-import { Application, Button, Device, Label, Page, ScrollView, StackLayout } from '@nativescript/core'
-import { bytesToHex, hexToBytes } from './util/hex-util'
+import { Application } from '@nativescript/core'
+import { createMainPage } from './phone-ui/main-page.ios'
-// Milestone 1: exercise native UI, TypeScript, and an existing shared utility
-// without loading the Android services used by the full glasses application.
-Application.run({
- create: () => {
- const page = new Page()
- page.actionBarHidden = true
- const scroll = new ScrollView()
- const content = new StackLayout()
- content.padding = 28
- content.verticalAlignment = 'middle'
-
- const label = (text: string, fontSize = 17) => {
- const view = new Label()
- view.text = text
- view.fontSize = fontSize
- view.textWrap = true
- view.marginBottom = 20
- content.addChild(view)
- return view
- }
-
- label('Faceclaw', 36)
- label('iOS port · First launch', 24)
- label(`NativeScript is running on ${Device.model} (iOS ${Device.osVersion}).`)
- label('Glasses pairing and the Android features are still to be ported.')
- const status = label('Tap below to test native input and shared TypeScript code.')
- const button = new Button()
- button.text = 'Run shared-code check'
- button.accessibilityIdentifier = 'shared-code-check'
- let checks = 0
- button.on('tap', () => {
- const result = bytesToHex(hexToBytes('46 61 63 65 63 6c 61 77'))
- const passed = result === '46616365636C6177'
- checks += 1
- status.text = `${passed ? 'Passed' : 'Failed'} · Check ${checks}\nShared hex utilities returned ${result}.`
- console.log(`[ios-bootstrap] Shared-code check ${checks}: ${passed ? 'PASS' : 'FAIL'} (${result})`)
- })
- content.addChild(button)
- scroll.content = content
- page.content = scroll
- page.on('loaded', () => console.log('[ios-bootstrap] Faceclaw launch screen loaded'))
- return page
- },
-})
+Application.run({ create: createMainPage })
diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts
new file mode 100644
index 00000000..c2ff1807
--- /dev/null
+++ b/app/g2/ios-preview-controller.ts
@@ -0,0 +1,220 @@
+import { Dialogs, type ImageSource } from '@nativescript/core'
+import { createLauncherWindow, LAUNCHER_SURFACE_ID } from '../apps/launcher/launcher-app'
+import { CalculatorLayer } from '../apps/calculator/calculator'
+import { MathCoordinator } from '../apps/calculator/math/coordinator'
+import { SurfaceCompositor } from '../graphics/surface-compositor'
+import { flattenPlanes, type Plane } from '../graphics/plane'
+import { G2_LENS_WIDTH, G2_LENS_HEIGHT } from '../graphics/image'
+import { previewPixels } from '../native/ios-graphics'
+import { makeInputEvent, type InputEventPayload } from '../ui/gestures'
+import { noopLayerActions, type LayerActions } from '../ui/layers'
+import { MenuLayer } from '../ui/menu'
+import { createInProcessWindow } from '../ui/shell/in-process-window'
+import { shell, type ShellWindow } from '../ui/shell/shell'
+import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible } from '../ui/shell/geometry'
+import { DISPLAY_MODE_VALUES, displayModeLabel, displayModeSetting, onAnySettingChanged,
+ previewColorSetting, timeFormatSetting, verticalPositionSetting } from '../ui/dashboard-settings'
+import type { PhoneGesture } from '../phone-ui/phone-gestures'
+
+/** Local display host: shared shell/windows, no device-service initialization. */
+export class IosPreviewController {
+ private readonly compositor = new SurfaceCompositor(G2_LENS_WIDTH, G2_LENS_HEIGHT)
+ private renderTimer: ReturnType | null = null
+ private clockTimer: ReturnType | null = null
+ private offSettings: (() => void) | null = null
+ private active = false
+ private shellDirty = true
+ private inputQueue: Promise = Promise.resolve()
+ private lastLayout = ''
+ private prompting = false
+ private readonly actions: LayerActions = {
+ ...noopLayerActions,
+ requestRender: () => this.requestShellRender(),
+ startTextSettingEdit: setting => this.editSetting(setting),
+ startTextSettingsEdit: async (settings, _title, finished) => {
+ for (const setting of settings) await this.editSetting(setting)
+ finished?.()
+ },
+ }
+
+ constructor(private readonly onFrame: (image: ImageSource, focus: string) => void,
+ private readonly onError: (message: string) => void) {
+ this.compositor.configureSurface('shell', { x: 0, y: 0, width: 640, height: 480, zOrder: 1, transparency: 'color-key' })
+ shell.configure({
+ actions: this.actions,
+ voiceInputEnabled: false,
+ getScreenTimeoutMs: () => null,
+ requestShellRender: () => this.requestShellRender(),
+ onWindowsChanged: () => this.requestShellRender(),
+ onScreenStateChanged: on => { this.compositor.setScreenBlanked(!on); this.requestShellRender() },
+ })
+ const launcher = createLauncherWindow({
+ actions: this.actions,
+ apps: () => [
+ { appId: 'calculator', label: 'Calculator', icon: 'calculator' },
+ { appId: 'display', label: 'Display', icon: 'settings' },
+ ],
+ launchApp: id => this.launchApp(id),
+ uninstallApp: () => {},
+ submitFrame: planes => this.submit(LAUNCHER_SURFACE_ID, planes),
+ setSurfaceVisible: visible => { this.compositor.setSurfaceVisible(LAUNCHER_SURFACE_ID, visible); this.scheduleFrame() },
+ })
+ this.configureWindow(launcher)
+ shell.registerWindow(launcher)
+ shell.wake('window')
+ shell.focusWindow(launcher.windowId)
+ }
+
+ resume(): void {
+ if (this.active) return
+ this.active = true
+ this.offSettings = onAnySettingChanged(() => {
+ this.relayout()
+ shell.foregroundWindow()?.requestRender()
+ this.requestShellRender()
+ })
+ this.clockTimer = setInterval(() => this.requestShellRender(), 60_000)
+ this.relayout()
+ shell.foregroundWindow()?.requestRender()
+ this.requestShellRender()
+ console.log('[ios-preview] Main screen active')
+ }
+ pause(): void {
+ this.active = false
+ this.offSettings?.(); this.offSettings = null
+ if (this.clockTimer) clearInterval(this.clockTimer)
+ if (this.renderTimer) clearTimeout(this.renderTimer)
+ this.clockTimer = this.renderTimer = null
+ }
+ private configureWindow(window: ShellWindow): void {
+ this.compositor.configureSurface(window.surfaceId, {
+ ...appViewportRect(window.heightMode, window.appId), zOrder: 0, transparency: 'opaque',
+ })
+ this.compositor.setSurfaceVisible(window.surfaceId, shell.foregroundWindow()?.windowId === window.windowId)
+ }
+ private relayout(): void {
+ const layout = `${displayModeSetting.get()}:${verticalPositionSetting.get()}`
+ if (layout === this.lastLayout) return
+ this.lastLayout = layout
+ for (const window of shell.getWindows()) {
+ this.configureWindow(window)
+ window.relayout?.()
+ }
+ }
+ private async submit(id: string, planes: Plane[]): Promise {
+ const image = flattenPlanes(planes)
+ this.compositor.submitSurfaceFrame(id, image.pixels, { x: 0, y: 0, width: image.width, height: image.height })
+ this.scheduleFrame()
+ }
+ private requestShellRender(): void { this.shellDirty = true; this.scheduleFrame() }
+ private scheduleFrame(): void {
+ if (!this.active || this.renderTimer !== null) return
+ // Coalesce window/chrome updates into one preview, capped at 30 fps.
+ this.renderTimer = setTimeout(() => {
+ this.renderTimer = null
+ try {
+ if (this.shellDirty) {
+ this.shellDirty = false
+ const image = flattenPlanes(shell.paintSurface(), { width: 640, height: 480 })
+ this.compositor.submitSurfaceFrame('shell', image.pixels, { x: 0, y: 0, width: 640, height: 480 })
+ this.compositor.setUnderlayDim(1, shell.underlayDim())
+ }
+ const image = previewPixels(this.compositor.composite(), 640, 480, previewColorSetting.get() === 'green')
+ this.onFrame(image, `${shell.foregroundWindow()?.title ?? 'Apps'} · ${shell.getFocus() === 'sidebar' ? 'App switcher' : 'App'}`)
+ } catch (error) { this.fail(error) }
+ }, 33)
+ }
+ private fail(error: unknown): void {
+ const message = error instanceof Error ? error.stack ?? error.message : String(error)
+ console.error(`[ios-preview] ${message}`)
+ this.onError(error instanceof Error ? error.message : String(error))
+ }
+ gesture(gesture: PhoneGesture, origin: 'watch' | 'ring' | 'mirror', nx = 0, ny = 0): void {
+ this.inputQueue = this.inputQueue.then(async () => {
+ if (!this.active) return
+ if (gesture === 'tap' && origin === 'mirror' && shell.isScreenOn()) {
+ await this.mirrorTap(nx, ny)
+ } else {
+ let type: string = ({ tap: 'click', 'double-tap': 'double-click' } as Record)[gesture] ?? gesture
+ if (origin === 'ring' && type.startsWith('swipe-')) {
+ if (type === 'swipe-left' || type === 'swipe-right') return
+ type = type === 'swipe-up' ? 'scroll-up' : 'scroll-down'
+ }
+ const event = makeInputEvent({ type, source: origin === 'ring' ? 'ring' : 'watch' } as InputEventPayload)
+ await shell.receiveInput(event)
+ this.requestShellRender()
+ }
+ console.log(`[ios-preview] ${origin} ${gesture}: ${shell.describeInputTarget()}`)
+ }).catch(error => this.fail(error))
+ }
+ private async mirrorTap(nx: number, ny: number): Promise {
+ const x = Math.max(0, Math.min(639, Math.floor(nx * 640)))
+ const y = Math.max(0, Math.min(479, Math.floor(ny * 480)))
+ const window = shell.foregroundWindow()
+ if (!shell.hasOverlay() && sidebarStripVisible(shell.getFocus(), window?.appId) && x < SIDEBAR_WIDTH) {
+ const target = shell.windowAtSidebarPoint(x, y)
+ if (target) { shell.focusWindow(target.windowId); target.requestRender(); this.requestShellRender() }
+ return
+ }
+ if (window && !shell.hasOverlay()) {
+ const rect = appViewportRect(window.heightMode, window.appId)
+ if (x < rect.x || x >= rect.x + rect.width || y < rect.y || y >= rect.y + rect.height) return
+ shell.focusWindow(window.windowId)
+ if (await window.hitTest?.(x - rect.x, y - rect.y)) { this.requestShellRender(); return }
+ }
+ await shell.receiveInput(makeInputEvent({ type: 'click', source: 'watch' }))
+ this.requestShellRender()
+ }
+ launchApp(id: string): void {
+ const existing = shell.getWindows().find(window => window.appId === id)
+ if (existing) { shell.focusWindow(existing.windowId); existing.requestRender(); this.requestShellRender(); return }
+ const surfaceId = `window:${id}`
+ let render = () => {}
+ const actions = { ...this.actions, requestRender: () => render() }
+ const layer = id === 'calculator'
+ ? new CalculatorLayer(new MathCoordinator(), actions, () => this.typeIntoApp())
+ : new MenuLayer('Display', [
+ { label: 'Change screen size', onSelect: () => this.cycleDisplayMode() },
+ { label: 'Toggle green / grayscale preview', onSelect: () => { previewColorSetting.set(previewColorSetting.get() === 'green' ? 'white' : 'green') } },
+ { label: 'Toggle 12 / 24 hour clock', onSelect: () => { timeFormatSetting.set(timeFormatSetting.get() === '24h' ? '12h' : '24h') } },
+ ], { x: 8, y: 8, width: 320, minHeight: 160, opaque: true })
+ const app = createInProcessWindow({
+ appId: id, windowId: id, title: id === 'calculator' ? 'Calculator' : 'Display',
+ iconLetter: id === 'calculator' ? '=' : 'D', icon: id === 'calculator' ? 'calculator' : 'settings',
+ closeable: true, actions, baseLayer: layer,
+ receiveTextInput: id === 'calculator' ? text => { app.stack.receiveTextInput(text); app.requestRender() } : undefined,
+ submitFrame: planes => this.submit(surfaceId, planes),
+ setSurfaceVisible: visible => {
+ if (layer instanceof CalculatorLayer) layer.setForeground(visible)
+ this.compositor.setSurfaceVisible(surfaceId, visible); this.scheduleFrame()
+ },
+ removeSurface: () => { this.compositor.removeSurface(surfaceId); this.scheduleFrame() },
+ onClosed: () => { if (layer instanceof CalculatorLayer) layer.onRemoved() },
+ })
+ render = app.requestRender
+ if (layer instanceof CalculatorLayer) layer.requestRender = render
+ this.configureWindow(app.window)
+ shell.registerWindow(app.window)
+ shell.focusWindow(app.window.windowId)
+ app.requestRender(); this.requestShellRender()
+ }
+ cycleDisplayMode(): void {
+ const values = DISPLAY_MODE_VALUES
+ displayModeSetting.set(values[(values.indexOf(displayModeSetting.get()) + 1) % values.length])
+ }
+ get displayModeLabel(): string { return displayModeLabel(displayModeSetting.get()) }
+ async typeIntoApp(): Promise {
+ if (this.prompting || !shell.foregroundWindow()?.receiveTextInput) return
+ this.prompting = true
+ try {
+ const result = await Dialogs.prompt({ title: 'Type into ' + shell.foregroundWindow()?.title,
+ message: 'Enter an expression or follow-up.', okButtonText: 'Send', cancelButtonText: 'Cancel' })
+ if (result.result) shell.sendTextToForegroundWindow(result.text)
+ } catch (error) { this.fail(error) }
+ finally { this.prompting = false }
+ }
+ private async editSetting(setting: { editorTitle: string; get(): string; set(value: string): void }): Promise {
+ const result = await Dialogs.prompt({ title: setting.editorTitle, defaultText: setting.get(), okButtonText: 'Save', cancelButtonText: 'Cancel' })
+ if (result.result) setting.set(result.text)
+ }
+}
diff --git a/app/graphics/icons.ts b/app/graphics/icons.ts
index 7c59d667..fc6f23d1 100644
--- a/app/graphics/icons.ts
+++ b/app/graphics/icons.ts
@@ -1,12 +1,10 @@
import { GrayImage } from "./image";
-
-declare const com: any;
-declare const global: any;
+import { rasterizeSvg } from "../native/svg-rasterizer";
/**
* Vector icons for window indicators (and anywhere else). SVGs are rendered
- * once to a correctly sized grayscale bitmap by the Java IconRenderer (a
- * small SVG subset: path/circle/rect/line/polyline) and cached here. To add
+ * once to a correctly sized grayscale bitmap by the platform rasterizer
+ * (Android IconRenderer or iOS SVGKit) and cached here. To add
* an icon, drop its SVG source into ICON_SVGS — Lucide icons
* (https://lucide.dev, stroked, 24px viewBox) work as-is; simple single-color
* Noun Project glyphs also work.
@@ -171,18 +169,10 @@ function renderSvgCached(cacheName: string, svg: string, size: number): GrayImag
if (cached !== undefined) return cached;
let icon: GrayImage | null = null;
- if (global.isAndroid) {
- try {
- const bytes = com.faceclaw.app.IconRenderer.renderSvgGray(svg, Math.round(size), ICON_STROKE_WIDTH);
- if (bytes && bytes.length >= size * size) {
- icon = new GrayImage(size, size, 0);
- for (let i = 0; i < size * size; i++) {
- icon.pixels[i] = bytes[i] & 0xff;
- }
- }
- } catch (error) {
- console.warn(`renderIcon(${cacheName}) failed: ${error}`);
- }
+ try {
+ icon = rasterizeSvg(svg, Math.round(size), ICON_STROKE_WIDTH);
+ } catch (error) {
+ console.warn(`renderIcon(${cacheName}) failed: ${error}`);
}
cache.set(key, icon);
return icon;
diff --git a/app/graphics/surface-compositor.ts b/app/graphics/surface-compositor.ts
new file mode 100644
index 00000000..1d8f80e7
--- /dev/null
+++ b/app/graphics/surface-compositor.ts
@@ -0,0 +1,75 @@
+/** Platform-independent 8bpp surface composition for the local display. */
+export type SurfaceRect = { x: number; y: number; width: number; height: number }
+export type SurfaceConfiguration = SurfaceRect & {
+ zOrder: number
+ transparency: 'opaque' | 'color-key'
+}
+type Surface = SurfaceConfiguration & { pixels: Uint8Array; visible: boolean }
+
+export class SurfaceCompositor {
+ private readonly surfaces = new Map()
+ private dimBelow = 0
+ private dimFactor = 1
+ private blanked = false
+ constructor(readonly width: number, readonly height: number) {
+ if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0) {
+ throw new Error('Invalid compositor size')
+ }
+ }
+ configureSurface(id: string, options: SurfaceConfiguration): void {
+ if (![options.x, options.y, options.width, options.height, options.zOrder].every(Number.isInteger)
+ || options.width <= 0 || options.height <= 0) throw new Error('Invalid surface geometry')
+ const previous = this.surfaces.get(id)
+ const pixels = previous?.width === options.width && previous.height === options.height
+ ? previous.pixels : new Uint8Array(options.width * options.height)
+ this.surfaces.set(id, { ...options, pixels, visible: previous?.visible ?? true })
+ }
+ removeSurface(id: string): void { this.surfaces.delete(id) }
+ setSurfaceVisible(id: string, visible: boolean): void {
+ const surface = this.surfaces.get(id)
+ if (surface) surface.visible = visible
+ }
+ setUnderlayDim(belowZOrder: number, factor: number): void {
+ if (!Number.isFinite(factor)) throw new Error('Invalid dim factor')
+ this.dimBelow = belowZOrder
+ this.dimFactor = Math.max(0, Math.min(1, factor))
+ }
+ setScreenBlanked(blanked: boolean): void { this.blanked = blanked }
+ submitSurfaceFrame(id: string, pixels: Uint8Array, rect: SurfaceRect): void {
+ const surface = this.surfaces.get(id)
+ if (!surface) throw new Error(`Unknown surface: ${id}`)
+ if (![rect.x, rect.y, rect.width, rect.height].every(Number.isInteger)
+ || rect.width <= 0 || rect.height <= 0 || pixels.length !== rect.width * rect.height) {
+ throw new Error('Invalid frame buffer or rectangle')
+ }
+ const left = Math.max(0, rect.x), right = Math.min(surface.width, rect.x + rect.width)
+ const top = Math.max(0, rect.y), bottom = Math.min(surface.height, rect.y + rect.height)
+ for (let y = top; y < bottom; y++) {
+ if (right <= left) break
+ const source = (y - rect.y) * rect.width + left - rect.x
+ surface.pixels.set(pixels.subarray(source, source + right - left), y * surface.width + left)
+ }
+ }
+ composite(): Uint8Array {
+ const output = new Uint8Array(this.width * this.height)
+ if (this.blanked) return output
+ const surfaces = [...this.surfaces.values()].filter(s => s.visible).sort((a, b) => a.zOrder - b.zOrder)
+ for (const surface of surfaces) {
+ const left = Math.max(0, surface.x), right = Math.min(this.width, surface.x + surface.width)
+ const top = Math.max(0, surface.y), bottom = Math.min(this.height, surface.y + surface.height)
+ const dim = surface.zOrder < this.dimBelow ? this.dimFactor : 1
+ for (let y = top; y < bottom; y++) {
+ let source = (y - surface.y) * surface.width + left - surface.x
+ let target = y * this.width + left
+ for (let x = left; x < right; x++, source++, target++) {
+ const value = surface.pixels[source]
+ // Test the original value: opaque near-black must still cover the
+ // window beneath, even when dimming rounds it down to black.
+ if (surface.transparency === 'color-key' && value === 0) continue
+ output[target] = Math.round(value * dim)
+ }
+ }
+ }
+ return output
+ }
+}
diff --git a/app/native/ios-graphics.ts b/app/native/ios-graphics.ts
new file mode 100644
index 00000000..6052d625
--- /dev/null
+++ b/app/native/ios-graphics.ts
@@ -0,0 +1,21 @@
+import { ImageSource } from '@nativescript/core'
+import { GrayImage } from '../graphics/image'
+
+declare const FaceclawGraphics: any
+
+export function previewPixels(pixels: Uint8Array, width: number, height: number, green = false): ImageSource {
+ // NSData copies the buffer; the UIImage owns its pixels after this call.
+ const copy = new Uint8Array(pixels)
+ const data = NSData.dataWithBytesLength(interop.handleof(copy.buffer), copy.byteLength)
+ const native = FaceclawGraphics.previewWidthHeightGreen(data, width, height, green)
+ if (!native) throw new Error('Could not create preview image')
+ return new ImageSource(native)
+}
+
+export function rasterizeSvg(svg: string, size: number): GrayImage | null {
+ const data = FaceclawGraphics.renderSVGSize(svg, size)
+ if (!data) return null
+ const image = new GrayImage(size, size, 0)
+ image.pixels.set(new Uint8Array(interop.bufferFromData(data)))
+ return image
+}
diff --git a/app/native/settings-store.ios.ts b/app/native/settings-store.ios.ts
new file mode 100644
index 00000000..2d4c3dd5
--- /dev/null
+++ b/app/native/settings-store.ios.ts
@@ -0,0 +1,28 @@
+import { ApplicationSettings } from '@nativescript/core'
+
+// Main-isolate settings for the initial iOS port. Worker synchronization will
+// be added when worker-hosted apps are enabled on iOS.
+const listeners = new Set<(key: string) => void>()
+function changed(key: string): void {
+ setTimeout(() => { for (const listener of [...listeners]) listener(key) }, 0)
+}
+export function getStringSetting(key: string, fallback: string): string {
+ return ApplicationSettings.getString(key, fallback)
+}
+export function setStringSetting(key: string, value: string): void {
+ if (getStringSetting(key, '') === value && ApplicationSettings.hasKey(key)) return
+ ApplicationSettings.setString(key, value)
+ changed(key)
+}
+export function getBooleanSetting(key: string, fallback: boolean): boolean {
+ return ApplicationSettings.getBoolean(key, fallback)
+}
+export function setBooleanSetting(key: string, value: boolean): void {
+ if (getBooleanSetting(key, false) === value && ApplicationSettings.hasKey(key)) return
+ ApplicationSettings.setBoolean(key, value)
+ changed(key)
+}
+export function onSettingsStoreChanged(listener: (key: string) => void): () => void {
+ listeners.add(listener)
+ return () => { listeners.delete(listener) }
+}
diff --git a/app/native/svg-rasterizer.ios.ts b/app/native/svg-rasterizer.ios.ts
new file mode 100644
index 00000000..283045dd
--- /dev/null
+++ b/app/native/svg-rasterizer.ios.ts
@@ -0,0 +1,14 @@
+import { rasterizeSvg as render } from './ios-graphics'
+export function rasterizeSvg(svg: string, size: number, strokeWidth: number) {
+ // Shared icon sources rely on the Android renderer's white, rounded
+ // stroke defaults. Supply those explicitly for a standards SVG renderer.
+ const source = svg.replace(/