Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff1b846b73 | ||
|
|
ad47d4a0d2 | ||
|
|
c080b79c5b | ||
|
|
f19f614e0d | ||
|
|
8fbf617e05 | ||
|
|
a9d30cdf4a | ||
|
|
4c27c8afeb |
No files matched your search
@@ -0,0 +1,144 @@
|
||||
---
|
||||
name: marqdo-dev
|
||||
description: >-
|
||||
Develop Marqdo programs and libraries the readable way: GFM tables as data,
|
||||
code-as-documentation, table.put over json.set chains, lib/ext authoring.
|
||||
Use when writing or refactoring .mq.md, creating lib/* or ext/*, reviewing
|
||||
Marqdo style, fixing unreadable json glue, or when the user asks how to
|
||||
develop Marqdo / 如何开发 marqdo.
|
||||
---
|
||||
|
||||
# Marqdo development (author + library)
|
||||
|
||||
Read this **before** writing or expanding `.mq.md`. Syntax basics stay in [marqdo](../marqdo/SKILL.md); this skill is the **style and library craft** contract.
|
||||
|
||||
## Non-negotiable: code is documentation
|
||||
|
||||
A `.mq.md` file must stay readable as Markdown. If a human cannot skim the data and intent without decoding nested `json.set` / `json.append` chains, the code is wrong.
|
||||
|
||||
| Prefer | Avoid |
|
||||
|--------|--------|
|
||||
| GFM tables for maps, lists, records, wire, commands | Building the same with `json.set` / `json.append` |
|
||||
| Named library helpers (`web.*`, `browser.*`, `table.*`) | Copy-paste effect-map glue in every handler |
|
||||
| `table.put` for **one** dynamic key | Long `json.set` pipelines |
|
||||
| `json.parse` / `json.stringify` / `json.quote` only | Using `json` as a general dict builder |
|
||||
|
||||
`lib/json` is for **parse / stringify / quote**. Collection edits use **GFM tables** and **`lib/table`** (`doc/design/stdlib-table.md`).
|
||||
|
||||
## How to shape data
|
||||
|
||||
### 1. GFM table geometry (memorize)
|
||||
|
||||
| Shape | Result |
|
||||
|-------|--------|
|
||||
| 1 column | list |
|
||||
| ≥2 columns, **one** data row | map (headers = keys) |
|
||||
| ≥2 columns, **many** rows | map of lists (column-oriented) |
|
||||
| First header `@` / `行` / `row` | **list of maps** (row records) |
|
||||
|
||||
Cells are expressions (`doc/design/table-cell-expressions.md`): bare words = text, `` `var` `` = variable, quote paths/`/` ratios.
|
||||
|
||||
### 2. Good patterns
|
||||
|
||||
**Wire / steps / commands** — `@` record table:
|
||||
|
||||
```markdown
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 |
|
||||
|---|--------|------|------|
|
||||
| 1 | "#bump" | click | bump |
|
||||
```
|
||||
|
||||
**Multi-key return / boot** — map table with variable cells:
|
||||
|
||||
```markdown
|
||||
`boot` =
|
||||
|
||||
| wire | set_text |
|
||||
|------|----------|
|
||||
| `wire` | `set_text` |
|
||||
```
|
||||
|
||||
**Single dynamic key** — one `table.put` (or a helper), not a json chain:
|
||||
|
||||
```markdown
|
||||
*`set_text` = > table.put in=None at="#log" value=msg*
|
||||
**> table.put in=None at="set_text" value=set_text**
|
||||
```
|
||||
|
||||
Better still — call a named helper:
|
||||
|
||||
```markdown
|
||||
**> browser.set_text sel="#log" text=msg**
|
||||
```
|
||||
|
||||
### 3. Bad pattern (do not write)
|
||||
|
||||
```markdown
|
||||
*`ret` = > json.set map=None key="set_text" value=…*
|
||||
*`ret` = > json.set map=ret key="canvas" value=…*
|
||||
*`cmds` = > json.append list=cmds item=c0*
|
||||
```
|
||||
|
||||
## Writing application `.mq.md`
|
||||
|
||||
1. Frontmatter: title + imports (`table`, domain libs). **Do not import `json` unless parsing strings.**
|
||||
2. `# main`: state binds, then **tables** for wire/config, return boot map via table or helper.
|
||||
3. `##` handlers: short prose OK; data as tables; return via `browser.*` / `web.*` / one `table.put`.
|
||||
4. Blank line between comment paragraphs and code.
|
||||
5. Run `marqdo run path.mq.md` from repo root.
|
||||
|
||||
Browser client programs: prefer `import browser:lib/browser.mq.md` (no native plugin). Server sites: `ext/web` + GFM page/style tables.
|
||||
|
||||
## Developing libraries (`lib/*`, `ext/*`)
|
||||
|
||||
### Goals
|
||||
|
||||
- **Authors** see tables and short calls; **library** may hide `table.put` / host calls.
|
||||
- One concern per helper; name the effect (`set_text`, `canvas`, …), do not expose bag surgery.
|
||||
- EN + ZH pair when shipping user-facing libs (`lib/browser.mq.md` ↔ `lib/浏览器.mq.md`, `ext/web` ↔ `ext/web/网页.mq.md`).
|
||||
- `ext/**` never calls `host_*` — use plugins / public lib only (`doc/design/ext-agent.md`).
|
||||
|
||||
### Library checklist
|
||||
|
||||
- [ ] Public examples use **tables + helpers**, not json glue
|
||||
- [ ] Helpers documented with a one-line purpose above `##`
|
||||
- [ ] Defaults on `+` params; omit `None` fields in merged maps
|
||||
- [ ] No `json.set` chains in new code — use `table.put` / `table.merge` / GFM
|
||||
- [ ] `marqdo run` on a tiny demo under `examples/` or inline smoke
|
||||
|
||||
### Where helpers live
|
||||
|
||||
| Need | Place |
|
||||
|------|--------|
|
||||
| Browser effect maps (WASM client) | `lib/browser.mq.md` |
|
||||
| Site HTML / HTTP / DB | `ext/web` classes + compose from tables |
|
||||
| List/map primitives | `lib/table.mq.md` |
|
||||
| Parse JSON text | `lib/json.mq.md` only |
|
||||
|
||||
## Refactoring existing glue
|
||||
|
||||
When editing a file full of `json.set`:
|
||||
|
||||
1. Turn static structures into GFM tables.
|
||||
2. Replace repeated effect shapes with `browser.*` / `web.text_patch` / `web.dom_patch`.
|
||||
3. Leave at most sparse `table.put` for dynamic keys.
|
||||
4. Drop `import json:…` if unused.
|
||||
|
||||
## Anti-patterns
|
||||
|
||||
| Wrong | Right |
|
||||
|-------|-------|
|
||||
| `json.set` × N to build boot | GFM map table or `browser`/`web` helper |
|
||||
| `json.append` to build command list | `@` record table |
|
||||
| Dummy column to force a 1-key map | `table.put` or helper |
|
||||
| Importing `ext/web` only for `text_patch` in WASM | `lib/browser` (no native plugin) |
|
||||
| Unreadable nested maps as “clever” | Flatten into tables humans can read |
|
||||
|
||||
## Related
|
||||
|
||||
- Syntax: [marqdo/SKILL.md](../marqdo/SKILL.md) · [examples.md](../marqdo/examples.md)
|
||||
- Tables: `doc/design/stdlib-table.md` · `doc/design/table-cell-expressions.md`
|
||||
- Browser effects: `doc/roadmap/browser-wasm-e.md` · `doc/roadmap/browser-wasm-f.md`
|
||||
- Release: [marqdo-release](../marqdo-release/SKILL.md)
|
||||
@@ -231,7 +231,7 @@ export HTTP_PROXY=http://HOST:PORT
|
||||
|
||||
3. **Agent Shell**: retry `git push` / `gh` with `required_permissions: ["all"]` (and `full_network` if needed).
|
||||
|
||||
4. **`gh` auth**: if `gh auth status` fails, ask user to `gh auth login` or set `GH_TOKEN` / `GITHUB_TOKEN` for the session — **never commit tokens**.
|
||||
4. **`gh` auth**: if `gh auth status` fails, ask user to `gh auth login` or set `GH_TOKEN` / `GITHUB_TOKEN` for the session — **never commit tokens**. Fallback used in this repo: load password from `git credential fill` (`protocol=https` / `host=github.com`) into `GH_TOKEN` for the session only, then delete the temp env file.
|
||||
|
||||
5. **Git remote**: prefer `https://github.com/cflmy/marqdo.git`; SSH needs keys.
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ Marqdo = **Markdown markers as syntax**. A `.mq.md` file is both documentation a
|
||||
|
||||
Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords.md`. Deeper tables: [reference.md](reference.md). Copy-paste patterns: [examples.md](examples.md).
|
||||
|
||||
**Authoring / library craft** (GFM-first, no json glue, how to develop Marqdo): use **[marqdo-dev](../marqdo-dev/SKILL.md)** whenever writing or refactoring `.mq.md`, `lib/*`, or `ext/*`.
|
||||
|
||||
**Product release** (tag, CHANGELOG, README, public docs, VSIX, GitHub assets): use [marqdo-release](../marqdo-release/SKILL.md) — detect latest version, **ask the user for the next SemVer**, then follow that playbook. Do not invent a version number.
|
||||
|
||||
## Hard rules (do not violate)
|
||||
@@ -29,7 +31,9 @@ Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords.
|
||||
7. **Paths:** In bare *expressions* `/` is division. In **call args / param defaults / table cells**, unspaced `a/b` and quoted `".marqdo/agent-kb"` are path text — no `json.parse` needed. Numeric ratios that must stay text use quotes (`"1/5"`, `"16/9"`); bare `1/5` is division.
|
||||
8. Prefer ending side-effect-only function bodies with a lone `---` or `***` line (or `****` empty return) so later siblings are not swallowed.
|
||||
9. **`ext/**` never calls `host_*`.** Agent/OKF helpers are plugin names (`agent_kb_*`, …) after `plugin.load`. Do **not** add agent/OKF domain code to `src/host/` (core bloat). See `doc/design/ext-agent.md` §4.
|
||||
10. **Browser (route C):** client logic is Marqdo on WASM ([ADR 0002](../../../doc/adr/0002-browser-marqdo-wasm.md)); async I/O via return effects `fetch`/`after` ([ADR 0003](../../../doc/adr/0003-browser-async-effects.md)); official bridge is host glue only.
|
||||
10. **Browser (route C/D/E/F):** client logic is Marqdo on WASM; official bridge is host glue and **may** implement lists, routing, storage, WebSocket, canvas, file read, observers — authors **must not hand-write business JS**. Use `web.client_embed` / `data-mq-source-url` auto-mount. Client effects: prefer **GFM tables + `lib/browser`** ([marqdo-dev](../marqdo-dev/SKILL.md)).
|
||||
11. **Code-as-documentation / no bag glue:** Prefer **GFM tables** for maps, lists, wire, commands. Prefer **`table.put` / named helpers** over `json.set` / `json.append` chains. `lib/json` is for parse/stringify/quote only — not a dict builder. Unreadable json pipelines are a style bug.
|
||||
|
||||
|
||||
## Markup → meaning (v0.2)
|
||||
|
||||
@@ -175,11 +179,11 @@ data/ # sqlite runtime (gitignore)
|
||||
|
||||
**Core objects (EN / ZH):** `# page`/`页面`, `# style`/`样式`, `# db`/`数据库`, `# form`/`表单`, `# app`/`应用`, `# auth`/`鉴权`, `# cache`/`缓存`, `# storage`/`存储`.
|
||||
|
||||
**Typical flow:** `db.init` → `page.compose_components` + `page.compose_main` → `page.head` / `page.images` / `page.meta` → `app` with `route` / `static` / `icons` / `configure` / `listen`.
|
||||
**Typical flow:** `db.init` → `page.compose_*` → `app` + `static` / `listen`. Client: `marqdo wasm build -o static` + `web.client_embed source="/static/client.mq.md"` — **no author JS**; bridge may implement rich host effects ([browser-wasm-e.md](../../doc/roadmap/browser-wasm-e.md) · [browser-app](../../examples/browser-app/)).
|
||||
|
||||
**Shipped surface (W0–W7 + P3 + W8):** middleware + JSON API (`app.configure`); transactions, pagination, FTS search (`db.migrate`, `db.fts`, `db.search`); security (argon2, CSRF, SQLite sessions, login rate limit); SEO / RSS / Markdown (`page.meta`, `route_rss`, `lib/net.markdown_parse`); upload / download / gallery; sitemap / robots / error pages / redirects; RBAC (`app.gate`, user `role`); audit timestamps + FK in `db.init`; ETag on downloads; **W8** site icons (`app.icons` → `/favicon.ico`), head resource tables (`page.head`), image assembly (`make_images` / `page.images`).
|
||||
**Shipped surface (W0–W7 + P3 + W8 + route D mount):** middleware + JSON API (`app.configure`); transactions, pagination, FTS search (`db.migrate`, `db.fts`, `db.search`); security (argon2, CSRF, SQLite sessions, login rate limit); SEO / RSS / Markdown (`page.meta`, `route_rss`, `lib/net.markdown_parse`); upload / download / gallery; sitemap / robots / error pages / redirects; RBAC (`app.gate`, user `role`); audit timestamps + FK in `db.init`; ETag on downloads; **W8** site icons (`app.icons` → `/favicon.ico`), head resource tables (`page.head`), image assembly (`make_images` / `page.images`); **D** `client_embed` auto-mount + DOM effect helpers (`text_patch` / `dom_patch`).
|
||||
|
||||
Design: [ext-web.md](../../doc/design/ext-web.md) · assets: [web-assets-and-images.md](../../doc/design/web-assets-and-images.md) · capability matrix: [web-net-capabilities.md](../../doc/design/web-net-capabilities.md) · example: [examples/marqdo-blog/](../../examples/marqdo-blog/).
|
||||
Design: [ext-web.md](../../doc/design/ext-web.md) · assets: [web-assets-and-images.md](../../doc/design/web-assets-and-images.md) · capability matrix: [web-net-capabilities.md](../../doc/design/web-net-capabilities.md) · example: [examples/marqdo-blog/](../../examples/marqdo-blog/) · client: [examples/web-client-site/](../../examples/web-client-site/).
|
||||
|
||||
Web patterns: [examples.md](examples.md) §13 · API index: [reference.md](reference.md).
|
||||
|
||||
@@ -228,7 +232,9 @@ Design: [ext-quantum.md](../../doc/design/ext-quantum.md) · Q7: [ext-quantum-q7
|
||||
| Forgetting `---` after nested `##` helper | Add `---` / `***` / `****` |
|
||||
| Import `lib/text` then call bare `split` | `> text.split …` (qualified) |
|
||||
| Import `lib/text` then call `拆分` | Match file language (`text.split`, not 文本) |
|
||||
| `json.set` / `json.append` to build maps or lists | GFM tables; sparse `table.put`; named helpers (`browser.*`, `web.*`) |
|
||||
| `json.set` to build page parts | GFM tables + `page.compose_*` / `web.page` methods |
|
||||
| Import `json` for every browser handler | `import browser:lib/browser.mq.md` + tables ([marqdo-dev](../marqdo-dev/SKILL.md)) |
|
||||
| Mix `web.page` and `网页.页面` in one file | One import language per `.mq.md` |
|
||||
| Call `host_web_*` from `ext/web` | Use `# app` / `# db` methods; plugin ABI only |
|
||||
| Call `host_*` from `ext/quantum` | Use `# circuit` / `# density` methods; plugin ABI only |
|
||||
@@ -244,6 +250,8 @@ Design: [ext-quantum.md](../../doc/design/ext-quantum.md) · Q7: [ext-quantum-q7
|
||||
- [ ] `# main` exists when the file is an entry program
|
||||
- [ ] Nested functions ended with `---` / `***` / `****` when needed
|
||||
- [ ] Imports and call names share the same language file
|
||||
- [ ] Data shaped as **GFM tables** (or short helpers) — no `json.set` / `json.append` glue
|
||||
- [ ] Web sites: tables + web classes only (no JSON glue); `data/` gitignored
|
||||
- [ ] Browser client: `lib/browser` + tables when returning effects
|
||||
- [ ] Quantum draw: quote `kind=` / `theme=`; rebuild plugin → `ext add quantum` before view
|
||||
- [ ] `marqdo run` succeeds (or errors addressed)
|
||||
@@ -78,6 +78,7 @@ Greeting via a nested function:
|
||||
> print text=`果`
|
||||
```
|
||||
|
||||
|
||||
## 6b. Map table + footnote get
|
||||
|
||||
```markdown
|
||||
@@ -109,6 +110,31 @@ Row-oriented records (SQL-like): first header `@` / `行` / `row` → list of ma
|
||||
*名 = 订单[^1][^品名]*
|
||||
```
|
||||
|
||||
## 6c. Browser effects — tables + lib/browser (not json.set)
|
||||
|
||||
```markdown
|
||||
---
|
||||
import browser:lib/browser.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 |
|
||||
|---|--------|------|------|
|
||||
| 1 | "#bump" | click | bump |
|
||||
|
||||
**`wire`**
|
||||
|
||||
## bump
|
||||
*`count` = count + 1*
|
||||
*`label` = > str count*
|
||||
**> browser.set_text sel="#count" text=label**
|
||||
```
|
||||
|
||||
Do **not** build effect maps with `json.set` chains. See [marqdo-dev](../marqdo-dev/SKILL.md).
|
||||
|
||||
## 7. Import text stdlib
|
||||
|
||||
```markdown
|
||||
|
||||
@@ -44,12 +44,13 @@ Import one file; use **that** file’s function names.
|
||||
|-----------|-----------|-------------------------|
|
||||
| `lib/text.mq.md` | `lib/文本.mq.md` | text helpers / 去空白·拆分·拼接… |
|
||||
| `lib/table.mq.md` | `lib/表.mq.md` | `put`/`改` + list/map(见 `doc/design/stdlib-table.md`) |
|
||||
| `lib/browser.mq.md` | `lib/浏览器.mq.md` | WASM client effect helpers(GFM + `set_text`/`canvas`/…;见 marqdo-dev) |
|
||||
| `lib/fs.mq.md` | `lib/文件.mq.md` | filesystem |
|
||||
| `lib/sys.mq.md` | `lib/系统.mq.md` | process / cwd / load_dotenv |
|
||||
| `lib/plugin.mq.md` | `lib/插件.mq.md` | load native ABI plugins (`doc/design/ext-abi.md`) |
|
||||
| `lib/time.mq.md` | `lib/时间.mq.md` | time/format |
|
||||
| `lib/net.mq.md` | `lib/网络.mq.md` | HTTP(S) helpers (+ optional headers) |
|
||||
| `lib/json.mq.md` | (see design) | JSON (+ `quote`) |
|
||||
| `lib/json.mq.md` | (see design) | **parse / stringify / quote only** — not a dict builder |
|
||||
| `lib/math.mq.md` | `lib/数学.mq.md` | num, trig, random, formula, plot |
|
||||
| `lib/foreign.mq.md` | `lib/外联.mq.md` | run foreign fenced blocks |
|
||||
| `ext/llm.mq.md` | `ext/大模型.mq.md` | `# llm` / `# 大模型` object + chat methods |
|
||||
|
||||
@@ -92,10 +92,10 @@ jobs:
|
||||
body: |
|
||||
## Marqdo ${{ github.ref_name }}
|
||||
|
||||
### 亮点 / Highlights — v0.3.2
|
||||
- **浏览器 Marqdo(路线 C)**:`marqdo wasm build`、官方 bridge、会话 ABI、`fetch`/`after` 效应;示例 `examples/browser-hello/`
|
||||
- **Browser Marqdo (route C)**: WASM build, official bridge, session ABI, async effects; see CHANGELOG
|
||||
- Fix: Admin 长内容布局 · `ext add` 原生插件预检 · `@keyframes` / 样式表比率引号约定
|
||||
### 亮点 / Highlights — v0.3.3
|
||||
- **浏览器作者零业务 JS(D/E/F)**:bridge 自启;DOM/路由/storage/ws/文件/Canvas/音频/Observer/拖放;`lib/browser` + GFM
|
||||
- **Browser author-zero-JS (routes D/E/F)**: host effects + `lib/browser`; examples `browser-hello` / `browser-app` / `browser-media`
|
||||
- Skill: `marqdo-dev`(代码即文档 / 禁止 json.set 胶水)
|
||||
- Install: `marqdo ext list` / `marqdo ext add llm|agent|web|quantum`
|
||||
- Native plugins: `cargo build --release -p marqdo_plugin_*` then `ext add`
|
||||
- Details: [CHANGELOG](https://github.com/cflmy/marqdo/blob/main/CHANGELOG.md) · [README](https://github.com/cflmy/marqdo/blob/main/README.md)
|
||||
|
||||
@@ -42,6 +42,9 @@ spike/.pytest_cache/
|
||||
# Built browser WASM (rebuild via crates/marqdo-wasm README)
|
||||
/examples/browser-hello/marqdo_wasm.wasm
|
||||
/examples/browser-hello/pkg/
|
||||
/examples/web-client-site/static/marqdo_wasm.wasm
|
||||
/examples/browser-app/marqdo_wasm.wasm
|
||||
/examples/browser-media/marqdo_wasm.wasm
|
||||
|
||||
# Local sqlite / scratch
|
||||
/data/
|
||||
|
||||
@@ -8,6 +8,30 @@
|
||||
|
||||
### Changed
|
||||
|
||||
## v0.3.3 — 2026-09-04
|
||||
|
||||
### Highlights
|
||||
|
||||
**浏览器作者零业务 JS(路线 D/E/F)**:官方 bridge 自启 + 宿主效应补齐(DOM/路由/storage/ws/文件/Canvas/音频/Observer/拖放);`lib/browser` + GFM 表格写法;新增 [marqdo-dev](.cursor/skills/marqdo-dev/SKILL.md) 开发约定。
|
||||
|
||||
```bash
|
||||
git checkout v0.3.3
|
||||
cargo build --release
|
||||
marqdo wasm build
|
||||
# examples: browser-hello / browser-app / browser-media / web-client-site
|
||||
```
|
||||
|
||||
### Added
|
||||
- **路线 D(作者零 JS)**:[roadmap](doc/roadmap/browser-wasm-d.md) · 设计 §16。官方 bridge `mount` / `data-mq-*` 自启;`client_embed` 带 `wasm`/`source`/`boot`;DOM 效应;`examples/web-client-site/`。
|
||||
- **路线 E(前端补齐)**:[browser-wasm-e.md](doc/roadmap/browser-wasm-e.md)。多节点 DOM、`add_class`/`remove_class`、cookie、clipboard/download、`fetch_all`/`ws`/`interval`;示例 [browser-app](examples/browser-app/)。
|
||||
- **路线 F(媒体/文件,F1–F5)**:[browser-wasm-f.md](doc/roadmap/browser-wasm-f.md)。`read_file`、Canvas 2D、Audio beep、Intersection/ResizeObserver、drag/drop;示例 [browser-media](examples/browser-media/)。
|
||||
- **`lib/browser` / `lib/浏览器`**:WASM 客户端效应助手(GFM 表格 + named helpers;勿用 `json.set` 链)。
|
||||
- **Skill `marqdo-dev`**:代码即文档 / GFM-first / 库开发约定。
|
||||
|
||||
### Changed
|
||||
- 浏览器示例(hello / app / media / web-client)改为表格 + `lib/browser`;`ext/web` 效应助手改用 `table.put`。
|
||||
- 标准库模块表收录 `browser`;路线 F 收口 F1–F5(F6 Service Worker 仍可选)。
|
||||
|
||||
## v0.3.2 — 2026-09-01
|
||||
|
||||
### Highlights
|
||||
|
||||
Generated
+2
-2
@@ -1018,7 +1018,7 @@ checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
||||
|
||||
[[package]]
|
||||
name = "marqdo"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
@@ -1042,7 +1042,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "marqdo-wasm"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
dependencies = [
|
||||
"marqdo",
|
||||
"serde_json",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "marqdo"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
description = "Marqdo — Markdown markers as an interpreted programming language"
|
||||
|
||||
@@ -99,7 +99,7 @@ marqdo catalog public -o .marqdo
|
||||
|
||||
---
|
||||
|
||||
## 现状(v0.3.2)
|
||||
## 现状(v0.3.3)
|
||||
|
||||
- 映射与解释器:Phase I 树遍历 + 字节码后端可用;金样例在 `tests/`
|
||||
- **对象**:`#` = 类型/构造,`##`+ = 函数/方法;见 [objects.md](doc/design/objects.md)
|
||||
@@ -107,7 +107,7 @@ marqdo catalog public -o .marqdo
|
||||
- **`marqdo debug`**:独立调试页(断点 / 单步 / locals;默认端口 7430;页面 favicon / 品牌使用官方 Logo)
|
||||
- **`marqdo catalog` / `sync`**:OKF 风格 YAML + 模块概念页
|
||||
- **`marqdo version --check`**:与 GitHub 最新 release 对比
|
||||
- 标准库:**内置于二进制**(v0.1.2+);磁盘 `lib/` 或 `MARQDO_LIB` 可覆盖。模块含文本、文件、系统、时间、JSON、网络、数学、外联、插件、**自写回**、**子任务**
|
||||
- 标准库:**内置于二进制**(v0.1.2+);磁盘 `lib/` 或 `MARQDO_LIB` 可覆盖。模块含文本、表、**浏览器效应**、文件、系统、时间、JSON、网络、数学、外联、插件、**自写回**、**子任务**
|
||||
- **官方扩展库 `ext/`**(**非** stdlib,本版收口):
|
||||
- **`web`**:W0–W7 + P3 + **W8**(favicon / Head 资源 / 图片装配,见 [web-assets-and-images.md](doc/design/web-assets-and-images.md));示例 [marqdo-blog](examples/marqdo-blog/);生产路径见 [web-asgi-servers-and-marqdo.md](doc/design/web-asgi-servers-and-marqdo.md)(反向代理 → 嵌入式 `listen`,非 Daphne/Uvicorn)
|
||||
- **`quantum`**:Q0–Q7 + Q8a/b 主题 SVG;示例 [quantum-entanglement](examples/quantum-entanglement/)
|
||||
@@ -117,15 +117,15 @@ marqdo catalog public -o .marqdo
|
||||
- **原生插件 ABI**:[`include/marqdo_abi.h`](include/marqdo_abi.h) · [ext-abi.md](doc/design/ext-abi.md);`plugins/{demo,agent,web,quantum}`
|
||||
- **用户静态站**:`public/` → `view output` → CI 发布 [gh-pages](https://cflmy.github.io/marqdo/)
|
||||
- **VS Code 扩展**:分支 **`vscode-extension`**(`main` 不跟踪源码;见 [vscode-extension-commit.md](doc/design/vscode-extension-commit.md));Release 附带 `.vsix`
|
||||
- **浏览器 Marqdo(WASM)**:`marqdo wasm build` + 官方 bridge;示例 [browser-hello](examples/browser-hello/);站点挂载 `web.client_embed` / `网页.客户端挂载`([ADR 0002](doc/adr/0002-browser-marqdo-wasm.md) · [ADR 0003](doc/adr/0003-browser-async-effects.md))
|
||||
- **浏览器 Marqdo(WASM)**:`marqdo wasm build` + 官方 bridge 自启(作者零业务 JS;桥内可含列表/路由/storage/ws/文件/Canvas/音频/Observer/拖放);`lib/browser` + GFM;`web.client_embed`;示例 [browser-hello](examples/browser-hello/) · [browser-app](examples/browser-app/) · [browser-media](examples/browser-media/) · [web-client-site](examples/web-client-site/)([ADR 0002](doc/adr/0002-browser-marqdo-wasm.md) · [D](doc/roadmap/browser-wasm-d.md) · [E](doc/roadmap/browser-wasm-e.md) · [F](doc/roadmap/browser-wasm-f.md))
|
||||
- 选型:[ADR 0001 — Rust](doc/adr/0001-implementation-language.md) · [ADR 0002 — 浏览器 WASM](doc/adr/0002-browser-marqdo-wasm.md)(C0–C5 完结,见 [roadmap/browser-wasm.md](doc/roadmap/browser-wasm.md))· [ADR 0003 — 异步效应](doc/adr/0003-browser-async-effects.md)
|
||||
|
||||
### 如何使用最新 Marqdo(v0.3.2)
|
||||
### 如何使用最新 Marqdo(v0.3.3)
|
||||
|
||||
```bash
|
||||
# 1) 源码安装(跟 tag 或 main)
|
||||
git clone https://github.com/cflmy/marqdo.git && cd marqdo
|
||||
git checkout v0.3.2 # 或留在 main
|
||||
git checkout v0.3.3 # 或留在 main
|
||||
cargo build --release
|
||||
export PATH="$PWD/target/release:$PATH"
|
||||
marqdo version
|
||||
@@ -154,7 +154,7 @@ marqdo wasm build
|
||||
# → dist/wasm/ … 见 examples/browser-hello/
|
||||
|
||||
# 6) Windows:也可从 GitHub Releases 下载 exe / zip / vsix
|
||||
# https://github.com/cflmy/marqdo/releases/tag/v0.3.2
|
||||
# https://github.com/cflmy/marqdo/releases/tag/v0.3.3
|
||||
```
|
||||
|
||||
开发期也可用 `cargo run -- …` 代替已安装的 `marqdo`:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "marqdo-wasm"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
description = "Marqdo interpreter as WebAssembly (browser host bridge)"
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+5
-1
@@ -59,7 +59,11 @@
|
||||
| [roadmap/object-inheritance.md](roadmap/object-inheritance.md) | **对象继承**(`# 子类 = > 父类`;I0–I2 已落地) |
|
||||
| [roadmap/tables-maps-footnotes.md](roadmap/tables-maps-footnotes.md) | **表格语义**(竖表 / 横表字典 / 脚注取元 / 行向记录 / **单元格表达式 T5**) |
|
||||
| [design/table-cell-expressions.md](design/table-cell-expressions.md) | **表数据单元格 = 表达式**(同调用实参值语法;Accepted) |
|
||||
| [roadmap/ext-web.md](roadmap/ext-web.md) | **实现路线:`ext/web`**(W0–W4;设计见 [ext-web.md](../design/ext-web.md)) |
|
||||
| [roadmap/browser-wasm.md](roadmap/browser-wasm.md) | **浏览器 WASM 路线 C(C0–C5 Completed)** |
|
||||
| [roadmap/browser-wasm-d.md](roadmap/browser-wasm-d.md) | **路线 D:作者零 JS 前端(Completed)** |
|
||||
| [roadmap/browser-wasm-e.md](roadmap/browser-wasm-e.md) | **路线 E:前端能力补齐(Completed)** |
|
||||
| [roadmap/browser-wasm-f.md](roadmap/browser-wasm-f.md) | **路线 F:媒体/文件/Canvas 等(Completed,F1–F5;v0.3.3)** |
|
||||
| [design/browser-marqdo-wasm.md](design/browser-marqdo-wasm.md) | **浏览器 Marqdo(WASM)设计** |
|
||||
| [roadmap/ext-quantum.md](roadmap/ext-quantum.md) | **规划:`ext/quantum` 量子模拟**(基础门·电路·ABI·`ext add`) |
|
||||
| [research/okf-and-marqdo.md](research/okf-and-marqdo.md) | OKF 调研 |
|
||||
| [research/agent-frameworks-and-marqdo.md](research/agent-frameworks-and-marqdo.md) | 主流智能体框架 vs Marqdo 优势 |
|
||||
|
||||
@@ -299,6 +299,93 @@ marqdo wasm build -o static # marqdo_wasm.wasm + marqdo-bridge.js
|
||||
|
||||
---
|
||||
|
||||
## 16. 路线 D — 作者零 JS(Active)
|
||||
|
||||
路线图:[browser-wasm-d.md](../roadmap/browser-wasm-d.md)。
|
||||
|
||||
**原则:** 业务与交互 100% `.mq.md`;`marqdo-bridge.js` 仅宿主胶。作者仓库可不含自写 `.js`。
|
||||
|
||||
### 16.1 一键挂载
|
||||
|
||||
| API | 含义 |
|
||||
|-----|------|
|
||||
| `mount({ wasmUrl, source \| sourceUrl, … })` | `loadWasm` → `boot` → `wireEvents` → 初始效应 |
|
||||
| `script[data-mq-source-url]` / `data-mq-wasm` | 模块脚本属性自启 |
|
||||
| `#marqdo-boot` | `application/json` 配置块 |
|
||||
| `data-mq-playground` | 官方 playground(`#src,#run,#out`),仍非业务 JS |
|
||||
|
||||
`ext/web`:`client_embed` / `客户端挂载` 参数 `bridge`、`wasm`、`source`、`boot`(默认 true)。
|
||||
|
||||
```bash
|
||||
marqdo wasm build -o static # marqdo_wasm.wasm + marqdo-bridge.js
|
||||
# app.static dir=static
|
||||
# intro 或主区嵌入 > web.client_embed source="/static/client.mq.md"
|
||||
```
|
||||
|
||||
### 16.2 DOM / 表单效应(D3)
|
||||
|
||||
与 `set_text` / `fetch` / `after` 并列(白名单;**默认无**任意脚本注入):
|
||||
|
||||
| 字段 | 作用 |
|
||||
|------|------|
|
||||
| `set_text` | `textContent` |
|
||||
| `set_value` | input/textarea/select 的 `value` |
|
||||
| `set_attr` | 属性;值为 `null`/`false` 则 `removeAttribute` |
|
||||
| `set_class` | `className` 字符串 |
|
||||
| `toggle_class` | `{ "#sel": "cls" }` 切换 class |
|
||||
| `set_html` | **仅**键前缀 `#trusted` 的选择器才写 `innerHTML`;其它键忽略 |
|
||||
|
||||
Wire 行可选 `值选择器` / `value_from`:事件触发时把该节点内容写入实参 `value`。
|
||||
事件实参默认含:`event`、`value`、`checked`、`id`(来自 event.target);`submit` 另含 `fields` 表单字典。
|
||||
|
||||
L1:`web.dom_patch` / `网页.DOM补丁` 合并效应键;`web.text_patch` / `网页.文本补丁` 快捷 `set_text`。
|
||||
|
||||
### 16.3 非目标(D)
|
||||
|
||||
| # | 非目标 |
|
||||
|---|--------|
|
||||
| D-N1 | 用 Marqdo 重写 bridge 自身 |
|
||||
| D-N2 | 作者手写业务 JS / TS(官方桥内机制允许) |
|
||||
| D-N3 | ~~开放无前缀的 set_html~~(E 已允许任意选择器;内容由 MQ 产出) |
|
||||
|
||||
---
|
||||
|
||||
## 17. 路线 E — 前端能力补齐(Active)
|
||||
|
||||
路线图:[browser-wasm-e.md](../roadmap/browser-wasm-e.md)。
|
||||
|
||||
**原则:** 唯一硬禁是**作者手写业务 JS**。官方 bridge 可实现列表装配、路由、storage、WebSocket、内部模板/轻量 VDOM 等;作者只写 `.mq.md` + 效应表。
|
||||
|
||||
| 波 | 要点 |
|
||||
|----|------|
|
||||
| E1 | `set_style` / `focus` / `blur` / `scroll_into`;wire `委托`;键盘事件 |
|
||||
| E2 | `set_html` / `replace_children` / `render_list` |
|
||||
| E3 | `navigate` + `popstate`(选择器 `window`) |
|
||||
| E4 | `storage` `{ op, key, value?, scope?, then? }` |
|
||||
| E5 | `ws` `{ op: open\|send\|close, … }` |
|
||||
| E6 | `fetch_all` / `interval` / `clear_interval` / fetch `fields` |
|
||||
|
||||
### 17.1 效应速查(E)
|
||||
|
||||
| 字段 | 含义 |
|
||||
|------|------|
|
||||
| `set_style` | `{ "#sel": { color: "red" } }` 或 `{ "#sel": "color:red" }` |
|
||||
| `focus` / `blur` | `"#sel"` 或选择器数组 |
|
||||
| `scroll_into` | `"#sel"` |
|
||||
| `set_html` / `append_html` / `replace_children` | 写/追加 HTML(MQ 产出;XSS 自负) |
|
||||
| `render_list` | `{ "#sel": { tag, items } }` |
|
||||
| `remove` | 选择器或数组,删除节点 |
|
||||
| `add_class` / `remove_class` | classList |
|
||||
| `navigate` | `{ url, replace?: bool }` |
|
||||
| `storage` | `{ op, key, value?, scope?: local\|session\|cookie, days?, then? }` |
|
||||
| `ws` | `{ op: open\|send\|close, … }` |
|
||||
| `fetch_all` | `{ requests: []\|map, then }` |
|
||||
| `interval` / `clear_interval` | 定时 |
|
||||
| `clipboard` / `download` | 剪贴板 / 触发下载 |
|
||||
| `fetch.fields` | → FormData |
|
||||
|
||||
Wire 列:`委托` / `delegate` = 在容器上监听,目标须 `closest(delegate)`;选择器 `window` 绑 `window`。
|
||||
|
||||
## 15. 决策摘要
|
||||
|
||||
| 问题 | 答案 |
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **已落地**:text/table/fs/sys/time/json/net/math/foreign/**plugin** |
|
||||
| 状态 | **已落地**:text/table/fs/sys/time/json/net/math/foreign/**plugin**/browser |
|
||||
| 日期 | 2026-08-07 |
|
||||
| 原则 | 全部经 frontmatter **导入**;除 JSON 外中英分文件;内核保持少而精 |
|
||||
| 相关 | [stdlib.md](stdlib.md) · [stdlib-i18n.md](stdlib-i18n.md) · [ext-abi.md](ext-abi.md) · [ext-llm.md](ext-llm.md) · [ext-agent.md](ext-agent.md) · [**module-namespace.md**](module-namespace.md)(导入命名空间;**M1/M2 已落地**:`库.成员` / `库.对象.成员` / `use`) |
|
||||
@@ -17,10 +17,11 @@
|
||||
|--------|--------|--------|------|
|
||||
| 文本 | `lib/text.mq.md` | `lib/文本.mq.md` | 已有 |
|
||||
| 表 | `lib/table.mq.md` | `lib/表.mq.md` | 已有(`put`/`改` + list/map;见 [stdlib-table.md](stdlib-table.md)) |
|
||||
| 浏览器效应 | `lib/browser.mq.md` | `lib/浏览器.mq.md` | WASM 客户端效应助手(GFM + helpers;勿用 `json.set` 链) |
|
||||
| 文件 | `lib/fs.mq.md` | `lib/文件.mq.md` | 已有 |
|
||||
| 系统 | `lib/sys.mq.md` | `lib/系统.mq.md` | 已有(含 `load_dotenv`) |
|
||||
| 时间 | `lib/time.mq.md` | `lib/时间.mq.md` | 已有 |
|
||||
| JSON | `lib/json.mq.md` | **同文件** | 已有(含 `quote`) |
|
||||
| JSON | `lib/json.mq.md` | **同文件** | **仅** parse / stringify / quote;集合请用 table / GFM |
|
||||
| 网络 | `lib/net.mq.md` | `lib/网络.mq.md` | 已有(HTTPS + headers) |
|
||||
| 数学 | `lib/math.mq.md` | `lib/数学.mq.md` | 已有 |
|
||||
| 外联 | `lib/foreign.mq.md` | `lib/外联.mq.md` | 已有 |
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# 路线图:浏览器 Marqdo 路线 D(作者零 JS)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **Completed**(D0–D4 已落地;续作见 [browser-wasm-e.md](browser-wasm-e.md)) |
|
||||
| 日期 | 2026-09-03 |
|
||||
| 前置 | [browser-wasm.md](browser-wasm.md)(C0–C5 **Completed**) |
|
||||
| ADR | [0002](../adr/0002-browser-marqdo-wasm.md) · [0003](../adr/0003-browser-async-effects.md) |
|
||||
| 设计 | [browser-marqdo-wasm.md](../design/browser-marqdo-wasm.md) §16 |
|
||||
|
||||
## 一句话
|
||||
|
||||
作者侧**零业务 JS**:页面逻辑与交互只写 `.mq.md`;官方 `marqdo-bridge.js` 仍作不透明宿主胶(加载 WASM / DOM / fetch),由 `mount` + `client_embed` 自动启动。
|
||||
|
||||
## 阶段
|
||||
|
||||
| 阶段 | 内容 | 状态 |
|
||||
|------|------|------|
|
||||
| **D0** | 路线图 + 设计增补 | **done** |
|
||||
| **D1** | bridge `mount` + data-mq / `#marqdo-boot` 自启;hello 去掉 loader/interact/fetch.js | **done** |
|
||||
| **D2** | `client_embed` / `客户端挂载`:`wasm` / `source` / `boot` | **done** |
|
||||
| **D3** | DOM/表单效应 + wire 传 `value`;`dom_patch` L1 | **done** |
|
||||
| **D4** | `examples/web-client-site` + skill / README | **done** |
|
||||
|
||||
## 非目标
|
||||
|
||||
- 消灭官方 bridge 文件本身(宿主胶必须存在)
|
||||
- 任意 `eval(JS)` / React 式 VDOM
|
||||
- 把 axum / SQLite 搬进浏览器(仍属 C 非目标)
|
||||
|
||||
## 验收
|
||||
|
||||
- 示例无作者业务 `.js`(允许构建拷贝的 `marqdo-bridge.js`)
|
||||
- `ext/web` 一行挂载即可 boot + wire
|
||||
- 点击、表单 input、`fetch` 效应可演示
|
||||
@@ -0,0 +1,32 @@
|
||||
# 路线图:浏览器 Marqdo 路线 E(前端能力补齐)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **Completed** |
|
||||
| 日期 | 2026-09-04 |
|
||||
| 前置 | [browser-wasm-d.md](browser-wasm-d.md)(D0–D4 **Completed**) |
|
||||
| 续作 | [browser-wasm-f.md](browser-wasm-f.md)(媒体 / 文件 / Canvas 等) |
|
||||
| 设计 | [browser-marqdo-wasm.md](../design/browser-marqdo-wasm.md) §16–§17 |
|
||||
|
||||
## 原则(已修正)
|
||||
|
||||
**禁止的只有:作者手写业务 JS。**
|
||||
官方 `marqdo-bridge.js` / 构建生成物可以包含任意宿主机制(含轻量列表装配、路由、存储、WebSocket、内部模板等)。
|
||||
|
||||
## 阶段
|
||||
|
||||
| 阶段 | 内容 | 状态 |
|
||||
|------|------|------|
|
||||
| **E0** | 原则修正 + 能力矩阵 | **done** |
|
||||
| **E1** | `set_style` / `focus` / `blur` / `scroll_into`;键盘;wire `委托`;多节点 `querySelectorAll` | **done** |
|
||||
| **E2** | `set_html` / `append_html` / `replace_children` / `render_list` / `remove`;L1 `list_html` | **done** |
|
||||
| **E3** | `navigate` / `replace`;`window`+`popstate` | **done** |
|
||||
| **E4** | `storage` local/session/**cookie** | **done** |
|
||||
| **E5** | `ws` open/send/close + callbacks | **done** |
|
||||
| **E6** | `fetch_all`(数组或 map)/ `interval` / FormData / `clipboard` / `download` | **done** |
|
||||
| **E7** | `add_class` / `remove_class`;示例列表真删除 + net 面板 | **done** |
|
||||
|
||||
## 验收
|
||||
|
||||
- [examples/browser-app/](../../examples/browser-app/):列表 CRUD、storage、三页路由、interval、fetch_all、ws、clipboard、download
|
||||
- 冒烟:`tests/wasm/smoke.mjs`
|
||||
@@ -0,0 +1,26 @@
|
||||
# 路线图:浏览器 Marqdo 路线 F(进阶宿主能力)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **Completed**(F1–F5;F6 Service Worker 可选未做) |
|
||||
| 日期 | 2026-09-04 |
|
||||
| 发布 | **v0.3.3** |
|
||||
| 前置 | [browser-wasm-e.md](browser-wasm-e.md)(E **Completed**) |
|
||||
| 写法 | 客户端 `.mq.md`:**GFM 表格 + `lib/browser`**,禁止 `json.set` 链([marqdo-dev](../../.cursor/skills/marqdo-dev/SKILL.md)) |
|
||||
|
||||
## 原则
|
||||
|
||||
同 E:禁止作者手写业务 JS;官方 bridge 可扩展。作者数据与效应用**可读表格/助手**表达。
|
||||
|
||||
## 阶段
|
||||
|
||||
| 阶段 | 内容 | 状态 |
|
||||
|------|------|------|
|
||||
| **F1** | `read_file` → text / DataURL → `mq_call` | **done** |
|
||||
| **F2** | Canvas 2D 指令表(`canvas.commands`) | **done** |
|
||||
| **F3** | Audio play / pause / stop;`src=beep` Web Audio | **done** |
|
||||
| **F4** | `observe` / `unobserve`(Intersection / Resize) | **done** |
|
||||
| **F5** | drag/drop wire + `data-drag` / `drop_text` | **done** |
|
||||
| **F6** | Service Worker / 离线缓存 | optional / skipped |
|
||||
|
||||
示例:[examples/browser-media/](../../examples/browser-media/) · 助手:`lib/browser.mq.md`。
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **Completed**(路线 C 首版功能完备) |
|
||||
| 状态 | **Completed**(路线 C 首版功能完备;续作见 [browser-wasm-d.md](browser-wasm-d.md)) |
|
||||
| 日期 | 2026-09-01 |
|
||||
| ADR | [0002](../adr/0002-browser-marqdo-wasm.md) · [0003](../adr/0003-browser-async-effects.md) |
|
||||
| 设计 | [browser-marqdo-wasm.md](../design/browser-marqdo-wasm.md) |
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# browser-app(路线 E)
|
||||
|
||||
作者**零业务 JS**;逻辑用 **GFM 表格 + `lib/browser`**(无 `json.set` 链)。
|
||||
|
||||
| 能力 | 演示 |
|
||||
|------|------|
|
||||
| 列表 CRUD | 添加 / 委托删除(`bag` + `set_html`) |
|
||||
| storage | 草稿 localStorage |
|
||||
| navigate | `/` `/about` `/net` + `popstate` |
|
||||
| interval | 计时起停 |
|
||||
| fetch_all | 并行两个 uuid |
|
||||
| ws | `wss://echo.websocket.events`(依赖外网) |
|
||||
| clipboard / download | 复制/下载列表文本 |
|
||||
|
||||
```bash
|
||||
cargo build -p marqdo --release
|
||||
./target/release/marqdo wasm build -o examples/browser-app
|
||||
cd examples/browser-app && python3 -m http.server 8766
|
||||
```
|
||||
|
||||
写法:[marqdo-dev](../../.cursor/skills/marqdo-dev/SKILL.md) · 路线图:[browser-wasm-e.md](../../doc/roadmap/browser-wasm-e.md)。
|
||||
@@ -0,0 +1,283 @@
|
||||
---
|
||||
title: browser-app (route E+)
|
||||
description: list CRUD, storage, navigate, interval, fetch_all, ws — GFM + lib/browser
|
||||
import browser:lib/browser.mq.md
|
||||
import table:lib/table.mq.md
|
||||
import text:lib/text.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`ticks` = 0*
|
||||
*`bag` = ""*
|
||||
*`path` = "/"*
|
||||
*`ws_id` = "echo"*
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 | 委托 | 值选择器 |
|
||||
|---|--------|------|------|------|----------|
|
||||
| 1 | "#add" | click | add | | "#draft" |
|
||||
| 2 | "#save" | click | save_draft | | "#draft" |
|
||||
| 3 | "#load" | click | load_draft | | |
|
||||
| 4 | "#start-tick" | click | start_tick | | |
|
||||
| 5 | "#stop-tick" | click | stop_tick | | |
|
||||
| 6 | "#nav-home" | click | go_home | | |
|
||||
| 7 | "#nav-about" | click | go_about | | |
|
||||
| 8 | "#nav-net" | click | go_net | | |
|
||||
| 9 | "window" | popstate | on_pop | | |
|
||||
| 10 | "#items" | click | on_item | "button[data-id]" | |
|
||||
| 11 | "#fetch-all" | click | do_fetch_all | | |
|
||||
| 12 | "#ws-open" | click | ws_open | | |
|
||||
| 13 | "#ws-send" | click | ws_send | | "#ws-msg" |
|
||||
| 14 | "#ws-close" | click | ws_close | | |
|
||||
| 15 | "#copy-log" | click | copy_log | | |
|
||||
| 16 | "#dl-list" | click | dl_list | | |
|
||||
|
||||
`nav` =
|
||||
|
||||
| url | replace |
|
||||
|-----|---------|
|
||||
| / | False |
|
||||
|
||||
`st` =
|
||||
|
||||
| op | key | then |
|
||||
|----|-----|------|
|
||||
| get | mq-draft | on_draft |
|
||||
|
||||
`boot` =
|
||||
|
||||
| wire | navigate | storage |
|
||||
|------|----------|---------|
|
||||
| `wire` | `nav` | `st` |
|
||||
|
||||
**boot**
|
||||
|
||||
## add
|
||||
+ `value`=""
|
||||
|
||||
1. `value` != ""
|
||||
1. `bag` == ""
|
||||
*`bag` = value*
|
||||
2. *
|
||||
*`bag` = bag + "\n" + value*
|
||||
*`parts` = > text.str_split s=bag sep="\n"*
|
||||
*`html` = ""*
|
||||
- [item](parts)
|
||||
1. `item` != ""
|
||||
*`html` = html + "<li><span>" + item + "</span> <button type=\"button\" data-id=\"" + item + "\">删</button></li>"*
|
||||
*`ret` = > browser.set_html sel="#items" html=html*
|
||||
*`clr` = > browser.set_value sel="#draft" value=""*
|
||||
*`ret` = > browser.merge a=ret b=clr*
|
||||
*`f` = > browser.focus sel="#draft"*
|
||||
**> browser.merge a=ret b=f**
|
||||
2. *
|
||||
****
|
||||
|
||||
## on_item
|
||||
+ `data_id`=""
|
||||
|
||||
1. `data_id` != ""
|
||||
*`parts` = > text.str_split s=bag sep="\n"*
|
||||
*`next` = ""*
|
||||
- [item](parts)
|
||||
1. `item` != ""
|
||||
1. `item` != `data_id`
|
||||
1. `next` == ""
|
||||
*`next` = item*
|
||||
2. *
|
||||
*`next` = next + "\n" + item*
|
||||
*`bag` = next*
|
||||
*`parts2` = > text.str_split s=bag sep="\n"*
|
||||
*`html` = ""*
|
||||
- [item](parts2)
|
||||
1. `item` != ""
|
||||
*`html` = html + "<li><span>" + item + "</span> <button type=\"button\" data-id=\"" + item + "\">删</button></li>"*
|
||||
*`ret` = > browser.set_html sel="#items" html=html*
|
||||
*`msg` = "removed " + data_id*
|
||||
*`t` = > browser.set_text sel="#log" text=msg*
|
||||
**> browser.merge a=ret b=t**
|
||||
2. *
|
||||
****
|
||||
|
||||
## save_draft
|
||||
+ `value`=""
|
||||
|
||||
`st` =
|
||||
|
||||
| op | key | value |
|
||||
|----|-----|-------|
|
||||
| set | mq-draft | `value` |
|
||||
|
||||
*`msg` = > browser.set_text sel="#log" text="draft saved"*
|
||||
*`s` = > browser.storage spec=st*
|
||||
**> browser.merge a=msg b=s**
|
||||
|
||||
## load_draft
|
||||
|
||||
`st` =
|
||||
|
||||
| op | key | then |
|
||||
|----|-----|------|
|
||||
| get | mq-draft | on_draft |
|
||||
|
||||
**> browser.storage spec=st**
|
||||
|
||||
## on_draft
|
||||
+ `ok`=True
|
||||
+ `value`=""
|
||||
+ `found`=False
|
||||
|
||||
1. `found`
|
||||
*`ret` = > browser.set_value sel="#draft" value=value*
|
||||
*`msg` = > browser.set_text sel="#log" text="draft loaded"*
|
||||
**> browser.merge a=ret b=msg**
|
||||
2. *
|
||||
**> browser.set_text sel="#log" text="no draft"**
|
||||
|
||||
## start_tick
|
||||
**> browser.interval ms=1000 then="on_tick" id="tick"**
|
||||
|
||||
## stop_tick
|
||||
**> browser.clear_interval id="tick"**
|
||||
|
||||
## on_tick
|
||||
+ `ok`=True
|
||||
+ `id`=""
|
||||
|
||||
*`ticks` = ticks + 1*
|
||||
*`label` = > str ticks*
|
||||
**> browser.set_text sel="#tick" text=label**
|
||||
|
||||
## go_home
|
||||
*`path` = "/"*
|
||||
**> show_path**
|
||||
|
||||
## go_about
|
||||
*`path` = "/about"*
|
||||
**> show_path**
|
||||
|
||||
## go_net
|
||||
*`path` = "/net"*
|
||||
**> show_path**
|
||||
|
||||
## on_pop
|
||||
+ `path`=""
|
||||
|
||||
*`path` = path*
|
||||
**> show_path**
|
||||
|
||||
## show_path
|
||||
*`hide` = > table.put in=None at="hidden" value=""*
|
||||
*`show` = > table.put in=None at="hidden" value=False*
|
||||
1. `path` == "/about"
|
||||
`attrs` =
|
||||
|
||||
| #panel-about | #panel-home | #panel-net |
|
||||
|--------------|-------------|------------|
|
||||
| `show` | `hide` | `hide` |
|
||||
2. *
|
||||
1. `path` == "/net"
|
||||
`attrs` =
|
||||
|
||||
| #panel-net | #panel-home | #panel-about |
|
||||
|------------|-------------|--------------|
|
||||
| `show` | `hide` | `hide` |
|
||||
2. *
|
||||
`attrs` =
|
||||
|
||||
| #panel-home | #panel-about | #panel-net |
|
||||
|-------------|--------------|------------|
|
||||
| `show` | `hide` | `hide` |
|
||||
*`label` = "path: " + path*
|
||||
*`ret` = > browser.set_text sel="#path" text=label*
|
||||
*`a` = > browser.wrap key="set_attr" value=attrs*
|
||||
*`ret` = > browser.merge a=ret b=a*
|
||||
*`nav` = > browser.navigate url=path*
|
||||
**> browser.merge a=ret b=nav**
|
||||
|
||||
## do_fetch_all
|
||||
|
||||
`reqs` =
|
||||
|
||||
| @ | url |
|
||||
|---|-----|
|
||||
| 1 | "https://httpbin.org/uuid" |
|
||||
| 2 | "https://httpbin.org/uuid" |
|
||||
|
||||
*`msg` = > browser.set_text sel="#net-out" text="fetch_all…"*
|
||||
*`fa` = > browser.fetch_all requests=reqs then="on_fetch_all"*
|
||||
**> browser.merge a=msg b=fa**
|
||||
|
||||
## on_fetch_all
|
||||
+ `ok`=True
|
||||
+ `results`=None
|
||||
|
||||
**> browser.set_text sel="#net-out" text="fetch_all done (see console / results in session)"**
|
||||
|
||||
## ws_open
|
||||
|
||||
`w` =
|
||||
|
||||
| op | id | url | then_open | then_message | then_error | then_close |
|
||||
|----|----|-----|-----------|--------------|------------|------------|
|
||||
| open | `ws_id` | "wss://echo.websocket.events" | on_ws_open | on_ws_msg | on_ws_err | on_ws_close |
|
||||
|
||||
**> browser.ws spec=w**
|
||||
|
||||
## on_ws_open
|
||||
+ `ok`=True
|
||||
+ `id`=""
|
||||
|
||||
**> browser.set_text sel="#net-out" text="ws open"**
|
||||
|
||||
## on_ws_msg
|
||||
+ `ok`=True
|
||||
+ `data`=""
|
||||
|
||||
*`msg` = "ws ← " + data*
|
||||
**> browser.set_text sel="#net-out" text=msg**
|
||||
|
||||
## on_ws_err
|
||||
+ `ok`=False
|
||||
+ `error`=""
|
||||
|
||||
*`msg` = "ws error: " + error*
|
||||
**> browser.set_text sel="#net-out" text=msg**
|
||||
|
||||
## on_ws_close
|
||||
+ `ok`=True
|
||||
|
||||
**> browser.set_text sel="#net-out" text="ws closed"**
|
||||
|
||||
## ws_send
|
||||
+ `value`=""
|
||||
|
||||
`w` =
|
||||
|
||||
| op | id | data |
|
||||
|----|----|------|
|
||||
| send | `ws_id` | `value` |
|
||||
|
||||
**> browser.ws spec=w**
|
||||
|
||||
## ws_close
|
||||
|
||||
`w` =
|
||||
|
||||
| op | id |
|
||||
|----|----|
|
||||
| close | `ws_id` |
|
||||
|
||||
**> browser.ws spec=w**
|
||||
|
||||
## copy_log
|
||||
*`msg` = > browser.set_text sel="#log" text="copied bag to clipboard"*
|
||||
*`c` = > browser.clipboard text=bag*
|
||||
**> browser.merge a=msg b=c**
|
||||
|
||||
## dl_list
|
||||
*`msg` = > browser.set_text sel="#log" text="download started"*
|
||||
*`d` = > browser.download body=bag filename="items.txt"*
|
||||
**> browser.merge a=msg b=d**
|
||||
@@ -0,0 +1,96 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-Hans">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Marqdo · browser-app (route E)</title>
|
||||
<style>
|
||||
:root { --ink: #1a1f1c; --paper: #e8efe6; --accent: #2f6f4e; --muted: #5a6b60; }
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0; min-height: 100vh; font-family: "IBM Plex Sans", "Noto Sans SC", sans-serif;
|
||||
color: var(--ink);
|
||||
background: linear-gradient(165deg, #f3f7f2, var(--paper));
|
||||
padding: 2rem clamp(1rem, 4vw, 3rem);
|
||||
}
|
||||
h1 { font-family: "IBM Plex Serif", "Noto Serif SC", serif; margin: 0 0 0.35rem; }
|
||||
.lead { color: var(--muted); max-width: 42rem; }
|
||||
nav a { margin-right: 0.75rem; color: var(--accent); }
|
||||
section { margin: 1.5rem 0; padding: 1rem 0; border-top: 1px solid #c5d4c9; }
|
||||
#path { font-family: ui-monospace, monospace; color: var(--muted); }
|
||||
#items { list-style: none; padding: 0; margin: 0.75rem 0; }
|
||||
#items li {
|
||||
display: flex; align-items: center; gap: 0.5rem;
|
||||
padding: 0.4rem 0.6rem; margin-bottom: 0.35rem;
|
||||
background: rgba(255,255,255,0.65); border: 1px solid #b7c7bb;
|
||||
}
|
||||
#items button { margin-left: auto; }
|
||||
input[type="text"] { padding: 0.45rem 0.65rem; border: 1px solid #b7c7bb; width: min(16rem, 70%); }
|
||||
button {
|
||||
padding: 0.45rem 0.9rem; border: 0; background: var(--accent); color: #f5faf6;
|
||||
font: inherit; cursor: pointer; margin: 0.2rem 0.35rem 0.2rem 0;
|
||||
}
|
||||
button.secondary { background: #3a4740; }
|
||||
#tick, #net-out { font-variant-numeric: tabular-nums; }
|
||||
#net-out {
|
||||
min-height: 2.5rem; padding: 0.6rem 0.75rem; background: rgba(255,255,255,0.55);
|
||||
border: 1px solid #b7c7bb; white-space: pre-wrap; word-break: break-all;
|
||||
}
|
||||
pre {
|
||||
margin-top: 1rem; padding: 0.85rem 1rem; background: #122018; color: #d7eadc;
|
||||
font-size: 0.8rem; overflow: auto; max-width: 42rem;
|
||||
}
|
||||
.err { color: #ffb4a8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Marqdo browser-app</h1>
|
||||
<p class="lead">路线 E:列表 CRUD / storage / navigate / interval / fetch_all / ws / clipboard / download — <strong>无作者业务 JS</strong>。</p>
|
||||
<p id="path">path: /</p>
|
||||
<nav>
|
||||
<a href="#/" id="nav-home">首页</a>
|
||||
<a href="#/about" id="nav-about">关于</a>
|
||||
<a href="#/net" id="nav-net">网络</a>
|
||||
</nav>
|
||||
|
||||
<section id="panel-home">
|
||||
<h2>待办</h2>
|
||||
<input id="draft" type="text" placeholder="新项…" disabled />
|
||||
<button id="add" type="button" disabled>添加</button>
|
||||
<button id="save" class="secondary" type="button" disabled>存草稿</button>
|
||||
<button id="load" class="secondary" type="button" disabled>读草稿</button>
|
||||
<button id="copy-log" class="secondary" type="button" disabled>复制列表</button>
|
||||
<button id="dl-list" class="secondary" type="button" disabled>下载列表</button>
|
||||
<ul id="items"></ul>
|
||||
<p>计时:<span id="tick">0</span>s
|
||||
<button id="start-tick" type="button" disabled>开始</button>
|
||||
<button id="stop-tick" class="secondary" type="button" disabled>停止</button>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section id="panel-about" hidden>
|
||||
<h2>关于</h2>
|
||||
<p>作者只写 <code>app.mq.md</code>。官方 bridge 提供 DOM / 路由 / storage / ws / fetch_all 等宿主能力。</p>
|
||||
</section>
|
||||
|
||||
<section id="panel-net" hidden>
|
||||
<h2>网络</h2>
|
||||
<p id="net-out">idle</p>
|
||||
<button id="fetch-all" type="button" disabled>fetch_all ×2 uuid</button>
|
||||
<button id="ws-open" type="button" disabled>WS 打开</button>
|
||||
<input id="ws-msg" type="text" placeholder="ws 消息" disabled />
|
||||
<button id="ws-send" type="button" disabled>WS 发送</button>
|
||||
<button id="ws-close" class="secondary" type="button" disabled>WS 关闭</button>
|
||||
</section>
|
||||
|
||||
<pre id="log">loading…</pre>
|
||||
<script
|
||||
type="module"
|
||||
src="./marqdo-bridge.js"
|
||||
data-mq-wasm="./marqdo_wasm.wasm"
|
||||
data-mq-source-url="./app.mq.md"
|
||||
data-mq-ready="#log"
|
||||
data-mq-enable="#draft,#add,#save,#load,#start-tick,#stop-tick,#fetch-all,#ws-open,#ws-msg,#ws-send,#ws-close,#copy-log,#dl-list"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
# browser-hello(WASM C1–C3)
|
||||
# browser-hello(WASM C1–C4 / 路线 D)
|
||||
|
||||
浏览器内跑 Marqdo(路线 C)。
|
||||
浏览器内跑 Marqdo。**无作者业务 JS**——只保留官方 `marqdo-bridge.js`(`marqdo wasm build` 拷贝)。客户端 `.mq.md` 用 **GFM 表格 + `lib/browser`**。
|
||||
|
||||
```bash
|
||||
# 仓库根目录
|
||||
@@ -13,9 +13,9 @@ python3 -m http.server 8765
|
||||
|
||||
| 页 | 说明 |
|
||||
|----|------|
|
||||
| [/](http://127.0.0.1:8765/) | C1:编辑源码 → `mq_run` 打印 |
|
||||
| [/interact.html](http://127.0.0.1:8765/interact.html) | C3:`counter.mq.md` 交互表 → 点击改 DOM |
|
||||
| [/fetch.html](http://127.0.0.1:8765/fetch.html) | C4:`fetch` / `after` 效应续体 |
|
||||
| [/](http://127.0.0.1:8765/) | playground:`data-mq-playground` + textarea → `mq_run` |
|
||||
| [/interact.html](http://127.0.0.1:8765/interact.html) | `counter.mq.md` wire → 点击改 DOM |
|
||||
| [/fetch.html](http://127.0.0.1:8765/fetch.html) | `fetch` / `after` 效应 |
|
||||
| [/form.html](http://127.0.0.1:8765/form.html) | `input` + `value` / `set_class`(D3) |
|
||||
|
||||
- `marqdo-bridge.js`:官方宿主桥(`boot` / `call` / `wireEvents` / `applyEffects`)
|
||||
- 业务源码只有 `.mq.md`;异步见 [ADR 0003](../../doc/adr/0003-browser-async-effects.md)
|
||||
自启方式:脚本上的 `data-mq-source-url` / `data-mq-playground`,或 `#marqdo-boot` JSON。详见 [browser-wasm-d.md](../../doc/roadmap/browser-wasm-d.md)。
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: browser counter (C3)
|
||||
description: wire table + shared entry env; click updates DOM via set_text
|
||||
import json:lib/json.mq.md
|
||||
description: wire table + browser.set_text — no json glue
|
||||
import browser:lib/browser.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
@@ -20,10 +20,8 @@ import json:lib/json.mq.md
|
||||
## bump
|
||||
*`count` = count + 1*
|
||||
*`label` = > str count*
|
||||
*`patch` = > json.set map=None key="#count" value=label*
|
||||
**> json.set map=None key="set_text" value=patch**
|
||||
**> browser.set_text sel="#count" text=label**
|
||||
|
||||
## reset
|
||||
*`count` = 0*
|
||||
*`patch` = > json.set map=None key="#count" value="0"*
|
||||
**> json.set map=None key="set_text" value=patch**
|
||||
**> browser.set_text sel="#count" text="0"**
|
||||
@@ -69,11 +69,18 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Marqdo</h1>
|
||||
<p class="lead">C4:返回 <code>fetch</code> / <code>after</code> 效应,由官方 bridge 续体回调(ADR 0003)。业务只在 <code>fetch.mq.md</code>。<a href="./interact.html">计数器</a> · <a href="./">打印</a></p>
|
||||
<p class="lead">C4/D:返回 <code>fetch</code> / <code>after</code> 效应;bridge 自启(ADR 0003)。业务只在 <code>fetch.mq.md</code>。<a href="./interact.html">计数器</a> · <a href="./form.html">表单</a> · <a href="./">打印</a></p>
|
||||
<div id="status">idle</div>
|
||||
<button id="load" type="button" disabled>请求 UUID</button>
|
||||
<button id="ping" class="secondary" type="button" disabled>延迟 pong</button>
|
||||
<pre id="log">loading…</pre>
|
||||
<script type="module" src="./fetch.js"></script>
|
||||
<script
|
||||
type="module"
|
||||
src="./marqdo-bridge.js"
|
||||
data-mq-wasm="./marqdo_wasm.wasm"
|
||||
data-mq-source-url="./fetch.mq.md"
|
||||
data-mq-ready="#log"
|
||||
data-mq-enable="#load,#ping"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,52 +0,0 @@
|
||||
import {
|
||||
applyDomPatch,
|
||||
boot,
|
||||
loadWasm,
|
||||
readCString,
|
||||
wireEvents,
|
||||
} from "./marqdo-bridge.js";
|
||||
|
||||
async function main() {
|
||||
const log = document.getElementById("log");
|
||||
const loadBtn = document.getElementById("load");
|
||||
const pingBtn = document.getElementById("ping");
|
||||
|
||||
let exports;
|
||||
try {
|
||||
exports = await loadWasm("./marqdo_wasm.wasm");
|
||||
} catch (e) {
|
||||
log.classList.add("err");
|
||||
log.textContent = String(e);
|
||||
return;
|
||||
}
|
||||
|
||||
const srcRes = await fetch("./fetch.mq.md");
|
||||
if (!srcRes.ok) {
|
||||
log.classList.add("err");
|
||||
log.textContent = `failed to load fetch.mq.md (${srcRes.status})`;
|
||||
return;
|
||||
}
|
||||
const source = await srcRes.text();
|
||||
const result = boot(exports, source);
|
||||
if (!result.ok) {
|
||||
log.classList.add("err");
|
||||
log.textContent = result.error || "boot failed";
|
||||
return;
|
||||
}
|
||||
|
||||
const n = wireEvents(exports, result.value, {
|
||||
onError: (err) => {
|
||||
log.classList.add("err");
|
||||
log.textContent = err;
|
||||
},
|
||||
});
|
||||
applyDomPatch({ set_text: { "#status": "idle" } });
|
||||
|
||||
const ver = readCString(exports.memory, exports.mq_version());
|
||||
log.classList.remove("err");
|
||||
log.textContent = `marqdo-wasm ${ver} · wired ${n} · ADR 0003 effects\nsource: fetch.mq.md`;
|
||||
loadBtn.disabled = false;
|
||||
pingBtn.disabled = false;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: browser fetch (C4)
|
||||
description: return fetch/after effects; bridge continues via mq_call
|
||||
import json:lib/json.mq.md
|
||||
description: fetch/after effects via lib/browser — no json glue
|
||||
import browser:lib/browser.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
@@ -16,11 +16,9 @@ import json:lib/json.mq.md
|
||||
**`wire`**
|
||||
|
||||
## load
|
||||
*`patch` = > json.set map=None key="#status" value="loading…"*
|
||||
*`ret` = > json.set map=None key="set_text" value=patch*
|
||||
*`req` = > json.set map=None key="url" value="https://httpbin.org/uuid"*
|
||||
*`req` = > json.set map=req key="then" value="on_uuid"*
|
||||
**> json.set map=ret key="fetch" value=req**
|
||||
*`msg` = > browser.set_text sel="#status" text="loading…"*
|
||||
*`req` = > browser.fetch url="https://httpbin.org/uuid" then="on_uuid"*
|
||||
**> browser.merge a=msg b=req**
|
||||
|
||||
## on_uuid
|
||||
+ `ok`
|
||||
@@ -29,22 +27,16 @@ import json:lib/json.mq.md
|
||||
+ `error`=""
|
||||
|
||||
1. ok
|
||||
*`p` = > json.set map=None key="#status" value=body*
|
||||
**> json.set map=None key="set_text" value=p**
|
||||
**> browser.set_text sel="#status" text=body**
|
||||
2. *
|
||||
*`msg` = "fetch failed"*
|
||||
*`p` = > json.set map=None key="#status" value=msg*
|
||||
**> json.set map=None key="set_text" value=p**
|
||||
**> browser.set_text sel="#status" text="fetch failed"**
|
||||
|
||||
## ping
|
||||
*`patch` = > json.set map=None key="#status" value="wait 600ms…"*
|
||||
*`ret` = > json.set map=None key="set_text" value=patch*
|
||||
*`t` = > json.set map=None key="ms" value=600*
|
||||
*`t` = > json.set map=t key="then" value="on_ping"*
|
||||
**> json.set map=ret key="after" value=t**
|
||||
*`msg` = > browser.set_text sel="#status" text="wait 600ms…"*
|
||||
*`t` = > browser.after ms=600 then="on_ping"*
|
||||
**> browser.merge a=msg b=t**
|
||||
|
||||
## on_ping
|
||||
+ `ok`=True
|
||||
|
||||
*`p` = > json.set map=None key="#status" value="pong"*
|
||||
**> json.set map=None key="set_text" value=p**
|
||||
**> browser.set_text sel="#status" text="pong"**
|
||||
@@ -0,0 +1,76 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-Hans">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Marqdo · 表单 (D3)</title>
|
||||
<style>
|
||||
:root {
|
||||
--ink: #1a1f1c;
|
||||
--paper: #e8efe6;
|
||||
--accent: #2f6f4e;
|
||||
--muted: #5a6b60;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
font-family: "IBM Plex Sans", "Noto Sans SC", sans-serif;
|
||||
color: var(--ink);
|
||||
background:
|
||||
radial-gradient(700px 400px at 100% 20%, #d0e0d4 0%, transparent 50%),
|
||||
linear-gradient(165deg, #f3f7f2, var(--paper));
|
||||
padding: 2rem clamp(1rem, 4vw, 3rem);
|
||||
}
|
||||
h1 {
|
||||
font-family: "IBM Plex Serif", "Noto Serif SC", serif;
|
||||
font-weight: 600;
|
||||
font-size: clamp(1.6rem, 3vw, 2.2rem);
|
||||
margin: 0 0 0.35rem;
|
||||
}
|
||||
.lead { color: var(--muted); margin: 0 0 1.25rem; max-width: 38rem; }
|
||||
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.75rem 0 0.35rem; }
|
||||
input[type="text"] {
|
||||
width: min(24rem, 100%);
|
||||
padding: 0.5rem 0.75rem;
|
||||
border: 1px solid #b7c7bb;
|
||||
background: rgba(255,255,255,0.75);
|
||||
font: inherit;
|
||||
}
|
||||
#echo {
|
||||
margin-top: 1rem;
|
||||
font-size: 1.25rem;
|
||||
min-height: 1.5em;
|
||||
}
|
||||
#echo.hi { color: var(--accent); font-weight: 600; }
|
||||
pre {
|
||||
margin-top: 1.5rem;
|
||||
width: min(42rem, 100%);
|
||||
padding: 0.9rem 1rem;
|
||||
background: #122018;
|
||||
color: #d7eadc;
|
||||
overflow: auto;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.err { color: #ffb4a8; }
|
||||
a { color: var(--accent); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Marqdo</h1>
|
||||
<p class="lead">D3:<code>input</code> 事件把 <code>value</code> 传入 Marqdo;<code>set_value</code> / <code>set_class</code> / <code>set_attr</code> 回写 DOM。业务只在 <code>form.mq.md</code>。<a href="./interact.html">计数器</a> · <a href="./">打印</a></p>
|
||||
<label for="name">名字</label>
|
||||
<input id="name" type="text" placeholder="输入…" disabled />
|
||||
<div id="echo">(等待输入)</div>
|
||||
<pre id="log">loading…</pre>
|
||||
<script
|
||||
type="module"
|
||||
src="./marqdo-bridge.js"
|
||||
data-mq-wasm="./marqdo_wasm.wasm"
|
||||
data-mq-source-url="./form.mq.md"
|
||||
data-mq-ready="#log"
|
||||
data-mq-enable="#name"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: browser form (D3)
|
||||
description: input wire passes value; effects via lib/browser
|
||||
import browser:lib/browser.mq.md
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 |
|
||||
|---|--------|------|------|
|
||||
| 1 | "#name" | input | on_input |
|
||||
|
||||
**`wire`**
|
||||
|
||||
## on_input
|
||||
+ `value`=""
|
||||
+ `event`=""
|
||||
|
||||
1. `value` != ""
|
||||
*`label` = "你好," + value*
|
||||
*`ret` = > browser.set_text sel="#echo" text=label*
|
||||
*`cls` = > browser.set_class sel="#echo" class="hi"*
|
||||
*`ret` = > browser.merge a=ret b=cls*
|
||||
*`attrs` = > table.put in=None at="data-name" value=value*
|
||||
*`attr` = > browser.set_attr sel="#echo" attrs=attrs*
|
||||
**> browser.merge a=ret b=attr**
|
||||
2. *
|
||||
*`ret` = > browser.set_text sel="#echo" text="(等待输入)"*
|
||||
*`cls` = > browser.set_class sel="#echo" class=""*
|
||||
**> browser.merge a=ret b=cls**
|
||||
@@ -67,7 +67,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Marqdo</h1>
|
||||
<p class="lead">浏览器内 WASM 解释器(路线 C / C1):源码是 <code>.mq.md</code>,无业务手写 JS。<a href="./interact.html">交互示例 (C3)</a></p>
|
||||
<p class="lead">浏览器内 WASM(路线 C/D):源码是 <code>.mq.md</code>,官方 bridge 自启 playground,无作者业务 JS。<a href="./interact.html">交互</a> · <a href="./fetch.html">fetch</a> · <a href="./form.html">表单</a></p>
|
||||
<label for="src">程序</label>
|
||||
<textarea id="src"># main
|
||||
|
||||
@@ -77,6 +77,12 @@
|
||||
<button id="run" disabled>运行</button>
|
||||
</div>
|
||||
<pre id="out">loading wasm…</pre>
|
||||
<script type="module" src="./loader.js"></script>
|
||||
<script
|
||||
type="module"
|
||||
src="./marqdo-bridge.js"
|
||||
data-mq-wasm="./marqdo_wasm.wasm"
|
||||
data-mq-playground="#src,#run,#out"
|
||||
data-mq-ready="#out"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -62,11 +62,18 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Marqdo</h1>
|
||||
<p class="lead">C3:GFM 交互表装配事件;点击由 WASM 会话里的 Marqdo 函数处理并回写 DOM。<a href="./fetch.html">fetch (C4)</a> · <a href="./">打印示例</a></p>
|
||||
<p class="lead">C3/D:GFM 交互表装配事件;官方 <code>mount</code> 自启,业务只在 <code>counter.mq.md</code>。<a href="./fetch.html">fetch</a> · <a href="./form.html">表单</a> · <a href="./">打印</a></p>
|
||||
<div id="count">0</div>
|
||||
<button id="bump" type="button" disabled>加一</button>
|
||||
<button id="reset" class="secondary" type="button" disabled>清零</button>
|
||||
<pre id="log">loading…</pre>
|
||||
<script type="module" src="./interact.js"></script>
|
||||
<script
|
||||
type="module"
|
||||
src="./marqdo-bridge.js"
|
||||
data-mq-wasm="./marqdo_wasm.wasm"
|
||||
data-mq-source-url="./counter.mq.md"
|
||||
data-mq-ready="#log"
|
||||
data-mq-enable="#bump,#reset"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,53 +0,0 @@
|
||||
import {
|
||||
applyDomPatch,
|
||||
boot,
|
||||
loadWasm,
|
||||
readCString,
|
||||
wireEvents,
|
||||
} from "./marqdo-bridge.js";
|
||||
|
||||
async function main() {
|
||||
const log = document.getElementById("log");
|
||||
const bump = document.getElementById("bump");
|
||||
const reset = document.getElementById("reset");
|
||||
|
||||
let exports;
|
||||
try {
|
||||
exports = await loadWasm("./marqdo_wasm.wasm");
|
||||
} catch (e) {
|
||||
log.classList.add("err");
|
||||
log.textContent = String(e);
|
||||
return;
|
||||
}
|
||||
|
||||
const srcRes = await fetch("./counter.mq.md");
|
||||
if (!srcRes.ok) {
|
||||
log.classList.add("err");
|
||||
log.textContent = `failed to load counter.mq.md (${srcRes.status})`;
|
||||
return;
|
||||
}
|
||||
const source = await srcRes.text();
|
||||
const result = boot(exports, source);
|
||||
if (!result.ok) {
|
||||
log.classList.add("err");
|
||||
log.textContent = result.error || "boot failed";
|
||||
return;
|
||||
}
|
||||
|
||||
const n = wireEvents(exports, result.value, {
|
||||
onError: (err) => {
|
||||
log.classList.add("err");
|
||||
log.textContent = err;
|
||||
},
|
||||
});
|
||||
// Ensure initial display matches Marqdo state.
|
||||
applyDomPatch({ set_text: { "#count": "0" } });
|
||||
|
||||
const ver = readCString(exports.memory, exports.mq_version());
|
||||
log.classList.remove("err");
|
||||
log.textContent = `marqdo-wasm ${ver} · wired ${n} handler(s)\nsource: counter.mq.md`;
|
||||
bump.disabled = false;
|
||||
reset.disabled = false;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,48 +0,0 @@
|
||||
import {
|
||||
loadWasm,
|
||||
readCString,
|
||||
runSource,
|
||||
} from "./marqdo-bridge.js";
|
||||
|
||||
const DEFAULT_SRC = `# main
|
||||
|
||||
> print text=Hello from browser WASM!
|
||||
`;
|
||||
|
||||
async function main() {
|
||||
const out = document.getElementById("out");
|
||||
const btn = document.getElementById("run");
|
||||
const src = document.getElementById("src");
|
||||
if (!src.value.trim()) src.value = DEFAULT_SRC;
|
||||
|
||||
let exports;
|
||||
try {
|
||||
exports = await loadWasm("./marqdo_wasm.wasm");
|
||||
} catch (e) {
|
||||
out.classList.add("err");
|
||||
out.textContent = String(e);
|
||||
return;
|
||||
}
|
||||
const ver = readCString(exports.memory, exports.mq_version());
|
||||
out.classList.remove("err");
|
||||
out.textContent = `marqdo-wasm ${ver} ready.\n`;
|
||||
btn.disabled = false;
|
||||
|
||||
btn.addEventListener("click", () => {
|
||||
try {
|
||||
const result = runSource(exports, src.value);
|
||||
out.classList.toggle("err", !result.ok);
|
||||
out.textContent = result.ok
|
||||
? (result.stdout || "(empty stdout)") +
|
||||
(result.value != null && result.value !== "None"
|
||||
? `\n[return] ${typeof result.value === "string" ? result.value : JSON.stringify(result.value)}`
|
||||
: "")
|
||||
: result.error || "error";
|
||||
} catch (e) {
|
||||
out.classList.add("err");
|
||||
out.textContent = String(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,20 @@
|
||||
# browser-media(路线 F)
|
||||
|
||||
作者**零业务 JS**;`.mq.md` 用 **GFM 表格 + `lib/browser`**(禁止 `json.set` 链)。
|
||||
|
||||
| 能力 | 演示 |
|
||||
|------|------|
|
||||
| read_file | 文本 / DataURL |
|
||||
| canvas | `@` 指令表 |
|
||||
| audio | beep(Web Audio) |
|
||||
| observe | Intersection + Resize |
|
||||
| drag/drop | `data-drag` → `drop_text` |
|
||||
|
||||
```bash
|
||||
cargo build -p marqdo --release
|
||||
./target/release/marqdo wasm build -o examples/browser-media
|
||||
cd examples/browser-media && python3 -m http.server 8767
|
||||
```
|
||||
|
||||
写法约定见 [.cursor/skills/marqdo-dev/SKILL.md](../../.cursor/skills/marqdo-dev/SKILL.md)。
|
||||
路线图:[browser-wasm-f.md](../../doc/roadmap/browser-wasm-f.md)。
|
||||
@@ -0,0 +1,98 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-Hans">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Marqdo · browser-media (route F)</title>
|
||||
<style>
|
||||
:root { --ink: #1a1f1c; --paper: #e8efe6; --accent: #2f6f4e; --muted: #5a6b60; }
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0; min-height: 100vh; font-family: "IBM Plex Sans", "Noto Sans SC", sans-serif;
|
||||
color: var(--ink);
|
||||
background: linear-gradient(165deg, #f3f7f2, var(--paper));
|
||||
padding: 2rem clamp(1rem, 4vw, 3rem);
|
||||
}
|
||||
h1 { font-family: "IBM Plex Serif", "Noto Serif SC", serif; margin: 0 0 0.35rem; }
|
||||
.lead { color: var(--muted); max-width: 42rem; }
|
||||
section { margin: 1.5rem 0; padding: 1rem 0; border-top: 1px solid #c5d4c9; }
|
||||
button {
|
||||
padding: 0.45rem 0.9rem; border: 0; background: var(--accent); color: #f5faf6;
|
||||
font: inherit; cursor: pointer; margin: 0.2rem 0.35rem 0.2rem 0;
|
||||
}
|
||||
button.secondary { background: #3a4740; }
|
||||
#pad {
|
||||
display: block; background: #fff; border: 1px solid #b7c7bb;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
#chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.75rem 0; }
|
||||
#chips span {
|
||||
padding: 0.45rem 0.75rem; background: rgba(255,255,255,0.75);
|
||||
border: 1px dashed #2f6f4e; cursor: grab; user-select: none;
|
||||
}
|
||||
#dropzone {
|
||||
min-height: 3.5rem; padding: 0.85rem; border: 2px dashed #7a9584;
|
||||
background: rgba(255,255,255,0.45); color: var(--muted);
|
||||
}
|
||||
#beacon {
|
||||
margin-top: 8rem; padding: 2rem; background: #2f6f4e; color: #f5faf6;
|
||||
text-align: center;
|
||||
}
|
||||
#preview { margin-top: 0.5rem; min-height: 1rem; }
|
||||
pre {
|
||||
margin-top: 1rem; padding: 0.85rem 1rem; background: #122018; color: #d7eadc;
|
||||
font-size: 0.8rem; overflow: auto; max-width: 42rem;
|
||||
}
|
||||
.err { color: #ffb4a8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Marqdo browser-media</h1>
|
||||
<p class="lead">路线 F:文件 / Canvas / Audio / Observer / 拖放 — <strong>无作者业务 JS</strong>。</p>
|
||||
|
||||
<section>
|
||||
<h2>F1 文件</h2>
|
||||
<input id="file" type="file" accept="image/*,text/*,.txt,.md" disabled />
|
||||
<button id="read-text" type="button" disabled>读文本</button>
|
||||
<button id="read-dataurl" type="button" disabled>读 DataURL</button>
|
||||
<div id="preview"></div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>F2 Canvas · F3 Audio</h2>
|
||||
<button id="draw" type="button" disabled>绘制</button>
|
||||
<button id="play" type="button" disabled>蜂鸣</button>
|
||||
<canvas id="pad" width="280" height="120"></canvas>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>F4 Observer</h2>
|
||||
<button id="watch" type="button" disabled>开始观察</button>
|
||||
<button id="unwatch" class="secondary" type="button" disabled>停止</button>
|
||||
<p id="obs">idle</p>
|
||||
<p>向下滚动可触发 Intersection;改窗口大小触发 Resize。</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>F5 拖放</h2>
|
||||
<div id="chips">
|
||||
<span draggable="true" data-drag="alpha">alpha</span>
|
||||
<span draggable="true" data-drag="beta">beta</span>
|
||||
<span draggable="true" data-drag="gamma">gamma</span>
|
||||
</div>
|
||||
<div id="dropzone">拖到这里</div>
|
||||
</section>
|
||||
|
||||
<div id="beacon">beacon(滚到可见)</div>
|
||||
|
||||
<pre id="log">loading…</pre>
|
||||
<script
|
||||
type="module"
|
||||
src="./marqdo-bridge.js"
|
||||
data-mq-wasm="./marqdo_wasm.wasm"
|
||||
data-mq-source-url="./media.mq.md"
|
||||
data-mq-ready="#log"
|
||||
data-mq-enable="#file,#read-text,#read-dataurl,#draw,#play,#watch,#unwatch"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,162 @@
|
||||
---
|
||||
title: browser-media (route F)
|
||||
description: file / canvas / audio / observers / drag — GFM tables + lib/browser
|
||||
import browser:lib/browser.mq.md
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Route F demo: author data stays in tables; effects via `browser.*`.
|
||||
|
||||
*`obs_on` = False*
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 | 委托 |
|
||||
|---|--------|------|------|------|
|
||||
| 1 | "#read-text" | click | read_text | |
|
||||
| 2 | "#read-dataurl" | click | read_dataurl | |
|
||||
| 3 | "#draw" | click | draw_box | |
|
||||
| 4 | "#play" | click | play_tone | |
|
||||
| 5 | "#watch" | click | start_watch | |
|
||||
| 6 | "#unwatch" | click | stop_watch | |
|
||||
| 7 | "#chips" | dragstart | on_drag | "[data-drag]" |
|
||||
| 8 | "#dropzone" | dragover | on_dragover | |
|
||||
| 9 | "#dropzone" | drop | on_drop | |
|
||||
|
||||
*`ready` = > browser.set_text sel="#log" text="ready (route F)"*
|
||||
*`boot` = > table.put in=None at="wire" value=wire*
|
||||
**> browser.merge a=boot b=ready**
|
||||
|
||||
## read_text
|
||||
**> browser.read_file sel="#file" then="on_file" as="text"**
|
||||
|
||||
## read_dataurl
|
||||
**> browser.read_file sel="#file" then="on_file" as="data_url"**
|
||||
|
||||
## on_file
|
||||
+ `ok`=False
|
||||
+ `name`=""
|
||||
+ `size`=0
|
||||
+ `body`=""
|
||||
+ `data_url`=""
|
||||
+ `as`=""
|
||||
+ `error`=""
|
||||
|
||||
1. `ok`
|
||||
1. `as` == "data_url"
|
||||
*`n` = > len value=data_url*
|
||||
*`ns` = > str `n`*
|
||||
*`preview` = name + " data_url chars=" + ns*
|
||||
*`ret` = > browser.set_text sel="#log" text=preview*
|
||||
1. `data_url` != ""
|
||||
*`h` = "<img alt=\"preview\" src=\"" + data_url + "\" style=\"max-width:12rem;max-height:8rem\" />"*
|
||||
*`img` = > browser.set_html sel="#preview" html=h*
|
||||
**> browser.merge a=ret b=img**
|
||||
2. *
|
||||
**ret**
|
||||
2. *
|
||||
*`n` = > len value=body*
|
||||
*`ns` = > str `n`*
|
||||
*`ss` = > str `size`*
|
||||
*`preview` = name + " (" + ss + " B, chars=" + ns + ") ok"*
|
||||
**> browser.set_text sel="#log" text=preview**
|
||||
2. *
|
||||
*`preview` = "file error: " + error*
|
||||
**> browser.set_text sel="#log" text=preview**
|
||||
|
||||
## draw_box
|
||||
|
||||
Canvas commands as a readable `@` table:
|
||||
|
||||
`commands` =
|
||||
|
||||
| @ | op | x | y | w | h | fill | stroke | text |
|
||||
|---|----|---|---|---|---|------|--------|------|
|
||||
| 1 | fillrect | 10 | 10 | 120 | 80 | "#2f6f4e" | | |
|
||||
| 2 | strokerect | 20 | 20 | 100 | 60 | | "#122018" | |
|
||||
| 3 | filltext | 40 | 55 | | | "#f5faf6" | | Marqdo |
|
||||
|
||||
*`cv` = > browser.canvas sel="#pad" commands=commands clear=True*
|
||||
*`msg` = > browser.set_text sel="#log" text="canvas drawn"*
|
||||
**> browser.merge a=cv b=msg**
|
||||
|
||||
## play_tone
|
||||
*`tone` = > browser.audio op="play" id="demo" src="beep" freq=523 ms=220*
|
||||
*`msg` = > browser.set_text sel="#log" text="audio beep"*
|
||||
**> browser.merge a=tone b=msg**
|
||||
|
||||
## start_watch
|
||||
*`obs_on` = True*
|
||||
|
||||
`obs` =
|
||||
|
||||
| @ | kind | sel | id | then | threshold |
|
||||
|---|------|-----|----|------|-----------|
|
||||
| 1 | intersect | "#beacon" | beacon | on_intersect | 0.25 |
|
||||
| 2 | resize | "#pad" | pad | on_resize | |
|
||||
|
||||
*`o` = > browser.observe specs=obs*
|
||||
*`msg` = > browser.set_text sel="#log" text="observers on"*
|
||||
**> browser.merge a=o b=msg**
|
||||
|
||||
## stop_watch
|
||||
*`obs_on` = False*
|
||||
|
||||
`ids` =
|
||||
|
||||
| @ | id |
|
||||
|---|----|
|
||||
| 1 | beacon |
|
||||
| 2 | pad |
|
||||
|
||||
*`u` = > browser.unobserve specs=ids*
|
||||
*`msg` = > browser.set_text sel="#log" text="observers off"*
|
||||
**> browser.merge a=u b=msg**
|
||||
|
||||
## on_intersect
|
||||
+ `intersecting`=False
|
||||
+ `ratio`=0
|
||||
|
||||
1. `obs_on`
|
||||
*`state` = "hidden"*
|
||||
1. `intersecting`
|
||||
*`state` = "visible"*
|
||||
2. *
|
||||
---
|
||||
*`r` = > str `ratio`*
|
||||
*`msg` = "beacon " + state + " ratio=" + r*
|
||||
**> browser.set_text sel="#obs" text=msg**
|
||||
2. *
|
||||
****
|
||||
|
||||
## on_resize
|
||||
+ `width`=0
|
||||
+ `height`=0
|
||||
|
||||
1. `obs_on`
|
||||
*`w` = > str `width`*
|
||||
*`h` = > str `height`*
|
||||
*`msg` = "pad size " + w + "×" + h*
|
||||
**> browser.set_text sel="#obs" text=msg**
|
||||
2. *
|
||||
****
|
||||
|
||||
## on_drag
|
||||
+ `drag`=""
|
||||
|
||||
*`msg` = "dragging: " + drag*
|
||||
**> browser.set_text sel="#log" text=msg**
|
||||
|
||||
## on_dragover
|
||||
****
|
||||
|
||||
## on_drop
|
||||
+ `drop_text`=""
|
||||
|
||||
*`msg` = "dropped: " + drop_text*
|
||||
*`h` = "<strong>" + drop_text + "</strong>"*
|
||||
*`t` = > browser.set_text sel="#log" text=msg*
|
||||
*`box` = > browser.set_html sel="#dropzone" html=h*
|
||||
**> browser.merge a=t b=box**
|
||||
@@ -0,0 +1,20 @@
|
||||
# web-client-site(路线 D)
|
||||
|
||||
服务端 `ext/web` + 浏览器 WASM 会话;**作者零业务 JS**。
|
||||
|
||||
```bash
|
||||
# 仓库根
|
||||
cargo build -p marqdo --release
|
||||
cargo build --release -p marqdo_plugin_web
|
||||
./target/release/marqdo ext add web
|
||||
|
||||
# 构建 WASM + bridge 到本示例 static/
|
||||
./target/release/marqdo wasm build -o examples/web-client-site/static
|
||||
# 保留 client.mq.md(wasm build 只写入 wasm/bridge)
|
||||
|
||||
cd examples/web-client-site
|
||||
marqdo run index.mq.md
|
||||
# 打开 http://127.0.0.1:18090/
|
||||
```
|
||||
|
||||
`index.mq.md` 用 `web.client_embed source="/static/client.mq.md"` 注入自启脚本;交互在 `static/client.mq.md`。
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: web-client-site
|
||||
description: SSR shell + client_embed auto-mount; author zero JS (route D)
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Server page with a counter UI. Client logic lives in `static/client.mq.md`
|
||||
(loaded by official bridge via `client_embed`).
|
||||
|
||||
*`embed` = > web.client_embed bridge="/static/marqdo-bridge.js" wasm="/static/marqdo_wasm.wasm" source="/static/client.mq.md" boot=True*
|
||||
|
||||
*`intro` = "<h1>Marqdo client site</h1><p>SSR + WASM session. No author JS.</p><div id=\"count\">0</div><p><button id=\"bump\" type=\"button\" disabled>Bump</button> <button id=\"reset\" type=\"button\" disabled>Reset</button></p><pre id=\"log\">booting…</pre>" + embed*
|
||||
|
||||
*page = > web.page title="Marqdo client site" intro=intro*
|
||||
*app = > web.app page=page host="127.0.0.1" port=18090*
|
||||
*app = > app.static dir="static" mount="/static"*
|
||||
> `app`.listen
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
title: client counter (route D)
|
||||
description: wired by client_embed auto-mount; GFM + lib/browser
|
||||
import browser:lib/browser.mq.md
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`count` = 0*
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 |
|
||||
|---|--------|------|------|
|
||||
| 1 | "#bump" | click | bump |
|
||||
| 2 | "#reset" | click | reset |
|
||||
|
||||
*`ready` = > browser.set_text sel="#log" text="client.mq.md ready"*
|
||||
*`boot` = > table.put in=None at="wire" value=wire*
|
||||
**> browser.merge a=boot b=ready**
|
||||
|
||||
## bump
|
||||
*`count` = count + 1*
|
||||
*`label` = > str count*
|
||||
**> browser.set_text sel="#count" text=label**
|
||||
|
||||
## reset
|
||||
*`count` = 0*
|
||||
**> browser.set_text sel="#count" text="0"**
|
||||
File diff suppressed because it is too large.
Load diff
+123
-9
@@ -3,6 +3,7 @@ title: ext/web/web
|
||||
description: Official web site classes (English). Tables + methods; no bag glue.
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
## ensure_plugin
|
||||
@@ -53,6 +54,128 @@ preview; prefer `page.head` to attach resources to a page.
|
||||
> ensure_plugin
|
||||
**> web_head table=`table`**
|
||||
|
||||
## client_embed
|
||||
+ `bridge`="/static/marqdo-bridge.js"
|
||||
+ `wasm`="/static/marqdo_wasm.wasm"
|
||||
+ `source`=""
|
||||
+ `boot`=True
|
||||
|
||||
Return an HTML snippet that loads the official browser Marqdo bridge (route C/D).
|
||||
With `boot` and non-empty `source` (URL path to `.mq.md`), emits `data-mq-wasm` / `data-mq-source-url` so the bridge **auto-mounts** (author zero JS).
|
||||
Run `marqdo wasm build -o static` and `app.static dir=static`. Design: [browser-marqdo-wasm.md](../../doc/design/browser-marqdo-wasm.md) §16.
|
||||
|
||||
1. `boot`
|
||||
1. `source` != ""
|
||||
**"<script type=\"module\" src=\"" + bridge + "\" data-mq-wasm=\"" + wasm + "\" data-mq-source-url=\"" + source + "\"></script>"**
|
||||
2. *
|
||||
**"<script type=\"module\" src=\"" + bridge + "\"></script>"**
|
||||
2. *
|
||||
**"<script type=\"module\" src=\"" + bridge + "\" data-mq-no-boot=\"1\"></script>"**
|
||||
|
||||
## text_patch
|
||||
+ `sel`
|
||||
+ `text`
|
||||
|
||||
Shortcut: build a `set_text` effects map `{ set_text: { sel: text } }` for browser return values.
|
||||
Prefer authoring with `lib/browser` + GFM tables in client `.mq.md` ([marqdo-dev](../../.cursor/skills/marqdo-dev/SKILL.md)).
|
||||
|
||||
*`m` = > table.put in=None at=sel value=text*
|
||||
**> table.put in=None at="set_text" value=m**
|
||||
|
||||
## dom_patch
|
||||
+ `set_text`=None
|
||||
+ `set_value`=None
|
||||
+ `set_attr`=None
|
||||
+ `set_class`=None
|
||||
+ `toggle_class`=None
|
||||
+ `set_style`=None
|
||||
+ `set_html`=None
|
||||
+ `render_list`=None
|
||||
+ `navigate`=None
|
||||
+ `storage`=None
|
||||
+ `ws`=None
|
||||
+ `fetch`=None
|
||||
+ `fetch_all`=None
|
||||
+ `after`=None
|
||||
+ `interval`=None
|
||||
+ `clear_interval`=None
|
||||
+ `focus`=None
|
||||
+ `blur`=None
|
||||
+ `scroll_into`=None
|
||||
+ `canvas`=None
|
||||
+ `audio`=None
|
||||
+ `read_file`=None
|
||||
+ `observe`=None
|
||||
+ `unobserve`=None
|
||||
+ `wire`=None
|
||||
|
||||
Merge browser effect keys into one return map (omit `None`). Route E/F effects included.
|
||||
|
||||
*`out` = > table.put in=None at="_mq" value=True*
|
||||
1. `set_text` != None
|
||||
*`out` = > table.put in=`out` at="set_text" value=set_text*
|
||||
1. `set_value` != None
|
||||
*`out` = > table.put in=`out` at="set_value" value=set_value*
|
||||
1. `set_attr` != None
|
||||
*`out` = > table.put in=`out` at="set_attr" value=set_attr*
|
||||
1. `set_class` != None
|
||||
*`out` = > table.put in=`out` at="set_class" value=set_class*
|
||||
1. `toggle_class` != None
|
||||
*`out` = > table.put in=`out` at="toggle_class" value=toggle_class*
|
||||
1. `set_style` != None
|
||||
*`out` = > table.put in=`out` at="set_style" value=set_style*
|
||||
1. `set_html` != None
|
||||
*`out` = > table.put in=`out` at="set_html" value=set_html*
|
||||
1. `render_list` != None
|
||||
*`out` = > table.put in=`out` at="render_list" value=render_list*
|
||||
1. `navigate` != None
|
||||
*`out` = > table.put in=`out` at="navigate" value=navigate*
|
||||
1. `storage` != None
|
||||
*`out` = > table.put in=`out` at="storage" value=storage*
|
||||
1. `ws` != None
|
||||
*`out` = > table.put in=`out` at="ws" value=ws*
|
||||
1. `fetch` != None
|
||||
*`out` = > table.put in=`out` at="fetch" value=fetch*
|
||||
1. `fetch_all` != None
|
||||
*`out` = > table.put in=`out` at="fetch_all" value=fetch_all*
|
||||
1. `after` != None
|
||||
*`out` = > table.put in=`out` at="after" value=after*
|
||||
1. `interval` != None
|
||||
*`out` = > table.put in=`out` at="interval" value=interval*
|
||||
1. `clear_interval` != None
|
||||
*`out` = > table.put in=`out` at="clear_interval" value=clear_interval*
|
||||
1. `focus` != None
|
||||
*`out` = > table.put in=`out` at="focus" value=focus*
|
||||
1. `blur` != None
|
||||
*`out` = > table.put in=`out` at="blur" value=blur*
|
||||
1. `scroll_into` != None
|
||||
*`out` = > table.put in=`out` at="scroll_into" value=scroll_into*
|
||||
1. `canvas` != None
|
||||
*`out` = > table.put in=`out` at="canvas" value=canvas*
|
||||
1. `audio` != None
|
||||
*`out` = > table.put in=`out` at="audio" value=audio*
|
||||
1. `read_file` != None
|
||||
*`out` = > table.put in=`out` at="read_file" value=read_file*
|
||||
1. `observe` != None
|
||||
*`out` = > table.put in=`out` at="observe" value=observe*
|
||||
1. `unobserve` != None
|
||||
*`out` = > table.put in=`out` at="unobserve" value=unobserve*
|
||||
1. `wire` != None
|
||||
*`out` = > table.put in=`out` at="wire" value=wire*
|
||||
**out**
|
||||
|
||||
## list_html
|
||||
+ `sel`
|
||||
+ `tag`="li"
|
||||
+ `items`
|
||||
|
||||
Build a `render_list` effect: `{ render_list: { sel: { tag, items } } }`.
|
||||
|
||||
*`spec` = > table.put in=None at="tag" value=tag*
|
||||
*`spec` = > table.put in=`spec` at="items" value=items*
|
||||
*`m` = > table.put in=None at=sel value=spec*
|
||||
**> table.put in=None at="render_list" value=m**
|
||||
|
||||
# page
|
||||
+ `title`="Marqdo Web"
|
||||
+ `intro`=""
|
||||
@@ -127,15 +250,6 @@ Assemble `<head>` resources from a GFM table (`|rel|href|type|sizes|media|as|cro
|
||||
|
||||
**> web_page_head page=`self` table=`table`**
|
||||
|
||||
## client_embed
|
||||
+ `bridge`="/static/marqdo-bridge.js"
|
||||
|
||||
Return an HTML snippet that loads the official browser Marqdo bridge (`marqdo-bridge.js`, route C).
|
||||
Run `marqdo wasm build -o static` first, and prefer a `head` table row with `rel=module`.
|
||||
Author `.mq.md` wire/`fetch` effects: [browser-marqdo-wasm.md](../../doc/design/browser-marqdo-wasm.md).
|
||||
|
||||
**"<script type=\"module\" src=\"" + bridge + "\"></script>"**
|
||||
|
||||
## images
|
||||
+ `table`
|
||||
|
||||
|
||||
+121
-9
@@ -3,6 +3,7 @@ title: ext/web/网页
|
||||
description: 官方网站类(中文)。表格 + 方法;不写袋式胶水。
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
## 确保插件
|
||||
@@ -50,6 +51,126 @@ import sys:lib/sys.mq.md
|
||||
> 确保插件
|
||||
**> web_head table=`表`**
|
||||
|
||||
## 客户端挂载
|
||||
+ `桥`="/static/marqdo-bridge.js"
|
||||
+ `wasm`="/static/marqdo_wasm.wasm"
|
||||
+ `源`=""
|
||||
+ `启动`=True
|
||||
|
||||
返回挂载浏览器 Marqdo(路线 C/D)的 HTML。`启动` 且 `源` 非空(客户端 `.mq.md` URL)时写入 `data-mq-wasm` / `data-mq-source-url`,官方 bridge **自动 mount**(作者零业务 JS)。
|
||||
请先 `marqdo wasm build -o static`,并用 `app.静态` 提供该目录。设计见 [browser-marqdo-wasm.md](../../doc/design/browser-marqdo-wasm.md) §16。
|
||||
|
||||
1. `启动`
|
||||
1. `源` != ""
|
||||
**"<script type=\"module\" src=\"" + 桥 + "\" data-mq-wasm=\"" + wasm + "\" data-mq-source-url=\"" + 源 + "\"></script>"**
|
||||
2. *
|
||||
**"<script type=\"module\" src=\"" + 桥 + "\"></script>"**
|
||||
2. *
|
||||
**"<script type=\"module\" src=\"" + 桥 + "\" data-mq-no-boot=\"1\"></script>"**
|
||||
|
||||
## 文本补丁
|
||||
+ `选择器`
|
||||
+ `文本`
|
||||
|
||||
快捷构造 `set_text` 效应表。客户端优先 `lib/浏览器` + GFM 表格。
|
||||
|
||||
*`m` = > table.put in=None at=选择器 value=文本*
|
||||
**> table.put in=None at="set_text" value=m**
|
||||
|
||||
## DOM补丁
|
||||
+ `set_text`=None
|
||||
+ `set_value`=None
|
||||
+ `set_attr`=None
|
||||
+ `set_class`=None
|
||||
+ `toggle_class`=None
|
||||
+ `set_style`=None
|
||||
+ `set_html`=None
|
||||
+ `render_list`=None
|
||||
+ `navigate`=None
|
||||
+ `storage`=None
|
||||
+ `ws`=None
|
||||
+ `fetch`=None
|
||||
+ `fetch_all`=None
|
||||
+ `after`=None
|
||||
+ `interval`=None
|
||||
+ `clear_interval`=None
|
||||
+ `focus`=None
|
||||
+ `blur`=None
|
||||
+ `scroll_into`=None
|
||||
+ `canvas`=None
|
||||
+ `audio`=None
|
||||
+ `read_file`=None
|
||||
+ `observe`=None
|
||||
+ `unobserve`=None
|
||||
+ `wire`=None
|
||||
|
||||
合并浏览器效应键(含路线 E/F)为一张返回表(跳过 `None`)。
|
||||
|
||||
*`out` = > table.put in=None at="_mq" value=True*
|
||||
1. `set_text` != None
|
||||
*`out` = > table.put in=`out` at="set_text" value=set_text*
|
||||
1. `set_value` != None
|
||||
*`out` = > table.put in=`out` at="set_value" value=set_value*
|
||||
1. `set_attr` != None
|
||||
*`out` = > table.put in=`out` at="set_attr" value=set_attr*
|
||||
1. `set_class` != None
|
||||
*`out` = > table.put in=`out` at="set_class" value=set_class*
|
||||
1. `toggle_class` != None
|
||||
*`out` = > table.put in=`out` at="toggle_class" value=toggle_class*
|
||||
1. `set_style` != None
|
||||
*`out` = > table.put in=`out` at="set_style" value=set_style*
|
||||
1. `set_html` != None
|
||||
*`out` = > table.put in=`out` at="set_html" value=set_html*
|
||||
1. `render_list` != None
|
||||
*`out` = > table.put in=`out` at="render_list" value=render_list*
|
||||
1. `navigate` != None
|
||||
*`out` = > table.put in=`out` at="navigate" value=navigate*
|
||||
1. `storage` != None
|
||||
*`out` = > table.put in=`out` at="storage" value=storage*
|
||||
1. `ws` != None
|
||||
*`out` = > table.put in=`out` at="ws" value=ws*
|
||||
1. `fetch` != None
|
||||
*`out` = > table.put in=`out` at="fetch" value=fetch*
|
||||
1. `fetch_all` != None
|
||||
*`out` = > table.put in=`out` at="fetch_all" value=fetch_all*
|
||||
1. `after` != None
|
||||
*`out` = > table.put in=`out` at="after" value=after*
|
||||
1. `interval` != None
|
||||
*`out` = > table.put in=`out` at="interval" value=interval*
|
||||
1. `clear_interval` != None
|
||||
*`out` = > table.put in=`out` at="clear_interval" value=clear_interval*
|
||||
1. `focus` != None
|
||||
*`out` = > table.put in=`out` at="focus" value=focus*
|
||||
1. `blur` != None
|
||||
*`out` = > table.put in=`out` at="blur" value=blur*
|
||||
1. `scroll_into` != None
|
||||
*`out` = > table.put in=`out` at="scroll_into" value=scroll_into*
|
||||
1. `canvas` != None
|
||||
*`out` = > table.put in=`out` at="canvas" value=canvas*
|
||||
1. `audio` != None
|
||||
*`out` = > table.put in=`out` at="audio" value=audio*
|
||||
1. `read_file` != None
|
||||
*`out` = > table.put in=`out` at="read_file" value=read_file*
|
||||
1. `observe` != None
|
||||
*`out` = > table.put in=`out` at="observe" value=observe*
|
||||
1. `unobserve` != None
|
||||
*`out` = > table.put in=`out` at="unobserve" value=unobserve*
|
||||
1. `wire` != None
|
||||
*`out` = > table.put in=`out` at="wire" value=wire*
|
||||
**out**
|
||||
|
||||
## 列表HTML
|
||||
+ `选择器`
|
||||
+ `标签`="li"
|
||||
+ `项`
|
||||
|
||||
构造 `render_list` 效应。
|
||||
|
||||
*`spec` = > table.put in=None at="tag" value=标签*
|
||||
*`spec` = > table.put in=`spec` at="items" value=项*
|
||||
*`m` = > table.put in=None at=选择器 value=spec*
|
||||
**> table.put in=None at="render_list" value=m**
|
||||
|
||||
# 页面
|
||||
+ `标题`="站点"
|
||||
+ `引言`=""
|
||||
@@ -116,15 +237,6 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
|
||||
**> web_page_head page=`self` table=`表`**
|
||||
|
||||
## 客户端挂载
|
||||
+ `桥`="/static/marqdo-bridge.js"
|
||||
|
||||
返回一段用于挂载浏览器 Marqdo(路线 C)的 HTML:加载官方 `marqdo-bridge.js` 模块。
|
||||
请先 `marqdo wasm build -o static`(或站点静态目录),并用 `头装配` 挂 `关系=module` 行;
|
||||
业务 `.mq.md` 与 `wire`/`fetch` 效应见 [browser-marqdo-wasm.md](../../doc/design/browser-marqdo-wasm.md)。
|
||||
|
||||
**"<script type=\"module\" src=\"" + 桥 + "\"></script>"**
|
||||
|
||||
## 图片装配
|
||||
+ `表`
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
---
|
||||
title: lib/browser
|
||||
description: >-
|
||||
Readable browser effect helpers for WASM clients. Prefer GFM tables + these
|
||||
helpers; do not build effects with json.set chains.
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
## set_text
|
||||
+ `sel`
|
||||
+ `text`
|
||||
|
||||
Build set_text effect map for the official bridge.
|
||||
|
||||
*`m` = > table.put in=None at=sel value=text*
|
||||
**> table.put in=None at="set_text" value=m**
|
||||
|
||||
## set_html
|
||||
+ `sel`
|
||||
+ `html`
|
||||
|
||||
Build set_html effect map.
|
||||
|
||||
*`m` = > table.put in=None at=sel value=html*
|
||||
**> table.put in=None at="set_html" value=m**
|
||||
|
||||
## set_value
|
||||
+ `sel`
|
||||
+ `value`
|
||||
|
||||
Build set_value effect map.
|
||||
|
||||
*`m` = > table.put in=None at=sel value=value*
|
||||
**> table.put in=None at="set_value" value=m**
|
||||
|
||||
## set_class
|
||||
+ `sel`
|
||||
+ `class`
|
||||
|
||||
Build set_class effect map.
|
||||
|
||||
*`m` = > table.put in=None at=sel value=class*
|
||||
**> table.put in=None at="set_class" value=m**
|
||||
|
||||
## set_attr
|
||||
+ `sel`
|
||||
+ `attrs`
|
||||
|
||||
Build set_attr effect map; attrs is usually a small map of attribute names to values.
|
||||
|
||||
*`m` = > table.put in=None at=sel value=attrs*
|
||||
**> table.put in=None at="set_attr" value=m**
|
||||
|
||||
## wrap
|
||||
+ `key`
|
||||
+ `value`
|
||||
|
||||
Single-key effect map wrapper.
|
||||
|
||||
**> table.put in=None at=key value=value**
|
||||
|
||||
## merge
|
||||
+ `a`
|
||||
+ `b`
|
||||
|
||||
Merge two effect maps; right-hand keys win.
|
||||
|
||||
**> table.merge a=`a` b=`b`**
|
||||
|
||||
## canvas
|
||||
+ `sel`
|
||||
+ `commands`
|
||||
+ `clear`=True
|
||||
|
||||
Build canvas effect; commands is usually an @ GFM table.
|
||||
|
||||
`spec` =
|
||||
|
||||
| sel | clear | commands |
|
||||
|-----|-------|----------|
|
||||
| `sel` | `clear` | `commands` |
|
||||
|
||||
**> table.put in=None at="canvas" value=spec**
|
||||
|
||||
## audio
|
||||
+ `op`="play"
|
||||
+ `id`="default"
|
||||
+ `src`=""
|
||||
+ `freq`=None
|
||||
+ `ms`=None
|
||||
+ `sel`=""
|
||||
|
||||
Build audio effect for the bridge.
|
||||
|
||||
*`spec` = > table.put in=None at="op" value=op*
|
||||
*`spec` = > table.put in=`spec` at="id" value=id*
|
||||
1. `src` != ""
|
||||
*`spec` = > table.put in=`spec` at="src" value=src*
|
||||
1. `freq` != None
|
||||
*`spec` = > table.put in=`spec` at="freq" value=freq*
|
||||
1. `ms` != None
|
||||
*`spec` = > table.put in=`spec` at="ms" value=ms*
|
||||
1. `sel` != ""
|
||||
*`spec` = > table.put in=`spec` at="sel" value=sel*
|
||||
**> table.put in=None at="audio" value=spec**
|
||||
|
||||
## read_file
|
||||
+ `sel`
|
||||
+ `then`
|
||||
+ `as`="text"
|
||||
|
||||
Build read_file effect.
|
||||
|
||||
`spec` =
|
||||
|
||||
| sel | as | then |
|
||||
|-----|----|------|
|
||||
| `sel` | `as` | `then` |
|
||||
|
||||
**> table.put in=None at="read_file" value=spec**
|
||||
|
||||
## observe
|
||||
+ `specs`
|
||||
|
||||
Build observe effect; specs is one map or an @ list of maps.
|
||||
|
||||
**> table.put in=None at="observe" value=specs**
|
||||
|
||||
## unobserve
|
||||
+ `specs`
|
||||
|
||||
Build unobserve effect; specs is a map or @ list with id.
|
||||
|
||||
**> table.put in=None at="unobserve" value=specs**
|
||||
|
||||
## focus
|
||||
+ `sel`
|
||||
|
||||
**> table.put in=None at="focus" value=sel**
|
||||
|
||||
## navigate
|
||||
+ `url`
|
||||
+ `replace`=False
|
||||
|
||||
`spec` =
|
||||
|
||||
| url | replace |
|
||||
|-----|---------|
|
||||
| `url` | `replace` |
|
||||
|
||||
**> table.put in=None at="navigate" value=spec**
|
||||
|
||||
## storage
|
||||
+ `spec`
|
||||
|
||||
**> table.put in=None at="storage" value=spec**
|
||||
|
||||
## interval
|
||||
+ `ms`
|
||||
+ `then`
|
||||
+ `id`="default"
|
||||
|
||||
`spec` =
|
||||
|
||||
| ms | then | id |
|
||||
|----|------|----|
|
||||
| `ms` | `then` | `id` |
|
||||
|
||||
**> table.put in=None at="interval" value=spec**
|
||||
|
||||
## clear_interval
|
||||
+ `id`="default"
|
||||
|
||||
*`spec` = > table.put in=None at="id" value=id*
|
||||
**> table.put in=None at="clear_interval" value=spec**
|
||||
|
||||
## fetch
|
||||
+ `url`
|
||||
+ `then`
|
||||
+ `method`="GET"
|
||||
|
||||
`spec` =
|
||||
|
||||
| url | then | method |
|
||||
|-----|------|--------|
|
||||
| `url` | `then` | `method` |
|
||||
|
||||
**> table.put in=None at="fetch" value=spec**
|
||||
|
||||
## fetch_all
|
||||
+ `requests`
|
||||
+ `then`
|
||||
|
||||
`spec` =
|
||||
|
||||
| requests | then |
|
||||
|----------|------|
|
||||
| `requests` | `then` |
|
||||
|
||||
**> table.put in=None at="fetch_all" value=spec**
|
||||
|
||||
## after
|
||||
+ `ms`
|
||||
+ `then`
|
||||
|
||||
`spec` =
|
||||
|
||||
| ms | then |
|
||||
|----|------|
|
||||
| `ms` | `then` |
|
||||
|
||||
**> table.put in=None at="after" value=spec**
|
||||
|
||||
## ws
|
||||
+ `spec`
|
||||
|
||||
**> table.put in=None at="ws" value=spec**
|
||||
|
||||
## clipboard
|
||||
+ `text`
|
||||
|
||||
*`spec` = > table.put in=None at="text" value=text*
|
||||
**> table.put in=None at="clipboard" value=spec**
|
||||
|
||||
## download
|
||||
+ `body`
|
||||
+ `filename`="download.txt"
|
||||
+ `mime`="text/plain;charset=utf-8"
|
||||
|
||||
`spec` =
|
||||
|
||||
| body | filename | mime |
|
||||
|------|----------|------|
|
||||
| `body` | `filename` | `mime` |
|
||||
|
||||
**> table.put in=None at="download" value=spec**
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
---
|
||||
title: lib/浏览器
|
||||
description: >-
|
||||
浏览器效应助手(WASM 客户端)。优先 GFM 表格 + 本库;勿用 json.set 链拼效应。
|
||||
import table:lib/table.mq.md
|
||||
---
|
||||
|
||||
## 设文本
|
||||
+ `选择器`
|
||||
+ `文本`
|
||||
|
||||
构造 set_text 效应。
|
||||
|
||||
*`m` = > table.put in=None at=选择器 value=文本*
|
||||
**> table.put in=None at="set_text" value=m**
|
||||
|
||||
## 设HTML
|
||||
+ `选择器`
|
||||
+ `html`
|
||||
|
||||
构造 set_html 效应。
|
||||
|
||||
*`m` = > table.put in=None at=选择器 value=html*
|
||||
**> table.put in=None at="set_html" value=m**
|
||||
|
||||
## 设值
|
||||
+ `选择器`
|
||||
+ `值`
|
||||
|
||||
构造 set_value 效应。
|
||||
|
||||
*`m` = > table.put in=None at=选择器 value=值*
|
||||
**> table.put in=None at="set_value" value=m**
|
||||
|
||||
## 设类
|
||||
+ `选择器`
|
||||
+ `类`
|
||||
|
||||
构造 set_class 效应。
|
||||
|
||||
*`m` = > table.put in=None at=选择器 value=类*
|
||||
**> table.put in=None at="set_class" value=m**
|
||||
|
||||
## 设属性
|
||||
+ `选择器`
|
||||
+ `属性`
|
||||
|
||||
构造 set_attr 效应。
|
||||
|
||||
*`m` = > table.put in=None at=选择器 value=属性*
|
||||
**> table.put in=None at="set_attr" value=m**
|
||||
|
||||
## 包装
|
||||
+ `键`
|
||||
+ `值`
|
||||
|
||||
单键效应包装。
|
||||
|
||||
**> table.put in=None at=键 value=值**
|
||||
|
||||
## 合并
|
||||
+ `甲`
|
||||
+ `乙`
|
||||
|
||||
合并两张效应表,右侧优先。
|
||||
|
||||
**> table.merge a=`甲` b=`乙`**
|
||||
|
||||
## 画布
|
||||
+ `选择器`
|
||||
+ `命令`
|
||||
+ `清空`=True
|
||||
|
||||
构造 canvas 效应;命令一般为 @ 行表。
|
||||
|
||||
`spec` =
|
||||
|
||||
| sel | clear | commands |
|
||||
|-----|-------|----------|
|
||||
| `选择器` | `清空` | `命令` |
|
||||
|
||||
**> table.put in=None at="canvas" value=spec**
|
||||
|
||||
## 音频
|
||||
+ `操作`="play"
|
||||
+ `id`="default"
|
||||
+ `源`=""
|
||||
+ `频率`=None
|
||||
+ `毫秒`=None
|
||||
+ `选择器`=""
|
||||
|
||||
构造 audio 效应。
|
||||
|
||||
*`spec` = > table.put in=None at="op" value=操作*
|
||||
*`spec` = > table.put in=`spec` at="id" value=id*
|
||||
1. `源` != ""
|
||||
*`spec` = > table.put in=`spec` at="src" value=源*
|
||||
1. `频率` != None
|
||||
*`spec` = > table.put in=`spec` at="freq" value=频率*
|
||||
1. `毫秒` != None
|
||||
*`spec` = > table.put in=`spec` at="ms" value=毫秒*
|
||||
1. `选择器` != ""
|
||||
*`spec` = > table.put in=`spec` at="sel" value=选择器*
|
||||
**> table.put in=None at="audio" value=spec**
|
||||
|
||||
## 读文件
|
||||
+ `选择器`
|
||||
+ `然后`
|
||||
+ `格式`="text"
|
||||
|
||||
构造 read_file 效应。
|
||||
|
||||
`spec` =
|
||||
|
||||
| sel | as | then |
|
||||
|-----|----|------|
|
||||
| `选择器` | `格式` | `然后` |
|
||||
|
||||
**> table.put in=None at="read_file" value=spec**
|
||||
|
||||
## 观察
|
||||
+ `规格`
|
||||
|
||||
构造 observe 效应。
|
||||
|
||||
**> table.put in=None at="observe" value=规格**
|
||||
|
||||
## 取消观察
|
||||
+ `规格`
|
||||
|
||||
构造 unobserve 效应。
|
||||
|
||||
**> table.put in=None at="unobserve" value=规格**
|
||||
|
||||
## 聚焦
|
||||
+ `选择器`
|
||||
|
||||
**> table.put in=None at="focus" value=选择器**
|
||||
|
||||
## 导航
|
||||
+ `url`
|
||||
+ `替换`=False
|
||||
|
||||
`spec` =
|
||||
|
||||
| url | replace |
|
||||
|-----|---------|
|
||||
| `url` | `替换` |
|
||||
|
||||
**> table.put in=None at="navigate" value=spec**
|
||||
|
||||
## 存储
|
||||
+ `规格`
|
||||
|
||||
**> table.put in=None at="storage" value=规格**
|
||||
|
||||
## 定时
|
||||
+ `毫秒`
|
||||
+ `然后`
|
||||
+ `id`="default"
|
||||
|
||||
`spec` =
|
||||
|
||||
| ms | then | id |
|
||||
|----|------|----|
|
||||
| `毫秒` | `然后` | `id` |
|
||||
|
||||
**> table.put in=None at="interval" value=spec**
|
||||
|
||||
## 清定时
|
||||
+ `id`="default"
|
||||
|
||||
*`spec` = > table.put in=None at="id" value=id*
|
||||
**> table.put in=None at="clear_interval" value=spec**
|
||||
|
||||
## 拉取
|
||||
+ `url`
|
||||
+ `然后`
|
||||
+ `方法`="GET"
|
||||
|
||||
`spec` =
|
||||
|
||||
| url | then | method |
|
||||
|-----|------|--------|
|
||||
| `url` | `然后` | `方法` |
|
||||
|
||||
**> table.put in=None at="fetch" value=spec**
|
||||
|
||||
## 拉取全部
|
||||
+ `请求`
|
||||
+ `然后`
|
||||
|
||||
`spec` =
|
||||
|
||||
| requests | then |
|
||||
|----------|------|
|
||||
| `请求` | `然后` |
|
||||
|
||||
**> table.put in=None at="fetch_all" value=spec**
|
||||
|
||||
## 延后
|
||||
+ `毫秒`
|
||||
+ `然后`
|
||||
|
||||
`spec` =
|
||||
|
||||
| ms | then |
|
||||
|----|------|
|
||||
| `毫秒` | `然后` |
|
||||
|
||||
**> table.put in=None at="after" value=spec**
|
||||
|
||||
## 套接字
|
||||
+ `规格`
|
||||
|
||||
**> table.put in=None at="ws" value=规格**
|
||||
|
||||
## 剪贴板
|
||||
+ `文本`
|
||||
|
||||
*`spec` = > table.put in=None at="text" value=文本*
|
||||
**> table.put in=None at="clipboard" value=spec**
|
||||
|
||||
## 下载
|
||||
+ `正文`
|
||||
+ `文件名`="download.txt"
|
||||
+ `mime`="text/plain;charset=utf-8"
|
||||
|
||||
`spec` =
|
||||
|
||||
| body | filename | mime |
|
||||
|------|----------|------|
|
||||
| `正文` | `文件名` | `mime` |
|
||||
|
||||
**> table.put in=None at="download" value=spec**
|
||||
@@ -34,7 +34,7 @@ ext/llm — OpenAI-compatible chat. Design: doc/design/ext-llm.md
|
||||
|
||||
ext/agent — agent framework + native plugin. Design: doc/design/ext-agent.md
|
||||
|
||||
ext/web — HTTP / SQLite·Postgres site helpers + native plugin. **W0–W7 + P3 + W8** (middleware, CRUD+FTS, security, SEO/RSS, upload/gallery, RBAC, sitemap, favicon/head/images). **Browser embed (v0.3.2+)**: `web.client_embed` mounts WASM client scripts — build with `marqdo wasm build`; examples: examples/browser-hello/. Design: doc/design/ext-web.md · capabilities: doc/design/web-net-capabilities.md · WASM: doc/adr/0002-browser-marqdo-wasm.md · example: examples/marqdo-blog/
|
||||
ext/web — HTTP / SQLite·Postgres site helpers + native plugin. **W0–W7 + P3 + W8**. **Browser embed (routes D/E/F, v0.3.3)**: `web.client_embed` auto-mounts WASM — zero author JS; `lib/browser` + GFM tables; build with `marqdo wasm build`; examples: browser-hello · browser-app · browser-media · web-client-site. Design: doc/design/ext-web.md · WASM: doc/adr/0002-browser-marqdo-wasm.md · roadmaps D/E/F.
|
||||
|
||||
ext/quantum — circuits, draw, noise, formula matrix custom gates, Q7 density/viz, Q8 themed SVG (`theme=dark|light|bw`). Design: doc/design/ext-quantum.md · doc/design/ext-quantum-viz-style.md
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ ext/llm(大模型)— OpenAI 兼容聊天。设计:doc/design/ext-llm.md
|
||||
|
||||
ext/agent(智能体)— 智能体框架 + 原生插件。设计:doc/design/ext-agent.md
|
||||
|
||||
ext/web(网页)— HTTP / SQLite 站点助手 + 原生插件。**W0–W7 + P3 + W8**。**浏览器挂载(v0.3.2+)**:`网页.客户端挂载` / `web.client_embed`;先 `marqdo wasm build`;示例 examples/browser-hello/。设计:doc/design/ext-web.md · WASM:doc/adr/0002-browser-marqdo-wasm.md
|
||||
ext/web(网页)— HTTP / SQLite 站点助手 + 原生插件。**W0–W7 + P3 + W8**。**浏览器挂载(路线 D/E/F,v0.3.3)**:`网页.客户端挂载` / `web.client_embed` 自动 mount(作者零业务 JS);`lib/浏览器` + GFM;先 `marqdo wasm build`;示例 examples/browser-hello/ · examples/browser-app/ · examples/browser-media/ · examples/web-client-site/。设计:doc/design/ext-web.md · WASM:doc/adr/0002-browser-marqdo-wasm.md · 路线 D/E/F:doc/roadmap/browser-wasm-*.md
|
||||
|
||||
ext/quantum(量子)— 电路、绘图、噪声、公式矩阵自定义门、Q7 密度/高级图、Q8 主题 SVG(`主题=dark|light|bw`)。设计:doc/design/ext-quantum.md · doc/design/ext-quantum-viz-style.md
|
||||
|
||||
|
||||
+13
-4
@@ -16,6 +16,8 @@ Marqdo = **Markdown markers as syntax**. A `.mq.md` file is both documentation a
|
||||
|
||||
Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords.md`. Deeper tables: [reference.md](reference.md). Copy-paste patterns: [examples.md](examples.md).
|
||||
|
||||
**Authoring / library craft** (GFM-first, no json glue, how to develop Marqdo): use **[`.cursor/skills/marqdo-dev/SKILL.md`](../../.cursor/skills/marqdo-dev/SKILL.md)** whenever writing or refactoring `.mq.md`, `lib/*`, or `ext/*`.
|
||||
|
||||
**Product release** (tag, CHANGELOG, README, public docs, VSIX, GitHub assets): use [`.cursor/skills/marqdo-release/SKILL.md`](../../.cursor/skills/marqdo-release/SKILL.md) — detect latest version, **ask the user for the next SemVer**, then follow that playbook. Do not invent a version number.
|
||||
|
||||
## Hard rules (do not violate)
|
||||
@@ -26,9 +28,12 @@ Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords.
|
||||
4. **Do not invent keywords** `if` / `else` / `while` / `for` / `def` / `return`. Control flow is Markdown: **`+` params** (under heading), **`1.` `2.` … branches**, **`-` loops**, arm `N. *` = else, `#` = **object/type**, `##`+ = **function/method**, `**…**` = return.
|
||||
5. **Identifiers use backticks** — params `` + `name` ``. **Exemptions:** foreach `` - [item](coll) ``; footnote `` name[^key] ``; **inside italic `*…*` / bold `**…**`**, bare ids are **variables** (Python-style unified namespace) and method-call receivers are bare too. **Drop the backticks on value-expression variable names and method receivers inside `*…*` / `**…**`** — they are redundant once the `*…*`/`**…**` markers mark the segment as code: `*分类 = 分类[^苹果]*`, `**n * 2**`, `*p = > page.主体装配 组件=home*`. **Text literals must be quoted**: `*a = > text.split value=src sep=","*`. Backticks **still required** where a bare word is *not* a variable in **standalone `>` calls** (bare = text there): `` > str `n` ``, `` > `obj`.method ``. **No trailing space** inside `*…*` / `**…**` wrapped code: the closing marker must touch the last token directly (`*a = 1*`, `**n**`), never `` *a = 1 * ``.
|
||||
6. **Structure lines are not wrapped in italics.** `#` `>` `+` `-` `|` lines stand alone; use `*…*` only for general statements (bindings / expressions).
|
||||
7. **Paths:** In bare *expressions* `/` is division. In **call args / param defaults**, unspaced `a/b` and quoted `".marqdo/agent-kb"` are path text — no `json.parse` needed.
|
||||
7. **Paths:** In bare *expressions* `/` is division. In **call args / param defaults / table cells**, unspaced `a/b` and quoted `".marqdo/agent-kb"` are path text — no `json.parse` needed. Numeric ratios that must stay text use quotes (`"1/5"`, `"16/9"`); bare `1/5` is division.
|
||||
8. Prefer ending side-effect-only function bodies with a lone `---` or `***` line (or `****` empty return) so later siblings are not swallowed.
|
||||
9. **`ext/**` never calls `host_*`.** Agent/OKF helpers are plugin names (`agent_kb_*`, …) after `plugin.load`. Do **not** add agent/OKF domain code to `src/host/` (core bloat). See `doc/design/ext-agent.md` §4.
|
||||
10. **Browser (route C/D/E/F):** client logic is Marqdo on WASM; official bridge is host glue and **may** implement lists, routing, storage, WebSocket, canvas, file read, observers — authors **must not hand-write business JS**. Use `web.client_embed` / `data-mq-source-url` auto-mount. Client effects: prefer **GFM tables + `lib/browser`** ([`.cursor/skills/marqdo-dev/SKILL.md`](../../.cursor/skills/marqdo-dev/SKILL.md)).
|
||||
11. **Code-as-documentation / no bag glue:** Prefer **GFM tables** for maps, lists, wire, commands. Prefer **`table.put` / named helpers** over `json.set` / `json.append` chains. `lib/json` is for parse/stringify/quote only — not a dict builder. Unreadable json pipelines are a style bug.
|
||||
|
||||
|
||||
## Markup → meaning (v0.2)
|
||||
|
||||
@@ -174,11 +179,11 @@ data/ # sqlite runtime (gitignore)
|
||||
|
||||
**Core objects (EN / ZH):** `# page`/`页面`, `# style`/`样式`, `# db`/`数据库`, `# form`/`表单`, `# app`/`应用`, `# auth`/`鉴权`, `# cache`/`缓存`, `# storage`/`存储`.
|
||||
|
||||
**Typical flow:** `db.init` → `page.compose_components` + `page.compose_main` → `page.head` / `page.images` / `page.meta` → `app` with `route` / `static` / `icons` / `configure` / `listen`.
|
||||
**Typical flow:** `db.init` → `page.compose_*` → `app` + `static` / `listen`. Client: `marqdo wasm build -o static` + `web.client_embed source="/static/client.mq.md"` — **no author JS**; bridge may implement rich host effects ([browser-wasm-e.md](../../doc/roadmap/browser-wasm-e.md) · [browser-app](../../examples/browser-app/)).
|
||||
|
||||
**Shipped surface (W0–W7 + P3 + W8):** middleware + JSON API (`app.configure`); transactions, pagination, FTS search (`db.migrate`, `db.fts`, `db.search`); security (argon2, CSRF, SQLite sessions, login rate limit); SEO / RSS / Markdown (`page.meta`, `route_rss`, `lib/net.markdown_parse`); upload / download / gallery; sitemap / robots / error pages / redirects; RBAC (`app.gate`, user `role`); audit timestamps + FK in `db.init`; ETag on downloads; **W8** site icons (`app.icons` → `/favicon.ico`), head resource tables (`page.head`), image assembly (`make_images` / `page.images`).
|
||||
**Shipped surface (W0–W7 + P3 + W8 + route D mount):** middleware + JSON API (`app.configure`); transactions, pagination, FTS search (`db.migrate`, `db.fts`, `db.search`); security (argon2, CSRF, SQLite sessions, login rate limit); SEO / RSS / Markdown (`page.meta`, `route_rss`, `lib/net.markdown_parse`); upload / download / gallery; sitemap / robots / error pages / redirects; RBAC (`app.gate`, user `role`); audit timestamps + FK in `db.init`; ETag on downloads; **W8** site icons (`app.icons` → `/favicon.ico`), head resource tables (`page.head`), image assembly (`make_images` / `page.images`); **D** `client_embed` auto-mount + DOM effect helpers (`text_patch` / `dom_patch`).
|
||||
|
||||
Design: [ext-web.md](../../doc/design/ext-web.md) · assets: [web-assets-and-images.md](../../doc/design/web-assets-and-images.md) · capability matrix: [web-net-capabilities.md](../../doc/design/web-net-capabilities.md) · example: [examples/marqdo-blog/](../../examples/marqdo-blog/).
|
||||
Design: [ext-web.md](../../doc/design/ext-web.md) · assets: [web-assets-and-images.md](../../doc/design/web-assets-and-images.md) · capability matrix: [web-net-capabilities.md](../../doc/design/web-net-capabilities.md) · example: [examples/marqdo-blog/](../../examples/marqdo-blog/) · client: [examples/web-client-site/](../../examples/web-client-site/).
|
||||
|
||||
Web patterns: [examples.md](examples.md) §13 · API index: [reference.md](reference.md).
|
||||
|
||||
@@ -227,7 +232,9 @@ Design: [ext-quantum.md](../../doc/design/ext-quantum.md) · Q7: [ext-quantum-q7
|
||||
| Forgetting `---` after nested `##` helper | Add `---` / `***` / `****` |
|
||||
| Import `lib/text` then call bare `split` | `> text.split …` (qualified) |
|
||||
| Import `lib/text` then call `拆分` | Match file language (`text.split`, not 文本) |
|
||||
| `json.set` / `json.append` to build maps or lists | GFM tables; sparse `table.put`; named helpers (`browser.*`, `web.*`) |
|
||||
| `json.set` to build page parts | GFM tables + `page.compose_*` / `web.page` methods |
|
||||
| Import `json` for every browser handler | `import browser:lib/browser.mq.md` + tables ([`.cursor/skills/marqdo-dev/SKILL.md`](../../.cursor/skills/marqdo-dev/SKILL.md)) |
|
||||
| Mix `web.page` and `网页.页面` in one file | One import language per `.mq.md` |
|
||||
| Call `host_web_*` from `ext/web` | Use `# app` / `# db` methods; plugin ABI only |
|
||||
| Call `host_*` from `ext/quantum` | Use `# circuit` / `# density` methods; plugin ABI only |
|
||||
@@ -243,6 +250,8 @@ Design: [ext-quantum.md](../../doc/design/ext-quantum.md) · Q7: [ext-quantum-q7
|
||||
- [ ] `# main` exists when the file is an entry program
|
||||
- [ ] Nested functions ended with `---` / `***` / `****` when needed
|
||||
- [ ] Imports and call names share the same language file
|
||||
- [ ] Data shaped as **GFM tables** (or short helpers) — no `json.set` / `json.append` glue
|
||||
- [ ] Web sites: tables + web classes only (no JSON glue); `data/` gitignored
|
||||
- [ ] Browser client: `lib/browser` + tables when returning effects
|
||||
- [ ] Quantum draw: quote `kind=` / `theme=`; rebuild plugin → `ext add quantum` before view
|
||||
- [ ] `marqdo run` succeeds (or errors addressed)
|
||||
@@ -78,6 +78,7 @@ Greeting via a nested function:
|
||||
> print text=`果`
|
||||
```
|
||||
|
||||
|
||||
## 6b. Map table + footnote get
|
||||
|
||||
```markdown
|
||||
@@ -109,6 +110,31 @@ Row-oriented records (SQL-like): first header `@` / `行` / `row` → list of ma
|
||||
*名 = 订单[^1][^品名]*
|
||||
```
|
||||
|
||||
## 6c. Browser effects — tables + lib/browser (not json.set)
|
||||
|
||||
```markdown
|
||||
---
|
||||
import browser:lib/browser.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 |
|
||||
|---|--------|------|------|
|
||||
| 1 | "#bump" | click | bump |
|
||||
|
||||
**`wire`**
|
||||
|
||||
## bump
|
||||
*`count` = count + 1*
|
||||
*`label` = > str count*
|
||||
**> browser.set_text sel="#count" text=label**
|
||||
```
|
||||
|
||||
Do **not** build effect maps with `json.set` chains. See [marqdo-dev](../marqdo-dev/SKILL.md).
|
||||
|
||||
## 7. Import text stdlib
|
||||
|
||||
```markdown
|
||||
|
||||
@@ -44,12 +44,13 @@ Import one file; use **that** file’s function names.
|
||||
|-----------|-----------|-------------------------|
|
||||
| `lib/text.mq.md` | `lib/文本.mq.md` | text helpers / 去空白·拆分·拼接… |
|
||||
| `lib/table.mq.md` | `lib/表.mq.md` | `put`/`改` + list/map(见 `doc/design/stdlib-table.md`) |
|
||||
| `lib/browser.mq.md` | `lib/浏览器.mq.md` | WASM client effect helpers(GFM + `set_text`/`canvas`/…;见 marqdo-dev) |
|
||||
| `lib/fs.mq.md` | `lib/文件.mq.md` | filesystem |
|
||||
| `lib/sys.mq.md` | `lib/系统.mq.md` | process / cwd / load_dotenv |
|
||||
| `lib/plugin.mq.md` | `lib/插件.mq.md` | load native ABI plugins (`doc/design/ext-abi.md`) |
|
||||
| `lib/time.mq.md` | `lib/时间.mq.md` | time/format |
|
||||
| `lib/net.mq.md` | `lib/网络.mq.md` | HTTP(S) helpers (+ optional headers) |
|
||||
| `lib/json.mq.md` | (see design) | JSON (+ `quote`) |
|
||||
| `lib/json.mq.md` | (see design) | **parse / stringify / quote only** — not a dict builder |
|
||||
| `lib/math.mq.md` | `lib/数学.mq.md` | num, trig, random, formula, plot |
|
||||
| `lib/foreign.mq.md` | `lib/外联.mq.md` | run foreign fenced blocks |
|
||||
| `ext/llm.mq.md` | `ext/大模型.mq.md` | `# llm` / `# 大模型` object + chat methods |
|
||||
|
||||
+51
-4
@@ -1,11 +1,17 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* WASM ABI smoke (C1/C3): boot counter.mq.md, call bump twice.
|
||||
* WASM ABI + bridge helpers smoke (C1/C3/D1).
|
||||
* Usage: node tests/wasm/smoke.mjs [path/to/marqdo_wasm.wasm]
|
||||
*/
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { fileURLToPath, pathToFileURL } from "url";
|
||||
import {
|
||||
normalizeMountOptions,
|
||||
eventArgsFromDom,
|
||||
applyDomPatch,
|
||||
renderListItems,
|
||||
} from "../../crates/marqdo-wasm/js/marqdo-bridge.js";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const root = path.resolve(__dirname, "../..");
|
||||
@@ -67,8 +73,8 @@ if (!Array.isArray(b.value) || b.value.length < 1) {
|
||||
console.error("expected wire list", b.value);
|
||||
process.exit(1);
|
||||
}
|
||||
const c1 = call("bump", {});
|
||||
const c2 = call("bump", {});
|
||||
const c1 = call("bump", { event: "click" });
|
||||
const c2 = call("bump", { event: "click", value: "x" });
|
||||
if (!c1.ok || !c2.ok) {
|
||||
console.error("call failed", c1, c2);
|
||||
process.exit(1);
|
||||
@@ -77,4 +83,45 @@ if (c2.value?.set_text?.["#count"] !== "2") {
|
||||
console.error("expected count 2, got", c2.value);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const norm = normalizeMountOptions({
|
||||
dataset: {
|
||||
mqWasm: "./w.wasm",
|
||||
mqSourceUrl: "./c.mq.md",
|
||||
mqReady: "#log",
|
||||
mqEnable: "#a,#b",
|
||||
},
|
||||
});
|
||||
if (norm.wasmUrl !== "./w.wasm" || norm.sourceUrl !== "./c.mq.md") {
|
||||
console.error("normalizeMountOptions failed", norm);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const args = eventArgsFromDom(
|
||||
{ type: "input", target: { value: "Ada", id: "name" } },
|
||||
"",
|
||||
);
|
||||
if (args.value !== "Ada" || args.event !== "input") {
|
||||
console.error("eventArgsFromDom failed", args);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const html = renderListItems({
|
||||
tag: "li",
|
||||
items: ["a", { text: "b", attrs: { "data-id": "2" } }],
|
||||
});
|
||||
if (!html.includes("<li>a</li>") || !html.includes('data-id="2"')) {
|
||||
console.error("renderListItems failed", html);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// DOM patch without document should no-op
|
||||
applyDomPatch({
|
||||
set_text: { "#x": "y" },
|
||||
set_style: { "#x": { color: "red" } },
|
||||
navigate: { url: "/x" },
|
||||
});
|
||||
|
||||
console.log("wasm smoke ok");
|
||||
console.log("bridge helpers ok");
|
||||
void pathToFileURL;
|
||||
Reference in new issue
Block a user