@cogniplay/logic-games-sheet 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -2
- package/font/generated/roboto-regular.d.ts +2 -0
- package/font/generated/roboto-regular.d.ts.map +1 -0
- package/font/generated/roboto-regular.js +4 -0
- package/font/generated/roboto-regular.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/limits.d.ts +51 -0
- package/limits.d.ts.map +1 -0
- package/limits.js +92 -0
- package/limits.js.map +1 -0
- package/package.json +27 -4
- package/pdfmake-augment.d.ts +8 -0
- package/pdfmake-augment.d.ts.map +1 -0
- package/pdfmake-augment.js +2 -0
- package/pdfmake-augment.js.map +1 -0
- package/pdfmake.d.ts +12 -0
- package/pdfmake.d.ts.map +1 -0
- package/pdfmake.js +34 -0
- package/pdfmake.js.map +1 -0
- package/sheet.d.ts +21 -0
- package/sheet.d.ts.map +1 -0
- package/sheet.js +323 -0
- package/sheet.js.map +1 -0
- package/src/font/OFL.txt +93 -0
- package/src/font/README.md +7 -0
- package/src/font/generated/roboto-regular.ts +4 -0
- package/src/index.ts +16 -0
- package/src/limits.ts +131 -0
- package/src/pdfmake-augment.ts +15 -0
- package/src/pdfmake.ts +37 -0
- package/src/sheet.ts +449 -0
- package/src/types.ts +38 -0
- package/src/wording.ts +10 -0
- package/types.d.ts +34 -0
- package/types.d.ts.map +1 -0
- package/types.js +2 -0
- package/types.js.map +1 -0
- package/wording.d.ts +9 -0
- package/wording.d.ts.map +1 -0
- package/wording.js +9 -0
- package/wording.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,118 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cogniplay/logic-games-sheet
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Makes the child's printed sheet for a logic-game instance: a one-page PDF with the board at the exact size of the kit's pieces, the variant's title, the instance's instruction and the instance's code. For a Line Counts board it also shows the pieces to place, and for a Fair Shares board the pieces to share. The same function serves the content repository's play-test prints in Node and, later, the `/edu` print button in the browser.
|
|
4
|
+
|
|
5
|
+
It builds on `@cogniplay/logic-games`, which draws the board, and on pdfmake 0.3, which lays the page out and embeds the font. The designs are in `docs/superpowers/specs/2026-11-05-logic-games-sheet-design.md`, `docs/superpowers/specs/2026-11-10-line-counts-drawing-design.md` and `docs/superpowers/specs/2026-11-11-fair-shares-drawing-design.md`.
|
|
6
|
+
|
|
7
|
+
## Installing
|
|
8
|
+
|
|
9
|
+
The package is published on npm. The renderer is a peer dependency, so install the two together, each at an exact version:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add --save-exact @cogniplay/logic-games @cogniplay/logic-games-sheet
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The sheet asks for the renderer's minor version it was built with (`^0.1.0` takes any 0.1 patch); pdfmake comes as its own dependency. The package holds the built JavaScript, its types, the source under `src/` and this README.
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { renderSheet } from "@cogniplay/logic-games-sheet";
|
|
21
|
+
|
|
22
|
+
const bytes = await renderSheet({
|
|
23
|
+
instance: file.data, // the instance's data, as the renderer takes it
|
|
24
|
+
code: "AMO-03-0005",
|
|
25
|
+
instruction: file.texts.hu.instruction, // what the child is told: one plain line
|
|
26
|
+
language: "hu", // the sheet's fixed wording: "hu" or "en"
|
|
27
|
+
paper: "A4", // or "Letter"
|
|
28
|
+
cellSizeMm: 16, // the kit's cell size; 16 by default
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
In Node, write the bytes to a file:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
writeFileSync("amo-03-0005.pdf", bytes);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In the browser, open them as a blob:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const url = URL.createObjectURL(new Blob([bytes], { type: "application/pdf" }));
|
|
42
|
+
window.open(url);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`marks`, as in the renderer, passes drawings for mark kinds through to it.
|
|
46
|
+
|
|
47
|
+
### Several sheets in one PDF
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { renderSheets } from "@cogniplay/logic-games-sheet";
|
|
51
|
+
|
|
52
|
+
const bytes = await renderSheets([first, second, third], { title: "Tuesday, year 3" });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`renderSheets` takes a list of the same options and puts each sheet on a page of its own, in the order given, exactly as it prints alone: its own paper, turned its own way, with its own title, code and QR code. Each sheet is a pdfmake section, and `renderSheet` makes its one sheet the same way, so a sheet is the same alone or among others. `title` is the document's, which a viewer names a saved file by; there is none without it. A sheet that can't print fails the whole with a `SheetError`: its `code` is that sheet's code, its message is the code before the reason, and its `cause` is the sheet's own error, so a caller can name the board. An empty list is an error rather than an empty PDF. `renderSheet`'s errors are the sheet's own, without a code, since the caller knows which sheet it asked for. A hundred sheets of mixed games and orientations take about a second and a quarter in a browser on a recent laptop and make a PDF of under 1 MB.
|
|
56
|
+
|
|
57
|
+
### What the sheet holds
|
|
58
|
+
|
|
59
|
+
One page, A4 or Letter, with 10 mm margins. From the top: the variant's title, when one is given; the instruction; the board, drawn by the renderer at the cell size and centred in the room left; and at the bottom the code with a label and, when a link is given, a QR code to the instance's page. The page is portrait when the board fits upright and landscape otherwise.
|
|
60
|
+
|
|
61
|
+
The pieces on the board print as ghosts, thin outlines with light stripes, since the child covers them with the real pieces. A Line Counts board's clues print beside it, and its pieces to place print under it at half scale, as tiles in the kit's colours or in grey: they say which pieces to take, and the child matches them by shape. A Fair Shares board's grids print at true size, as many side by side as fit, with its pieces to share above them at half scale in the same way. Nothing on its sheet marks a place for a piece to leave out, and nothing prints the shares' sizes or the difference to reach.
|
|
62
|
+
|
|
63
|
+
The PDF states its sizes in physical units and asks viewers not to scale it (`PrintScaling: None`). For viewers that ignore that, Edu tells the teacher to print at actual size.
|
|
64
|
+
|
|
65
|
+
### The limits
|
|
66
|
+
|
|
67
|
+
A sheet holds a footprint of at most 190×219 mm upright or 259×150 mm sideways, the same numbers the content repository's validator and the backend's import assume. For Amoeba the footprint is the board. For Line Counts it is:
|
|
68
|
+
|
|
69
|
+
- width = (columns + 1 if any row has a clue) × cell size
|
|
70
|
+
- height = (rows + 1 if any column has a clue + 2 if any piece is to place) × cell size
|
|
71
|
+
|
|
72
|
+
At 16 mm, with clues both ways and pieces to place, that allows boards up to 10×10 upright and 15×6 sideways. The two cells for the pieces assume they lie in one row at half scale and none is more than three cells on its shorter side, which holds for the Square Blocks and Square Mino kits.
|
|
73
|
+
|
|
74
|
+
For Fair Shares the grids lie in rows of some number across, with one cell between two grids across and down. With `n` grids across and `r = ceil(shares / n)` rows:
|
|
75
|
+
|
|
76
|
+
- width = (n × columns + n − 1) × cell size
|
|
77
|
+
- height = (r × rows + r − 1 + 2 if any piece is to share) × cell size
|
|
78
|
+
|
|
79
|
+
The board fits when some `n` from 1 to `shares` gives a footprint within a limit. The sheet takes the most across that fits upright, or failing that the most across that fits sideways; `gridsAcross(instance, 16)` says which. At 16 mm, two grids of 5×5 are 176×112 mm, and three grids of 5×5 with pieces to share are two above one, 176×208 mm, upright. Three grids of 6×6 fit no sheet. Nothing is counted for a piece left out: the sheet draws no place for it.
|
|
80
|
+
|
|
81
|
+
To tell ahead of time:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { boardLimitsMm, footprintMm, sheetOrientation } from "@cogniplay/logic-games-sheet";
|
|
85
|
+
|
|
86
|
+
const size = footprintMm(instance, 16); // what the board takes on a sheet, in mm
|
|
87
|
+
sheetOrientation(size); // "portrait", "landscape", or undefined if it fits neither way
|
|
88
|
+
boardLimitsMm; // { upright: { width: 190, height: 219 }, sideways: { width: 259, height: 150 } }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`boardSizeMm(instance, 16)` still gives the cells' bounding box alone.
|
|
92
|
+
|
|
93
|
+
`renderSheet` throws in these cases, and draws anything else it is given:
|
|
94
|
+
|
|
95
|
+
- a board that fits neither way: `A 192×224 mm board fits no sheet: at most 190×219 mm upright or 259×150 mm sideways`. A Line Counts board's message also gives its footprint, and a Fair Shares board's reads `3 grids of 96×96 mm, 208×240 mm with the pieces to share, fit no sheet: …`;
|
|
96
|
+
- a piece or a mark so far off the board that the drawing, which the renderer widens to hold it, no longer fits the way up the cells chose: `A piece or a mark lies off the 96×96 mm board: the drawing is 258×98 mm, which fits no sheet upright`;
|
|
97
|
+
- a Line Counts board whose pieces to place need more than the two cells counted for them, such as a second row: `The clues and the pieces to place don't fit beside the 160×160 mm board: the drawing is 178×238 mm, which fits no sheet upright`;
|
|
98
|
+
- a Fair Shares board in the same case: `The pieces to share don't fit beside the 3 grids of 80×80 mm: the drawing is 178×238 mm, which fits no sheet upright`;
|
|
99
|
+
- an instruction so long it leaves the board no room: `The instruction (1200 characters) is too long for a board this tall`. Nothing caps the instruction in the format; the content repository's validator runs the sheet for every instance and reports this failure, so the sheet fails here and never shrinks or clips the text.
|
|
100
|
+
|
|
101
|
+
A `paper` or `language` outside the type, from a caller without TypeScript, throws too: `Unknown paper "a4": "A4" or "Letter"`. The renderer's own errors, for an instance it can't draw, pass through unchanged.
|
|
102
|
+
|
|
103
|
+
### The fixed wording
|
|
104
|
+
|
|
105
|
+
| Language | The code's label |
|
|
106
|
+
| -------- | ---------------- |
|
|
107
|
+
| `hu` | `Feladat:` |
|
|
108
|
+
| `en` | `Puzzle:` |
|
|
109
|
+
|
|
110
|
+
The Hungarian is a first draft; a Hungarian speaker reviews it in the pull request that changes it. It lives in `src/wording.ts`.
|
|
111
|
+
|
|
112
|
+
## The font
|
|
113
|
+
|
|
114
|
+
Roboto Regular, the file pdfmake ships, under the SIL Open Font License 1.1; see `src/font/README.md` and `src/font/OFL.txt`. It is embedded as a base64 module so it loads the same way in Node and in the browser, and only the glyphs a sheet uses go into the PDF. Regenerate the module after a pdfmake upgrade with `node scripts/font.mjs` from this directory.
|
|
115
|
+
|
|
116
|
+
## Releasing
|
|
117
|
+
|
|
118
|
+
As for the renderer: a pull request that changes what the package holds raises `version` in `package.json`, and the Pipeline publishes it from `main`. A new renderer version needs a new sheet version as well, even with no change to the sheet, because the sheet's peer range is built from the renderer's version; the checks ask for both.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roboto-regular.d.ts","sourceRoot":"","sources":["../../src/font/generated/roboto-regular.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,EAAE,MAC8q5M,CAAC"}
|