mypgs 1.5.0 → 1.5.1

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 CHANGED
@@ -12,40 +12,35 @@ La libreria nasce come base di design system: layout, spacing, colori, bottoni,
12
12
  - `dist/css/`: CSS compilato.
13
13
  - `dist/javascript/`: bundle JavaScript compilato.
14
14
  - `dist/index.d.ts`: dichiarazioni TypeScript esportate dal pacchetto.
15
- - `AI_GUIDELINES.md`: guida operativa per AI/Codex.
16
- - `AI_GUIDELINES_EN.md`: versione inglese della guida.
15
+ - `AGENTS.md`: guida operativa per AI.
17
16
 
18
17
  ## Installazione
19
18
 
20
- Da registry npm:
19
+ Da registry **npm**:
21
20
 
22
21
  ```bash
23
22
  npm install mypgs
24
23
  ```
25
24
 
26
- ## Uso rapido
27
-
28
- Importa JavaScript e CSS compilato nell'entrypoint del progetto:
25
+ ### JavaScript
29
26
 
30
27
  ```js
31
28
  import "mypgs";
32
- import "mypgs/style.css";
33
29
  ```
34
30
 
35
31
  Se ti serve accedere direttamente all'helper:
36
32
 
37
33
  ```js
38
34
  import { pgs } from "mypgs";
39
- import "mypgs/style.css";
40
35
  ```
41
36
 
42
- In progetti React/TSX con Vite, abilita i tipi JSX e il plugin che converte `pgsHtml` in `pgs`:
37
+ **React/TSX con Vite:**
43
38
 
44
- ```ts
45
- import "mypgs/react";
46
- ```
39
+ Configura il plugin che converte `pgsHtml` in `pgs`:
47
40
 
48
41
  ```ts
42
+ // vite.config.ts
43
+ import { defineConfig } from 'vite'
49
44
  import react from "@vitejs/plugin-react";
50
45
  import pgsVite from "mypgs/vite-plugin-pgs";
51
46
 
@@ -54,19 +49,7 @@ export default {
54
49
  };
55
50
  ```
56
51
 
57
- Markup minimo consigliato:
58
-
59
- ```html
60
- <html lang="it" pgs="htmlBase initP">
61
- <body pgs="bodyBase bodyImg bodyText bodyHeading">
62
- <main pgs="main"></main>
63
- </body>
64
- </html>
65
- ```
66
-
67
- `initP` e' importante: molti layout, componenti e pattern SCSS sono definiti sotto `[pgs~=initP]`.
68
-
69
- ## Uso SCSS sorgente
52
+ ### SCSS
70
53
 
71
54
  Se il progetto vuole compilare un CSS unico, importa gli SCSS sorgenti:
72
55
 
@@ -82,356 +65,22 @@ Se servono solo i mixin:
82
65
  @use "../../node_modules/mypgs/assets/scss/mixin/mixin.scss" as * ;
83
66
  ```
84
67
 
85
- La libreria espone molte custom properties da preferire agli hardcode, per esempio:
86
-
87
- ```scss
88
- :root {
89
- --color-primary: #5c7d6f;
90
- --padding: 30px;
91
- --gap-texts: 1rem;
92
- --gap-elements: 4rem;
93
- --border-radius: 4.5rem;
94
- --border-radius-input: 2.25rem;
95
- }
96
- ```
97
-
98
- Override consigliato:
68
+ ### Markup
99
69
 
100
- ```scss
101
- #danger-action {
102
- --button-background: var(--color-error);
103
- --button-color: var(--color-whiteFixed);
104
- }
105
- ```
106
-
107
- Evita di riscrivere da zero padding, gap, border-radius o colori se esiste gia' una variabile o un token PGS adatto.
108
-
109
- ## Il sistema `pgs`
110
-
111
- Il markup usa token separati da spazio dentro l'attributo `pgs`:
70
+ `initP` e' importante: tutti i layout, componenti e pattern SCSS sono definiti sotto `[pgs~=initP]`.
112
71
 
113
72
  ```html
