@pictogrammers/components 0.5.9 → 0.5.10
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
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
The `pg-input-pixel-editor` component is used to edit images. Tailored for pen or mouse input the editor can be used for various image editing tasks.
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
|
-
import '@pictogrammers/components/
|
|
6
|
+
import '@pictogrammers/components/pg/inputPixelEditor';
|
|
7
7
|
import PgInputPixelEditor, {
|
|
8
8
|
InputMode,
|
|
9
9
|
LayerType,
|
|
10
|
-
} from '@pictogrammers/components/
|
|
10
|
+
} from '@pictogrammers/components/pg/inputPixelEditor';
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```html
|
|
@@ -50,8 +50,10 @@ See usage for each method below.
|
|
|
50
50
|
| `setData()` | - | Set layer data. |
|
|
51
51
|
| `setJson(json)` | - | Set JSON file. |
|
|
52
52
|
| `reset()` | - | Reset canvas and data. |
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
53
|
+
| `getExport()` | - | 2d array of pixel color indexes. Already calculated. |
|
|
54
|
+
| `getExport(id)` | - | 2d array of pixel color indexes by export size. Minimal perf. |
|
|
55
|
+
| `getExportCanvas()` | - | Get new prepopulated HTML canvas, ideal for advanced export screens. |
|
|
56
|
+
| `await getExportPng(options, meta)` | - | Get png image with optional metadata. |
|
|
55
57
|
| `undo()` | - | Undo. |
|
|
56
58
|
| `hasUndo()` | - | Has undo |
|
|
57
59
|
| `hasRedo()` | - | Has redo |
|
|
@@ -179,6 +181,11 @@ A complete JSON storage for a 10x10 image.
|
|
|
179
181
|
[{ "color": 2, "path": "M...Z" }]
|
|
180
182
|
]
|
|
181
183
|
],
|
|
184
|
+
"grid": {
|
|
185
|
+
"vertical": [],
|
|
186
|
+
"horizontal": []
|
|
187
|
+
},
|
|
188
|
+
"exports": [],
|
|
182
189
|
"history": []
|
|
183
190
|
}
|
|
184
191
|
```
|
|
@@ -291,6 +298,92 @@ this.$input.addEventListener('reference', (e: any) => {
|
|
|
291
298
|
});
|
|
292
299
|
```
|
|
293
300
|
|
|
301
|
+
## Grid
|
|
302
|
+
|
|
303
|
+
Grids seperate the frame into regions. The vertical and horizontal lines can be assigned a unique color often used in fonts.
|
|
304
|
+
|
|
305
|
+
Grid lines on 0 or when equal or greater than to width/height are deleted. Applying a grid or resizing a frame will result in an error. Errors are handled by the consumer via the `error` event. `errorType: 'grid'`.
|
|
306
|
+
|
|
307
|
+
```text
|
|
308
|
+
0, 0 | 1, 0 | 2, 0
|
|
309
|
+
0, 1 | 1, 1 | 2, 1
|
|
310
|
+
0, 2 | 1, 2 | 2, 2
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
An example of a 9 segment grid for instance. Negative values offset from the right or bottom.
|
|
314
|
+
|
|
315
|
+
> Note: When configuring exports all grid colors with `color: 0` will be visible.
|
|
316
|
+
|
|
317
|
+
```json
|
|
318
|
+
{
|
|
319
|
+
"grid": [{
|
|
320
|
+
"vertical": [
|
|
321
|
+
{ "offset": 10, "color": 0 },
|
|
322
|
+
{ "offset": -10, "color": 0 }
|
|
323
|
+
],
|
|
324
|
+
"horizontal": [
|
|
325
|
+
{ "offset": 10, "color": 0 },
|
|
326
|
+
{ "offset": -10, "color": 0 }
|
|
327
|
+
]
|
|
328
|
+
}]
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Specific grid colors are configured on the editor level and do not persist in this input component. In a font the first 5 colors are reserved for the below lines.
|
|
333
|
+
|
|
334
|
+
- `1` - Ascender Line
|
|
335
|
+
- `2` - Cap Line
|
|
336
|
+
- `3` - Median / Mean line
|
|
337
|
+
- `4` - Baseline
|
|
338
|
+
- `5` - Decender Line
|
|
339
|
+
|
|
340
|
+
### Repeating Grids
|
|
341
|
+
|
|
342
|
+
A repeating grid is useful for tilesets and can be represented as.
|
|
343
|
+
- `offset` can be optional or null when `step` is defined.
|
|
344
|
+
- `limit` can be optional or null. Null repeats for as many times as it can fit.
|
|
345
|
+
- Similar to regular grids an error will throw if the first line is outside the `width` or `height`.
|
|
346
|
+
|
|
347
|
+
To create a repeating 20 pixel grid without an offset.
|
|
348
|
+
|
|
349
|
+
```json
|
|
350
|
+
{ "step": 20, "color": 0 },
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
To create a repeating 10 pixel grid with an offset `5` and limit `10`. The use case of this would be comps where a tileset does not evently sit in a viewport and needs to be centered.
|
|
354
|
+
|
|
355
|
+
```json
|
|
356
|
+
{ "offset": 5, "step": 10, "limit": 10, "color": 0 },
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Export
|
|
360
|
+
|
|
361
|
+
Exports by default include the entire canvas, but can be resized to a specific pixel size or grid. The `x`, `y`, `width`, and `height` are optional.
|
|
362
|
+
|
|
363
|
+
Use `getExport(id)` with a `id` value to get the data grid. This is ideal for export previews.
|
|
364
|
+
|
|
365
|
+
```json
|
|
366
|
+
{
|
|
367
|
+
"exports": [{
|
|
368
|
+
"id": "uuid",
|
|
369
|
+
"unit": "pixel",
|
|
370
|
+
"path": ["file.png"],
|
|
371
|
+
"x": 0,
|
|
372
|
+
"y": 0,
|
|
373
|
+
"width": null,
|
|
374
|
+
"height": null,
|
|
375
|
+
}, {
|
|
376
|
+
"id": "uuid",
|
|
377
|
+
"unit": "grid",
|
|
378
|
+
"path": ["folder", "bottomRight.png"],
|
|
379
|
+
"x": 2,
|
|
380
|
+
"y": 2,
|
|
381
|
+
"width": 1,
|
|
382
|
+
"height": 1,
|
|
383
|
+
}]
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
294
387
|
## History
|
|
295
388
|
|
|
296
389
|
The history list contains every change made to the canvas. All feature insert an entry into history. Pens and pattern tools will group as to cut down history entries.
|
|
@@ -96,6 +96,16 @@ interface Export {
|
|
|
96
96
|
height?: number
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
interface GridItem {
|
|
100
|
+
value: number
|
|
101
|
+
color: number
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface Grid {
|
|
105
|
+
vertical: GridItem[]
|
|
106
|
+
horizontal: GridItem[]
|
|
107
|
+
}
|
|
108
|
+
|
|
99
109
|
function toColor([r, g, b, a]: Color) {
|
|
100
110
|
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
101
111
|
}
|
|
@@ -139,6 +149,7 @@ export default class PgInputPixelEditor extends HTMLElement {
|
|
|
139
149
|
#selectionPixels = new Map<string, number[]>(); // 'x,y', [x, y]
|
|
140
150
|
#selection: number[][] = [];
|
|
141
151
|
#export: number[][] = [];
|
|
152
|
+
#grid: Grid = { vertical: [], horizontal: [] };
|
|
142
153
|
#undoHistory: History[] = [];
|
|
143
154
|
#redoHistory: History[] = [];
|
|
144
155
|
#context: CanvasRenderingContext2D;
|
|
@@ -1518,6 +1529,10 @@ export default class PgInputPixelEditor extends HTMLElement {
|
|
|
1518
1529
|
});
|
|
1519
1530
|
}
|
|
1520
1531
|
|
|
1532
|
+
getExport() {
|
|
1533
|
+
return this.#export;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1521
1536
|
getExportPath() {
|
|
1522
1537
|
return bitmaskToPath(this.#export, { scale: 1 });
|
|
1523
1538
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ExportType = 'pixel' | 'grid';
|