# 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 の章にあるものだけにし、値は文字列か整数にします。
