# はじめかた

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()` を呼ぶ。
