ember-nativescript 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +6 -1
  2. package/dist/components/RouteError.d.ts +8 -0
  3. package/dist/components/RouteError.d.ts.map +1 -0
  4. package/dist/components/RouteError.js +13 -0
  5. package/dist/components/RouteError.js.map +1 -0
  6. package/dist/src/application-entry.d.ts +4 -0
  7. package/dist/src/application-entry.d.ts.map +1 -0
  8. package/dist/src/application-entry.js +4 -0
  9. package/dist/src/application-testing.d.ts +19 -0
  10. package/dist/src/application-testing.d.ts.map +1 -0
  11. package/dist/src/application-testing.js +32 -0
  12. package/dist/src/application-testing.js.map +1 -0
  13. package/dist/src/application.d.ts +45 -0
  14. package/dist/src/application.d.ts.map +1 -0
  15. package/dist/src/application.js +136 -0
  16. package/dist/src/application.js.map +1 -0
  17. package/dist/src/nativescript-application.d.ts +8 -0
  18. package/dist/src/nativescript-application.d.ts.map +1 -0
  19. package/dist/src/nativescript-application.js +23 -0
  20. package/dist/src/nativescript-application.js.map +1 -0
  21. package/dist/src/testing.d.ts +2 -0
  22. package/dist/src/testing.d.ts.map +1 -1
  23. package/dist/src/testing.js +7 -2
  24. package/dist/src/testing.js.map +1 -1
  25. package/dist/src/web-adapter.d.ts +1 -1
  26. package/dist/src/web-adapter.d.ts.map +1 -1
  27. package/dist/src/web-adapter.js +6 -43
  28. package/dist/src/web-adapter.js.map +1 -1
  29. package/dist/src/web-app.d.ts +6 -0
  30. package/dist/src/web-app.d.ts.map +1 -1
  31. package/dist/src/web-app.js +26 -18
  32. package/dist/src/web-app.js.map +1 -1
  33. package/dist/src/web-application.d.ts +10 -0
  34. package/dist/src/web-application.d.ts.map +1 -0
  35. package/dist/src/web-application.js +37 -0
  36. package/dist/src/web-application.js.map +1 -0
  37. package/dist/src/web-host.d.ts +9 -2
  38. package/dist/src/web-host.d.ts.map +1 -1
  39. package/dist/src/web-host.js +10 -3
  40. package/dist/src/web-host.js.map +1 -1
  41. package/dist/src/web-list.d.ts +18 -0
  42. package/dist/src/web-list.d.ts.map +1 -0
  43. package/dist/src/web-list.js +224 -0
  44. package/dist/src/web-list.js.map +1 -0
  45. package/dist/src/web-styles.d.ts +1 -1
  46. package/dist/src/web-styles.d.ts.map +1 -1
  47. package/dist/src/web-styles.js +6 -3
  48. package/dist/src/web-styles.js.map +1 -1
  49. package/package.json +11 -2
