@jsenv/navi 0.29.62 → 0.29.63

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.
@@ -1,5 +1,5 @@
1
+ import { getVirtualKeyboardOverlayHeight, subscribeWindowResizeSettled, subscribeVisualViewportResizeSettled, setVirtualKeyboardOverlaysContent } from "@jsenv/dom";
1
2
  import { signal, computed, effect } from "@preact/signals";
2
- import { subscribeWindowResizeSettled, subscribeVisualViewportResizeSettled } from "@jsenv/dom";
3
3
 
4
4
  const installImportMetaCssBuild = (importMeta) => {
5
5
  const IMPORT_META_CSS_BUILD = "jsenv_import_meta_css_build";
@@ -129,10 +129,18 @@ const readAppMax = (propertyName) => {
129
129
  };
130
130
  const getAppWidth = () =>
131
131
  Math.min(visualViewportWidthSignal.value, readAppMax("--navi-app-max-width"));
132
+ // Minus what the keyboard covers, so this stays the JS reading of the very
133
+ // same rectangle --navi-app-height describes in CSS (see safe_area.js's own
134
+ // --navi-keyboard-inset-bottom). Zero unless the app opted into the keyboard
135
+ // overlaying its content — otherwise the shrinking visual viewport above has
136
+ // already accounted for it, and subtracting again would count it twice.
132
137
  const getAppHeight = () =>
133
- Math.min(
134
- visualViewportHeightSignal.value,
135
- readAppMax("--navi-app-max-height"),
138
+ Math.max(
139
+ 0,
140
+ Math.min(
141
+ visualViewportHeightSignal.value,
142
+ readAppMax("--navi-app-max-height"),
143
+ ) - getVirtualKeyboardOverlayHeight(),
136
144
  );
137
145
 
138
146
  // Whether the primary input is a finger rather than a mouse. A pointer type is
@@ -238,6 +246,18 @@ const SAFE_AREA_CSS = /* css */ `
238
246
  --navi-fixed-bar-space-bottom: 0px;
239
247
  --navi-fixed-bar-space-left: 0px;
240
248
 
249
+ /* What the on-screen keyboard covers — and ONLY where it overlays the
250
+ content rather than shrinking the viewport, which is navi's default
251
+ wherever the browser has the VirtualKeyboard API (see
252
+ layout/virtual_keyboard.js). Zero on Firefox/Safari, which have no
253
+ such API, and zero for an app that called
254
+ disableVirtualKeyboardOverlay(): both get a keyboard that shrinks the
255
+ visual viewport instead, which --navi-vvh already tracks. Reading
256
+ env() rather than a JS-written value keeps it live: the keyboard
257
+ slides in over several frames and this follows it without a
258
+ listener. */
259
+ --navi-keyboard-inset-bottom: env(keyboard-inset-height, 0px);
260
+
241
261
  /* Level 1. Centered bands, so that declaring one ceiling
242
262
  (--navi-app-max-width) is all an app has to do to be a narrow screen in
243
263
  a wide window; an app that wants them uneven writes these directly. */
@@ -245,7 +265,15 @@ const SAFE_AREA_CSS = /* css */ `
245
265
  0px,
246
266
  (var(--navi-vvh) - var(--navi-app-max-height, var(--navi-vvh))) / 2
247
267
  );
248
- --navi-app-inset-bottom: var(--navi-app-inset-top);
268
+ /* The keyboard on top of the band, and on this edge only: it eats into
269
+ the app's own rectangle exactly like a viewport that shrank, which is
270
+ what makes both paths end up at the same --navi-app-height (and so at
271
+ the same dialog/popover ceiling). Not part of the centering, hence
272
+ added here rather than folded into --navi-app-inset-top: a keyboard
273
+ takes the bottom, it doesn't re-center anything. */
274
+ --navi-app-inset-bottom: calc(
275
+ var(--navi-app-inset-top) + var(--navi-keyboard-inset-bottom)
276
+ );
249
277
  --navi-app-inset-left: max(
250
278
  0px,
251
279
  (var(--navi-vvw) - var(--navi-app-max-width, var(--navi-vvw))) / 2
@@ -308,6 +336,42 @@ const SAFE_AREA_CSS = /* css */ `
308
336
  }
309
337
  `;
310
338
 
339
+ /**
340
+ * navi's stance on the on-screen keyboard: it overlays the app rather than
341
+ * resizing the viewport, wherever the browser can be told so (the
342
+ * VirtualKeyboard API — Chromium only). See virtual_keyboard.js in @jsenv/dom
343
+ * for what that trades away and what it gives back.
344
+ *
345
+ * Turned on rather than offered, because navi already sizes everything that
346
+ * escapes normal flow against the app's own rectangle rather than against the
347
+ * window (--navi-app-width/height, see navi_css_vars.js), and
348
+ * --navi-keyboard-inset-bottom (safe_area.js) puts the keyboard into exactly
349
+ * that rectangle. So the two mechanisms reach the same numbers here, and the
350
+ * overlay reaches them without reflowing the page underneath — a resizing
351
+ * viewport is a resize of everything, fired transiently every time focus goes
352
+ * from one input to the next.
353
+ *
354
+ * An app that built its own layout around the viewport shrinking can say so
355
+ * with disableVirtualKeyboardOverlay(), and gets the behavior Firefox and
356
+ * Safari give it anyway.
357
+ *
358
+ * The one thing it hands back to the app: scrolling the focused field into
359
+ * view. A viewport that shrinks makes the browser do it; a keyboard that
360
+ * merely paints over the page leaves whatever is under it under it. navi
361
+ * answers that for what it places itself — a popup is sized and positioned
362
+ * against the app rectangle the keyboard was just subtracted from — and for
363
+ * anything marked [data-navi-safe-area], whose scroll-padding-bottom counts
364
+ * the keyboard in (safe_area.js). A field in a scroller the app never marked
365
+ * is the app's own to handle.
366
+ */
367
+
368
+
369
+ setVirtualKeyboardOverlaysContent(true);
370
+
371
+ const disableVirtualKeyboardOverlay = () => {
372
+ setVirtualKeyboardOverlaysContent(false);
373
+ };
374
+
311
375
  installImportMetaCssBuild(import.meta);/**
312
376
  * Regroup CSS vars that makes sense to share across all navi components.
313
377
  */
@@ -539,5 +603,5 @@ effect(() => {
539
603
  document.documentElement.style.setProperty("--navi-vvh", `${visualViewportHeightSignal.value}px`);
540
604
  });
541
605
 
542
- export { coarsePointerSignal, getAppHeight, getAppWidth, installImportMetaCssBuild, smallTouchScreenSignal, visualViewportHeightSignal, visualViewportWidthSignal, windowHeightSignal, windowWidthSignal };
606
+ export { coarsePointerSignal, disableVirtualKeyboardOverlay, getAppHeight, getAppWidth, installImportMetaCssBuild, smallTouchScreenSignal, visualViewportHeightSignal, visualViewportWidthSignal, windowHeightSignal, windowWidthSignal };
543
607
  //# sourceMappingURL=jsenv_navi_side_effects.js.map