akanjs 3.3.0-rc.8 → 3.3.0-rc.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -231,6 +231,7 @@
231
231
  **Upgrading.** Opening an optimized image's URL directly in a browser tab now downloads it instead of showing it; images in pages, CSS and `srcset` are unchanged. A cached passthrough image of type heic, ico, icns, bmp, jxl or tiff is now stored under its own extension instead of `.jpg`, so each one is fetched once more and its old cache file is left behind.
232
232
 
233
233
  - e9598f3: Under an iOS shell that leaves the keyboard to the page, the page box now starts moving with the keys on their first frame. It followed a store update and React's render of the frame, which on a phone started the move about 100 ms after the keys, then jumped to catch up. `Device` now sets `--akan-keyboard-cover`, `--akan-keyboard-duration`, `--akan-keyboard-easing` and `data-akan-keyboard` on the root in the shell's keyboard event itself, and the page box's height and bottom padding follow `--akan-keyboard-cover` in CSS, so the transition starts before any render. `isPageKeyboardAvoidance` and `IOS_KEYBOARD_ANIMATION_EASING` now come from `akanjs/client` too.
234
+ - 45e3ffa: Under an iOS shell that leaves the keyboard to the page, the page now follows the keys without laying out on every frame. #715 animated the page box's `height`, which re-laid the page out on each frame of the keys' move and dropped frames on a phone, more so under glass (backdrop-filter) surfaces. `KeyboardRide` now changes the box once and carries whatever the page marks `data-akan-keyboard-ride` (a chat's list content, its composer) there as a `transform`, which WebKit hands to Core Animation: keys coming up hold the old box until they are up, since the shorter box would clip a rider still on its way, and keys going down give the taller box at once while the riders start from where they were drawn. A scroller resting at its end stays there. `data-akan-keyboard` on the root follows the keys at once, for what moves with them by transform or opacity; `data-akan-keyboard-layout` and `--akan-keyboard-cover` follow the box, for what changes layout. A page with no rider still gets the box in one step.
234
235
  - c10f7cf: A loader sends its store at most 500 distinct keys per query and splits a larger batch into several queries that run together. A `load<Model>Many` or a nested list with more ids than a database takes in one statement now loads instead of failing: Postgres refused more than 65,534 values, and SQLite refused a `byQuery` batch of about 1,000 keys.
235
236
  - c10f7cf: A loader asks its store for each key once per batch: loads of the same key in one batch share one lookup, and each caller still gets its own document wherever the loader has `copy`, as every model and declared loader does. A `new DataLoader(...)` without `copy` now hands the callers of a repeated key one result object, where a batch function that built a fresh object per position gave each its own: pass `copy` to keep them apart. A batch function that throws, or resolves to something that is not an array, now rejects its callers instead of leaving them waiting.
236
237
  - 10641a0: `agentService.loop` keeps fewer tools in a long run's requests. A compaction closes each toolkit from `toolkits` that the messages it keeps neither opened nor called a tool of, and the model opens it again with `openToolkit` when it needs it. Remotes stay open. `compact.at` now counts the round's tools, instructions and context along with the transcript, so a run with a large tool list compacts before the provider refuses the request, not after. An opened toolkit's tools are listed after every tool already listed, in the order the toolkits were opened, so opening one leaves the start of the tool list unchanged.
package/client/device.ts CHANGED
@@ -5,6 +5,7 @@ import { readCssSafeAreaInsets } from "./frameConfig";
5
5
  import type { DeviceInfo } from "./native";
6
6
 
7
7
  type NativeModule = typeof import("./native");
8
+ type KeyboardRideClass = typeof import("./keyboardRide").KeyboardRide;
8
9
  type NativeControls = Pick<NativeModule, "haptics" | "keyboard">;
9
10
  type ProcessEnvLike = { env?: Record<string, string | undefined> };
10
11
  type DebugPayload = Record<string, unknown>;
