@profitlich/template-toolkit 7.6.0 → 7.7.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.
@@ -80,6 +80,14 @@ export class MenuToggle {
80
80
  }
81
81
  });
82
82
 
83
+ // Der Button sagt Hilfstechnik an, ob das Menü offen ist (ARIA Authoring
84
+ // Practices, «Disclosure»). Verborgen wird das Menü weiter über das CSS an
85
+ // `data-menu-active`, nicht mit `hidden`, damit Projekte das Öffnen animieren können.
86
+ this.#menuButton.setAttribute('aria-expanded', 'false');
87
+ if (this.#menu.id) {
88
+ this.#menuButton.setAttribute('aria-controls', this.#menu.id);
89
+ }
90
+
83
91
  this.#setBodyAttribute('data-menu-active', 'false');
84
92
  this.#setBodyAttribute('data-menu-moving', 'false');
85
93
  this.#fixElement.setAttribute('data-menu-fixed', 'false');
@@ -102,65 +110,98 @@ export class MenuToggle {
102
110
  return MenuToggle.#instance;
103
111
  }
104
112
 
105
- #toggleMenu() {
113
+ /**
114
+ * Öffnet das Menü – wie ein Klick auf den Menü-Button, aber von anderer Stelle,
115
+ * etwa wenn ein Projekt das Menü über eigene Knöpfe öffnet. Ist es schon offen,
116
+ * geschieht nichts.
117
+ */
118
+ open() {
106
119
  if (this.isActive) {
107
- this.isActive = false;
108
- document.body.removeEventListener('click', this.#bodyClickHandler);
109
- window.removeEventListener('resize', this.#resizeHandler);
110
- this.#setBodyAttribute('data-menu-active', 'false');
111
- if (this.#lockScroll) {
112
- this.#fixElement.setAttribute('data-menu-fixed', 'false');
113
- if (this.#shiftElement) {
114
- this.#shiftElement.style.marginRight = '';
115
- this.#shiftElement.style.width = '';
116
- }
117
- if (this.#fixElementIsBody) {
118
- this.#fixElement.style.paddingRight = '';
119
- }
120
- this.#fixElement.style.top = '';
121
- window.scrollTo(0, this.#y);
120
+ return;
121
+ }
122
+ this.isActive = true;
123
+ this.#menuButton.setAttribute('aria-expanded', 'true');
124
+ document.body.addEventListener('click', this.#bodyClickHandler);
125
+ this.#setBodyAttribute('data-menu-active', 'true');
126
+ if (this.#lockScroll) {
127
+ window.addEventListener('resize', this.#resizeHandler);
128
+ this.#setBodyAttribute('data-menu-moving', 'true');
129
+ if (!this.#deferPositionFixed) {
130
+ this.#applyFix();
122
131
  }
123
- this.#toggleEscape(false);
124
- } else {
125
- this.isActive = true;
126
- document.body.addEventListener('click', this.#bodyClickHandler);
127
- this.#setBodyAttribute('data-menu-active', 'true');
128
- if (this.#lockScroll) {
129
- window.addEventListener('resize', this.#resizeHandler);
130
- this.#setBodyAttribute('data-menu-moving', 'true');
131
- if (!this.#deferPositionFixed) {
132
+ setTimeout(() => {
133
+ if (this.#deferPositionFixed) {
132
134
  this.#applyFix();
133
135
  }
134
- setTimeout(() => {
135
- if (this.#deferPositionFixed) {
136
- this.#applyFix();
137
- }
138
- if (this.#shiftElement) {
139
- const marginOriginal = parseFloat(window.getComputedStyle(this.#menuButton).marginRight);
140
- this.#shiftElement.style.marginRight = `${marginOriginal + this.#scrollbarWidth}px`;
141
- this.#adjustShiftElementWidth();
142
- }
143
- this.#setBodyAttribute('data-menu-moving', 'false');
144
- }, this.#shiftDelay);
136
+ if (this.#shiftElement) {
137
+ const marginOriginal = parseFloat(window.getComputedStyle(this.#menuButton).marginRight);
138
+ this.#shiftElement.style.marginRight = `${marginOriginal + this.#scrollbarWidth}px`;
139
+ this.#adjustShiftElementWidth();
140
+ }
141
+ this.#setBodyAttribute('data-menu-moving', 'false');
142
+ }, this.#shiftDelay);
143
+ }
144
+ this.#toggleEscape(true);
145
+ this.#dispatchStatus();
146
+ }
147
+
148
+ /**
149
+ * Schliesst das Menü und stellt die Scroll-Position wieder her. Ist es schon zu,
150
+ * geschieht nichts.
151
+ */
152
+ close() {
153
+ if (!this.isActive) {
154
+ return;
155
+ }
156
+ this.isActive = false;
157
+ this.#menuButton.setAttribute('aria-expanded', 'false');
158
+ document.body.removeEventListener('click', this.#bodyClickHandler);
159
+ window.removeEventListener('resize', this.#resizeHandler);
160
+ this.#setBodyAttribute('data-menu-active', 'false');
161
+ if (this.#lockScroll) {
162
+ this.#fixElement.setAttribute('data-menu-fixed', 'false');
163
+ if (this.#shiftElement) {
164
+ this.#shiftElement.style.marginRight = '';
165
+ this.#shiftElement.style.width = '';
166
+ }
167
+ if (this.#fixElementIsBody) {
168
+ this.#fixElement.style.paddingRight = '';
145
169
  }
146
- this.#toggleEscape(true);
170
+ this.#fixElement.style.top = '';
171
+ window.scrollTo(0, this.#y);
172
+ }
173
+ this.#toggleEscape(false);
174
+ this.#dispatchStatus();
175
+ }
176
+
177
+ #toggleMenu() {
178
+ if (this.isActive) {
179
+ this.close();
180
+ } else {
181
+ this.open();
147
182
  }
183
+ }
184
+
185
+ #dispatchStatus() {
148
186
  const event = new CustomEvent('eventMenuestatus', {
149
187
  detail: { menueStatus: this.isActive }
150
188
  });
151
189
  document.dispatchEvent(event);
152
190
  }
153
191
 
154
- // Scrollbar-Ausgleich nur nötig, wenn der Body fixiert wird –
155
- // bei anderem #fixElement bleibt die Seiten-Scrollbar bestehen.
192
+ // Ausgeglichen wird nur, was das Fixieren an Breite wirklich freigibt. Bleibt die
193
+ // Scrollbar stehen – `overflow-y: scroll` oder `scrollbar-gutter: stable` an `html`,
194
+ // oder ein anderes #fixElement als der Body –, ist das nichts; ein Ausgleich um die
195
+ // volle Scrollbar-Breite schöbe den Inhalt dann nach links.
156
196
  #applyFix() {
157
- this.#scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
197
+ const widthBefore = document.documentElement.clientWidth;
158
198
  this.#y = window.scrollY;
199
+ this.#fixElement.style.top = `-${this.#y}px`;
200
+ this.#fixElement.setAttribute('data-menu-fixed', 'true');
201
+ this.#scrollbarWidth = Math.max(0, document.documentElement.clientWidth - widthBefore);
159
202
  if (this.#fixElementIsBody) {
160
203
  this.#fixElement.style.paddingRight = `${this.#scrollbarWidth}px`;
161
204
  }
162
- this.#fixElement.style.top = `-${this.#y}px`;
163
- this.#fixElement.setAttribute('data-menu-fixed', 'true');
164
205
  if (!this.#fixElementIsBody) {
165
206
  // Bei nicht-body-Fix-Element bleibt der window-Scroll erhalten; ohne Reset
166
207
  // erscheint ein absolut positioniertes Menü um den vorherigen Scroll-Betrag verschoben.
@@ -1,7 +1,7 @@
1
1
  import GUI from 'lil-gui';
2
2
  import { canvasGridLines } from 'canvas-grid-lines';
3
3
  import { MediaQueries } from '../../utils/MediaQueries.js';
4
- import { gridColumnsTriple } from './gridColumns.js';
4
+ import { gridColumnsOptions } from './gridColumns.js';
5
5
  import './toolbar.scss';
6
6
 
7
7
  /**
@@ -149,14 +149,14 @@ export class Toolbar {
149
149
  const mode = GRID_MODES[this.#state.grid];
150
150
  if (!mode) return;
151
151
 
152
- const columns = gridColumnsTriple(this.#config, this.#mediaQueries.layout);
152
+ const columns = gridColumnsOptions(this.#config, this.#mediaQueries.layout);
153
153
  if (!columns) return;
154
154
 
155
155
  if (!this.#grid) {
156
156
  [this.#grid] = canvasGridLines.initGrid({
157
157
  targets: this.#gridElement,
158
158
  gridType: mode.gridType,
159
- columns,
159
+ ...columns,
160
160
  color: mode.color,
161
161
  lineWidth: 1,
162
162
  units: 'devicepixel',
@@ -164,12 +164,11 @@ export class Toolbar {
164
164
  return;
165
165
  }
166
166
 
167
- // Reihenfolge: erst die Spalten, dann die Rasterart. Der gridType-Setter
168
- // leitet sein Lückenmuster aus dem aktuellen columns-Wert ab, und der
169
- // muss nach einem Breakpoint-Wechsel schon der neue sein.
170
- this.#grid.columns = columns;
171
- this.#grid.gridType = mode.gridType;
172
- this.#grid.color = mode.color;
167
+ // In einem Schritt statt über einzelne Setter: Wechselt ein Breakpoint
168
+ // zwischen festem und mitwachsendem Gutter, hat `columns` eine andere
169
+ // Anzahl Werte, und jede Reihenfolge einzelner Zuweisungen liefe über
170
+ // einen ungültigen Zwischenstand.
171
+ this.#grid.configure({ ...columns, gridType: mode.gridType, color: mode.color });
173
172
  }
174
173
 
175
174
  #onLayoutChange = () => {
@@ -1,19 +1,31 @@
1
1
  /**
2
- * Rechnet die Spaltenkonfiguration eines Layouts in das Tripel um, das
3
- * `canvas-grid-lines` für die Rasterarten `columns` und `ribbons` erwartet:
4
- * `[total, band, gap]` in Rastereinheiten.
2
+ * Spaltenangaben für `canvas-grid-lines`, Rasterarten `columns` und `ribbons`.
3
+ * @typedef {Object} GridColumnsOptions
4
+ * @property {number|number[]} columns - Spaltenzahl bei festem Gutter, sonst das
5
+ * Tripel `[total, band, gap]` in Rastereinheiten.
6
+ * @property {number|null} fixedGap - Gutter in CSS-Pixeln, oder `null`, wenn er
7
+ * mit dem Layout mitwächst.
8
+ */
9
+
10
+ /**
11
+ * Rechnet die Spaltenkonfiguration eines Layouts in die Angaben um, die
12
+ * `canvas-grid-lines` für die Rasterarten `columns` und `ribbons` erwartet.
5
13
  *
6
- * Die Einheit ist der grösste gemeinsame Teiler von Spaltenbreite und Gutter —
7
- * aus einem Verhältnis wie 80 : 20 werden damit die ganzen Zahlen 4 : 1, die
8
- * das Paket als Wiederholungsmuster braucht. Beide Rasterarten teilen sich
9
- * dieselbe Kantenfolge: `columns` strichelt sie, `ribbons` füllt dazwischen.
14
+ * Welche Form sie haben, entscheidet `units` — dieselbe Angabe, nach der
15
+ * `size()` im SCSS rechnet:
16
+ *
17
+ * - `px`: Der Gutter ist bei jeder Fensterbreite gleich breit, die Spalten
18
+ * teilen sich den Rest. Das Raster bekommt die Spaltenzahl und den Gutter als
19
+ * festen Abstand.
20
+ * - `vw`: Spalten und Gutter wachsen gemeinsam; ihr Verhältnis ist bei jeder
21
+ * Breite dasselbe und geht als Tripel `[total, band, gap]` ans Raster.
10
22
  *
11
23
  * @param {Object} config - Inhalt von `src/config.json` des Projekts.
12
24
  * @param {string} layout - Layoutname, etwa `desktop`.
13
- * @returns {number[]|undefined} `[total, band, gap]`, oder `undefined`, wenn die
14
- * Angaben fehlen oder sich das Verhältnis nicht ganzzahlig ausdrücken lässt.
25
+ * @returns {GridColumnsOptions|undefined} `undefined`, wenn die Angaben fehlen
26
+ * oder kein brauchbares Raster ergeben.
15
27
  */
16
- export function gridColumnsTriple(config, layout) {
28
+ export function gridColumnsOptions(config, layout) {
17
29
  const width = config?.layouts?.[layout];
18
30
  const margins = config?.margins?.[layout];
19
31
  const gutter = config?.gutter?.[layout];
@@ -24,12 +36,22 @@ export function gridColumnsTriple(config, layout) {
24
36
  return undefined;
25
37
  }
26
38
 
39
+ if (config?.units?.[layout] === 'px') {
40
+ if (!Number.isInteger(count) || count <= 0 || !Number.isFinite(gutter) || gutter < 0) {
41
+ console.warn(`Dev-Toolbar: Layout "${layout}" ergibt keine brauchbare Spaltenaufteilung (Gutter ${gutter}, Spalten ${count}) — das Raster bleibt aus.`);
42
+ return undefined;
43
+ }
44
+ return { columns: count, fixedGap: gutter };
45
+ }
46
+
27
47
  // Die Spaltenbreite ist `zaehler / count` und oft kein ganzer Designpixel —
28
48
  // in `template-kirbycms` etwa 91,428…. Deshalb wird sie nie ausgerechnet:
29
49
  // Das Verhältnis Spalte zu Gutter ist `zaehler/count : gutter`, und mit
30
50
  // `count` erweitert wird daraus `zaehler : count · gutter`, also ein
31
51
  // Verhältnis zweier ganzer Zahlen. Gekürzt ergibt das exakt das gesuchte
32
- // Muster, ohne jede Rundung.
52
+ // Muster, ohne jede Rundung — der grösste gemeinsame Teiler macht aus
53
+ // 80 : 20 die ganzen Zahlen 4 : 1, die das Paket als Wiederholungsmuster
54
+ // braucht.
33
55
  const zaehler = width - margins.left - margins.right - (count - 1) * gutter;
34
56
 
35
57
  if (!Number.isInteger(zaehler) || !Number.isInteger(gutter) || !Number.isInteger(count) || zaehler <= 0) {
@@ -41,7 +63,7 @@ export function gridColumnsTriple(config, layout) {
41
63
  const band = zaehler / unit;
42
64
  const gap = (count * gutter) / unit;
43
65
 
44
- return [count * band + (count - 1) * gap, band, gap];
66
+ return { columns: [count * band + (count - 1) * gap, band, gap], fixedGap: null };
45
67
  }
46
68
 
47
69
  function greatestCommonDivisor(a, b) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profitlich/template-toolkit",
3
- "version": "7.6.0",
3
+ "version": "7.7.0",
4
4
  "description": "Shared SCSS layout system, JS utilities, components and build scripts for profitlich template repos",
5
5
  "type": "module",
6
6
  "sass": "scss/forward.scss",
@@ -45,7 +45,7 @@
45
45
  ],
46
46
  "dependencies": {
47
47
  "basic-ftp": "^6.2.2",
48
- "canvas-grid-lines": "^10.5.1",
48
+ "canvas-grid-lines": "^10.6.0",
49
49
  "chokidar": "^5.0.0",
50
50
  "cli-progress": "^3.12.0",
51
51
  "dotenv": "^18.0.6",