@@ -1 +1 @@
1
- {"version":3,"file":"web-adapter.js","names":[],"sources":["../../src/web-adapter.ts"],"sourcesContent":["// The adapter that shows an app's screens in a browser: each NativeScript view is an HTML element with the class\n// `ns-<tag>` (a stackLayout is a flex column, a gridLayout a CSS grid, a textField an <input>), its properties set as\n// the element's attributes and styles, and NativeScript's events (tap, textChange, checkedChange…) raised from DOM\n// events with the data NativeScript gives them.\n//\n// The layout follows NativeScript's rules where CSS has a match: sizes in device-independent pixels are CSS pixels,\n// GridLayout's `*` is `fr`, children of a layout stretch unless aligned. web-styles.ts holds the CSS that does it.\n// What has no match yet (DockLayout, pan and pinch, a recycling list) is approximated or left out; see the spike notes.\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport type { FrameHost } from './navigator.ts';\nimport { WebFrameHost } from './web-host.ts';\n\ntype View = HTMLElement;\n\ninterface State {\n tag: string;\n listeners: Map<string, Set<Listener>>;\n /** DOM events already wired to raise a NativeScript event, by NativeScript event name. */\n wired: Set<string>;\n /** Properties as last set, for the ones read back (items, selectedIndex, the grid cell). */\n props: Map<string, unknown>;\n /** Parts of composite views: an ActionBar's title and its sides, a TabView's bar, a switch's input. */\n parts: Record<string, HTMLElement>;\n}\n\nconst STATES = new WeakMap<View, State>();\n\nconst state = (view: View): State => {\n const found = STATES.get(view);\n if (!found) throw new Error('[ember-nativescript] Not a view made by the web adapter.');\n return found;\n};\n\n/** Raises a NativeScript event on a view, with NativeScript's data shape: `{ eventName, object, …data }`. */\nexport function emit(view: View, eventName: string, data: Record<string, unknown> = {}): void {\n const listeners = STATES.get(view)?.listeners.get(eventName);\n if (!listeners) return;\n for (const listener of [...listeners]) listener({ eventName, object: view, ...data });\n}\n\n/** Raises `loaded` on a view and everything in it, once it is in the document. */\nexport function emitLoaded(view: View): void {\n if (!view.isConnected) return;\n const all = [view, ...view.querySelectorAll<HTMLElement>('*')];\n for (const each of all) emit(each, 'loaded');\n}\n\n// Tag → the element that stands for it.\nconst ELEMENTS: Record<string, string> = {\n absoluteLayout: 'div',\n actionBar: 'header',\n actionItem: 'button',\n activityIndicator: 'div',\n button: 'button',\n contentView: 'div',\n datePicker: 'input',\n dockLayout: 'div',\n flexboxLayout: 'div',\n formattedString: 'span',\n frame: 'div',\n gridLayout: 'div',\n htmlView: 'div',\n image: 'img',\n label: 'div',\n listPicker: 'select',\n listView: 'div',\n navigationButton: 'button',\n page: 'div',\n placeholder: 'div',\n progress: 'progress',\n rootLayout: 'div',\n scrollView: 'div',\n searchBar: 'input',\n segmentedBar: 'div',\n segmentedBarItem: 'button',\n slider: 'input',\n span: 'span',\n stackLayout: 'div',\n switch: 'label',\n tabView: 'div',\n tabViewItem: 'div',\n textField: 'input',\n textView: 'textarea',\n timePicker: 'input',\n webView: 'iframe',\n wrapLayout: 'div',\n};\n\nconst TEXT_TAGS = new Set(['label', 'button', 'textField', 'textView', 'span', 'searchBar']);\n// Views that hold one child, replaced when another comes: NativeScript's ContentView, Page and ScrollView.\nconst SINGLE_CHILD = new Set(['page', 'scrollView', 'contentView']);\nconst LAYOUTS = new Set([\n 'stackLayout',\n 'gridLayout',\n 'flexboxLayout',\n 'wrapLayout',\n 'absoluteLayout',\n 'dockLayout',\n 'rootLayout',\n]);\n// Not properties of a NativeScript view (what a layout or a stylesheet sets), and `element`, which renderComponent\n// probes to tell a cursor from an element: these stay strings, as in the fake adapter.\nconst NOT_PROPERTIES = new Set(['class', 'style', 'element']);\n\nconst isTrue = (value: unknown): boolean => value === true || value === 'true';\n\n/** A NativeScript length (device-independent pixels, a percentage, `auto`) as CSS. */\nexport function cssLength(value: unknown): string {\n if (typeof value === 'number') return `${value}px`;\n const text = String(value).trim();\n return /^-?\\d*\\.?\\d+$/.test(text) ? `${text}px` : text;\n}\n\nconst cssLengths = (value: unknown): string => String(value).trim().split(/\\s+/).map(cssLength).join(' ');\n\n/** GridLayout's `rows`/`columns` (`'*, auto, 2*, 100'`) as a CSS grid template. */\nexport function gridTemplate(value: unknown): string {\n return String(value)\n .split(/[,\\s]+/)\n .filter(Boolean)\n .map((part) => {\n const star = /^(\\d*\\.?\\d*)\\*$/.exec(part);\n if (star) return `minmax(0, ${star[1] || 1}fr)`;\n return part === 'auto' ? 'auto' : cssLength(part);\n })\n .join(' ');\n}\n\nconst ALIGN: Record<string, string> = {\n left: 'start',\n top: 'start',\n center: 'center',\n middle: 'center',\n right: 'end',\n bottom: 'end',\n stretch: 'stretch',\n};\n\n// NativeScript style properties that are CSS properties under another name, or need units.\nconst STYLE: Record<string, (style: CSSStyleDeclaration, value: unknown) => void> = {\n width: (s, v) => (s.width = cssLength(v)),\n height: (s, v) => (s.height = cssLength(v)),\n minWidth: (s, v) => (s.minWidth = cssLength(v)),\n minHeight: (s, v) => (s.minHeight = cssLength(v)),\n margin: (s, v) => (s.margin = cssLengths(v)),\n marginTop: (s, v) => (s.marginTop = cssLength(v)),\n marginRight: (s, v) => (s.marginRight = cssLength(v)),\n marginBottom: (s, v) => (s.marginBottom = cssLength(v)),\n marginLeft: (s, v) => (s.marginLeft = cssLength(v)),\n padding: (s, v) => (s.padding = cssLengths(v)),\n paddingTop: (s, v) => (s.paddingTop = cssLength(v)),\n paddingRight: (s, v) => (s.paddingRight = cssLength(v)),\n paddingBottom: (s, v) => (s.paddingBottom = cssLength(v)),\n paddingLeft: (s, v) => (s.paddingLeft = cssLength(v)),\n fontSize: (s, v) => (s.fontSize = cssLength(v)),\n lineHeight: (s, v) => (s.lineHeight = cssLength(v)),\n letterSpacing: (s, v) => (s.letterSpacing = `${Number(v)}em`),\n borderRadius: (s, v) => (s.borderRadius = cssLengths(v)),\n borderWidth: (s, v) => {\n s.borderWidth = cssLengths(v);\n s.borderStyle = 'solid';\n },\n textAlignment: (s, v) => (s.textAlign = String(v)),\n horizontalAlignment: (s, v) => s.setProperty('--ns-ha', ALIGN[String(v)] ?? 'stretch'),\n verticalAlignment: (s, v) => s.setProperty('--ns-va', ALIGN[String(v)] ?? 'stretch'),\n visibility: (s, v) => {\n s.display = v === 'collapse' || v === 'collapsed' ? 'none' : '';\n s.visibility = v === 'hidden' ? 'hidden' : '';\n },\n // AbsoluteLayout's and FlexboxLayout's properties, set on the child.\n left: (s, v) => (s.left = cssLength(v)),\n top: (s, v) => (s.top = cssLength(v)),\n order: (s, v) => (s.order = String(v)),\n flexGrow: (s, v) => (s.flexGrow = String(v)),\n flexShrink: (s, v) => (s.flexShrink = String(v)),\n alignSelf: (s, v) => (s.alignSelf = String(v)),\n};\n\n// Style properties whose NativeScript name is the CSS one and whose value needs nothing.\nconst PLAIN_STYLE = new Set([\n 'color',\n 'backgroundColor',\n 'background',\n 'backgroundImage',\n 'backgroundPosition',\n 'backgroundSize',\n 'backgroundRepeat',\n 'borderColor',\n 'borderTopColor',\n 'borderRightColor',\n 'borderBottomColor',\n 'borderLeftColor',\n 'fontWeight',\n 'fontStyle',\n 'fontFamily',\n 'textDecoration',\n 'textTransform',\n 'opacity',\n 'zIndex',\n 'boxShadow',\n // FlexboxLayout's own.\n 'flexDirection',\n 'flexWrap',\n 'justifyContent',\n 'alignItems',\n 'alignContent',\n]);\n\nconst GRID_CELL = new Set(['row', 'col', 'rowSpan', 'colSpan']);\n\nconst SWIPE = { right: 1, left: 2, up: 4, down: 8 };\n\n/** The web adapter: NativeScript's views as HTML elements. */\nexport class WebAdapter implements NativeAdapter<View> {\n readonly platform = 'web' as const;\n\n createView(tag: string): View | null {\n const name = ELEMENTS[tag];\n if (!name) return null;\n const view = document.createElement(name);\n view.className = `ns-${tag}`;\n STATES.set(view, { tag, listeners: new Map(), wired: new Set(), props: new Map(), parts: {} });\n this.#build(view, tag);\n return view;\n }\n\n // The inside of views that are more than one element.\n #build(view: View, tag: string): void {\n const { parts } = state(view);\n const part = (name: string, className: string, element = 'div'): HTMLElement => {\n const made = document.createElement(element);\n made.className = className;\n parts[name] = made;\n return made;\n };\n\n switch (tag) {\n case 'actionBar':\n view.append(\n part('left', 'ns-actionBar-left'),\n part('title', 'ns-actionBar-title'),\n part('right', 'ns-actionBar-right'),\n );\n break;\n case 'tabView':\n view.append(part('items', 'ns-tabView-items'), part('bar', 'ns-tabView-bar', 'nav'));\n parts.bar!.setAttribute('role', 'tablist');\n break;\n case 'tabViewItem': {\n // Its button in the TabView's bar, made here and placed there when the item goes into a TabView.\n const tab = part('tab', 'ns-tabView-tab', 'button');\n tab.setAttribute('type', 'button');\n tab.setAttribute('role', 'tab');\n break;\n }\n case 'switch': {\n const input = part('input', 'ns-switch-input', 'input') as HTMLInputElement;\n input.type = 'checkbox';\n input.setAttribute('role', 'switch');\n view.append(input, part('track', 'ns-switch-track', 'span'));\n break;\n }\n case 'button':\n case 'actionItem':\n case 'navigationButton':\n case 'segmentedBarItem':\n view.setAttribute('type', 'button');\n break;\n case 'datePicker':\n (view as HTMLInputElement).type = 'date';\n break;\n case 'timePicker':\n (view as HTMLInputElement).type = 'time';\n break;\n case 'slider':\n (view as HTMLInputElement).type = 'range';\n break;\n case 'searchBar':\n (view as HTMLInputElement).type = 'search';\n break;\n case 'segmentedBar':\n view.setAttribute('role', 'tablist');\n break;\n case 'listView':\n view.setAttribute('role', 'list');\n break;\n case 'stackLayout':\n view.classList.add('ns-vertical');\n break;\n case 'label':\n // The text in a span of its own, so the label can center it vertically, as UILabel does, and still cut it\n // with an ellipsis.\n view.append(part('text', 'ns-label-text', 'span'));\n break;\n }\n }\n\n setProperty(view: View, name: string, value: unknown): void {\n const { tag, props, parts } = state(view);\n if (value === null) props.delete(name);\n else props.set(name, value);\n const style = view.style;\n\n if (name === 'class') {\n // Keep the classes the adapter put there.\n const own = [...view.classList].filter((each) => each.startsWith('ns-'));\n view.className = [...own, ...(value === null ? [] : String(value).split(/\\s+/).filter(Boolean))].join(' ');\n return;\n }\n if (name === 'style') {\n style.cssText = value === null ? '' : String(value);\n return;\n }\n if (name === 'id') {\n if (value === null) view.removeAttribute('id');\n else view.id = String(value);\n return;\n }\n if (GRID_CELL.has(name)) {\n const at = (key: string, fallback: number): number => Number(props.get(key) ?? fallback);\n style.gridRow = `${at('row', 0) + 1} / span ${at('rowSpan', 1)}`;\n style.gridColumn = `${at('col', 0) + 1} / span ${at('colSpan', 1)}`;\n return;\n }\n if (value === null) {\n this.#unset(view, name);\n return;\n }\n if (this.#setOwn(view, tag, name, value, parts)) return;\n if (STYLE[name]) STYLE[name](style, value);\n else if (PLAIN_STYLE.has(name)) style.setProperty(kebab(name), String(value));\n }\n\n #unset(view: View, name: string): void {\n const kebabName = kebab(name);\n if (STYLE[name] || PLAIN_STYLE.has(name)) {\n view.style.removeProperty(kebabName);\n if (name === 'horizontalAlignment') view.style.removeProperty('--ns-ha');\n if (name === 'verticalAlignment') view.style.removeProperty('--ns-va');\n if (name === 'borderWidth') view.style.removeProperty('border-style');\n return;\n }\n if (name === 'text') this.#setText(view, '');\n else if (name === 'isEnabled') this.#setOwn(view, state(view).tag, name, true, state(view).parts);\n }\n\n // Properties a view of this tag handles itself. False when the name is a plain style property instead.\n #setOwn(view: View, tag: string, name: string, value: unknown, parts: Record<string, HTMLElement>): boolean {\n const input = view as HTMLInputElement;\n switch (name) {\n case 'text':\n if (TEXT_TAGS.has(tag) || tag === 'actionItem' || tag === 'navigationButton') {\n this.#setText(view, String(value));\n return true;\n }\n return false;\n case 'title':\n if (tag === 'actionBar') parts.title!.textContent = String(value);\n else if (tag === 'tabViewItem') parts.tab!.textContent = String(value);\n else if (tag === 'segmentedBarItem') view.textContent = String(value);\n else view.title = String(value);\n return true;\n case 'hint':\n view.setAttribute('placeholder', String(value));\n return true;\n case 'secure':\n if (tag === 'textField') input.type = isTrue(value) ? 'password' : 'text';\n return true;\n case 'keyboardType': {\n const types: Record<string, string> = {\n email: 'email',\n number: 'text',\n phone: 'tel',\n url: 'url',\n integer: 'text',\n };\n const modes: Record<string, string> = {\n number: 'decimal',\n integer: 'numeric',\n phone: 'tel',\n email: 'email',\n url: 'url',\n };\n if (tag === 'textField' && input.type !== 'password') input.type = types[String(value)] ?? 'text';\n view.setAttribute('inputmode', modes[String(value)] ?? 'text');\n return true;\n }\n case 'returnKeyType':\n view.setAttribute('enterkeyhint', String(value));\n return true;\n case 'editable':\n (input as HTMLInputElement | HTMLTextAreaElement).readOnly = !isTrue(value);\n return true;\n case 'maxLength':\n view.setAttribute('maxlength', String(value));\n return true;\n case 'autocorrect':\n view.setAttribute('autocorrect', isTrue(value) ? 'on' : 'off');\n return true;\n case 'autocapitalizationType':\n view.setAttribute('autocapitalize', String(value) === 'none' ? 'off' : String(value));\n return true;\n case 'isEnabled': {\n const enabled = isTrue(value);\n if ('disabled' in view) (view as HTMLButtonElement).disabled = !enabled;\n if (parts.input) (parts.input as HTMLInputElement).disabled = !enabled;\n view.classList.toggle('ns-disabled', !enabled);\n return true;\n }\n case 'isUserInteractionEnabled':\n view.style.pointerEvents = isTrue(value) ? '' : 'none';\n return true;\n case 'textWrap':\n view.classList.toggle('ns-wrap', isTrue(value));\n return true;\n case 'orientation':\n if (tag === 'stackLayout' || tag === 'wrapLayout' || tag === 'scrollView') {\n view.classList.toggle('ns-horizontal', value === 'horizontal');\n view.classList.toggle('ns-vertical', value !== 'horizontal');\n return true;\n }\n return false;\n case 'rows':\n if (tag === 'gridLayout') view.style.gridTemplateRows = gridTemplate(value);\n return tag === 'gridLayout';\n case 'columns':\n if (tag === 'gridLayout') view.style.gridTemplateColumns = gridTemplate(value);\n return tag === 'gridLayout';\n case 'itemWidth':\n view.style.setProperty('--ns-item-width', cssLength(value));\n return true;\n case 'itemHeight':\n view.style.setProperty('--ns-item-height', cssLength(value));\n return true;\n case 'checked':\n if (tag === 'switch') (parts.input as HTMLInputElement).checked = isTrue(value);\n return true;\n case 'value':\n if (tag === 'slider' || tag === 'progress') (view as HTMLInputElement).value = String(value);\n return true;\n case 'minValue':\n view.setAttribute('min', String(value));\n return true;\n case 'maxValue':\n view.setAttribute('max', String(value));\n return true;\n case 'date':\n if (tag === 'datePicker') input.value = toDateInput(value);\n return true;\n case 'minDate':\n view.setAttribute('min', toDateInput(value));\n return true;\n case 'maxDate':\n view.setAttribute('max', toDateInput(value));\n return true;\n case 'time':\n if (tag === 'timePicker') input.value = toTimeInput(value);\n return true;\n case 'items':\n if (tag === 'listPicker') this.#setOptions(view as HTMLSelectElement, value);\n return true;\n case 'selectedIndex':\n this.#select(view, tag, Number(value), false);\n return true;\n case 'busy':\n view.classList.toggle('ns-busy', isTrue(value));\n return true;\n case 'src':\n if (tag === 'image') (view as HTMLImageElement).src = imageUrl(value);\n else if (tag === 'webView') (view as HTMLIFrameElement).src = String(value);\n return true;\n case 'stretch':\n view.style.objectFit =\n { none: 'none', aspectFit: 'contain', aspectFill: 'cover', fill: 'fill' }[String(value)] ?? '';\n return true;\n case 'html':\n // HtmlView renders HTML; here it shows as text until there's a sanitizer in between.\n view.textContent = String(value);\n return true;\n case 'busyIndicator':\n return true;\n default:\n return false;\n }\n }\n\n // The text of a label or button, or the value of a field (left alone when it already says that, so the cursor\n // stays where it is while typing).\n #setText(view: View, text: string): void {\n const { tag } = state(view);\n if (tag === 'textField' || tag === 'textView' || tag === 'searchBar') {\n const field = view as HTMLInputElement;\n if (field.value !== text) field.value = text;\n } else if (tag === 'label') {\n const { parts } = state(view);\n if (!parts.text!.isConnected) view.replaceChildren(parts.text!);\n parts.text!.textContent = text;\n } else if (!view.querySelector(':scope > .ns-formattedString')) {\n view.textContent = text;\n }\n }\n\n #setOptions(select: HTMLSelectElement, items: unknown): void {\n const list = Array.isArray(items) ? items : typeof items === 'string' ? items.split(',') : [];\n select.replaceChildren(\n ...list.map((item, index) => {\n const option = document.createElement('option');\n option.value = String(index);\n option.textContent = String(item);\n return option;\n }),\n );\n const selected = state(select).props.get('selectedIndex');\n if (selected !== undefined) select.value = String(selected);\n }\n\n // A ListPicker's, SegmentedBar's or TabView's selection: from a property (raise = false) or from a tap or a change\n // in the browser (raise = true), which also raises selectedIndexChange.\n #select(view: View, tag: string, index: number, raise: boolean): void {\n const { props, parts } = state(view);\n const old = Number(props.get('currentIndex') ?? -1);\n props.set('currentIndex', index);\n if (raise) props.set('selectedIndex', index);\n\n if (tag === 'listPicker') {\n (view as HTMLSelectElement).value = String(index);\n } else if (tag === 'segmentedBar') {\n [...view.children].forEach((item, each) => item.setAttribute('aria-selected', String(each === index)));\n } else if (tag === 'tabView') {\n [...parts.items!.children].forEach((item, each) => ((item as HTMLElement).hidden = each !== index));\n [...parts.bar!.children].forEach((tab, each) => tab.setAttribute('aria-selected', String(each === index)));\n const shown = parts.items!.children[index] as HTMLElement | undefined;\n if (shown) emitLoaded(shown);\n }\n if (raise && old !== index) emit(view, 'selectedIndexChange', { oldIndex: old, newIndex: index, value: index });\n }\n\n hasProperty(_view: View, name: string): boolean {\n return !NOT_PROPERTIES.has(name.replace(/^(ios|android|web):/, ''));\n }\n\n takesText(view: View): boolean {\n return TEXT_TAGS.has(state(view).tag);\n }\n\n insertChild(parent: View, child: View, index: number): void {\n const { tag } = state(parent);\n if (SINGLE_CHILD.has(tag)) {\n // The page's ActionBar stays: the content is the page's other child.\n for (const each of [...parent.children]) if (!each.classList.contains('ns-actionBar')) each.remove();\n parent.append(child);\n } else if (LAYOUTS.has(tag) || tag === 'listView') {\n parent.insertBefore(child, parent.children[index] ?? null);\n } else {\n throw new Error(`[ember-nativescript] <${tag}> can't hold views.`);\n }\n if (parent.isConnected) emitLoaded(child);\n }\n\n removeChild(_parent: View, child: View): void {\n child.remove();\n }\n\n setSlot(parent: View, property: string, child: View | null): void {\n const { parts } = state(parent);\n const into: HTMLElement | undefined =\n property === 'navigationButton' ? parts.left : property === 'titleView' ? parts.title : undefined;\n\n if (property === 'actionBar') {\n parent.querySelector(':scope > .ns-actionBar')?.remove();\n if (child) parent.prepend(child);\n } else if (into) {\n into.replaceChildren(...(child ? [child] : []));\n } else {\n // A label's formattedText, an ActionItem's actionView, a TabViewItem's view: the child is all it shows.\n parent.replaceChildren(...(child ? [child] : []));\n }\n }\n\n insertInSlot(parent: View, property: string, child: View, index: number): void {\n const { tag, parts } = state(parent);\n if (tag === 'actionBar') {\n parts.right!.insertBefore(child, parts.right!.children[index] ?? null);\n } else if (tag === 'tabView') {\n parts.items!.insertBefore(child, parts.items!.children[index] ?? null);\n const tab = state(child).parts.tab!;\n parts.bar!.insertBefore(tab, parts.bar!.children[index] ?? null);\n tab.onclick = () => this.#select(parent, 'tabView', [...parts.bar!.children].indexOf(tab), true);\n this.#select(parent, 'tabView', Number(state(parent).props.get('selectedIndex') ?? 0), false);\n } else if (tag === 'segmentedBar') {\n parent.insertBefore(child, parent.children[index] ?? null);\n child.onclick = () => this.#select(parent, 'segmentedBar', [...parent.children].indexOf(child), true);\n this.#select(parent, 'segmentedBar', Number(state(parent).props.get('selectedIndex') ?? 0), false);\n } else {\n parent.insertBefore(child, parent.children[index] ?? null);\n }\n }\n\n removeFromSlot(parent: View, _property: string, child: View): void {\n if (state(parent).tag === 'tabView') state(child).parts.tab!.remove();\n child.remove();\n }\n\n on(view: View, event: string, listener: Listener): void {\n const { listeners } = state(view);\n let set = listeners.get(event);\n if (!set) listeners.set(event, (set = new Set()));\n set.add(listener);\n this.#wire(view, event);\n }\n\n off(view: View, event: string, listener: Listener): void {\n state(view).listeners.get(event)?.delete(listener);\n }\n\n // Raises a NativeScript event from the DOM events that stand for it, wired the first time someone listens.\n #wire(view: View, event: string): void {\n const { wired, tag, parts } = state(view);\n if (wired.has(event)) return;\n wired.add(event);\n const field = view as HTMLInputElement;\n\n switch (event) {\n case 'tap':\n view.addEventListener('click', () => emit(view, 'tap'));\n break;\n case 'doubleTap':\n view.addEventListener('dblclick', () => emit(view, 'doubleTap'));\n break;\n case 'longPress':\n pressAndHold(view, () => emit(view, 'longPress'));\n break;\n case 'swipe':\n swipes(view, (direction) => emit(view, 'swipe', { direction }));\n break;\n case 'textChange':\n view.addEventListener('input', () => emit(view, 'textChange', { value: field.value }));\n break;\n case 'returnPress':\n view.addEventListener('keydown', (key) => {\n if (key.key === 'Enter' && tag !== 'textView') emit(view, 'returnPress');\n });\n break;\n case 'submit':\n view.addEventListener('keydown', (key) => key.key === 'Enter' && emit(view, 'submit'));\n break;\n case 'focus':\n case 'blur':\n view.addEventListener(event, () => emit(view, event));\n break;\n case 'checkedChange':\n parts.input?.addEventListener('change', () =>\n emit(view, 'checkedChange', { value: (parts.input as HTMLInputElement).checked }),\n );\n break;\n case 'valueChange':\n view.addEventListener('input', () => emit(view, 'valueChange', { value: Number(field.value) }));\n break;\n case 'dateChange':\n view.addEventListener(\n 'change',\n () => field.value && emit(view, 'dateChange', { value: new Date(`${field.value}T00:00`) }),\n );\n break;\n case 'timeChange':\n view.addEventListener('change', () => emit(view, 'timeChange', { value: fromTimeInput(field.value) }));\n break;\n case 'selectedIndexChange':\n if (tag === 'listPicker')\n view.addEventListener('change', () => this.#select(view, tag, Number(field.value), true));\n break;\n }\n }\n\n frameHost(view: View): FrameHost<View> | null {\n return state(view).tag === 'frame' ? new WebFrameHost(view) : null;\n }\n\n // A list in the browser: a cell per row, added as the user scrolls near the end, rather than a pool of recycled\n // cells. It raises itemTap with the row's index, and loadMoreItems when the last row comes into view.\n bindList(view: View, cell: (container: View, index: number) => void, _options?: ListOptions): ListBinding | null {\n if (state(view).tag !== 'listView') return null;\n const PAGE = 40;\n let count = 0;\n let shown = 0;\n let lastAsked = -1;\n\n const makeCell = (index: number): void => {\n const container = this.createView('stackLayout')!;\n container.classList.add('ns-listView-cell');\n container.setAttribute('role', 'listitem');\n container.addEventListener('click', (click) => {\n // A tap on a button inside the row is the button's.\n if ((click.target as HTMLElement).closest('button, input, select, textarea, a') !== null) return;\n emit(view, 'itemTap', { index: [...view.children].indexOf(container) });\n });\n view.append(container);\n cell(container, index);\n };\n\n const fill = (): void => {\n const target = Math.min(count, Math.max(shown + PAGE, PAGE));\n // Cells already there show the first rows again when the items change.\n [...view.children].forEach((container, index) => index < count && cell(container as View, index));\n for (let index = shown; index < target; index++) makeCell(index);\n shown = Math.max(shown, target);\n };\n\n const nearEnd = (): void => {\n if (view.scrollTop + view.clientHeight < view.scrollHeight - 400) return;\n if (shown < count) fill();\n else if (count > 0 && lastAsked !== count) {\n lastAsked = count;\n emit(view, 'loadMoreItems');\n }\n };\n view.addEventListener('scroll', nearEnd, { passive: true });\n\n return {\n setCount(next) {\n count = next;\n // Rows past the end go; the rest show their (maybe new) items.\n while (view.children.length > count) view.lastElementChild!.remove();\n shown = Math.min(shown, count);\n fill();\n requestAnimationFrame(nearEnd);\n },\n release() {\n view.removeEventListener('scroll', nearEnd);\n },\n };\n }\n}\n\nconst kebab = (name: string): string => name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\nfunction toDateInput(value: unknown): string {\n const date = value instanceof Date ? value : new Date(String(value));\n if (Number.isNaN(date.getTime())) return '';\n const pad = (n: number) => String(n).padStart(2, '0');\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n}\n\nfunction toTimeInput(value: unknown): string {\n const date = value instanceof Date ? value : new Date(String(value));\n if (Number.isNaN(date.getTime())) return '';\n return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;\n}\n\nfunction fromTimeInput(value: string): Date {\n const [hours, minutes] = value.split(':').map(Number);\n const date = new Date();\n date.setHours(hours ?? 0, minutes ?? 0, 0, 0);\n return date;\n}\n\n// `~/images/logo.png` is the app's folder, `res://logo` an App_Resources image: both served from the site's root.\nfunction imageUrl(value: unknown): string {\n const src = String(value);\n if (src.startsWith('~/')) return `/${src.slice(2)}`;\n if (src.startsWith('res://')) return `/res/${src.slice('res://'.length)}.png`;\n return src;\n}\n\nfunction pressAndHold(view: View, held: () => void): void {\n let timer: ReturnType<typeof setTimeout> | undefined;\n const cancel = (): void => clearTimeout(timer);\n view.addEventListener('pointerdown', () => {\n cancel();\n timer = setTimeout(held, 500);\n });\n for (const name of ['pointerup', 'pointerleave', 'pointercancel']) view.addEventListener(name, cancel);\n}\n\nfunction swipes(view: View, swiped: (direction: number) => void): void {\n let start: { x: number; y: number } | undefined;\n view.addEventListener('pointerdown', (down) => (start = { x: down.clientX, y: down.clientY }));\n view.addEventListener('pointerup', (up) => {\n if (!start) return;\n const dx = up.clientX - start.x;\n const dy = up.clientY - start.y;\n start = undefined;\n if (Math.max(Math.abs(dx), Math.abs(dy)) < 40) return;\n if (Math.abs(dx) > Math.abs(dy)) swiped(dx > 0 ? SWIPE.right : SWIPE.left);\n else swiped(dy > 0 ? SWIPE.down : SWIPE.up);\n });\n}\n"],"mappings":";;AA0BA,IAAM,yBAAS,IAAI,QAAqB;AAExC,IAAM,SAAS,SAAsB;CACnC,MAAM,QAAQ,OAAO,IAAI,IAAI;CAC7B,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,0DAA0D;CACtF,OAAO;AACT;;AAGA,SAAgB,KAAK,MAAY,WAAmB,OAAgC,CAAC,GAAS;CAC5F,MAAM,YAAY,OAAO,IAAI,IAAI,CAAC,EAAE,UAAU,IAAI,SAAS;CAC3D,IAAI,CAAC,WAAW;CAChB,KAAK,MAAM,YAAY,CAAC,GAAG,SAAS,GAAG,SAAS;EAAE;EAAW,QAAQ;EAAM,GAAG;CAAK,CAAC;AACtF;;AAGA,SAAgB,WAAW,MAAkB;CAC3C,IAAI,CAAC,KAAK,aAAa;CACvB,MAAM,MAAM,CAAC,MAAM,GAAG,KAAK,iBAA8B,GAAG,CAAC;CAC7D,KAAK,MAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ;AAC7C;AAGA,IAAM,WAAmC;CACvC,gBAAgB;CAChB,WAAW;CACX,YAAY;CACZ,mBAAmB;CACnB,QAAQ;CACR,aAAa;CACb,YAAY;CAC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C9B,QAAQ,KAAA;EACR,IAAI,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,IAAI;EAC/C,IAAI,KAAK,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,GAAG,OAAO,KAAK,IAAI,MAAM,QAAQ,MAAM,IAAI;OACpE,OAAO,KAAK,IAAI,MAAM,OAAO,MAAM,EAAE;CAC5C,CAAC;AACH"}
1
+ {"version":3,"file":"web-adapter.js","names":[],"sources":["../../src/web-adapter.ts"],"sourcesContent":["// The adapter that shows an app's screens in a browser: each NativeScript view is an HTML element with the class\n// `ns-<tag>` (a stackLayout is a flex column, a gridLayout a CSS grid, a textField an <input>), its properties set as\n// the element's attributes and styles, and NativeScript's events (tap, textChange, checkedChange…) raised from DOM\n// events with the data NativeScript gives them.\n//\n// The layout follows NativeScript's rules where CSS has a match: sizes in device-independent pixels are CSS pixels,\n// GridLayout's `*` is `fr`, children of a layout stretch unless aligned. web-styles.ts holds the CSS that does it.\n// What has no match yet (DockLayout, pan and pinch) is approximated or left out. Lists recycle their cells: web-list.ts.\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport type { FrameHost } from './navigator.ts';\nimport { WebFrameHost } from './web-host.ts';\nimport { WebList } from './web-list.ts';\n\ntype View = HTMLElement;\n\ninterface State {\n tag: string;\n listeners: Map<string, Set<Listener>>;\n /** DOM events already wired to raise a NativeScript event, by NativeScript event name. */\n wired: Set<string>;\n /** Properties as last set, for the ones read back (items, selectedIndex, the grid cell). */\n props: Map<string, unknown>;\n /** Parts of composite views: an ActionBar's title and its sides, a TabView's bar, a switch's input. */\n parts: Record<string, HTMLElement>;\n}\n\nconst STATES = new WeakMap<View, State>();\n\nconst state = (view: View): State => {\n const found = STATES.get(view);\n if (!found) throw new Error('[ember-nativescript] Not a view made by the web adapter.');\n return found;\n};\n\n/** Raises a NativeScript event on a view, with NativeScript's data shape: `{ eventName, object, …data }`. */\nexport function emit(view: View, eventName: string, data: Record<string, unknown> = {}): void {\n const listeners = STATES.get(view)?.listeners.get(eventName);\n if (!listeners) return;\n for (const listener of [...listeners]) listener({ eventName, object: view, ...data });\n}\n\n/** Raises `loaded` on a view and everything in it, once it is in the document. */\nexport function emitLoaded(view: View): void {\n if (!view.isConnected) return;\n const all = [view, ...view.querySelectorAll<HTMLElement>('*')];\n for (const each of all) emit(each, 'loaded');\n}\n\n// Tag → the element that stands for it.\nconst ELEMENTS: Record<string, string> = {\n absoluteLayout: 'div',\n actionBar: 'header',\n actionItem: 'button',\n activityIndicator: 'div',\n button: 'button',\n contentView: 'div',\n datePicker: 'input',\n dockLayout: 'div',\n flexboxLayout: 'div',\n formattedString: 'span',\n frame: 'div',\n gridLayout: 'div',\n htmlView: 'div',\n image: 'img',\n label: 'div',\n listPicker: 'select',\n listView: 'div',\n navigationButton: 'button',\n page: 'div',\n placeholder: 'div',\n progress: 'progress',\n rootLayout: 'div',\n scrollView: 'div',\n searchBar: 'input',\n segmentedBar: 'div',\n segmentedBarItem: 'button',\n slider: 'input',\n span: 'span',\n stackLayout: 'div',\n switch: 'label',\n tabView: 'div',\n tabViewItem: 'div',\n textField: 'input',\n textView: 'textarea',\n timePicker: 'input',\n webView: 'iframe',\n wrapLayout: 'div',\n};\n\nconst TEXT_TAGS = new Set(['label', 'button', 'textField', 'textView', 'span', 'searchBar']);\n// Views that hold one child, replaced when another comes: NativeScript's ContentView, Page and ScrollView.\nconst SINGLE_CHILD = new Set(['page', 'scrollView', 'contentView']);\nconst LAYOUTS = new Set([\n 'stackLayout',\n 'gridLayout',\n 'flexboxLayout',\n 'wrapLayout',\n 'absoluteLayout',\n 'dockLayout',\n 'rootLayout',\n]);\n// Not properties of a NativeScript view (what a layout or a stylesheet sets), and `element`, which renderComponent\n// probes to tell a cursor from an element: these stay strings, as in the fake adapter.\nconst NOT_PROPERTIES = new Set(['class', 'style', 'element']);\n\nconst isTrue = (value: unknown): boolean => value === true || value === 'true';\n\n/** A NativeScript length (device-independent pixels, a percentage, `auto`) as CSS. */\nexport function cssLength(value: unknown): string {\n if (typeof value === 'number') return `${value}px`;\n const text = String(value).trim();\n return /^-?\\d*\\.?\\d+$/.test(text) ? `${text}px` : text;\n}\n\nconst cssLengths = (value: unknown): string => String(value).trim().split(/\\s+/).map(cssLength).join(' ');\n\n/** GridLayout's `rows`/`columns` (`'*, auto, 2*, 100'`) as a CSS grid template. */\nexport function gridTemplate(value: unknown): string {\n return String(value)\n .split(/[,\\s]+/)\n .filter(Boolean)\n .map((part) => {\n const star = /^(\\d*\\.?\\d*)\\*$/.exec(part);\n if (star) return `minmax(0, ${star[1] || 1}fr)`;\n return part === 'auto' ? 'auto' : cssLength(part);\n })\n .join(' ');\n}\n\nconst ALIGN: Record<string, string> = {\n left: 'start',\n top: 'start',\n center: 'center',\n middle: 'center',\n right: 'end',\n bottom: 'end',\n stretch: 'stretch',\n};\n\n// NativeScript style properties that are CSS properties under another name, or need units.\nconst STYLE: Record<string, (style: CSSStyleDeclaration, value: unknown) => void> = {\n width: (s, v) => (s.width = cssLength(v)),\n height: (s, v) => (s.height = cssLength(v)),\n minWidth: (s, v) => (s.minWidth = cssLength(v)),\n minHeight: (s, v) => (s.minHeight = cssLength(v)),\n margin: (s, v) => (s.margin = cssLengths(v)),\n marginTop: (s, v) => (s.marginTop = cssLength(v)),\n marginRight: (s, v) => (s.marginRight = cssLength(v)),\n marginBottom: (s, v) => (s.marginBottom = cssLength(v)),\n marginLeft: (s, v) => (s.marginLeft = cssLength(v)),\n padding: (s, v) => (s.padding = cssLengths(v)),\n paddingTop: (s, v) => (s.paddingTop = cssLength(v)),\n paddingRight: (s, v) => (s.paddingRight = cssLength(v)),\n paddingBottom: (s, v) => (s.paddingBottom = cssLength(v)),\n paddingLeft: (s, v) => (s.paddingLeft = cssLength(v)),\n fontSize: (s, v) => (s.fontSize = cssLength(v)),\n lineHeight: (s, v) => (s.lineHeight = cssLength(v)),\n letterSpacing: (s, v) => (s.letterSpacing = `${Number(v)}em`),\n borderRadius: (s, v) => (s.borderRadius = cssLengths(v)),\n borderWidth: (s, v) => {\n s.borderWidth = cssLengths(v);\n s.borderStyle = 'solid';\n },\n textAlignment: (s, v) => (s.textAlign = String(v)),\n horizontalAlignment: (s, v) => s.setProperty('--ns-ha', ALIGN[String(v)] ?? 'stretch'),\n verticalAlignment: (s, v) => s.setProperty('--ns-va', ALIGN[String(v)] ?? 'stretch'),\n visibility: (s, v) => {\n s.display = v === 'collapse' || v === 'collapsed' ? 'none' : '';\n s.visibility = v === 'hidden' ? 'hidden' : '';\n },\n // AbsoluteLayout's and FlexboxLayout's properties, set on the child.\n left: (s, v) => (s.left = cssLength(v)),\n top: (s, v) => (s.top = cssLength(v)),\n order: (s, v) => (s.order = String(v)),\n flexGrow: (s, v) => (s.flexGrow = String(v)),\n flexShrink: (s, v) => (s.flexShrink = String(v)),\n alignSelf: (s, v) => (s.alignSelf = String(v)),\n};\n\n// Style properties whose NativeScript name is the CSS one and whose value needs nothing.\nconst PLAIN_STYLE = new Set([\n 'color',\n 'backgroundColor',\n 'background',\n 'backgroundImage',\n 'backgroundPosition',\n 'backgroundSize',\n 'backgroundRepeat',\n 'borderColor',\n 'borderTopColor',\n 'borderRightColor',\n 'borderBottomColor',\n 'borderLeftColor',\n 'fontWeight',\n 'fontStyle',\n 'fontFamily',\n 'textDecoration',\n 'textTransform',\n 'opacity',\n 'zIndex',\n 'boxShadow',\n // FlexboxLayout's own.\n 'flexDirection',\n 'flexWrap',\n 'justifyContent',\n 'alignItems',\n 'alignContent',\n]);\n\nconst GRID_CELL = new Set(['row', 'col', 'rowSpan', 'colSpan']);\n\nconst SWIPE = { right: 1, left: 2, up: 4, down: 8 };\n\n/** The web adapter: NativeScript's views as HTML elements. */\nexport class WebAdapter implements NativeAdapter<View> {\n readonly platform = 'web' as const;\n\n createView(tag: string): View | null {\n const name = ELEMENTS[tag];\n if (!name) return null;\n const view = document.createElement(name);\n view.className = `ns-${tag}`;\n STATES.set(view, { tag, listeners: new Map(), wired: new Set(), props: new Map(), parts: {} });\n this.#build(view, tag);\n return view;\n }\n\n // The inside of views that are more than one element.\n #build(view: View, tag: string): void {\n const { parts } = state(view);\n const part = (name: string, className: string, element = 'div'): HTMLElement => {\n const made = document.createElement(element);\n made.className = className;\n parts[name] = made;\n return made;\n };\n\n switch (tag) {\n case 'actionBar':\n view.append(\n part('left', 'ns-actionBar-left'),\n part('title', 'ns-actionBar-title'),\n part('right', 'ns-actionBar-right'),\n );\n break;\n case 'tabView':\n view.append(part('items', 'ns-tabView-items'), part('bar', 'ns-tabView-bar', 'nav'));\n parts.bar!.setAttribute('role', 'tablist');\n break;\n case 'tabViewItem': {\n // Its button in the TabView's bar, made here and placed there when the item goes into a TabView.\n const tab = part('tab', 'ns-tabView-tab', 'button');\n tab.setAttribute('type', 'button');\n tab.setAttribute('role', 'tab');\n break;\n }\n case 'switch': {\n const input = part('input', 'ns-switch-input', 'input') as HTMLInputElement;\n input.type = 'checkbox';\n input.setAttribute('role', 'switch');\n view.append(input, part('track', 'ns-switch-track', 'span'));\n break;\n }\n case 'button':\n case 'actionItem':\n case 'navigationButton':\n case 'segmentedBarItem':\n view.setAttribute('type', 'button');\n break;\n case 'datePicker':\n (view as HTMLInputElement).type = 'date';\n break;\n case 'timePicker':\n (view as HTMLInputElement).type = 'time';\n break;\n case 'slider':\n (view as HTMLInputElement).type = 'range';\n break;\n case 'searchBar':\n (view as HTMLInputElement).type = 'search';\n break;\n case 'segmentedBar':\n view.setAttribute('role', 'tablist');\n break;\n case 'listView':\n view.setAttribute('role', 'list');\n break;\n case 'stackLayout':\n view.classList.add('ns-vertical');\n break;\n case 'label':\n // The text in a span of its own, so the label can center it vertically, as UILabel does, and still cut it\n // with an ellipsis.\n view.append(part('text', 'ns-label-text', 'span'));\n break;\n }\n }\n\n setProperty(view: View, name: string, value: unknown): void {\n const { tag, props, parts } = state(view);\n if (value === null) props.delete(name);\n else props.set(name, value);\n const style = view.style;\n\n if (name === 'class') {\n // Keep the classes the adapter put there.\n const own = [...view.classList].filter((each) => each.startsWith('ns-'));\n view.className = [...own, ...(value === null ? [] : String(value).split(/\\s+/).filter(Boolean))].join(' ');\n return;\n }\n if (name === 'style') {\n style.cssText = value === null ? '' : String(value);\n return;\n }\n if (name === 'id') {\n if (value === null) view.removeAttribute('id');\n else view.id = String(value);\n return;\n }\n if (GRID_CELL.has(name)) {\n const at = (key: string, fallback: number): number => Number(props.get(key) ?? fallback);\n style.gridRow = `${at('row', 0) + 1} / span ${at('rowSpan', 1)}`;\n style.gridColumn = `${at('col', 0) + 1} / span ${at('colSpan', 1)}`;\n return;\n }\n if (value === null) {\n this.#unset(view, name);\n return;\n }\n if (this.#setOwn(view, tag, name, value, parts)) return;\n if (STYLE[name]) STYLE[name](style, value);\n else if (PLAIN_STYLE.has(name)) style.setProperty(kebab(name), String(value));\n }\n\n #unset(view: View, name: string): void {\n const kebabName = kebab(name);\n if (STYLE[name] || PLAIN_STYLE.has(name)) {\n view.style.removeProperty(kebabName);\n if (name === 'horizontalAlignment') view.style.removeProperty('--ns-ha');\n if (name === 'verticalAlignment') view.style.removeProperty('--ns-va');\n if (name === 'borderWidth') view.style.removeProperty('border-style');\n return;\n }\n if (name === 'text') this.#setText(view, '');\n else if (name === 'isEnabled') this.#setOwn(view, state(view).tag, name, true, state(view).parts);\n }\n\n // Properties a view of this tag handles itself. False when the name is a plain style property instead.\n #setOwn(view: View, tag: string, name: string, value: unknown, parts: Record<string, HTMLElement>): boolean {\n const input = view as HTMLInputElement;\n switch (name) {\n case 'text':\n if (TEXT_TAGS.has(tag) || tag === 'actionItem' || tag === 'navigationButton') {\n this.#setText(view, String(value));\n return true;\n }\n return false;\n case 'title':\n if (tag === 'actionBar') parts.title!.textContent = String(value);\n else if (tag === 'tabViewItem') parts.tab!.textContent = String(value);\n else if (tag === 'segmentedBarItem') view.textContent = String(value);\n else view.title = String(value);\n return true;\n case 'hint':\n view.setAttribute('placeholder', String(value));\n return true;\n case 'secure':\n if (tag === 'textField') input.type = isTrue(value) ? 'password' : 'text';\n return true;\n case 'keyboardType': {\n const types: Record<string, string> = {\n email: 'email',\n number: 'text',\n phone: 'tel',\n url: 'url',\n integer: 'text',\n };\n const modes: Record<string, string> = {\n number: 'decimal',\n integer: 'numeric',\n phone: 'tel',\n email: 'email',\n url: 'url',\n };\n if (tag === 'textField' && input.type !== 'password') input.type = types[String(value)] ?? 'text';\n view.setAttribute('inputmode', modes[String(value)] ?? 'text');\n return true;\n }\n case 'returnKeyType':\n view.setAttribute('enterkeyhint', String(value));\n return true;\n case 'editable':\n (input as HTMLInputElement | HTMLTextAreaElement).readOnly = !isTrue(value);\n return true;\n case 'maxLength':\n view.setAttribute('maxlength', String(value));\n return true;\n case 'autocorrect':\n view.setAttribute('autocorrect', isTrue(value) ? 'on' : 'off');\n return true;\n case 'autocapitalizationType':\n view.setAttribute('autocapitalize', String(value) === 'none' ? 'off' : String(value));\n return true;\n case 'isEnabled': {\n const enabled = isTrue(value);\n if ('disabled' in view) (view as HTMLButtonElement).disabled = !enabled;\n if (parts.input) (parts.input as HTMLInputElement).disabled = !enabled;\n view.classList.toggle('ns-disabled', !enabled);\n return true;\n }\n case 'isUserInteractionEnabled':\n view.style.pointerEvents = isTrue(value) ? '' : 'none';\n return true;\n case 'textWrap':\n view.classList.toggle('ns-wrap', isTrue(value));\n return true;\n case 'orientation':\n if (tag === 'stackLayout' || tag === 'wrapLayout' || tag === 'scrollView') {\n view.classList.toggle('ns-horizontal', value === 'horizontal');\n view.classList.toggle('ns-vertical', value !== 'horizontal');\n return true;\n }\n return false;\n case 'rows':\n if (tag === 'gridLayout') view.style.gridTemplateRows = gridTemplate(value);\n return tag === 'gridLayout';\n case 'columns':\n if (tag === 'gridLayout') view.style.gridTemplateColumns = gridTemplate(value);\n return tag === 'gridLayout';\n case 'itemWidth':\n view.style.setProperty('--ns-item-width', cssLength(value));\n return true;\n case 'itemHeight':\n view.style.setProperty('--ns-item-height', cssLength(value));\n return true;\n case 'checked':\n if (tag === 'switch') (parts.input as HTMLInputElement).checked = isTrue(value);\n return true;\n case 'value':\n if (tag === 'slider' || tag === 'progress') (view as HTMLInputElement).value = String(value);\n return true;\n case 'minValue':\n view.setAttribute('min', String(value));\n return true;\n case 'maxValue':\n view.setAttribute('max', String(value));\n return true;\n case 'date':\n if (tag === 'datePicker') input.value = toDateInput(value);\n return true;\n case 'minDate':\n view.setAttribute('min', toDateInput(value));\n return true;\n case 'maxDate':\n view.setAttribute('max', toDateInput(value));\n return true;\n case 'time':\n if (tag === 'timePicker') input.value = toTimeInput(value);\n return true;\n case 'items':\n if (tag === 'listPicker') this.#setOptions(view as HTMLSelectElement, value);\n return true;\n case 'selectedIndex':\n this.#select(view, tag, Number(value), false);\n return true;\n case 'busy':\n view.classList.toggle('ns-busy', isTrue(value));\n return true;\n case 'src':\n if (tag === 'image') (view as HTMLImageElement).src = imageUrl(value);\n else if (tag === 'webView') (view as HTMLIFrameElement).src = String(value);\n return true;\n case 'stretch':\n view.style.objectFit =\n { none: 'none', aspectFit: 'contain', aspectFill: 'cover', fill: 'fill' }[String(value)] ?? '';\n return true;\n case 'html':\n // HtmlView renders HTML; here it shows as text until there's a sanitizer in between.\n view.textContent = String(value);\n return true;\n case 'busyIndicator':\n return true;\n default:\n return false;\n }\n }\n\n // The text of a label or button, or the value of a field (left alone when it already says that, so the cursor\n // stays where it is while typing).\n #setText(view: View, text: string): void {\n const { tag } = state(view);\n if (tag === 'textField' || tag === 'textView' || tag === 'searchBar') {\n const field = view as HTMLInputElement;\n if (field.value !== text) field.value = text;\n } else if (tag === 'label') {\n const { parts } = state(view);\n if (!parts.text!.isConnected) view.replaceChildren(parts.text!);\n parts.text!.textContent = text;\n } else if (!view.querySelector(':scope > .ns-formattedString')) {\n view.textContent = text;\n }\n }\n\n #setOptions(select: HTMLSelectElement, items: unknown): void {\n const list = Array.isArray(items) ? items : typeof items === 'string' ? items.split(',') : [];\n select.replaceChildren(\n ...list.map((item, index) => {\n const option = document.createElement('option');\n option.value = String(index);\n option.textContent = String(item);\n return option;\n }),\n );\n const selected = state(select).props.get('selectedIndex');\n if (selected !== undefined) select.value = String(selected);\n }\n\n // A ListPicker's, SegmentedBar's or TabView's selection: from a property (raise = false) or from a tap or a change\n // in the browser (raise = true), which also raises selectedIndexChange.\n #select(view: View, tag: string, index: number, raise: boolean): void {\n const { props, parts } = state(view);\n const old = Number(props.get('currentIndex') ?? -1);\n props.set('currentIndex', index);\n if (raise) props.set('selectedIndex', index);\n\n if (tag === 'listPicker') {\n (view as HTMLSelectElement).value = String(index);\n } else if (tag === 'segmentedBar') {\n [...view.children].forEach((item, each) => item.setAttribute('aria-selected', String(each === index)));\n } else if (tag === 'tabView') {\n [...parts.items!.children].forEach((item, each) => ((item as HTMLElement).hidden = each !== index));\n [...parts.bar!.children].forEach((tab, each) => tab.setAttribute('aria-selected', String(each === index)));\n const shown = parts.items!.children[index] as HTMLElement | undefined;\n if (shown) emitLoaded(shown);\n }\n if (raise && old !== index) emit(view, 'selectedIndexChange', { oldIndex: old, newIndex: index, value: index });\n }\n\n hasProperty(_view: View, name: string): boolean {\n return !NOT_PROPERTIES.has(name.replace(/^(ios|android|web):/, ''));\n }\n\n takesText(view: View): boolean {\n return TEXT_TAGS.has(state(view).tag);\n }\n\n insertChild(parent: View, child: View, index: number): void {\n const { tag } = state(parent);\n if (SINGLE_CHILD.has(tag)) {\n // The page's ActionBar stays: the content is the page's other child.\n for (const each of [...parent.children]) if (!each.classList.contains('ns-actionBar')) each.remove();\n parent.append(child);\n } else if (LAYOUTS.has(tag) || tag === 'listView') {\n parent.insertBefore(child, parent.children[index] ?? null);\n } else {\n throw new Error(`[ember-nativescript] <${tag}> can't hold views.`);\n }\n if (parent.isConnected) emitLoaded(child);\n }\n\n removeChild(_parent: View, child: View): void {\n child.remove();\n }\n\n setSlot(parent: View, property: string, child: View | null): void {\n const { parts } = state(parent);\n const into: HTMLElement | undefined =\n property === 'navigationButton' ? parts.left : property === 'titleView' ? parts.title : undefined;\n\n if (property === 'actionBar') {\n parent.querySelector(':scope > .ns-actionBar')?.remove();\n if (child) parent.prepend(child);\n } else if (into) {\n into.replaceChildren(...(child ? [child] : []));\n } else {\n // A label's formattedText, an ActionItem's actionView, a TabViewItem's view: the child is all it shows.\n parent.replaceChildren(...(child ? [child] : []));\n }\n }\n\n insertInSlot(parent: View, property: string, child: View, index: number): void {\n const { tag, parts } = state(parent);\n if (tag === 'actionBar') {\n parts.right!.insertBefore(child, parts.right!.children[index] ?? null);\n } else if (tag === 'tabView') {\n parts.items!.insertBefore(child, parts.items!.children[index] ?? null);\n const tab = state(child).parts.tab!;\n parts.bar!.insertBefore(tab, parts.bar!.children[index] ?? null);\n tab.onclick = () => this.#select(parent, 'tabView', [...parts.bar!.children].indexOf(tab), true);\n this.#select(parent, 'tabView', Number(state(parent).props.get('selectedIndex') ?? 0), false);\n } else if (tag === 'segmentedBar') {\n parent.insertBefore(child, parent.children[index] ?? null);\n child.onclick = () => this.#select(parent, 'segmentedBar', [...parent.children].indexOf(child), true);\n this.#select(parent, 'segmentedBar', Number(state(parent).props.get('selectedIndex') ?? 0), false);\n } else {\n parent.insertBefore(child, parent.children[index] ?? null);\n }\n }\n\n removeFromSlot(parent: View, _property: string, child: View): void {\n if (state(parent).tag === 'tabView') state(child).parts.tab!.remove();\n child.remove();\n }\n\n on(view: View, event: string, listener: Listener): void {\n const { listeners } = state(view);\n let set = listeners.get(event);\n if (!set) listeners.set(event, (set = new Set()));\n set.add(listener);\n this.#wire(view, event);\n }\n\n off(view: View, event: string, listener: Listener): void {\n state(view).listeners.get(event)?.delete(listener);\n }\n\n // Raises a NativeScript event from the DOM events that stand for it, wired the first time someone listens.\n #wire(view: View, event: string): void {\n const { wired, tag, parts } = state(view);\n if (wired.has(event)) return;\n wired.add(event);\n const field = view as HTMLInputElement;\n\n switch (event) {\n case 'tap':\n view.addEventListener('click', () => emit(view, 'tap'));\n break;\n case 'doubleTap':\n view.addEventListener('dblclick', () => emit(view, 'doubleTap'));\n break;\n case 'longPress':\n pressAndHold(view, () => emit(view, 'longPress'));\n break;\n case 'swipe':\n swipes(view, (direction) => emit(view, 'swipe', { direction }));\n break;\n case 'textChange':\n view.addEventListener('input', () => emit(view, 'textChange', { value: field.value }));\n break;\n case 'returnPress':\n view.addEventListener('keydown', (key) => {\n if (key.key === 'Enter' && tag !== 'textView') emit(view, 'returnPress');\n });\n break;\n case 'submit':\n view.addEventListener('keydown', (key) => key.key === 'Enter' && emit(view, 'submit'));\n break;\n case 'focus':\n case 'blur':\n view.addEventListener(event, () => emit(view, event));\n break;\n case 'checkedChange':\n parts.input?.addEventListener('change', () =>\n emit(view, 'checkedChange', { value: (parts.input as HTMLInputElement).checked }),\n );\n break;\n case 'valueChange':\n view.addEventListener('input', () => emit(view, 'valueChange', { value: Number(field.value) }));\n break;\n case 'dateChange':\n view.addEventListener(\n 'change',\n () => field.value && emit(view, 'dateChange', { value: new Date(`${field.value}T00:00`) }),\n );\n break;\n case 'timeChange':\n view.addEventListener('change', () => emit(view, 'timeChange', { value: fromTimeInput(field.value) }));\n break;\n case 'selectedIndexChange':\n if (tag === 'listPicker')\n view.addEventListener('change', () => this.#select(view, tag, Number(field.value), true));\n break;\n }\n }\n\n frameHost(view: View): FrameHost<View> | null {\n return state(view).tag === 'frame' ? new WebFrameHost(view) : null;\n }\n\n // A list in the browser: a cell per row, added as the user scrolls near the end, rather than a pool of recycled\n // cells. It raises itemTap with the row's index, and loadMoreItems when the last row comes into view.\n bindList(view: View, cell: (container: View, index: number) => void, options: ListOptions = {}): ListBinding | null {\n if (state(view).tag !== 'listView') return null;\n return new WebList(view, cell, options, {\n createCell: () => this.createView('stackLayout')!,\n emit: (name, data) => emit(view, name, data),\n });\n }\n}\n\nconst kebab = (name: string): string => name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\nfunction toDateInput(value: unknown): string {\n const date = value instanceof Date ? value : new Date(String(value));\n if (Number.isNaN(date.getTime())) return '';\n const pad = (n: number) => String(n).padStart(2, '0');\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n}\n\nfunction toTimeInput(value: unknown): string {\n const date = value instanceof Date ? value : new Date(String(value));\n if (Number.isNaN(date.getTime())) return '';\n return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;\n}\n\nfunction fromTimeInput(value: string): Date {\n const [hours, minutes] = value.split(':').map(Number);\n const date = new Date();\n date.setHours(hours ?? 0, minutes ?? 0, 0, 0);\n return date;\n}\n\n// `~/images/logo.png` is the app's folder, `res://logo` an App_Resources image: both served from the site's root.\nfunction imageUrl(value: unknown): string {\n const src = String(value);\n if (src.startsWith('~/')) return `/${src.slice(2)}`;\n if (src.startsWith('res://')) return `/res/${src.slice('res://'.length)}.png`;\n return src;\n}\n\nfunction pressAndHold(view: View, held: () => void): void {\n let timer: ReturnType<typeof setTimeout> | undefined;\n const cancel = (): void => clearTimeout(timer);\n view.addEventListener('pointerdown', () => {\n cancel();\n timer = setTimeout(held, 500);\n });\n for (const name of ['pointerup', 'pointerleave', 'pointercancel']) view.addEventListener(name, cancel);\n}\n\nfunction swipes(view: View, swiped: (direction: number) => void): void {\n let start: { x: number; y: number } | undefined;\n view.addEventListener('pointerdown', (down) => (start = { x: down.clientX, y: down.clientY }));\n view.addEventListener('pointerup', (up) => {\n if (!start) return;\n const dx = up.clientX - start.x;\n const dy = up.clientY - start.y;\n start = undefined;\n if (Math.max(Math.abs(dx), Math.abs(dy)) < 40) return;\n if (Math.abs(dx) > Math.abs(dy)) swiped(dx > 0 ? SWIPE.right : SWIPE.left);\n else swiped(dy > 0 ? SWIPE.down : SWIPE.up);\n });\n}\n"],"mappings":";;;AA2BA,IAAM,yBAAS,IAAI,QAAqB;AAExC,IAAM,SAAS,SAAsB;CACnC,MAAM,QAAQ,OAAO,IAAI,IAAI;CAC7B,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,0DAA0D;CACtF,OAAO;AACT;;AAGA,SAAgB,K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ACxB,IAAI,IAAI,WAAW,IAAI,GAAG,OAAO,IAAI,IAAI,MAAM,CAAC;CAChD,IAAI,IAAI,WAAW,QAAQ,GAAG,OAAO,QAAQ,IAAI,MAAM,CAAe,EAAE;CACxE,OAAO;AACT;AAEA,SAAS,aAAa,MAAY,MAAwB;CACxD,IAAI;CACJ,MAAM,eAAqB,aAAa,KAAK;CAC7C,KAAK,iBAAiB,qBAAqB;EACzC,OAAO;EACP,QAAQ,WAAW,MAAM,GAAG;CAC9B,CAAC;CACD,KAAK,MAAM,QAAQ;EAAC;EAAa;EAAgB;CAAe,GAAG,KAAK,iBAAiB,MAAM,MAAM;AACvG;AAEA,SAAS,OAAO,MAAY,QAA2C;CACrE,IAAI;CACJ,KAAK,iBAAiB,gBAAgB,SAAU,QAAQ;EAAE,GAAG,KAAK;EAAS,GAAG,KAAK;CAAQ,CAAE;CAC7F,KAAK,iBAAiB,cAAc,OAAO;EACzC,IAAI,CAAC,OAAO;EACZ,MAAM,KAAK,GAAG,UAAU,MAAM;EAC9B,MAAM,KAAK,GAAG,UAAU,MAAM;EAC9B,QAAQ,KAAA;EACR,IAAI,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,IAAI;EAC/C,IAAI,KAAK,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,GAAG,OAAO,KAAK,IAAI,MAAM,QAAQ,MAAM,IAAI;OACpE,OAAO,KAAK,IAAI,MAAM,OAAO,MAAM,EAAE;CAC5C,CAAC;AACH"}
@@ -1,5 +1,6 @@
1
1
  import { type Modules, type NativeOwner, type ServiceEntry } from './owner.js';
