# リビングが描く画面の概要
**公開の準備中です。** 会員への表示は、端末での確認が済んでから開きます。いまは、コードを作って [試し環境](https://niho.life/developer/living-surface-emulator/sdk-1.0.0) で確かめるところまでできます。開くまでは、この版(1.0.0)の資料を作り直すことがあります。
会員が見る画面の「描く部分」を、ホストが自分のコードで作れます。いま作れる画面は **予定** です。普段使っている AI(ChatGPT・Claude・Codex など)にこの資料を渡し、できたコードを貼り付けます。プログラミングの知識は要りません。
## 誰が何を持つか
| 部分 | 持ち主 | 中身 |
| --- | --- | --- |
| 器 | NIHO | 画面の URL、ヘッダー、ドック、戻る、標準で見るボタン、通報、失敗したときの標準の画面 |
| データ | NIHO | 予定の取得、更新、権限。その会員に見えるものだけを、1 つの値にして渡す |
| 描画 | **ホストが書いたコード** | 渡された値から HTML・CSS・SVG を描く。状態とタイマーを持てる |
| 部品 | NIHO | 予定のカレンダー。リビングの描画の上か下か間に置ける |
| 操作 | NIHO | 予定の詳細、予約の作成、参加、支払い、画面の移動。ホストのコードは「開く」を頼むだけ |
ホストが書いたコードからは、通信・保存・入力欄・リンク・外の画像が使えません。予約や支払いを決めるのは、いつも NIHO の画面で会員本人です。
描けなかったとき(エラー・時間切れ・対応していない端末)は、会員には NIHO の標準の予定が出ます。
## この資料の位置づけ
型・使えるもの・上限・エラーの一覧は、実際に動くコードから作っています。ただし、この資料は安全の境界ではありません。通るかどうかは、動かすたびに NIHO の検査が決めます。
## 章
- [はじめかた](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/getting-started.md)
- [渡される値](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/data.md)
- [頼める操作](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/actions.md)
- [並びと大きさ](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/layout.md)
- [描けるもの](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/drawing.md)
- [画像と書体](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/assets.md)
- [作例](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/examples.md)
- [確認の一覧](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/checklist.md)
- [リファレンス(型・許可・上限・エラー)](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/reference.md)
- [全文(AI に渡す 1 つの URL)](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/llms-full.txt)
# はじめかた
1. 普段使っている AI に、次の URL と作りたいものを渡します。
`https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/llms-full.txt`
2. 返ってきたコードを [試し環境](https://niho.life/developer/living-surface-emulator/sdk-1.0.0) に貼り、「表示する」を押します。ログインは要りません。コードは端末の中だけで動きます。
3. 止まったら「AI に渡す文をコピー」を押し、その文を AI に渡して直してもらいます。
4. 幅・言語・動きを減らす・予定なし・多い・満席を切り替えて、崩れないことを見ます。押したときに頼む操作も、記録の欄で確かめます。
AI に渡す文の例:
> 次の資料を読んで、予定の画面のコードを書いてください。https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/llms-full.txt
> 和紙のような背景に、これからの予定を大きな日付で並べたいです。押したら予定の詳細を開いてください。
> 完全なコードを 1 つのコードブロックで、並び(before・slot・after)と一緒に返してください。
## いちばん短いコード
これだけで検査を通ります。コード全体が 1 つの式で、その Promise が終わるまでに最初の描画と `niho.ready()` を済ませます。
```js
(async () => {
const style = document.createElement("style");
style.textContent = ".list{padding:16px}.item{min-height:48px;margin-top:8px;padding:12px;border:1px solid #d6d3d1;border-radius:12px;background:#ffffff;font-size:16px;overflow-wrap:anywhere}";
document.head.append(style);
function draw() {
const view = niho.surface.get();
const english = view.language === "en";
const list = document.createElement("section");
list.className = "list";
const events = view.events.filter((event) => event.endAt.slice(0, 10) >= view.today).slice(0, 10);
if (events.length === 0) list.append(english ? "Nothing coming up" : "これからの予定はありません");
for (const event of events) {
const label = event.startAt.slice(5, 10).replace("-", "/") + " " + event.title;
const item = document.createElement("div");
item.className = "item";
item.textContent = label;
item.setAttribute("data-on-tap", "open");
item.setAttribute("aria-label", label.slice(0, 120));
item.dataset.ref = event.ref;
list.append(item);
}
document.getElementById("before").replaceChildren(list);
}
draw();
niho.surface.onChange(draw);
niho.ui.onTap("open", ({ data }) => niho.actions.request({ type: "openBooking", ref: data["data-ref"] }));
await niho.ready();
})();
```
1. `niho.surface.get()` で値を読む。
2. `document.getElementById("before")` の中に描く。
3. `niho.surface.onChange(draw)` で、値が変わったら描き直す。
4. 押せる要素に `data-on-tap` と `aria-label` を付け、`niho.ui.onTap` の中で操作を頼む。
5. `await niho.ready()` を呼ぶ。
# 渡される値
`niho.surface.get()` は、いまの値を返します。呼ぶたびに別の写しなので、書き換えても元は変わりません。値が変わると `niho.surface.onChange` が呼ばれます。正確な型は [sdk.d.ts](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/sdk.d.ts) にあります。
| 鍵 | 中身 |
| --- | --- |
| `schema` | `"SCHEDULE_V1"` |
| `language` | `"ja"` か `"en"`。会員の表示の言語。文言をこれで切り替える |
| `reducedMotion` | 動きを減らす設定。CSS の動きは NIHO が止める。タイマーで動かすものは自分で止める |
| `spot.name` | リビングの名称 |
| `labels.event` | イベントの呼び名(「イベント」「まつり」など) |
| `today` | 今日の日付(JST) |
| `range` | 渡された予定の期間(`from` から。`to` の日は含まない) |
| `viewer.canBook` | この会員が予定を作れるか。作れない人には、作るボタンを出さない |
| `zones` | 場所(`ref`・`name`)。60 件まで。0 件のこともある |
| `events` | イベント。120 件まで |
| `bookings` | 予約。400 件まで |
## events
| 鍵 | 中身 |
| --- | --- |
| `ref` | その場限りの番号(`e1`)。操作を頼むときに使う。保存できる ID ではない |
| `title` | 題名。200 字まであるので、折り返しと高さを決める |
| `startAt`・`endAt` | JST の時刻(`2026-12-03T19:30:00+09:00`)。日付は `slice(0, 10)`、時刻は `slice(11, 16)` |
| `places` | 場所の名前。0 件のこともある |
| `fee` | 円。`0` は無料、`null` は金額の設定なし(「無料」と書かない) |
| `seats` | `{ capacity, left }`。`null` は残りの席を出さないイベント |
| `registration` | `"OPEN"`・`"FULL"`(満席)・`"CLOSED"`(受付終了) |
| `joined` | この会員が参加している。満席でも参加していれば、こちらを先に見せる |
## bookings
`ref`(`b1`)・`startAt`・`endAt`・`places`・`headCount`(`null` は人数を出さない)・`exclusive`(貸切)・`mine`(この会員の予約)。**題名はありません。**
## 並びと期間
- `events` と `bookings` は、開始の順(同じなら終了の順)に並んでいます。過ぎた予定も入っているので、これからの予定は `event.endAt.slice(0, 10) >= view.today` で選びます。
- 開いたときの期間は、今日の 7 日前から 62 日。`showMonth` やカレンダーで月を移すと、その月の最初の週(日曜)から 42 日になります。見せている月は「期間が 42 日なら `from` の 7 日後の月、そうでなければ今日の月」で決められます。
- 件数が上限を超えた回は、間引いた値は渡りません。会員には標準の予定が出ます。
## 渡らないもの
ほかの会員の名前、予約の題名、説明、連絡先、支払い、参加した人の一覧、NIHO の中の ID は渡りません。予約の題名には利用した人の名前が入ることがあるためです。標準の予定でその会員に見えないものも渡りません。
これらが要る画面は作れません。予定を押したときに `openBooking` を頼むと、NIHO の詳細の画面で会員が見られます。
# 頼める操作
`niho.actions.request(操作)` を、`niho.ui.onTap` の中で呼びます。予定の画面で頼めるのは次の 4 つだけです。
| type | 中身 | 起きること |
| --- | --- | --- |
| `openBooking` | `ref`: イベントか予約の `ref` | 予定の詳細を開く |
| `startBooking` | `date`・`startHour`・`endHour`・`zoneRef`(どれも省ける) | 予約の作成を開く。予定を作れない会員では何も起きない |
| `showMonth` | `month`: `"2027-01"` | 見せる期間を、その月へ移す(今日の月から前後 24 か月まで。外の月では何も起きない) |
| `openSurface` | `surface`: `"HOME"`・`"HELP_TASKS"` | リビングのホームか、お手伝いへ移る |
```js
niho.ui.onTap("open", ({ data }) => niho.actions.request({ type: "openBooking", ref: data["data-ref"] }));
niho.ui.onTap("book", () => niho.actions.request({ type: "startBooking", date: "2026-12-03", startHour: 13, endHour: 15 }));
niho.ui.onTap("next", () => niho.actions.request({ type: "showMonth", month: "2027-01" }));
niho.ui.onTap("home", () => niho.actions.request({ type: "openSurface", surface: "HOME" }));
```
## 決まり
- 頼めるのは、会員が本当に押した(または Enter・Space を押した)ときの `onTap` の中だけです。最初の描画・`onChange`・タイマーの中から頼むと、止まります(`ACTION`)。
- 1 回のタップで頼めるのは 1 つです。
- 値は文字列か整数だけ。決まった鍵のほかは書けません。`startHour` は `date` があるときだけ、`endHour` は `startHour` があるときだけ書けます(時は 0〜24 の整数で、終わりは始まりより後)。`zoneRef` は書けますが、予約の作成の画面には、いまはまだ渡りません。
- 結果は返りません。予約が増えた・参加した・月が移ったことは、次の値(`onChange`)で分かります。「予約しました」のような文言を、押した直後に自分で出さないでください。
- 確定・支払い・同意は、開いた NIHO の画面で会員本人が行います。
## 押せる要素
```js
const item = document.createElement("div");
item.setAttribute("data-on-tap", "open");
item.setAttribute("aria-label", (day + " " + event.title).slice(0, 120));
item.dataset.ref = event.ref;
```
- `data-on-tap` の名前は、英字で始まる英数字・`.`・`_`・`-` の 40 字まで。同じ名前の `niho.ui.onTap` が呼ばれます。登録は最初に 1 回だけ(24 個まで)。
- `aria-label` は必ず付けます(空でなく 120 字まで)。題名は 200 字まであるので切ります。
- 押した要素の `data-*`(8 個・1 つ 128 字まで)が `data` に入ります。`dataset.ref` に書いたものは `data["data-ref"]` で読みます。
- HTML の要素だけが押せます(SVG は押せません)。押せる要素の中に、押せる要素は置けません。`aria-hidden="true"` の中にも置けません。
- 大きさは縦横 44px 以上にします。
# 並びと大きさ
画面は、上から順に並ぶ最大 3 つのブロックでできています。順番は変えられません。
1. `before`: リビングの描画
2. `slot`: NIHO の部品(予定のカレンダー)
3. `after`: リビングの描画
どれを使うかは、コードではなく manifest の `livingSurface.layout` に書きます。AI がコードと一緒に返すのは、`layout` の中身(`{ "before": true, … }`)だけで足ります。
```json
{ "surface": "SCHEDULE", "schema": "SCHEDULE_V1", "layout": { "before": true, "slot": { "name": "calendar", "view": "week" }, "after": true } }
```
- `before` と `after` のどちらかは要ります。使わないブロックは、鍵ごと省きます。
- `after` は `slot` があるときだけ使えます(部品が無いなら `before` の 1 つで足ります)。
- `slot` は `calendar` の `day`・`week`・`month`。カレンダーを NIHO に任せると、NIHO の新しい機能がそのまま使えます。
- コードの中では `document.getElementById("before")` と `document.getElementById("after")` に描きます。使わないブロックは `null` になるので、触りません。
## 高さ
高さは中身で決まります。縦のスクロールは画面が持つので、ブロックの中で縦に動かすことはできません(横は `overflow-x:auto`)。1 つのブロックの高さは 4096px まで、幅は 2048px までです。**題名の長い予定がたくさんあっても超えないように、並べる件数と題名の高さ(`max-height` と `overflow:hidden`)を決めます。** 描き終わった高さがそのまま画面の高さになるので、押すたびに高さが大きく変わらないようにします。
## 幅
幅 320px から PC まで、同じコードで描きます。`@media` と `vw` は無いので、`grid`・`flex`・`minmax(0,1fr)`・`max-width`・`%` で、そのまま広がる形にします。文字には `overflow-wrap:anywhere` を付け、横にはみ出さないようにします。英語は日本語より長くなるので、見出しとボタンを横に並べる所は、見出しに `min-width:0` を付けて折り返します。
## 縦書き
`writing-mode:vertical-rl` が使えます。縦書きの要素の高さは、`px` か `rem` で決めます(`auto` や `%` は使えません)。長い縦書きは、`overflow-x:auto` の箱に入れて横に流します。縦書きは日本語だけにし、英語(`language` が `"en"`)では横書きに切り替えます(1 字ずつ立った英語は読みにくいためです)。
```css
.tate{writing-mode:vertical-rl;height:320px;overflow-x:auto}
```
## 器の地の色
manifest の `layout.chrome` は書けますが、いまはまだ画面に反映されません。省いてください。
# 描けるもの
一覧は [permissions.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/permissions.json)、上限は [limits.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/limits.json) にあります。**一覧に無いものは使えません。** ブラウザにあるはずの機能も、ここでは動きません。
## 動く場所
コードは、ブラウザから切り離された小さな JavaScript の中で動きます。言語そのもの(配列・文字列・Date・正規表現・async / await・`?.`・`??` など)は使えますが、ブラウザの API は次のものだけです。
- `niho`: `niho.surface.get`・`niho.surface.onChange`・`niho.ui.onTap`・`niho.clock.now`・`niho.actions.request`・`niho.ready`
- `document`: `document.head`・`document.body`・`document.createElement`・`document.createElementNS`・`document.createTextNode`・`document.getElementById`
- 要素: `append`・`appendChild`・`attributes`・`children`・`classList.add`・`classList.contains`・`classList.remove`・`className`・`dataset`・`id`・`innerHTML`・`parentNode`・`remove`・`replaceChildren`・`setAttribute`・`textContent`(`innerHTML` は書くだけ)
- タイマー: `setTimeout`・`setInterval`・`clearTimeout`・`clearInterval`
無いもの: `fetch`・`XMLHttpRequest`・`WebSocket`・`EventSource`・`Worker`・`requestAnimationFrame`・`localStorage`・`sessionStorage`・`indexedDB`・`navigator`・`location`・`window`・`alert`・`Intl`・`getComputedStyle`・`document.querySelector`・`document.addEventListener`・`element.style`・`element.getAttribute`・`element.removeAttribute`・`element.querySelector`・`element.addEventListener`・`element.getBoundingClientRect`・`element.insertBefore`・`element.onclick`・`console`
- `append`・`replaceChildren` に渡せるのは、要素と文字列だけです。
- `dataset` は書けます。`dataset.ref = "e1"` は `data-ref="e1"` になります。
- スタイルは `style` 要素を作り、`document.head.append(style)` で入れます。
- 描き直しは、毎回ブロックの中身を `replaceChildren` で入れ替えるのが確実です。
## HTML と SVG
- 文字と箱と見出しと一覧のタグだけです。リンク・ボタン・画像・入力欄・表はありません。押せるのは `data-on-tap` を付けた要素です。
- 属性は `class`・`id`・`role`・`aria-label`・`aria-hidden`・`aria-live`・`data-*`。`style` 属性と `onclick` は使えません。値は 256 字まで、`class` と `id` は英字で始めます。
- SVG は `document.createElementNS("http://www.w3.org/2000/svg", …)` か `innerHTML` で作ります。座標は数だけ(`%` や単位は書けません)。飾りの SVG には `aria-hidden="true"`、意味のある SVG には `role="img"` と `aria-label` を付けます。
## CSS
- selector は、class・id・タグ・`[data-…]` と、つなぎの空白・`>`(3 つまで)、`:first-child`・`:last-child`・`:nth-child(数・odd・even)`・`::before`・`::after`。
- 長さは `px`(1,024 まで)・`rem`・`em`(64 まで)・`%`(100 まで)・`fr`。文字の大きさは 12〜64px。色は `#rrggbb`・`rgb()`・`hsl()`・色の名前。
- 背景に `linear-gradient`・`radial-gradient`・`conic-gradient` が使えます。影とグラデーションと画像を使う要素は、合わせて 64 個まで。影は `box-shadow`・`text-shadow` で、長さは 24px か 1.5rem まで、1 つの宣言に 2 つまで。
- 書体は `font-family` に書きます。NIHO の書体を manifest で宣言して使うか([画像と書体](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/assets.md))、端末にある書体の名前(`"Hiragino Mincho ProN"` など)と `serif`・`sans-serif`・`monospace` を並べます。書体のファイル(`url()`)は読み込めません。
- 動きは `transform` と `opacity` だけ。1 回 1 秒・3 回・遅れ 1 秒まで、動かす要素は 16 個まで(動く要素の中に、動く要素は置けません)。`transform` は `scale`(1.5 まで)・`rotate`・`translate`・`translateX`・`translateY`(前後 64px か 4rem まで)から 3 つまで、同じものは 1 つ。どれも値は 1 つです。
- 動きを減らす設定の会員には、NIHO が動きを止めて見せます。
## タイマー
`setTimeout` と `setInterval` は、合わせて 4 個、間隔は 250〜60000 ミリ秒。描き直しは 1 秒に 24 回まで。画面の外や裏にある間は止まり、戻ると続きから動きます。予定の更新は `onChange` で届くので、タイマーで確かめ直す必要はありません。
## よくある落とし穴
- `void (async () => { await niho.ready(); })();` → `SOURCE`。先頭の void を外します。最後の式が Promise になるようにします。
- `console.log("ok");` → `SOURCE`。console は使えません。消します。
- `root.style.color = "#333333";` → `SOURCE`。style は使えません。class を付け、style 要素の CSS で決めます。
- `document.querySelector(".list");` → `SOURCE`。探す関数はありません。作った要素を変数に持ちます。
- `root.addEventListener("click", () => {});` → `SOURCE`。押す操作は data-on-tap と niho.ui.onTap にします。
- `root.getAttribute("id");` → `SOURCE`。読み取る関数はありません。dataset か、自分の変数から読みます。
- `new Intl.DateTimeFormat("ja-JP");` → `SOURCE`。Intl はありません。日付と時刻の文字は startAt.slice(5, 10) のように切り出します。
- `await new Promise((resolve) => setTimeout(resolve, 300));` → `SOURCE`。最初の描画でタイマーを待ちません。先に描いて ready を呼び、後からタイマーで描き直します。
- `fetch("/data.json");` → `UNSUPPORTED_API`。通信はできません。値は niho.surface.get() だけから読みます。
- `requestAnimationFrame(() => {});` → `UNSUPPORTED_API`。動きは CSS の animation か、setInterval(250ms 以上)にします。
- `root.append(12);` → `HTML`。数は String(12) にします。
- `root.append(null);` → `HTML`。無いときは渡しません。
- `
予定
` → `HTML`。コメントを外します。
- `for (let i = 0; i < 1201; i += 1) document.createElement("i");` → `VM_LIMIT`。件数を絞ります。文字も 1 つと数えます。
- `while (true) {}` → `TIMEOUT`。終わる条件を書きます。
- `niho.actions.request({ type: "openBooking", ref: "e1" });` → `ACTION`。onTap の中だけで呼びます。
- `(async () => { document.getElementById("before").textContent = "予定"; })();` → `PACKET`。最後に await niho.ready() を呼びます。
- `
` → `PACKET`。登録した画像の名前を div の data-asset に書きます。
- `プラン` → `PACKET`。リンクはありません。画面の移動は openSurface を頼みます。
- `` → `PACKET`。div に data-on-tap と aria-label を付けます。
- `予定
` → `PACKET`。style 属性は使えません。class と CSS にします。
- `予定
` → `PACKET`。aria-label を付けます。
- `` → `PACKET`。押せる要素の中に、押せる要素を入れません。
- `` → `PACKET`。SVG は押せません。押せる div を上に重ねます。
- `` → `PACKET`。SVG の transform は使えません。座標を書き換えるか、CSS の transform にします。
- `const box = document.createElement("div"); box.className = ""; root.append(box);` → `PACKET`。class を空にしません。無いときは設定しません。
- `const box = document.createElement("div"); box.setAttribute("data-on-tap", "open"); box.setAttribute("aria-label", "あ".repeat(121)); root.append(box);` → `PACKET`。題名は 200 字まであります。aria-label は slice(0, 120) で切ります。
- `.a{color:var(--main)}` → `CSS`。色をそのまま書きます。
- `.a{width:calc(100% - 16px)}` → `CSS`。padding と box-sizing(既定で border-box)で作ります。
- `@media (min-width:600px){.a{color:#000000}}` → `CSS`。画面の幅で分けられません。grid・flex・max-width・% で、320px からそのまま広がる形にします。
- `.a{height:100vh}` → `CSS`。vh・vw はありません。高さは中身で決まります。
- `.a{background:url(photo.png)}` → `CSS`。画像は data-asset にします。
- `.a{font-size:11px}` → `CSS`。12px〜64px(0.75〜4 rem / em)にします。
- `.a{transition:opacity 300ms}` → `CSS`。時間は .3s のように秒で書きます。
- `.a{animation:blink 1s infinite}@keyframes blink{to{opacity:0}}` → `CSS`。1 秒・3 回までです。ずっと動かすものは作れません。
- `@keyframes glow{to{color:#ff0000}}` → `CSS`。動かせるのは transform と opacity だけです。
- `.a{box-shadow:0 0 40px #000000}` → `CSS`。影は 24px(1.5rem)まで、1 つの宣言に 2 つまでです。
- `.a{overflow:auto}` → `PACKET`。縦には動かせません。横だけなら overflow-x:auto です。
- `.a{filter:blur(4px)}` → `PACKET`。permissions.json に無い property は使えません(filter・clip-path・cursor・list-style・outline・content・font など)。
- `.a::before{content:"●"}` → `PACKET`。content はありません。文字の要素を足します。
- `.a:hover{opacity:.8}` → `PACKET`。使える擬似クラスは :first-child・:last-child・:nth-child(数か odd / even) だけです。
- `.a + .b{margin:0}` → `PACKET`。つなぎは空白(子孫)と > だけで、3 つまでです。
- `:root{color:#333333}` → `PACKET`。いちばん外の要素に class を付けて書きます。
- `.a{transform:translate(8px,8px)}` → `PACKET`。translateX と translateY に分けます(64px か 4rem まで。% は使えません)。
- `.a{grid-template-columns:repeat(auto-fill,minmax(120px,1fr))}` → `PACKET`。repeat の数は 2 のような数にします。
# 画像と書体
## 画像
ホストがスタジオに登録した静止画像を、要素の背景として出せます。コードには、登録した**名前**だけを書きます。
```js
const photo = document.createElement("div");
photo.className = "photo";
photo.dataset.asset = "photo";
photo.dataset.assetFit = "cover";
```
```css
.photo{height:148px;border-radius:12px;background:#c22f3e}
```
- `data-asset` は、登録した画像の名前(英小文字で始まる、英小文字・数字・ハイフンの 32 字まで)。
- `data-asset-fit` は `contain`(全体が入る。省いたときも同じ)か `cover`(箱いっぱい)。
- **画像が無くても成り立つように作ります。** 画像は、あとから届くことも、届かないこともあります。届いたかどうかは、コードからは分かりません。箱の大きさは CSS で決め、地の色(`background`)も付けます。画像の上に文字を重ねるなら、画像が無くても読める色にします。
- 画像は背景なので、読み上げられません。意味のある画像には `role="img"` と `aria-label`、飾りの画像には `aria-hidden="true"` を付けます。
- 画像の箱は、1 回の描画に 64 個まで。HTML の要素だけに付けられます(SVG には付けられません)。
- `img`・`url()`・外の画像・動く画像・SVG のファイル・書体のファイルは使えません。
登録できるのは PNG・JPEG・WebP の静止画像で、1 つの作品に 12 点までです。長辺 1080px の WebP に変換されます(1 点 320 KiB・合計 1536 KiB まで)。
## 書体
NIHO が配る書体を、manifest の `livingSurface.fonts` で宣言すると、CSS の `font-family` で使えます。使えるのは次の一覧だけです(書体のファイルや URL は書けません)。
| ID | `font-family` に書く名前 | 太さ | 大きさ |
| --- | --- | --- | --- |
| `jost-800` | `"NIHO Jost"` | 800 | 13 KiB |
| `dela-gothic-one` | `"NIHO Dela Gothic One"` | 400 | 432 KiB |
| `zen-maru-gothic-400-v1` | `"NIHO Zen Maru Gothic"` | 400 | 232 KiB |
| `yomogi-400-v1` | `"NIHO Yomogi"` | 400 | 305 KiB |
| `shippori-mincho-400-v1` | `"NIHO Shippori Mincho"` | 400 | 243 KiB |
```json
"livingSurface": {
"surface": "SCHEDULE",
"schema": "SCHEDULE_V1",
"layout": { "before": true },
"fonts": [{ "id": "dela-gothic-one", "fallback": "serif" }]
}
```
```css
.title{font-family:"NIHO Dela Gothic One";font-size:28px}
```
- `font-family` の先頭に、宣言した書体の名前を引用符つきで書きます。そのとき NIHO は、並びのうち宣言した書体と、先頭の書体の `fallback` だけを使います(ほかの名前は使いません)。
- `fallback` は `system-ui`・`sans-serif`・`serif`・`monospace` のどれかです。書体が読めない・まだ届かない端末では、この書体で表示されます。届くと差し替わるので、高さが少し変わることがあります。届かなくても描画は止まりません。
- 宣言は 5 つまで、同じ書体は 1 度だけです。使わないときは `fonts` ごと省きます(空の一覧は書けません)。
- 宣言していない名前は、端末にある書体の名前として扱います(端末に無ければ使われません)。
- 太さは一覧の 1 つだけです。`font-weight` を変えても、別の太さは読み込みません。
- 試し環境を単体の HTML として保存して開いたときは、書体を読めず、`fallback` の書体で表示されます。
# 作例
どれも検査を通り、[試し環境](https://niho.life/developer/living-surface-emulator/sdk-1.0.0) で選んで動かせます。日本語と英語、動きを減らす設定、予定なし、満席・受付終了、予定を作れない会員を扱っています。元にして、色・文言・並びを変えてください。
## 標準
これからの予定を 3 件並べ、下に NIHO の週のカレンダーを置きます。作品を作ったときに最初に入っているコードです。
- [コード](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-standard.js)・[manifest](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-standard.manifest.json)
- 並び: `{"before":true,"slot":{"name":"calendar","view":"week"}}`
## カレンダーは NIHO
月のカレンダーは NIHO の部品のまま、上に次の予定の告知、下にボタンだけを描きます。
- [コード](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-calendar.js)・[manifest](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-calendar.manifest.json)
- 並び: `{"before":true,"slot":{"name":"calendar","view":"month"},"after":true}`
## 月のポスター
写真を 1 枚使った、ポスターのような月の予定です。月を移せます。写真が無くても同じ大きさで描けます。
- [コード](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-matsuri.js)・[manifest](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-matsuri.manifest.json)
- 並び: `{"before":true,"slot":{"name":"calendar","view":"week"},"after":true}`
## 平面図
場所ごとの空きを SVG の平面図で見せます。日と時刻を変え、空いている場所を押すと予約の作成を開きます。NIHO の部品は使いません。
- [コード](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-floor-plan.js)・[manifest](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-floor-plan.manifest.json)
- 並び: `{"before":true}`
# 確認の一覧
## コードを返す前に(AI)
- コード全体が `(async () => { … await niho.ready(); })();` の 1 つの式になっている。先頭に `void` が無い。
- `niho.surface.onChange` で描き直している。`onTap`・`onChange` の登録は 1 回だけ。
- [描けるもの](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/drawing.md) の一覧に無い API・タグ・属性・CSS を使っていない。`console`・`element.style`・`querySelector`・`var()`・`calc()`・`@media`・`url()`・`vh` が無い。
- コードの中に `fetch`・`eval`・`Function`・`Worker`・`localStorage` という語が、コメントや文字列も含めて無い(あると保存できません)。
- 押せる要素すべてに、`data-on-tap` と、空でなく 120 字までの `aria-label` がある。大きさは 44px 以上。
- 操作は `onTap` の中で 1 つだけ頼んでいる。`ref` は `data-ref` から読んでいる。
- 予定が 0 件・場所が 0 件・題名が 200 字・イベントが 120 件でも、描けて、高さが 4096px を超えない。
- `fee` と `seats` の `null`、`places` の 0 件、`registration` の `FULL`・`CLOSED`、`joined` を分けて見せている。
- `language` で日本語と英語を切り替えている。`viewer.canBook` が false なら、予約のボタンを出していない。
- `reducedMotion` のとき、タイマーで動かすものを止めている。
- 画像が無くても読める。箱の大きさと地の色を CSS で決めている。
- NIHO の書体を使うなら、`livingSurface.fonts` に宣言している。書体が届かず `fallback` の書体になっても崩れない。
- 文字と地の色のコントラストが 4.5:1 以上ある。色だけで状態を伝えていない。
- 実在の人の名前、連絡先、ID、秘密を、コードに書いていない。
- 並び(`livingSurface.layout`)を、コードと一緒に書いている。
## 貼った後に(人)
- 幅 320・360・PC で、横にはみ出さない。
- 日本語と英語、動きを減らす設定で読める。
- 予定なし・多い・満席で崩れない。
- 見本の画像の、あり・なしで崩れない。
- 書体の宣言の、あり・なしで崩れない。
- 「参加した」「予約が増えた」「月を移した」で、表示が変わる。
- 押したときに、思った操作が記録される。
# SDK 1.0.0 リファレンス
型・検査・エンジンから作った一覧です。値の細かい決まりは、この一覧より厳しいことがあります。最後の判定は、動かすたびに NIHO の検査が行います。
## 配布ファイル
- [sdk.d.ts](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/sdk.d.ts): 渡される値・操作・niho の型です。契約の型から作っています。
- [manifest.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/manifest.json): 検査を通る manifest です。並びは livingSurface.layout に書きます。
- [manifest.schema.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/manifest.schema.json): manifest の構造の確認に使います。最後の判定は NIHO の検査が行います。
- [permissions.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/permissions.json): JavaScript の API・HTML・SVG・CSS の、使えるものの一覧です。
- [limits.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/limits.json): 描画・処理・値・操作・画像の上限です。
- [errors.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/errors.json): 止まったときの code ごとの、何が起きたか・どう直すか・よくある書き間違いです。
- [example-standard.js](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-standard.js): これからの予定を 3 件並べ、下に NIHO の週のカレンダーを置きます。作品を作ったときに最初に入っているコードです。
- [example-standard.manifest.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-standard.manifest.json): 作例「標準」の manifest です。
- [example-calendar.js](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-calendar.js): 月のカレンダーは NIHO の部品のまま、上に次の予定の告知、下にボタンだけを描きます。
- [example-calendar.manifest.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-calendar.manifest.json): 作例「カレンダーは NIHO」の manifest です。
- [example-matsuri.js](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-matsuri.js): 写真を 1 枚使った、ポスターのような月の予定です。月を移せます。写真が無くても同じ大きさで描けます。
- [example-matsuri.manifest.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-matsuri.manifest.json): 作例「月のポスター」の manifest です。
- [example-floor-plan.js](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-floor-plan.js): 場所ごとの空きを SVG の平面図で見せます。日と時刻を変え、空いている場所を押すと予約の作成を開きます。NIHO の部品は使いません。
- [example-floor-plan.manifest.json](https://niho.life/developer/docs/living-surfaces/sdk-1.0.0/example-floor-plan.manifest.json): 作例「平面図」の manifest です。
## 使えるもの
- HTML のタグ: `div` `section` `article` `header` `footer` `main` `h1` `h2` `h3` `h4` `h5` `h6` `p` `span` `strong` `em` `b` `i` `small` `ul` `ol` `li` `br` `hr`
- HTML の属性: `class` `id` `role` `aria-label` `aria-hidden` `aria-live` `data-*`
- `role` の値: `article` `button` `group` `heading` `img` `list` `listitem` `presentation` `status` `text`
- SVG のタグ: `svg` `g` `path` `circle` `ellipse` `rect` `line` `polyline` `polygon` `text`
- SVG の属性: `class` `id` `role` `aria-label` `aria-hidden` `viewBox` `d` `cx` `cy` `r` `rx` `ry` `x` `y` `x1` `x2` `y1` `y2` `width` `height` `points` `fill` `stroke` `stroke-width` `stroke-linecap` `stroke-linejoin` `opacity`
- CSS の property: `align-content` `align-items` `align-self` `animation` `animation-delay` `animation-duration` `animation-fill-mode` `animation-iteration-count` `animation-name` `animation-timing-function` `aspect-ratio` `background` `background-color` `border` `border-bottom` `border-bottom-left-radius` `border-bottom-right-radius` `border-bottom-width` `border-color` `border-left` `border-left-width` `border-radius` `border-right` `border-right-width` `border-style` `border-top` `border-top-left-radius` `border-top-right-radius` `border-top-width` `border-width` `bottom` `box-shadow` `color` `column-gap` `display` `flex` `flex-basis` `flex-direction` `flex-grow` `flex-shrink` `flex-wrap` `font-family` `font-size` `font-style` `font-weight` `gap` `grid-auto-flow` `grid-column` `grid-row` `grid-template-columns` `grid-template-rows` `height` `inset` `justify-content` `justify-items` `justify-self` `left` `letter-spacing` `line-height` `margin` `margin-bottom` `margin-left` `margin-right` `margin-top` `max-height` `max-width` `min-height` `min-width` `opacity` `overflow` `overflow-wrap` `overflow-x` `padding` `padding-bottom` `padding-left` `padding-right` `padding-top` `place-content` `place-items` `position` `right` `row-gap` `text-align` `text-decoration` `text-orientation` `text-overflow` `text-shadow` `text-transform` `top` `transform` `transform-origin` `transition` `transition-delay` `transition-duration` `transition-property` `transition-timing-function` `white-space` `width` `word-break` `writing-mode` `z-index`
- CSS の関数: `rgb` `rgba` `hsl` `hsla` `linear-gradient` `radial-gradient` `conic-gradient` `repeat` `minmax` `scale` `rotate` `translate` `translateX` `translateY`
- CSS の単位: `px` `rem` `em` `s` `deg` `fr` `%`
- 語が決まっている CSS: `overflow: hidden / visible / clip`・`overflow-x: auto / hidden / visible`・`writing-mode: horizontal-tb / vertical-rl`・`text-orientation: mixed / upright`
- NIHO の書体(`livingSurface.fonts` で宣言): `jost-800`(`"NIHO Jost"`・800)・`dela-gothic-one`(`"NIHO Dela Gothic One"`・400)・`zen-maru-gothic-400-v1`(`"NIHO Zen Maru Gothic"`・400)・`yomogi-400-v1`(`"NIHO Yomogi"`・400)・`shippori-mincho-400-v1`(`"NIHO Shippori Mincho"`・400)
- 書体の `fallback`: `system-ui` `sans-serif` `serif` `monospace`
## 上限
### 描画(2 つのブロックの合計)
| 名前 | 値 |
| --- | --- |
| `sourceMaxBytes` | 1048576 |
| `maxBytesExclusive` | 131072 |
| `maxNodes` | 1200 |
| `maxDepth` | 16 |
| `maxTextCodeUnits` | 32768 |
| `maxCssCodeUnits` | 49152 |
| `maxCssRules` | 256 |
| `maxKeyframes` | 16 |
| `maxCssTokens` | 4096 |
| `maxCssTokenDepth` | 8 |
| `maxMotionTargets` | 16 |
| `maxExpensiveTargets` | 64 |
| `maxAssetTargets` | 64 |
| `maxBlockWidthPx` | 2048 |
| `maxBlockHeightPx` | 4096 |
| `maxBlockAreaPx` | 8388608 |
| `maxComputedFontSizePx` | 256 |
| `maxHeightMessagesPerSecond` | 10 |
| `maxAnimationDelaySeconds` | 1 |
| `maxAnimationIterations` | 3 |
| `maxSelectorCodeUnits` | 128 |
| `maxSelectorCombinators` | 3 |
| `maxTapNameCodeUnits` | 40 |
| `maxTapAriaLabelCodeUnits` | 120 |
| `maxTapDataAttributes` | 8 |
| `maxTapDataValueCodeUnits` | 128 |
| `maxTapListeners` | 24 |
| `maxTimers` | 4 |
| `minTimerDelayMs` | 250 |
| `maxTimerDelayMs` | 60000 |
| `maxLocalJobsPerSecond` | 24 |
### 処理
| 名前 | 値 |
| --- | --- |
| `initialJobMs` | 300 |
| `jobMs` | 200 |
| `memoryBytes` | 33554432 |
| `stackBytes` | 262144 |
| `promiseJobsPerJob` | 64 |
| `innerHtmlCodeUnits` | 16384 |
| `renderMsPerSecond` | 600 |
### 予定の値
| 名前 | 値 |
| --- | --- |
| `events` | 120 |
| `bookings` | 400 |
| `zones` | 60 |
| `placesPerItem` | 20 |
| `titleCodeUnits` | 200 |
| `nameCodeUnits` | 60 |
| `labelCodeUnits` | 40 |
| `rangeDays` | 62 |
| `monthReach` | 24 |
| `capacity` | 500 |
| `headCount` | 10000 |
| `feeYen` | 50000000 |
### 操作の依頼
| 名前 | 値 |
| --- | --- |
| `maxKeys` | 8 |
| `maxStringCodeUnits` | 80 |
### 画像
| 名前 | 値 |
| --- | --- |
| `assets` | 12 |
| `sourceBytes` | 4194304 |
| `sourceEdge` | 4096 |
| `sourcePixels` | 16777216 |
| `displayEdge` | 1080 |
| `derivativeBytes` | 327680 |
| `totalDerivativeBytes` | 1572864 |
## エラー
### SOURCE
コードが途中で止まりました。書き間違い、無い関数の呼び出し、投げられたままの例外、終わらない Promise のどれかです。
コード全体を (async () => { 最初の描画; await niho.ready(); })(); の 1 つの式にします。無い関数(console・window・element.style・querySelector・getAttribute・addEventListener など)を、resource の permissions.json にあるものへ置き換えます。
### VM_LIMIT
1 回の処理で作る要素・タイマー・聞き手・メモリ・描き直しの回数の、どれかが上限を超えました。
並べる件数を slice で減らします。要素は 1 回の処理で 1200 個、タイマーは 4 個、onTap は 24 個までです。onTap と onChange は最初に 1 回だけ登録し、描き直しの中で登録しません。
### UNSUPPORTED_API
使えない機能を呼びました。
通信(fetch など)・requestAnimationFrame・innerHTML の読み取りを外します。値は niho.surface.get()、変化は niho.surface.onChange()、時間の流れは setTimeout / setInterval(引数は関数と時間だけ)を使います。
### HTML
要素の組み立て方が正しくありません。append に文字列・要素以外(数・null など)を渡した、HTML にコメントがある、innerHTML が長すぎる、のどれかです。
数は String(値) にしてから渡します。空の要素は渡さず、配列から除きます。HTML のコメントを外し、長い HTML は createElement で組み立てます。
### CSS
CSS に、使えない書き方があります。
var()・calc()・url()・@media・@import・vh・vw・ms を外します。長さは px / rem / em / %、時間は s、文字の大きさは 12px 以上、動きは 1 秒・3 回までの transform と opacity にします。
### PACKET
描いた結果が検査を通りませんでした。使えないタグ・属性・CSS の property・selector がある、押せる要素に読み上げの名前が無い、await niho.ready() が無い、大きさ・数の上限を超えた、のどれかです。
permissions.json の一覧に無いものを外します。押せる要素は div にし、data-on-tap と、空でなく 120 字までの aria-label を付けます。class を空にしません。長い一覧は件数を絞り、題名の高さを max-height で決めて、1 つのブロックの高さを 4096px までにします。
### ENGINE
描画のエンジンを準備できませんでした。コードの間違いではありません。
最新の Chrome で開き直し、標準の作例が表示されるか確かめます。
### TIMEOUT
決められた時間の中で処理が終わりませんでした。
終わらない繰り返しと、時間のかかる正規表現を外します。1 回の処理で調べる件数を減らし、同じ計算を描き直しのたびに繰り返さないようにします。
### STALE
値の更新の順が入れ替わりました。コードの間違いではありません。
もう一度表示します。
### DISPOSED
表示が終わりました。コードの間違いではありません。
もう一度表示します。
### ACTION
操作の依頼が決まりに合いませんでした。onTap の外で頼んだ、1 回のタップで 2 つ頼んだ、形が違う、のどれかです。
niho.actions.request は onTap の中で 1 回だけ呼びます。type と中身の鍵は actions の章にあるものだけにし、値は文字列か整数にします。
# 型・manifest・作例のコード
## sdk.d.ts
```ts
export declare const SCHEDULE_SURFACE_SCHEMA: "SCHEDULE_V1";
export declare const SCHEDULE_SURFACE_LANGUAGES: readonly [
"ja",
"en"
];
export type ScheduleSurfaceLanguage = (typeof SCHEDULE_SURFACE_LANGUAGES)[number];
export declare const SCHEDULE_SURFACE_REGISTRATIONS: readonly [
"OPEN",
"FULL",
"CLOSED"
];
export type ScheduleSurfaceRegistration = (typeof SCHEDULE_SURFACE_REGISTRATIONS)[number];
export type ScheduleSurfaceEventV1 = Readonly<{
/** 親が画面を開くたびに作る使い捨ての番号。予定の ID ではない。 */
ref: string;
title: string;
/** JST の時刻(`2026-12-03T19:30:00+09:00`)。 */
startAt: string;
endAt: string;
places: readonly string[];
/** 円。0 は無料、null は金額の設定なし。 */
fee: number | null;
/** 残りの席。null は残席を出さないイベント。 */
seats: Readonly<{
capacity: number;
left: number;
}> | null;
registration: ScheduleSurfaceRegistration;
joined: boolean;
}>;
export type ScheduleSurfaceBookingV1 = Readonly<{
ref: string;
startAt: string;
endAt: string;
places: readonly string[];
headCount: number | null;
/** 貸切。 */
exclusive: boolean;
mine: boolean;
}>;
export type ScheduleSurfaceSnapshotV1 = Readonly<{
schema: typeof SCHEDULE_SURFACE_SCHEMA;
language: ScheduleSurfaceLanguage;
reducedMotion: boolean;
spot: Readonly<{
name: string;
}>;
labels: Readonly<{
event: string;
}>;
/** JST の日付。`range.to` は含まない。 */
today: string;
range: Readonly<{
from: string;
to: string;
}>;
viewer: Readonly<{
canBook: boolean;
}>;
zones: readonly Readonly<{
ref: string;
name: string;
}>[];
events: readonly ScheduleSurfaceEventV1[];
bookings: readonly ScheduleSurfaceBookingV1[];
}>;
/** `openSurface` で移れる画面。描けるかどうか(台帳)とは別。 */
export declare const SCHEDULE_SURFACE_LINK_TARGETS: readonly [
"HOME",
"SCHEDULE",
"HELP_TASKS"
];
export type ScheduleSurfaceLinkTarget = (typeof SCHEDULE_SURFACE_LINK_TARGETS)[number];
/** どれも「開く」「見る期間を変える」だけ。予約・参加・支払いの確定は NIHO の画面で会員が行う。 */
export type ScheduleSurfaceAction = Readonly<{
type: "openBooking";
ref: string;
}> | Readonly<{
type: "startBooking";
date?: string;
startHour?: number;
endHour?: number;
zoneRef?: string;
}> | Readonly<{
type: "showMonth";
month: string;
}> | Readonly<{
type: "openSurface";
surface: ScheduleSurfaceLinkTarget;
}>;
export type LivingSurfaceChangeV1 = Readonly<{
snapshot: Snapshot;
sequence: number;
}>;
export type LivingSurfaceTapInputV1 = Readonly<{
name: string;
/** 押した要素の `data-*`(`data-on-tap` を除く)。鍵は `data-ref` のように属性の名前のまま。 */
data: Readonly>;
}>;
/** ホストが書いたコードから使える `niho`。実体は描画エンジンの中にあり、ここに無いものは使えない。 */
export interface LivingSurfaceSdkV1 {
readonly surface: {
/** 今の値。呼ぶたびに別の写しを返す。 */
get(): Snapshot;
/** 値が変わったときに呼ばれる。戻り値を呼ぶと聞くのをやめる。 */
onChange(listener: (change: LivingSurfaceChangeV1) => void | Promise): () => void;
};
readonly ui: {
/** `data-on-tap` に同じ名前を書いた要素が押されたときに呼ばれる。 */
onTap(name: string, listener: (input: LivingSurfaceTapInputV1) => void | Promise): () => void;
};
readonly clock: {
/** 端末の時刻(JST・秒まで。`2026-12-03T19:30:00+09:00`)。1 回の処理の間は変わらない。 */
now(): string;
};
readonly actions: {
/** NIHO の操作を頼む。`onTap` の中で、1 回のタップに 1 つだけ。結果は返らない。 */
request(action: Action): void;
};
/** 最初の描画ができたら 1 回呼ぶ。 */
ready(): Promise;
}
export type NihoScheduleSurfaceSdkV1 = LivingSurfaceSdkV1;
declare global { const niho: NihoScheduleSurfaceSdkV1; }
```
## manifest.json
```json
{
"manifestVersion": "0.1",
"bridgeVersion": "0.1.0",
"runtimeProfile": "LIVING_SURFACE_V1",
"livingSurface": {
"surface": "SCHEDULE",
"schema": "SCHEDULE_V1",
"layout": {
"before": true,
"slot": {
"name": "calendar",
"view": "week"
}
}
},
"name": "予定の画面",
"strings": {
"ja": {
"surface.title": "予定の画面"
},
"en": {
"surface.title": "Schedule"
}
},
"languages": [
"ja",
"en"
],
"capabilities": [
"diagnostics.write"
],
"dataSchemas": [],
"editableFields": {
"type": "object",
"additionalProperties": false,
"properties": {},
"required": []
},
"surfaces": [
"MEMBER"
]
}
```
## example-standard.js
```js
(async () => {
const copy = {
ja: { heading: "これからの予定", empty: "これからの予定はありません", free: "無料", full: "満席", joined: "参加します" },
en: { heading: "Coming up", empty: "Nothing coming up", free: "Free", full: "Full", joined: "Joined" },
};
const style = document.createElement("style");
style.textContent = ".next{padding:16px;color:#292524}.heading{margin:0 0 8px;font-size:17px;font-weight:700}.item{display:grid;grid-template-columns:56px minmax(0,1fr);gap:12px;align-items:center;min-height:56px;margin-top:8px;padding:10px 12px;border:1px solid #e7e5e4;border-radius:12px;background:#ffffff}.date{font-size:15px;font-weight:700;text-align:center}.title{font-size:15px;font-weight:700;overflow-wrap:anywhere}.meta{margin-top:2px;font-size:13px;color:#57534e;overflow-wrap:anywhere}.empty{margin:0;font-size:14px;color:#57534e}";
document.head.append(style);
const root = document.getElementById("before");
const element = (tag, className, text) => { const node = document.createElement(tag); node.className = className; if (text) node.textContent = text; return node; };
const draw = () => {
const view = niho.surface.get();
const text = copy[view.language] || copy.ja;
const section = element("section", "next");
section.append(element("h2", "heading", text.heading));
const events = view.events.filter((event) => event.endAt.slice(0, 10) >= view.today).slice(0, 3);
if (events.length === 0) section.append(element("p", "empty", text.empty));
for (const event of events) {
const day = Number(event.startAt.slice(5, 7)) + "/" + Number(event.startAt.slice(8, 10));
const fee = event.fee === null ? "" : event.fee === 0 ? text.free : "¥" + String(event.fee).replace(/\B(?=(\d{3})+$)/g, ",");
const state = event.joined ? text.joined : event.registration === "FULL" ? text.full : "";
const meta = [event.startAt.slice(11, 16), event.places.join(" / "), fee, state].filter((part) => part !== "").join(" ");
const body = element("div", "body");
body.append(element("div", "title", event.title), element("div", "meta", meta));
const item = element("div", "item");
item.setAttribute("data-on-tap", "open");
item.setAttribute("aria-label", (day + " " + event.title).slice(0, 120));
item.dataset.ref = event.ref;
item.append(element("div", "date", day), body);
section.append(item);
}
root.replaceChildren(section);
};
draw();
niho.surface.onChange(draw);
niho.ui.onTap("open", ({ data }) => niho.actions.request({ type: "openBooking", ref: data["data-ref"] }));
await niho.ready();
})();
```
## example-calendar.js
```js
(async () => {
// カレンダーは NIHO の部品に任せ、上の告知と下のボタンだけを描く。
const el = (tag, className, ...children) => {
const node = document.createElement(tag);
if (className) node.className = className;
node.append(...children);
return node;
};
// 押せる要素には、名前(data-on-tap)と読み上げの名前(aria-label・120 字まで)が要る。
const tap = (node, name, label, data) => {
node.setAttribute("data-on-tap", name);
node.setAttribute("aria-label", label.slice(0, 120));
for (const [key, value] of Object.entries(data || {})) node.dataset[key] = value;
return node;
};
const dayOf = (instant) => Number(instant.slice(5, 7)) + "/" + Number(instant.slice(8, 10));
// 申込の状態。参加している → 満席 → 受付終了 → 残りの席 の順に見る。
const stateOf = (event, text) => event.joined ? text.joined
: event.registration === "FULL" ? text.full
: event.registration === "CLOSED" ? text.closed
: event.seats ? text.left(event.seats.left) : "";
const join = (...parts) => parts.filter((part) => part !== "").join(" ");
const yen = (amount) => "¥" + String(amount).replace(/\B(?=(\d{3})+$)/g, ",");
const feeOf = (event, text) => event.fee === null ? "" : event.fee === 0 ? text.free : yen(event.fee);
const TEXT = {
ja: { next: "つぎの", empty: "これからの予定はありません", book: "場所をとる", home: "リビングへ戻る", free: "無料", joined: "参加します", full: "満席", closed: "受付終了", left: (count) => "あと" + count + "席" },
en: { next: "Next ", empty: "Nothing coming up", book: "Book a space", home: "Back to the living room", free: "Free", joined: "Joined", full: "Full", closed: "Closed", left: (count) => count + " left" },
};
const style = document.createElement("style");
style.textContent = [
".notice{margin:12px 16px;padding:16px;border-radius:12px;background:#2f5d50;color:#ffffff}",
".kicker{font-size:13px;font-weight:700}",
".title{max-height:2.8em;margin:4px 0 0;overflow:hidden;font-size:20px;font-weight:800;line-height:1.4;overflow-wrap:anywhere}",
".meta{margin:6px 0 0;font-size:14px;overflow-wrap:anywhere}",
".empty{margin:12px 16px;padding:16px;border-radius:12px;background:#eef3ec;color:#2b3a33;font-size:15px}",
".foot{display:grid;gap:8px;padding:12px 16px 20px}",
".main{min-height:48px;padding:12px;border-radius:12px;background:#2f5d50;color:#ffffff;font-size:16px;font-weight:700;text-align:center}",
".sub{min-height:48px;padding:12px;border:1px solid #9aa89f;border-radius:12px;color:#2b3a33;font-size:15px;font-weight:700;text-align:center}",
].join("");
document.head.append(style);
const draw = () => {
const view = niho.surface.get();
const text = TEXT[view.language] || TEXT.ja;
const next = view.events.find((event) => event.endAt.slice(0, 10) >= view.today);
const when = next ? dayOf(next.startAt) + " " + next.startAt.slice(11, 16) : "";
document.getElementById("before").replaceChildren(next
? tap(el("section", "notice",
el("div", "kicker", text.next + view.labels.event),
el("h2", "title", next.title),
el("p", "meta", join(when, next.places.slice(0, 3).join("・"))),
el("p", "meta", join(feeOf(next, text), stateOf(next, text)))), "open", when + " " + next.title, { ref: next.ref })
: el("section", "empty", text.empty));
const foot = el("section", "foot");
// 予定を作れない人には、作るボタンを出さない(押しても何も起きないため)。
if (view.viewer.canBook) foot.append(tap(el("div", "main", text.book), "book", text.book));
foot.append(tap(el("div", "sub", text.home), "home", text.home));
document.getElementById("after").replaceChildren(foot);
};
draw();
niho.surface.onChange(draw);
niho.ui.onTap("open", ({ data }) => niho.actions.request({ type: "openBooking", ref: data["data-ref"] }));
niho.ui.onTap("book", () => niho.actions.request({ type: "startBooking", date: niho.surface.get().today }));
niho.ui.onTap("home", () => niho.actions.request({ type: "openSurface", surface: "HOME" }));
await niho.ready();
})();
```
## example-matsuri.js
```js
(async () => {
// ポスターのような月の予定。写真は「photo」という名前で登録した画像で、無くても地の色と箱の大きさは同じ。
const el = (tag, className, ...children) => {
const node = document.createElement(tag);
if (className) node.className = className;
node.append(...children);
return node;
};
// 押せる要素には、名前(data-on-tap)と読み上げの名前(aria-label・120 字まで)が要る。
const tap = (node, name, label, data) => {
node.setAttribute("data-on-tap", name);
node.setAttribute("aria-label", label.slice(0, 120));
for (const [key, value] of Object.entries(data || {})) node.dataset[key] = value;
return node;
};
const dayOf = (instant) => Number(instant.slice(5, 7)) + "/" + Number(instant.slice(8, 10));
// 申込の状態。参加している → 満席 → 受付終了 → 残りの席 の順に見る。
const stateOf = (event, text) => event.joined ? text.joined
: event.registration === "FULL" ? text.full
: event.registration === "CLOSED" ? text.closed
: event.seats ? text.left(event.seats.left) : "";
const join = (...parts) => parts.filter((part) => part !== "").join(" ");
const yen = (amount) => "¥" + String(amount).replace(/\B(?=(\d{3})+$)/g, ",");
const feeOf = (event, text) => event.fee === null ? "" : event.fee === 0 ? text.free : yen(event.fee);
const svg = (tag, attributes, ...children) => {
const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
node.append(...children);
return node;
};
const TEXT = {
ja: { empty: "この月の予定は、まだありません", more: (count) => "ほか " + count + " 件", previous: "前の月", next: "次の月", book: "場所をとる", free: "無料", joined: "参加します", full: "満席", closed: "受付終了", left: (count) => "あと" + count + "席" },
en: { empty: "Nothing planned this month yet", more: (count) => count + " more", previous: "Previous month", next: "Next month", book: "Book a space", free: "Free", joined: "Joined", full: "Full", closed: "Closed", left: (count) => count + " left" },
};
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const WEEK = { ja: ["日", "月", "火", "水", "木", "金", "土"], en: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] };
const MAX_ROWS = 24;
const style = document.createElement("style");
style.textContent = [
".poster{padding-bottom:8px;background:#f4ede3;color:#26231f}",
".head{display:flex;align-items:center;gap:8px;padding:12px 16px}",
".month{flex:1 1 0;min-width:0}",
".kicker{max-height:1.4em;overflow:hidden;font-size:13px;font-weight:700;line-height:1.4;color:#a3243a;overflow-wrap:anywhere}",
".name{margin:0;font-size:32px;font-weight:800;line-height:1.2;color:#c22f3e}",
".turn{width:48px;height:48px;border:2px solid #26231f;border-radius:24px;font-size:18px;font-weight:800;line-height:44px;text-align:center}",
".photo{position:relative;height:148px;margin:0 16px;overflow:hidden;border-radius:12px;background:#c22f3e}",
".lantern{position:absolute;top:0;width:28px;height:44px}",
".sway{animation:sway .9s ease-in-out 3 both}",
"@keyframes sway{from{transform:rotate(-4deg)}to{transform:rotate(4deg)}}",
".row{display:grid;grid-template-columns:60px minmax(0,1fr);gap:12px;align-items:center;min-height:64px;margin:0 16px;padding:10px 0;border-bottom:2px solid #26231f}",
".day{font-size:30px;font-weight:800;line-height:1;text-align:center}",
".day small{display:block;margin-top:4px;font-size:12px}",
".title{max-height:2.8em;overflow:hidden;font-size:17px;font-weight:800;line-height:1.4;overflow-wrap:anywhere}",
".meta{margin-top:4px;font-size:13px;overflow-wrap:anywhere}",
".mark{display:inline-block;margin-top:4px;padding:2px 8px;border-radius:10px;background:#c22f3e;color:#ffffff;font-size:12px;font-weight:800}",
".note{margin:0;padding:20px 16px;font-size:15px}",
".book{min-height:52px;margin:12px 16px 20px;padding:14px;border-radius:12px;background:#26231f;color:#f4ede3;font-size:16px;font-weight:800;text-align:center}",
].concat([0, 1, 2, 3, 4].map((index) => ".at" + index + "{left:" + (6 + index * 20) + "%}")).join("");
document.head.append(style);
const daysBetween = (from, to) => (Date.parse(to + "T00:00:00Z") - Date.parse(from + "T00:00:00Z")) / 86400000;
// いま見せる月。「月を移す」の後の期間は、その月の最初の週から 42 日。開いたときは今日の月を見せる。
const monthOf = ({ range, today }) => daysBetween(range.from, range.to) === 42
? new Date(Date.parse(range.from + "T00:00:00Z") + 7 * 86400000).toISOString().slice(0, 7)
: today.slice(0, 7);
const shift = (month, step) => {
const date = new Date(month + "-01T00:00:00Z");
date.setUTCMonth(date.getUTCMonth() + step);
return date.toISOString().slice(0, 7);
};
const lantern = (index) => svg("svg", { class: "lantern sway at" + index, viewBox: "0 0 40 60", "aria-hidden": "true" },
svg("path", { d: "M20 0v14", stroke: "#26231f", "stroke-width": "2" }),
svg("ellipse", { cx: "20", cy: "34", rx: "17", ry: "20", fill: index % 2 ? "#f7b0a4" : "#ffe2c9" }),
svg("path", { d: "M5 28h30M3 34h34M5 40h30", stroke: "#c22f3e", "stroke-width": "1.5" }));
const draw = () => {
const view = niho.surface.get();
const text = TEXT[view.language] || TEXT.ja;
const week = WEEK[view.language] || WEEK.ja;
const month = monthOf(view);
const number = Number(month.slice(5, 7));
const turn = (name, label, sign) => tap(el("div", "turn", sign), "month", label, { month: name });
const photo = el("div", "photo", ...[0, 1, 2, 3, 4].map(lantern));
photo.dataset.asset = "photo";
photo.dataset.assetFit = "cover";
const page = el("section", "poster",
el("header", "head",
el("div", "month", el("div", "kicker", view.spot.name), el("h1", "name", view.language === "en" ? MONTHS[number - 1] : number + "月")),
turn(shift(month, -1), text.previous, "←"),
turn(shift(month, 1), text.next, "→")),
photo);
const events = view.events.filter((event) => event.startAt.slice(0, 7) === month && event.endAt.slice(0, 10) >= view.today);
for (const event of events.slice(0, MAX_ROWS)) {
const weekday = week[new Date(event.startAt.slice(0, 10) + "T00:00:00Z").getUTCDay()];
const state = stateOf(event, text);
const body = el("div", "", el("div", "title", event.title),
el("div", "meta", join(event.startAt.slice(11, 16), event.places.slice(0, 2).join("・"), feeOf(event, text))));
if (state !== "") body.append(el("span", "mark", state));
const row = el("div", "row", el("div", "day", String(Number(event.startAt.slice(8, 10))), el("small", "", weekday)), body);
page.append(tap(row, "open", dayOf(event.startAt) + " " + event.title, { ref: event.ref }));
}
if (events.length === 0) page.append(el("p", "note", text.empty));
if (events.length > MAX_ROWS) page.append(el("p", "note", text.more(events.length - MAX_ROWS)));
document.getElementById("before").replaceChildren(page);
document.getElementById("after").replaceChildren(...(view.viewer.canBook ? [tap(el("div", "book", text.book), "book", text.book)] : []));
};
draw();
niho.surface.onChange(draw);
niho.ui.onTap("open", ({ data }) => niho.actions.request({ type: "openBooking", ref: data["data-ref"] }));
niho.ui.onTap("month", ({ data }) => niho.actions.request({ type: "showMonth", month: data["data-month"] }));
niho.ui.onTap("book", () => niho.actions.request({ type: "startBooking", date: niho.surface.get().today }));
await niho.ready();
})();
```
## example-floor-plan.js
```js
(async () => {
// 場所ごとの空きを平面図で見せる。SVG は絵だけで、押せるのは上に重ねた HTML の要素。
const el = (tag, className, ...children) => {
const node = document.createElement(tag);
if (className) node.className = className;
node.append(...children);
return node;
};
// 押せる要素には、名前(data-on-tap)と読み上げの名前(aria-label・120 字まで)が要る。
const tap = (node, name, label, data) => {
node.setAttribute("data-on-tap", name);
node.setAttribute("aria-label", label.slice(0, 120));
for (const [key, value] of Object.entries(data || {})) node.dataset[key] = value;
return node;
};
const dayOf = (instant) => Number(instant.slice(5, 7)) + "/" + Number(instant.slice(8, 10));
// 申込の状態。参加している → 満席 → 受付終了 → 残りの席 の順に見る。
const stateOf = (event, text) => event.joined ? text.joined
: event.registration === "FULL" ? text.full
: event.registration === "CLOSED" ? text.closed
: event.seats ? text.left(event.seats.left) : "";
const join = (...parts) => parts.filter((part) => part !== "").join(" ");
const svg = (tag, attributes, ...children) => {
const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
node.append(...children);
return node;
};
const TEXT = {
ja: { open: "あいています", mine: "あなたの予約", exclusive: "貸切", until: (time) => time + "まで", vacant: (count) => count + "か所あいています", none: "いまはいっぱいです", noZones: "場所がまだありません", previousDay: "前の日", nextDay: "次の日", previousHour: "1時間前", nextHour: "1時間後", play: "一日を流す", stop: "止める", joined: "参加します", full: "満席", closed: "受付終了", left: (count) => "あと" + count + "席" },
en: { open: "Open", mine: "Your booking", exclusive: "Private", until: (time) => "Until " + time, vacant: (count) => count + " open", none: "All taken now", noZones: "No spaces yet", previousDay: "Previous day", nextDay: "Next day", previousHour: "1 hour earlier", nextHour: "1 hour later", play: "Play the day", stop: "Stop", joined: "Joined", full: "Full", closed: "Closed", left: (count) => count + " left" },
};
const FIRST_HOUR = 9;
const LAST_HOUR = 20;
// 平面図の部屋の位置(320 × 240 の図の中)。7 つ目からの場所は、図の下に並べる。
const ROOMS = [[8, 8, 148, 72], [164, 8, 148, 72], [8, 88, 100, 72], [116, 88, 196, 72], [8, 168, 148, 64], [164, 168, 148, 64]];
const COLOR = { open: "#ffffff", mine: "#bfe3c6", exclusive: "#dadfd2", used: "#f3cfa8", event: "#fbe3a6" };
const style = document.createElement("style");
style.textContent = [
".plan{padding:12px 16px 16px;background:#f3f7ec;color:#2b3a2e}",
".bar{display:grid;grid-template-columns:48px minmax(0,1fr) 48px;gap:8px;align-items:center;margin-bottom:8px}",
".step{height:48px;border:1px solid #9bb08a;border-radius:12px;background:#ffffff;font-size:18px;font-weight:800;line-height:46px;text-align:center}",
".now{font-size:20px;font-weight:800;text-align:center}",
".sum{margin:0 0 8px;font-size:14px;font-weight:700}",
".map{position:relative;aspect-ratio:4 / 3}",
".map svg{position:absolute;left:0;top:0;width:100%;height:100%}",
".room{position:absolute;padding:8px;overflow:hidden;font-size:13px;font-weight:800;line-height:1.3;overflow-wrap:anywhere}",
".room small,.row small{display:block;max-height:2.6em;overflow:hidden;font-size:12px;font-weight:700;line-height:1.3;color:#4d5c4c}",
".row{min-height:48px;margin-top:8px;padding:8px 12px;border:1px solid #c9d8ba;border-radius:12px;background:#ffffff;font-size:14px;font-weight:800;overflow-wrap:anywhere}",
".play{min-height:48px;margin-top:12px;padding:12px;border-radius:12px;background:#356f46;color:#ffffff;font-size:15px;font-weight:700;text-align:center}",
".bar,.sum,.map,.row,.play{max-width:640px;margin-left:auto;margin-right:auto}",
].concat(ROOMS.map(([x, y, width, height], index) =>
".r" + index + "{left:" + (x / 3.2).toFixed(2) + "%;top:" + (y / 2.4).toFixed(2) + "%;width:" + (width / 3.2).toFixed(2) + "%;height:" + (height / 2.4).toFixed(2) + "%}")).join("");
document.head.append(style);
const pad = (value) => String(value).padStart(2, "0");
const state = {
date: niho.surface.get().today,
hour: Math.max(FIRST_HOUR, Math.min(LAST_HOUR, Number(niho.clock.now().slice(11, 13)))),
timer: 0,
};
const shiftDay = (date, step) => new Date(Date.parse(date + "T00:00:00Z") + step * 86400000).toISOString().slice(0, 10);
// その時刻にその場所で起きていること。予定・予約が無ければ空き。
const statusOf = (view, zone, moment, text) => {
const covers = (item) => item.startAt <= moment && item.endAt > moment && item.places.includes(zone.name);
const event = view.events.find(covers);
if (event) return { kind: "event", text: join(event.title, stateOf(event, text)), ref: event.ref };
const booking = view.bookings.find(covers);
if (!booking) return { kind: "open", text: text.open, ref: "" };
if (booking.mine) return { kind: "mine", text: text.mine, ref: booking.ref };
return { kind: booking.exclusive ? "exclusive" : "used", text: join(booking.exclusive ? text.exclusive : "", text.until(booking.endAt.slice(11, 16))), ref: booking.ref };
};
const draw = () => {
const view = niho.surface.get();
const text = TEXT[view.language] || TEXT.ja;
// 見せる日が、渡された期間から外れたら今日へ戻す。今日も外れていたら(月を移したとき)、その月の 1 日にする。
const inRange = (date) => date >= view.range.from && date < view.range.to;
if (!inRange(state.date)) state.date = inRange(view.today) ? view.today : shiftDay(view.range.from, 7).slice(0, 8) + "01";
// 動きを控える設定に変わったら、流していた時間を止める。
if (view.reducedMotion && state.timer) { clearInterval(state.timer); state.timer = 0; }
const moment = state.date + "T" + pad(state.hour) + ":30:00+09:00";
const statuses = view.zones.map((zone) => statusOf(view, zone, moment, text));
const vacant = statuses.filter((status) => status.kind === "open").length;
const step = (kind, sign, label, amount) => tap(el("div", "step", sign), kind, label, { step: String(amount) });
const cell = (zone, status, className) => {
const node = el("div", className, zone.name, el("small", "", status.text));
const label = zone.name + " " + status.text;
if (status.ref !== "") return tap(node, "open", label, { ref: status.ref });
return view.viewer.canBook ? tap(node, "start", label, { zone: zone.ref }) : node;
};
const map = el("div", "map", svg("svg", { viewBox: "0 0 320 240", "aria-hidden": "true" },
svg("rect", { x: "1", y: "1", width: "318", height: "238", rx: "14", fill: "#e1ead6", stroke: "#9bb08a", "stroke-width": "2" }),
...statuses.slice(0, ROOMS.length).flatMap((status, index) => {
const [x, y, width, height] = ROOMS[index];
const room = { x: String(x), y: String(y), width: String(width), height: String(height), rx: "8", stroke: "#9bb08a", fill: COLOR[status.kind] };
const table = { x: String(x + width - 44), y: String(y + height - 22), width: "34", height: "12", rx: "4", stroke: "#9bb08a", fill: "none" };
return [svg("rect", room), svg("rect", table)];
})),
...view.zones.slice(0, ROOMS.length).map((zone, index) => cell(zone, statuses[index], "room r" + index)));
const page = el("section", "plan",
el("div", "bar", step("day", "←", text.previousDay, -1), el("div", "now", dayOf(state.date)), step("day", "→", text.nextDay, 1)),
el("div", "bar", step("hour", "←", text.previousHour, -1), el("div", "now", state.hour + ":00"), step("hour", "→", text.nextHour, 1)),
el("p", "sum", view.zones.length === 0 ? text.noZones : vacant > 0 ? text.vacant(vacant) : text.none),
...(view.zones.length > 0 ? [map] : []),
...view.zones.slice(ROOMS.length).map((zone, index) => cell(zone, statuses[ROOMS.length + index], "row")));
// 動きを控える設定の人には、時間を流すボタンを出さない。
if (!view.reducedMotion) page.append(tap(el("div", "play", state.timer ? text.stop : text.play), "play", state.timer ? text.stop : text.play));
document.getElementById("before").replaceChildren(page);
};
draw();
niho.surface.onChange(draw);
niho.ui.onTap("day", ({ data }) => {
const { range } = niho.surface.get();
const next = shiftDay(state.date, Number(data["data-step"]));
if (next >= range.from && next < range.to) state.date = next;
draw();
});
niho.ui.onTap("hour", ({ data }) => {
state.hour = Math.max(FIRST_HOUR, Math.min(LAST_HOUR, state.hour + Number(data["data-step"])));
draw();
});
niho.ui.onTap("play", () => {
if (state.timer) { clearInterval(state.timer); state.timer = 0; }
else state.timer = setInterval(() => { state.hour = state.hour >= LAST_HOUR ? FIRST_HOUR : state.hour + 1; draw(); }, 600);
draw();
});
niho.ui.onTap("open", ({ data }) => niho.actions.request({ type: "openBooking", ref: data["data-ref"] }));
niho.ui.onTap("start", ({ data }) => niho.actions.request({ type: "startBooking", date: state.date, startHour: state.hour, endHour: state.hour + 1, zoneRef: data["data-zone"] }));
await niho.ready();
})();
```