@lintje/slides 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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ EUROPEAN UNION PUBLIC LICENCE v. 1.2
2
+ EUPL © the European Union 2007, 2016
3
+
4
+ This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the
5
+ terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such
6
+ use is covered by a right of the copyright holder of the Work).
7
+ The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following
8
+ notice immediately following the copyright notice for the Work:
9
+ Licensed under the EUPL
10
+ or has expressed by any other means his willingness to license under the EUPL.
11
+
12
+ 1.Definitions
13
+ In this Licence, the following terms have the following meaning:
14
+ — ‘The Licence’:this Licence.
15
+ — ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available
16
+ as Source Code and also as Executable Code as the case may be.
17
+ — ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or
18
+ modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work
19
+ required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in
20
+ the country mentioned in Article 15.
21
+ — ‘The Work’:the Original Work or its Derivative Works.
22
+ — ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and
23
+ modify.
24
+ — ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by
25
+ a computer as a program.
26
+ — ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence.
27
+ — ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to
28
+ the creation of a Derivative Work.
29
+ — ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the
30
+ Licence.
31
+ — ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating,
32
+ transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential
33
+ functionalities at the disposal of any other natural or legal person.
34
+
35
+ 2.Scope of the rights granted by the Licence
36
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for
37
+ the duration of copyright vested in the Original Work:
38
+ — use the Work in any circumstance and for all usage,
39
+ — reproduce the Work,
40
+ — modify the Work, and make Derivative Works based upon the Work,
41
+ — communicate to the public, including the right to make available or display the Work or copies thereof to the public
42
+ and perform publicly, as the case may be, the Work,
43
+ — distribute the Work or copies thereof,
44
+ — lend and rent the Work or copies thereof,
45
+ — sublicense rights in the Work or copies thereof.
46
+ Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the
47
+ applicable law permits so.
48
+ In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed
49
+ by law in order to make effective the licence of the economic rights here above listed.
50
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the
51
+ extent necessary to make use of the rights granted on the Work under this Licence.
52
+
53
+ 3.Communication of the Source Code
54
+ The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as
55
+ Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with
56
+ each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to
57
+ the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to
58
+ distribute or communicate the Work.
59
+
60
+ 4.Limitations on copyright
61
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the
62
+ exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations
63
+ thereto.
64
+
65
+ 5.Obligations of the Licensee
66
+ The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those
67
+ obligations are the following:
68
+
69
+ Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to
70
+ the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the
71
+ Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work
72
+ to carry prominent notices stating that the Work has been modified and the date of modification.
73
+
74
+ Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this
75
+ Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless
76
+ the Original Work is expressly distributed only under this version of the Licence — for example by communicating
77
+ ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the
78
+ Work or Derivative Work that alter or restrict the terms of the Licence.
79
+
80
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both
81
+ the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done
82
+ under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed
83
+ in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with
84
+ his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
85
+
86
+ Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide
87
+ a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available
88
+ for as long as the Licensee continues to distribute or communicate the Work.
89
+ Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names
90
+ of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
91
+ reproducing the content of the copyright notice.
92
+
93
+ 6.Chain of Authorship
94
+ The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or
95
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
96
+ Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or
97
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
98
+ Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions
99
+ to the Work, under the terms of this Licence.
100
+
101
+ 7.Disclaimer of Warranty
102
+ The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work
103
+ and may therefore contain defects or ‘bugs’ inherent to this type of development.
104
+ For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind
105
+ concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or
106
+ errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this
107
+ Licence.
108
+ This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
109
+
110
+ 8.Disclaimer of Liability
111
+ Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be
112
+ liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the
113
+ Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss
114
+ of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However,
115
+ the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
116
+
117
+ 9.Additional agreements
118
+ While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services
119
+ consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole
120
+ responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify,
121
+ defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by
122
+ the fact You have accepted any warranty or additional liability.
123
+
124
+ 10.Acceptance of the Licence
125
+ The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window
126
+ displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of
127
+ applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms
128
+ and conditions.
129
+ Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You
130
+ by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution
131
+ or Communication by You of the Work or copies thereof.
132
+
133
+ 11.Information to the public
134
+ In case of any Distribution or Communication of the Work by means of electronic communication by You (for example,
135
+ by offering to download the Work from a remote location) the distribution channel or media (for example, a website)
136
+ must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence
137
+ and the way it may be accessible, concluded, stored and reproduced by the Licensee.
138
+
139
+ 12.Termination of the Licence
140
+ The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms
141
+ of the Licence.
142
+ Such a termination will not terminate the licences of any person who has received the Work from the Licensee under
143
+ the Licence, provided such persons remain in full compliance with the Licence.
144
+
145
+ 13.Miscellaneous
146
+ Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the
147
+ Work.
148
+ If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or
149
+ enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid
150
+ and enforceable.
151
+ The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of
152
+ the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence.
153
+ New versions of the Licence will be published with a unique version number.
154
+ All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take
155
+ advantage of the linguistic version of their choice.
156
+
157
+ 14.Jurisdiction
158
+ Without prejudice to specific agreement between parties,
159
+ — any litigation resulting from the interpretation of this License, arising between the European Union institutions,
160
+ bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice
161
+ of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
162
+ — any litigation arising between other parties and resulting from the interpretation of this License, will be subject to
163
+ the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
164
+
165
+ 15.Applicable Law
166
+ Without prejudice to specific agreement between parties,
167
+ — this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat,
168
+ resides or has his registered office,
169
+ — this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside
170
+ a European Union Member State.
171
+
172
+
173
+ Appendix
174
+
175
+ ‘Compatible Licences’ according to Article 5 EUPL are:
176
+ — GNU General Public License (GPL) v. 2, v. 3
177
+ — GNU Affero General Public License (AGPL) v. 3
178
+ — Open Software License (OSL) v. 2.1, v. 3.0
179
+ — Eclipse Public License (EPL) v. 1.0
180
+ — CeCILL v. 2.0, v. 2.1
181
+ — Mozilla Public Licence (MPL) v. 2
182
+ — GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
183
+ — Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
184
+ — European Union Public Licence (EUPL) v. 1.1, v. 1.2
185
+ — Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+).
186
+
187
+ The European Commission may update this Appendix to later versions of the above licences without producing
188
+ a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the
189
+ covered Source Code from exclusive appropriation.
190
+ All other changes or additions to this Appendix require the production of a new EUPL version.
package/README.md CHANGED
@@ -1,3 +1,152 @@
1
- # Temporary Holding Version
1
+ # @lintje/slides
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Presentaties in HTML met [Lintje](https://github.com/h11t-labs/lintje), in de nieuwe
4
+ Rijkshuisstijl. Een presentatie is één HTML-bestand. Elke dia kiest een van dertig indelingen en
5
+ vult die met tekst, foto's en data. De opmaak komt uit de indeling, dus een mens en een agent
6
+ maken dezelfde dia's. Je presenteert in de browser en exporteert naar pdf, in licht en donker.
7
+
8
+ De dertig indelingen staan in vijf ondergronden: foto, licht vlak, blauwe band, vol blauw en half
9
+ beeld. De skill in [`skills/lintje-slides/`](skills/lintje-slides/SKILL.md) beschrijft ze
10
+ allemaal, met hun velden en wanneer je welke kiest.
11
+ [`examples/begrijpelijke-brieven.html`](examples/begrijpelijke-brieven.html) gebruikt elke
12
+ indeling één keer.
13
+
14
+ ## Installeren
15
+
16
+ ```bash
17
+ npm install --save-dev @lintje/slides
18
+ npx playwright install chromium # eenmalig, voor de controle en de pdf
19
+ ```
20
+
21
+ Het pakket brengt zijn eigen versie van Lintje mee. Start de opdrachten in de map van je project,
22
+ waar `node_modules/` staat.
23
+
24
+ ## Een presentatie maken
25
+
26
+ Kopieer het voorbeeld, `node_modules/@lintje/slides/examples/begrijpelijke-brieven.html`, naar
27
+ je project, houd de dia's die je nodig hebt en vervang hun inhoud. Twee regels in de `<head>`
28
+ laden het pakket:
29
+
30
+ ```html
31
+ <link rel="stylesheet" href="/node_modules/@lintje/slides/src/slides.css" />
32
+ <script type="module" src="/node_modules/@lintje/slides/src/slides.js"></script>
33
+ ```
34
+
35
+ Een dia ziet er zo uit:
36
+
37
+ ```html
38
+ <section class="slide" data-layout="band-list" data-chapter="1 Waarom">
39
+ <h1>Een brief die niet begrepen wordt, kost twee keer</h1>
40
+ <p data-field="intro">Elke vraag die binnenkomt, is werk dat de brief had kunnen voorkomen.</p>
41
+ <div data-field="points">
42
+ <ul>
43
+ <li>Wie de brief niet snapt, belt, mailt of komt langs.</li>
44
+ <li>Op taalniveau B1 lezen de meeste mensen een brief in één keer.</li>
45
+ </ul>
46
+ </div>
47
+ </section>
48
+ ```
49
+
50
+ De voet, het embleem, de nummers en de opsommingstekens zet `slides.js` erbij.
51
+
52
+ ## Met een AI-assistent
53
+
54
+ Het pakket brengt een skill mee, `skills/lintje-slides/`: de werkwijze van verhaallijn tot pdf,
55
+ welke indeling bij welke boodschap past, goed gebruik van tekst, cijfers, grafieken en foto's, en
56
+ de velden van elke indeling. Kopieer de map naar de skills-map van je assistent; bij Claude Code
57
+ is dat `.claude/skills/` van je project:
58
+
59
+ ```bash
60
+ mkdir -p .claude/skills && cp -R node_modules/@lintje/slides/skills/lintje-slides .claude/skills/
61
+ ```
62
+
63
+ Vraag daarna gewoon om een presentatie. Een assistent zonder skills wijs je de weg met een regel
64
+ in je eigen `AGENTS.md`: "Volg voor een presentatie
65
+ `node_modules/@lintje/slides/skills/lintje-slides/SKILL.md`."
66
+
67
+ ## Bekijken, controleren en exporteren
68
+
69
+ ```bash
70
+ npx lintje-slides serve # een server op poort 5190, met een link per deck
71
+ npx lintje-slides check decks/brieven.html # meldt wat niet past
72
+ npx lintje-slides check decks/brieven.html --images # en zet een png per dia in out/brieven/
73
+ npx lintje-slides pdf decks/brieven.html # out/brieven.pdf
74
+ npx lintje-slides pdf decks/brieven.html --dark # out/brieven-dark.pdf
75
+ ```
76
+
77
+ Dubbelklik een deck niet: via `file://` laadt de browser de scripts niet. Zonder pad nemen de
78
+ opdrachten elk deck in de map en eronder: elk `.html`-bestand met `<section class="slide">`,
79
+ buiten `node_modules/` en `out/`. Een andere server die de map van het project serveert, werkt
80
+ ook; `lintje-slides serve` levert altijd de versie van Lintje die bij het pakket hoort.
81
+
82
+ De controle meldt een onbekende indeling of veld, een ontbrekend veld, te veel woorden of punten,
83
+ een foto zonder alt-tekst, opmaak in de inhoud, en tekst die niet in zijn vak past. Een deck met
84
+ meldingen krijgt geen pdf.
85
+
86
+ In de browser zet `?mode=dark` het deck donker, `?theme=defensie` probeert een ander thema dan het
87
+ deck zelf noemt (`data-theme`), en `?check` toont de meldingen van de controle op de dia's.
88
+
89
+ ## Presenteren
90
+
91
+ Onderaan in het midden staan knoppen voor de vorige dia, de volgende dia, licht of donker, het
92
+ overzicht van alle dia's en volledig scherm. Ze faden in als je de muis beweegt en faden langzamer
93
+ uit als hij even stilstaat, als je bladert met de toetsen of een clicker, en kort nadat het deck
94
+ opent. In de pdf staan ze nooit. In het overzicht staan alle dia's klein naast elkaar, met hun
95
+ nummer; de dia waar je bent heeft een rand en de rest is gedimd: klik er een aan, of kies met de
96
+ pijltoetsen en Enter. Met het toetsenbord gaat het zo:
97
+
98
+ | toets | wat er gebeurt |
99
+ |---|---|
100
+ | → ↓ spatie PageDown | volgende dia |
101
+ | ← ↑ shift+spatie PageUp | vorige dia |
102
+ | Home / End | eerste / laatste dia |
103
+ | F | volledig scherm aan of uit |
104
+ | O | overzicht van alle dia's; Escape of O sluit het |
105
+ | D | licht of donker; de keuze komt in de URL (`?mode=dark`) |
106
+
107
+ Het nummer van de dia staat in de URL (`#3`). Herlaad je de pagina of deel je de link, dan kom je
108
+ op dezelfde dia uit.
109
+
110
+ ## Hoe het werkt
111
+
112
+ - `src/layouts.js` noemt de indelingen en hun velden. De controle en de catalogus van de skill
113
+ lezen hem.
114
+ - `src/slides.css` tekent de indelingen. Elke indeling is een grid over het vlak van 1280 × 720:
115
+ een langere titel duwt wat eronder staat omlaag. De kleuren zijn tokens van Lintje, dus het
116
+ thema en de donkere modus komen uit Lintje.
117
+ - `src/slides.js` schaalt de dia naar het scherm, bladert, zet de voet en het embleem en
118
+ controleert elke dia.
119
+ - `lintje-slides` (`bin/` en `cli/`) serveert het project, en opent elk deck in Chromium voor de
120
+ controle en de pdf.
121
+
122
+ ## Wat afwijkt van Lintje
123
+
124
+ `src/slides.css` noemt alleen tokens van Lintje voor kleur, ruimte tussen tekst en de hoeken. De
125
+ controle van Lintje (`node node_modules/lintje/dist-elements/skills/lintje/check.mjs
126
+ node_modules/lintje/dist-elements/tokens.json src/slides.css`) meldt toch zeventien plekken. Die
127
+ staan er met reden:
128
+
129
+ - **Plaatsen op het vlak**: de voet op 684 px, de witte rand van 24 en 48 px, de marge van 72 px,
130
+ het vlak van de stappen vanaf 845 px, de kolommen van de planning. Een dia is een vast vlak van
131
+ 1280 × 720 en geen pagina; deze maten komen uit het ontwerpcanvas.
132
+ - **Uitlijning**: het grote aanhalingsteken staat waar het canvas het zet.
133
+ - **`--slide-scale`** is de schaal waarmee `slides.js` de dia op het scherm past.
134
+ - **Het overzicht**: `slides.js` zet het aantal kolommen en de verkleining
135
+ (`--slide-overview-columns`, `--slide-overview-zoom`), en marges van 1280 en 720 px maal die
136
+ verkleining trekken de kleine dia's tegen elkaar.
137
+ - **Letters in punten**: een dia heeft een eigen schaal (titel 32 pt, tekst 18 pt), want hij wordt
138
+ van een afstand gelezen. Lintje's tekststappen zijn voor een scherm op armlengte.
139
+
140
+ De foto's in het voorbeeld zijn vrij te gebruiken (CC0, van Wikimedia Commons); de bronnen staan
141
+ in [`examples/photos/SOURCES.md`](examples/photos/SOURCES.md). Zet er voor echt gebruik foto's
142
+ uit de beeldbank van je organisatie in. De cijfers in het voorbeeld zijn fictief.
143
+
144
+ ## Meewerken
145
+
146
+ Hoe je aan het pakket werkt en hoe een release gaat, staat in
147
+ [`CONTRIBUTING.md`](CONTRIBUTING.md). Wat er per versie veranderde, staat in
148
+ [`CHANGELOG.md`](CHANGELOG.md).
149
+
150
+ ## Licentie
151
+
152
+ [EUPL-1.2](LICENSE).
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import { findDecks, serve, urlOf } from '../cli/server.mjs'
3
+
4
+ const usage = `lintje-slides <opdracht> [deck.html …]
5
+
6
+ serve start de server op poort 5190 (PORT=… voor een andere)
7
+ check [--images] meldt wat niet past; --images zet een png per dia in out/<deck>/
8
+ pdf zet elk deck zonder meldingen in out/<deck>.pdf
9
+
10
+ --dark bij check en pdf: de donkere versie
11
+ Zonder deck: elk .html-bestand met <section class="slide"> in deze map en eronder.`
12
+
13
+ const [command, ...rest] = process.argv.slice(2)
14
+ const flags = new Set(rest.filter((arg) => arg.startsWith('--')))
15
+ const names = rest.filter((arg) => !arg.startsWith('--'))
16
+ const known = { serve: [], check: ['--images', '--dark'], pdf: ['--dark'] }
17
+
18
+ if (!(command in known)) {
19
+ console.log(usage)
20
+ process.exit(command && !['help', '--help', '-h'].includes(command) ? 2 : 0)
21
+ }
22
+ for (const flag of flags) {
23
+ if (!known[command].includes(flag)) {
24
+ console.error(`${flag} hoort niet bij ${command}\n\n${usage}`)
25
+ process.exit(2)
26
+ }
27
+ }
28
+
29
+ const decks = await findDecks(names)
30
+ if (command === 'serve') {
31
+ const server = await serve()
32
+ const { port } = server.address()
33
+ for (const deck of decks) console.log(`http://127.0.0.1:${port}${urlOf(deck)}`)
34
+ } else if (command === 'check') {
35
+ const { check } = await import('../cli/check.mjs')
36
+ const ok = await check(decks, { images: flags.has('--images'), dark: flags.has('--dark') })
37
+ process.exit(ok ? 0 : 1)
38
+ } else {
39
+ const { pdf } = await import('../cli/pdf.mjs')
40
+ const ok = await pdf(decks, { dark: flags.has('--dark') })
41
+ process.exit(ok ? 0 : 1)
42
+ }
@@ -0,0 +1,51 @@
1
+ // Opens each deck in Chromium, for the check and the PDF. Playwright loads only here, so serve
2
+ // works without it.
3
+ import { basename } from 'node:path'
4
+ import { serve, urlOf } from './server.mjs'
5
+
6
+ export async function eachDeck(decks, { dark }, visit) {
7
+ let chromium
8
+ try {
9
+ ;({ chromium } = await import('playwright'))
10
+ } catch {
11
+ console.error('Playwright ontbreekt: npm install --save-dev playwright && npx playwright install chromium')
12
+ process.exit(1)
13
+ }
14
+ const server = await serve(0)
15
+ const { port } = server.address()
16
+ const browser = await chromium.launch().catch((error) => {
17
+ server.close()
18
+ console.error(`Chromium start niet (${error.message.split('\n')[0]}); eenmalig: npx playwright install chromium`)
19
+ process.exit(1)
20
+ })
21
+ let failed = false
22
+ try {
23
+ for (const deck of decks) {
24
+ const name = basename(deck).replace(/\.html$/, '')
25
+ // Reduced motion: slides and charts stand at once, as the check and the PDF want them.
26
+ const page = await browser.newPage({ viewport: { width: 1280, height: 720 }, reducedMotion: 'reduce' })
27
+ page.on('pageerror', (error) => {
28
+ failed = true
29
+ console.error(`${deck}: fout in de pagina, vaak de data van een grafiek die niet de vorm van zijn soort heeft (${error.message})`)
30
+ })
31
+ await page.goto(`http://127.0.0.1:${port}${urlOf(deck)}?mode=${dark ? 'dark' : 'light'}`, { waitUntil: 'networkidle' })
32
+ const ready = await page.waitForSelector('html[data-slides-ready]', { timeout: 15000 }).catch(() => null)
33
+ if (!ready) {
34
+ failed = true
35
+ console.error(`${deck}: laadt niet als deck; staan de twee regels van @lintje/slides in de <head>?`)
36
+ } else {
37
+ const findings = await page.evaluate(() => window.slidesCheck())
38
+ if ((await visit({ deck, name, page, findings })) === false) failed = true
39
+ }
40
+ await page.close()
41
+ }
42
+ } finally {
43
+ await browser.close()
44
+ server.close()
45
+ }
46
+ return !failed
47
+ }
48
+
49
+ export function printFindings(deck, findings) {
50
+ for (const { slide, layout, message } of findings) console.log(` dia ${slide} (${layout}): ${message}`)
51
+ }
package/cli/check.mjs ADDED
@@ -0,0 +1,28 @@
1
+ // Checks each deck against its layouts and lists what does not fit. With images, it also writes
2
+ // a PNG per slide to out/<deck>/, to look at.
3
+ import { mkdir } from 'node:fs/promises'
4
+ import { eachDeck, printFindings } from './browser.mjs'
5
+
6
+ export function check(decks, { images = false, dark = false } = {}) {
7
+ return eachDeck(decks, { dark }, async ({ deck, name, page, findings }) => {
8
+ const count = await page.locator('.slide').count()
9
+ if (findings.length) {
10
+ console.log(`${deck}: ${findings.length} ${findings.length === 1 ? 'melding' : 'meldingen'}`)
11
+ printFindings(deck, findings)
12
+ } else {
13
+ console.log(`${deck}: ${count} dia's, in orde`)
14
+ }
15
+ if (images) {
16
+ const dir = `out/${name}${dark ? '-dark' : ''}`
17
+ await mkdir(dir, { recursive: true })
18
+ await page.addStyleTag({ content: '.slides-nav { display: none }' })
19
+ for (let number = 1; number <= count; number++) {
20
+ await page.evaluate((n) => (location.hash = String(n)), number)
21
+ await page.waitForTimeout(150)
22
+ await page.screenshot({ path: `${dir}/${String(number).padStart(2, '0')}.png` })
23
+ }
24
+ console.log(` beelden in ${dir}/`)
25
+ }
26
+ return findings.length === 0
27
+ })
28
+ }
package/cli/pdf.mjs ADDED
@@ -0,0 +1,24 @@
1
+ // Writes each deck to out/<deck>.pdf, one page per slide, after the check: a deck with findings
2
+ // gets no PDF. Dark writes the dark deck to out/<deck>-dark.pdf.
3
+ import { mkdir } from 'node:fs/promises'
4
+ import { eachDeck, printFindings } from './browser.mjs'
5
+
6
+ export async function pdf(decks, { dark = false } = {}) {
7
+ await mkdir('out', { recursive: true })
8
+ return eachDeck(decks, { dark }, async ({ deck, name, page, findings }) => {
9
+ if (findings.length) {
10
+ console.log(`${deck}: geen pdf, eerst ${findings.length === 1 ? 'deze melding' : `deze ${findings.length} meldingen`} oplossen`)
11
+ printFindings(deck, findings)
12
+ return false
13
+ }
14
+ // Lintje keeps paper light; this PDF is the slides as the screen shows them, dark included.
15
+ await page.emulateMedia({ media: 'screen' })
16
+ await page.evaluate(() => document.documentElement.classList.add('slides-pdf'))
17
+ // Every slide is shown now: a chart measures its new box before it is printed.
18
+ await page.waitForTimeout(500)
19
+ const file = `out/${name}${dark ? '-dark' : ''}.pdf`
20
+ await page.pdf({ path: file, preferCSSPageSize: true, printBackground: true })
21
+ console.log(file)
22
+ return true
23
+ })
24
+ }
package/cli/server.mjs ADDED
@@ -0,0 +1,105 @@
1
+ // A static server over the project the command runs in: module scripts do not load over file://.
2
+ // /node_modules/@lintje/slides/ and /node_modules/lintje/ always serve the copies this command was
3
+ // installed with, wherever npm put them, so a deck and its scripts load one Lintje.
4
+ import { createServer } from 'node:http'
5
+ import { readdir, readFile, stat } from 'node:fs/promises'
6
+ import { createRequire } from 'node:module'
7
+ import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path'
8
+ import { fileURLToPath } from 'node:url'
9
+
10
+ export const root = process.cwd()
11
+ const own = fileURLToPath(new URL('..', import.meta.url))
12
+ const lintje = dirname(createRequire(import.meta.url).resolve('lintje/package.json'))
13
+ const mounts = [
14
+ ['/node_modules/@lintje/slides/', own],
15
+ ['/node_modules/lintje/', lintje],
16
+ ['/', root],
17
+ ]
18
+ const types = {
19
+ '.html': 'text/html; charset=utf-8',
20
+ '.js': 'text/javascript',
21
+ '.mjs': 'text/javascript',
22
+ '.css': 'text/css',
23
+ '.json': 'application/json',
24
+ '.svg': 'image/svg+xml',
25
+ '.woff2': 'font/woff2',
26
+ '.png': 'image/png',
27
+ '.jpg': 'image/jpeg',
28
+ '.jpeg': 'image/jpeg',
29
+ '.webp': 'image/webp',
30
+ }
31
+
32
+ function fileFor(pathname) {
33
+ const [prefix, base] = mounts.find(([prefix]) => pathname.startsWith(prefix))
34
+ const file = resolve(base, `.${pathname.slice(prefix.length - 1)}`)
35
+ return file === base || file.startsWith(base.endsWith(sep) ? base : base + sep) ? file : null
36
+ }
37
+
38
+ export function serve(port = Number(process.env.PORT ?? 5190)) {
39
+ const server = createServer(async (request, response) => {
40
+ let pathname = decodeURIComponent(new URL(request.url, 'http://x').pathname)
41
+ if (pathname.endsWith('/')) pathname += 'index.html'
42
+ const file = fileFor(pathname)
43
+ try {
44
+ if (!file) throw new Error('outside')
45
+ const body = await readFile(file)
46
+ response.writeHead(200, { 'content-type': types[extname(file)] ?? 'application/octet-stream' })
47
+ response.end(body)
48
+ } catch {
49
+ response.writeHead(404).end('Niet gevonden')
50
+ }
51
+ })
52
+ return new Promise((done, fail) => {
53
+ server.once('error', fail)
54
+ server.listen(port, '127.0.0.1', () => done(server))
55
+ })
56
+ }
57
+
58
+ /** The URL path of a deck, from its path relative to the project. */
59
+ export function urlOf(deck) {
60
+ return `/${deck.split(sep).map(encodeURIComponent).join('/')}`
61
+ }
62
+
63
+ const skip = new Set(['node_modules', 'out'])
64
+
65
+ async function walk(dir, found) {
66
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
67
+ if (entry.name.startsWith('.') || skip.has(entry.name)) continue
68
+ const path = join(dir, entry.name)
69
+ if (entry.isDirectory()) await walk(path, found)
70
+ else if (entry.name.endsWith('.html') && (await readFile(path, 'utf8')).includes('class="slide"')) found.push(path)
71
+ }
72
+ return found
73
+ }
74
+
75
+ // A deck is a path, or the name of a deck in the project. Without one, every deck in the
76
+ // project: each .html file with a <section class="slide">, outside node_modules/ and out/.
77
+ export async function findDecks(names = []) {
78
+ const all = async () => (await walk(root, [])).map((path) => relative(root, path)).sort()
79
+ if (!names.length) {
80
+ const decks = await all()
81
+ if (!decks.length) fail('geen deck gevonden: geef het pad van een .html-bestand')
82
+ return decks
83
+ }
84
+ let known
85
+ const decks = []
86
+ for (const name of names) {
87
+ const path = resolve(root, name)
88
+ if (await stat(path).then((s) => s.isFile(), () => false)) {
89
+ if (relative(root, path).startsWith('..')) fail(`${name} staat buiten deze map; start lintje-slides in de map van het project`)
90
+ decks.push(relative(root, path))
91
+ continue
92
+ }
93
+ known ??= await all()
94
+ const file = basename(name).replace(/(\.html)?$/, '.html')
95
+ const deck = known.find((path) => basename(path) === file)
96
+ if (!deck) fail(`${name} bestaat niet, en geen deck in deze map heet ${file}`)
97
+ decks.push(deck)
98
+ }
99
+ return decks
100
+ }
101
+
102
+ function fail(message) {
103
+ console.error(message)
104
+ process.exit(1)
105
+ }