akanjs 3.3.0-rc.2 → 3.3.0-rc.4
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 +38 -23
- package/README.ko.md +40 -296
- package/README.md +41 -297
- package/client/csrTypes.ts +2 -0
- package/client/device.ts +13 -1
- package/index.ts +2 -0
- package/package.json +2 -1
- package/server/ssrFromRscRenderer.tsx +26 -26
- package/types/client/csrTypes.d.ts +2 -0
- package/types/client/device.d.ts +3 -0
- package/types/index.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/core/src/boot.d.ts +5 -0
- package/types/webkit/index.d.ts +1 -1
- package/types/webkit/useCsrKeyboard.d.ts +2 -1
- package/types/webkit/useFrameRuntime.d.ts +4 -1
- package/types/webkit/useVisualViewportFrame.d.ts +2 -0
- package/ui/Dialog/Modal.tsx +16 -2
- package/ui/KeyboardAvoiding.tsx +2 -1
- package/vendor/@akanjs/native/CHANGELOG.md +4 -60
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +21 -2
- package/vendor/@akanjs/native/packages/core/src/boot.ts +6 -0
- package/vendor/use-agentic/CHANGELOG.md +0 -64
- package/webkit/index.ts +1 -1
- package/webkit/useCsrKeyboard.ts +27 -1
- package/webkit/useCsrTransitions.ts +11 -6
- package/webkit/useCsrValues.ts +8 -2
- package/webkit/useFrameRuntime.ts +48 -4
- package/webkit/useVisualViewportFrame.tsx +26 -0
package/README.md
CHANGED
|
@@ -6,11 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
**The TypeScript framework, agents included.** Powered by Bun.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
one AI can use, on the model you choose. One line of business code runs through every layer, ships to six platforms,
|
|
13
|
-
and reaches everyone who uses it — people and agents.
|
|
9
|
+
Akan.js is a full-stack TypeScript framework. One field declaration runs through the schema, service, API, client
|
|
10
|
+
state and UI, and the same code ships as a web app, iOS and Android apps, and desktop apps. Every guarded endpoint is
|
|
11
|
+
also an MCP tool and every control on screen an in-page agent tool, behind the guards people pass.
|
|
14
12
|
|
|
15
13
|
## Quick Start
|
|
16
14
|
|
|
@@ -61,307 +59,53 @@ Node and npm, or URLs given by a spec, a coding agent needs these, and nothing h
|
|
|
61
59
|
- **Exact URLs:** pages live under `/<locale>/…`. To serve the default locale at the bare path (`/books/OL45804W`),
|
|
62
60
|
set `i18n: { defaultLocale: "en", locales: ["en"], localePrefix: "as-needed" }` in `akan.config.ts`; `<Link>`
|
|
63
61
|
follows.
|
|
64
|
-
- **A host with only Node and npm:**
|
|
65
|
-
`
|
|
66
|
-
`
|
|
67
|
-
|
|
68
|
-
- **Build and run without Docker** through these package scripts; `npm run build`, then `PORT=3000 npm start`:
|
|
69
|
-
|
|
70
|
-
```json
|
|
71
|
-
"build": "akan build <app>",
|
|
72
|
-
"start": "cd dist/apps/<app> && bun main.js"
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
A fresh clone builds as is: the env files stay gitignored and `akan` writes the ones it lacks, so commit none. The
|
|
76
|
-
build carries the env it needs, and a variable set at start overrides it.
|
|
62
|
+
- **A host with only Node and npm:** `npx -y bun@1.4.4 x create-akan-workspace@latest . --app <app> --dir <folder> --sample false`,
|
|
63
|
+
then `npm run build` and `PORT=3000 npm start`. The
|
|
64
|
+
[`create-akan-workspace` README](https://www.npmjs.com/package/create-akan-workspace#with-only-node-and-npm) has the
|
|
65
|
+
scripts it writes and what a fresh clone needs.
|
|
77
66
|
- **Build for where it runs.** A variable set in the shell, or in a `.env.local` Bun loads, outranks the workspace `.env`
|
|
78
67
|
(an empty one counts as unset, and the build names each one it took), and `--env` outranks both for `AKAN_PUBLIC_ENV`. A new workspace's `.env` says `local`, which suits your own machine or a test runner, but the
|
|
79
68
|
server runs without endpoint rate limits and on local defaults. For a host others can reach, run
|
|
80
69
|
`akan build <app> --env main` with `AKAN_PUBLIC_REPO_NAME` and `AKAN_PUBLIC_SERVE_DOMAIN` (the domain it serves) set
|
|
81
70
|
in the shell or the workspace `.env`.
|
|
82
71
|
|
|
83
|
-
##
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
export class ProductInput extends via((field) => ({
|
|
87
|
-
name: field(String),
|
|
88
|
-
})) {}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
**1 line × 8 layers × 6 platforms × people & agents.**
|
|
92
|
-
|
|
93
|
-
- **1 line.** Adding a field is one declaration: a name and a type.
|
|
94
|
-
- **× 8 layers.** That line runs through the schema, query, service, API, fetch, client type, state and UI prop. In a
|
|
95
|
-
usual stack those are eight places to change by hand, and missing one breaks a type or fails at runtime. Here they
|
|
96
|
-
change together.
|
|
97
|
-
- **× 6 platforms.** The same code ships as SEO-ready web, iOS and Android apps, and macOS, Windows and Linux desktop
|
|
98
|
-
apps, with native-level screen transitions rather than a wrapped website.
|
|
99
|
-
- **× people & agents.** Every guarded endpoint becomes an MCP tool and every control on screen an in-page agent
|
|
100
|
-
tool, behind the same guards people pass.
|
|
101
|
-
|
|
102
|
-
## The Screen You Build Is The Agent's Interface
|
|
103
|
-
|
|
104
|
-
```tsx
|
|
105
|
-
export const Order = () => {
|
|
106
|
-
const { l } = usePage();
|
|
107
|
-
const icecreamOrderForm = st.use.icecreamOrderForm();
|
|
108
|
-
const order = st.tool("createIcecreamOrder", { confirm: true })
|
|
109
|
-
.desc("Place the order in the form.")
|
|
110
|
-
.exec(() => st.do.createIcecreamOrder());
|
|
111
|
-
return (
|
|
112
|
-
<>
|
|
113
|
-
<Field.MultiToggleSelect
|
|
114
|
-
label={l("icecreamOrder.toppings")}
|
|
115
|
-
items={cnst.Topping}
|
|
116
|
-
value={icecreamOrderForm.toppings}
|
|
117
|
-
onChange={st.do.setToppingsOnIcecreamOrder}
|
|
118
|
-
/>
|
|
119
|
-
<Button onClick={order}>{l("icecreamOrder.createIcecreamOrder")}</Button>
|
|
120
|
-
</>
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
- **Write the screen you were going to write.** A field handed its setter publishes it. A button's handler becomes a
|
|
126
|
-
tool with one `st.tool` line — the same function the button calls.
|
|
127
|
-
- **An agent sees tools, not pixels.** Every control you wired is published under its own name, with the arguments it
|
|
128
|
-
takes. What isn't on the screen isn't on the list.
|
|
129
|
-
- **It works the screen in the user's own tab**, with their session, exactly like a click.
|
|
130
|
-
- **What matters waits for a yes.** A tool declared with `confirm` stops on an approval card.
|
|
131
|
-
|
|
132
|
-
Setup is one `<Agent.Chat />` in a layout and your model's key in `option.ts`. OpenAI-compatible hosts and Anthropic
|
|
133
|
-
both work.
|
|
134
|
-
|
|
135
|
-
## Your Server Is Already An MCP Server
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
serveIcecreamOrder: mutation(cnst.IcecreamOrder, {
|
|
139
|
-
guards: [Admin],
|
|
140
|
-
})
|
|
141
|
-
.param("icecreamOrderId", ID)
|
|
142
|
-
.exec(async function (icecreamOrderId) {
|
|
143
|
-
return await this.icecreamOrderService.serve(icecreamOrderId);
|
|
144
|
-
}),
|
|
145
|
-
refundIcecreamOrder: mutation(cnst.IcecreamOrder, {
|
|
146
|
-
guards: [Every, Person],
|
|
147
|
-
})
|
|
148
|
-
.param("icecreamOrderId", ID)
|
|
149
|
-
.with(Self)
|
|
150
|
-
.exec(async function (icecreamOrderId, self) {
|
|
151
|
-
return await this.icecreamOrderService.refund(icecreamOrderId, self.id);
|
|
152
|
-
}),
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
- **Point any MCP client at your app.** `POST /mcp` is on by default. Every endpoint whose guards admit the caller is
|
|
156
|
-
a tool, described by the dictionary you already write.
|
|
157
|
-
- **Sign-in and consent happen on your app.** OAuth 2.1 ships with `libs/shared`. The AI gets a token for one user —
|
|
158
|
-
exactly their rights, revocable at any time.
|
|
159
|
-
- **It can't do what it shouldn't.** `refundIcecreamOrder` is guarded by `Person`, so it never reaches the shelf. To
|
|
160
|
-
the AI it looks exactly like a tool that doesn't exist.
|
|
161
|
-
- **Pages become prompts.** `page().prompt(name, description)` publishes a screen as an MCP prompt: its fetches run
|
|
162
|
-
under the caller's token and the agent receives the data, with no second implementation to keep in sync.
|
|
163
|
-
|
|
164
|
-
## One Rule, Three Kinds Of Users
|
|
165
|
-
|
|
166
|
-
You write a guard once per endpoint. It decides for a person on the screen, for the agent in their tab, and for an AI
|
|
167
|
-
calling over MCP.
|
|
168
|
-
|
|
169
|
-
- **Refusals give nothing away.** A tool an agent may not use answers exactly like one that doesn't exist.
|
|
170
|
-
- **Rate-limited per caller.** MCP calls are capped at 120 a minute and 8 at once for each caller.
|
|
171
|
-
- **Secrets stay home.** Hidden and secret fields are stripped before anything reaches a model.
|
|
172
|
-
- **Connections end when you say.** Revoke a connection and its next call is refused. The chat relay keeps no
|
|
173
|
-
session and no transcript.
|
|
174
|
-
|
|
175
|
-
## Agents Build It, Too
|
|
176
|
-
|
|
177
|
-
AI coding turns to spaghetti past a certain size: the faster an agent writes, the more file paths, names, structures
|
|
178
|
-
and declaration styles drift apart. Akan stops this at the source with strict rules.
|
|
179
|
-
|
|
180
|
-
- **Config hell ends.** Everything is configured in `akan.config.ts`, and an empty one still runs.
|
|
181
|
-
- **Strict rules, unified style.** File paths, names, structures and declarations stay consistent, and lint enforces
|
|
182
|
-
them, so code reads like one person wrote it.
|
|
183
|
-
- **Rules agents can't route around.** Every workspace ships a generated `AGENTS.md`, bundled guidelines, a
|
|
184
|
-
plan-then-apply workflow MCP, and `akan code`, a terminal coding agent that works through them.
|
|
185
|
-
- **Fixed blocks.** Upload, login, admin, chat, boards and alerts are ready-made blocks, so agents produce
|
|
186
|
-
consistent code on top of them.
|
|
187
|
-
|
|
188
|
-
## The Domain Module
|
|
189
|
-
|
|
190
|
-
Code is organized around business domains such as `user`, `product`, `ticket` or `project`, not by technical layer
|
|
191
|
-
first.
|
|
192
|
-
|
|
193
|
-
```text
|
|
194
|
-
lib/product/
|
|
195
|
-
├── product.constant.ts # model, scalar, enum, schema definition
|
|
196
|
-
├── product.dictionary.ts # i18n labels, descriptions, errors
|
|
197
|
-
├── product.signal.ts # typed endpoint contract, guards
|
|
198
|
-
├── product.document.ts # persistence and document queries
|
|
199
|
-
├── product.service.ts # business logic
|
|
200
|
-
├── product.store.ts # domain state and actions
|
|
201
|
-
├── Product.Template.tsx # form UI
|
|
202
|
-
├── Product.Unit.tsx # list item UI
|
|
203
|
-
├── Product.View.tsx # detail UI
|
|
204
|
-
└── Product.Zone.tsx # page section UI
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
```mermaid
|
|
208
|
-
flowchart LR
|
|
209
|
-
ConstantDictionarySignal["constant + dictionary + signal"] --> DocumentService["document + service"]
|
|
210
|
-
ConstantDictionarySignal --> StoreComponents["store + UI components"]
|
|
211
|
-
DocumentService --> ServerRuntime["server runtime + MCP"]
|
|
212
|
-
StoreComponents --> ClientRuntime["client runtime + in-page agent"]
|
|
213
|
-
ServerRuntime --> DeployArtifacts["deploy artifacts"]
|
|
214
|
-
ClientRuntime --> DeployArtifacts
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## Faster Than v2
|
|
218
|
-
|
|
219
|
-
v3 adds agents, MCP and a new UI system, and it is still faster than v2 on every number we measured.
|
|
220
|
-
|
|
221
|
-
| Metric | v2 | v3 | Change |
|
|
222
|
-
| --- | --- | --- | --- |
|
|
223
|
-
| Requests per second | 112K | 123K | +10% |
|
|
224
|
-
| Response time (p99) | 1.30 ms | 1.04 ms | −20% |
|
|
225
|
-
| Startup time | 204 ms | 102 ms | −50% |
|
|
226
|
-
| Memory at rest | 84 MB | 57 MB | −32% |
|
|
227
|
-
| Memory under load | 105 MB | 85 MB | −19% |
|
|
72
|
+
## Your First App
|
|
228
73
|
|
|
229
|
-
-
|
|
230
|
-
|
|
231
|
-
- A
|
|
74
|
+
- **A screen** is a file under `apps/<app>/page/`: `<route>.tsx` or `_index.tsx`, `_layout.tsx` around it, `[id]/`
|
|
75
|
+
for a segment. It exports one `page()` chain from `akanjs/client`. [Routing](https://akanjs.com/docs/core/routing)
|
|
76
|
+
- **A stored model** is a module under `lib/<model>/`, made by `akan create-module <model> <app>`. A service with no
|
|
77
|
+
stored model, such as an outside API, goes under `lib/_<service>/` with `akan create-service <service> <app>`.
|
|
78
|
+
[File rules](https://akanjs.com/docs/core/file-rule)
|
|
79
|
+
- **The rules** a coding agent follows are in the workspace: `AGENTS.md`, `.claude/rules/akan/`, and the skills in
|
|
80
|
+
`.claude/skills/` and `.agents/skills/`. `akan guideline show <name>` prints any bundled guideline.
|
|
81
|
+
- **`akan.config.ts`** may stay empty. It grows only for routes, domains, locales, database modes or native apps.
|
|
82
|
+
[Configuration](https://akanjs.com/docs/core/config)
|
|
232
83
|
|
|
233
|
-
|
|
234
|
-
in [`benchmarks/api-benchmark`](https://github.com/akan-team/akanjs/tree/main/benchmarks/api-benchmark).
|
|
235
|
-
|
|
236
|
-
## From Build To A Live URL
|
|
237
|
-
|
|
238
|
-
[Akan Cloud](https://cloud.akanjs.com) is the deploy platform built for Akan apps.
|
|
239
|
-
|
|
240
|
-
```bash
|
|
241
|
-
akan login # sign in to Akan Cloud from your machine
|
|
242
|
-
akan tunnel <app> # share the app you are running on a public URL
|
|
243
|
-
akan build <app> # build the production artifact Akan Cloud runs
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
## Docs For You And Your Agent
|
|
247
|
-
|
|
248
|
-
- Read the docs at [akanjs.com/docs](https://akanjs.com/docs). Every docs page carries the in-page agent, so you can
|
|
249
|
-
ask it about a topic and it opens the page.
|
|
250
|
-
- Connect Claude Code or Cursor to `https://akanjs.com/mcp`, and your AI reads the docs (`listDocPages`,
|
|
251
|
-
`searchDocPages`, `readDocPage`) while it writes your code.
|
|
252
|
-
- [`llms.txt`](https://akanjs.com/llms.txt) indexes the docs for any model.
|
|
253
|
-
|
|
254
|
-
## One Package, Many Boundaries
|
|
255
|
-
|
|
256
|
-
Akan is published as a single npm package, `akanjs`. The root import is intentionally small; subpath imports keep
|
|
257
|
-
server-only, client-only, UI and tooling surfaces apart.
|
|
258
|
-
|
|
259
|
-
```ts
|
|
260
|
-
import { Int, dayjs } from "akanjs/base";
|
|
261
|
-
import { via } from "akanjs/constant";
|
|
262
|
-
import { endpoint } from "akanjs/signal";
|
|
263
|
-
import { Button, Layout } from "akanjs/ui";
|
|
264
|
-
import { page } from "akanjs/client";
|
|
265
|
-
import { AkanApp } from "akanjs/server/akanApp";
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
```css
|
|
269
|
-
@import "akanjs/ui/styles.css";
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
| Subpath | Purpose |
|
|
273
|
-
| --- | --- |
|
|
274
|
-
| `akanjs/base` | Core primitives, scalars (`Int`, `Float`, `ID`, `Binary`, `enumOf`), `dayjs`, environment helpers. |
|
|
275
|
-
| `akanjs/common` | Shared cross-runtime helpers. |
|
|
276
|
-
| `akanjs/constant` | Model declarations, schema shaping, serialization, defaults, and the `via` builder. |
|
|
277
|
-
| `akanjs/dictionary` | Locale, translation, and dictionary helpers for labels, descriptions and errors. |
|
|
278
|
-
| `akanjs/document` | Database documents, filters, query builders, full-text search, and persistence utilities. |
|
|
279
|
-
| `akanjs/signal` | Endpoints, slices, guards, middleware, and typed signal contracts. |
|
|
280
|
-
| `akanjs/service` | Services, adaptors, dependency injection, and the business logic runtime. |
|
|
281
|
-
| `akanjs/fetch` | Typed fetch, HTTP and WebSocket clients. |
|
|
282
|
-
| `akanjs/store` | Domain state, actions, and the in-page agent's `st.tool` / `st.use` surface. |
|
|
283
|
-
| `akanjs/ui` | React components, recipes, and `_overrides.tsx` slots: layout, form, modal, table, loading, agent chat. |
|
|
284
|
-
| `akanjs/client` | The route chain (`page()`, `layout()`), routing, cookies, storage, locale, and `cn`. |
|
|
285
|
-
| `akanjs/client/native` | The native bridge and builtin plugins for iOS, Android and desktop apps. |
|
|
286
|
-
| `akanjs/webkit` | Browser-side helpers such as `lazy` and SEO pages. |
|
|
287
|
-
| `akanjs/server` | Server runtime, SSR/RSC, MCP, logging, and server types. `akanjs/server/akanApp` is the entrypoint. |
|
|
288
|
-
| `akanjs/native/desktop` | Desktop parts of native plugins. |
|
|
289
|
-
| `akanjs/test` | Test helpers and sample generation. |
|
|
290
|
-
|
|
291
|
-
Tooling ships as separate packages: `@akanjs/cli` (the `akan` command), `@akanjs/devkit` (build runners, code
|
|
292
|
-
generation, lint rules) and `create-akan-workspace`.
|
|
293
|
-
|
|
294
|
-
## CLI Overview
|
|
84
|
+
## Build And Run
|
|
295
85
|
|
|
296
86
|
```bash
|
|
297
|
-
akan
|
|
298
|
-
akan
|
|
299
|
-
akan
|
|
300
|
-
|
|
301
|
-
akan build <app>
|
|
302
|
-
akan build-ios <app> # also build-android, build-desktop
|
|
303
|
-
akan lint <app>
|
|
304
|
-
akan typecheck <app>
|
|
305
|
-
akan test <app>
|
|
306
|
-
akan logs <app>
|
|
307
|
-
akan code
|
|
308
|
-
akan update
|
|
87
|
+
akan start <app> # dev server, http://localhost:8282
|
|
88
|
+
akan verify <app> # sync, lint, typecheck, build and SSR check
|
|
89
|
+
akan build <app> # production build in dist/apps/<app>
|
|
90
|
+
cd dist/apps/<app> && PORT=3000 bun main.js
|
|
309
91
|
```
|
|
310
92
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
],
|
|
331
|
-
database: { modes: ["single", "cluster"] },
|
|
332
|
-
native: {
|
|
333
|
-
basePath: "app",
|
|
334
|
-
appName: "Example",
|
|
335
|
-
appId: "com.example.app",
|
|
336
|
-
version: "1.0.0",
|
|
337
|
-
buildNum: 1,
|
|
338
|
-
},
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
export default config;
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
## Contributor Notes
|
|
345
|
-
|
|
346
|
-
This repository is a Bun-first monorepo. Framework code lives under `pkgs/akanjs`, tooling under `pkgs/@akanjs`,
|
|
347
|
-
applications under `apps`, shared libraries under `libs`, and deployment assets under `infra`. `apps/akan` is
|
|
348
|
-
[akanjs.com](https://akanjs.com) itself.
|
|
349
|
-
|
|
350
|
-
Inside this repository, `bun run akan` builds the CLI from source and runs it:
|
|
351
|
-
|
|
352
|
-
```bash
|
|
353
|
-
bun run akan start <app>
|
|
354
|
-
bun run akan lint <app>
|
|
355
|
-
bun run akan typecheck <app>
|
|
356
|
-
bun run akan test <app-or-lib-or-pkg>
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
`AGENTS.md` is the guide for coding agents and contributors alike. When editing framework code, prefer established
|
|
360
|
-
subpaths and keep the root `akanjs` entrypoint small. The package boundary is part of the runtime design.
|
|
361
|
-
|
|
362
|
-
## Open Source Notes
|
|
363
|
-
|
|
364
|
-
- License: MIT. See [`pkgs/akanjs/LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE).
|
|
365
|
-
- Repository: [akan-team/akanjs](https://github.com/akan-team/akanjs).
|
|
366
|
-
- Contribution guide: [`pkgs/akanjs/CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md).
|
|
367
|
-
- Code of conduct: [`pkgs/akanjs/CODE_OF_CONDUCT.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md).
|
|
93
|
+
[Akan Cloud](https://cloud.akanjs.com) runs Akan apps: `akan login` signs in, and `akan tunnel <app>` shares the app
|
|
94
|
+
you are running on a public URL.
|
|
95
|
+
|
|
96
|
+
## Learn More
|
|
97
|
+
|
|
98
|
+
- [akanjs.com](https://akanjs.com): what one line of code reaches, the screen as an agent's interface, and your server
|
|
99
|
+
as an MCP server.
|
|
100
|
+
- [Docs](https://akanjs.com/docs), the [CLI reference](https://akanjs.com/references/cli/overview), and
|
|
101
|
+
[`llms.txt`](https://akanjs.com/llms.txt). Connect a coding agent to `https://akanjs.com/mcp` to read the docs while
|
|
102
|
+
it writes code.
|
|
103
|
+
- [MCP](https://akanjs.com/cheatsheet/interface/mcp) and the [in-page agent](https://akanjs.com/cheatsheet/interface/agent-chat):
|
|
104
|
+
guards, refusals, rate limits and model setup.
|
|
105
|
+
- [v3 performance](https://akanjs.com/blog/v3release#v3-performance): the numbers against v2 and how they were measured.
|
|
106
|
+
- `akanjs` is one npm package. Its subpaths (`akanjs/base`, `akanjs/client`, `akanjs/signal`, `akanjs/ui`, …) keep
|
|
107
|
+
server-only, client-only, UI and tooling code apart, and the [package reference](https://akanjs.com/references/akanjs/base)
|
|
108
|
+
covers them; the tooling ships as `@akanjs/cli` and `@akanjs/devkit`.
|
|
109
|
+
- Contributing: [`CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md) and
|
|
110
|
+
the [code of conduct](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md). License: MIT
|
|
111
|
+
([`LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE)).
|
package/client/csrTypes.ts
CHANGED
|
@@ -437,6 +437,8 @@ export interface KeyboardFrameState {
|
|
|
437
437
|
source?: "native" | "visualViewport" | "fallback";
|
|
438
438
|
animationDuration?: number;
|
|
439
439
|
animationEasing?: string;
|
|
440
|
+
/** The page's content ends at the keyboard, as UIKit's keyboard layout guide does: an iOS shell no longer pans. */
|
|
441
|
+
avoidsContent?: boolean;
|
|
440
442
|
}
|
|
441
443
|
export interface FrameContentViewportState {
|
|
442
444
|
top: number;
|
package/client/device.ts
CHANGED
|
@@ -151,6 +151,9 @@ export class Device {
|
|
|
151
151
|
topSafeArea: number;
|
|
152
152
|
bottomSafeArea: number;
|
|
153
153
|
isMobile = isMobileDevice();
|
|
154
|
+
keyboardAnimationMs = 0;
|
|
155
|
+
keyboardHeight = 0;
|
|
156
|
+
#keyboardSubscribers = new Set<(height: number) => void>();
|
|
154
157
|
#native: NativeControls | null;
|
|
155
158
|
#stopKeyboardListeners: (() => void)[] = [];
|
|
156
159
|
#pageContentRef: RefObject<HTMLDivElement | null> | null = null;
|
|
@@ -176,16 +179,25 @@ export class Device {
|
|
|
176
179
|
debugFrame("keyboard.event", { event, height, previousHeight: currentHeight });
|
|
177
180
|
if (currentHeight === height) return;
|
|
178
181
|
currentHeight = height;
|
|
182
|
+
this.keyboardHeight = height;
|
|
179
183
|
onKeyboardChanged(height);
|
|
184
|
+
for (const subscriber of this.#keyboardSubscribers) subscriber(height);
|
|
180
185
|
};
|
|
181
186
|
this.#stopKeyboardListeners.push(
|
|
182
187
|
...(["willShow", "didShow", "willHide", "didHide"] as const).map((event) =>
|
|
183
|
-
keyboard.listen(event, ({ height }) => {
|
|
188
|
+
keyboard.listen(event, ({ height, duration }) => {
|
|
189
|
+
if (duration > 0) this.keyboardAnimationMs = duration;
|
|
184
190
|
emitKeyboardHeight(event, height);
|
|
185
191
|
}),
|
|
186
192
|
),
|
|
187
193
|
);
|
|
188
194
|
}
|
|
195
|
+
subscribeKeyboard(onKeyboardChanged: (height: number) => void) {
|
|
196
|
+
this.#keyboardSubscribers.add(onKeyboardChanged);
|
|
197
|
+
return () => {
|
|
198
|
+
this.#keyboardSubscribers.delete(onKeyboardChanged);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
189
201
|
unlistenKeyboardChanged() {
|
|
190
202
|
for (const stop of this.#stopKeyboardListeners.splice(0)) stop();
|
|
191
203
|
}
|
package/index.ts
CHANGED
|
@@ -180,6 +180,8 @@ export interface AkanNativeIosConfig {
|
|
|
180
180
|
privacy?: AkanNativeConfig["privacy"];
|
|
181
181
|
/** Files copied into the app bundle, keyed by their path there; the value is the source, relative to the app folder. */
|
|
182
182
|
files?: Record<string, string>;
|
|
183
|
+
/** Leaves out the bar WebKit puts above the keyboard for a focused field, which a page cannot hide. Default false. */
|
|
184
|
+
hideFormAccessoryBar?: boolean;
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
export interface AkanNativeAndroidConfig {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akanjs",
|
|
3
|
-
"version": "3.3.0-rc.
|
|
3
|
+
"version": "3.3.0-rc.4",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
+
"description": "Akan.js, a full-stack TypeScript framework: business code written once reaches web, native apps, server, database and infrastructure. Start with: bunx create-akan-workspace@latest",
|
|
9
10
|
"homepage": "https://akanjs.com",
|
|
10
11
|
"license": "MIT",
|
|
11
12
|
"repository": {
|
|
@@ -608,16 +608,12 @@ export class SsrFromRscRenderer {
|
|
|
608
608
|
throw error;
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
+
const headPreloads = [...new Set([...(input.bootstrapModules ?? []), ...(input.modulePreloads ?? [])])];
|
|
611
612
|
const withHeadScripts = SsrFromRscRenderer.#injectHeadScriptsIntoHead(htmlStream, {
|
|
612
613
|
importmap: input.importmap,
|
|
614
|
+
modulePreloads: headPreloads,
|
|
613
615
|
|
|
614
|
-
|
|
615
|
-
...new Set([
|
|
616
|
-
...(input.bootstrapModules ?? []),
|
|
617
|
-
...(chunkPreloads?.urls ?? []),
|
|
618
|
-
...(input.modulePreloads ?? []),
|
|
619
|
-
]),
|
|
620
|
-
],
|
|
616
|
+
chunkPreloads: (chunkPreloads?.urls ?? []).filter((src) => !headPreloads.includes(src)),
|
|
621
617
|
theme: input.theme,
|
|
622
618
|
injectThemeInitScript: input.injectThemeInitScript,
|
|
623
619
|
});
|
|
@@ -747,6 +743,7 @@ export class SsrFromRscRenderer {
|
|
|
747
743
|
options: {
|
|
748
744
|
importmap?: Record<string, string>;
|
|
749
745
|
modulePreloads: string[];
|
|
746
|
+
chunkPreloads: string[];
|
|
750
747
|
theme?: AkanTheme;
|
|
751
748
|
injectThemeInitScript?: boolean;
|
|
752
749
|
},
|
|
@@ -754,6 +751,8 @@ export class SsrFromRscRenderer {
|
|
|
754
751
|
const encoder = new TextEncoder();
|
|
755
752
|
const decoder = new TextDecoder();
|
|
756
753
|
const { importmap, modulePreloads, theme, injectThemeInitScript } = options;
|
|
754
|
+
|
|
755
|
+
const chunkTags = SsrFromRscRenderer.#createModulePreloadTags(options.chunkPreloads);
|
|
757
756
|
const htmlTheme = theme && theme !== "css" && theme !== "system" ? theme : undefined;
|
|
758
757
|
const importmapTag =
|
|
759
758
|
importmap && Object.keys(importmap).length > 0
|
|
@@ -763,11 +762,11 @@ export class SsrFromRscRenderer {
|
|
|
763
762
|
const shouldInjectThemeScript = theme === "system" || (theme === undefined && injectThemeInitScript);
|
|
764
763
|
const themeInitTag = shouldInjectThemeScript ? SsrFromRscRenderer.#themeInitScript : "";
|
|
765
764
|
const tags = `${themeInitTag}${importmapTag}${modulePreloadTags}`;
|
|
766
|
-
if (!tags && !htmlTheme) return stream;
|
|
765
|
+
if (!tags && !chunkTags && !htmlTheme) return stream;
|
|
767
766
|
const htmlOpenRe = /<html(\s[^>]*)?>/i;
|
|
768
767
|
const headOpenRe = /<head(\s[^>]*)?>/i;
|
|
769
768
|
let buffered = "";
|
|
770
|
-
let
|
|
769
|
+
let awaiting: "<head>" | "</head>" | undefined = "<head>";
|
|
771
770
|
|
|
772
771
|
const withHtmlTheme = (html: string): string => {
|
|
773
772
|
if (!htmlTheme) return html;
|
|
@@ -780,30 +779,31 @@ export class SsrFromRscRenderer {
|
|
|
780
779
|
return stream.pipeThrough(
|
|
781
780
|
new TransformStream<Uint8Array, Uint8Array>({
|
|
782
781
|
transform(chunk, controller) {
|
|
783
|
-
if (
|
|
782
|
+
if (!awaiting) {
|
|
784
783
|
controller.enqueue(chunk);
|
|
785
784
|
return;
|
|
786
785
|
}
|
|
787
786
|
buffered += decoder.decode(chunk, { stream: true });
|
|
788
|
-
|
|
789
|
-
if (
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
787
|
+
let out = "";
|
|
788
|
+
if (awaiting === "<head>") {
|
|
789
|
+
const m = headOpenRe.exec(buffered);
|
|
790
|
+
if (!m) return;
|
|
791
|
+
const end = m.index + m[0].length;
|
|
792
|
+
out = withHtmlTheme(buffered.slice(0, end)) + tags;
|
|
793
|
+
buffered = buffered.slice(end);
|
|
794
|
+
awaiting = "</head>";
|
|
795
|
+
}
|
|
796
|
+
const close = chunkTags ? buffered.indexOf(awaiting) : 0;
|
|
797
|
+
const cut = close >= 0 ? close : Math.max(0, buffered.length - awaiting.length + 1);
|
|
798
|
+
out += buffered.slice(0, cut) + (close >= 0 ? chunkTags + buffered.slice(cut) : "");
|
|
799
|
+
buffered = close >= 0 ? "" : buffered.slice(cut);
|
|
800
|
+
if (close >= 0) awaiting = undefined;
|
|
801
|
+
if (out) controller.enqueue(encoder.encode(out));
|
|
796
802
|
},
|
|
797
803
|
flush(controller) {
|
|
798
|
-
if (injected) {
|
|
799
|
-
const tail = decoder.decode();
|
|
800
|
-
if (tail) controller.enqueue(encoder.encode(tail));
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
804
|
|
|
804
|
-
const
|
|
805
|
-
|
|
806
|
-
if (rest) controller.enqueue(encoder.encode(rest));
|
|
805
|
+
const rest = buffered + decoder.decode();
|
|
806
|
+
if (rest) controller.enqueue(encoder.encode(awaiting === "<head>" ? withHtmlTheme(rest) : rest));
|
|
807
807
|
},
|
|
808
808
|
}),
|
|
809
809
|
);
|
|
@@ -421,6 +421,8 @@ export interface KeyboardFrameState {
|
|
|
421
421
|
source?: "native" | "visualViewport" | "fallback";
|
|
422
422
|
animationDuration?: number;
|
|
423
423
|
animationEasing?: string;
|
|
424
|
+
/** The page's content ends at the keyboard, as UIKit's keyboard layout guide does: an iOS shell no longer pans. */
|
|
425
|
+
avoidsContent?: boolean;
|
|
424
426
|
}
|
|
425
427
|
export interface FrameContentViewportState {
|
|
426
428
|
top: number;
|
package/types/client/device.d.ts
CHANGED
|
@@ -27,10 +27,13 @@ export declare class Device {
|
|
|
27
27
|
topSafeArea: number;
|
|
28
28
|
bottomSafeArea: number;
|
|
29
29
|
isMobile: boolean;
|
|
30
|
+
keyboardAnimationMs: number;
|
|
31
|
+
keyboardHeight: number;
|
|
30
32
|
constructor({ lang, info, topSafeArea, bottomSafeArea, native }: DeviceInitOption);
|
|
31
33
|
setPageContentRef(pageContentRef: RefObject<HTMLDivElement | null>): void;
|
|
32
34
|
hideKeyboard(): Promise<void>;
|
|
33
35
|
listenKeyboardChanged(onKeyboardChanged: (height: number) => void): void;
|
|
36
|
+
subscribeKeyboard(onKeyboardChanged: (height: number) => void): () => void;
|
|
34
37
|
unlistenKeyboardChanged(): void;
|
|
35
38
|
vibrate(type?: "light" | "medium" | "heavy" | number): Promise<void>;
|
|
36
39
|
getScrollTop(): number;
|
package/types/index.d.ts
CHANGED
|
@@ -167,6 +167,8 @@ export interface AkanNativeIosConfig {
|
|
|
167
167
|
privacy?: AkanNativeConfig["privacy"];
|
|
168
168
|
/** Files copied into the app bundle, keyed by their path there; the value is the source, relative to the app folder. */
|
|
169
169
|
files?: Record<string, string>;
|
|
170
|
+
/** Leaves out the bar WebKit puts above the keyboard for a focused field, which a page cannot hide. Default false. */
|
|
171
|
+
hideFormAccessoryBar?: boolean;
|
|
170
172
|
}
|
|
171
173
|
export interface AkanNativeAndroidConfig {
|
|
172
174
|
/** Where the Android app starts, over the section's `indexPath`. */
|
|
@@ -50,6 +50,11 @@ export interface AkanNativeBoot {
|
|
|
50
50
|
/** Native hosts: the page's engine (wkwebview, webview2, webkitgtk, android-webview) and its version. */
|
|
51
51
|
engine?: string;
|
|
52
52
|
engineVersion?: string;
|
|
53
|
+
/**
|
|
54
|
+
* iOS: "page" when the shell took the WebView's own keyboard avoidance away (keyboard mode "none"), so nothing
|
|
55
|
+
* pans the page to a focused field and the page lays itself out from the keyboard plugin's events.
|
|
56
|
+
*/
|
|
57
|
+
keyboardAvoidance?: "page";
|
|
53
58
|
}
|
|
54
59
|
/** The global object. init.js fills the boot fields, @akanjs/native/core adds `receive`. */
|
|
55
60
|
export interface AkanNativeGlobal extends Partial<AkanNativeBoot> {
|
package/types/webkit/index.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export { usePageTool } from "./usePageTool.d.ts";
|
|
|
24
24
|
export type { ScreenScopeItem } from "./useScreenScope.d.ts";
|
|
25
25
|
export { useScreenScope } from "./useScreenScope.d.ts";
|
|
26
26
|
export { useThrottle } from "./useThrottle.d.ts";
|
|
27
|
-
export { useVisualViewportFrame, type VisualViewportFrame } from "./useVisualViewportFrame.d.ts";
|
|
27
|
+
export { isPageKeyboardAvoidance, useVisualViewportFrame, type VisualViewportFrame } from "./useVisualViewportFrame.d.ts";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type KeyboardFrameState } from "akanjs/client";
|
|
1
2
|
import type { CsrLocationState } from "./useCsrLocationState.d.ts";
|
|
2
3
|
import type { CsrRefs } from "./useCsrRefs.d.ts";
|
|
3
4
|
import { type useFrameSlots, type useFrameViewport } from "./useFrameRuntime.d.ts";
|
|
@@ -13,7 +14,7 @@ export declare const useCsrKeyboard: ({ viewport, updateViewport, frameSlots, ph
|
|
|
13
14
|
platformProfile: import("akanjs/client").FramePlatformProfile;
|
|
14
15
|
accessoryHeight: number;
|
|
15
16
|
shouldAnchorContentBottom: boolean;
|
|
16
|
-
keyboardFrame:
|
|
17
|
+
keyboardFrame: KeyboardFrameState;
|
|
17
18
|
keyboardLayout: Pick<import("akanjs/client").FrameLayoutState, "keyboardAccessory" | "contentViewport">;
|
|
18
19
|
};
|
|
19
20
|
export type CsrKeyboard = ReturnType<typeof useCsrKeyboard>;
|
|
@@ -8,6 +8,7 @@ export declare const KEYBOARD_SHOW_ANIMATION_DURATION_MS = 420;
|
|
|
8
8
|
export declare const KEYBOARD_HIDE_ANIMATION_DURATION_MS = 90;
|
|
9
9
|
export declare const KEYBOARD_SHOW_ANIMATION_EASING = "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
10
10
|
export declare const KEYBOARD_HIDE_ANIMATION_EASING = "cubic-bezier(0.7, 0, 0.84, 0)";
|
|
11
|
+
export declare const IOS_KEYBOARD_ANIMATION_EASING = "cubic-bezier(0.38, 0.7, 0.125, 1)";
|
|
11
12
|
export declare const FRAME_Z_INDEX: {
|
|
12
13
|
readonly page: 10;
|
|
13
14
|
readonly previousPage: 0;
|
|
@@ -43,13 +44,15 @@ export declare function getKeyboardAccessorySlots(path: string, frameSlots: Fram
|
|
|
43
44
|
export declare function resolveKeyboardAccessoryHeight(path: string, frameSlots: FrameSlotMap): number;
|
|
44
45
|
export declare function hasKeyboardStickySlot(path: string, frameSlots: FrameSlotMap): boolean;
|
|
45
46
|
export declare function hasBottomAnchoredKeyboardSlot(path: string, frameSlots: FrameSlotMap): boolean;
|
|
46
|
-
export declare function resolveKeyboardFrame({ keyboardHeight, visualViewportKeyboardHeight, platformProfile, sticky, freeze, }: {
|
|
47
|
+
export declare function resolveKeyboardFrame({ keyboardHeight, visualViewportKeyboardHeight, platformProfile, sticky, freeze, pageAvoidsKeyboard, nativeAnimationDuration, }: {
|
|
47
48
|
keyboardHeight: number;
|
|
48
49
|
bottomSafeArea: number;
|
|
49
50
|
visualViewportKeyboardHeight: number;
|
|
50
51
|
platformProfile: FramePlatformProfile;
|
|
51
52
|
sticky: boolean;
|
|
52
53
|
freeze?: boolean;
|
|
54
|
+
pageAvoidsKeyboard?: boolean;
|
|
55
|
+
nativeAnimationDuration?: number;
|
|
53
56
|
}): KeyboardFrameState;
|
|
54
57
|
export declare function resolveKeyboardLayout({ viewport, keyboard, accessoryHeight, bottomSafeArea, }: {
|
|
55
58
|
viewport: FrameLayoutState["viewport"];
|
|
@@ -5,6 +5,8 @@ export interface VisualViewportFrame {
|
|
|
5
5
|
height: number;
|
|
6
6
|
offsetTop: number;
|
|
7
7
|
}
|
|
8
|
+
/** Whether the iOS shell left the keyboard to the page; an older shell still pans to the field, so the page must not. */
|
|
9
|
+
export declare const isPageKeyboardAvoidance: () => boolean;
|
|
8
10
|
/**
|
|
9
11
|
* The visible part of the page while the on-screen keyboard is up, on the web. Only `visualViewport` reports the
|
|
10
12
|
* keyboard: `dvh` tracks the browser's own chrome, and iOS pans the visual viewport to the field instead of shrinking
|