summaryrefslogtreecommitdiff
path: root/web/src/index.ts
blob: fbbf37c8fe501395c73d65b464d0d0086c453eee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Ratio from "./math/Ratio";
import { Cell, Doc, Grid } from "./types";

function defaultDoc(): Doc {
  const defaultCells: Cell[] = Array.from({ length: 16 }, () => ({
    widthRatio: new Ratio(1, 16),
  }));

  return {
    grids: [
      {
        id: window.crypto.randomUUID(),
        baseCellSize: 48,
        baseCellWidthRatio: new Ratio(1, 16),
        parts: [
          {
            rows: Array.from({ length: 4 }, () => ({
              cells: [...defaultCells],
            })),
          },
        ],
      },
    ],
  };
}

export default class Notive {
  doc: Doc = defaultDoc();
  gridsById = Object.fromEntries(this.doc.grids.map((grid) => [grid.id, grid]));

  getGrid(id: string): Grid | undefined {
    return this.gridsById[id];
  }
}

window.notive = new Notive();