@ng-native/device 0.25.0 → 0.26.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/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ export { NavigationBar, navigationBarSource, type NavigationBarSource, type Navi
28
28
  export { SCREEN_IN_FRONT } from './screen-in-front.ts';
29
29
  export { SCREEN_SHOWN } from './screen-shown.ts';
30
30
  export { NATIVE_HISTORY } from './native-history.ts';
31
- export { APPLE, DESKTOP, OS } from './os.ts';
31
+ export { APPLE, DESKTOP, OS, OS_NAMES, type OsName } from './os.ts';
32
32
  export { MENU_MODEL, createMenuModel, defaultMenuBar, isSeparator, mergeMenuBar, menuModelInTreeOrder, treeOrder, type MenuEntry, type MenuGroupModel, type MenuGroupRole, type MenuItemModel, type MenuModel, type MenuRole, type MenuSeparator, } from './menu-model.ts';
33
33
  export { isEditingShortcut, matchesShortcut, navigationShortcut, parseShortcut, shortcutFires, type KeyChord, type ParsedShortcut, type ShortcutOs, } from './shortcut.ts';
34
34
  export { Processes, UndeclaredCapabilityError, type ChildProcess, type NativeProcesses, type ProcessEvent, type ProcessExit, type SpawnOptions, } from './processes.ts';
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ export { NavigationBar, navigationBarSource, } from "./navigation-bar.js";
27
27
  export { SCREEN_IN_FRONT } from "./screen-in-front.js";
28
28
  export { SCREEN_SHOWN } from "./screen-shown.js";
29
29
  export { NATIVE_HISTORY } from "./native-history.js";
30
- export { APPLE, DESKTOP, OS } from "./os.js";
30
+ export { APPLE, DESKTOP, OS, OS_NAMES } from "./os.js";
31
31
  export { MENU_MODEL, createMenuModel, defaultMenuBar, isSeparator, mergeMenuBar, menuModelInTreeOrder, treeOrder, } from "./menu-model.js";
32
32
  export { isEditingShortcut, matchesShortcut, navigationShortcut, parseShortcut, shortcutFires, } from "./shortcut.js";
33
33
  export { Processes, UndeclaredCapabilityError, } from "./processes.js";
package/dist/index.js.map CHANGED
@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O,EACL,IAAI,GAKL,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EACL,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EAajB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAA2B,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAoB,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,GAGzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAqB,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,0BAA0B,EAC1B,UAAU,GAMX,MAAM,2BAA2B,CAAC","sourcesContent":["/**\n * The host: the device, the operating system, and the user's settings.\n *\n * Every capability here is a service with its own factory, so injecting one is the whole setup\n * and one nobody injects is never constructed. Off a device each falls back to doing nothing,\n * which is what makes the whole package importable by the test suite.\n */\nexport {\n Accessibility,\n type AccessibilitySettings,\n type AccessibilitySource,\n} from './accessibility.ts';\nexport { AppState, type AppStateSource, type AppStatus } from './app-state.ts';\nexport { ColorScheme, type ColorSchemeSource, type Scheme } from './color-scheme.ts';\nexport {\n currentConditions,\n deviceTokens,\n hairlineTokens,\n watchConditions,\n type WatchOptions,\n} from './conditions.ts';\nexport { DeepLinks, deepLinkSource, pathOf, type DeepLinkSource } from './deep-links.ts';\nexport {\n Direction,\n type DirectionContext,\n type DirectionSource,\n type LayoutDirection,\n} from './direction.ts';\nexport {\n androidPermission,\n type AndroidPermissions,\n type PermissionAnswer,\n} from './android-permissions.ts';\nexport { DevMenu, type DevMenuSource, type NativeDevMenu } from './dev-menu.ts';\nexport { Dialogs, type Choice, type NativeDialogs } from './dialogs.ts';\nexport {\n LayoutAnimation,\n type LayoutChange,\n type LayoutEasing,\n type NativeLayoutAnimation,\n} from './layout-animation.ts';\nexport { Sharing, type NativeSharing, type ShareRequest } from './sharing.ts';\nexport { Vibration, type NativeVibration } from './vibration.ts';\nexport { HardwareBack, hardwareBackSource, type HardwareBackSource } from './hardware-back.ts';\nexport {\n KEYBOARD_MOTION,\n Keyboard,\n keyboardSource,\n type KeyboardMetrics,\n type KeyboardMotion,\n type KeyboardSource,\n} from './keyboard.ts';\nexport type { NativeKeyboardEvent } from './react-native.ts';\nexport { SafeArea, type Frame, type Insets } from './safe-area.ts';\nexport { COMPACT_WIDTH, Screen, type ScreenSource, type Size, type Sizes } from './screen.ts';\nexport {\n StatusBar,\n statusBarSource,\n type PlatformStatusBarStyle,\n type StatusBarSource,\n type StatusBarState,\n type StatusBarStyle,\n} from './status-bar.ts';\nexport {\n TopClaim,\n WindowClaims,\n onWindowFront,\n sharedBySource,\n type Claim,\n} from './window-claims.ts';\nexport {\n NavigationBar,\n navigationBarSource,\n type NavigationBarSource,\n type NavigationBarState,\n type NavigationBarStyle,\n} from './navigation-bar.ts';\nexport { SCREEN_IN_FRONT } from './screen-in-front.ts';\nexport { SCREEN_SHOWN } from './screen-shown.ts';\nexport { NATIVE_HISTORY } from './native-history.ts';\nexport { APPLE, DESKTOP, OS } from './os.ts';\nexport {\n MENU_MODEL,\n createMenuModel,\n defaultMenuBar,\n isSeparator,\n mergeMenuBar,\n menuModelInTreeOrder,\n treeOrder,\n type MenuEntry,\n type MenuGroupModel,\n type MenuGroupRole,\n type MenuItemModel,\n type MenuModel,\n type MenuRole,\n type MenuSeparator,\n} from './menu-model.ts';\nexport {\n isEditingShortcut,\n matchesShortcut,\n navigationShortcut,\n parseShortcut,\n shortcutFires,\n type KeyChord,\n type ParsedShortcut,\n type ShortcutOs,\n} from './shortcut.ts';\nexport {\n Processes,\n UndeclaredCapabilityError,\n type ChildProcess,\n type NativeProcesses,\n type ProcessEvent,\n type ProcessExit,\n type SpawnOptions,\n} from './processes.ts';\nexport {\n SEARCH_PATH,\n SpawnRuleError,\n compileCapability,\n filterEnvironment,\n matchArguments,\n matchSpawn,\n parseArgument,\n programProblem,\n resolveProgram,\n type ArgumentRule,\n type CompiledCapability,\n type PlaceholderValues,\n type ProgramLookup,\n type SpawnCapability,\n type SpawnMatch,\n} from './spawn-rules.ts';\nexport {\n desktopOptionProblems,\n pathAllowed,\n pathProblem,\n validateDesktopOptions,\n type DesktopCapabilities,\n type DesktopOptions,\n type DocumentType,\n type PathCapability,\n} from './desktop-options.ts';\nexport {\n macosPermissions,\n type ExpoPermissionConfig,\n type MacosPermissions,\n} from './desktop-permissions.ts';\nexport {\n Menus,\n menuActionId,\n menusSource,\n serializeMenu,\n type NativeMenuEntry,\n type NativeMenuEvent,\n type NativeMenus,\n type NativeWindowHistory,\n type NativeShortcut,\n type SerializedMenu,\n} from './menus.ts';\nexport { Dock, type NativeDock } from './dock.ts';\nexport { nativeSplitViews } from './split-views.ts';\nexport {\n DragAndDrop,\n dragAndDropSource,\n type NativeDragAndDrop,\n type NativeDragItem,\n type NativeDropEvent,\n} from './drag-and-drop.ts';\nexport { UndoStack, type NativeUndo, type NativeUndoEvent, type UndoAction } from './undo-stack.ts';\nexport {\n OS_SUPPORT,\n SUPPORT_OSES,\n platformsLine,\n supportRowOf,\n type OsSupportRow,\n type SupportOs,\n} from './os-support.ts';\nexport { Shell, type NativeShell } from './shell.ts';\nexport {\n Tray,\n type NativeTray,\n type NativeTrayEvent,\n type NativeTrayIcon,\n type TrayIconModel,\n} from './tray.ts';\nexport { SIDEBAR_SELECTION } from './sidebar-selection.ts';\nexport { expoViewName } from './expo-view-name.ts';\nexport { hostInputNames, ownHost } from './own-host.ts';\nexport { WINDOW_NAVIGATOR, type WindowNavigator } from './window-navigator.ts';\nexport {\n AppWindows,\n CURRENT_WINDOW,\n MAIN_WINDOW_OPTIONS,\n WINDOW_MOUNTER,\n provideMainWindow,\n type AppWindow,\n type CloseGuard,\n type ComponentWindowOptions,\n type MainWindowOptions,\n type NativeWindowEvent,\n type NativeWindowRequest,\n type NativeWindows,\n type RouteWindowOptions,\n type TitleBar,\n type WindowMount,\n type WindowMounter,\n type WindowOptions,\n windowsSource,\n} from './app-windows.ts';\nexport {\n APP_LIFECYCLE_OPTIONS,\n AppLifecycle,\n WILL_QUIT_DEADLINE_MS,\n provideAppLifecycle,\n quitsWithLastWindow,\n type AppLifecycleOptions,\n} from './app-lifecycle.ts';\nexport { OS_VERSION } from './os-version.ts';\nexport { injectToken, type InjectTokenOptions } from './inject-token.ts';\nexport { type ControlSize } from './control-size.ts';\nexport {\n RESTORABLE_WINDOWS,\n WINDOW_RESTORE_STORE,\n provideRestorableWindows,\n type RestoredWindow,\n type WindowRestoreStore,\n} from './window-restore.ts';\nexport { buildMenuTemplate, type MenuTemplate } from './menu-template.ts';\nexport {\n INTERACTION_OBSERVERS,\n MAX_TEXT_LENGTH,\n describeElement,\n interactionObservers,\n notifyInteraction,\n provideInteractionObserver,\n textWithin,\n type InteractionDirection,\n type InteractionEvent,\n type InteractionGesture,\n type InteractionObserver,\n type InteractionType,\n} from './interaction-observer.ts';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,aAAa,GAGd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAuC,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAuC,MAAM,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gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EACL,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EAajB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAA2B,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAoB,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,GAGzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAqB,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,0BAA0B,EAC1B,UAAU,GAMX,MAAM,2BAA2B,CAAC","sourcesContent":["/**\n * The host: the device, the operating system, and the user's settings.\n *\n * Every capability here is a service with its own factory, so injecting one is the whole setup\n * and one nobody injects is never constructed. Off a device each falls back to doing nothing,\n * which is what makes the whole package importable by the test suite.\n */\nexport {\n Accessibility,\n type AccessibilitySettings,\n type AccessibilitySource,\n} from './accessibility.ts';\nexport { AppState, type AppStateSource, type AppStatus } from './app-state.ts';\nexport { ColorScheme, type ColorSchemeSource, type Scheme } from './color-scheme.ts';\nexport {\n currentConditions,\n deviceTokens,\n hairlineTokens,\n watchConditions,\n type WatchOptions,\n} from './conditions.ts';\nexport { DeepLinks, deepLinkSource, pathOf, type DeepLinkSource } from './deep-links.ts';\nexport {\n Direction,\n type DirectionContext,\n type DirectionSource,\n type LayoutDirection,\n} from './direction.ts';\nexport {\n androidPermission,\n type AndroidPermissions,\n type PermissionAnswer,\n} from './android-permissions.ts';\nexport { DevMenu, type DevMenuSource, type NativeDevMenu } from './dev-menu.ts';\nexport { Dialogs, type Choice, type NativeDialogs } from './dialogs.ts';\nexport {\n LayoutAnimation,\n type LayoutChange,\n type LayoutEasing,\n type NativeLayoutAnimation,\n} from './layout-animation.ts';\nexport { Sharing, type NativeSharing, type ShareRequest } from './sharing.ts';\nexport { Vibration, type NativeVibration } from './vibration.ts';\nexport { HardwareBack, hardwareBackSource, type HardwareBackSource } from './hardware-back.ts';\nexport {\n KEYBOARD_MOTION,\n Keyboard,\n keyboardSource,\n type KeyboardMetrics,\n type KeyboardMotion,\n type KeyboardSource,\n} from './keyboard.ts';\nexport type { NativeKeyboardEvent } from './react-native.ts';\nexport { SafeArea, type Frame, type Insets } from './safe-area.ts';\nexport { COMPACT_WIDTH, Screen, type ScreenSource, type Size, type Sizes } from './screen.ts';\nexport {\n StatusBar,\n statusBarSource,\n type PlatformStatusBarStyle,\n type StatusBarSource,\n type StatusBarState,\n type StatusBarStyle,\n} from './status-bar.ts';\nexport {\n TopClaim,\n WindowClaims,\n onWindowFront,\n sharedBySource,\n type Claim,\n} from './window-claims.ts';\nexport {\n NavigationBar,\n navigationBarSource,\n type NavigationBarSource,\n type NavigationBarState,\n type NavigationBarStyle,\n} from './navigation-bar.ts';\nexport { SCREEN_IN_FRONT } from './screen-in-front.ts';\nexport { SCREEN_SHOWN } from './screen-shown.ts';\nexport { NATIVE_HISTORY } from './native-history.ts';\nexport { APPLE, DESKTOP, OS, OS_NAMES, type OsName } from './os.ts';\nexport {\n MENU_MODEL,\n createMenuModel,\n defaultMenuBar,\n isSeparator,\n mergeMenuBar,\n menuModelInTreeOrder,\n treeOrder,\n type MenuEntry,\n type MenuGroupModel,\n type MenuGroupRole,\n type MenuItemModel,\n type MenuModel,\n type MenuRole,\n type MenuSeparator,\n} from './menu-model.ts';\nexport {\n isEditingShortcut,\n matchesShortcut,\n navigationShortcut,\n parseShortcut,\n shortcutFires,\n type KeyChord,\n type ParsedShortcut,\n type ShortcutOs,\n} from './shortcut.ts';\nexport {\n Processes,\n UndeclaredCapabilityError,\n type ChildProcess,\n type NativeProcesses,\n type ProcessEvent,\n type ProcessExit,\n type SpawnOptions,\n} from './processes.ts';\nexport {\n SEARCH_PATH,\n SpawnRuleError,\n compileCapability,\n filterEnvironment,\n matchArguments,\n matchSpawn,\n parseArgument,\n programProblem,\n resolveProgram,\n type ArgumentRule,\n type CompiledCapability,\n type PlaceholderValues,\n type ProgramLookup,\n type SpawnCapability,\n type SpawnMatch,\n} from './spawn-rules.ts';\nexport {\n desktopOptionProblems,\n pathAllowed,\n pathProblem,\n validateDesktopOptions,\n type DesktopCapabilities,\n type DesktopOptions,\n type DocumentType,\n type PathCapability,\n} from './desktop-options.ts';\nexport {\n macosPermissions,\n type ExpoPermissionConfig,\n type MacosPermissions,\n} from './desktop-permissions.ts';\nexport {\n Menus,\n menuActionId,\n menusSource,\n serializeMenu,\n type NativeMenuEntry,\n type NativeMenuEvent,\n type NativeMenus,\n type NativeWindowHistory,\n type NativeShortcut,\n type SerializedMenu,\n} from './menus.ts';\nexport { Dock, type NativeDock } from './dock.ts';\nexport { nativeSplitViews } from './split-views.ts';\nexport {\n DragAndDrop,\n dragAndDropSource,\n type NativeDragAndDrop,\n type NativeDragItem,\n type NativeDropEvent,\n} from './drag-and-drop.ts';\nexport { UndoStack, type NativeUndo, type NativeUndoEvent, type UndoAction } from './undo-stack.ts';\nexport {\n OS_SUPPORT,\n SUPPORT_OSES,\n platformsLine,\n supportRowOf,\n type OsSupportRow,\n type SupportOs,\n} from './os-support.ts';\nexport { Shell, type NativeShell } from './shell.ts';\nexport {\n Tray,\n type NativeTray,\n type NativeTrayEvent,\n type NativeTrayIcon,\n type TrayIconModel,\n} from './tray.ts';\nexport { SIDEBAR_SELECTION } from './sidebar-selection.ts';\nexport { expoViewName } from './expo-view-name.ts';\nexport { hostInputNames, ownHost } from './own-host.ts';\nexport { WINDOW_NAVIGATOR, type WindowNavigator } from './window-navigator.ts';\nexport {\n AppWindows,\n CURRENT_WINDOW,\n MAIN_WINDOW_OPTIONS,\n WINDOW_MOUNTER,\n provideMainWindow,\n type AppWindow,\n type CloseGuard,\n type ComponentWindowOptions,\n type MainWindowOptions,\n type NativeWindowEvent,\n type NativeWindowRequest,\n type NativeWindows,\n type RouteWindowOptions,\n type TitleBar,\n type WindowMount,\n type WindowMounter,\n type WindowOptions,\n windowsSource,\n} from './app-windows.ts';\nexport {\n APP_LIFECYCLE_OPTIONS,\n AppLifecycle,\n WILL_QUIT_DEADLINE_MS,\n provideAppLifecycle,\n quitsWithLastWindow,\n type AppLifecycleOptions,\n} from './app-lifecycle.ts';\nexport { OS_VERSION } from './os-version.ts';\nexport { injectToken, type InjectTokenOptions } from './inject-token.ts';\nexport { type ControlSize } from './control-size.ts';\nexport {\n RESTORABLE_WINDOWS,\n WINDOW_RESTORE_STORE,\n provideRestorableWindows,\n type RestoredWindow,\n type WindowRestoreStore,\n} from './window-restore.ts';\nexport { buildMenuTemplate, type MenuTemplate } from './menu-template.ts';\nexport {\n INTERACTION_OBSERVERS,\n MAX_TEXT_LENGTH,\n describeElement,\n interactionObservers,\n notifyInteraction,\n provideInteractionObserver,\n textWithin,\n type InteractionDirection,\n type InteractionEvent,\n type InteractionGesture,\n type InteractionObserver,\n type InteractionType,\n} from './interaction-observer.ts';\n"]}
package/dist/menus.js CHANGED
@@ -117,8 +117,6 @@ function contextMenuMethods(module) {
117
117
  ...(setTakesLongPress && { setTakesLongPress }),
118
118
  };
119
119
  }
