so-web-components 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stefan Ziegler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ # so-web-components
2
+
3
+ Vanilla **TypeScript** Web Components + ein kleines **Design-Token**-Set (CSS Custom Properties),
4
+ abgeleitet aus dem Layout-Prinzip von so.ch.
5
+
6
+ ## Enthalten
7
+
8
+ - `src/styles/tokens.css` – Farben/Typografie/Container-Tokens
9
+ - Hintergrund: `#fff`
10
+ - Schriftfarbe: `rgb(47, 72, 88)`
11
+ - Schrift: `Frutiger, sans-serif`
12
+ - `src/components/so-header.ts` – `<so-header>` Web Component (Shadow DOM)
13
+ - `src/components/so-breadcrumb.ts` – `<so-breadcrumb>` Web Component (Shadow DOM)
14
+ - `src/demo/index.html` – Demo-Seite
15
+ - `tests/so-header.test.ts` – Tests (Jest + JSDOM)
16
+ - `tests/so-breadcrumb.test.ts` – Tests (Jest + JSDOM)
17
+
18
+ ## Voraussetzungen
19
+
20
+ - Node.js >= 18
21
+ - npm
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install
27
+ ```
28
+
29
+ ## Build
30
+
31
+ ```bash
32
+ npm run build
33
+ ```
34
+
35
+ Outputs:
36
+
37
+ - `dist/index.js` (ESM)
38
+ - `dist/index.d.ts`
39
+ - `dist/components/...`
40
+ - `dist/styles/tokens.css`
41
+ - `dist/styles/reset.css`
42
+ - `dist/demo/index.html`
43
+
44
+ ## Tests
45
+
46
+ ```bash
47
+ npm test
48
+ ```
49
+
50
+ ## Publish (npm)
51
+
52
+ ### Voraussetzungen
53
+
54
+ - npm Account
55
+ - **Automation Token** (Classic Tokens werden nicht mehr akzeptiert)
56
+ - GitHub Secret `NPM_TOKEN` im Repo hinterlegen (Automation Token)
57
+
58
+ > Optional: Alternativ kannst du **npm Trusted Publishing (OIDC)** aktivieren und dann ohne Token veröffentlichen.
59
+
60
+ ### Ablauf
61
+
62
+ 1) Änderungen auf `main` pushen (CI läuft).
63
+ 2) Version taggen (Semver) und Tag pushen → Publish-Workflow lädt auf npm.
64
+
65
+ ```bash
66
+ git tag v0.1.1
67
+ git push origin v0.1.1
68
+ ```
69
+
70
+ ## CDN Nutzung (nach npm Publish)
71
+
72
+ Nach dem Publish sind die Web Components z.B. über **unpkg** oder **jsDelivr** verfügbar:
73
+
74
+ ```html
75
+ <script type="module" src="https://unpkg.com/so-web-components@0.1.1/dist/index.js"></script>
76
+ ```
77
+
78
+ ```html
79
+ <script type="module" src="https://cdn.jsdelivr.net/npm/so-web-components@0.1.1/dist/index.js"></script>
80
+ ```
81
+
82
+ Optional ohne Versions-Pin:
83
+
84
+ ```html
85
+ <script type="module" src="https://unpkg.com/so-web-components/dist/index.js"></script>
86
+ ```
87
+
88
+ ```html
89
+ <script type="module" src="https://cdn.jsdelivr.net/npm/so-web-components/dist/index.js"></script>
90
+ ```
91
+
92
+ ## Dev / Demo starten
93
+
94
+ ### Live Reload (empfohlen)
95
+
96
+ ```bash
97
+ npm run dev:hot
98
+ ```
99
+
100
+ Das startet:
101
+
102
+ - TypeScript im Watch-Modus
103
+ - automatisches Kopieren von Demo/Styles nach `dist/`
104
+ - den Dev-Server mit Live-Reload
105
+
106
+ Dann im Browser öffnen:
107
+
108
+ - http://localhost:5173
109
+
110
+ ### Ohne Live Reload
111
+
112
+ > Wichtig: Der Dev-Server serviert aus `dist/`. Deshalb immer zuerst `npm run build` ausführen.
113
+
114
+ ```bash
115
+ npm run build
116
+ npm run dev
117
+ ```
118
+
119
+ Dann im Browser öffnen:
120
+
121
+ - http://localhost:5173
122
+
123
+ ## Verwendung
124
+
125
+ ### 1) Fonts / Tokens / Reset laden
126
+
127
+ ```html
128
+ <link rel="stylesheet" href="/dist/styles/reset.css">
129
+ <link rel="stylesheet" href="/dist/styles/fonts.css">
130
+ <link rel="stylesheet" href="/dist/styles/tokens.css">
131
+ ```
132
+
133
+ ### 2) Component laden und einsetzen
134
+
135
+ ```html
136
+ <script type="module" src="/dist/index.js"></script>
137
+
138
+ <so-header></so-header>
139
+ <so-breadcrumb></so-breadcrumb>
140
+ ```
141
+
142
+ ### 3) Navigation konfigurieren (optional)
143
+
144
+ `top-nav` und `section-nav` sind JSON-Arrays:
145
+
146
+ ```html
147
+ <so-header
148
+ top-nav='[{"label":"Regierung","href":"/regierung"},{"label":"Gerichte","href":"/gerichte"}]'
149
+ section-nav='[{"label":"Services","href":"/services"},{"label":"Verwaltung","href":"/verwaltung"}]'
150
+ active-section="Services"
151
+ logo-href="/"
152
+ site-name="Kanton Solothurn"
153
+ ></so-header>
154
+ ```
155
+
156
+ ## Generelle Informationen
157
+
158
+ - Alle Komponenten sind **Custom Elements** mit **Shadow DOM**.
159
+ - Konfiguration erfolgt über Attribute (meist JSON-Strings).
160
+ - Styling per CSS Custom Properties, die im Host-Kontext gesetzt werden können.
161
+
162
+ ## Komponenten
163
+
164
+ ### `<so-header>`
165
+
166
+ **Attribute**
167
+
168
+ - `top-nav`: JSON-Array aus `{ label, href }`
169
+ - `section-nav`: JSON-Array aus `{ label, href }`
170
+ - `active-section`: String
171
+ - `logo-href`: String
172
+ - `site-name`: String
173
+
174
+ **Events**
175
+
176
+ - `so-section-select` → wird ausgelöst, wenn ein Bereich (Services/Verwaltung) geklickt wird
177
+ `detail: { label, href }`
178
+
179
+ ### `<so-breadcrumb>`
180
+
181
+ **Beispiel**
182
+
183
+ ```html
184
+ <so-breadcrumb>
185
+ <so-breadcrumb-item href="https://so.ch">so.ch</so-breadcrumb-item>
186
+ <so-breadcrumb-item href="https://so.ch/verwaltung/">Verwaltung</so-breadcrumb-item>
187
+ <so-breadcrumb-item href="https://so.ch/verwaltung/bau-und-justizdepartement/">Bau- und Justizdepartement</so-breadcrumb-item>
188
+ <so-breadcrumb-item href="https://so.ch/verwaltung/bau-und-justizdepartement/amt-fuer-geoinformation/" isCurrentPage>
189
+ Amt für Geoinformation
190
+ </so-breadcrumb-item>
191
+ </so-breadcrumb>
192
+ ```
193
+
194
+ **Custom Properties**
195
+
196
+ - `--so-breadcrumb-padding`: Padding (Default `24px`)
197
+
198
+ ## Customizing
199
+
200
+ Einfach per CSS Custom Properties:
201
+
202
+ ```css
203
+ :root{
204
+ --so-bg: #fff;
205
+ --so-fg: rgb(47, 72, 88);
206
+
207
+ /* z.B. Contentbreite/Gutters anpassen */
208
+ --so-container-size-full: 120rem;
209
+ --so-container-padding: 1rem;
210
+ }
211
+ ```
212
+
213
+ > Hinweis: **Frutiger** muss auf dem System vorhanden sein (oder du bindest eine Webfont ein).
214
+
215
+ ## Lizenz
216
+
217
+ MIT (für dieses Beispielprojekt).
@@ -0,0 +1,12 @@
1
+ export declare class SoBreadcrumbItem extends HTMLElement {
2
+ }
3
+ export declare class SoBreadcrumb extends HTMLElement {
4
+ private root;
5
+ private observer;
6
+ constructor();
7
+ connectedCallback(): void;
8
+ disconnectedCallback(): void;
9
+ private getItems;
10
+ private render;
11
+ private styles;
12
+ }
@@ -0,0 +1,157 @@
1
+ const CHEVRON_SVG = `<svg class="chevron" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
2
+ <path d="m15.53 11.47-6-6c-.29-.29-.77-.29-1.06 0s-.29.77 0 1.06L13.94 12l-5.47 5.47c-.29.29-.29.77 0 1.06.15.15.34.22.53.22s.38-.07.53-.22l6-6c.29-.29.29-.77 0-1.06Z"/>
3
+ </svg>`;
4
+ function el(tag, cls) {
5
+ const n = document.createElement(tag);
6
+ if (cls)
7
+ n.className = cls;
8
+ return n;
9
+ }
10
+ function isCurrentPageAttribute(el) {
11
+ return el.hasAttribute("iscurrentpage") || el.hasAttribute("isCurrentPage");
12
+ }
13
+ export class SoBreadcrumbItem extends HTMLElement {
14
+ }
15
+ export class SoBreadcrumb extends HTMLElement {
16
+ constructor() {
17
+ super();
18
+ this.observer = null;
19
+ this.root = this.attachShadow({ mode: "open" });
20
+ }
21
+ connectedCallback() {
22
+ this.render();
23
+ this.observer = new MutationObserver(() => this.render());
24
+ this.observer.observe(this, {
25
+ childList: true,
26
+ subtree: true,
27
+ attributes: true,
28
+ characterData: true
29
+ });
30
+ }
31
+ disconnectedCallback() {
32
+ this.observer?.disconnect();
33
+ this.observer = null;
34
+ }
35
+ getItems() {
36
+ const nodes = Array.from(this.querySelectorAll("so-breadcrumb-item"));
37
+ const items = nodes
38
+ .map((node) => {
39
+ const label = (node.textContent ?? "").trim();
40
+ return {
41
+ label,
42
+ href: node.getAttribute("href"),
43
+ isCurrentPage: isCurrentPageAttribute(node)
44
+ };
45
+ })
46
+ .filter((item) => item.label.length > 0);
47
+ if (!items.length)
48
+ return [];
49
+ if (!items.some((item) => item.isCurrentPage)) {
50
+ items[items.length - 1].isCurrentPage = true;
51
+ }
52
+ return items;
53
+ }
54
+ render() {
55
+ this.root.innerHTML = "";
56
+ const styleEl = document.createElement("style");
57
+ styleEl.textContent = this.styles();
58
+ this.root.appendChild(styleEl);
59
+ const wrapper = el("nav", "so-breadcrumb");
60
+ wrapper.setAttribute("aria-label", "Breadcrumb");
61
+ const container = el("div", "so-breadcrumb-container");
62
+ const list = el("ol", "list");
63
+ const items = this.getItems();
64
+ items.forEach((item, index) => {
65
+ const isLast = index === items.length - 1;
66
+ const li = el("li", "item");
67
+ if (item.isCurrentPage)
68
+ li.classList.add("current");
69
+ if (item.isCurrentPage || !item.href) {
70
+ const labelEl = el("span", "label");
71
+ labelEl.textContent = item.label;
72
+ if (item.isCurrentPage) {
73
+ labelEl.setAttribute("aria-current", "page");
74
+ }
75
+ li.appendChild(labelEl);
76
+ }
77
+ else {
78
+ const labelEl = el("a");
79
+ labelEl.href = item.href;
80
+ labelEl.textContent = item.label;
81
+ li.appendChild(labelEl);
82
+ }
83
+ if (!isLast) {
84
+ li.insertAdjacentHTML("beforeend", CHEVRON_SVG);
85
+ }
86
+ list.appendChild(li);
87
+ });
88
+ container.appendChild(list);
89
+ wrapper.appendChild(container);
90
+ this.root.appendChild(wrapper);
91
+ }
92
+ styles() {
93
+ return `
94
+ :host{
95
+ display: block;
96
+ width: 100%;
97
+ font-family: var(--so-font-family, Frutiger, sans-serif);
98
+ }
99
+
100
+ .so-breadcrumb{
101
+ width: 100%;
102
+ color: var(--so-fg, rgb(47, 72, 88));
103
+ }
104
+
105
+ .so-breadcrumb-container{
106
+ width: 100%;
107
+ padding: var(--so-breadcrumb-padding, 24px);
108
+ }
109
+
110
+ .list{
111
+ list-style: none;
112
+ display: flex;
113
+ flex-wrap: wrap;
114
+ align-items: flex-end;
115
+ gap: 0.5rem;
116
+ padding: 0;
117
+ margin: 0;
118
+ font-size: 14px;
119
+ line-height: 1.4;
120
+ }
121
+
122
+ .item{
123
+ display: inline-flex;
124
+ align-items: flex-end;
125
+ gap: 0.5rem;
126
+ color: inherit;
127
+ }
128
+
129
+ .item a,
130
+ .item .label{
131
+ color: inherit;
132
+ text-decoration: none;
133
+ line-height: 1;
134
+ }
135
+
136
+ .item a:hover,
137
+ .item a:focus-visible{
138
+ color: #e01f26;
139
+ text-decoration: none;
140
+ }
141
+
142
+ .item.current,
143
+ .item.current .label,
144
+ .item.current a{
145
+ color: #e01f26;
146
+ }
147
+
148
+ .chevron{
149
+ width: 21px;
150
+ height: 21px;
151
+ fill: #e01f26;
152
+ flex: 0 0 auto;
153
+ display: block;
154
+ }
155
+ `;
156
+ }
157
+ }
@@ -0,0 +1,16 @@
1
+ export declare class SoHeader extends HTMLElement {
2
+ static observedAttributes: string[];
3
+ private root;
4
+ private topNav;
5
+ private sectionNav;
6
+ private activeSection;
7
+ private logoHref;
8
+ private siteName;
9
+ constructor();
10
+ attributeChangedCallback(): void;
11
+ private updateFromAttributes;
12
+ private bindEvents;
13
+ private toggleMobileMenu;
14
+ private render;
15
+ private styles;
16
+ }