@pixerate/editor-svelte 0.136.0 → 0.137.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { imageSectionTitleClass } from './styles.js';
|
|
3
3
|
import type { AlphaChannel, ImageEditorController } from '@pixerate/editor/image-editor';
|
|
4
|
-
import { channelThumbnail, selectionModeFromModifiers } from '@pixerate/editor/image-editor';
|
|
4
|
+
import { MASK_FILE_ACCEPT, channelThumbnail, downloadMaskImage, openMaskFile, selectionModeFromModifiers } from '@pixerate/editor/image-editor';
|
|
5
5
|
import { untrack } from 'svelte';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
let activeId = $state<string | null>(null);
|
|
30
30
|
let renaming = $state<string | null>(null);
|
|
31
31
|
let error = $state<string | null>(null);
|
|
32
|
+
let fileInput = $state<HTMLInputElement | null>(null);
|
|
32
33
|
const active = $derived(snapshot.channels.find((c) => c.id === activeId) ?? null);
|
|
33
34
|
|
|
34
35
|
function attempt(fn: () => unknown) {
|
|
@@ -40,6 +41,16 @@
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
async function importFile(file: File | undefined) {
|
|
45
|
+
if (!file) return;
|
|
46
|
+
error = null;
|
|
47
|
+
try {
|
|
48
|
+
activeId = (await openMaskFile(controller, file)).id;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
error = err instanceof Error ? err.message : String(err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
/** Draws a channel's thumbnail (nothing without a 2D context). */
|
|
44
55
|
function thumb(canvas: HTMLCanvasElement, channel: AlphaChannel) {
|
|
45
56
|
const draw = (c: AlphaChannel) => {
|
|
@@ -65,7 +76,8 @@
|
|
|
65
76
|
<!--
|
|
66
77
|
The Channels panel: alpha channels (saved selections) with thumbnails, an eye to show each as a
|
|
67
78
|
tint, click to load it as the selection (Shift adds, Alt subtracts, both intersect), double-click
|
|
68
|
-
to rename; Save Selection, Add to Channel, Duplicate and Delete;
|
|
79
|
+
to rename; Save Selection, Add to Channel, Duplicate and Delete; Import (a mask image into a new
|
|
80
|
+
channel) and Export PNG (the active channel, else the selection); and the Quick Mask mode switch.
|
|
69
81
|
-->
|
|
70
82
|
<div data-testid="channels-panel" class="flex flex-col gap-2 text-xs {className}">
|
|
71
83
|
<div class="flex items-center justify-between">
|
|
@@ -135,6 +147,25 @@
|
|
|
135
147
|
controller.deleteChannel(active!.id);
|
|
136
148
|
activeId = null;
|
|
137
149
|
})}>Delete</button>
|
|
150
|
+
<button type="button" class={btn()} title="Load a mask image (white = selected) into a new channel" onclick={() => fileInput?.click()}>Import…</button>
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
class={btn()}
|
|
154
|
+
disabled={!active && !snapshot.hasSelection}
|
|
155
|
+
title={active ? 'Save the channel as a greyscale PNG' : 'Save the selection as a greyscale PNG'}
|
|
156
|
+
onclick={() => attempt(() => downloadMaskImage(controller, active ? { channelId: active.id } : 'selection', active?.name ?? 'selection'))}>Export PNG</button>
|
|
157
|
+
<input
|
|
158
|
+
bind:this={fileInput}
|
|
159
|
+
type="file"
|
|
160
|
+
accept={MASK_FILE_ACCEPT}
|
|
161
|
+
hidden
|
|
162
|
+
data-testid="channel-import-input"
|
|
163
|
+
onchange={(e) => {
|
|
164
|
+
const input = e.currentTarget as HTMLInputElement;
|
|
165
|
+
void importFile(input.files?.[0]);
|
|
166
|
+
input.value = '';
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
138
169
|
</div>
|
|
139
170
|
{#if error}
|
|
140
171
|
<p role="alert" class="text-destructive">{error}</p>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.137.1",
|
|
4
4
|
"description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
"**/*.css"
|
|
166
166
|
],
|
|
167
167
|
"dependencies": {
|
|
168
|
-
"@pixerate/editor": "0.
|
|
168
|
+
"@pixerate/editor": "0.188.0"
|
|
169
169
|
},
|
|
170
170
|
"peerDependencies": {
|
|
171
171
|
"@dagrejs/dagre": "^1.1.4",
|