@@ -177,9 +178,15 @@ export class Device {
177
178
  async hideKeyboard() {
178
179
  await this.#native?.keyboard.hide();
179
180
  }
181
+
182
+ static #keyboardRide: KeyboardRideClass | null = null;
180
183
  listenKeyboardChanged(onKeyboardChanged: (height: number) => void) {
181
184
  const keyboard = this.#native?.keyboard;
182
185
  if (!keyboard) return;
186
+ if (isPageKeyboardAvoidance())
187
+ void import("./keyboardRide").then(({ KeyboardRide }) => {
188
+ Device.#keyboardRide = KeyboardRide;
189
+ });
183
190
  let currentHeight = 0;
184
191
  const emitKeyboardHeight = (event: string, height: number) => {
185
192
  debugFrame("keyboard.event", { event, height, previousHeight: currentHeight });
@@ -193,22 +200,12 @@ export class Device {
193
200
  ...(["willShow", "didShow", "willHide", "didHide"] as const).map((event) =>
194
201
  keyboard.listen(event, ({ height, duration }) => {
195
202
  if (duration > 0) this.keyboardAnimationMs = duration;
196
- if (isPageKeyboardAvoidance()) this.#moveRootWithKeyboard(height);
203
+ Device.#keyboardRide?.move(height, this.keyboardAnimationMs);
197
204
  emitKeyboardHeight(event, height);
198
205
  }),
199
206
  ),
200
207
  );
201
208
  }
202
-
203
- #moveRootWithKeyboard(height: number) {
204
- const root = document.documentElement;
205
- if (this.keyboardAnimationMs > 0) {
206
- root.style.setProperty("--akan-keyboard-duration", `${this.keyboardAnimationMs}ms`);
207
- root.style.setProperty("--akan-keyboard-easing", IOS_KEYBOARD_ANIMATION_EASING);
208
- }
209
- root.style.setProperty("--akan-keyboard-cover", `${height}px`);
210
- root.toggleAttribute("data-akan-keyboard", height > 0);
211
- }
212
209
  subscribeKeyboard(onKeyboardChanged: (height: number) => void) {
213
210
  this.#keyboardSubscribers.add(onKeyboardChanged);
214
211
  return () => {
@@ -0,0 +1,88 @@
1
+ import { IOS_KEYBOARD_ANIMATION_EASING } from "./device";
2
+
3
+ const RIDE_SELECTOR = "[data-akan-keyboard-ride]";
4
+ const END_SLACK_PX = 2;
5
+
6
+ const bottomOf = (element: HTMLElement) => element.getBoundingClientRect().bottom;
7
+
8
+ /**
9
+ * Moves the page with an iOS keyboard the shell left to it. A layout change on every frame drops frames on a phone, so
10
+ * the page box (`--akan-keyboard-cover`) changes once and what is marked `data-akan-keyboard-ride` travels the way
11
+ * there as a transform, which WebKit hands to Core Animation. Keys coming up hold the old box until they are up, since
12
+ * the new, shorter box would clip a rider still on its way; keys going down give the taller box at once and the riders
13
+ * start from where they were drawn. A scroller resting at its end stays there, as a chat list does.
14
+ */
15
+ export class KeyboardRide {
16
+ static #committed = 0;
17
+ static #target = 0;
18
+ static #timer: ReturnType<typeof setTimeout> | null = null;
19
+
20
+ static move(height: number, durationMs: number) {
21
+ if (height === KeyboardRide.#target) return;
22
+ KeyboardRide.#target = height;
23
+ const root = document.documentElement;
24
+ if (durationMs > 0) {
25
+ root.style.setProperty("--akan-keyboard-duration", `${durationMs}ms`);
26
+ root.style.setProperty("--akan-keyboard-easing", IOS_KEYBOARD_ANIMATION_EASING);
27
+ }
28
+ root.toggleAttribute("data-akan-keyboard", height > 0);
29
+ if (KeyboardRide.#timer) clearTimeout(KeyboardRide.#timer);
30
+ KeyboardRide.#timer = null;
31
+
32
+ const riders = [...document.querySelectorAll<HTMLElement>(RIDE_SELECTOR)].filter(
33
+ (element) => element.getClientRects().length > 0,
34
+ );
35
+ const drawn = riders.map(bottomOf);
36
+ for (const rider of riders) {
37
+ rider.style.transition = "none";
38
+ rider.style.transform = "";
39
+ }
40
+ const scrollers = KeyboardRide.#scrollersAtEnd(riders);
41
+ const previous = KeyboardRide.#committed;
42
+ const isRising = height > previous;
43
+ KeyboardRide.#commit(height, scrollers);
44
+ const settled = riders.map(bottomOf);
45
+ if (isRising) KeyboardRide.#commit(previous, scrollers);
46
+ const laid = isRising ? riders.map(bottomOf) : settled;
47
+ riders.forEach((rider, idx) => {
48
+ rider.style.transform = `translateY(${drawn[idx] - laid[idx]}px)`;
49
+ });
50
+ void root.offsetHeight;
51
+ const transition = `transform ${durationMs}ms ${IOS_KEYBOARD_ANIMATION_EASING}`;
52
+ riders.forEach((rider, idx) => {
53
+ rider.style.transition = transition;
54
+ rider.style.transform = `translateY(${settled[idx] - laid[idx]}px)`;
55
+ });
56
+ KeyboardRide.#timer = setTimeout(() => {
57
+ KeyboardRide.#timer = null;
58
+ if (isRising) KeyboardRide.#commit(height, KeyboardRide.#scrollersAtEnd(riders));
59
+ for (const rider of riders) {
60
+ rider.style.transition = "none";
61
+ rider.style.transform = "";
62
+ }
63
+ void root.offsetHeight;
64
+ for (const rider of riders) rider.style.transition = "";
65
+ }, durationMs);
66
+ }
67
+
68
+ static #commit(height: number, scrollers: HTMLElement[]) {
69
+ const root = document.documentElement;
70
+ root.style.setProperty("--akan-keyboard-cover", `${height}px`);
71
+ root.toggleAttribute("data-akan-keyboard-layout", height > 0);
72
+ KeyboardRide.#committed = height;
73
+ for (const scroller of scrollers) scroller.scrollTop = scroller.scrollHeight;
74
+ }
75
+
76
+ static #scrollersAtEnd(riders: HTMLElement[]) {
77
+ const scrollers = new Set<HTMLElement>();
78
+ for (const rider of riders) {
79
+ for (let element = rider.parentElement; element; element = element.parentElement) {
80
+ const { overflowY } = getComputedStyle(element);
81
+ if (overflowY !== "auto" && overflowY !== "scroll") continue;
82
+ if (element.scrollHeight - element.scrollTop - element.clientHeight <= END_SLACK_PX) scrollers.add(element);
83
+ break;
84
+ }
85
+ }
86
+ return [...scrollers];
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.8",
3
+ "version": "3.3.0-rc.9",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Moves the page with an iOS keyboard the shell left to it. A layout change on every frame drops frames on a phone, so
3
+ * the page box (`--akan-keyboard-cover`) changes once and what is marked `data-akan-keyboard-ride` travels the way
4
+ * there as a transform, which WebKit hands to Core Animation. Keys coming up hold the old box until they are up, since
5
+ * the new, shorter box would clip a rider still on its way; keys going down give the taller box at once and the riders
6
+ * start from where they were drawn. A scroller resting at its end stays there, as a chat list does.
7
+ */
8
+ export declare class KeyboardRide {
9
+ #private;
10
+ static move(height: number, durationMs: number): void;
11
+ }
@@ -224,6 +224,8 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
224
224
  const useCsrTransitionMap = useCsrTransitions(routeState);
225
225
 
226
226
  const contentResizeStyle = useMemo(() => {
227
+
228
+ if (keyboardFrame.avoidsContent && !keyboardFrame.sticky) return null;
227
229
  if (!keyboardFrame.avoidsContent && (!shouldAnchorContentBottom || !keyboardFrame.sticky)) return null;
228
230
  const duration = keyboardFrame.avoidsContent
229
231
  ? "var(--akan-keyboard-duration, 250ms)"