120
- /** The `ShortcutOs` an `OS` reads shortcuts as. */
121
- const shortcutOs = (os) => os === 'android' || os === 'macos' || os === 'web' ? os : 'ios';
122
120
  /**
123
121
  * The menus and shortcuts an app has, sent to the host as they change. `<menu-bar>` and
124
122
  * `[shortcut]` in `@ng-native/components` register here; an app rarely injects it.
@@ -129,7 +127,7 @@ export class Menus {
129
127
  factory: menusSource,
130
128
  });
131
129
  native = inject(Menus.SOURCE);
132
- os = shortcutOs(injectOs());
130
+ os = injectOs();
133
131
  /** Whether the host has the module: shortcuts from a hardware keyboard, and menus. */
134
132
  available = signal(this.native !== null).asReadonly();
135
133
  /** Whether the menu bar is drawn: macOS and iPadOS. Elsewhere its shortcuts still work. */
package/dist/menus.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"menus.js","sourceRoot":"","sources":["../src/menus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EACL,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,cAAc,GAGf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,GAGd,MAAM,eAAe,CAAC;;AA4BvB,MAAM,SAAS,GAAG,IAAI,OAAO,EAAsB,CAAC;AACpD,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,IAAI,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,KAAK,SAAS;QAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;IACzE,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA6B,EAC7B,EAAc,EACd,MAAM,GAAG,EAAE;IAEX,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC9C,MAAM,IAAI,GAAG,CAAC,IAA0B,EAAE,EAAU,EAAqB,EAAE,CACzE,IAAI,CAAC,GAAG,CAAC,CAA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GAxPU,KAAK;wGAAL,KAAK;;2FAAL,KAAK;kBADjB,OAAO","sourcesContent":["/**\n * Menus and keyboard shortcuts as the host receives them: the menu bar, the shortcuts that are in\n * no menu, and the form a menu takes on its way to native, which a context menu shares.\n *\n * The host contract, on the `NgNativeMenus` module:\n * - `setMenuBar(groups)`: the whole merged menu bar, each time it changes. The desktop host draws\n * it as the main menu, iPadOS through UIMenuBuilder. Each item has an `id`; an item with a\n * `menuRole` and no `id`'s action is the OS's own (Copy, Quit).\n * - `setShortcuts(shortcuts)`: every shortcut the app listens for outside the menu bar, each with\n * its `id`, its chord read for the OS, and a `label` and `group` for Android's Keyboard Shortcuts\n * helper. On iPhone and Android the menu bar's own shortcuts are in it too, since no bar is drawn.\n * - It sends `ngNativeMenus` events on `DeviceEventEmitter`: `{ type: 'menuSelect', id }` for a menu\n * bar item, and `{ type: 'shortcut', id, textInputFocused }` for a chord pressed.\n * - Its constants say whether it draws a menu bar (`menuBar`) and the app's name (`appName`).\n * - On Android it is an Expo module: the constants are properties, it sends the same events through\n * its own `addListener('ngNativeMenus', ...)`, and it has `setContextMenu(nativeID, entries)`,\n * since React Native's Android view drops a `contextMenu` prop it does not know.\n * - On iOS it is a TurboModule with `setContextMenu(nativeID, entries)` too, for the same reason.\n * React Native's iOS view sends no event it does not know either, so the module sends the item\n * chosen as `{ type: 'contextMenuSelect', nativeID, id }`.\n * - Where it draws context menus, `setTakesLongPress(nativeID, takes)` names a view inside one\n * whose own `(longPress)` takes a long press first: a long press there opens no menu around it,\n * as the innermost handler wins in a native app. A right-click still opens the menu on Android.\n * iOS tells a long press from a secondary click only by the gesture, so an iPad pointer's\n * secondary click there opens none either.\n */\nimport {\n InjectionToken,\n Service,\n computed,\n effect,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport {\n defaultMenuBar,\n isSeparator,\n mergeMenuBar,\n unmergedGroups,\n type MenuEntry,\n type MenuGroupModel,\n} from './menu-model.ts';\nimport { injectOs } from './os.ts';\nimport { reactNative } from './react-native.ts';\nimport {\n isEditingShortcut,\n navigationShortcut,\n parseShortcut,\n type ParsedShortcut,\n type ShortcutOs,\n} from './shortcut.ts';\n\n/** A menu entry as the host receives it. */\nexport type NativeMenuEntry =\n | { readonly separator: true }\n | {\n readonly id: string;\n readonly label: string;\n readonly menuRole?: string;\n /** On an item with a `menuRole`: the app handles it, and the OS does not. */\n readonly handled?: true;\n readonly shortcut?: ParsedShortcut;\n readonly disabled?: boolean;\n readonly checked?: boolean;\n readonly destructive?: boolean;\n readonly subtitle?: string;\n readonly sfSymbol?: string;\n readonly icon?: string;\n readonly inline?: boolean;\n readonly items?: readonly NativeMenuEntry[];\n };\n\n/** A menu ready for the host, and what each id it was given does. */\nexport interface SerializedMenu {\n readonly entries: NativeMenuEntry[];\n readonly actions: ReadonlyMap<string, () => void>;\n}\n\nconst actionIds = new WeakMap<() => void, string>();\nlet actionsNamed = 0;\n\n/**\n * The id a menu item with `select` is sent under: the same for as long as the handler is, and no\n * other handler's. `<menu-item>` keeps one handler for its life, so a host that reports a choice\n * from a menu it drew before the items changed still runs that item, or nothing once it has gone,\n * never the item that has taken its place.\n */\nexport function menuActionId(select: () => void): string {\n let id = actionIds.get(select);\n if (id === undefined) actionIds.set(select, (id = `a${++actionsNamed}`));\n return id;\n}\n\n/**\n * `entries` as the host takes them: an id for each item, its shortcut read for `os`, and the\n * handlers by id. An item with a handler is named by it (`menuActionId`); one without, which the\n * app never runs, by its place (`2.0.1`).\n */\nexport function serializeMenu(\n entries: readonly MenuEntry[],\n os: ShortcutOs,\n prefix = '',\n): SerializedMenu {\n const actions = new Map<string, () => void>();\n const walk = (list: readonly MenuEntry[], at: string): NativeMenuEntry[] =>\n list.map((entry, index) => {\n if (isSeparator(entry)) return { separator: true };\n const place = `${at}${index}`;\n const { select, shortcut, items, group: _group, ...rest } = entry;\n const id = select ? menuActionId(select) : place;\n if (select) actions.set(id, select);\n return {\n id,\n ...rest,\n // A role item the app handles: the host sends its select rather than doing the role.\n ...(select && entry.menuRole && { handled: true }),\n ...(shortcut\n ? { shortcut: parseShortcut(shortcut, os) }\n : (entry.menuRole === 'back' || entry.menuRole === 'forward') && {\n shortcut: navigationShortcut(entry.menuRole, os),\n }),\n ...(items && { items: walk(items, `${place}.`) }),\n };\n });\n return { entries: walk(entries, prefix), actions };\n}\n\n/** A shortcut as the host receives it. */\nexport interface NativeShortcut {\n readonly id: string;\n readonly chord: ParsedShortcut;\n /** What Android's Keyboard Shortcuts helper lists it as. */\n readonly label: string;\n /** The heading it is listed under there: its menu's label, or the app's name. */\n readonly group: string;\n}\n\nexport type NativeMenuEvent =\n | { readonly type: 'menuSelect'; readonly id: string }\n | { readonly type: 'shortcut'; readonly id: string; readonly textInputFocused?: boolean }\n /** An item chosen in the context menu of the view with `nativeID` (iOS). */\n | { readonly type: 'contextMenuSelect'; readonly nativeID: string; readonly id: string }\n /**\n * Back or forward, from whichever input the OS has for it: View > Back and Forward and their\n * keys, a two-finger swipe, mouse buttons 4 and 5, the toolbar's chevrons and their history\n * menus. `surface` is the window it was in, and `steps` how many entries (one where absent).\n */\n | {\n readonly type: 'navigate';\n readonly direction: 'back' | 'forward';\n readonly surface?: number;\n readonly steps?: number;\n };\n\n/** A window's history as the host draws it: the titles behind and ahead, nearest first. */\nexport interface NativeWindowHistory {\n readonly back: readonly string[];\n readonly forward: readonly string[];\n}\n\n/** The host's menu module. */\nexport interface NativeMenus {\n /** Whether the host draws a menu bar: macOS, and iPadOS. */\n readonly menuBar: boolean;\n readonly appName: string;\n setMenuBar(\n groups: readonly { label: string; menuRole?: string; items: NativeMenuEntry[] }[],\n ): void;\n setShortcuts(shortcuts: readonly NativeShortcut[]): void;\n /** The history of the window on `surface`, for its back and forward chevrons. Desktop only. */\n setHistory?(surface: number, history: NativeWindowHistory): void;\n /**\n * The context menu of the view with `nativeID`, or null to take it away. Android and iOS, whose\n * views read no `contextMenu` prop: the host finds the view by its `nativeID`.\n */\n setContextMenu?(nativeID: string, entries: readonly NativeMenuEntry[] | null): void;\n /**\n * Whether the view with `nativeID` takes a long press itself, so a context menu around it does\n * not open on one there. Android and iOS, beside `setContextMenu`.\n */\n setTakesLongPress?(nativeID: string, takes: boolean): void;\n subscribe(listener: (event: NativeMenuEvent) => void): () => void;\n}\n\ninterface MenusModule {\n getConstants?(): { menuBar?: boolean; appName?: string };\n /** An Expo module's constants, which are its properties. */\n readonly menuBar?: boolean;\n readonly appName?: string;\n setMenuBar?(groups: unknown): void;\n setShortcuts?(shortcuts: unknown): void;\n setHistory?(surface: number, history: unknown): void;\n setContextMenu?(nativeID: string, entries: unknown): void;\n setTakesLongPress?(nativeID: string, takes: boolean): void;\n /** An Expo module's own events. */\n addListener?(event: string, listener: (event: unknown) => void): { remove(): void };\n}\n\n/** Android's `NgNativeMenus`, an Expo module, where React Native has no TurboModule of the name. */\nfunction expoMenusModule(): MenusModule | undefined {\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n return modules?.['NgNativeMenus'] as MenusModule | undefined;\n}\n\n/**\n * The host's menu module: a TurboModule (the desktop host, iOS), or else Android's Expo module.\n * Null where there is neither, as in Expo Go.\n */\nexport function menusSource(): NativeMenus | null {\n const native = reactNative();\n const turbo = native?.TurboModuleRegistry?.get?.('NgNativeMenus') as\n MenusModule | null | undefined;\n const expo = turbo ? undefined : expoMenusModule();\n const module = turbo ?? expo;\n if (!module) return null;\n const constants = module.getConstants?.() ?? module;\n // An Expo module sends its events itself; a TurboModule's come through DeviceEventEmitter.\n const listen = (hear: (event: unknown) => void) =>\n expo\n ? expo.addListener?.('ngNativeMenus', hear)\n : native?.DeviceEventEmitter?.addListener('ngNativeMenus', hear);\n return {\n menuBar: constants.menuBar === true,\n appName: constants.appName ?? '',\n setMenuBar: (groups) => module.setMenuBar?.(groups),\n setShortcuts: (shortcuts) => module.setShortcuts?.(shortcuts),\n setHistory: (surface, history) => module.setHistory?.(surface, history),\n ...contextMenuMethods(module),\n subscribe: (listener) => {\n const subscription = listen((event) => listener(event as NativeMenuEvent));\n return () => subscription?.remove();\n },\n };\n}\n\n/** The context menu methods a module has, bound, and none it lacks: a host without them reads props. */\nfunction contextMenuMethods(\n module: MenusModule,\n): Pick<NativeMenus, 'setContextMenu' | 'setTakesLongPress'> {\n const setContextMenu = module.setContextMenu?.bind(module);\n const setTakesLongPress = module.setTakesLongPress?.bind(module);\n return {\n ...(setContextMenu && { setContextMenu }),\n ...(setTakesLongPress && { setTakesLongPress }),\n };\n}\n\n/** The `ShortcutOs` an `OS` reads shortcuts as. */\nconst shortcutOs = (os: string): ShortcutOs =>\n os === 'android' || os === 'macos' || os === 'web' ? os : 'ios';\n\n/** A `[shortcut]` registered with `KeyboardShortcuts`. */\ninterface Registered {\n readonly shortcut: Signal<string>;\n readonly label: Signal<string>;\n readonly press: () => void;\n}\n\n/**\n * The menus and shortcuts an app has, sent to the host as they change. `<menu-bar>` and\n * `[shortcut]` in `@ng-native/components` register here; an app rarely injects it.\n */\n@Service()\nexport class Menus {\n /** Overridden in a test with a fake host. */\n static readonly SOURCE = new InjectionToken<NativeMenus | null>('angular-native.menusSource', {\n factory: menusSource,\n });\n\n private readonly native = inject(Menus.SOURCE);\n private readonly os = shortcutOs(injectOs());\n\n /** Whether the host has the module: shortcuts from a hardware keyboard, and menus. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\n\n /** Whether the menu bar is drawn: macOS and iPadOS. Elsewhere its shortcuts still work. */\n readonly menuBarShown: Signal<boolean> = signal(this.native?.menuBar === true).asReadonly();\n\n /**\n * Whether the host takes a `[contextMenu]` by the view's `nativeID` through `setContextMenu`\n * (Android and iOS) rather than as the view's `contextMenu` prop. Where it does, it draws the\n * menu on a long press.\n */\n readonly contextMenuByNativeId: boolean = this.native?.setContextMenu !== undefined;\n\n /**\n * Whether the host, which draws context menus on a long press, can be told which views inside\n * one take a long press themselves (`setTakesLongPress`).\n */\n readonly longPressByNativeId: boolean =\n this.contextMenuByNativeId && this.native?.setTakesLongPress !== undefined;\n\n /**\n * Say whether the view with `nativeID` takes a long press itself: one there then opens no\n * context menu around it.\n */\n setTakesLongPress(nativeID: string, takes: boolean): void {\n if (takes) this.longPressTakers.add(nativeID);\n else this.longPressTakers.delete(nativeID);\n this.native?.setTakesLongPress?.(nativeID, takes);\n }\n\n /** The `nativeID`s sent with a context menu, and with a long press of their own. */\n private readonly withContextMenu = new Set<string>();\n private readonly longPressTakers = new Set<string>();\n\n /**\n * Whether the host opens a context menu on a long press of the view whose `nativeID`s, from it\n * outwards, are `chain`: as it decides, the nearest view with a menu, unless one on the way takes\n * the long press itself. A `(longPress)` around that view leaves the hold to the menu, which the\n * host opens after its own long-press timeout.\n */\n opensContextMenu(chain: Iterable<string | null>): boolean {\n for (const nativeID of chain) {\n if (nativeID === null) continue;\n if (this.withContextMenu.has(nativeID)) return true;\n if (this.longPressTakers.has(nativeID)) return false;\n }\n return false;\n }\n\n /** What choosing an item does, by the `nativeID` of the view whose menu it is in. */\n private readonly contextMenuChoices = new Map<string, (id: string) => void>();\n\n /**\n * Send the context menu of the view with `nativeID`, or null to take it away. `choose` runs with\n * the item's `id` where the host sends the choice itself (iOS) rather than through the view.\n */\n setContextMenu(\n nativeID: string,\n entries: readonly NativeMenuEntry[] | null,\n choose?: (id: string) => void,\n ): void {\n if (entries && choose) this.contextMenuChoices.set(nativeID, choose);\n else this.contextMenuChoices.delete(nativeID);\n if (entries?.length) this.withContextMenu.add(nativeID);\n else this.withContextMenu.delete(nativeID);\n this.native?.setContextMenu?.(nativeID, entries);\n }\n\n private readonly bars = signal<readonly Signal<readonly MenuEntry[]>[]>([]);\n private readonly shortcuts = signal<readonly Registered[]>([]);\n\n /** The app's groups, from every `<menu-bar>`, in the order they registered. */\n private readonly appGroups = computed<MenuGroupModel[]>(() =>\n this.bars()\n .flatMap((bar) => bar())\n .flatMap((entry) =>\n isSeparator(entry)\n ? []\n : [\n {\n label: entry.label,\n ...(entry.group && { menuRole: entry.group }),\n items: entry.items ?? [],\n },\n ],\n ),\n );\n\n /** The menu bar as it is drawn: the OS's defaults with the app's merged in. */\n readonly menuBar: Signal<MenuGroupModel[]> = computed(() =>\n mergeMenuBar(defaultMenuBar(this.native?.appName || 'App'), this.appGroups()),\n );\n\n private readonly sentBar = computed(() => {\n const groups = this.menuBar();\n const actions = new Map<string, () => void>();\n const sent = groups.map((group, index) => {\n const menu = serializeMenu(group.items, this.os, `${index}.`);\n menu.actions.forEach((action, id) => actions.set(id, action));\n return {\n label: group.label,\n ...(group.menuRole && { menuRole: group.menuRole }),\n items: menu.entries,\n };\n });\n return { sent, actions };\n });\n\n /**\n * The shortcuts sent to the host: every `[shortcut]`, and where no menu bar is drawn, every\n * menu bar item the app gave a shortcut and a handler, so a hardware keyboard still has them.\n */\n private readonly sentShortcuts = computed(() => {\n const presses = new Map<string, () => void>();\n const editing = new Set<string>();\n const sent: NativeShortcut[] = [];\n const add = (id: string, shortcut: string, label: string, group: string, press: () => void) => {\n presses.set(id, press);\n if (isEditingShortcut(shortcut, this.os)) editing.add(id);\n sent.push({ id, chord: parseShortcut(shortcut, this.os), label, group });\n };\n this.shortcuts().forEach((one, index) =>\n add(`s${index}`, one.shortcut(), one.label(), this.native?.appName || 'App', one.press),\n );\n if (!this.menuBarShown()) {\n const walk = (entries: readonly MenuEntry[], group: string, at: string) =>\n entries.forEach((entry, index) => {\n if (isSeparator(entry)) return;\n if (entry.shortcut && entry.select && !entry.disabled) {\n add(`m${at}${index}`, entry.shortcut, entry.label, group, entry.select);\n }\n if (entry.items) walk(entry.items, group, `${at}${index}.`);\n });\n this.appGroups().forEach((group, index) => walk(group.items, group.label, `${index}.`));\n }\n return { sent, presses, editing };\n });\n\n private readonly unsubscribe = this.native?.subscribe((event) => this.hostSaid(event)) ?? null;\n\n constructor() {\n // Once a label: a `<menu-group label=\"File\">` with no role that is still a group of its own\n // once merged is drawn as a second File menu, on a host that draws a menu bar.\n const warned = new Set<string>();\n effect(() => {\n if (!this.menuBarShown()) return;\n const defaults = defaultMenuBar(this.native?.appName || 'App');\n for (const label of unmergedGroups(defaults, this.menuBar())) {\n if (warned.has(label)) continue;\n warned.add(label);\n const role = defaults.find(\n (group) => group.label.toLowerCase() === label.toLowerCase(),\n )?.menuRole;\n console.warn(\n `[angular-native] <menu-group label=\"${label}\"> has no menuRole, so it shows as a second ` +\n `${label} menu. Give it menuRole=\"${role}\" to add its items to the ${label} menu.`,\n );\n }\n });\n const native = this.native;\n if (!native) {\n // Read for nothing, so a shortcut the app gets wrong throws where there is no host too, and\n // not first on a device that has one.\n effect(() => this.sentShortcuts());\n return;\n }\n effect(() => {\n if (this.menuBarShown()) native.setMenuBar(this.sentBar().sent);\n });\n effect(() => native.setShortcuts(this.sentShortcuts().sent));\n }\n\n /**\n * Add a `<menu-bar>`'s groups, each a `MenuItemModel` with `items` and its `group` role. Answers\n * the function that takes them out again, as the `<menu-bar>` goes.\n */\n addMenuBar(groups: Signal<readonly MenuEntry[]>): () => void {\n this.bars.update((all) => [...all, groups]);\n return () => this.bars.update((all) => all.filter((one) => one !== groups));\n }\n\n /**\n * Listen for `shortcut`, pressed anywhere in the app: `mod+k`, as `parseShortcut` reads it.\n * `label` is what Android's Keyboard Shortcuts helper lists it as. Answers the function that\n * stops listening.\n */\n addShortcut(shortcut: Signal<string>, label: Signal<string>, press: () => void): () => void {\n const registered: Registered = { shortcut, label, press };\n this.shortcuts.update((all) => [...all, registered]);\n return () => this.shortcuts.update((all) => all.filter((one) => one !== registered));\n }\n\n private readonly navigators = new Set<\n (direction: 'back' | 'forward', surface?: number, steps?: number) => void\n >();\n\n /**\n * Hear the OS's back and forward commands. `@ng-native/router` listens, and moves through the\n * history of the window each was in, `steps` entries (one, but for a pick from a chevron's\n * history menu). Answers the function that stops listening.\n */\n onNavigate(\n listener: (direction: 'back' | 'forward', surface?: number, steps?: number) => void,\n ): () => void {\n this.navigators.add(listener);\n return () => void this.navigators.delete(listener);\n }\n\n /**\n * Tell the host the history of the window on `surface`, which its toolbar's back and forward\n * chevrons and their menus show. `@ng-native/router` calls it. Does nothing where the host has\n * no chevrons.\n */\n setHistory(surface: number, history: NativeWindowHistory): void {\n this.native?.setHistory?.(surface, history);\n }\n\n private hostSaid(event: NativeMenuEvent): void {\n if (event.type === 'navigate') {\n const steps = event.steps ?? 1;\n this.navigators.forEach((listener) => listener(event.direction, event.surface, steps));\n return;\n }\n if (event.type === 'menuSelect') {\n this.sentBar().actions.get(event.id)?.();\n return;\n }\n if (event.type === 'contextMenuSelect') {\n this.contextMenuChoices.get(event.nativeID)?.(event.id);\n return;\n }\n const { presses, editing } = this.sentShortcuts();\n // The editing keys belong to a focused text input: the app's shortcut on one waits.\n if (event.textInputFocused && editing.has(event.id)) return;\n presses.get(event.id)?.();\n }\n\n ngOnDestroy(): void {\n this.unsubscribe?.();\n }\n}\n"]}
1
+ {"version":3,"file":"menus.js","sourceRoot":"","sources":["../src/menus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EACL,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,cAAc,GAGf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,GAGd,MAAM,eAAe,CAAC;;AA4BvB,MAAM,SAAS,GAAG,IAAI,OAAO,EAAsB,CAAC;AACpD,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,IAAI,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,KAAK,SAAS;QAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,C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,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC5B,CAAC;IAED,WAAW;QACT,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;IACvB,CAAC;uGAxPU,KAAK;wGAAL,KAAK;;2FAAL,KAAK;kBADjB,OAAO","sourcesContent":["/**\n * Menus and keyboard shortcuts as the host receives them: the menu bar, the shortcuts that are in\n * no menu, and the form a menu takes on its way to native, which a context menu shares.\n *\n * The host contract, on the `NgNativeMenus` module:\n * - `setMenuBar(groups)`: the whole merged menu bar, each time it changes. The desktop host draws\n * it as the main menu, iPadOS through UIMenuBuilder. Each item has an `id`; an item with a\n * `menuRole` and no `id`'s action is the OS's own (Copy, Quit).\n * - `setShortcuts(shortcuts)`: every shortcut the app listens for outside the menu bar, each with\n * its `id`, its chord read for the OS, and a `label` and `group` for Android's Keyboard Shortcuts\n * helper. On iPhone and Android the menu bar's own shortcuts are in it too, since no bar is drawn.\n * - It sends `ngNativeMenus` events on `DeviceEventEmitter`: `{ type: 'menuSelect', id }` for a menu\n * bar item, and `{ type: 'shortcut', id, textInputFocused }` for a chord pressed.\n * - Its constants say whether it draws a menu bar (`menuBar`) and the app's name (`appName`).\n * - On Android it is an Expo module: the constants are properties, it sends the same events through\n * its own `addListener('ngNativeMenus', ...)`, and it has `setContextMenu(nativeID, entries)`,\n * since React Native's Android view drops a `contextMenu` prop it does not know.\n * - On iOS it is a TurboModule with `setContextMenu(nativeID, entries)` too, for the same reason.\n * React Native's iOS view sends no event it does not know either, so the module sends the item\n * chosen as `{ type: 'contextMenuSelect', nativeID, id }`.\n * - Where it draws context menus, `setTakesLongPress(nativeID, takes)` names a view inside one\n * whose own `(longPress)` takes a long press first: a long press there opens no menu around it,\n * as the innermost handler wins in a native app. A right-click still opens the menu on Android.\n * iOS tells a long press from a secondary click only by the gesture, so an iPad pointer's\n * secondary click there opens none either.\n */\nimport {\n InjectionToken,\n Service,\n computed,\n effect,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport {\n defaultMenuBar,\n isSeparator,\n mergeMenuBar,\n unmergedGroups,\n type MenuEntry,\n type MenuGroupModel,\n} from './menu-model.ts';\nimport { injectOs } from './os.ts';\nimport { reactNative } from './react-native.ts';\nimport {\n isEditingShortcut,\n navigationShortcut,\n parseShortcut,\n type ParsedShortcut,\n type ShortcutOs,\n} from './shortcut.ts';\n\n/** A menu entry as the host receives it. */\nexport type NativeMenuEntry =\n | { readonly separator: true }\n | {\n readonly id: string;\n readonly label: string;\n readonly menuRole?: string;\n /** On an item with a `menuRole`: the app handles it, and the OS does not. */\n readonly handled?: true;\n readonly shortcut?: ParsedShortcut;\n readonly disabled?: boolean;\n readonly checked?: boolean;\n readonly destructive?: boolean;\n readonly subtitle?: string;\n readonly sfSymbol?: string;\n readonly icon?: string;\n readonly inline?: boolean;\n readonly items?: readonly NativeMenuEntry[];\n };\n\n/** A menu ready for the host, and what each id it was given does. */\nexport interface SerializedMenu {\n readonly entries: NativeMenuEntry[];\n readonly actions: ReadonlyMap<string, () => void>;\n}\n\nconst actionIds = new WeakMap<() => void, string>();\nlet actionsNamed = 0;\n\n/**\n * The id a menu item with `select` is sent under: the same for as long as the handler is, and no\n * other handler's. `<menu-item>` keeps one handler for its life, so a host that reports a choice\n * from a menu it drew before the items changed still runs that item, or nothing once it has gone,\n * never the item that has taken its place.\n */\nexport function menuActionId(select: () => void): string {\n let id = actionIds.get(select);\n if (id === undefined) actionIds.set(select, (id = `a${++actionsNamed}`));\n return id;\n}\n\n/**\n * `entries` as the host takes them: an id for each item, its shortcut read for `os`, and the\n * handlers by id. An item with a handler is named by it (`menuActionId`); one without, which the\n * app never runs, by its place (`2.0.1`).\n */\nexport function serializeMenu(\n entries: readonly MenuEntry[],\n os: ShortcutOs,\n prefix = '',\n): SerializedMenu {\n const actions = new Map<string, () => void>();\n const walk = (list: readonly MenuEntry[], at: string): NativeMenuEntry[] =>\n list.map((entry, index) => {\n if (isSeparator(entry)) return { separator: true };\n const place = `${at}${index}`;\n const { select, shortcut, items, group: _group, ...rest } = entry;\n const id = select ? menuActionId(select) : place;\n if (select) actions.set(id, select);\n return {\n id,\n ...rest,\n // A role item the app handles: the host sends its select rather than doing the role.\n ...(select && entry.menuRole && { handled: true }),\n ...(shortcut\n ? { shortcut: parseShortcut(shortcut, os) }\n : (entry.menuRole === 'back' || entry.menuRole === 'forward') && {\n shortcut: navigationShortcut(entry.menuRole, os),\n }),\n ...(items && { items: walk(items, `${place}.`) }),\n };\n });\n return { entries: walk(entries, prefix), actions };\n}\n\n/** A shortcut as the host receives it. */\nexport interface NativeShortcut {\n readonly id: string;\n readonly chord: ParsedShortcut;\n /** What Android's Keyboard Shortcuts helper lists it as. */\n readonly label: string;\n /** The heading it is listed under there: its menu's label, or the app's name. */\n readonly group: string;\n}\n\nexport type NativeMenuEvent =\n | { readonly type: 'menuSelect'; readonly id: string }\n | { readonly type: 'shortcut'; readonly id: string; readonly textInputFocused?: boolean }\n /** An item chosen in the context menu of the view with `nativeID` (iOS). */\n | { readonly type: 'contextMenuSelect'; readonly nativeID: string; readonly id: string }\n /**\n * Back or forward, from whichever input the OS has for it: View > Back and Forward and their\n * keys, a two-finger swipe, mouse buttons 4 and 5, the toolbar's chevrons and their history\n * menus. `surface` is the window it was in, and `steps` how many entries (one where absent).\n */\n | {\n readonly type: 'navigate';\n readonly direction: 'back' | 'forward';\n readonly surface?: number;\n readonly steps?: number;\n };\n\n/** A window's history as the host draws it: the titles behind and ahead, nearest first. */\nexport interface NativeWindowHistory {\n readonly back: readonly string[];\n readonly forward: readonly string[];\n}\n\n/** The host's menu module. */\nexport interface NativeMenus {\n /** Whether the host draws a menu bar: macOS, and iPadOS. */\n readonly menuBar: boolean;\n readonly appName: string;\n setMenuBar(\n groups: readonly { label: string; menuRole?: string; items: NativeMenuEntry[] }[],\n ): void;\n setShortcuts(shortcuts: readonly NativeShortcut[]): void;\n /** The history of the window on `surface`, for its back and forward chevrons. Desktop only. */\n setHistory?(surface: number, history: NativeWindowHistory): void;\n /**\n * The context menu of the view with `nativeID`, or null to take it away. Android and iOS, whose\n * views read no `contextMenu` prop: the host finds the view by its `nativeID`.\n */\n setContextMenu?(nativeID: string, entries: readonly NativeMenuEntry[] | null): void;\n /**\n * Whether the view with `nativeID` takes a long press itself, so a context menu around it does\n * not open on one there. Android and iOS, beside `setContextMenu`.\n */\n setTakesLongPress?(nativeID: string, takes: boolean): void;\n subscribe(listener: (event: NativeMenuEvent) => void): () => void;\n}\n\ninterface MenusModule {\n getConstants?(): { menuBar?: boolean; appName?: string };\n /** An Expo module's constants, which are its properties. */\n readonly menuBar?: boolean;\n readonly appName?: string;\n setMenuBar?(groups: unknown): void;\n setShortcuts?(shortcuts: unknown): void;\n setHistory?(surface: number, history: unknown): void;\n setContextMenu?(nativeID: string, entries: unknown): void;\n setTakesLongPress?(nativeID: string, takes: boolean): void;\n /** An Expo module's own events. */\n addListener?(event: string, listener: (event: unknown) => void): { remove(): void };\n}\n\n/** Android's `NgNativeMenus`, an Expo module, where React Native has no TurboModule of the name. */\nfunction expoMenusModule(): MenusModule | undefined {\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n return modules?.['NgNativeMenus'] as MenusModule | undefined;\n}\n\n/**\n * The host's menu module: a TurboModule (the desktop host, iOS), or else Android's Expo module.\n * Null where there is neither, as in Expo Go.\n */\nexport function menusSource(): NativeMenus | null {\n const native = reactNative();\n const turbo = native?.TurboModuleRegistry?.get?.('NgNativeMenus') as\n MenusModule | null | undefined;\n const expo = turbo ? undefined : expoMenusModule();\n const module = turbo ?? expo;\n if (!module) return null;\n const constants = module.getConstants?.() ?? module;\n // An Expo module sends its events itself; a TurboModule's come through DeviceEventEmitter.\n const listen = (hear: (event: unknown) => void) =>\n expo\n ? expo.addListener?.('ngNativeMenus', hear)\n : native?.DeviceEventEmitter?.addListener('ngNativeMenus', hear);\n return {\n menuBar: constants.menuBar === true,\n appName: constants.appName ?? '',\n setMenuBar: (groups) => module.setMenuBar?.(groups),\n setShortcuts: (shortcuts) => module.setShortcuts?.(shortcuts),\n setHistory: (surface, history) => module.setHistory?.(surface, history),\n ...contextMenuMethods(module),\n subscribe: (listener) => {\n const subscription = listen((event) => listener(event as NativeMenuEvent));\n return () => subscription?.remove();\n },\n };\n}\n\n/** The context menu methods a module has, bound, and none it lacks: a host without them reads props. */\nfunction contextMenuMethods(\n module: MenusModule,\n): Pick<NativeMenus, 'setContextMenu' | 'setTakesLongPress'> {\n const setContextMenu = module.setContextMenu?.bind(module);\n const setTakesLongPress = module.setTakesLongPress?.bind(module);\n return {\n ...(setContextMenu && { setContextMenu }),\n ...(setTakesLongPress && { setTakesLongPress }),\n };\n}\n\n/** A `[shortcut]` registered with `KeyboardShortcuts`. */\ninterface Registered {\n readonly shortcut: Signal<string>;\n readonly label: Signal<string>;\n readonly press: () => void;\n}\n\n/**\n * The menus and shortcuts an app has, sent to the host as they change. `<menu-bar>` and\n * `[shortcut]` in `@ng-native/components` register here; an app rarely injects it.\n */\n@Service()\nexport class Menus {\n /** Overridden in a test with a fake host. */\n static readonly SOURCE = new InjectionToken<NativeMenus | null>('angular-native.menusSource', {\n factory: menusSource,\n });\n\n private readonly native = inject(Menus.SOURCE);\n private readonly os: ShortcutOs = injectOs();\n\n /** Whether the host has the module: shortcuts from a hardware keyboard, and menus. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\n\n /** Whether the menu bar is drawn: macOS and iPadOS. Elsewhere its shortcuts still work. */\n readonly menuBarShown: Signal<boolean> = signal(this.native?.menuBar === true).asReadonly();\n\n /**\n * Whether the host takes a `[contextMenu]` by the view's `nativeID` through `setContextMenu`\n * (Android and iOS) rather than as the view's `contextMenu` prop. Where it does, it draws the\n * menu on a long press.\n */\n readonly contextMenuByNativeId: boolean = this.native?.setContextMenu !== undefined;\n\n /**\n * Whether the host, which draws context menus on a long press, can be told which views inside\n * one take a long press themselves (`setTakesLongPress`).\n */\n readonly longPressByNativeId: boolean =\n this.contextMenuByNativeId && this.native?.setTakesLongPress !== undefined;\n\n /**\n * Say whether the view with `nativeID` takes a long press itself: one there then opens no\n * context menu around it.\n */\n setTakesLongPress(nativeID: string, takes: boolean): void {\n if (takes) this.longPressTakers.add(nativeID);\n else this.longPressTakers.delete(nativeID);\n this.native?.setTakesLongPress?.(nativeID, takes);\n }\n\n /** The `nativeID`s sent with a context menu, and with a long press of their own. */\n private readonly withContextMenu = new Set<string>();\n private readonly longPressTakers = new Set<string>();\n\n /**\n * Whether the host opens a context menu on a long press of the view whose `nativeID`s, from it\n * outwards, are `chain`: as it decides, the nearest view with a menu, unless one on the way takes\n * the long press itself. A `(longPress)` around that view leaves the hold to the menu, which the\n * host opens after its own long-press timeout.\n */\n opensContextMenu(chain: Iterable<string | null>): boolean {\n for (const nativeID of chain) {\n if (nativeID === null) continue;\n if (this.withContextMenu.has(nativeID)) return true;\n if (this.longPressTakers.has(nativeID)) return false;\n }\n return false;\n }\n\n /** What choosing an item does, by the `nativeID` of the view whose menu it is in. */\n private readonly contextMenuChoices = new Map<string, (id: string) => void>();\n\n /**\n * Send the context menu of the view with `nativeID`, or null to take it away. `choose` runs with\n * the item's `id` where the host sends the choice itself (iOS) rather than through the view.\n */\n setContextMenu(\n nativeID: string,\n entries: readonly NativeMenuEntry[] | null,\n choose?: (id: string) => void,\n ): void {\n if (entries && choose) this.contextMenuChoices.set(nativeID, choose);\n else this.contextMenuChoices.delete(nativeID);\n if (entries?.length) this.withContextMenu.add(nativeID);\n else this.withContextMenu.delete(nativeID);\n this.native?.setContextMenu?.(nativeID, entries);\n }\n\n private readonly bars = signal<readonly Signal<readonly MenuEntry[]>[]>([]);\n private readonly shortcuts = signal<readonly Registered[]>([]);\n\n /** The app's groups, from every `<menu-bar>`, in the order they registered. */\n private readonly appGroups = computed<MenuGroupModel[]>(() =>\n this.bars()\n .flatMap((bar) => bar())\n .flatMap((entry) =>\n isSeparator(entry)\n ? []\n : [\n {\n label: entry.label,\n ...(entry.group && { menuRole: entry.group }),\n items: entry.items ?? [],\n },\n ],\n ),\n );\n\n /** The menu bar as it is drawn: the OS's defaults with the app's merged in. */\n readonly menuBar: Signal<MenuGroupModel[]> = computed(() =>\n mergeMenuBar(defaultMenuBar(this.native?.appName || 'App'), this.appGroups()),\n );\n\n private readonly sentBar = computed(() => {\n const groups = this.menuBar();\n const actions = new Map<string, () => void>();\n const sent = groups.map((group, index) => {\n const menu = serializeMenu(group.items, this.os, `${index}.`);\n menu.actions.forEach((action, id) => actions.set(id, action));\n return {\n label: group.label,\n ...(group.menuRole && { menuRole: group.menuRole }),\n items: menu.entries,\n };\n });\n return { sent, actions };\n });\n\n /**\n * The shortcuts sent to the host: every `[shortcut]`, and where no menu bar is drawn, every\n * menu bar item the app gave a shortcut and a handler, so a hardware keyboard still has them.\n */\n private readonly sentShortcuts = computed(() => {\n const presses = new Map<string, () => void>();\n const editing = new Set<string>();\n const sent: NativeShortcut[] = [];\n const add = (id: string, shortcut: string, label: string, group: string, press: () => void) => {\n presses.set(id, press);\n if (isEditingShortcut(shortcut, this.os)) editing.add(id);\n sent.push({ id, chord: parseShortcut(shortcut, this.os), label, group });\n };\n this.shortcuts().forEach((one, index) =>\n add(`s${index}`, one.shortcut(), one.label(), this.native?.appName || 'App', one.press),\n );\n if (!this.menuBarShown()) {\n const walk = (entries: readonly MenuEntry[], group: string, at: string) =>\n entries.forEach((entry, index) => {\n if (isSeparator(entry)) return;\n if (entry.shortcut && entry.select && !entry.disabled) {\n add(`m${at}${index}`, entry.shortcut, entry.label, group, entry.select);\n }\n if (entry.items) walk(entry.items, group, `${at}${index}.`);\n });\n this.appGroups().forEach((group, index) => walk(group.items, group.label, `${index}.`));\n }\n return { sent, presses, editing };\n });\n\n private readonly unsubscribe = this.native?.subscribe((event) => this.hostSaid(event)) ?? null;\n\n constructor() {\n // Once a label: a `<menu-group label=\"File\">` with no role that is still a group of its own\n // once merged is drawn as a second File menu, on a host that draws a menu bar.\n const warned = new Set<string>();\n effect(() => {\n if (!this.menuBarShown()) return;\n const defaults = defaultMenuBar(this.native?.appName || 'App');\n for (const label of unmergedGroups(defaults, this.menuBar())) {\n if (warned.has(label)) continue;\n warned.add(label);\n const role = defaults.find(\n (group) => group.label.toLowerCase() === label.toLowerCase(),\n )?.menuRole;\n console.warn(\n `[angular-native] <menu-group label=\"${label}\"> has no menuRole, so it shows as a second ` +\n `${label} menu. Give it menuRole=\"${role}\" to add its items to the ${label} menu.`,\n );\n }\n });\n const native = this.native;\n if (!native) {\n // Read for nothing, so a shortcut the app gets wrong throws where there is no host too, and\n // not first on a device that has one.\n effect(() => this.sentShortcuts());\n return;\n }\n effect(() => {\n if (this.menuBarShown()) native.setMenuBar(this.sentBar().sent);\n });\n effect(() => native.setShortcuts(this.sentShortcuts().sent));\n }\n\n /**\n * Add a `<menu-bar>`'s groups, each a `MenuItemModel` with `items` and its `group` role. Answers\n * the function that takes them out again, as the `<menu-bar>` goes.\n */\n addMenuBar(groups: Signal<readonly MenuEntry[]>): () => void {\n this.bars.update((all) => [...all, groups]);\n return () => this.bars.update((all) => all.filter((one) => one !== groups));\n }\n\n /**\n * Listen for `shortcut`, pressed anywhere in the app: `mod+k`, as `parseShortcut` reads it.\n * `label` is what Android's Keyboard Shortcuts helper lists it as. Answers the function that\n * stops listening.\n */\n addShortcut(shortcut: Signal<string>, label: Signal<string>, press: () => void): () => void {\n const registered: Registered = { shortcut, label, press };\n this.shortcuts.update((all) => [...all, registered]);\n return () => this.shortcuts.update((all) => all.filter((one) => one !== registered));\n }\n\n private readonly navigators = new Set<\n (direction: 'back' | 'forward', surface?: number, steps?: number) => void\n >();\n\n /**\n * Hear the OS's back and forward commands. `@ng-native/router` listens, and moves through the\n * history of the window each was in, `steps` entries (one, but for a pick from a chevron's\n * history menu). Answers the function that stops listening.\n */\n onNavigate(\n listener: (direction: 'back' | 'forward', surface?: number, steps?: number) => void,\n ): () => void {\n this.navigators.add(listener);\n return () => void this.navigators.delete(listener);\n }\n\n /**\n * Tell the host the history of the window on `surface`, which its toolbar's back and forward\n * chevrons and their menus show. `@ng-native/router` calls it. Does nothing where the host has\n * no chevrons.\n */\n setHistory(surface: number, history: NativeWindowHistory): void {\n this.native?.setHistory?.(surface, history);\n }\n\n private hostSaid(event: NativeMenuEvent): void {\n if (event.type === 'navigate') {\n const steps = event.steps ?? 1;\n this.navigators.forEach((listener) => listener(event.direction, event.surface, steps));\n return;\n }\n if (event.type === 'menuSelect') {\n this.sentBar().actions.get(event.id)?.();\n return;\n }\n if (event.type === 'contextMenuSelect') {\n this.contextMenuChoices.get(event.nativeID)?.(event.id);\n return;\n }\n const { presses, editing } = this.sentShortcuts();\n // The editing keys belong to a focused text input: the app's shortcut on one waits.\n if (event.textInputFocused && editing.has(event.id)) return;\n presses.get(event.id)?.();\n }\n\n ngOnDestroy(): void {\n this.unsubscribe?.();\n }\n}\n"]}
package/dist/os.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  import { InjectionToken } from '@angular/core';
2
+ /**
3
+ * Every OS Angular Native runs on, as `Platform.OS` and the `OS` token name it. The one list the
4
+ * OS types and checks derive from (`OS`, `ShortcutOs`, `TestOs`, `ModulePlatform`), so a new OS is
5
+ * one entry here.
6
+ */
7
+ export declare const OS_NAMES: readonly ["ios", "android", "macos", "web"];
8
+ /** One of `OS_NAMES`: what the `OS` token answers. */
9
+ export type OsName = (typeof OS_NAMES)[number];
10
+ /** Whether `os` is one of `OS_NAMES`. */
11
+ export declare const isOsName: (os: unknown) => os is OsName;
2
12
  /**
3
13
  * The operating system the app runs on: `Platform.OS` on a device, `'macos'` on a Mac, and `'web'`
4
14
  * in the web host, which provides it. Off a device, in a test in Node, it is the platform the engine
@@ -9,13 +19,17 @@ import { InjectionToken } from '@angular/core';
9
19
  * too. A test provides the OS it wants.
10
20
  */
11
21
  export declare const OS: InjectionToken<"ios" | "android" | "macos" | "web">;
12
- /** The OS as React Native, or off a device the engine, reports it: what `OS` answers unprovided. */
13
- export declare function platformOs(): 'ios' | 'android' | 'macos' | 'web';
22
+ /**
23
+ * The OS as React Native, or off a device the engine, reports it: what `OS` answers unprovided.
24
+ * Throws on an OS not in `OS_NAMES`, which no check in the packages was written for: read as iOS,
25
+ * as it once was, it would take iOS's shortcuts, sources and layout with no sign of why.
26
+ */
27
+ export declare function platformOs(): OsName;
14
28
  /**
15
29
  * The `OS` a service is made under: the one provided, or, in an injector with no root to make it
16
30
  * in, the platform's own.
17
31
  */
18
- export declare const injectOs: () => "ios" | "android" | "macos" | "web";
32
+ export declare const injectOs: () => OsName;
19
33
  /** Whether `os` is a phone and tablet OS, with a status bar and a software keyboard. */
20
34
  export declare const isPhoneOs: (os: string) => boolean;
21
35
  /**
package/dist/os.js CHANGED
@@ -1,6 +1,14 @@
1
1
  import { InjectionToken, inject } from '@angular/core';
2
2
  import { nativePlatform } from '@ng-native/fabric';
3
3
  import { reactNative } from "./react-native.js";
4
+ /**
5
+ * Every OS Angular Native runs on, as `Platform.OS` and the `OS` token name it. The one list the
6
+ * OS types and checks derive from (`OS`, `ShortcutOs`, `TestOs`, `ModulePlatform`), so a new OS is
7
+ * one entry here.
8
+ */
9
+ export const OS_NAMES = ['ios', 'android', 'macos', 'web'];
10
+ /** Whether `os` is one of `OS_NAMES`. */
11
+ export const isOsName = (os) => OS_NAMES.includes(os);
4
12
  /**
5
13
  * The operating system the app runs on: `Platform.OS` on a device, `'macos'` on a Mac, and `'web'`
6
14
  * in the web host, which provides it. Off a device, in a test in Node, it is the platform the engine
@@ -13,10 +21,17 @@ import { reactNative } from "./react-native.js";
13
21
  export const OS = new InjectionToken('angular-native.os', {
14
22
  factory: platformOs,
15
23
  });
16
- /** The OS as React Native, or off a device the engine, reports it: what `OS` answers unprovided. */
24
+ /**
25
+ * The OS as React Native, or off a device the engine, reports it: what `OS` answers unprovided.
26
+ * Throws on an OS not in `OS_NAMES`, which no check in the packages was written for: read as iOS,
27
+ * as it once was, it would take iOS's shortcuts, sources and layout with no sign of why.
28
+ */
17
29
  export function platformOs() {
18
30
  const os = reactNative()?.Platform?.OS ?? nativePlatform();
19
- return os === 'android' || os === 'macos' || os === 'web' ? os : 'ios';
31
+ if (isOsName(os))
32
+ return os;
33
+ throw new Error(`[angular-native] The platform reports the OS '${os}', which Angular Native does not run on. ` +
34
+ `It runs on ${OS_NAMES.join(', ')}.`);
20
35
  }
21
36
  /**
22
37
  * The `OS` a service is made under: the one provided, or, in an injector with no root to make it
package/dist/os.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"os.js","sourceRoot":"","sources":["../src/os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,cAAc,CAAsC,mBAAmB,EAAE;IAC7F,OAAO,EAAE,UAAU;CACpB,CAAC,CAAC;AAEH,oGAAoG;AACpG,MAAM,UAAU,UAAU;IACxB,MAAM,EAAE,GAAG,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,cAAc,EAAE,CAAC;IAC3D,OAAO,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AACzE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAwC,EAAE,CAChE,MAAM,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC;AAEjD,wFAAwF;AACxF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,SAAS,CAAC;AAEnF;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAU,wBAAwB,EAAE;IAC3E,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO;CACtC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,cAAc,CAAU,sBAAsB,EAAE;IACvE,OAAO,EAAE,GAAG,EAAE;QACZ,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QACtB,OAAO,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,OAAO,CAAC;IACxC,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { InjectionToken, inject } from '@angular/core';\nimport { nativePlatform } from '@ng-native/fabric';\nimport { reactNative } from './react-native.ts';\n\n/**\n * The operating system the app runs on: `Platform.OS` on a device, `'macos'` on a Mac, and `'web'`\n * in the web host, which provides it. Off a device, in a test in Node, it is the platform the engine\n * renders as, iOS unless `registerPlatformComponents` said otherwise.\n *\n * For a feature that depends on the platform, beside `OS_VERSION`, whose number is the API level\n * on Android and the macOS major on a Mac: a check for iOS 26 needs both, or it matches macOS 26\n * too. A test provides the OS it wants.\n */\nexport const OS = new InjectionToken<'ios' | 'android' | 'macos' | 'web'>('angular-native.os', {\n factory: platformOs,\n});\n\n/** The OS as React Native, or off a device the engine, reports it: what `OS` answers unprovided. */\nexport function platformOs(): 'ios' | 'android' | 'macos' | 'web' {\n const os = reactNative()?.Platform?.OS ?? nativePlatform();\n return os === 'android' || os === 'macos' || os === 'web' ? os : 'ios';\n}\n\n/**\n * The `OS` a service is made under: the one provided, or, in an injector with no root to make it\n * in, the platform's own.\n */\nexport const injectOs = (): 'ios' | 'android' | 'macos' | 'web' =>\n inject(OS, { optional: true }) ?? platformOs();\n\n/** Whether `os` is a phone and tablet OS, with a status bar and a software keyboard. */\nexport const isPhoneOs = (os: string): boolean => os === 'ios' || os === 'android';\n\n/**\n * Whether the app runs on a desktop OS: macOS today. Worked out from `OS`, so the two cannot\n * disagree, and a test that provides `OS` gets the answer that goes with it.\n */\nexport const DESKTOP = new InjectionToken<boolean>('angular-native.desktop', {\n factory: () => inject(OS) === 'macos',\n});\n\n/**\n * Whether the app runs on one of Apple's OSes: iOS (iPadOS included) or macOS. For a check that\n * Apple's OSes share, written as `inject(APPLE)` rather than `OS === 'ios'`, which a Mac fails.\n * Worked out from `OS`, as `DESKTOP` is.\n */\nexport const APPLE = new InjectionToken<boolean>('angular-native.apple', {\n factory: () => {\n const os = inject(OS);\n return os === 'ios' || os === 'macos';\n },\n});\n"]}
1
+ {"version":3,"file":"os.js","sourceRoot":"","sources":["../src/os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAU,CAAC;AAKpE,yCAAyC;AACzC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAW,EAAgB,EAAE,CACnD,QAA+B,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,cAAc,CAAS,mBAAmB,EAAE;IAChE,OAAO,EAAE,UAAU;CACpB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,EAAE,GAAG,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,cAAc,EAAE,CAAC;IAC3D,IAAI,QAAQ,CAAC,EAAE,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5B,MAAM,IAAI,KAAK,CACb,iDAAiD,EAAE,2CAA2C;QAC5F,cAAc,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACvC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAW,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC;AAErF,wFAAwF;AACxF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,SAAS,CAAC;AAEnF;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAU,wBAAwB,EAAE;IAC3E,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO;CACtC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,cAAc,CAAU,sBAAsB,EAAE;IACvE,OAAO,EAAE,GAAG,EAAE;QACZ,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QACtB,OAAO,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,OAAO,CAAC;IACxC,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { InjectionToken, inject } from '@angular/core';\nimport { nativePlatform } from '@ng-native/fabric';\nimport { reactNative } from './react-native.ts';\n\n/**\n * Every OS Angular Native runs on, as `Platform.OS` and the `OS` token name it. The one list the\n * OS types and checks derive from (`OS`, `ShortcutOs`, `TestOs`, `ModulePlatform`), so a new OS is\n * one entry here.\n */\nexport const OS_NAMES = ['ios', 'android', 'macos', 'web'] as const;\n\n/** One of `OS_NAMES`: what the `OS` token answers. */\nexport type OsName = (typeof OS_NAMES)[number];\n\n/** Whether `os` is one of `OS_NAMES`. */\nexport const isOsName = (os: unknown): os is OsName =>\n (OS_NAMES as readonly unknown[]).includes(os);\n\n/**\n * The operating system the app runs on: `Platform.OS` on a device, `'macos'` on a Mac, and `'web'`\n * in the web host, which provides it. Off a device, in a test in Node, it is the platform the engine\n * renders as, iOS unless `registerPlatformComponents` said otherwise.\n *\n * For a feature that depends on the platform, beside `OS_VERSION`, whose number is the API level\n * on Android and the macOS major on a Mac: a check for iOS 26 needs both, or it matches macOS 26\n * too. A test provides the OS it wants.\n */\nexport const OS = new InjectionToken<OsName>('angular-native.os', {\n factory: platformOs,\n});\n\n/**\n * The OS as React Native, or off a device the engine, reports it: what `OS` answers unprovided.\n * Throws on an OS not in `OS_NAMES`, which no check in the packages was written for: read as iOS,\n * as it once was, it would take iOS's shortcuts, sources and layout with no sign of why.\n */\nexport function platformOs(): OsName {\n const os = reactNative()?.Platform?.OS ?? nativePlatform();\n if (isOsName(os)) return os;\n throw new Error(\n `[angular-native] The platform reports the OS '${os}', which Angular Native does not run on. ` +\n `It runs on ${OS_NAMES.join(', ')}.`,\n );\n}\n\n/**\n * The `OS` a service is made under: the one provided, or, in an injector with no root to make it\n * in, the platform's own.\n */\nexport const injectOs = (): OsName => inject(OS, { optional: true }) ?? platformOs();\n\n/** Whether `os` is a phone and tablet OS, with a status bar and a software keyboard. */\nexport const isPhoneOs = (os: string): boolean => os === 'ios' || os === 'android';\n\n/**\n * Whether the app runs on a desktop OS: macOS today. Worked out from `OS`, so the two cannot\n * disagree, and a test that provides `OS` gets the answer that goes with it.\n */\nexport const DESKTOP = new InjectionToken<boolean>('angular-native.desktop', {\n factory: () => inject(OS) === 'macos',\n});\n\n/**\n * Whether the app runs on one of Apple's OSes: iOS (iPadOS included) or macOS. For a check that\n * Apple's OSes share, written as `inject(APPLE)` rather than `OS === 'ios'`, which a Mac fails.\n * Worked out from `OS`, as `DESKTOP` is.\n */\nexport const APPLE = new InjectionToken<boolean>('angular-native.apple', {\n factory: () => {\n const os = inject(OS);\n return os === 'ios' || os === 'macos';\n },\n});\n"]}
@@ -4,8 +4,9 @@
4
4
  * serves every OS. The matching and the text-input rule are here, in TypeScript, so the desktop
5
5
  * host, iOS hardware keyboards and Android's key-shortcut dispatch all follow the same rules.
6
6
  */
7
+ import type { OsName } from './os.ts';
7
8
  /** The OSes a shortcut is read on, as the `OS` token names them. */
8
- export type ShortcutOs = 'ios' | 'android' | 'macos' | 'web';
9
+ export type ShortcutOs = OsName;
9
10
  /** A key pressed with its modifiers, as a key event reports it. */
10
11
  export interface KeyChord {
11
12
  /** The key, as `KeyboardEvent.key` names it: `s`, `,`, `ArrowLeft`, `[`. */
@@ -1 +1 @@
1
- {"version":3,"file":"shortcut.js","sourceRoot":"","sources":["../src/shortcut.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0BH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAEpF,0DAA0D;AAC1D,MAAM,KAAK,GAAG,CAAC,EAAc,EAAW,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,OAAO,CAAC;AAE1E;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,EAAc;IAC5D,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG;QAC/C,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/D,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7C,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,KAA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AAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC;IACxD,OAAO,CAAC,CAAC,gBAAgB,IAAI,iBAAiB,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAA6B,EAAE,EAAc;IAC9E,IAAI,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;QACd,OAAO;YACL,GAAG,EAAE,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG;YACrC,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,KAAK;YACV,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;IAC9D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACpE,CAAC","sourcesContent":["/**\n * Keyboard shortcuts, as `<menu-item shortcut>` and `[shortcut]` write them: `mod+s`,\n * `mod+shift+k`, `mod+,`. `mod` is Cmd on Apple's OSes and Ctrl everywhere else, so one string\n * serves every OS. The matching and the text-input rule are here, in TypeScript, so the desktop\n * host, iOS hardware keyboards and Android's key-shortcut dispatch all follow the same rules.\n */\n\n/** The OSes a shortcut is read on, as the `OS` token names them. */\nexport type ShortcutOs = 'ios' | 'android' | 'macos' | 'web';\n\n/** A key pressed with its modifiers, as a key event reports it. */\nexport interface KeyChord {\n /** The key, as `KeyboardEvent.key` names it: `s`, `,`, `ArrowLeft`, `[`. */\n readonly key: string;\n /** Cmd on a Mac or an iPad keyboard, the Windows or Meta key elsewhere. */\n readonly meta?: boolean;\n readonly ctrl?: boolean;\n /** Option on a Mac. */\n readonly alt?: boolean;\n readonly shift?: boolean;\n}\n\n/** A shortcut read for one OS: the key, lower case, and exactly the modifiers it needs. */\nexport interface ParsedShortcut {\n readonly key: string;\n readonly meta: boolean;\n readonly ctrl: boolean;\n readonly alt: boolean;\n readonly shift: boolean;\n}\n\nconst MODIFIERS = new Set(['mod', 'cmd', 'meta', 'ctrl', 'alt', 'option', 'shift']);\n\n/** Whether `os` is one of Apple's, where `mod` is Cmd. */\nconst apple = (os: ShortcutOs): boolean => os === 'ios' || os === 'macos';\n\n/**\n * A shortcut read for `os`. Throws on one that names no key or a modifier it does not know, since\n * that is a mistake in the app, not something a user can press.\n */\nexport function parseShortcut(shortcut: string, os: ShortcutOs): ParsedShortcut {\n const { key, held } = split(shortcut);\n const mod = held.has('mod');\n return {\n key: key.length === 1 ? key.toLowerCase() : key,\n meta: held.has('cmd') || held.has('meta') || (mod && apple(os)),\n ctrl: held.has('ctrl') || (mod && !apple(os)),\n alt: held.has('alt') || held.has('option'),\n shift: held.has('shift'),\n };\n}\n\n/** A shortcut's key and the modifiers it names, checked. */\nfunction split(shortcut: string): { key: string; held: Set<string> } {\n // A trailing `+` is the plus key itself: `mod++`.\n const parts = shortcut.endsWith('++')\n ? [...shortcut.slice(0, -2).split('+'), '+']\n : shortcut.split('+');\n const key = parts.pop() ?? '';\n const held = new Set(parts.map((part) => part.trim().toLowerCase()));\n for (const modifier of held) {\n if (!MODIFIERS.has(modifier)) {\n throw new Error(`[angular-native] '${shortcut}' has no modifier '${modifier}'.`);\n }\n }\n if (!key || MODIFIERS.has(key.toLowerCase())) {\n throw new Error(`[angular-native] '${shortcut}' names no key to press.`);\n }\n return { key, held };\n}\n\n/** Whether pressing `chord` on `os` is `shortcut`: the same key, and exactly its modifiers. */\nexport function matchesShortcut(shortcut: string, chord: KeyChord, os: ShortcutOs): boolean {\n const wanted = parseShortcut(shortcut, os);\n const key = chord.key.length === 1 ? chord.key.toLowerCase() : chord.key;\n return (\n key === wanted.key &&\n Boolean(chord.meta) === wanted.meta &&\n Boolean(chord.ctrl) === wanted.ctrl &&\n Boolean(chord.alt) === wanted.alt &&\n Boolean(chord.shift) === wanted.shift\n );\n}\n\n/** The editing keys a focused text input owns: undo, cut, copy, paste and select all. */\nconst EDITING = ['mod+z', 'mod+x', 'mod+c', 'mod+v', 'mod+a'];\n\n/** Whether `shortcut` is one of the editing keys a focused text input owns on `os`. */\nexport function isEditingShortcut(shortcut: string, os: ShortcutOs): boolean {\n const parsed = parseShortcut(shortcut, os);\n return EDITING.some((editing) => {\n const own = parseShortcut(editing, os);\n return (Object.keys(own) as (keyof ParsedShortcut)[]).every((k) => own[k] === parsed[k]);\n });\n}\n\n/**\n * Whether an app's `shortcut` fires for `chord`. It fires when the chord matches, except that the\n * editing keys (mod+z, x, c, v and a) go to a focused text input, so an app's shortcut on one of\n * them fires only while no text input has focus. Every other shortcut fires wherever focus is, as\n * a menu's key equivalents do.\n */\nexport function shortcutFires(\n shortcut: string,\n chord: KeyChord,\n os: ShortcutOs,\n textInputFocused: boolean,\n): boolean {\n if (!matchesShortcut(shortcut, chord, os)) return false;\n return !(textInputFocused && isEditingShortcut(shortcut, os));\n}\n\n/**\n * The back and forward keys on `os`: a shortcut role rather than a `mod` chord, since each OS has\n * its own. Cmd-[ and Cmd-] on macOS and iPadOS keyboards (Cmd-Left stays with text editing), and\n * Alt-Left and Alt-Right elsewhere, as Windows, Linux and Android browsers have them.\n */\nexport function navigationShortcut(direction: 'back' | 'forward', os: ShortcutOs): ParsedShortcut {\n if (apple(os)) {\n return {\n key: direction === 'back' ? '[' : ']',\n meta: true,\n ctrl: false,\n alt: false,\n shift: false,\n };\n }\n const key = direction === 'back' ? 'ArrowLeft' : 'ArrowRight';\n return { key, meta: false, ctrl: false, alt: true, shift: false };\n}\n"]}
1
+ {"version":3,"file":"shortcut.js","sourceRoot":"","sources":["../src/shortcut.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4BH,MAAM,SAAS,GAAG,IAAI,GAAG,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CAAC,CAAC,CAAC,GAAG;YACrC,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,KAAK;YACV,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;IAC9D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACpE,CAAC","sourcesContent":["/**\n * Keyboard shortcuts, as `<menu-item shortcut>` and `[shortcut]` write them: `mod+s`,\n * `mod+shift+k`, `mod+,`. `mod` is Cmd on Apple's OSes and Ctrl everywhere else, so one string\n * serves every OS. The matching and the text-input rule are here, in TypeScript, so the desktop\n * host, iOS hardware keyboards and Android's key-shortcut dispatch all follow the same rules.\n */\n\nimport type { OsName } from './os.ts';\n\n/** The OSes a shortcut is read on, as the `OS` token names them. */\nexport type ShortcutOs = OsName;\n\n/** A key pressed with its modifiers, as a key event reports it. */\nexport interface KeyChord {\n /** The key, as `KeyboardEvent.key` names it: `s`, `,`, `ArrowLeft`, `[`. */\n readonly key: string;\n /** Cmd on a Mac or an iPad keyboard, the Windows or Meta key elsewhere. */\n readonly meta?: boolean;\n readonly ctrl?: boolean;\n /** Option on a Mac. */\n readonly alt?: boolean;\n readonly shift?: boolean;\n}\n\n/** A shortcut read for one OS: the key, lower case, and exactly the modifiers it needs. */\nexport interface ParsedShortcut {\n readonly key: string;\n readonly meta: boolean;\n readonly ctrl: boolean;\n readonly alt: boolean;\n readonly shift: boolean;\n}\n\nconst MODIFIERS = new Set(['mod', 'cmd', 'meta', 'ctrl', 'alt', 'option', 'shift']);\n\n/** Whether `os` is one of Apple's, where `mod` is Cmd. */\nconst apple = (os: ShortcutOs): boolean => os === 'ios' || os === 'macos';\n\n/**\n * A shortcut read for `os`. Throws on one that names no key or a modifier it does not know, since\n * that is a mistake in the app, not something a user can press.\n */\nexport function parseShortcut(shortcut: string, os: ShortcutOs): ParsedShortcut {\n const { key, held } = split(shortcut);\n const mod = held.has('mod');\n return {\n key: key.length === 1 ? key.toLowerCase() : key,\n meta: held.has('cmd') || held.has('meta') || (mod && apple(os)),\n ctrl: held.has('ctrl') || (mod && !apple(os)),\n alt: held.has('alt') || held.has('option'),\n shift: held.has('shift'),\n };\n}\n\n/** A shortcut's key and the modifiers it names, checked. */\nfunction split(shortcut: string): { key: string; held: Set<string> } {\n // A trailing `+` is the plus key itself: `mod++`.\n const parts = shortcut.endsWith('++')\n ? [...shortcut.slice(0, -2).split('+'), '+']\n : shortcut.split('+');\n const key = parts.pop() ?? '';\n const held = new Set(parts.map((part) => part.trim().toLowerCase()));\n for (const modifier of held) {\n if (!MODIFIERS.has(modifier)) {\n throw new Error(`[angular-native] '${shortcut}' has no modifier '${modifier}'.`);\n }\n }\n if (!key || MODIFIERS.has(key.toLowerCase())) {\n throw new Error(`[angular-native] '${shortcut}' names no key to press.`);\n }\n return { key, held };\n}\n\n/** Whether pressing `chord` on `os` is `shortcut`: the same key, and exactly its modifiers. */\nexport function matchesShortcut(shortcut: string, chord: KeyChord, os: ShortcutOs): boolean {\n const wanted = parseShortcut(shortcut, os);\n const key = chord.key.length === 1 ? chord.key.toLowerCase() : chord.key;\n return (\n key === wanted.key &&\n Boolean(chord.meta) === wanted.meta &&\n Boolean(chord.ctrl) === wanted.ctrl &&\n Boolean(chord.alt) === wanted.alt &&\n Boolean(chord.shift) === wanted.shift\n );\n}\n\n/** The editing keys a focused text input owns: undo, cut, copy, paste and select all. */\nconst EDITING = ['mod+z', 'mod+x', 'mod+c', 'mod+v', 'mod+a'];\n\n/** Whether `shortcut` is one of the editing keys a focused text input owns on `os`. */\nexport function isEditingShortcut(shortcut: string, os: ShortcutOs): boolean {\n const parsed = parseShortcut(shortcut, os);\n return EDITING.some((editing) => {\n const own = parseShortcut(editing, os);\n return (Object.keys(own) as (keyof ParsedShortcut)[]).every((k) => own[k] === parsed[k]);\n });\n}\n\n/**\n * Whether an app's `shortcut` fires for `chord`. It fires when the chord matches, except that the\n * editing keys (mod+z, x, c, v and a) go to a focused text input, so an app's shortcut on one of\n * them fires only while no text input has focus. Every other shortcut fires wherever focus is, as\n * a menu's key equivalents do.\n */\nexport function shortcutFires(\n shortcut: string,\n chord: KeyChord,\n os: ShortcutOs,\n textInputFocused: boolean,\n): boolean {\n if (!matchesShortcut(shortcut, chord, os)) return false;\n return !(textInputFocused && isEditingShortcut(shortcut, os));\n}\n\n/**\n * The back and forward keys on `os`: a shortcut role rather than a `mod` chord, since each OS has\n * its own. Cmd-[ and Cmd-] on macOS and iPadOS keyboards (Cmd-Left stays with text editing), and\n * Alt-Left and Alt-Right elsewhere, as Windows, Linux and Android browsers have them.\n */\nexport function navigationShortcut(direction: 'back' | 'forward', os: ShortcutOs): ParsedShortcut {\n if (apple(os)) {\n return {\n key: direction === 'back' ? '[' : ']',\n meta: true,\n ctrl: false,\n alt: false,\n shift: false,\n };\n }\n const key = direction === 'back' ? 'ArrowLeft' : 'ArrowRight';\n return { key, meta: false, ctrl: false, alt: true, shift: false };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/device",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Angular Native device services: keyboard, screen, color scheme, app state, accessibility, hardware back and deep links.",
5
5
  "keywords": [
6
6
  "angular",
@@ -17,7 +17,7 @@
17
17
  "type": "module",
18
18
  "main": "dist/index.js",
19
19
  "dependencies": {
20
- "@ng-native/fabric": "0.25.0"
20
+ "@ng-native/fabric": "0.26.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@angular/core": "^22.0.0",