114
- <button pgs="button buttonStrong" type="button">Salva</button>
115
- <section pgs="section flexColumnElements"></section>
116
- ```
117
-
118
- Gli stessi token collegano HTML, SCSS e JavaScript.
119
-
120
- ### Helper JavaScript
121
-
122
- `pgs(root)` permette di cercare e modificare token PGS senza scrivere selettori manuali:
123
-
124
- ```js
125
- const modal = pgs(document).querySelector("modal");
126
-
127
- pgs(modal).contains("modal");
128
- pgs(modal).add("custom-token");
129
- pgs(modal).remove("custom-token");
130
- pgs(modal).toggle("custom-token", true);
131
- ```
132
-
133
- Stati runtime:
134
-
135
- ```js
136
- pgs(modal).state.add("open");
137
- pgs(modal).state.toggle("open", false);
138
- pgs(modal).state.contains("open");
139
- ```
140
-
141
- Opzioni:
142
-
143
- ```js
144
- pgs(modal).option.contains("history");
145
- pgs(modal).option.getValueBrackets("containerID");
146
- ```
147
-
148
- Esempio markup con opzioni:
149
-
150
- ```html
151
- <div pgs="modal" pgs-option="containerID[modal-container]"></div>
152
- <div pgs="slides" pgs-option="singleScroll shadowDesktop"></div>
153
- ```
154
-
155
- ## JavaScript inizializzato automaticamente
156
-
157
- Importando `mypgs`, l'entrypoint inizializza:
158
-
159
- - helper globale `pgs`
160
- - dark mode
161
- - gestione object SVG
162
- - accordion
163
- - dropdown
164
- - menu
165
- - modali
166
- - slides
167
- - steps
168
- - step tabs
169
- - notifiche
170
- - header
171
- - cookie consent
172
-
173
- I componenti inizializzati usano `WeakMap` interne per esporre API di istanza.
174
-
175
- ## API dei moduli
176
-
177
- I moduli principali sono registrati in `assets/javascript/_imports.js` in due modi.
178
-
179
- ### Registro diretto
180
-
181
- Serve per usare i moduli direttamente da `pgs`:
182
-
183
- ```js
184
- pgs.registerModules({
185
- accordion: PGS_accordion,
186
- dropdown: PGS_dropdown,
187
- menu: PGS_menu,
188
- modal: PGS_modal,
189
- notification: PGS_notification,
190
- slides: PGS_slides,
191
- stepTabs: PGS_stepTabs,
192
- steps: PGS_steps,
193
- formValidate: PGS_formValidate,
194
- scrollHorizontal: PGS_scrollHorizontal,
195
- });
196
- ```
197
-
198
- Uso consigliato:
199
-
200
- ```js
201
- pgs.notification.toast.success("Salvato");
202
- pgs.modal.api(modalEl)?.open();
203
- pgs.dropdown.api(dropdownEl)?.close();
204
- pgs.slides.api(slidesEl)?.next();
205
- ```
206
-
207
- Shortcut disponibili dopo `import "mypgs"`:
208
-
209
- - `pgs.accordion`
210
- - `pgs.dropdown`
211
- - `pgs.menu`
212
- - `pgs.modal`
213
- - `pgs.notification`
214
- - `pgs.slides`
215
- - `pgs.stepTabs`
216
- - `pgs.steps`
217
- - `pgs.formValidate`
218
- - `pgs.scrollHorizontal`
219
-
220
- ## Struttura dei moduli componente
221
-
222
- I componenti con istanze seguono questo schema:
223
-
224
- ```js
225
- export const PGS_modal = {
226
- init: PGS_modal_init,
227
- api: PGS_modal_api
228
- };
229
- ```
230
-
231
- - `PGS_name`: nome ufficiale del modulo per il registro legacy.
232
- - `init`: inizializza o reinizializza markup, utile dopo contenuti dinamici.
233
- - `api`: recupera l'API di una singola istanza gia' inizializzata.
234
-
235
- Esempio:
236
-
237
- ```js
238
- pgs.modal.init();
239
- pgs.modal.init(container);
240
- pgs.modal.api(modalEl)?.open();
241
- ```
242
-
243
- `PGS_notification` e' un caso diverso: funziona piu' come service/helper e espone `alert`, `toast` e `trigger`.
244
-
245
- ## Componenti e markup
246
-
247
- I template completi sono in `templates/html/components/`, `templates/html/patterns/` e `templates/html/layout/`. Usa quei file come sorgente di riferimento prima di creare markup nuovo.
248
-
249
- ## Componenti disponibili
250
-
251
- Layout e utility:
252
-
253
- - `main`
254
- - `section`
255
- - `sectionFull`
256
- - `sectionMax`
257
- - `sectionNoPadding`
258
- - `container`
259
- - `pageShell`
260
- - `aside`
261
- - `flexColumn`
262
- - `flexColumnTexts`
263
- - `flexColumnElements`
264
- - `flexColumnSections`
265
- - `flexRow`
266
- - `grid-*`
267
- - `gapTexts`
268
- - `gapElements`
269
- - `gapSections`
270
- - `card`
271
- - `boxtext`
272
-
273
- Componenti:
274
-
275
- - `button`
276
- - `buttonStrong`
277
- - `buttonIcon`
278
- - `buttonMini`
279
- - `buttonBig`
280
- - `buttonClose`
281
- - `form`
282
- - `input`
283
- - `textarea`
284
- - `select`
285
- - `toggle`
286
- - `checkbox`
287
- - `radio`
288
- - `dropdown`
289
- - `tooltip`
290
- - `modal`
291
- - `accordion`
292
- - `slides`
293
- - `steps`
294
- - `stepTabs`
295
- - `notification`
296
- - `toast`
297
- - `table`
298
- - `breadcrumb`
299
- - `searchbar`
300
- - `logo`
301
- - `menuHorizontal`
302
- - `menuVertical`
303
- - `menuFooter`
304
-
305
- Pattern:
306
-
307
- - `header`
308
- - `footer`
309
- - `cookieConsent`
310
-
311
- ## Export npm
312
-
313
- Il pacchetto espone:
314
-
315
- ```json
316
- {
317
- ".": {
318
- "types": "./dist/index.d.ts",
319
- "import": "./assets/javascript/index.js",
320
- "default": "./dist/javascript/index.js"
321
- },
322
- "./style.css": "./dist/css/index.css",
323
- "./style.min.css": "./dist/css/index.min.css",
324
- "./react": {
325
- "types": "./react.d.ts",
326
- "import": "./react.js",
327
- "default": "./react.js"
328
- },
329
- "./vite-plugin-pgs": {
330
- "types": "./plugins/vite-plugin-pgs.d.ts",
331
- "import": "./plugins/vite-plugin-pgs.js",
332
- "default": "./plugins/vite-plugin-pgs.js"
333
- }
334
- }
335
- ```
336
-
337
- Uso compilato:
338
-
339
- ```js
340
- import "mypgs";
341
- import "mypgs/style.css";
342
- ```
343
-
344
- Uso sorgente SCSS:
345
-
346
- ```scss
347
- @use "sass:meta";
348
- @use "../../node_modules/mypgs/assets/scss/mixin/mixin.scss" as * ;
349
- @include meta.load-css("../../node_modules/mypgs/assets/scss/index.scss");
350
- ```
351
-
352
- ## Sviluppo
353
-
354
- Build una tantum:
355
-
356
- ```bash
357
- npm run start
358
- ```
359
-
360
- Build in watch mode:
361
-
362
- ```bash
363
- npm run "start watch"
364
- ```
365
-
366
- Creare un pacchetto locale:
367
-
368
- ```bash
369
- npm pack
370
- ```
371
-
372
- Flusso consigliato quando modifichi la libreria:
373
-
374
- 1. modifica i sorgenti in `assets/`;
375
- 2. aggiorna template o documentazione se cambia il modo d'uso;
376
- 3. ricompila con `npm run start`;
377
- 4. verifica `dist/`;
378
- 5. crea il pacchetto con `npm pack`;
379
- 6. installa il `.tgz` nel progetto che consuma la libreria.
380
-
381
- Nota: se la build Webpack fallisce, non modificare manualmente `dist/javascript` come sorgente primaria. Sistema la toolchain e rigenera gli asset compilati.
382
-
383
- ## Aggiungere un nuovo modulo
384
-
385
- Esempio componente:
386
-
387
- ```js
388
- export function PGS_myComponent_init(root = document) {
389
- pgs(root).querySelectorAll("myComponent").forEach((element) => {
390
- // init
391
- });
392
- }
393
-
394
- export function PGS_myComponent_api(element) {
395
- // return instance API
396
- }
397
-
398
- export const PGS_myComponent = {
399
- PGS_name: "PGS_myComponent",
400
- init: PGS_myComponent_init,
401
- api: PGS_myComponent_api
402
- };
403
- ```
404
-
405
- Registrazione in `assets/javascript/_imports.js`:
406
-
407
- ```js
408
- import { PGS_myComponent } from "./components/_myComponent.js";
409
-
410
- pgs.registerImport({
411
- PGS_myComponent,
412
- });
413
-
414
- pgs.registerModules({
415
- myComponent: PGS_myComponent,
416
- });
417
- ```
418
-
419
- Uso:
420
-
421
- ```js
422
- pgs.myComponent.init();
423
- pgs.myComponent.api(element);
73
+ <html lang="it" pgs="htmlBase initP">
74
+ <body pgs="bodyBase bodyImg bodyText bodyHeading">
75
+ <main pgs="main"></main>
76
+ </body>
77
+ </html>
424
78
  ```
425
79
 
426
- ## Convenzioni
80
+ ## Documentazione
427
81
 
428
- - Usa `pgs` come prima scelta per markup, layout, componenti e comportamenti.
429
- - Mantieni coerenti i token tra template, SCSS e JS.
430
- - Usa `pgs-state` per stati runtime.
431
- - Usa `pgs-option` per opzioni dichiarative.
432
- - Preferisci custom properties e mixin a CSS hardcoded.
433
- - Non duplicare componenti gia' presenti nella libreria.
434
- - Non inventare API: verifica i sorgenti in `assets/javascript/`.
435
- - Mantieni in `mypgs` solo stili e comportamenti riutilizzabili.
436
- - Mantieni nel progetto finale le personalizzazioni specifiche del progetto.
437
- - Aggiorna `AI_GUIDELINES.md` quando introduci pattern importanti.
82
+ - [Utilizzo CSS/SCSS](docs/utilizzo-css-scss.md)
83
+ - [Helper JavaScript](docs/helper-javascript.md)
84
+ - [Componenti e markup](docs/componenti-e-markup.md)
85
+ - [Export npm e sviluppo](docs/export-e-sviluppo.md)
86
+ - [Convenzioni](docs/convenzioni.md)
@@ -8,30 +8,23 @@
8
8
  &[data-darkmode=true] {
9
9
  color-scheme: dark;
10
10
  }
11
- }
12
11
 
13
- // == Primary colors
14
- :root {
12
+ // == Primary colors
15
13
  --color-primary: #5c7d6f;
16
14
  --color-secondary: #3d5f4f;
17
15
  --color-tertiary: #8fb082;
18
16
  --color-quaternary: #10201c;
19
- }
20
-
21
- // == Base colors
22
- :root {
17
+
18
+ // == Base colors
23
19
  --color-white: light-dark(#FFFFFF, #000000);
24
20
  --color-black: light-dark(#000000, #FFFFFF);
25
21
  --color-white-transparent: color-mix(in srgb, var(--color-white) 50%, transparent 100%);
26
22
  --color-black-transparent: color-mix(in srgb, var(--color-black) 50%, transparent 100%);
27
-
28
23
  --color-text: light-dark(#4a4a4a, #e3e3e3);
29
-
30
24
  --color-box: light-dark(#F8F8F8, #3A3A3A);
31
25
  --color-boxDark: light-dark(#3A3A3A, #F8F8F8);
32
26
  --color-box-transparent: light-dark(color-mix(in srgb, #eeeeee 50%, transparent 50%), color-mix(in srgb, #3A3A3A 50%, transparent 50%));
33
27
  --color-boxDark-transparent: light-dark(color-mix(in srgb, #3A3A3A 50%, transparent 50%), color-mix(in srgb, #eeeeee 50%, transparent 50%));
34
-
35
28
  --color-linkBackgorud: light-dark(#a0dbff, #002a44);
36
29
  --color-background: light-dark(#ffffff, #080808);
37
30
  --color-whiteFixed: #FFFFFF;
@@ -1,63 +1,51 @@
1
1
  @use "../mixin/mixin" as *;
2
2
 
3
3
  //# GENERAL
4
- [pgs~=initP] {
4
+ [pgs~=boxtext] {
5
+ @include boxtext();
6
+ }
5
7
 
6
- [pgs~=card],
7
- [pgs~=cardImg] {
8
- @include card();
8
+ [pgs~=darkmode] {
9
+ color-scheme: dark;
10
+ }
9
11
 
10
- [pgs~=card-img] {
11
- @include card-insideImg();
12
- }
13
- }
12
+ [pgs~=lightmode] {
13
+ color-scheme: light;
14
+ }
14
15
 
15
- [pgs~=boxtext] {
16
- @include boxtext();
17
- }
16
+ [pgs~=imgCover] {
17
+ object-fit: cover;
18
+ }
18
19
 
19
- [pgs~=darkmode] {
20
- color-scheme: dark;
21
- }
20
+ [pgs~=imgContain] {
21
+ object-fit: contain;
22
+ }
22
23
 
23
- [pgs~=lightmode] {
24
- color-scheme: light;
25
- }
24
+ [pgs~=borderRadius] {
25
+ border-radius: var(--border-radius);
26
+ }
26
27
 
27
- [pgs~=imgCover] {
28
- object-fit: cover;
29
- }
28
+ [pgs~=borderRadiusInput] {
29
+ border-radius: var(--border-radius-input);
30
+ }
30
31
 
31
- [pgs~=imgContain] {
32
- object-fit: contain;
33
- }
32
+ [pgs~=borderRadiusExternal] {
33
+ border-radius: var(--border-radius-external);
34
+ }
34
35
 
35
- [pgs~=borderRadius] {
36
- border-radius: var(--border-radius);
37
- }
36
+ [pgs~=blur] {
37
+ backdrop-filter: var(--blur);
38
+ }
38
39
 
39
- [pgs~=borderRadiusInput] {
40
- border-radius: var(--border-radius-input);
41
- }
40
+ [pgs~=appearanceNone] {
41
+ all: unset;
42
+ appearance: none;
43
+ }
42
44
 
43
- [pgs~=borderRadiusExternal] {
44
- border-radius: var(--border-radius-external);
45
- }
45
+ [pgs~=pointer] {
46
+ cursor: pointer;
47
+ }
46
48
 
47
- [pgs~=blur] {
48
- backdrop-filter: var(--blur);
49
- }
50
-
51
- [pgs~=appearanceNone] {
52
- all: unset;
53
- appearance: none;
54
- }
55
-
56
- [pgs~=pointer] {
57
- cursor: pointer;
58
- }
59
-
60
- [pgs~=hidden] {
61
- display: none !important;
62
- }
49
+ [pgs~=hidden] {
50
+ display: none !important;
63
51
  }
@@ -1,24 +1,22 @@
1
1
  @use "../mixin/mixin" as *;
2
2
 
3
3
  //# HEADING
4
- [pgs~=initP] {
5
- [pgs~=h1] {
6
- @include h1();
7
- }
4
+ [pgs~=h1] {
5
+ @include h1();
6
+ }
8
7
 
9
- [pgs~=h2] {
10
- @include h2();
11
- }
8
+ [pgs~=h2] {
9
+ @include h2();
10
+ }
12
11
 
13
- [pgs~=h3] {
14
- @include h3();
15
- }
12
+ [pgs~=h3] {
13
+ @include h3();
14
+ }
16
15
 
17
- [pgs~=h4] {
18
- @include h4();
19
- }
16
+ [pgs~=h4] {
17
+ @include h4();
18
+ }
20
19
 
21
- [pgs~=h5] {
22
- @include h5();
23
- }
20
+ [pgs~=h5] {
21
+ @include h5();
24
22
  }
@@ -0,0 +1,10 @@
1
+ @use "../mixin/mixin" as *;
2
+
3
+ [pgs~=card],
4
+ [pgs~=cardImg] {
5
+ @include card();
6
+
7
+ [pgs~=card-img] {
8
+ @include card-insideImg();
9
+ }
10
+ }
@@ -9,8 +9,11 @@
9
9
  @include meta.load-css("base/color");
10
10
  @include meta.load-css("base/html");
11
11
  @include meta.load-css("base/body");
12
- @include meta.load-css("base/heading");
13
- @include meta.load-css("base/general");
12
+
13
+ [pgs~=initP] {
14
+ @include meta.load-css("base/heading");
15
+ @include meta.load-css("base/general");
16
+ }
14
17
 
15
18
  /*
16
19
  |--------------------------------------------------------------------------
@@ -33,6 +36,7 @@
33
36
  |--------------------------------------------------------------------------
34
37
  */
35
38
  [pgs~=initP] {
39
+ @include meta.load-css("components/card");
36
40
  @include meta.load-css("components/button");
37
41
  @include meta.load-css("components/form");
38
42
  @include meta.load-css("components/menu");