@pictogrammers/components 0.5.1 → 0.5.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pictogrammers/components",
3
3
  "type": "module",
4
- "version": "0.5.1",
4
+ "version": "0.5.2",
5
5
  "license": "MIT",
6
6
  "author": "Austin Andrews",
7
7
  "scripts": {
@@ -0,0 +1,4 @@
1
+ .example-flex {
2
+ display: flex;
3
+ gap: 0.5rem;
4
+ }
@@ -1,10 +1,12 @@
1
1
  import { Component, Part, Prop } from '@pictogrammers/element';
2
2
 
3
+ import style from './basic.css';
3
4
  import template from './basic.html';
4
5
 
5
6
  @Component({
6
7
  selector: 'x-pg-button-basic',
7
- template
8
+ style,
9
+ template,
8
10
  })
9
11
  export default class XPgButtonBasic extends HTMLElement {
10
12
 
@@ -0,0 +1,3 @@
1
+ h4 {
2
+ margin-block: 0.25rem;
3
+ }
@@ -1,11 +1,13 @@
1
1
  import { Component, Part, Prop } from '@pictogrammers/element';
2
2
  import PgButton from '../../button';
3
3
 
4
+ import style from './states.css';
4
5
  import template from './states.html';
5
6
 
6
7
  @Component({
7
8
  selector: 'x-pg-button-states',
8
- template
9
+ style,
10
+ template,
9
11
  })
10
12
  export default class XPgButtonStates extends HTMLElement {
11
13
  @Part() $active: PgButton;
@@ -0,0 +1,4 @@
1
+ .example-flex {
2
+ display: flex;
3
+ gap: 0.5rem;
4
+ }
@@ -0,0 +1,10 @@
1
+ <div class="example">
2
+ <div class="example-flex">
3
+ <pg-button variant="brand">Example Button</pg-button>
4
+ <pg-button variant="brand"><pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon></pg-button>
5
+ <pg-button variant="brand">
6
+ <pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon>
7
+ With Icon
8
+ </pg-button>
9
+ </div>
10
+ </div>
@@ -0,0 +1,13 @@
1
+ import { Component, Part, Prop } from '@pictogrammers/element';
2
+
3
+ import style from './variants.css';
4
+ import template from './variants.html';
5
+
6
+ @Component({
7
+ selector: 'x-pg-button-variants',
8
+ style,
9
+ template,
10
+ })
11
+ export default class XPgVariantsBasic extends HTMLElement {
12
+
13
+ }
@@ -2,7 +2,7 @@
2
2
  display: inline-flex;
3
3
  }
4
4
 
5
- [part="button"] {
5
+ [part=button] {
6
6
  display: flex;
7
7
  align-items: center;
8
8
  align-content: center;
@@ -17,25 +17,26 @@
17
17
  outline: none;
18
18
  --pg-icon-color: var(--pg-button-color, #453C4F);
19
19
  cursor: var(--pg-button-cursor, var(--pg-cursor-default, default));
20
+ gap: var(--pg-button-gap, 0.325rem);
20
21
  }
21
22
 
22
- [part="button"]:hover {
23
+ [part=button]:hover {
23
24
  --pg-button-border-color: var(--pg-button-hover-border-color, #453C4F);
24
25
  background-color: var(--pg-button-hover-background-color, #453C4F);
25
26
  color: var(--pg-button-hover-color, #FFFFFF);
26
27
  --pg-icon-color: var(--pg-button-hover-color, #FFFFFF);
27
28
  }
28
29
 
29
- [part="button"]:active {
30
+ [part=button]:active {
30
31
  box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
31
32
  position: relative;
32
33
  }
33
34
 
34
- [part="button"]:focus-visible {
35
+ [part=button]:focus-visible {
35
36
  position: relative;
36
37
  }
37
38
 
38
- [part="button"]:active::before {
39
+ [part=button]:active::before {
39
40
  content: '';
40
41
  position: absolute;
41
42
  top: -1px;
@@ -45,7 +46,7 @@
45
46
  border-radius: var(--pg-button-border-radius, 0.25rem);
46
47
  box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
47
48
  }
48
- [part="button"]:focus-visible::before {
49
+ [part=button]:focus-visible::before {
49
50
  pointer-events: none;
50
51
  content: '';
51
52
  position: absolute;
@@ -57,37 +58,46 @@
57
58
  box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
58
59
  }
59
60
 
60
- [part="button"].start {
61
+ [part=button].start {
61
62
  border-top-right-radius: 0;
62
63
  border-bottom-right-radius: 0;
63
64
  margin-right: -1px;
64
65
  }
65
66
 
66
- [part="button"].center {
67
+ [part=button].center {
67
68
  border-radius: 0;
68
69
  margin-right: -1px;
69
70
  }
70
71
 
71
- [part="button"].end {
72
+ [part=button].end {
72
73
  border-top-left-radius: 0;
73
74
  border-bottom-left-radius: 0;
74
75
  }
75
76
 
76
- [part="button"].active {
77
+ [part=button].active {
77
78
  box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
78
79
  background-color: rgba(69, 60, 79, 0.1);
79
80
  color: var(--pg-button-color, #453C4F);
80
81
  }
81
- [part="button"].active:hover {
82
+ [part=button].active:hover {
82
83
  box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
83
84
  background-color: var(--pg-button-color, #453C4F);
84
- color: var(--pg-button-hover-color, #fff);
85
+ color: var(--pg-button-hover-color, #FFFFFF);
85
86
  }
86
87
 
87
- [part="button"].block {
88
+ [part=button].block {
88
89
  flex: 1;
89
90
  }
90
91
 
92
+ [part=button].brand {
93
+ --pg-button-background-color: #453C4F;
94
+ --pg-button-color: #FFFFFF;
95
+ }
96
+ [part=button].brand:hover {
97
+ --pg-button-hover-background-color: color-mix(in oklab, var(--pg-button-background-color), white 10%);
98
+ --pg-button-hover-border-color: color-mix(in oklab, var(--pg-button-background-color), white 10%);
99
+ }
100
+
91
101
  ::slotted {
92
102
  align-self: center;
93
- }
103
+ }
@@ -1,14 +1,17 @@
1
- import { Component, Part, Prop, normalizeBoolean } from '@pictogrammers/element';
1
+ import { Component, Part, Prop, normalizeBoolean, normalizeString } from '@pictogrammers/element';
2
2
 
3
3
  import template from './button.html';
4
4
  import style from './button.css';
5
5
 
6
+ const variants = ['neutral', 'brand'];
7
+
6
8
  @Component({
7
9
  selector: 'pg-button',
8
10
  style,
9
11
  template
10
12
  })
11
13
  export default class PgButton extends HTMLElement {
14
+ @Prop(normalizeString) variant: string = 'neutral';
12
15
  @Prop(normalizeBoolean) active: boolean = false;
13
16
  @Prop(normalizeBoolean) block: boolean = false;
14
17
  @Prop(normalizeBoolean) start: boolean = false;
@@ -27,6 +30,13 @@ export default class PgButton extends HTMLElement {
27
30
  }
28
31
 
29
32
  render(changes) {
33
+ if (changes.variant) {
34
+ if (!variants.includes(this.variant)) {
35
+ throw new Error(`invalid variant ${this.variant}`);
36
+ }
37
+ this.$button.classList.toggle('neutral', this.variant === 'neutral');
38
+ this.$button.classList.toggle('brand', this.variant === 'brand');
39
+ }
30
40
  if (changes.active) {
31
41
  this.$button.classList.toggle('active', this.active);
32
42
  }
@@ -70,7 +70,7 @@ See usage for each method below.
70
70
  | `inputModeEllipseOutline()` | - | Input Mode Ellipse Outline |
71
71
  | `selectLayer(index)` | - | Select layer. |
72
72
  | `getLayers()` | - | Get layer array. |
73
- | `addLayer(option)` | - | Add layer. |
73
+ | `addLayer(option)` | - | Add layer. `name`, `type` required. |
74
74
  | `removeLayer(index)` | - | Remove layer. |
75
75
  | `flattenLayers(layerIndexes)` | - | Flatten layers. |
76
76
  | `getColor()` | - | Get selected color |
@@ -23,6 +23,7 @@ import { readMetadata, textEncode, writeMetadata } from './utils/pngMetadata';
23
23
  import { canvasToPngBuffer } from './utils/canvasToPngBuffer';
24
24
  import { blobToImage } from './utils/blobToImage';
25
25
  import { diffLeftMapPixels } from './utils/diffMap';
26
+ import { maskToBitmap } from './utils/maskToBitmap';
26
27
 
27
28
  type Color = [number, number, number, number];
28
29
 
@@ -57,7 +58,7 @@ type HistoryColorUpdateType = {
57
58
  }
58
59
 
59
60
  type HistoryItem = {
60
- type: HistoryType,
61
+ type: HistoryType
61
62
  data: HistoryGroupType | HistoryPixelType | HistoryColorUpdateType
62
63
  }
63
64
 
@@ -1375,8 +1376,12 @@ export default class PgInputPixelEditor extends HTMLElement {
1375
1376
  export: optional.exclude ?? true,
1376
1377
  locked: optional.locked ?? false,
1377
1378
  visible: optional.hidden ?? true,
1378
- opacity: 1
1379
+ opacity: optional.opacity ?? 1,
1379
1380
  });
1381
+ // short hand for initial data
1382
+ if (optional.data) {
1383
+ this.setData(optional.data);
1384
+ }
1380
1385
  }
1381
1386
 
1382
1387
  /**
@@ -1467,7 +1472,28 @@ export default class PgInputPixelEditor extends HTMLElement {
1467
1472
  * Set data
1468
1473
  */
1469
1474
  setData(data: any[]) {
1470
-
1475
+ data.forEach((layerData, layerIndex) => {
1476
+ const { type } = this.#layers[layerIndex];
1477
+ switch(type) {
1478
+ case 'pixel':
1479
+ const { color, path } = layerData;
1480
+ const temp = maskToBitmap(path, this.width, this.height);
1481
+ temp.forEach((tempY, y) => {
1482
+ tempY.forEach((tempX, x) => {
1483
+ if (tempX !== 0) {
1484
+ //this.#data[layerIndex][y][x] = color;
1485
+ this.#setPixel(x, y, color, [layerIndex]);
1486
+ }
1487
+ });
1488
+ });
1489
+ break;
1490
+ case 'reference':
1491
+ console.log('reference', layerData);
1492
+ break;
1493
+ default:
1494
+ throw new Error(`unknown type ${type}`);
1495
+ }
1496
+ });
1471
1497
  }
1472
1498
 
1473
1499
  getExportPath() {
@@ -1,4 +1,4 @@
1
- export function maskToBitmap(pathData: string, width: number, height: number) {
1
+ export function maskToBitmap(pathData: string, width: number, height: number, fill: number = 1) {
2
2
  const grid: number[][] = Array(height).fill(0).map(() => Array(width).fill(0));
3
3
 
4
4
  // Store only the vertical edges
@@ -57,7 +57,7 @@ export function maskToBitmap(pathData: string, width: number, height: number) {
57
57
  }
58
58
  }
59
59
  if (inside) {
60
- grid[y][x] = 1;
60
+ grid[y][x] = fill;
61
61
  }
62
62
  }
63
63
  }
@@ -11,8 +11,8 @@
11
11
  font-size: 1rem;
12
12
  outline: none;
13
13
  field-sizing: content;
14
- min-width: calc(100% - 0.5rem - 2px);
15
- max-width: calc(var(--pg-input-text-max-width, 100%) - 0.5rem - 2px);
14
+ min-width: calc(100% - 1.5rem - 2px);
15
+ max-width: calc(var(--pg-input-text-max-width, 100%) - 1.5rem - 2px);
16
16
  background-color: transparent;
17
17
  }
18
18
 
@@ -2,10 +2,10 @@
2
2
  <div class="dialog"
3
3
  role="dialog"
4
4
  id="dialog1"
5
- aria-labelledby="dialog1_label"
5
+ aria-labelledby="dialog_label"
6
6
  aria-modal="true">
7
7
  <header part="header">
8
- <h2 id="dialog1_label"
8
+ <h2 id="dialog_label"
9
9
  class="dialog_label"
10
10
  part="headerText">
11
11
  Add Delivery Address
@@ -16,7 +16,7 @@
16
16
  </main>
17
17
  <footer>
18
18
  <pg-button part="no">No</pg-button>
19
- <pg-button part="yes">Yes</pg-button>
19
+ <pg-button part="yes" variant="brand">Yes</pg-button>
20
20
  </footer>
21
21
  </div>
22
22
  </div>
@@ -84,4 +84,4 @@ export default class XPgOverlayContextMenuBasic extends HTMLElement {
84
84
  }
85
85
  this.$result.textContent = JSON.stringify(result);
86
86
  }
87
- }
87
+ }