@lvl99dotcom/paintcanvas 0.4.0 → 0.6.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/README.md +30 -15
- package/dist/lib/brushes/configRanges/index.d.ts +17 -0
- package/dist/lib/brushes/configRanges/index.js +31 -1
- package/dist/lib/brushes/params/index.d.ts +2 -1
- package/dist/lib/brushes/params/index.js +7 -4
- package/dist/lib/brushes/presets/round/index.d.ts +1 -1
- package/dist/lib/brushes/presets/round/index.js +12 -7
- package/dist/lib/brushes/presets/square/index.d.ts +1 -1
- package/dist/lib/brushes/presets/square/index.js +7 -3
- package/dist/lib/brushes/shapeImage/index.d.ts +7 -3
- package/dist/lib/brushes/shapeImage/index.js +15 -9
- package/dist/lib/brushes/shapes/index.d.ts +18 -0
- package/dist/lib/brushes/shapes/index.js +86 -0
- package/dist/lib/brushes/types/index.d.ts +8 -0
- package/dist/lib/classes/BrushSettings/index.d.ts +29 -2
- package/dist/lib/classes/BrushSettings/index.js +51 -14
- package/dist/lib/classes/KeyboardShortcuts/index.d.ts +31 -2
- package/dist/lib/classes/KeyboardShortcuts/index.js +66 -4
- package/dist/lib/classes/Layer/index.d.ts +10 -0
- package/dist/lib/classes/Layer/index.js +15 -1
- package/dist/lib/classes/LayerAutosave/index.d.ts +9 -15
- package/dist/lib/classes/LayerAutosave/index.js +30 -43
- package/dist/lib/classes/LayerStack/index.d.ts +15 -0
- package/dist/lib/classes/LayerStack/index.js +26 -2
- package/dist/lib/classes/PaintCanvas/index.d.ts +72 -3
- package/dist/lib/classes/PaintCanvas/index.js +106 -12
- package/dist/lib/classes/PngEncoder/index.d.ts +41 -0
- package/dist/lib/classes/PngEncoder/index.js +104 -0
- package/dist/lib/classes/ProfileGraphs/index.d.ts +87 -0
- package/dist/lib/classes/ProfileGraphs/index.js +148 -0
- package/dist/lib/classes/SettingsAutosave/index.d.ts +3 -2
- package/dist/lib/classes/SettingsAutosave/index.js +6 -3
- package/dist/lib/classes/UiSettings/index.d.ts +68 -0
- package/dist/lib/classes/UiSettings/index.js +82 -0
- package/dist/lib/messages/schema.d.ts +720 -0
- package/dist/lib/presets/schema.d.ts +360 -0
- package/dist/lib/presets/schema.js +8 -1
- package/dist/lib/profiles/index.d.ts +61 -0
- package/dist/lib/profiles/index.js +131 -0
- package/dist/lib/profiles/schema.d.ts +73 -0
- package/dist/lib/profiles/schema.js +53 -0
- package/dist/lib/rendering/sample/index.d.ts +11 -0
- package/dist/lib/rendering/sample/index.js +36 -5
- package/dist/lib/settings/index.d.ts +2 -1
- package/dist/lib/settings/index.js +7 -2
- package/dist/lib/settings/schema.d.ts +67 -0
- package/dist/lib/settings/schema.js +20 -0
- package/dist/lib/validation/validators.generated.js +13191 -3655
- package/dist/locales/en-GB.js +39 -2
- package/dist/locales/en-US.js +39 -2
- package/dist/locales/fr.js +39 -2
- package/dist/locales/ja.js +39 -2
- package/dist/locales/ko.js +39 -2
- package/dist/locales/zh-Hans.js +39 -2
- package/dist/locales/zh-Hant.js +39 -2
- package/dist/package.js +1 -1
- package/dist/testing/recordingCanvas.js +2 -1
- package/dist/ui/ask/index.d.ts +48 -0
- package/dist/ui/ask/index.js +67 -0
- package/dist/ui/base/index.d.ts +10 -3
- package/dist/ui/base/index.js +19 -4
- package/dist/ui/dismiss/index.d.ts +21 -0
- package/dist/ui/dismiss/index.js +27 -0
- package/dist/ui/drag/index.d.ts +51 -0
- package/dist/ui/drag/index.js +81 -0
- package/dist/ui/elements/PaintCanvas/index.d.ts +17 -12
- package/dist/ui/elements/PaintCanvas/index.js +36 -17
- package/dist/ui/elements/PaintCanvas/style.js +1 -1
- package/dist/ui/elements/PcAppSettings/index.d.ts +6 -6
- package/dist/ui/elements/PcAppSettings/index.js +21 -65
- package/dist/ui/elements/PcBrushConfig/index.d.ts +34 -16
- package/dist/ui/elements/PcBrushConfig/index.js +263 -153
- package/dist/ui/elements/PcBrushConfig/style.js +1 -1
- package/dist/ui/elements/PcBrushSize/index.d.ts +53 -0
- package/dist/ui/elements/PcBrushSize/index.js +66 -0
- package/dist/ui/elements/PcBrushTest/index.d.ts +26 -0
- package/dist/ui/elements/PcBrushTest/index.js +79 -6
- package/dist/ui/elements/PcBrushTest/style.js +1 -1
- package/dist/ui/elements/PcButton/index.d.ts +12 -3
- package/dist/ui/elements/PcButton/index.js +18 -10
- package/dist/ui/elements/PcCanvas/index.d.ts +27 -2
- package/dist/ui/elements/PcCanvas/index.js +63 -13
- package/dist/ui/elements/PcCanvas/style.js +1 -1
- package/dist/ui/elements/PcCanvasMap/style.js +1 -1
- package/dist/ui/elements/PcClipboardTools/index.d.ts +49 -0
- package/dist/ui/elements/PcClipboardTools/index.js +125 -0
- package/dist/ui/elements/PcContextMenu/index.d.ts +2 -2
- package/dist/ui/elements/PcDialog/index.d.ts +46 -10
- package/dist/ui/elements/PcDialog/index.js +102 -51
- package/dist/ui/elements/PcDialogWindow/index.d.ts +141 -0
- package/dist/ui/elements/PcDialogWindow/index.js +385 -0
- package/dist/ui/elements/PcInputSettings/index.d.ts +13 -0
- package/dist/ui/elements/PcInputSettings/index.js +16 -1
- package/dist/ui/elements/PcMenu/index.d.ts +48 -3
- package/dist/ui/elements/PcMenu/index.js +111 -19
- package/dist/ui/elements/PcNumberSlider/index.d.ts +137 -0
- package/dist/ui/elements/PcNumberSlider/index.js +247 -0
- package/dist/ui/elements/PcPane/index.d.ts +3 -1
- package/dist/ui/elements/PcPane/index.js +44 -7
- package/dist/ui/elements/PcPanel/index.d.ts +2 -2
- package/dist/ui/elements/PcPanel/index.js +8 -8
- package/dist/ui/elements/PcPanelBrushes/index.d.ts +5 -17
- package/dist/ui/elements/PcPanelBrushes/index.js +13 -48
- package/dist/ui/elements/PcPanelBrushes/style.js +1 -1
- package/dist/ui/elements/PcPanelColours/index.js +2 -2
- package/dist/ui/elements/PcPanelColours/style.js +1 -1
- package/dist/ui/elements/PcPanelLayers/index.js +1 -1
- package/dist/ui/elements/PcPanelLayers/style.js +1 -1
- package/dist/ui/elements/PcPopover/index.d.ts +39 -1
- package/dist/ui/elements/PcPopover/index.js +72 -4
- package/dist/ui/elements/PcProfileEditor/index.d.ts +103 -0
- package/dist/ui/elements/PcProfileEditor/index.js +259 -0
- package/dist/ui/elements/PcProfileGraph/index.d.ts +84 -0
- package/dist/ui/elements/PcProfileGraph/index.js +317 -0
- package/dist/ui/elements/PcShortcutSettings/index.js +9 -13
- package/dist/ui/elements/PcSliderRange/index.d.ts +147 -0
- package/dist/ui/elements/PcSliderRange/index.js +307 -0
- package/dist/ui/elements/PcStats/index.d.ts +19 -4
- package/dist/ui/elements/PcStats/index.js +29 -13
- package/dist/ui/elements/PcThemePicker/index.d.ts +17 -15
- package/dist/ui/elements/PcThemePicker/index.js +22 -21
- package/dist/ui/elements/PcToolSettings/index.d.ts +48 -9
- package/dist/ui/elements/PcToolSettings/index.js +382 -318
- package/dist/ui/elements/PcToolSettings/style.js +1 -1
- package/dist/ui/elements/PcToolbar/index.d.ts +15 -0
- package/dist/ui/elements/PcToolbar/index.js +55 -14
- package/dist/ui/elements/PcToolbar/style.js +1 -1
- package/dist/ui/icons/images/icon-brush@2x.js +3 -0
- package/dist/ui/icons/images/icon-circle-mask@2x.js +3 -0
- package/dist/ui/icons/images/icon-clipboard@2x.js +3 -0
- package/dist/ui/icons/images/icon-cog@2x.js +3 -0
- package/dist/ui/icons/images/icon-cursor@2x.js +3 -0
- package/dist/ui/icons/images/icon-diagonal-tlbr-size@2x.js +3 -0
- package/dist/ui/icons/images/icon-diagonal-trbl-size@2x.js +3 -0
- package/dist/ui/icons/images/icon-eraser@2x.js +3 -0
- package/dist/ui/icons/images/icon-eyedropper@2x.js +3 -0
- package/dist/ui/icons/images/icon-flip-horizontal@2x.js +3 -0
- package/dist/ui/icons/images/icon-flip-vertical@2x.js +3 -0
- package/dist/ui/icons/images/icon-focus-pen@2x.js +3 -0
- package/dist/ui/icons/images/icon-freehand-mask@2x.js +3 -0
- package/dist/ui/icons/images/icon-hidden@2x.js +3 -0
- package/dist/ui/icons/images/icon-horizontal-size@2x.js +3 -0
- package/dist/ui/icons/images/icon-layers@2x.js +3 -0
- package/dist/ui/icons/images/icon-linked@2x.js +3 -0
- package/dist/ui/icons/images/icon-locked@2x.js +3 -0
- package/dist/ui/icons/images/icon-moon@2x.js +3 -0
- package/dist/ui/icons/images/icon-pan@2x.js +3 -0
- package/dist/ui/icons/images/icon-polygon-mask@2x.js +3 -0
- package/dist/ui/icons/images/icon-pressure@2x.js +3 -0
- package/dist/ui/icons/images/icon-profile-graph@2x.js +3 -0
- package/dist/ui/icons/images/icon-randomise@2x.js +3 -0
- package/dist/ui/icons/images/icon-rectangle-mask@2x.js +3 -0
- package/dist/ui/icons/images/icon-redo@2x.js +3 -0
- package/dist/ui/icons/images/icon-rotate-90-left@2x.js +3 -0
- package/dist/ui/icons/images/icon-rotate-90-right@2x.js +3 -0
- package/dist/ui/icons/images/icon-rotate@2x.js +3 -0
- package/dist/ui/icons/images/icon-smoothing-bezier-cubic@2x.js +3 -0
- package/dist/ui/icons/images/icon-smoothing-bezier-quad@2x.js +3 -0
- package/dist/ui/icons/images/icon-smoothing-linear@2x.js +3 -0
- package/dist/ui/icons/images/icon-star@2x.js +3 -0
- package/dist/ui/icons/images/icon-sun@2x.js +3 -0
- package/dist/ui/icons/images/icon-tilt@2x.js +3 -0
- package/dist/ui/icons/images/icon-undo@2x.js +3 -0
- package/dist/ui/icons/images/icon-unlinked@2x.js +3 -0
- package/dist/ui/icons/images/icon-unlocked@2x.js +3 -0
- package/dist/ui/icons/images/icon-vertical-size@2x.js +3 -0
- package/dist/ui/icons/images/icon-visible@2x.js +3 -0
- package/dist/ui/icons/images/icon-zoom-in@2x.js +3 -0
- package/dist/ui/icons/images/icon-zoom-out@2x.js +3 -0
- package/dist/ui/icons/images/icon-zoom@2x.js +3 -0
- package/dist/ui/icons/index.d.ts +1 -1
- package/dist/ui/icons/index.js +86 -72
- package/dist/ui/index.d.ts +13 -3
- package/dist/ui/index.js +15 -4
- package/dist/ui/layout/index.d.ts +9 -1
- package/dist/ui/layout/index.js +11 -2
- package/dist/ui/styles/index.d.ts +21 -1
- package/dist/ui/styles/index.js +73 -14
- package/dist/ui/tokens/index.d.ts +5 -4
- package/dist/ui/tokens/index.js +12 -7
- package/locales/en-GB.json +39 -2
- package/locales/en-US.json +39 -2
- package/locales/fr.json +39 -2
- package/locales/ja.json +39 -2
- package/locales/ko.json +39 -2
- package/locales/zh-Hans.json +39 -2
- package/locales/zh-Hant.json +39 -2
- package/package.json +27 -18
- package/dist/ui/icons/images/brush.js +0 -3
- package/dist/ui/icons/images/circle-mask.js +0 -3
- package/dist/ui/icons/images/clipboard.js +0 -3
- package/dist/ui/icons/images/cursor.js +0 -3
- package/dist/ui/icons/images/eraser.js +0 -3
- package/dist/ui/icons/images/eyedropper.js +0 -3
- package/dist/ui/icons/images/flip-horizontal.js +0 -3
- package/dist/ui/icons/images/flip-vertical.js +0 -3
- package/dist/ui/icons/images/focus-pen.js +0 -3
- package/dist/ui/icons/images/freehand-mask.js +0 -3
- package/dist/ui/icons/images/hidden.js +0 -3
- package/dist/ui/icons/images/layers.js +0 -3
- package/dist/ui/icons/images/linked.js +0 -3
- package/dist/ui/icons/images/locked.js +0 -3
- package/dist/ui/icons/images/moon.js +0 -3
- package/dist/ui/icons/images/pan.js +0 -3
- package/dist/ui/icons/images/polygon-mask.js +0 -3
- package/dist/ui/icons/images/pressure.js +0 -3
- package/dist/ui/icons/images/randomise.js +0 -3
- package/dist/ui/icons/images/rectangle-mask.js +0 -3
- package/dist/ui/icons/images/redo.js +0 -3
- package/dist/ui/icons/images/rotate-90-left.js +0 -3
- package/dist/ui/icons/images/rotate-90-right.js +0 -3
- package/dist/ui/icons/images/smoothing-bezier-cubic.js +0 -3
- package/dist/ui/icons/images/smoothing-bezier-quad.js +0 -3
- package/dist/ui/icons/images/smoothing-linear.js +0 -3
- package/dist/ui/icons/images/star.js +0 -3
- package/dist/ui/icons/images/sun.js +0 -3
- package/dist/ui/icons/images/tilt.js +0 -3
- package/dist/ui/icons/images/undo.js +0 -3
- package/dist/ui/icons/images/unlinked.js +0 -3
- package/dist/ui/icons/images/unlocked.js +0 -3
- package/dist/ui/icons/images/visible.js +0 -3
- package/dist/ui/icons/images/zoom-in.js +0 -3
- package/dist/ui/icons/images/zoom-out.js +0 -3
- package/dist/ui/icons/images/zoom.js +0 -3
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { PcElement } from "../../base";
|
|
2
|
+
import { type ConfirmFn, type PromptFn } from "../../ask";
|
|
3
|
+
import "../PcDialogWindow";
|
|
4
|
+
import "../PcProfileGraph";
|
|
5
|
+
import "../PcContextMenu";
|
|
6
|
+
import "../PcButton";
|
|
7
|
+
import ProfileGraphs from "../../../lib/classes/ProfileGraphs";
|
|
8
|
+
import { type ProfilePoint } from "../../../lib/profiles";
|
|
9
|
+
/** What the editor's `pc-save` gives: the points to use and the graph they came from (undefined for an unsaved one) */
|
|
10
|
+
export interface ProfileSaveDetail {
|
|
11
|
+
points: ProfilePoint[];
|
|
12
|
+
profileId?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A window for editing a brush setting's profile graph (see `<pc-profile-graph>`): a drop-down of the presets and the
|
|
16
|
+
* user's own graphs (it says "Custom" once the graph is edited, or for one that isn't saved), a ⋮ menu (New graph,
|
|
17
|
+
* Duplicate…, Rename… and Delete…, the last two for the user's own graphs), the graph, and Save, Reset and Dismiss.
|
|
18
|
+
*
|
|
19
|
+
* - Choosing a graph in the drop-down loads its points.
|
|
20
|
+
* - New graph starts from a straight line, and Duplicate… saves a copy of the current graph under a name ("Custom" to
|
|
21
|
+
* start with); Rename… and Delete… ask first.
|
|
22
|
+
* - Save uses the graph (firing `pc-save` with its points and ID); an edited or unsaved graph is first saved with a name
|
|
23
|
+
* it asks for, asking before replacing another of the user's graphs with that name.
|
|
24
|
+
* - Reset goes back to the graph it opened with; Dismiss, ⨉ and Escape close it (`pc-close`) without changing anything.
|
|
25
|
+
*
|
|
26
|
+
* Graphs are saved in `profiles` (the canvas's `ProfileGraphs`).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* html`<pc-profile-editor .profiles=${app.profiles} .points=${points} profile-id="overweight" label="Width"
|
|
30
|
+
* @pc-save=${(e) => use(e.detail)} @pc-close=${close}></pc-profile-editor>`
|
|
31
|
+
*/
|
|
32
|
+
export declare class PcProfileEditor extends PcElement {
|
|
33
|
+
static properties: {
|
|
34
|
+
profiles: {
|
|
35
|
+
attribute: boolean;
|
|
36
|
+
};
|
|
37
|
+
points: {
|
|
38
|
+
attribute: boolean;
|
|
39
|
+
};
|
|
40
|
+
profileId: {
|
|
41
|
+
type: StringConstructor;
|
|
42
|
+
attribute: string;
|
|
43
|
+
};
|
|
44
|
+
label: {
|
|
45
|
+
type: StringConstructor;
|
|
46
|
+
};
|
|
47
|
+
draft: {
|
|
48
|
+
state: boolean;
|
|
49
|
+
};
|
|
50
|
+
sourceId: {
|
|
51
|
+
state: boolean;
|
|
52
|
+
};
|
|
53
|
+
translations: {
|
|
54
|
+
attribute: boolean;
|
|
55
|
+
};
|
|
56
|
+
icons: {
|
|
57
|
+
attribute: boolean;
|
|
58
|
+
};
|
|
59
|
+
theme: {
|
|
60
|
+
type: StringConstructor;
|
|
61
|
+
reflect: boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
static styles: import("lit").CSSResultGroup[];
|
|
65
|
+
/** Where graphs are saved (the canvas's `ProfileGraphs`) */
|
|
66
|
+
profiles: ProfileGraphs;
|
|
67
|
+
/** The points it opens with */
|
|
68
|
+
points?: ProfilePoint[];
|
|
69
|
+
/** The ID of the graph it opens with, if it's one of the presets or saved graphs */
|
|
70
|
+
profileId?: string;
|
|
71
|
+
/** The setting's name, e.g. "Width" */
|
|
72
|
+
label: string;
|
|
73
|
+
/** The points being edited */
|
|
74
|
+
draft: ProfilePoint[];
|
|
75
|
+
/** The graph the points came from, until they're edited */
|
|
76
|
+
sourceId?: string;
|
|
77
|
+
/** Asks the user to confirm, in a dialog (replaceable for tests) */
|
|
78
|
+
confirm: ConfirmFn;
|
|
79
|
+
/** Asks the user for text, in a dialog (replaceable for tests) */
|
|
80
|
+
prompt: PromptFn;
|
|
81
|
+
constructor();
|
|
82
|
+
protected willUpdate(changed: Map<PropertyKey, unknown>): void;
|
|
83
|
+
/** Go back to the graph it opened with */
|
|
84
|
+
reset(): void;
|
|
85
|
+
/** Load a graph's points */
|
|
86
|
+
load(id: string): void;
|
|
87
|
+
/** Whether the graph being edited is one of the user's own, unchanged */
|
|
88
|
+
private get ownSource();
|
|
89
|
+
/**
|
|
90
|
+
* Ask for a name and save the points as one of the user's graphs, asking before replacing another with that name.
|
|
91
|
+
* Returns the saved graph's ID, or undefined if it wasn't saved.
|
|
92
|
+
*/
|
|
93
|
+
private saveAs;
|
|
94
|
+
/**
|
|
95
|
+
* Use the graph: save it first when it's edited or unsaved (asking for a name), then fire `pc-save`.
|
|
96
|
+
*/
|
|
97
|
+
save(): Promise<void>;
|
|
98
|
+
/** Do one of the ⋮ menu's actions */
|
|
99
|
+
act(action: string): Promise<void>;
|
|
100
|
+
/** A graph's name: the presets' in the chosen language */
|
|
101
|
+
private graphName;
|
|
102
|
+
render(): import("lit").TemplateResult<1>;
|
|
103
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { PcElement, defineElement, emit } from "../../base/index.js";
|
|
2
|
+
import { askConfirm, askText } from "../../ask/index.js";
|
|
3
|
+
import "../PcDialogWindow/index.js";
|
|
4
|
+
import "../PcProfileGraph/index.js";
|
|
5
|
+
import "../PcContextMenu/index.js";
|
|
6
|
+
import "../PcButton/index.js";
|
|
7
|
+
import ProfileGraphs from "../../../lib/classes/ProfileGraphs/index.js";
|
|
8
|
+
import { linearPoints, samePoints } from "../../../lib/profiles/index.js";
|
|
9
|
+
import { css, html } from "lit";
|
|
10
|
+
import { live } from "lit/directives/live.js";
|
|
11
|
+
// src/ui/elements/PcProfileEditor/index.ts
|
|
12
|
+
/** The value of the drop-down's "Custom" option */
|
|
13
|
+
var CUSTOM = "";
|
|
14
|
+
/**
|
|
15
|
+
* A window for editing a brush setting's profile graph (see `<pc-profile-graph>`): a drop-down of the presets and the
|
|
16
|
+
* user's own graphs (it says "Custom" once the graph is edited, or for one that isn't saved), a ⋮ menu (New graph,
|
|
17
|
+
* Duplicate…, Rename… and Delete…, the last two for the user's own graphs), the graph, and Save, Reset and Dismiss.
|
|
18
|
+
*
|
|
19
|
+
* - Choosing a graph in the drop-down loads its points.
|
|
20
|
+
* - New graph starts from a straight line, and Duplicate… saves a copy of the current graph under a name ("Custom" to
|
|
21
|
+
* start with); Rename… and Delete… ask first.
|
|
22
|
+
* - Save uses the graph (firing `pc-save` with its points and ID); an edited or unsaved graph is first saved with a name
|
|
23
|
+
* it asks for, asking before replacing another of the user's graphs with that name.
|
|
24
|
+
* - Reset goes back to the graph it opened with; Dismiss, ⨉ and Escape close it (`pc-close`) without changing anything.
|
|
25
|
+
*
|
|
26
|
+
* Graphs are saved in `profiles` (the canvas's `ProfileGraphs`).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* html`<pc-profile-editor .profiles=${app.profiles} .points=${points} profile-id="overweight" label="Width"
|
|
30
|
+
* @pc-save=${(e) => use(e.detail)} @pc-close=${close}></pc-profile-editor>`
|
|
31
|
+
*/
|
|
32
|
+
var PcProfileEditor = class extends PcElement {
|
|
33
|
+
static properties = {
|
|
34
|
+
...PcElement.properties,
|
|
35
|
+
profiles: { attribute: false },
|
|
36
|
+
points: { attribute: false },
|
|
37
|
+
profileId: {
|
|
38
|
+
type: String,
|
|
39
|
+
attribute: "profile-id"
|
|
40
|
+
},
|
|
41
|
+
label: { type: String },
|
|
42
|
+
draft: { state: true },
|
|
43
|
+
sourceId: { state: true }
|
|
44
|
+
};
|
|
45
|
+
static styles = [PcElement.styles, css`
|
|
46
|
+
:host {
|
|
47
|
+
display: contents;
|
|
48
|
+
}
|
|
49
|
+
pc-dialog-window {
|
|
50
|
+
--pc-dialog-width: 340px;
|
|
51
|
+
}
|
|
52
|
+
.choose {
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
gap: var(--pc-space-2);
|
|
56
|
+
width: 100%;
|
|
57
|
+
}
|
|
58
|
+
select {
|
|
59
|
+
flex: 1;
|
|
60
|
+
min-width: 0;
|
|
61
|
+
min-height: var(--pc-control-size);
|
|
62
|
+
padding: 0 var(--pc-space-2);
|
|
63
|
+
border: 1px solid var(--pc-border);
|
|
64
|
+
border-radius: var(--pc-radius-small);
|
|
65
|
+
background: var(--pc-surface);
|
|
66
|
+
color: var(--pc-text);
|
|
67
|
+
font: inherit;
|
|
68
|
+
}
|
|
69
|
+
.actions {
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
gap: var(--pc-space-2);
|
|
73
|
+
}
|
|
74
|
+
`];
|
|
75
|
+
/** Asks the user to confirm, in a dialog (replaceable for tests) */
|
|
76
|
+
confirm = (options) => askConfirm(this.renderRoot, options);
|
|
77
|
+
/** Asks the user for text, in a dialog (replaceable for tests) */
|
|
78
|
+
prompt = (options) => askText(this.renderRoot, options);
|
|
79
|
+
constructor() {
|
|
80
|
+
super();
|
|
81
|
+
this.profiles = new ProfileGraphs();
|
|
82
|
+
this.label = "";
|
|
83
|
+
this.draft = linearPoints();
|
|
84
|
+
}
|
|
85
|
+
willUpdate(changed) {
|
|
86
|
+
super.willUpdate(changed);
|
|
87
|
+
if (changed.has("points") || changed.has("profileId")) this.reset();
|
|
88
|
+
}
|
|
89
|
+
/** Go back to the graph it opened with */
|
|
90
|
+
reset() {
|
|
91
|
+
this.draft = structuredClone(this.points ?? linearPoints());
|
|
92
|
+
const source = this.profiles.get(this.profileId);
|
|
93
|
+
this.sourceId = source && samePoints(source.points, this.draft) ? source.id : void 0;
|
|
94
|
+
}
|
|
95
|
+
/** Load a graph's points */
|
|
96
|
+
load(id) {
|
|
97
|
+
const graph = this.profiles.get(id);
|
|
98
|
+
if (!graph) return;
|
|
99
|
+
this.draft = structuredClone(graph.points);
|
|
100
|
+
this.sourceId = graph.id;
|
|
101
|
+
}
|
|
102
|
+
/** Whether the graph being edited is one of the user's own, unchanged */
|
|
103
|
+
get ownSource() {
|
|
104
|
+
return this.sourceId !== void 0 && !this.profiles.isPreset(this.sourceId);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Ask for a name and save the points as one of the user's graphs, asking before replacing another with that name.
|
|
108
|
+
* Returns the saved graph's ID, or undefined if it wasn't saved.
|
|
109
|
+
*/
|
|
110
|
+
async saveAs(value) {
|
|
111
|
+
const name = (await this.prompt({
|
|
112
|
+
heading: this.t("paintCanvas.profileEditor.saveHeading"),
|
|
113
|
+
label: this.t("paintCanvas.profileEditor.name"),
|
|
114
|
+
value,
|
|
115
|
+
confirm: this.t("paintCanvas.common.save"),
|
|
116
|
+
cancel: this.t("paintCanvas.common.cancel")
|
|
117
|
+
}))?.trim();
|
|
118
|
+
if (!name) return void 0;
|
|
119
|
+
const existing = this.profiles.findByName(name);
|
|
120
|
+
if (existing && !await this.confirm({
|
|
121
|
+
heading: this.t("paintCanvas.profileEditor.replaceHeading"),
|
|
122
|
+
message: this.t("paintCanvas.profileEditor.replaceConfirm", { name }),
|
|
123
|
+
confirm: this.t("paintCanvas.presets.replace"),
|
|
124
|
+
cancel: this.t("paintCanvas.common.cancel"),
|
|
125
|
+
cancelling: true
|
|
126
|
+
})) return void 0;
|
|
127
|
+
const saved = this.profiles.save({
|
|
128
|
+
id: existing?.id,
|
|
129
|
+
name,
|
|
130
|
+
points: this.draft
|
|
131
|
+
});
|
|
132
|
+
if (saved) this.sourceId = saved.id;
|
|
133
|
+
return saved?.id;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Use the graph: save it first when it's edited or unsaved (asking for a name), then fire `pc-save`.
|
|
137
|
+
*/
|
|
138
|
+
async save() {
|
|
139
|
+
const id = this.sourceId ?? await this.saveAs(this.t("paintCanvas.profileEditor.custom"));
|
|
140
|
+
if (!id) return;
|
|
141
|
+
emit(this, "pc-save", {
|
|
142
|
+
points: structuredClone(this.draft),
|
|
143
|
+
profileId: id
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/** Do one of the ⋮ menu's actions */
|
|
147
|
+
async act(action) {
|
|
148
|
+
const graph = this.profiles.get(this.sourceId);
|
|
149
|
+
if (action === "new") {
|
|
150
|
+
this.draft = linearPoints();
|
|
151
|
+
this.sourceId = void 0;
|
|
152
|
+
} else if (action === "duplicate") await this.saveAs(this.t("paintCanvas.profileEditor.custom"));
|
|
153
|
+
else if (action === "rename" && graph && this.ownSource) {
|
|
154
|
+
const name = await this.prompt({
|
|
155
|
+
heading: this.t("paintCanvas.profileEditor.renameHeading"),
|
|
156
|
+
label: this.t("paintCanvas.profileEditor.name"),
|
|
157
|
+
value: graph.name,
|
|
158
|
+
confirm: this.t("paintCanvas.common.save"),
|
|
159
|
+
cancel: this.t("paintCanvas.common.cancel")
|
|
160
|
+
});
|
|
161
|
+
if (name && this.profiles.rename(graph.id, name)) this.requestUpdate();
|
|
162
|
+
} else if (action === "delete" && graph && this.ownSource) {
|
|
163
|
+
if (await this.confirm({
|
|
164
|
+
heading: this.t("paintCanvas.profileEditor.deleteHeading"),
|
|
165
|
+
message: this.t("paintCanvas.profileEditor.deleteConfirm", { name: graph.name }),
|
|
166
|
+
confirm: this.t("paintCanvas.common.delete"),
|
|
167
|
+
cancel: this.t("paintCanvas.common.cancel"),
|
|
168
|
+
cancelling: true
|
|
169
|
+
}) && this.profiles.remove(graph.id)) this.sourceId = void 0;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** A graph's name: the presets' in the chosen language */
|
|
173
|
+
graphName(id, name) {
|
|
174
|
+
return this.profiles.isPreset(id) ? this.t(`paintCanvas.profiles.${id}`) : name;
|
|
175
|
+
}
|
|
176
|
+
render() {
|
|
177
|
+
const own = this.ownSource;
|
|
178
|
+
const items = [
|
|
179
|
+
{
|
|
180
|
+
value: "new",
|
|
181
|
+
label: this.t("paintCanvas.profileEditor.new")
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
value: "duplicate",
|
|
185
|
+
label: this.t("paintCanvas.profileEditor.duplicate")
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
value: "rename",
|
|
189
|
+
label: this.t("paintCanvas.profileEditor.rename"),
|
|
190
|
+
disabled: !own
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
value: "delete",
|
|
194
|
+
label: this.t("paintCanvas.profileEditor.delete"),
|
|
195
|
+
disabled: !own,
|
|
196
|
+
danger: true
|
|
197
|
+
}
|
|
198
|
+
];
|
|
199
|
+
const title = this.t("paintCanvas.profileEditor.title", { param: this.label });
|
|
200
|
+
return html`<pc-dialog-window
|
|
201
|
+
open
|
|
202
|
+
shaded
|
|
203
|
+
label=${title}
|
|
204
|
+
@pc-dismiss=${(event) => {
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
emit(this, "pc-close");
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
<div slot="header-middle" class="choose">
|
|
210
|
+
<select
|
|
211
|
+
aria-label=${title}
|
|
212
|
+
.value=${live(this.sourceId ?? CUSTOM)}
|
|
213
|
+
@change=${(event) => this.load(event.target.value)}
|
|
214
|
+
>
|
|
215
|
+
${this.sourceId === void 0 ? html`<option value=${CUSTOM}>
|
|
216
|
+
${this.t("paintCanvas.profileEditor.custom")}
|
|
217
|
+
</option>` : ""}
|
|
218
|
+
${this.profiles.all.map((graph) => html`<option
|
|
219
|
+
value=${graph.id}
|
|
220
|
+
.selected=${graph.id === this.sourceId}
|
|
221
|
+
>
|
|
222
|
+
${this.graphName(graph.id, graph.name)}
|
|
223
|
+
</option>`)}
|
|
224
|
+
</select>
|
|
225
|
+
<pc-context-menu
|
|
226
|
+
label=${this.t("paintCanvas.profileEditor.actions")}
|
|
227
|
+
.items=${items}
|
|
228
|
+
@pc-select=${(event) => void this.act(event.detail.value)}
|
|
229
|
+
></pc-context-menu>
|
|
230
|
+
</div>
|
|
231
|
+
<pc-profile-graph
|
|
232
|
+
slot="body"
|
|
233
|
+
label=${title}
|
|
234
|
+
.points=${this.draft}
|
|
235
|
+
@pc-change=${(event) => {
|
|
236
|
+
this.draft = event.detail.points;
|
|
237
|
+
this.sourceId = void 0;
|
|
238
|
+
}}
|
|
239
|
+
></pc-profile-graph>
|
|
240
|
+
<div slot="footer-middle" class="actions">
|
|
241
|
+
<pc-button class="save" @click=${() => void this.save()}>
|
|
242
|
+
${this.t("paintCanvas.common.save")}
|
|
243
|
+
</pc-button>
|
|
244
|
+
<pc-button class="reset" variant="cancel" @click=${() => this.reset()}>
|
|
245
|
+
${this.t("paintCanvas.profileEditor.reset")}
|
|
246
|
+
</pc-button>
|
|
247
|
+
<pc-button
|
|
248
|
+
class="dismiss"
|
|
249
|
+
variant="dismiss"
|
|
250
|
+
@click=${() => emit(this, "pc-close")}
|
|
251
|
+
>
|
|
252
|
+
${this.t("paintCanvas.common.dismiss")}
|
|
253
|
+
</pc-button>
|
|
254
|
+
</div>
|
|
255
|
+
</pc-dialog-window>`;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
defineElement("pc-profile-editor", PcProfileEditor);
|
|
259
|
+
export { PcProfileEditor };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { PcElement } from "../../base";
|
|
2
|
+
import { Interpolation, type ProfilePoint } from "../../../lib/profiles";
|
|
3
|
+
/**
|
|
4
|
+
* The SVG path of a curve through points, drawn as short straight pieces (y is flipped: up is less negative).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* curvePath(linearPoints()); // "M0,10 L0.1,9.9 …"
|
|
8
|
+
*/
|
|
9
|
+
export declare const curvePath: (points: readonly ProfilePoint[]) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Move a point within the grid, keeping it between its neighbours (and the first and last points at the edges), to
|
|
12
|
+
* multiples of 0.1. Returns new points.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* movePoint(points, 1, 4.04, -3); // points[1] at { x: 4, y: -3 }
|
|
16
|
+
*/
|
|
17
|
+
export declare const movePoint: (points: readonly ProfilePoint[], index: number, x: number, y: number) => ProfilePoint[];
|
|
18
|
+
/**
|
|
19
|
+
* A profile graph to edit (see `@lvl99dotcom/paintcanvas/lib/profiles`): a 10 × 10 grid with the curve through its
|
|
20
|
+
* points, from the setting's min at the bottom left to its max at the top right.
|
|
21
|
+
*
|
|
22
|
+
* - Pressing the line adds a point there (smooth), selected.
|
|
23
|
+
* - Pressing a point selects it; dragging moves it (between its neighbours; the first and last stay at the edges).
|
|
24
|
+
* - With a point selected, the arrow keys move it a grid unit, and the buttons below make it a sharp corner (linear)
|
|
25
|
+
* or smooth (bezier cubic), or remove it (−; not the first or last).
|
|
26
|
+
*
|
|
27
|
+
* Points are focusable buttons (Tab moves between them; focusing one selects it). Fires `pc-change` (detail:
|
|
28
|
+
* `{ points }`) whenever the points change, after changing `points` itself.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* html`<pc-profile-graph .points=${points} @pc-change=${(e) => (points = e.detail.points)}></pc-profile-graph>`
|
|
32
|
+
*/
|
|
33
|
+
export declare class PcProfileGraph extends PcElement {
|
|
34
|
+
static properties: {
|
|
35
|
+
points: {
|
|
36
|
+
attribute: boolean;
|
|
37
|
+
};
|
|
38
|
+
selected: {
|
|
39
|
+
type: NumberConstructor;
|
|
40
|
+
};
|
|
41
|
+
label: {
|
|
42
|
+
type: StringConstructor;
|
|
43
|
+
};
|
|
44
|
+
translations: {
|
|
45
|
+
attribute: boolean;
|
|
46
|
+
};
|
|
47
|
+
icons: {
|
|
48
|
+
attribute: boolean;
|
|
49
|
+
};
|
|
50
|
+
theme: {
|
|
51
|
+
type: StringConstructor;
|
|
52
|
+
reflect: boolean;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
static styles: import("lit").CSSResultGroup[];
|
|
56
|
+
/** The points, from left to right */
|
|
57
|
+
points: ProfilePoint[];
|
|
58
|
+
/** The selected point's index, if any */
|
|
59
|
+
selected?: number;
|
|
60
|
+
/** The graph's name for screen readers */
|
|
61
|
+
label: string;
|
|
62
|
+
/** The point being dragged */
|
|
63
|
+
private dragging?;
|
|
64
|
+
constructor();
|
|
65
|
+
/** Change the points and tell listeners */
|
|
66
|
+
private setPoints;
|
|
67
|
+
/** A pointer's position in grid units */
|
|
68
|
+
private gridAt;
|
|
69
|
+
/**
|
|
70
|
+
* Add a point (smooth) where a press on the line is, and select it. Does nothing away from the line or when full.
|
|
71
|
+
*/
|
|
72
|
+
private onGraphDown;
|
|
73
|
+
/** Select a point and start dragging it */
|
|
74
|
+
private startDrag;
|
|
75
|
+
private onMove;
|
|
76
|
+
private onUp;
|
|
77
|
+
/** Move the selected point a grid unit with the arrow keys */
|
|
78
|
+
private onPointKeyDown;
|
|
79
|
+
/** Make the selected point a sharp corner or smooth */
|
|
80
|
+
setInterpolation(i: Interpolation): void;
|
|
81
|
+
/** Remove the selected point (not the first or last) */
|
|
82
|
+
removeSelected(): void;
|
|
83
|
+
render(): import("lit").TemplateResult<1>;
|
|
84
|
+
}
|