@inglorious/web 6.28.0 → 6.29.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 (36) hide show
  1. package/README.md +257 -200
  2. package/package.json +49 -37
  3. package/src/device/biometrics/index.js +86 -0
  4. package/src/device/compass/handlers.js +163 -0
  5. package/src/{sensors → device}/element-size/handlers.js +2 -2
  6. package/src/device/geolocation/index.js +120 -0
  7. package/src/device/local-notifications/index.js +133 -0
  8. package/src/{sensors → device}/media-query/handlers.js +2 -2
  9. package/src/{sensors → device}/network-status/handlers.js +1 -1
  10. package/src/{sensors → device}/page-visibility/handlers.js +1 -1
  11. package/src/{native → device}/share/index.js +1 -1
  12. package/src/device/storage/index.js +61 -0
  13. package/src/native/index.js +0 -32
  14. package/types/device/biometrics.d.ts +51 -0
  15. package/types/{sensors → device}/compass.d.ts +0 -2
  16. package/types/{sensors → device}/geolocation.d.ts +25 -7
  17. package/types/device/local-notifications.d.ts +76 -0
  18. package/types/device/storage.d.ts +30 -0
  19. package/types/native/index.d.ts +0 -19
  20. package/src/sensors/compass/handlers.js +0 -209
  21. package/src/sensors/geolocation/handlers.js +0 -168
  22. package/src/sensors/geolocation/index.js +0 -3
  23. /package/src/{sensors → device}/compass/index.js +0 -0
  24. /package/src/{sensors → device}/element-size/index.js +0 -0
  25. /package/src/{native → device}/haptics/index.js +0 -0
  26. /package/src/{keyboard → device/keyboard}/index.js +0 -0
  27. /package/src/{sensors → device}/media-query/index.js +0 -0
  28. /package/src/{sensors → device}/network-status/index.js +0 -0
  29. /package/src/{sensors → device}/page-visibility/index.js +0 -0
  30. /package/types/{sensors → device}/element-size.d.ts +0 -0
  31. /package/types/{native → device}/haptics.d.ts +0 -0
  32. /package/types/{keyboard.d.ts → device/keyboard.d.ts} +0 -0
  33. /package/types/{sensors → device}/media-query.d.ts +0 -0
  34. /package/types/{sensors → device}/network-status.d.ts +0 -0
  35. /package/types/{sensors → device}/page-visibility.d.ts +0 -0
  36. /package/types/{native → device}/share.d.ts +0 -0
