profitlich-template-toolkit 0.3.0 → 0.4.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/dev/Dev.js ADDED
@@ -0,0 +1,18 @@
1
+ import { Toolbar } from './toolbar/Toolbar.js';
2
+
3
+ class Dev {
4
+ devToolbar;
5
+
6
+ constructor() {
7
+ this.devToolbar = new Toolbar();
8
+ console.info('Dev initialized.');
9
+ }
10
+ }
11
+
12
+ let dev;
13
+
14
+ document.addEventListener('DOMContentLoaded', () => {
15
+ dev = new Dev();
16
+ });
17
+
18
+ export { dev };
@@ -0,0 +1,102 @@
1
+ import GUI from 'lil-gui';
2
+ import { MediaQueries } from '../../utils/MediaQueries.js';
3
+ import './toolbar.scss';
4
+
5
+ export class Toolbar {
6
+ #mediaQueries = MediaQueries.getInstance();
7
+ #gui;
8
+ #state;
9
+ #pictureElements;
10
+
11
+ constructor() {
12
+ // State aus localStorage laden
13
+ const saved = localStorage.getItem('devTools');
14
+ this.#state = saved
15
+ ? JSON.parse(saved)
16
+ : { visible: false, grid: 'aus', imageSize: false };
17
+
18
+ // Grid-Overlay DOM-Element erstellen
19
+ const gridOverlay = document.createElement('div');
20
+ gridOverlay.classList.add('dev-toolbar__grid');
21
+ document.body.prepend(gridOverlay);
22
+
23
+ // Picture-Elemente sammeln
24
+ this.#pictureElements = document.getElementsByTagName('picture');
25
+
26
+ // lil-gui initialisieren
27
+ this.#gui = new GUI({ title: this.#getViewportText() });
28
+
29
+ this.#gui.add(this.#state, 'grid', ['aus', 'lines', 'ribbons'])
30
+ .name('Grid')
31
+ .onChange(() => this.#onStateChange());
32
+
33
+ this.#gui.add(this.#state, 'imageSize')
34
+ .name('Bildgrössen')
35
+ .onChange(() => this.#onStateChange());
36
+
37
+ // State anwenden
38
+ this.#applyState();
39
+
40
+ // Panel ein-/ausblenden
41
+ if (!this.#state.visible) {
42
+ this.#gui.hide();
43
+ }
44
+
45
+ // Event-Listener
46
+ window.addEventListener('resize', this.#onResize);
47
+ document.addEventListener('keydown', this.#handleKeyDown);
48
+ }
49
+
50
+ #getViewportText() {
51
+ return `${this.#mediaQueries.layout} @ ${window.innerWidth}×${window.innerHeight}`;
52
+ }
53
+
54
+ #onStateChange() {
55
+ this.#applyState();
56
+ this.#saveState();
57
+ }
58
+
59
+ #applyState() {
60
+ const gridActive = this.#state.grid !== 'aus';
61
+ document.body.setAttribute('data-dev', String(gridActive));
62
+ document.body.setAttribute('data-dev-grid', this.#state.grid);
63
+ this.#updateImageSize();
64
+ }
65
+
66
+ #saveState() {
67
+ localStorage.setItem('devTools', JSON.stringify(this.#state));
68
+ }
69
+
70
+ #updateImageSize() {
71
+ if (!this.#pictureElements) return;
72
+ const pictures = Array.from(this.#pictureElements);
73
+ if (this.#state.imageSize) {
74
+ const windowWidth = window.innerWidth;
75
+ pictures.forEach((picture) => {
76
+ picture.setAttribute('data-size', `${Math.round(picture.offsetWidth / windowWidth * 100)}vw`);
77
+ });
78
+ } else {
79
+ pictures.forEach((picture) => {
80
+ picture.setAttribute('data-size', '');
81
+ });
82
+ }
83
+ }
84
+
85
+ #onResize = () => {
86
+ this.#gui.title(this.#getViewportText());
87
+ this.#updateImageSize();
88
+ }
89
+
90
+ #handleKeyDown = (event) => {
91
+ if (event.key === 'Control') {
92
+ event.preventDefault();
93
+ this.#state.visible = !this.#state.visible;
94
+ if (this.#state.visible) {
95
+ this.#gui.show();
96
+ } else {
97
+ this.#gui.hide();
98
+ }
99
+ this.#saveState();
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,102 @@
1
+ @use "sass:map";
2
+ @use "../../scss/forward" as *;
3
+
4
+ // grid
5
+ $color--dev-grid: rgba(0, 0, 255, 0.5);
6
+ $color--dev-grid-ribbons: rgba(191, 255, 254, 0.5);
7
+ $color--dev-grid-center: rgba(0, 0, 0, 0.2);
8
+
9
+
10
+ @mixin dev-toolbar-grid($layout, $columns, $gutter, $margin-left, $margin-right) {
11
+
12
+ $gutter: size($layout, $gutter);
13
+ $margin-left: size($layout, $margin-left);
14
+ $margin-right: size($layout, $margin-right);
15
+
16
+ body[data-dev='true'] {
17
+ .dev-toolbar__grid::after {
18
+ // the grid is made through repition
19
+ // 'important' because background settings are more specific than the grid settings
20
+ background-size: calc((100% - ($columns * $gutter)) * calc(1 / $columns) + $gutter) 1px !important;
21
+ margin: 0 ($margin-right - calc($gutter / 2)) 0 ($margin-left - calc($gutter / 2));
22
+ // The grid is calculated starting from the middle
23
+ // Thats why its necessary to add the half of the column gap to the left and right side
24
+ width: calc(100% - $margin-right + calc($gutter / 2) - $margin-left + calc($gutter / 2));
25
+ }
26
+ }
27
+
28
+ body[data-dev='true'][data-dev-grid="lines"] {
29
+ .dev-toolbar__grid::after {
30
+ background:
31
+ // center of the column spacing
32
+ linear-gradient(90deg, transparent 0.5px, transparent 0.5px) 0 0,
33
+ // Left column line
34
+ // position: from the column spacing center to the right by half a column spacing
35
+ linear-gradient(90deg, $color--dev-grid 0.5px, transparent 0.5px) calc($gutter / 2) 0,
36
+ // right column line
37
+ linear-gradient(90deg, $color--dev-grid 0.5px, transparent 0.5px) calc($gutter / 2 * -1) 0;
38
+ }
39
+ }
40
+
41
+ body[data-dev='true'][data-dev-grid="ribbons"] {
42
+ .dev-toolbar__grid::after {
43
+ background:
44
+ // ceft column ribbon
45
+ // position: from the column spacing center to the right by half a column spacing
46
+ linear-gradient(90deg, $color--dev-grid-ribbons calc(100% - $gutter), transparent 0.5px) calc($gutter / 2) 0,
47
+ }
48
+ }
49
+ }
50
+
51
+ // lil-gui z-index
52
+ .lil-gui.root {
53
+ z-index: 9999999;
54
+ }
55
+
56
+ .dev-toolbar__grid {
57
+ display: none;
58
+ width: 100%;
59
+ height: 100%;
60
+ left: 0;
61
+ pointer-events: none;
62
+ position: fixed;
63
+ top: 0;
64
+
65
+ body[data-dev='true'] & {
66
+ display: block;
67
+ }
68
+
69
+ body[data-dev-grid='lines'] & {
70
+ z-index: 9999999;
71
+ }
72
+
73
+ &::after {
74
+ content: "";
75
+ height: 100%;
76
+ left: 0;
77
+ position: absolute;
78
+ top: 0;
79
+ }
80
+ }
81
+
82
+ @each $layout, $breite in $layouts {
83
+ @include mediaquery($layout) using ($layout) {
84
+ @include dev-toolbar-grid($layout, map.get($columns, $layout), map.get($gutter, $layout), map.get(map.get($margins, $layout), 'left'), map.get(map.get($margins, $layout), 'right'));
85
+ }
86
+ }
87
+
88
+ picture {
89
+ position: relative;
90
+
91
+ &::before{
92
+ content: attr(data-size);
93
+ font-family: sans-serif;
94
+ position: absolute;
95
+ top: 10px;
96
+ left: 10px;
97
+ color: white;
98
+ font-size: 20px;
99
+ text-shadow: 0 0 10px black;
100
+ z-index: 10;
101
+ }
102
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "profitlich-template-toolkit",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Shared SCSS layout system, JS utilities and components for profitlich template repos",
5
5
  "type": "module",
6
6
  "exports": {
7
+ "./dev": "./dev/Dev.js",
7
8
  "./dev/toolbar": "./dev/toolbar/Toolbar.js",
8
9
  "./scss/forward": "./scss/forward.scss",
9
10
  "./scss/core/layout": "./scss/core/layout.scss",
@@ -16,6 +17,7 @@
16
17
  "./components/mux-player/MuxPlayer": "./components/mux-player/MuxPlayer.js"
17
18
  },
18
19
  "files": [
20
+ "dev/",
19
21
  "scss/",
20
22
  "utils/",
21
23
  "components/"
@@ -33,4 +35,4 @@
33
35
  "url": "https://github.com/profitlich-ch/profitlich-template-toolkit"
34
36
  },
35
37
  "license": "MIT"
36
- }
38
+ }