2
2
  import { Navigator } from './navigator.js';
3
+ import type { NativeDocument } from './dom.js';
3
4
  import { type Routes, WebRouter } from './web-router.js';
4
5
  export interface WebAppOptions {
5
6
  /** The first screen. */
@@ -20,4 +21,9 @@ export interface WebApp {
20
21
  router: WebRouter;
21
22
  }
22
23
  export declare function createWebApp(options: WebAppOptions): WebApp;
24
+ /** The app's element (light or dark, as the system is) with a frame in it, in `into`; and a document for its views. */
25
+ export declare function mountWebShell(into?: HTMLElement | string): {
26
+ nativeDocument: NativeDocument;
27
+ frame: HTMLElement;
28
+ };
23
29
  //# sourceMappingURL=web-app.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-app.d.ts","sourceRoot":"","sources":["../../src/web-app.ts"],"names":[],"mappings":"AASA,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,OAAO,EAAE,KAAK,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gHAAgH;IAChH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAsC3D"}
1
+ {"version":3,"file":"web-app.d.ts","sourceRoot":"","sources":["../../src/web-app.ts"],"names":[],"mappings":"AASA,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI/C,OAAO,EAAE,KAAK,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gHAAgH;IAChH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAiB3D;AAED,uHAAuH;AACvH,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG;IAAE,cAAc,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,CAoBjH"}
@@ -7,28 +7,12 @@ import { WebRouter } from "./web-router.js";
7
7
  import { installStyles } from "./web-styles.js";
8
8
  // src/web-app.ts
9
9
  function createWebApp(options) {
10
- installStyles();
11
- const container = typeof options.into === "string" ? document.querySelector(options.into) : options.into ?? document.body;
12
- if (!container) throw new Error(`[ember-nativescript] Nothing matches ${String(options.into)} to start the app in.`);
13
- const adapter = new WebAdapter();
14
- const nativeDocument = createDocument(adapter);
10
+ const { nativeDocument, frame } = mountWebShell(options.into);
15
11
  const owner = createOwner({
16
12
  services: options.services,
17
13
  modules: options.modules
18
14
  });
19
15
  const router = new WebRouter(options.routes ?? {}, options.base);
20
- const app = document.createElement("div");
21
- app.className = "ns-app ns-web ns-root";
22
- const dark = matchMedia("(prefers-color-scheme: dark)");
23
- const theme = () => {
24
- app.classList.toggle("ns-dark", dark.matches);
25
- app.classList.toggle("ns-light", !dark.matches);
26
- };
27
- theme();
28
- dark.addEventListener("change", theme);
29
- const frame = adapter.createView("frame");
30
- app.append(frame);
31
- container.append(app);
32
16
  const navigator = new Navigator(nativeDocument, new WebFrameHost(frame, router), owner);
33
17
  owner.register("service:navigator", navigator, { instantiate: false });
34
18
  router.navigator = navigator;
@@ -48,6 +32,30 @@ function createWebApp(options) {
48
32
  router
49
33
  };
50
34
  }
51
- export { createWebApp };
35
+ /** The app's element (light or dark, as the system is) with a frame in it, in `into`; and a document for its views. */
36
+ function mountWebShell(into) {
37
+ installStyles();
38
+ const container = typeof into === "string" ? document.querySelector(into) : into ?? document.body;
39
+ if (!container) throw new Error(`[ember-nativescript] Nothing matches ${String(into)} to start the app in.`);
40
+ const adapter = new WebAdapter();
41
+ const nativeDocument = createDocument(adapter);
42
+ const app = document.createElement("div");
43
+ app.className = "ns-app ns-web ns-root";
44
+ const dark = matchMedia("(prefers-color-scheme: dark)");
45
+ const theme = () => {
46
+ app.classList.toggle("ns-dark", dark.matches);
47
+ app.classList.toggle("ns-light", !dark.matches);
48
+ };
49
+ theme();
50
+ dark.addEventListener("change", theme);
51
+ const frame = adapter.createView("frame");
52
+ app.append(frame);
53
+ container.append(app);
54
+ return {
55
+ nativeDocument,
56
+ frame
57
+ };
58
+ }
59
+ export { createWebApp, mountWebShell };
52
60
 
53
61
  //# sourceMappingURL=web-app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-app.js","names":[],"sources":["../../src/web-app.ts"],"sourcesContent":["// Starts an Ember app on NativeScript's views in a browser, through the web adapter: the same screens and services as\n// on the phone, with URLs from a routes table.\n//\n// createWebApp({\n// main: Home,\n// services: { todos: Todos },\n// routes: { '/': Home, '/todos/:id': { screen: TodoScreen, args: ({ id }) => ({ id: Number(id) }) } },\n// });\n\nimport { createOwner, type Modules, type NativeOwner, type ServiceEntry } from './owner.ts';\nimport { Navigator } from './navigator.ts';\nimport { createDocument } from './render.ts';\nimport { WebAdapter } from './web-adapter.ts';\nimport { WebFrameHost } from './web-host.ts';\nimport { type Routes, WebRouter } from './web-router.ts';\nimport { installStyles } from './web-styles.ts';\n\nexport interface WebAppOptions {\n /** The first screen. */\n main: object;\n args?: Record<string, unknown>;\n services?: Record<string, ServiceEntry>;\n modules?: Modules;\n /** URLs for screens. Without routes, the URL stays as it is and the browser's back still goes back a screen. */\n routes?: Routes;\n /** Where the app is served from, such as `/app`. */\n base?: string;\n /** The element the app fills, or a selector for it. Defaults to the body. */\n into?: HTMLElement | string;\n}\n\nexport interface WebApp {\n owner: NativeOwner;\n navigator: Navigator;\n router: WebRouter;\n}\n\nexport function createWebApp(options: WebAppOptions): WebApp {\n installStyles();\n const container =\n typeof options.into === 'string'\n ? document.querySelector<HTMLElement>(options.into)\n : (options.into ?? document.body);\n if (!container) throw new Error(`[ember-nativescript] Nothing matches ${String(options.into)} to start the app in.`);\n\n const adapter = new WebAdapter();\n const nativeDocument = createDocument(adapter);\n const owner = createOwner({ services: options.services, modules: options.modules });\n const router = new WebRouter(options.routes ?? {}, options.base);\n\n const app = document.createElement('div');\n app.className = 'ns-app ns-web ns-root';\n const dark = matchMedia('(prefers-color-scheme: dark)');\n const theme = (): void => {\n app.classList.toggle('ns-dark', dark.matches);\n app.classList.toggle('ns-light', !dark.matches);\n };\n theme();\n dark.addEventListener('change', theme);\n const frame = adapter.createView('frame')!;\n app.append(frame);\n container.append(app);\n\n const navigator = new Navigator(nativeDocument, new WebFrameHost(frame, router), owner);\n owner.register('service:navigator', navigator, { instantiate: false });\n router.navigator = navigator;\n\n // The first screen, then the one the URL names on top of it, so back from a link goes to the first screen.\n const found = router.match(location.pathname);\n navigator.navigate(options.main, { args: options.args, name: 'main', animated: false });\n if (found && found.route.screen !== options.main) {\n navigator.navigate(found.route.screen, { args: router.argsFor(found.route, found.params), animated: false });\n }\n\n return { owner, navigator, router };\n}\n"],"mappings":";;;;;;;;AAqCA,SAAgB,aAAa,SAAgC;CAC3D,cAAc;CACd,MAAM,YACJ,OAAO,QAAQ,SAAS,WACpB,SAAS,cAA2B,QAAQ,IAAI,IAC/C,QAAQ,QAAQ,SAAS;CAChC,IAAI,CAAC,WAAW,MAAM,IAAI,MAAM,wCAAwC,OAAO,QAAQ,IAAI,EAAE,sBAAsB;CAEnH,MAAM,UAAU,IAAI,WAAW;CAC/B,MAAM,iBAAiB,eAAe,OAAO;CAC7C,MAAM,QAAQ,YAAY;EAAE,UAAU,QAAQ;EAAU,SAAS,QAAQ;CAAQ,CAAC;CAClF,MAAM,SAAS,IAAI,UAAU,QAAQ,UAAU,CAAC,GAAG,QAAQ,IAAI;CAE/D,MAAM,MAAM,SAAS,cAAc,KAAK;CACxC,IAAI,YAAY;CAChB,MAAM,OAAO,WAAW,8BAA8B;CACtD,MAAM,cAAoB;EACxB,IAAI,UAAU,OAAO,WAAW,KAAK,OAAO;EAC5C,IAAI,UAAU,OAAO,YAAY,CAAC,KAAK,OAAO;CAChD;CACA,MAAM;CACN,KAAK,iBAAiB,UAAU,KAAK;CACrC,MAAM,QAAQ,QAAQ,WAAW,OAAO;CACxC,IAAI,OAAO,KAAK;CAChB,UAAU,OAAO,GAAG;CAEpB,MAAM,YAAY,IAAI,UAAU,gBAAgB,IAAI,aAAa,OAAO,MAAM,GAAG,KAAK;CACtF,MAAM,SAAS,qBAAqB,WAAW,EAAE,aAAa,MAAM,CAAC;CACrE,OAAO,YAAY;CAGnB,MAAM,QAAQ,OAAO,MAAM,SAAS,QAAQ;CAC5C,UAAU,SAAS,QAAQ,MAAM;EAAE,MAAM,QAAQ;EAAM,MAAM;EAAQ,UAAU;CAAM,CAAC;CACtF,IAAI,SAAS,MAAM,MAAM,WAAW,QAAQ,MAC1C,UAAU,SAAS,MAAM,MAAM,QAAQ;EAAE,MAAM,OAAO,QAAQ,MAAM,OAAO,MAAM,MAAM;EAAG,UAAU;CAAM,CAAC;CAG7G,OAAO;EAAE;EAAO;EAAW;CAAO;AACpC"}
1
+ {"version":3,"file":"web-app.js","names":[],"sources":["../../src/web-app.ts"],"sourcesContent":["// Starts an Ember app on NativeScript's views in a browser, through the web adapter: the same screens and services as\n// on the phone, with URLs from a routes table.\n//\n// createWebApp({\n// main: Home,\n// services: { todos: Todos },\n// routes: { '/': Home, '/todos/:id': { screen: TodoScreen, args: ({ id }) => ({ id: Number(id) }) } },\n// });\n\nimport { createOwner, type Modules, type NativeOwner, type ServiceEntry } from './owner.ts';\nimport { Navigator } from './navigator.ts';\nimport type { NativeDocument } from './dom.ts';\nimport { createDocument } from './render.ts';\nimport { WebAdapter } from './web-adapter.ts';\nimport { WebFrameHost } from './web-host.ts';\nimport { type Routes, WebRouter } from './web-router.ts';\nimport { installStyles } from './web-styles.ts';\n\nexport interface WebAppOptions {\n /** The first screen. */\n main: object;\n args?: Record<string, unknown>;\n services?: Record<string, ServiceEntry>;\n modules?: Modules;\n /** URLs for screens. Without routes, the URL stays as it is and the browser's back still goes back a screen. */\n routes?: Routes;\n /** Where the app is served from, such as `/app`. */\n base?: string;\n /** The element the app fills, or a selector for it. Defaults to the body. */\n into?: HTMLElement | string;\n}\n\nexport interface WebApp {\n owner: NativeOwner;\n navigator: Navigator;\n router: WebRouter;\n}\n\nexport function createWebApp(options: WebAppOptions): WebApp {\n const { nativeDocument, frame } = mountWebShell(options.into);\n const owner = createOwner({ services: options.services, modules: options.modules });\n const router = new WebRouter(options.routes ?? {}, options.base);\n\n const navigator = new Navigator(nativeDocument, new WebFrameHost(frame, router), owner);\n owner.register('service:navigator', navigator, { instantiate: false });\n router.navigator = navigator;\n\n // The first screen, then the one the URL names on top of it, so back from a link goes to the first screen.\n const found = router.match(location.pathname);\n navigator.navigate(options.main, { args: options.args, name: 'main', animated: false });\n if (found && found.route.screen !== options.main) {\n navigator.navigate(found.route.screen, { args: router.argsFor(found.route, found.params), animated: false });\n }\n\n return { owner, navigator, router };\n}\n\n/** The app's element (light or dark, as the system is) with a frame in it, in `into`; and a document for its views. */\nexport function mountWebShell(into?: HTMLElement | string): { nativeDocument: NativeDocument; frame: HTMLElement } {\n installStyles();\n const container = typeof into === 'string' ? document.querySelector<HTMLElement>(into) : (into ?? document.body);\n if (!container) throw new Error(`[ember-nativescript] Nothing matches ${String(into)} to start the app in.`);\n\n const adapter = new WebAdapter();\n const nativeDocument = createDocument(adapter);\n const app = document.createElement('div');\n app.className = 'ns-app ns-web ns-root';\n const dark = matchMedia('(prefers-color-scheme: dark)');\n const theme = (): void => {\n app.classList.toggle('ns-dark', dark.matches);\n app.classList.toggle('ns-light', !dark.matches);\n };\n theme();\n dark.addEventListener('change', theme);\n const frame = adapter.createView('frame')!;\n app.append(frame);\n container.append(app);\n return { nativeDocument, frame };\n}\n"],"mappings":";;;;;;;;AAsCA,SAAgB,aAAa,SAAgC;CAC3D,MAAM,EAAE,gBAAgB,UAAU,cAAc,QAAQ,IAAI;CAC5D,MAAM,QAAQ,YAAY;EAAE,UAAU,QAAQ;EAAU,SAAS,QAAQ;CAAQ,CAAC;CAClF,MAAM,SAAS,IAAI,UAAU,QAAQ,UAAU,CAAC,GAAG,QAAQ,IAAI;CAE/D,MAAM,YAAY,IAAI,UAAU,gBAAgB,IAAI,aAAa,OAAO,MAAM,GAAG,KAAK;CACtF,MAAM,SAAS,qBAAqB,WAAW,EAAE,aAAa,MAAM,CAAC;CACrE,OAAO,YAAY;CAGnB,MAAM,QAAQ,OAAO,MAAM,SAAS,QAAQ;CAC5C,UAAU,SAAS,QAAQ,MAAM;EAAE,MAAM,QAAQ;EAAM,MAAM;EAAQ,UAAU;CAAM,CAAC;CACtF,IAAI,SAAS,MAAM,MAAM,WAAW,QAAQ,MAC1C,UAAU,SAAS,MAAM,MAAM,QAAQ;EAAE,MAAM,OAAO,QAAQ,MAAM,OAAO,MAAM,MAAM;EAAG,UAAU;CAAM,CAAC;CAG7G,OAAO;EAAE;EAAO;EAAW;CAAO;AACpC;;AAGA,SAAgB,cAAc,MAAqF;CACjH,cAAc;CACd,MAAM,YAAY,OAAO,SAAS,WAAW,SAAS,cAA2B,IAAI,IAAK,QAAQ,SAAS;CAC3G,IAAI,CAAC,WAAW,MAAM,IAAI,MAAM,wCAAwC,OAAO,IAAI,EAAE,sBAAsB;CAE3G,MAAM,UAAU,IAAI,WAAW;CAC/B,MAAM,iBAAiB,eAAe,OAAO;CAC7C,MAAM,MAAM,SAAS,cAAc,KAAK;CACxC,IAAI,YAAY;CAChB,MAAM,OAAO,WAAW,8BAA8B;CACtD,MAAM,cAAoB;EACxB,IAAI,UAAU,OAAO,WAAW,KAAK,OAAO;EAC5C,IAAI,UAAU,OAAO,YAAY,CAAC,KAAK,OAAO;CAChD;CACA,MAAM;CACN,KAAK,iBAAiB,UAAU,KAAK;CACrC,MAAM,QAAQ,QAAQ,WAAW,OAAO;CACxC,IAAI,OAAO,KAAK;CAChB,UAAU,OAAO,GAAG;CACpB,OAAO;EAAE;EAAgB;CAAM;AACjC"}
@@ -0,0 +1,10 @@
1
+ import type RouterService from '@ember/routing/router-service';
2
+ import { type RoutedApp, type StartApplicationOptions } from './application.js';
3
+ export interface WebApplicationOptions extends StartApplicationOptions {
4
+ /** The element the app fills, or a selector for it. Defaults to the body. */
5
+ into?: HTMLElement | string;
6
+ /** The document's title on each screen. */
7
+ title?: (router: RouterService) => string | undefined;
8
+ }
9
+ export declare function createWebApplication(options?: WebApplicationOptions): Promise<RoutedApp>;
10
+ //# sourceMappingURL=web-application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-application.d.ts","sourceRoot":"","sources":["../../src/web-application.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,uBAAuB,EAAkB,MAAM,kBAAkB,CAAC;AAIhG,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE,6EAA6E;IAC7E,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAC5B,2CAA2C;IAC3C,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,MAAM,GAAG,SAAS,CAAC;CACvD;AA2BD,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,SAAS,CAAC,CAU5F"}
@@ -0,0 +1,37 @@
1
+ import { startRoutedApp } from "./application.js";
2
+ import { mountWebShell } from "./web-app.js";
3
+ import { WebFrameHost } from "./web-host.js";
4
+ // src/web-application.ts
5
+ var RouterUrls = class {
6
+ router;
7
+ constructor(title) {
8
+ this.title = title;
9
+ }
10
+ pathFor() {
11
+ return this.router?.currentURL ?? void 0;
12
+ }
13
+ titleFor() {
14
+ return this.router && this.title?.(this.router);
15
+ }
16
+ href(path) {
17
+ return path;
18
+ }
19
+ open(pathname) {
20
+ const transition = this.router?.transitionTo(pathname + location.search);
21
+ return transition ? Promise.resolve(transition).catch(() => void 0) : void 0;
22
+ }
23
+ };
24
+ function createWebApplication(options = {}) {
25
+ const { nativeDocument, frame } = mountWebShell(options.into);
26
+ const urls = new RouterUrls(options.title);
27
+ return startRoutedApp(nativeDocument, new WebFrameHost(frame, urls), {
28
+ ...options,
29
+ url: options.url ?? location.pathname + location.search,
30
+ onBoot: (router) => {
31
+ urls.router = router;
32
+ }
33
+ });
34
+ }
35
+ export { createWebApplication };
36
+
37
+ //# sourceMappingURL=web-application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-application.js","names":["startRoutedApp","mountWebShell","WebFrameHost","RouterUrls","router","constructor","title","pathFor","currentURL","undefined","titleFor","href","path","open","pathname","transition","transitionTo","location","search","Promise","resolve","catch","createWebApplication","options","nativeDocument","frame","into","urls","url","onBoot"],"sources":["../../src/web-application.ts"],"sourcesContent":["// Opt-in: the full Ember Application in a browser (see application.ts). Ember's router gives each screen its URL:\n// the address bar follows it, the browser's back and forward move between screens, and a link opens its screen over\n// the home screen.\n//\n// createWebApplication({\n// modules: import.meta.glob('./{router.ts,routes,controllers,services,templates}/**', { eager: true }),\n// });\n\nimport type RouterService from '@ember/routing/router-service';\n\nimport { type RoutedApp, type StartApplicationOptions, startRoutedApp } from './application.ts';\nimport { mountWebShell } from './web-app.ts';\nimport { type ScreenUrls, WebFrameHost } from './web-host.ts';\n\nexport interface WebApplicationOptions extends StartApplicationOptions {\n /** The element the app fills, or a selector for it. Defaults to the body. */\n into?: HTMLElement | string;\n /** The document's title on each screen. */\n title?: (router: RouterService) => string | undefined;\n}\n\n// The URLs the web host keeps in the history: the router's own.\nclass RouterUrls implements ScreenUrls {\n router?: RouterService;\n\n constructor(readonly title?: (router: RouterService) => string | undefined) {}\n\n pathFor(): string | undefined {\n return this.router?.currentURL ?? undefined;\n }\n\n titleFor(): string | undefined {\n return this.router && this.title?.(this.router);\n }\n\n href(path: string): string {\n return path;\n }\n\n // The browser's forward button, or an entry from before a reload: the router goes there, and the screen follows.\n open(pathname: string): unknown {\n const transition = this.router?.transitionTo(pathname + location.search);\n return transition ? Promise.resolve(transition).catch(() => undefined) : undefined;\n }\n}\n\nexport function createWebApplication(options: WebApplicationOptions = {}): Promise<RoutedApp> {\n const { nativeDocument, frame } = mountWebShell(options.into);\n const urls = new RouterUrls(options.title);\n return startRoutedApp(nativeDocument, new WebFrameHost(frame, urls), {\n ...options,\n url: options.url ?? location.pathname + location.search,\n onBoot: (router) => {\n urls.router = router;\n },\n });\n}\n"],"mappings":";;;;AAsBA,IAAMG,aAAN,MAAuC;CACrCC;CAEAC,YAAqBC,OAAuD;EAAA,KAAvDA,QAAAA;CAAwD;CAE7EC,UAA8B;EAC5B,OAAO,KAAKH,QAAQI,cAAcC,KAAAA;CACpC;CAEAC,WAA+B;EAC7B,OAAO,KAAKN,UAAU,KAAKE,QAAQ,KAAKF,MAAM;CAChD;CAEAO,KAAKC,MAAsB;EACzB,OAAOA;CACT;CAGAC,KAAKC,UAA2B;EAC9B,MAAMC,aAAa,KAAKX,QAAQY,aAAaF,WAAWG,SAASC,MAAM;EACvE,OAAOH,aAAaI,QAAQC,QAAQL,UAAU,CAAC,CAACM,YAAYZ,KAAAA,CAAS,IAAIA,KAAAA;CAC3E;AACF;AAEA,SAAgBa,qBAAqBC,UAAiC,CAAC,GAAuB;CAC5F,MAAM,EAAEC,gBAAgBC,UAAUxB,cAAcsB,QAAQG,IAAI;CAC5D,MAAMC,OAAO,IAAIxB,WAAWoB,QAAQjB,KAAK;CACzC,OAAON,eAAewB,gBAAgB,IAAItB,aAAauB,OAAOE,IAAI,GAAG;EACnE,GAAGJ;EACHK,KAAKL,QAAQK,OAAOX,SAASH,WAAWG,SAASC;EACjDW,SAASzB,WAAW;GAClBuB,KAAKvB,SAASA;EAChB;CACF,CAAC;AACH"}
@@ -1,12 +1,19 @@
1
1
  import type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.js';
2
2
  import type { WebRouter } from './web-router.js';
3
+ /** What the host asks of a router: a WebRouter's routes table, or Ember's router in the full Application. */
4
+ export type ScreenUrls = Pick<WebRouter, 'pathFor' | 'titleFor' | 'href'> & {
5
+ /** Shows the screen a URL names. May finish later, as Ember's router does: the host waits for it. */
6
+ open(pathname: string, options: {
7
+ replace: boolean;
8
+ }): unknown;
9
+ };
3
10
  type View = HTMLElement;
4
11
  /** Moves between screens in a browser. With a router, it keeps the URL and the browser's history in step. */
5
12
  export declare class WebFrameHost implements FrameHost<View> {
6
13
  #private;
7
14
  readonly frame: View;
8
- readonly router?: WebRouter | undefined;
9
- constructor(frame: View, router?: WebRouter | undefined);
15
+ readonly router?: ScreenUrls | undefined;
16
+ constructor(frame: View, router?: ScreenUrls | undefined);
10
17
  show(page: View, options: ShowOptions): void;
11
18
  back(): void;
12
19
  showModal(view: View, options: ModalHostOptions): void;
@@ -1 +1 @@
1
- {"version":3,"file":"web-host.d.ts","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;AA0BxB,6GAA6G;AAC7G,qBAAa,YAAa,YAAW,SAAS,CAAC,IAAI,CAAC;;IAUhD,QAAQ,CAAC,KAAK,EAAE,IAAI;IACpB,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU;gBADnB,KAAK,EAAE,IAAI,EACX,MAAM,CAAC,EAAE,UAAU,YAAA;IAK9B,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IA+B5C,IAAI,IAAI,IAAI;IA4BZ,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAuBtD,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IA6E7C,6CAA6C;IAC7C,OAAO,IAAI,IAAI;CAGhB"}
@@ -52,6 +52,7 @@ var WebFrameHost = class {
52
52
  if (!leaving || !showing) return;
53
53
  showing.page.inert = false;
54
54
  showing.page.classList.add("ns-current");
55
+ if (showing.title) document.title = showing.title;
55
56
  emit(leaving.page, "navigatingFrom", { isBackNavigation: true });
56
57
  emit(showing.page, "navigatingTo", { isBackNavigation: true });
57
58
  const finish = () => {
@@ -120,10 +121,15 @@ var WebFrameHost = class {
120
121
  if (state.depth < this.#stack.length) while (this.#stack.length > Math.max(state.depth, 1)) this.#pop(this.#stack.length === state.depth + 1);
121
122
  else if (state.depth > this.#stack.length) {
122
123
  this.#restoring = true;
124
+ const done = () => {
125
+ this.#restoring = false;
126
+ };
127
+ let opening;
123
128
  try {
124
- this.router?.open(location.pathname, { replace: false });
129
+ opening = this.router?.open(location.pathname, { replace: false });
125
130
  } finally {
126
- this.#restoring = false;
131
+ if (isThenable(opening)) opening.then(done, done);
132
+ else done();
127
133
  }
128
134
  }
129
135
  };
@@ -135,7 +141,7 @@ var WebFrameHost = class {
135
141
  if (replace) history.replaceState(state, "", this.router.href(path));
136
142
  else history.pushState(state, "", this.router.href(path));
137
143
  const title = this.router.titleFor(options.screen);
138
- if (title) document.title = title;
144
+ if (title) document.title = this.#stack.at(-1).title = title;
139
145
  }
140
146
  #state(depth, modal = false) {
141
147
  return {
@@ -149,6 +155,7 @@ var WebFrameHost = class {
149
155
  removeEventListener("popstate", this.#onPopState);
150
156
  }
151
157
  };
158
+ var isThenable = (value) => value !== null && typeof value === "object" && typeof value.then === "function";
152
159
  function prefersLessMotion() {
153
160
  return matchMedia("(prefers-reduced-motion: reduce)").matches;
154
161
  }
@@ -1 +1 @@
1
- {"version":3,"file":"web-host.js","names":[],"sources":["../../src/web-host.ts"],"sourcesContent":["// Shows screens in a browser the way NativeScript's Frame does on a phone: a stack of pages, the new one sliding in\n// over the last, back sliding it out; modals as a sheet over the page. The root frame also keeps the browser's history\n// in step: each screen is a history entry, so the browser's back button is a back, and a screen with a route has its\n// own URL (see web-router.ts). Frames inside a screen (a tab's) keep their stack to themselves.\n\nimport type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.ts';\nimport { emit, emitLoaded } from './web-adapter.ts';\nimport type { WebRouter } from './web-router.ts';\n\ntype View = HTMLElement;\n\ninterface Entry {\n page: View;\n backstackVisible: boolean;\n}\n\ninterface Modal {\n view: View;\n backdrop: HTMLElement;\n onClose: (result?: unknown) => void;\n}\n\ninterface HistoryState {\n /** Which app's entries these are: entries from before a reload or a clearHistory aren't ours. */\n app: string;\n /** How many screens deep this entry is, from 1. */\n depth: number;\n modal?: boolean;\n}\n\nconst DURATION = 280;\nconst EASE = 'cubic-bezier(0.2, 0.8, 0.2, 1)';\n\n/** Moves between screens in a browser. With a router, it keeps the URL and the browser's history in step. */\nexport class WebFrameHost implements FrameHost<View> {\n readonly #stack: Entry[] = [];\n readonly #modals: Modal[] = [];\n #app = Math.random().toString(36).slice(2);\n // A back the host started itself through history.back(): its popstate is already handled.\n #ignorePops = 0;\n // Set while the browser's forward button re-opens a screen: the history entry is already there.\n #restoring = false;\n\n constructor(\n readonly frame: View,\n readonly router?: WebRouter,\n ) {\n if (router) addEventListener('popstate', this.#onPopState);\n }\n\n show(page: View, options: ShowOptions): void {\n const previous = this.#stack.at(-1);\n const dropped = options.clearHistory\n ? this.#stack.splice(0)\n : previous && !previous.backstackVisible\n ? [this.#stack.pop()!]\n : [];\n this.#stack.push({ page, backstackVisible: options.backstackVisible });\n\n if (this.router) this.#record(options);\n\n page.classList.add('ns-current');\n this.frame.append(page);\n emitLoaded(page);\n if (previous) emit(previous.page, 'navigatingFrom', { isBackNavigation: false });\n emit(page, 'navigatingTo', { isBackNavigation: false });\n\n const finish = (): void => {\n if (previous) {\n previous.page.classList.remove('ns-current');\n previous.page.inert = true;\n emit(previous.page, 'navigatedFrom', { isBackNavigation: false });\n }\n for (const entry of dropped) entry.page.remove();\n emit(page, 'navigatedTo', { isBackNavigation: false });\n };\n\n if (!options.animated || !previous || prefersLessMotion()) return finish();\n slide(page, ['100%', '0%'], previous.page, ['0%', '-30%']).then(finish);\n }\n\n back(): void {\n if (this.#stack.length < 2) return;\n // With history, the browser goes back and the popstate does the rest, as when the user presses back.\n if (this.router && history.state?.app === this.#app) history.back();\n else this.#pop(true);\n }\n\n // The top page leaves: it's destroyed by the navigator on navigatedFrom with isBackNavigation.\n #pop(animated: boolean): void {\n const leaving = this.#stack.pop();\n const showing = this.#stack.at(-1);\n if (!leaving || !showing) return;\n\n showing.page.inert = false;\n showing.page.classList.add('ns-current');\n emit(leaving.page, 'navigatingFrom', { isBackNavigation: true });\n emit(showing.page, 'navigatingTo', { isBackNavigation: true });\n\n const finish = (): void => {\n leaving.page.remove();\n emit(leaving.page, 'navigatedFrom', { isBackNavigation: true });\n emit(showing.page, 'navigatedTo', { isBackNavigation: true });\n };\n if (!animated || prefersLessMotion()) return finish();\n slide(leaving.page, ['0%', '100%'], showing.page, ['-30%', '0%']).then(finish);\n }\n\n showModal(view: View, options: ModalHostOptions): void {\n const backdrop = document.createElement('div');\n backdrop.className = 'ns-modal-backdrop';\n view.classList.add(options.fullscreen ? 'ns-modal-fullscreen' : 'ns-modal');\n backdrop.append(view);\n // A tap outside the sheet dismisses it, as a swipe down does on iOS.\n backdrop.addEventListener('click', (click) => {\n if (click.target === backdrop) this.#dismiss(view, undefined, true);\n });\n (this.frame.closest('.ns-app') ?? document.body).append(backdrop);\n this.#modals.push({ view, backdrop, onClose: options.onClose });\n\n if (this.router) history.pushState(this.#state(this.#stack.length, true), '', location.href);\n emitLoaded(view);\n if (options.animated && !prefersLessMotion()) {\n view.animate([{ transform: 'translateY(100%)' }, { transform: 'translateY(0)' }], {\n duration: DURATION,\n easing: EASE,\n });\n backdrop.animate([{ opacity: 0 }, { opacity: 1 }], { duration: DURATION });\n }\n }\n\n closeModal(view: View, result: unknown): void {\n this.#dismiss(view, result, true);\n }\n\n // Closes a modal. `fromApp` when the app or a tap closed it: then its history entry goes too.\n #dismiss(view: View, result: unknown, fromApp: boolean): void {\n const index = this.#modals.findIndex((modal) => modal.view === view);\n if (index === -1) return;\n const [modal] = this.#modals.splice(index, 1);\n if (fromApp && this.router && history.state?.modal && history.state.app === this.#app) {\n this.#ignorePops++;\n history.back();\n }\n const done = (): void => modal!.backdrop.remove();\n if (prefersLessMotion()) done();\n else\n Promise.all([\n modal!.view.animate([{ transform: 'translateY(0)' }, { transform: 'translateY(100%)' }], {\n duration: DURATION,\n easing: EASE,\n }).finished,\n modal!.backdrop.animate([{ opacity: 1 }, { opacity: 0 }], { duration: DURATION }).finished,\n ]).then(done, done);\n modal!.onClose(result);\n }\n\n // The browser's back or forward button.\n #onPopState = (event: PopStateEvent): void => {\n if (this.#ignorePops > 0) {\n this.#ignorePops--;\n return;\n }\n const state = event.state as HistoryState | null;\n const top = this.#modals.at(-1);\n if (top) return this.#dismiss(top.view, undefined, false);\n\n if (!state || state.app !== this.#app) {\n // An entry from before a reload or a clearHistory: there's no screen for it, so show what the URL says.\n this.router?.open(location.pathname, { replace: true });\n return;\n }\n if (state.depth < this.#stack.length) {\n while (this.#stack.length > Math.max(state.depth, 1)) this.#pop(this.#stack.length === state.depth + 1);\n } else if (state.depth > this.#stack.length) {\n // Forward: open the screen the URL names again.\n this.#restoring = true;\n try {\n this.router?.open(location.pathname, { replace: false });\n } finally {\n this.#restoring = false;\n }\n }\n };\n\n // The history entry for a screen just shown: pushed, or replacing the current one for the first screen, after\n // clearHistory, and when the browser already moved (forward).\n #record(options: ShowOptions): void {\n const path = this.router!.pathFor(options.screen) ?? location.pathname;\n const state = this.#state(this.#stack.length);\n const replace = this.#restoring || this.#stack.length === 1 || options.clearHistory;\n if (options.clearHistory) this.#app = state.app = Math.random().toString(36).slice(2);\n if (replace) history.replaceState(state, '', this.router!.href(path));\n else history.pushState(state, '', this.router!.href(path));\n const title = this.router!.titleFor(options.screen);\n if (title) document.title = title;\n }\n\n #state(depth: number, modal = false): HistoryState {\n return { app: this.#app, depth, ...(modal ? { modal } : {}) };\n }\n\n /** Stops following the browser's history. */\n destroy(): void {\n removeEventListener('popstate', this.#onPopState);\n }\n}\n\nfunction prefersLessMotion(): boolean {\n return matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\n// The incoming page slides over the outgoing one, which moves a little the other way, as UINavigationController does.\nfunction slide(moving: View, movingX: [string, string], under: View, underX: [string, string]): Promise<unknown> {\n const timing = { duration: DURATION, easing: EASE };\n const frames = ([from, to]: [string, string]) => [\n { transform: `translateX(${from})` },\n { transform: `translateX(${to})` },\n ];\n return Promise.all([\n moving.animate(frames(movingX), timing).finished,\n under.animate(frames(underX), timing).finished,\n ]).catch(() => undefined);\n}\n"],"mappings":";;AA8BA,IAAM,WAAW;AACjB,IAAM,OAAO;;AAGb,IAAa,eAAb,MAAqD;CAUxC;CACA;CAVF,SAAkB,CAAC;CACnB,UAAmB,CAAC;CAC7B,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;CAEzC,cAAc;CAEd,aAAa;CAEb,YACW,OACA,QACT;EAFS,KAAA,QAAA;EACA,KAAA,SAAA;EAET,IAAI,QAAQ,iBAAiB,YAAY,KAAK,WAA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AU,CAAC,MAAM,QAA0B,CAC/C,EAAE,WAAW,cAAc,KAAK,GAAG,GACnC,EAAE,WAAW,cAAc,GAAG,GAAG,CACnC;CACA,OAAO,QAAQ,IAAI,CACjB,OAAO,QAAQ,OAAO,OAAO,GAAG,MAAM,CAAC,CAAC,UACxC,MAAM,QAAQ,OAAO,MAAM,GAAG,MAAM,CAAC,CAAC,QACxC,CAAC,CAAC,CAAC,YAAY,KAAA,CAAS;AAC1B"}
1
+ {"version":3,"file":"web-host.js","names":[],"sources":["../../src/web-host.ts"],"sourcesContent":["// Shows screens in a browser the way NativeScript's Frame does on a phone: a stack of pages, the new one sliding in\n// over the last, back sliding it out; modals as a sheet over the page. The root frame also keeps the browser's history\n// in step: each screen is a history entry, so the browser's back button is a back, and a screen with a route has its\n// own URL (see web-router.ts). Frames inside a screen (a tab's) keep their stack to themselves.\n\nimport type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.ts';\nimport { emit, emitLoaded } from './web-adapter.ts';\nimport type { WebRouter } from './web-router.ts';\n\n/** What the host asks of a router: a WebRouter's routes table, or Ember's router in the full Application. */\nexport type ScreenUrls = Pick<WebRouter, 'pathFor' | 'titleFor' | 'href'> & {\n /** Shows the screen a URL names. May finish later, as Ember's router does: the host waits for it. */\n open(pathname: string, options: { replace: boolean }): unknown;\n};\n\ntype View = HTMLElement;\n\ninterface Entry {\n page: View;\n backstackVisible: boolean;\n /** The document's title on this screen, put back when a back shows it again. */\n title?: string;\n}\n\ninterface Modal {\n view: View;\n backdrop: HTMLElement;\n onClose: (result?: unknown) => void;\n}\n\ninterface HistoryState {\n /** Which app's entries these are: entries from before a reload or a clearHistory aren't ours. */\n app: string;\n /** How many screens deep this entry is, from 1. */\n depth: number;\n modal?: boolean;\n}\n\nconst DURATION = 280;\nconst EASE = 'cubic-bezier(0.2, 0.8, 0.2, 1)';\n\n/** Moves between screens in a browser. With a router, it keeps the URL and the browser's history in step. */\nexport class WebFrameHost implements FrameHost<View> {\n readonly #stack: Entry[] = [];\n readonly #modals: Modal[] = [];\n #app = Math.random().toString(36).slice(2);\n // A back the host started itself through history.back(): its popstate is already handled.\n #ignorePops = 0;\n // Set while the browser's forward button re-opens a screen: the history entry is already there.\n #restoring = false;\n\n constructor(\n readonly frame: View,\n readonly router?: ScreenUrls,\n ) {\n if (router) addEventListener('popstate', this.#onPopState);\n }\n\n show(page: View, options: ShowOptions): void {\n const previous = this.#stack.at(-1);\n const dropped = options.clearHistory\n ? this.#stack.splice(0)\n : previous && !previous.backstackVisible\n ? [this.#stack.pop()!]\n : [];\n this.#stack.push({ page, backstackVisible: options.backstackVisible });\n\n if (this.router) this.#record(options);\n\n page.classList.add('ns-current');\n this.frame.append(page);\n emitLoaded(page);\n if (previous) emit(previous.page, 'navigatingFrom', { isBackNavigation: false });\n emit(page, 'navigatingTo', { isBackNavigation: false });\n\n const finish = (): void => {\n if (previous) {\n previous.page.classList.remove('ns-current');\n previous.page.inert = true;\n emit(previous.page, 'navigatedFrom', { isBackNavigation: false });\n }\n for (const entry of dropped) entry.page.remove();\n emit(page, 'navigatedTo', { isBackNavigation: false });\n };\n\n if (!options.animated || !previous || prefersLessMotion()) return finish();\n slide(page, ['100%', '0%'], previous.page, ['0%', '-30%']).then(finish);\n }\n\n back(): void {\n if (this.#stack.length < 2) return;\n // With history, the browser goes back and the popstate does the rest, as when the user presses back.\n if (this.router && history.state?.app === this.#app) history.back();\n else this.#pop(true);\n }\n\n // The top page leaves: it's destroyed by the navigator on navigatedFrom with isBackNavigation.\n #pop(animated: boolean): void {\n const leaving = this.#stack.pop();\n const showing = this.#stack.at(-1);\n if (!leaving || !showing) return;\n\n showing.page.inert = false;\n showing.page.classList.add('ns-current');\n if (showing.title) document.title = showing.title;\n emit(leaving.page, 'navigatingFrom', { isBackNavigation: true });\n emit(showing.page, 'navigatingTo', { isBackNavigation: true });\n\n const finish = (): void => {\n leaving.page.remove();\n emit(leaving.page, 'navigatedFrom', { isBackNavigation: true });\n emit(showing.page, 'navigatedTo', { isBackNavigation: true });\n };\n if (!animated || prefersLessMotion()) return finish();\n slide(leaving.page, ['0%', '100%'], showing.page, ['-30%', '0%']).then(finish);\n }\n\n showModal(view: View, options: ModalHostOptions): void {\n const backdrop = document.createElement('div');\n backdrop.className = 'ns-modal-backdrop';\n view.classList.add(options.fullscreen ? 'ns-modal-fullscreen' : 'ns-modal');\n backdrop.append(view);\n // A tap outside the sheet dismisses it, as a swipe down does on iOS.\n backdrop.addEventListener('click', (click) => {\n if (click.target === backdrop) this.#dismiss(view, undefined, true);\n });\n (this.frame.closest('.ns-app') ?? document.body).append(backdrop);\n this.#modals.push({ view, backdrop, onClose: options.onClose });\n\n if (this.router) history.pushState(this.#state(this.#stack.length, true), '', location.href);\n emitLoaded(view);\n if (options.animated && !prefersLessMotion()) {\n view.animate([{ transform: 'translateY(100%)' }, { transform: 'translateY(0)' }], {\n duration: DURATION,\n easing: EASE,\n });\n backdrop.animate([{ opacity: 0 }, { opacity: 1 }], { duration: DURATION });\n }\n }\n\n closeModal(view: View, result: unknown): void {\n this.#dismiss(view, result, true);\n }\n\n // Closes a modal. `fromApp` when the app or a tap closed it: then its history entry goes too.\n #dismiss(view: View, result: unknown, fromApp: boolean): void {\n const index = this.#modals.findIndex((modal) => modal.view === view);\n if (index === -1) return;\n const [modal] = this.#modals.splice(index, 1);\n if (fromApp && this.router && history.state?.modal && history.state.app === this.#app) {\n this.#ignorePops++;\n history.back();\n }\n const done = (): void => modal!.backdrop.remove();\n if (prefersLessMotion()) done();\n else\n Promise.all([\n modal!.view.animate([{ transform: 'translateY(0)' }, { transform: 'translateY(100%)' }], {\n duration: DURATION,\n easing: EASE,\n }).finished,\n modal!.backdrop.animate([{ opacity: 1 }, { opacity: 0 }], { duration: DURATION }).finished,\n ]).then(done, done);\n modal!.onClose(result);\n }\n\n // The browser's back or forward button.\n #onPopState = (event: PopStateEvent): void => {\n if (this.#ignorePops > 0) {\n this.#ignorePops--;\n return;\n }\n const state = event.state as HistoryState | null;\n const top = this.#modals.at(-1);\n if (top) return this.#dismiss(top.view, undefined, false);\n\n if (!state || state.app !== this.#app) {\n // An entry from before a reload or a clearHistory: there's no screen for it, so show what the URL says.\n this.router?.open(location.pathname, { replace: true });\n return;\n }\n if (state.depth < this.#stack.length) {\n while (this.#stack.length > Math.max(state.depth, 1)) this.#pop(this.#stack.length === state.depth + 1);\n } else if (state.depth > this.#stack.length) {\n // Forward: open the screen the URL names again. Its history entry is already there, so the screen replaces it,\n // whenever it arrives.\n this.#restoring = true;\n const done = (): void => {\n this.#restoring = false;\n };\n let opening: unknown;\n try {\n opening = this.router?.open(location.pathname, { replace: false });\n } finally {\n if (isThenable(opening)) opening.then(done, done);\n else done();\n }\n }\n };\n\n // The history entry for a screen just shown: pushed, or replacing the current one for the first screen, after\n // clearHistory, and when the browser already moved (forward).\n #record(options: ShowOptions): void {\n const path = this.router!.pathFor(options.screen) ?? location.pathname;\n const state = this.#state(this.#stack.length);\n const replace = this.#restoring || this.#stack.length === 1 || options.clearHistory;\n if (options.clearHistory) this.#app = state.app = Math.random().toString(36).slice(2);\n if (replace) history.replaceState(state, '', this.router!.href(path));\n else history.pushState(state, '', this.router!.href(path));\n const title = this.router!.titleFor(options.screen);\n if (title) document.title = this.#stack.at(-1)!.title = title;\n }\n\n #state(depth: number, modal = false): HistoryState {\n return { app: this.#app, depth, ...(modal ? { modal } : {}) };\n }\n\n /** Stops following the browser's history. */\n destroy(): void {\n removeEventListener('popstate', this.#onPopState);\n }\n}\n\nconst isThenable = (value: unknown): value is PromiseLike<unknown> =>\n value !== null && typeof value === 'object' && typeof (value as PromiseLike<unknown>).then === 'function';\n\nfunction prefersLessMotion(): boolean {\n return matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\n// The incoming page slides over the outgoing one, which moves a little the other way, as UINavigationController does.\nfunction slide(moving: View, movingX: [string, string], under: View, underX: [string, string]): Promise<unknown> {\n const timing = { duration: DURATION, easing: EASE };\n const frames = ([from, to]: [string, string]) => [\n { transform: `translateX(${from})` },\n { transform: `translateX(${to})` },\n ];\n return Promise.all([\n moving.animate(frames(movingX), timing).finished,\n under.animate(frames(underX), timing).finished,\n ]).catch(() => undefined);\n}\n"],"mappings":";;AAsCA,IAAM,WAAW;AACjB,IAAM,OAAO;;AAGb,IAAa,eAAb,MAAqD;CAUxC;CACA;CAVF,SAAkB,CAAC;CACnB,UAAmB,CAAC;CAC7B,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;CAEzC,cAAc;CAEd,aAAa;CAEb,YACW,OACA,QACT;EAFS,KAAA,QAAA;EACA,KAAA,SAAA;EAET,IAAI,QAAQ,iBAAiB,YAAY,KAAK,WAAW;CAC3D;CAEA,KAAK,MAAY,SAA4B;EAC3C,MAAM,WAAW,KAAK,OAAO,GAAG,EAAE;EAClC,MAAM,UAAU,QAAQ,eACpB,KAAK,OAAO,OAAO,CAAC,IACpB,YAAY,CAAC,SAAS,mBACpB,CAAC,KAAK,OAAO,IAAI,CAAE,IACnB,CAAC;EACP,KAAK,OAAO,KAAK;GAAE;GAAM,kBAAkB,QAAQ;EAAiB,CAAC;EAErE,IAAI,KAAK,QAAQ,KAAK,QAAQ,OAAO;EAErC,KAAK,UAAU,IAAI,YAAY;EAC/B,KAAK,MAAM,OAAO,IAAI;EACtB,WAAW,IAAI;EACf,IAAI,UAAU,KAAK,SAAS,MAAM,kBAAkB,EAAE,kBAAkB,MAAM,CAAC;EAC/E,KAAK,MAAM,gBAAgB,EAAE,kBAAkB,MAAM,CAAC;EAEtD,MAAM,eAAqB;GACzB,IAAI,UAAU;IACZ,SAAS,KAAK,UAAU,OAAO,YAAY;IAC3C,SAAS,KAAK,QAAQ;IACtB,KAAK,SAAS,MAAM,iBAAiB,EAAE,kBAAkB,MAAM,CAAC;GAClE;GACA,KAAK,MAAM,SAAS,SAAS,MAAM,KAAK,OAAO;GAC/C,KAAK,MAAM,eAAe,EAAE,kBAAkB,MAAM,CAAC;EACvD;EAEA,IAAI,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AC;EACpF,IAAI,SAAS,QAAQ,aAAa,OAAO,IAAI,KAAK,OAAQ,KAAK,IAAI,CAAC;OAC/D,QAAQ,UAAU,OAAO,IAAI,KAAK,OAAQ,KAAK,IAAI,CAAC;EACzD,MAAM,QAAQ,KAAK,OAAQ,SAAS,QAAQ,MAAM;EAClD,IAAI,OAAO,SAAS,QAAQ,KAAK,OAAO,GAAG,EAAE,CAAC,CAAE,QAAQ;CAC1D;CAEA,OAAO,OAAe,QAAQ,OAAqB;EACjD,OAAO;GAAE,KAAK,KAAK;GAAM;GAAO,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;EAAG;CAC9D;;CAGA,UAAgB;EACd,oBAAoB,YAAY,KAAK,WAAW;CAClD;AACF;AAEA,IAAM,cAAc,UAClB,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAQ,MAA+B,SAAS;AAEjG,SAAS,oBAA6B;CACpC,OAAO,WAAW,kCAAkC,CAAC,CAAC;AACxD;AAGA,SAAS,MAAM,QAAc,SAA2B,OAAa,QAA4C;CAC/G,MAAM,SAAS;EAAE,UAAU;EAAU,QAAQ;CAAK;CAClD,MAAM,UAAU,CAAC,MAAM,QAA0B,CAC/C,EAAE,WAAW,cAAc,KAAK,GAAG,GACnC,EAAE,WAAW,cAAc,GAAG,GAAG,CACnC;CACA,OAAO,QAAQ,IAAI,CACjB,OAAO,QAAQ,OAAO,OAAO,GAAG,MAAM,CAAC,CAAC,UACxC,MAAM,QAAQ,OAAO,MAAM,GAAG,MAAM,CAAC,CAAC,QACxC,CAAC,CAAC,CAAC,YAAY,KAAA,CAAS;AAC1B"}
@@ -0,0 +1,18 @@
1
+ import type { ListBinding, ListOptions } from './adapter.js';
2
+ type View = HTMLElement;
3
+ export interface WebListHooks {
4
+ /** A new, empty container for a cell. */
5
+ createCell(): View;
6
+ /** Raises a NativeScript event on the list (itemTap, loadMoreItems). */
7
+ emit(name: string, data?: Record<string, unknown>): void;
8
+ }
9
+ export declare class WebList implements ListBinding {
10
+ #private;
11
+ constructor(view: View, show: (container: View, index: number) => void, options: ListOptions, hooks: WebListHooks);
12
+ setCount(count: number): void;
13
+ release(): void;
14
+ /** How many cells exist, on screen or waiting in a pool. */
15
+ get cellCount(): number;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=web-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-list.d.ts","sourceRoot":"","sources":["../../src/web-list.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE7D,KAAK,IAAI,GAAG,WAAW,CAAC;AAexB,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,UAAU,IAAI,IAAI,CAAC;IACnB,wEAAwE;IACxE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC1D;AAED,qBAAa,OAAQ,YAAW,WAAW;;gBA2B7B,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY;IA+BjH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAe7B,OAAO,IAAI,IAAI;IAOf,4DAA4D;IAC5D,IAAI,SAAS,IAAI,MAAM,CAItB;CAyKF"}