package/README.md CHANGED
@@ -1276,16 +1276,21 @@ For ready-made UI primitives (controls, data display, navigation, feedback, layo
1276
1276
 
1277
1277
  ---
1278
1278
 
1279
- ## Geolocation
1279
+ ## Device
1280
1280
 
1281
- `@inglorious/web` includes a `Geolocation` type for keeping browser geolocation state inside the store.
1281
+ `@inglorious/web/device/*` holds what the phone or browser can sense or do. Each works in a browser through its web API. In a native app, the ones with a Capacitor plugin use it, once you hand it over as `plugin`. Entity types answer to their own entity (`#id:event`) and keep listeners, observers and watches outside it. Besides the ones below, `ElementSize`, `MediaQuery`, `NetworkStatus` and `PageVisibility` follow an element's size, a media query, the connection and the page's visibility.
1282
+
1283
+ ### Geolocation
1284
+
1285
+ `createGeolocation` from `@inglorious/web/device/geolocation` returns the type that keeps the device's position in the store. In a native app it uses [`@capacitor/geolocation`](https://capacitorjs.com/docs/apis/geolocation) when given as `plugin`, so iOS asks for the location once, for the app; elsewhere it uses `navigator.geolocation`.
1282
1286
 
1283
1287
  ```javascript
1284
1288
  import { createStore } from "@inglorious/store"
1285
- import { Geolocation } from "@inglorious/web/geolocation"
1289
+ import { Geolocation as GeolocationPlugin } from "@capacitor/geolocation"
1290
+ import { createGeolocation } from "@inglorious/web/device/geolocation"
1286
1291
 
1287
1292
  const store = createStore({
1288
- types: { Geolocation },
1293
+ types: { Geolocation: createGeolocation({ plugin: GeolocationPlugin }) },
1289
1294
  autoCreateEntities: true,
1290
1295
  })
1291
1296
 
@@ -1295,12 +1300,11 @@ store.getState().geolocation
1295
1300
 
1296
1301
  The entity state contains:
1297
1302
 
1298
- - `isSupported` — whether `navigator.geolocation` is available
1303
+ - `isSupported` — whether the position can be read here
1299
1304
  - `isLoading` — whether a current-position request or first watch result is pending
1300
1305
  - `isWatching` — whether a geolocation watch is active
1301
1306
  - `position` — the latest normalized `{ coords, timestamp }` value
1302
1307
  - `error` — the latest normalized `{ code, message }` error
1303
- - `watchId` — the active browser watch id, or `null`
1304
1308
 
1305
1309
  Events:
1306
1310
 
@@ -1309,16 +1313,16 @@ Events:
1309
1313
  - `geolocationUnwatch` — stop the active watch
1310
1314
 
1311
1315
  ```javascript
1312
- api.notify("geolocationRequest", {
1316
+ api.notify("#geolocation:geolocationRequest", {
1313
1317
  enableHighAccuracy: true,
1314
1318
  timeout: 5000,
1315
1319
  })
1316
1320
 
1317
- api.notify("geolocationWatch")
1318
- api.notify("geolocationUnwatch")
1321
+ api.notify("#geolocation:geolocationWatch")
1322
+ api.notify("#geolocation:geolocationUnwatch")
1319
1323
  ```
1320
1324
 
1321
- ### Example: Show current location
1325
+ #### Example: Show current location
1322
1326
 
1323
1327
  ```javascript
1324
1328
  import { mount, html } from "@inglorious/web"
@@ -1347,17 +1351,17 @@ const renderApp = (api) => {
1347
1351
  <p>Error: ${geolocation.error ? geolocation.error.message : "none"}</p>
1348
1352
  <button
1349
1353
  @click=${() =>
1350
- api.notify("geolocationRequest", {
1354
+ api.notify("#geolocation:geolocationRequest", {
1351
1355
  enableHighAccuracy: true,
1352
1356
  timeout: 5000,
1353
1357
  })}
1354
1358
  >
1355
1359
  Request Current Position
1356
1360
  </button>
1357
- <button @click=${() => api.notify("geolocationWatch")}>
1361
+ <button @click=${() => api.notify("#geolocation:geolocationWatch")}>
1358
1362
  Start Watch
1359
1363
  </button>
1360
- <button @click=${() => api.notify("geolocationUnwatch")}>
1364
+ <button @click=${() => api.notify("#geolocation:geolocationUnwatch")}>
1361
1365
  Stop Watch
1362
1366
  </button>
1363
1367
  </section>
@@ -1367,9 +1371,7 @@ const renderApp = (api) => {
1367
1371
  mount(store, renderApp, document.getElementById("root"))
1368
1372
  ```
1369
1373
 
1370
- ---
1371
-
1372
- ## Compass
1374
+ ### Compass
1373
1375
 
1374
1376
  `@inglorious/web` also includes a `Compass` type for managing device orientation and heading state inside the store.
1375
1377
 
@@ -1407,12 +1409,12 @@ Events:
1407
1409
  - `compassError` — store a normalized compass error
1408
1410
 
1409
1411
  ```javascript
1410
- api.notify("compassPermissionsRequest")
1411
- api.notify("compassWatch")
1412
- api.notify("compassUnwatch")
1412
+ api.notify("#compass:compassPermissionsRequest")
1413
+ api.notify("#compass:compassWatch")
1414
+ api.notify("#compass:compassUnwatch")
1413
1415
  ```
1414
1416
 
1415
- ### Example: Show heading and request permission
1417
+ #### Example: Show heading and request permission
1416
1418
 
1417
1419
  ```javascript
1418
1420
  import { mount, html } from "@inglorious/web"
@@ -1439,11 +1441,15 @@ const renderApp = (api) => {
1439
1441
  }
1440
1442
  </p>
1441
1443
  <p>Error: ${compass.error ? compass.error.message : "none"}</p>
1442
- <button @click=${() => api.notify("compassPermissionsRequest")}>
1444
+ <button @click=${() => api.notify("#compass:compassPermissionsRequest")}>
1443
1445
  Request Permission
1444
1446
  </button>
1445
- <button @click=${() => api.notify("compassWatch")}>Start Compass</button>
1446
- <button @click=${() => api.notify("compassUnwatch")}>Stop Compass</button>
1447
+ <button @click=${() => api.notify("#compass:compassWatch")}>
1448
+ Start Compass
1449
+ </button>
1450
+ <button @click=${() => api.notify("#compass:compassUnwatch")}>
1451
+ Stop Compass
1452
+ </button>
1447
1453
  </section>
1448
1454
  `
1449
1455
  }
@@ -1451,185 +1457,163 @@ const renderApp = (api) => {
1451
1457
  mount(store, renderApp, document.getElementById("root"))
1452
1458
  ```
1453
1459
 
1454
- ---
1455
-
1456
- ## PWA Updates
1457
-
1458
- `@inglorious/web/pwa` keeps an installed PWA on its latest version. It works with the service worker that [`vite-plugin-pwa`](https://vite-pwa-org.netlify.app/) generates, and `@inglorious/create-app --pwa` sets it up for you.
1459
-
1460
- Updates are not optional. A new version downloads in the background, and is applied with a reload at the first moment nobody is in the middle of something:
1460
+ ### Share
1461
1461
 
1462
- - at launch, before anything is touched;
1463
- - each time the app goes to the background or comes back to the foreground.
1462
+ `@inglorious/web/device/share` is the type behind a share button. `share` hands a title, a text, a link or a file to whatever the device does best, and the entity says what happened:
1464
1463
 
1465
- It also checks for a new version every hour and on every return to the foreground: a phone suspends an installed PWA rather than closing it, so the browser's own check may never come.
1464
+ - in a native app, the system's share sheet, through [`@capacitor/share`](https://capacitorjs.com/docs/apis/share) when you hand it over;
1465
+ - in a browser, a file (a `url` with a `fileName`) downloads, since a browser has nowhere better to put it;
1466
+ - otherwise the browser's share sheet where there is one (Web Share API), else the link is copied.
1466
1467
 
1467
1468
  ```javascript
1468
- import { isNative } from "@inglorious/web/native"
1469
- import { watchPwaUpdate } from "@inglorious/web/pwa"
1470
- import { registerSW } from "virtual:pwa-register"
1469
+ import { Share } from "@capacitor/share"
1470
+ import { createShare } from "@inglorious/web/device/share"
1471
1471
 
1472
- if (!isNative()) {
1473
- registerSW({
1474
- onRegisteredSW(url, registration) {
1475
- if (registration) watchPwaUpdate(registration)
1476
- },
1477
- })
1478
- }
1472
+ const types = { Share: createShare({ plugin: Share }) }
1473
+
1474
+ api.notify("#share:share", {
1475
+ title: "My job",
1476
+ url: "https://example.com/jobs/1",
1477
+ })
1478
+ api.notify("#share:share", {
1479
+ title: "Wedding",
1480
+ url: icsUrl,
1481
+ fileName: "wedding.ics",
1482
+ })
1479
1483
  ```
1480
1484
 
1481
- Configure the plugin with `registerType: "prompt"` and `injectRegister: false`: the generated worker then waits for the `SKIP_WAITING` message this module sends, instead of taking over on its own.
1485
+ `result` is `"shared"`, `"downloaded"`, `"copied"` or `"cancelled"`: closing the sheet is not an error. `status` and `error` (`"unsupported"` or `"failed"`) come from `handleRequest`. `canShare` says whether a link can be shared at all, to hide the button where it can't.
1482
1486
 
1483
- ### Offering "Update now"
1487
+ ### Haptics
1484
1488
 
1485
- A version that lands while someone is using the app waits for the next trip to the background. To offer it right away, pass the store and register the `PwaUpdate` type:
1489
+ `@inglorious/web/device/haptics` plays taps the user can feel. In a native app it uses the system's haptics through [`@capacitor/haptics`](https://capacitorjs.com/docs/apis/haptics), once you hand the plugin over. Elsewhere it vibrates where the browser can (Chrome on Android), once the user has tapped the page; iOS browsers stay silent. Every call returns whether it played.
1486
1490
 
1487
1491
  ```javascript
1488
- import { PwaUpdate, watchPwaUpdate } from "@inglorious/web/pwa"
1492
+ import { Haptics } from "@capacitor/haptics"
1493
+ import { haptics } from "@inglorious/web/device/haptics"
1489
1494
 
1490
- const store = createStore({ types: { PwaUpdate }, autoCreateEntities: true })
1495
+ haptics.use(Haptics)
1491
1496
 
1492
- watchPwaUpdate(registration, store)
1497
+ haptics.selection() // a toggle flipped, a threshold crossed
1498
+ haptics.impact("heavy") // "light", "medium" (default) or "heavy"
1499
+ haptics.notification("error") // "success" (default), "warning" or "error"
1493
1500
  ```
1494
1501
 
1495
- The `pwaUpdate` entity contains:
1502
+ Inglorious UI plays them too: `PullToRefresh` gives a tick when letting go would refresh.
1496
1503
 
1497
- - `isUpdateReady` — a new version is waiting for the next reload
1504
+ ### Local Notifications
1498
1505
 
1499
- Events:
1500
-
1501
- - `pwaUpdateReady` — sent by `watchPwaUpdate` when a version lands mid-session
1502
- - `pwaUpdateApply` — moves over to the waiting version now, reloading the page
1506
+ `createLocalNotifications` from `@inglorious/web/device/local-notifications` is the type behind reminders the device shows on its own, such as "your job starts in an hour". In a native app they go through [`@capacitor/local-notifications`](https://capacitorjs.com/docs/apis/local-notifications), once you hand the plugin over, and show even with the app closed. In a browser they show only while the page is open, through the Notification API.
1503
1507
 
1504
1508
  ```javascript
1505
- const renderUpdate = (api) =>
1506
- when(
1507
- api.getEntity("pwaUpdate").isUpdateReady,
1508
- () =>
1509
- html`<button @click=${() => api.notify("#pwaUpdate:pwaUpdateApply")}>
1510
- Update now
1511
- </button>`,
1512
- )
1509
+ import { LocalNotifications } from "@capacitor/local-notifications"
1510
+ import { createLocalNotifications } from "@inglorious/web/device/local-notifications"
1511
+
1512
+ const types = {
1513
+ Reminders: createLocalNotifications({ plugin: LocalNotifications }),
1514
+ }
1515
+ const entities = { reminders: { type: "Reminders" } }
1516
+
1517
+ api.notify("#reminders:localNotificationSchedule", {
1518
+ id: 1,
1519
+ title: "Wedding in an hour",
1520
+ body: "Villa Erba, Cernobbio",
1521
+ at: new Date(start - HOUR),
1522
+ url: "/jobs/1",
1523
+ })
1524
+ api.notify("#reminders:localNotificationCancel", 1)
1513
1525
  ```
1514
1526
 
1515
- Inglorious UI's `Snackbar` is the usual place for it. `watchPwaUpdate` takes `{ id, checkEveryMs }` as a third argument, to announce to an entity with another id or to check more or less often, and returns a function that stops watching.
1527
+ The entity's `permission` is `"granted"`, `"denied"`, `"prompt"` or `"unsupported"`, and `null` until the device says. `localNotificationsAsk` brings up the system's dialog: send it from a tap, which a browser requires.
1516
1528
 
1517
- ---
1529
+ An `id` is a whole number, which the app chooses so it can cancel the reminder later. A tap on a reminder with a `url` navigates there, through `onTap(url, api)` in the config, by default `#router:navigate`.
1518
1530
 
1519
- ## Native App Updates
1531
+ #### Secrets
1520
1532
 
1521
- A Capacitor app carries its web code inside the binary, so only the stores update it. `@inglorious/web/native/update` makes an update mandatory: the app reads a minimum build per platform, and a build below it is blocked until the user updates. `@inglorious/create-app --mobile --push` sets it up with Supabase.
1533
+ `createSecureStorage` keeps what must stay private, such as a session's tokens, in the Keychain (iOS) or Keystore (Android), through the same [`@capgo/capacitor-native-biometric`](https://github.com/Cap-go/capacitor-native-biometric) plugin. A browser has nothing safer, so there it uses `localStorage`. It works wherever `createNativeStorage` does:
1522
1534
 
1523
1535
  ```javascript
1524
- import { App } from "@capacitor/app"
1525
- import {
1526
- createNativeUpdate,
1527
- watchNativeUpdate,
1528
- } from "@inglorious/web/native/update"
1536
+ import { NativeBiometric } from "@capgo/capacitor-native-biometric"
1537
+ import { createSecureStorage } from "@inglorious/web/device/storage"
1529
1538
 
1530
- const types = { NativeUpdate: [createNativeUpdate({ adapter }), template] }
1531
- const entities = { nativeUpdate: { type: "NativeUpdate" } }
1539
+ const secrets = createSecureStorage({ plugin: NativeBiometric })
1532
1540
 
1533
- watchNativeUpdate(App, store)
1541
+ createClient(url, key, { auth: { storage: secrets } })
1534
1542
  ```
1535
1543
 
1536
- `watchNativeUpdate` reads the installed build at launch and on every resume, and does nothing outside a native app. `{ id }` as a third argument notifies another entity; it returns a function that stops watching.
1537
-
1538
- The adapter says where the minimum lives: `requirement(platform)` resolves to `{ minBuild, storeUrl }`, or `null` for no minimum. `supabaseNativeUpdate` from `@inglorious/supabase` reads it from a table.
1544
+ ### Biometrics
1539
1545
 
1540
- The `nativeUpdate` entity contains:
1546
+ `createBiometrics` from `@inglorious/web/device/biometrics` is the type behind "unlock with Face ID". In a native app, `verify` shows the system's biometric prompt through [`@capgo/capacitor-native-biometric`](https://github.com/Cap-go/capacitor-native-biometric), once you hand the plugin over. A browser has no equivalent, so there it is never available.
1541
1547
 
1542
- - `isUpdateRequired` — the installed build is below the minimum
1543
- - `storeUrl` — where the update button goes, or `null`
1548
+ ```javascript
1549
+ import { NativeBiometric } from "@capgo/capacitor-native-biometric"
1550
+ import { createBiometrics } from "@inglorious/web/device/biometrics"
1544
1551
 
1545
- Events:
1552
+ const types = { Biometrics: createBiometrics({ plugin: NativeBiometric }) }
1553
+ const entities = { biometrics: { type: "Biometrics" } }
1546
1554
 
1547
- - `nativeUpdateCheck` — `{ platform, build }`, sent by `watchNativeUpdate`
1548
- - `nativeUpdateApply` — opens the store
1555
+ api.notify("#biometrics:verify", { reason: "Unlock your account" })
1556
+ ```
1549
1557
 
1550
- A failed check keeps the last answer, so nobody is blocked by being offline. Render the whole app as the update page while `isUpdateRequired`, and raise the minimum only once the new build is live in that store.
1558
+ - `isAvailable`: whether the device can verify, to hide the button otherwise.
1559
+ - `biometryType`: `"face"`, `"fingerprint"`, `"iris"`, `"multiple"` or `"passcode"`, to name it.
1560
+ - `result`: `"verified"` or `"cancelled"`. Closing the prompt is not an error.
1561
+ - `status` and `error`: those of `handleRequest`, with `error` `"unavailable"` or `"failed"`.
1551
1562
 
1552
- ---
1563
+ On iOS, Face ID needs an `NSFaceIDUsageDescription` in `Info.plist`.
1553
1564
 
1554
- ## Live Updates
1565
+ ### Keyboard
1555
1566
 
1556
- A store release is only needed for native changes. `@inglorious/web/native/live-update` replaces the web code inside a Capacitor app with a newer published bundle, through [`@capawesome/capacitor-live-update`](https://capawesome.io/plugins/live-update/), whose open source plugin downloads from any URL. `publishLiveUpdate` from `@inglorious/supabase/live-update` publishes one.
1567
+ Phones don't shrink the page for the on-screen keyboard: iOS never does, nor does Chrome on Android. Whatever sits at the bottom of the screen, such as a bottom sheet with an input, ends up behind it. `@inglorious/web/device/keyboard` reads the height the keyboard covers from the visual viewport and sets it as `--iw-keyboard-height` on `<html>`, with the `iw-keyboard-open` class while the keyboard is up. It needs no plugin and works in browsers and native apps alike. Where the page does shrink for the keyboard, as in an Android app, the class is still set but the height stays `0px`, since nothing is covered.
1557
1568
 
1558
1569
  ```javascript
1559
- import { App } from "@capacitor/app"
1560
- import { LiveUpdate } from "@capawesome/capacitor-live-update"
1561
- import {
1562
- createLiveUpdate,
1563
- watchLiveUpdate,
1564
- } from "@inglorious/web/native/live-update"
1570
+ import { watchKeyboard } from "@inglorious/web/device/keyboard"
1565
1571
 
1566
- const types = { LiveUpdate: createLiveUpdate({ plugin: LiveUpdate }) }
1567
- const entities = { liveUpdate: { type: "LiveUpdate" } }
1568
-
1569
- watchLiveUpdate({
1570
- plugin: LiveUpdate,
1571
- app: App,
1572
- store,
1573
- manifestUrl,
1574
- release: Number(import.meta.env.VITE_LIVE_UPDATE_RELEASE),
1575
- })
1572
+ watchKeyboard()
1576
1573
  ```
1577
1574
 
1578
- `watchLiveUpdate` tells the plugin the running bundle works, then reads the manifest at launch, every hour (`checkEveryMs`) and on each resume. The manifest is `{ release, minBuild, url, checksum, signature }`. A bundle is wanted when its `release` is newer than the running one and the installed build is at least `minBuild` (`isLiveUpdateWanted`). It downloads in the background, is applied on the next pause, and is announced as `#liveUpdate:liveUpdateReady` meanwhile; `liveUpdateApply` moves over at once. It does nothing outside a native app, and returns a function that stops watching.
1579
-
1580
- `release` must grow with every build, like the build's timestamp, and only release builds should have one: a development build without it must not watch, or it would turn into the published code.
1575
+ Inglorious UI's bottom sheets, snackbars and toasts move above the keyboard, and its bottom navigation hides while the keyboard is up. Your own fixed elements can do the same:
1581
1576
 
1582
- Set `publicKey` in the plugin's Capacitor config so it refuses unsigned bundles, and `readyTimeout` so a bundle that doesn't start is rolled back; with `autoBlockRolledBackBundles`, `watchLiveUpdate` never downloads it again.
1577
+ ```css
1578
+ .composer {
1579
+ position: fixed;
1580
+ bottom: var(--iw-keyboard-height, 0px);
1581
+ }
1582
+ ```
1583
1583
 
1584
- ---
1584
+ It returns a function that stops following.
1585
1585
 
1586
- ## Sign-in
1586
+ ### Storage
1587
1587
 
1588
- `@inglorious/web/auth` is the type behind a sign-in screen. It walks from the email to a password, a new account or a code sent by email, holds the signed-in `user`, and erases the account on request, as the App Store and Google Play require of apps that create accounts. Codes rather than links work in a native app too, since nobody has to open anything.
1588
+ iOS and Android can clear a WebView's `localStorage` when the device runs low on space. `createNativeStorage` keeps values in Capacitor Preferences instead, in the native app, and in `localStorage` in a browser. Give it to [`withStorage`](https://www.npmjs.com/package/@inglorious/store#withstorage):
1589
1589
 
1590
1590
  ```javascript
1591
- import { supabaseAuth } from "@inglorious/supabase"
1592
- import { createAuth, watchAuth } from "@inglorious/web/auth"
1591
+ import { Preferences } from "@capacitor/preferences"
1592
+ import { withStorage } from "@inglorious/store/storage"
1593
+ import { createNativeStorage } from "@inglorious/web/device/storage"
1593
1594
 
1594
- const adapter = supabaseAuth(supabase)
1595
+ const preferences = createNativeStorage({ plugin: Preferences })
1595
1596
 
1596
1597
  const types = {
1597
- Auth: { ...createAuth({ adapter, methods: ["password", "code"] }), render },
1598
+ Settings: [Settings, withStorage(["theme"], { storage: () => preferences })],
1598
1599
  }
1599
-
1600
- watchAuth(adapter, store) // keeps `user` in step with the session
1601
1600
  ```
1602
1601
 
1603
- `methods` lists what the screen offers: `"password"` (sign in, create an account confirmed with a code, reset a forgotten password with a code) and `"code"` (sign in with a code alone, creating the account on first use).
1604
-
1605
- The entity's `step` says what to ask for: `"email"`, `"password"`, `"signUp"`, `"code"` or `"reset"`. Its events take what the person typed: `emailSubmit(email)`, `signInSubmit(password)`, `signUpSubmit({ password, data })`, `codeSubmit(code)`, `resetSubmit({ code, password })`, and move between steps: `signUpShow`, `signInShow`, `codeRequest`, `codeResend`, `resetRequest`, `back`. Signed in, `signOut` and `accountEraseAsk`, then `accountErase` or `accountEraseCancel`. `isReady` turns true once the saved session is read: until then, render nothing rather than the sign-in screen.
1602
+ Preferences answers with promises, so in the native app the entity starts with its defaults and gets the stored fields back a moment later, through `storageRestore`. In a browser it uses `localStorage`.
1606
1603
 
1607
- Whoever signs in, by password, code, link or password reset, the entity gets `signedIn` with `{ user, isNew }`, `isNew` for an account just created. Add a handler to move on:
1604
+ It works as Supabase's session storage too, so signing in survives the same clean-ups:
1608
1605
 
1609
1606
  ```javascript
1610
- const types = {
1611
- Auth: [
1612
- createAuth({ adapter }),
1613
- {
1614
- signedIn(entity, { isNew }, api) {
1615
- api.notify("#router:navigate", isNew ? "/onboarding" : "/")
1616
- },
1617
- },
1618
- ],
1619
- }
1607
+ createClient(url, key, { auth: { storage: preferences } })
1620
1608
  ```
1621
1609
 
1622
- For a page that a confirmation email's link opens, `linkSubmit({ tokenHash })` signs in with the link instead of the code. Ask for a tap first: mail scanners open links too.
1623
-
1624
- `status` is `"loading"` while waiting, and `error` is a key to put into words: `"invalidEmail"`, `"invalidCode"`, `"weakPassword"`, `"invalidCredentials"`, `"accountExists"`, `"rateLimited"`, `"captcha"`, `"network"` or `"unknown"`. An account not confirmed yet goes straight to the code.
1610
+ ---
1625
1611
 
1626
- The adapter talks to the backend. `supabaseAuth` from `@inglorious/supabase` is one; another backend needs `onSessionChange`, `signIn`, `signUp`, `sendCode`, `verifyCode`, `verifyLink`, `resendCode`, `sendResetCode`, `updatePassword`, `signOut`, `eraseAccount` and `errorCode`, plus `accountExists` to skip straight to the password or the new account, and `prepare(action)`, called once the next step is known (`"signIn"` or `"signUp"`), such as to solve a CAPTCHA before the person submits.
1612
+ ## Native App
1627
1613
 
1628
- `create-app --auth` generates the screen, the account actions in the app bar, the Edge Function that erases accounts and the email templates.
1629
-
1630
- ---
1614
+ `@inglorious/web/native/*` holds what exists because the app is native. Each does nothing outside a native app, and `isNative()` from `@inglorious/web/native` says whether it is one.
1631
1615
 
1632
- ## App Links
1616
+ ### App Links
1633
1617
 
1634
1618
  With Universal Links (iOS) and App Links (Android), a link to the app's domain opens the installed app instead of the browser. `@inglorious/web/native/app-links` sends the router to that link's path, both for the link that started the app and for links that arrive while it runs. It does nothing outside a native app.
1635
1619
 
@@ -1644,9 +1628,7 @@ watchAppLinks(App, store)
1644
1628
 
1645
1629
  The operating system opens the app only when the domain vouches for it: iOS reads `/.well-known/apple-app-site-association` and Android `/.well-known/assetlinks.json`, and the app declares the domain (Associated Domains on iOS, an intent filter on Android). [`@inglorious/capacitor`](../capacitor) generates all of it from `native.appLinks` in `package.json`, and `@inglorious/create-app --mobile` sets it up.
1646
1630
 
1647
- ---
1648
-
1649
- ## Back Button
1631
+ ### Back Button
1650
1632
 
1651
1633
  On Android, the back button and the back gesture go back in history. `@inglorious/web/native/back-button` closes the app instead on a root path, a top-level page like a tab bar's, and when there is no history left, as other Android apps do. It does nothing outside a native app, and iOS has no back button.
1652
1634
 
@@ -1659,9 +1641,7 @@ watchBackButton(App, { rootPaths: ["/", "/search", "/profile"] })
1659
1641
 
1660
1642
  `rootPaths` defaults to `["/"]`; it returns a function that stops listening. Navigate between root paths with `{ to, replace: true }`, so switching tabs does not pile up history.
1661
1643
 
1662
- ---
1663
-
1664
- ## System Bars
1644
+ ### System Bars
1665
1645
 
1666
1646
  The status bar and Android's navigation bar follow the device's light or dark mode, so a light app on a phone in dark mode gets white icons on a white page. `@inglorious/web/native/system-bars` sets them from the app's own `color-scheme`, which every Inglorious UI theme sets, and follows it when the theme class changes. An app whose `color-scheme` is `light dark` keeps the device's style. It does nothing outside a native app.
1667
1647
 
@@ -1674,100 +1654,177 @@ watchSystemBars(SystemBars)
1674
1654
 
1675
1655
  It returns a function that stops following.
1676
1656
 
1677
- ---
1657
+ ### Native App Updates
1678
1658
 
1679
- ## Keyboard
1680
-
1681
- Phones don't shrink the page for the on-screen keyboard: iOS never does, nor does Chrome on Android. Whatever sits at the bottom of the screen, such as a bottom sheet with an input, ends up behind it. `@inglorious/web/keyboard` reads the height the keyboard covers from the visual viewport and sets it as `--iw-keyboard-height` on `<html>`, with the `iw-keyboard-open` class while the keyboard is up. It needs no plugin and works in browsers and native apps alike. Where the page does shrink for the keyboard, as in an Android app, the class is still set but the height stays `0px`, since nothing is covered.
1659
+ A Capacitor app carries its web code inside the binary, so only the stores update it. `@inglorious/web/native/update` makes an update mandatory: the app reads a minimum build per platform, and a build below it is blocked until the user updates. `@inglorious/create-app --mobile --push` sets it up with Supabase.
1682
1660
 
1683
1661
  ```javascript
1684
- import { watchKeyboard } from "@inglorious/web/keyboard"
1662
+ import { App } from "@capacitor/app"
1663
+ import {
1664
+ createNativeUpdate,
1665
+ watchNativeUpdate,
1666
+ } from "@inglorious/web/native/update"
1685
1667
 
1686
- watchKeyboard()
1668
+ const types = { NativeUpdate: [createNativeUpdate({ adapter }), template] }
1669
+ const entities = { nativeUpdate: { type: "NativeUpdate" } }
1670
+
1671
+ watchNativeUpdate(App, store)
1687
1672
  ```
1688
1673
 
1689
- Inglorious UI's bottom sheets, snackbars and toasts move above the keyboard, and its bottom navigation hides while the keyboard is up. Your own fixed elements can do the same:
1674
+ `watchNativeUpdate` reads the installed build at launch and on every resume, and does nothing outside a native app. `{ id }` as a third argument notifies another entity; it returns a function that stops watching.
1690
1675
 
1691
- ```css
1692
- .composer {
1693
- position: fixed;
1694
- bottom: var(--iw-keyboard-height, 0px);
1695
- }
1696
- ```
1676
+ The adapter says where the minimum lives: `requirement(platform)` resolves to `{ minBuild, storeUrl }`, or `null` for no minimum. `supabaseNativeUpdate` from `@inglorious/supabase` reads it from a table.
1697
1677
 
1698
- It returns a function that stops following.
1678
+ The `nativeUpdate` entity contains:
1699
1679
 
1700
- ---
1680
+ - `isUpdateRequired` — the installed build is below the minimum
1681
+ - `storeUrl` — where the update button goes, or `null`
1701
1682
 
1702
- ## Share
1683
+ Events:
1703
1684
 
1704
- `@inglorious/web/native/share` is the type behind a share button. `share` hands a title, a text, a link or a file to whatever the device does best, and the entity says what happened:
1685
+ - `nativeUpdateCheck` — `{ platform, build }`, sent by `watchNativeUpdate`
1686
+ - `nativeUpdateApply` — opens the store
1705
1687
 
1706
- - in a native app, the system's share sheet, through [`@capacitor/share`](https://capacitorjs.com/docs/apis/share) when you hand it over;
1707
- - in a browser, a file (a `url` with a `fileName`) downloads, since a browser has nowhere better to put it;
1708
- - otherwise the browser's share sheet where there is one (Web Share API), else the link is copied.
1688
+ A failed check keeps the last answer, so nobody is blocked by being offline. Render the whole app as the update page while `isUpdateRequired`, and raise the minimum only once the new build is live in that store.
1689
+
1690
+ ### Live Updates
1691
+
1692
+ A store release is only needed for native changes. `@inglorious/web/native/live-update` replaces the web code inside a Capacitor app with a newer published bundle, through [`@capawesome/capacitor-live-update`](https://capawesome.io/plugins/live-update/), whose open source plugin downloads from any URL. `publishLiveUpdate` from `@inglorious/supabase/live-update` publishes one.
1709
1693
 
1710
1694
  ```javascript
1711
- import { Share } from "@capacitor/share"
1712
- import { createShare } from "@inglorious/web/native/share"
1695
+ import { App } from "@capacitor/app"
1696
+ import { LiveUpdate } from "@capawesome/capacitor-live-update"
1697
+ import {
1698
+ createLiveUpdate,
1699
+ watchLiveUpdate,
1700
+ } from "@inglorious/web/native/live-update"
1713
1701
 
1714
- const types = { Share: createShare({ plugin: Share }) }
1702
+ const types = { LiveUpdate: createLiveUpdate({ plugin: LiveUpdate }) }
1703
+ const entities = { liveUpdate: { type: "LiveUpdate" } }
1715
1704
 
1716
- api.notify("#share:share", {
1717
- title: "My job",
1718
- url: "https://example.com/jobs/1",
1719
- })
1720
- api.notify("#share:share", {
1721
- title: "Wedding",
1722
- url: icsUrl,
1723
- fileName: "wedding.ics",
1705
+ watchLiveUpdate({
1706
+ plugin: LiveUpdate,
1707
+ app: App,
1708
+ store,
1709
+ manifestUrl,
1710
+ release: Number(import.meta.env.VITE_LIVE_UPDATE_RELEASE),
1724
1711
  })
1725
1712
  ```
1726
1713
 
1727
- `result` is `"shared"`, `"downloaded"`, `"copied"` or `"cancelled"`: closing the sheet is not an error. `status` and `error` (`"unsupported"` or `"failed"`) come from `handleRequest`. `canShare` says whether a link can be shared at all, to hide the button where it can't.
1714
+ `watchLiveUpdate` tells the plugin the running bundle works, then reads the manifest at launch, every hour (`checkEveryMs`) and on each resume. The manifest is `{ release, minBuild, url, checksum, signature }`. A bundle is wanted when its `release` is newer than the running one and the installed build is at least `minBuild` (`isLiveUpdateWanted`). It downloads in the background, is applied on the next pause, and is announced as `#liveUpdate:liveUpdateReady` meanwhile; `liveUpdateApply` moves over at once. It does nothing outside a native app, and returns a function that stops watching.
1715
+
1716
+ `release` must grow with every build, like the build's timestamp, and only release builds should have one: a development build without it must not watch, or it would turn into the published code.
1717
+
1718
+ Set `publicKey` in the plugin's Capacitor config so it refuses unsigned bundles, and `readyTimeout` so a bundle that doesn't start is rolled back; with `autoBlockRolledBackBundles`, `watchLiveUpdate` never downloads it again.
1728
1719
 
1729
1720
  ---
1730
1721
 
1731
- ## Native Storage
1722
+ ## PWA Updates
1732
1723
 
1733
- iOS and Android can clear a WebView's `localStorage` when the device runs low on space. `createNativeStorage` keeps values in Capacitor Preferences instead, in the native app, and in `localStorage` in a browser. Give it to [`withStorage`](https://www.npmjs.com/package/@inglorious/store#withstorage):
1724
+ `@inglorious/web/pwa` keeps an installed PWA on its latest version. It works with the service worker that [`vite-plugin-pwa`](https://vite-pwa-org.netlify.app/) generates, and `@inglorious/create-app --pwa` sets it up for you.
1734
1725
 
1735
- ```javascript
1736
- import { Preferences } from "@capacitor/preferences"
1737
- import { withStorage } from "@inglorious/store/storage"
1738
- import { createNativeStorage } from "@inglorious/web/native"
1726
+ Updates are not optional. A new version downloads in the background, and is applied with a reload at the first moment nobody is in the middle of something:
1739
1727
 
1740
- const preferences = createNativeStorage({ plugin: Preferences })
1728
+ - at launch, before anything is touched;
1729
+ - each time the app goes to the background or comes back to the foreground.
1741
1730
 
1742
- const types = {
1743
- Settings: [Settings, withStorage(["theme"], { storage: () => preferences })],
1731
+ It also checks for a new version every hour and on every return to the foreground: a phone suspends an installed PWA rather than closing it, so the browser's own check may never come.
1732
+
1733
+ ```javascript
1734
+ import { isNative } from "@inglorious/web/native"
1735
+ import { watchPwaUpdate } from "@inglorious/web/pwa"
1736
+ import { registerSW } from "virtual:pwa-register"
1737
+
1738
+ if (!isNative()) {
1739
+ registerSW({
1740
+ onRegisteredSW(url, registration) {
1741
+ if (registration) watchPwaUpdate(registration)
1742
+ },
1743
+ })
1744
1744
  }
1745
1745
  ```
1746
1746
 
1747
- Preferences answers with promises, so in the native app the entity starts with its defaults and gets the stored fields back a moment later, through `storageRestore`. In a browser it uses `localStorage`.
1747
+ Configure the plugin with `registerType: "prompt"` and `injectRegister: false`: the generated worker then waits for the `SKIP_WAITING` message this module sends, instead of taking over on its own.
1748
1748
 
1749
- It works as Supabase's session storage too, so signing in survives the same clean-ups:
1749
+ ### Offering "Update now"
1750
+
1751
+ A version that lands while someone is using the app waits for the next trip to the background. To offer it right away, pass the store and register the `PwaUpdate` type:
1750
1752
 
1751
1753
  ```javascript
1752
- createClient(url, key, { auth: { storage: preferences } })
1754
+ import { PwaUpdate, watchPwaUpdate } from "@inglorious/web/pwa"
1755
+
1756
+ const store = createStore({ types: { PwaUpdate }, autoCreateEntities: true })
1757
+
1758
+ watchPwaUpdate(registration, store)
1753
1759
  ```
1754
1760
 
1755
- ## Haptics
1761
+ The `pwaUpdate` entity contains:
1762
+
1763
+ - `isUpdateReady` — a new version is waiting for the next reload
1764
+
1765
+ Events:
1756
1766
 
1757
- `@inglorious/web/native/haptics` plays taps the user can feel. In a native app it uses the system's haptics through [`@capacitor/haptics`](https://capacitorjs.com/docs/apis/haptics), once you hand the plugin over. Elsewhere it vibrates where the browser can (Chrome on Android), once the user has tapped the page; iOS browsers stay silent. Every call returns whether it played.
1767
+ - `pwaUpdateReady` — sent by `watchPwaUpdate` when a version lands mid-session
1768
+ - `pwaUpdateApply` — moves over to the waiting version now, reloading the page
1758
1769
 
1759
1770
  ```javascript
1760
- import { Haptics } from "@capacitor/haptics"
1761
- import { haptics } from "@inglorious/web/native/haptics"
1771
+ const renderUpdate = (api) =>
1772
+ when(
1773
+ api.getEntity("pwaUpdate").isUpdateReady,
1774
+ () =>
1775
+ html`<button @click=${() => api.notify("#pwaUpdate:pwaUpdateApply")}>
1776
+ Update now
1777
+ </button>`,
1778
+ )
1779
+ ```
1762
1780
 
1763
- haptics.use(Haptics)
1781
+ Inglorious UI's `Snackbar` is the usual place for it. `watchPwaUpdate` takes `{ id, checkEveryMs }` as a third argument, to announce to an entity with another id or to check more or less often, and returns a function that stops watching.
1764
1782
 
1765
- haptics.selection() // a toggle flipped, a threshold crossed
1766
- haptics.impact("heavy") // "light", "medium" (default) or "heavy"
1767
- haptics.notification("error") // "success" (default), "warning" or "error"
1783
+ ---
1784
+
1785
+ ## Sign-in
1786
+
1787
+ `@inglorious/web/auth` is the type behind a sign-in screen. It walks from the email to a password, a new account or a code sent by email, holds the signed-in `user`, and erases the account on request, as the App Store and Google Play require of apps that create accounts. Codes rather than links work in a native app too, since nobody has to open anything.
1788
+
1789
+ ```javascript
1790
+ import { supabaseAuth } from "@inglorious/supabase"
1791
+ import { createAuth, watchAuth } from "@inglorious/web/auth"
1792
+
1793
+ const adapter = supabaseAuth(supabase)
1794
+
1795
+ const types = {
1796
+ Auth: { ...createAuth({ adapter, methods: ["password", "code"] }), render },
1797
+ }
1798
+
1799
+ watchAuth(adapter, store) // keeps `user` in step with the session
1768
1800
  ```
1769
1801
 
1770
- Inglorious UI plays them too: `PullToRefresh` gives a tick when letting go would refresh.
1802
+ `methods` lists what the screen offers: `"password"` (sign in, create an account confirmed with a code, reset a forgotten password with a code) and `"code"` (sign in with a code alone, creating the account on first use).
1803
+
1804
+ The entity's `step` says what to ask for: `"email"`, `"password"`, `"signUp"`, `"code"` or `"reset"`. Its events take what the person typed: `emailSubmit(email)`, `signInSubmit(password)`, `signUpSubmit({ password, data })`, `codeSubmit(code)`, `resetSubmit({ code, password })`, and move between steps: `signUpShow`, `signInShow`, `codeRequest`, `codeResend`, `resetRequest`, `back`. Signed in, `signOut` and `accountEraseAsk`, then `accountErase` or `accountEraseCancel`. `isReady` turns true once the saved session is read: until then, render nothing rather than the sign-in screen.
1805
+
1806
+ Whoever signs in, by password, code, link or password reset, the entity gets `signedIn` with `{ user, isNew }`, `isNew` for an account just created. Add a handler to move on:
1807
+
1808
+ ```javascript
1809
+ const types = {
1810
+ Auth: [
1811
+ createAuth({ adapter }),
1812
+ {
1813
+ signedIn(entity, { isNew }, api) {
1814
+ api.notify("#router:navigate", isNew ? "/onboarding" : "/")
1815
+ },
1816
+ },
1817
+ ],
1818
+ }
1819
+ ```
1820
+
1821
+ For a page that a confirmation email's link opens, `linkSubmit({ tokenHash })` signs in with the link instead of the code. Ask for a tap first: mail scanners open links too.
1822
+
1823
+ `status` is `"loading"` while waiting, and `error` is a key to put into words: `"invalidEmail"`, `"invalidCode"`, `"weakPassword"`, `"invalidCredentials"`, `"accountExists"`, `"rateLimited"`, `"captcha"`, `"network"` or `"unknown"`. An account not confirmed yet goes straight to the code.
1824
+
1825
+ The adapter talks to the backend. `supabaseAuth` from `@inglorious/supabase` is one; another backend needs `onSessionChange`, `signIn`, `signUp`, `sendCode`, `verifyCode`, `verifyLink`, `resendCode`, `sendResetCode`, `updatePassword`, `signOut`, `eraseAccount` and `errorCode`, plus `accountExists` to skip straight to the password or the new account, and `prepare(action)`, called once the next step is known (`"signIn"` or `"signUp"`), such as to solve a CAPTCHA before the person submits.
1826
+
1827
+ `create-app --auth` generates the screen, the account actions in the app bar, the Edge Function that erases accounts and the email templates.
1771
1828
 
1772
1829
  ---
1773
1830
 
@@ -2117,8 +2174,8 @@ import { render, trigger } from "@inglorious/web/test"
2117
2174
 
2118
2175
  import { Form } from "@inglorious/web/form"
2119
2176
  import { Router, setRoutes } from "@inglorious/web/router"
2120
- import { Geolocation } from "@inglorious/web/sensors/geolocation"
2121
- import { Compass } from "@inglorious/web/sensors/compass"
2177
+ import { createGeolocation } from "@inglorious/web/device/geolocation"
2178
+ import { Compass } from "@inglorious/web/device/compass"
2122
2179
  ```
2123
2180
 
2124
2181
  This keeps `lit-html` as an internal implementation detail while still giving applications stable, tree-shakeable import paths.