@molecule/app-feature-image-canvas-vue 0.0.0-stage → 0.0.1-stage

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # @molecule/app-feature-image-canvas-vue
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Canvas2D image-editing surface — accepts an image source, applies a filter chain (brightness, contrast, saturation, hue, sepia, grayscale, blur, sharpen), supports zoom + pan, exports back to data URL
4
+
5
+ ```
6
+ npm install @molecule/app-feature-image-canvas-vue
7
+ ```
8
+
9
+ Part of the [Molecule](https://www.molecule.dev) package fleet. This page carries the manifest summary; the full generated documentation ships with the package's first committed version.
10
+
11
+ License: Apache-2.0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Vue Canvas2D image-editing surface — a filter chain, pointer-drag panning,
3
+ * wheel zooming and a data-URL export handle.
4
+ *
5
+ * Vue counterpart of `@molecule/app-feature-image-canvas-react`'s
6
+ * `ImageCanvas` — the same props (React names), the same DOM for the same
7
+ * input.
8
+ *
9
+ * @module
10
+ */
11
+ import { type PropType, type VNode } from 'vue';
12
+ import type { ImageCanvasFilters, ImageCanvasProps, PanOffset } from './types.js';
13
+ /**
14
+ * Canvas2D image-editing surface. Renders a source image onto a canvas with a
15
+ * filter chain (brightness, contrast, saturation, hue, sepia, grayscale, blur,
16
+ * sharpen), pointer-event drag panning, and wheel zooming. The current state
17
+ * can be exported to a data URL via the `exportRef` imperative handle.
18
+ *
19
+ * All styling routes through `getClassMap()` (no raw class names). All
20
+ * user-visible text routes through `t()` so the canvas translates via the
21
+ * companion locale bond.
22
+ *
23
+ * @param props - Component props (see {@link ImageCanvasProps}).
24
+ * @returns The image-canvas component.
25
+ */
26
+ export declare const ImageCanvas: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
27
+ src: {
28
+ type: PropType<string | HTMLImageElement>;
29
+ required: true;
30
+ };
31
+ filters: {
32
+ type: PropType<ImageCanvasFilters>;
33
+ };
34
+ zoom: {
35
+ type: NumberConstructor;
36
+ default: number;
37
+ };
38
+ pan: {
39
+ type: PropType<PanOffset>;
40
+ };
41
+ onChange: {
42
+ type: PropType<NonNullable<ImageCanvasProps["onChange"]>>;
43
+ };
44
+ exportRef: {
45
+ type: PropType<NonNullable<ImageCanvasProps["exportRef"]>>;
46
+ };
47
+ width: {
48
+ type: NumberConstructor;
49
+ default: number;
50
+ };
51
+ height: {
52
+ type: NumberConstructor;
53
+ default: number;
54
+ };
55
+ className: StringConstructor;
56
+ }>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
57
+ src: {
58
+ type: PropType<string | HTMLImageElement>;
59
+ required: true;
60
+ };
61
+ filters: {
62
+ type: PropType<ImageCanvasFilters>;
63
+ };
64
+ zoom: {
65
+ type: NumberConstructor;
66
+ default: number;
67
+ };
68
+ pan: {
69
+ type: PropType<PanOffset>;
70
+ };
71
+ onChange: {
72
+ type: PropType<NonNullable<ImageCanvasProps["onChange"]>>;
73
+ };
74
+ exportRef: {
75
+ type: PropType<NonNullable<ImageCanvasProps["exportRef"]>>;
76
+ };
77
+ width: {
78
+ type: NumberConstructor;
79
+ default: number;
80
+ };
81
+ height: {
82
+ type: NumberConstructor;
83
+ default: number;
84
+ };
85
+ className: StringConstructor;
86
+ }>> & Readonly<{}>, {
87
+ zoom: number;
88
+ width: number;
89
+ height: number;
90
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
91
+ //# sourceMappingURL=ImageCanvas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageCanvas.d.ts","sourceRoot":"","sources":["../src/ImageCanvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAOL,KAAK,QAAQ,EAEb,KAAK,KAAK,EAEX,MAAM,KAAK,CAAA;AAOZ,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEjF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW;;cAKQ,QAAQ,CAAC,MAAM,GAAG,gBAAgB,CAAC;;;;cAI7C,QAAQ,CAAC,kBAAkB,CAAC;;;;;;;cAO5B,QAAQ,CAAC,SAAS,CAAC;;;cAGjB,QAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC;;;cAGrD,QAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;;;;;;;;;;;UAqL3D,KAAK;;cAtMY,QAAQ,CAAC,MAAM,GAAG,gBAAgB,CAAC;;;;cAI7C,QAAQ,CAAC,kBAAkB,CAAC;;;;;;;cAO5B,QAAQ,CAAC,SAAS,CAAC;;;cAGjB,QAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC;;;cAGrD,QAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;4EA8PxE,CAAA"}
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Vue Canvas2D image-editing surface — a filter chain, pointer-drag panning,
3
+ * wheel zooming and a data-URL export handle.
4
+ *
5
+ * Vue counterpart of `@molecule/app-feature-image-canvas-react`'s
6
+ * `ImageCanvas` — the same props (React names), the same DOM for the same
7
+ * input.
8
+ *
9
+ * @module
10
+ */
11
+ import { computed, defineComponent, h, onBeforeUnmount, onMounted, ref, watch, } from 'vue';
12
+ import { getClassMap } from '@molecule/app-ui';
13
+ import { useTranslation } from '@molecule/app-vue';
14
+ import { clamp, clampPan, composeFilterString } from './helpers.js';
15
+ import { isImageElement } from './image-source.js';
16
+ /**
17
+ * Canvas2D image-editing surface. Renders a source image onto a canvas with a
18
+ * filter chain (brightness, contrast, saturation, hue, sepia, grayscale, blur,
19
+ * sharpen), pointer-event drag panning, and wheel zooming. The current state
20
+ * can be exported to a data URL via the `exportRef` imperative handle.
21
+ *
22
+ * All styling routes through `getClassMap()` (no raw class names). All
23
+ * user-visible text routes through `t()` so the canvas translates via the
24
+ * companion locale bond.
25
+ *
26
+ * @param props - Component props (see {@link ImageCanvasProps}).
27
+ * @returns The image-canvas component.
28
+ */
29
+ export const ImageCanvas = defineComponent({
30
+ name: 'ImageCanvas',
31
+ props: {
32
+ // A URL string or an already-loaded `HTMLImageElement`.
33
+ src: {
34
+ type: [String, Object],
35
+ required: true,
36
+ },
37
+ filters: {
38
+ type: Object,
39
+ },
40
+ zoom: {
41
+ type: Number,
42
+ default: 1,
43
+ },
44
+ pan: {
45
+ type: Object,
46
+ },
47
+ onChange: {
48
+ type: Function,
49
+ },
50
+ exportRef: {
51
+ type: Object,
52
+ },
53
+ width: {
54
+ type: Number,
55
+ default: 512,
56
+ },
57
+ height: {
58
+ type: Number,
59
+ default: 512,
60
+ },
61
+ className: String,
62
+ },
63
+ setup(props) {
64
+ const cm = getClassMap();
65
+ const { t } = useTranslation();
66
+ const canvasRef = ref(null);
67
+ const internalImage = ref(isImageElement(props.src)
68
+ ? props.src
69
+ : null);
70
+ const loadError = ref(null);
71
+ const safeZoom = computed(() => {
72
+ const zoom = props.zoom;
73
+ return Number.isFinite(zoom) && zoom > 0 ? zoom : 1;
74
+ });
75
+ const safePan = computed(() => ({
76
+ x: Number.isFinite(props.pan?.x) ? props.pan?.x : 0,
77
+ y: Number.isFinite(props.pan?.y) ? props.pan?.y : 0,
78
+ }));
79
+ const filterString = computed(() => composeFilterString(props.filters));
80
+ // Drag state lives outside reactive state: handlers mutate it without
81
+ // re-rendering, exactly like React's ref.
82
+ let dragState = { pointerId: null, startX: 0, startY: 0, startPan: { x: 0, y: 0 } };
83
+ // Load the source image when the prop is a URL string.
84
+ watch(() => props.src, (src, _previous, onCleanup) => {
85
+ if (typeof src !== 'string') {
86
+ if (isImageElement(src)) {
87
+ internalImage.value = src;
88
+ loadError.value = null;
89
+ }
90
+ return;
91
+ }
92
+ let cancelled = false;
93
+ onCleanup(() => {
94
+ cancelled = true;
95
+ });
96
+ loadError.value = null;
97
+ const img = new Image();
98
+ img.crossOrigin = 'anonymous';
99
+ img.onload = () => {
100
+ if (cancelled)
101
+ return;
102
+ internalImage.value = img;
103
+ };
104
+ img.onerror = () => {
105
+ if (cancelled)
106
+ return;
107
+ loadError.value = src;
108
+ internalImage.value = null;
109
+ };
110
+ img.src = src;
111
+ }, { immediate: true });
112
+ // Re-paint whenever the image, viewport, or filter chain changes.
113
+ const paint = () => {
114
+ const canvas = canvasRef.value;
115
+ if (!canvas)
116
+ return;
117
+ const ctx = canvas.getContext('2d');
118
+ if (!ctx)
119
+ return;
120
+ const image = internalImage.value;
121
+ const zoom = safeZoom.value;
122
+ const pan = safePan.value;
123
+ ctx.save();
124
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
125
+ if (!image) {
126
+ ctx.restore();
127
+ return;
128
+ }
129
+ ctx.filter = filterString.value;
130
+ const drawWidth = image.naturalWidth * zoom;
131
+ const drawHeight = image.naturalHeight * zoom;
132
+ const dx = canvas.width / 2 - drawWidth / 2 + pan.x;
133
+ const dy = canvas.height / 2 - drawHeight / 2 + pan.y;
134
+ ctx.drawImage(image, dx, dy, drawWidth, drawHeight);
135
+ ctx.restore();
136
+ };
137
+ watch([
138
+ internalImage,
139
+ filterString,
140
+ safeZoom,
141
+ () => safePan.value.x,
142
+ () => safePan.value.y,
143
+ () => props.width,
144
+ () => props.height,
145
+ ], paint, { flush: 'post' });
146
+ // The canvas element exists only after mount, so the first paint runs here;
147
+ // the watcher above covers every later change.
148
+ onMounted(paint);
149
+ onMounted(() => {
150
+ if (!props.exportRef)
151
+ return;
152
+ props.exportRef.current = {
153
+ toDataURL: (type, quality) => {
154
+ const canvas = canvasRef.value;
155
+ if (!canvas)
156
+ return '';
157
+ return canvas.toDataURL(type, quality);
158
+ },
159
+ };
160
+ });
161
+ onBeforeUnmount(() => {
162
+ if (props.exportRef)
163
+ props.exportRef.current = null;
164
+ });
165
+ const handlePointerDown = (event) => {
166
+ if (!canvasRef.value)
167
+ return;
168
+ canvasRef.value.setPointerCapture(event.pointerId);
169
+ dragState = {
170
+ pointerId: event.pointerId,
171
+ startX: event.clientX,
172
+ startY: event.clientY,
173
+ startPan: { ...safePan.value },
174
+ };
175
+ };
176
+ const handlePointerMove = (event) => {
177
+ const state = dragState;
178
+ if (state.pointerId !== event.pointerId)
179
+ return;
180
+ const dx = event.clientX - state.startX;
181
+ const dy = event.clientY - state.startY;
182
+ const image = internalImage.value;
183
+ const next = clampPan({ x: state.startPan.x + dx, y: state.startPan.y + dy }, { width: props.width, height: props.height }, image
184
+ ? { width: image.naturalWidth, height: image.naturalHeight }
185
+ : { width: props.width, height: props.height }, safeZoom.value);
186
+ props.onChange?.({ zoom: safeZoom.value, pan: next });
187
+ };
188
+ const endDrag = (event) => {
189
+ const state = dragState;
190
+ if (state.pointerId !== event.pointerId)
191
+ return;
192
+ const node = canvasRef.value;
193
+ if (node && node.hasPointerCapture(event.pointerId)) {
194
+ node.releasePointerCapture(event.pointerId);
195
+ }
196
+ dragState = { pointerId: null, startX: 0, startY: 0, startPan: { x: 0, y: 0 } };
197
+ };
198
+ const handleWheel = (event) => {
199
+ // Negative deltaY = scroll up = zoom in.
200
+ const factor = event.deltaY < 0 ? 1.1 : 1 / 1.1;
201
+ const nextZoom = clamp(safeZoom.value * factor, 0.05, 32);
202
+ props.onChange?.({ zoom: nextZoom, pan: safePan.value });
203
+ };
204
+ return () => {
205
+ const ariaLabel = t('imageCanvas.aria.region', {}, { defaultValue: 'Image canvas' });
206
+ const dragLabel = t('imageCanvas.aria.canvas', {}, { defaultValue: 'Drag to pan, scroll to zoom' });
207
+ const loadingLabel = t('imageCanvas.loading', {}, { defaultValue: 'Loading image…' });
208
+ const errorLabel = t('imageCanvas.error', {}, { defaultValue: 'Image failed to load.' });
209
+ const width = props.width;
210
+ const height = props.height;
211
+ const image = internalImage.value;
212
+ const error = loadError.value;
213
+ const containerStyle = {
214
+ display: 'inline-block',
215
+ width: `${width}px`,
216
+ height: `${height}px`,
217
+ position: 'relative',
218
+ };
219
+ const canvasStyle = {
220
+ display: 'block',
221
+ width: `${width}px`,
222
+ height: `${height}px`,
223
+ cursor: props.onChange ? 'grab' : 'default',
224
+ touchAction: 'none',
225
+ };
226
+ const noteClass = cm.cn(cm.textSize('xs'), cm.sp('p', 2));
227
+ return h('div', {
228
+ role: 'region',
229
+ 'aria-label': ariaLabel,
230
+ 'data-mol-id': 'image-canvas',
231
+ class: cm.cn(props.className),
232
+ style: containerStyle,
233
+ }, [
234
+ h('canvas', {
235
+ ref: canvasRef,
236
+ width,
237
+ height,
238
+ 'aria-label': dragLabel,
239
+ 'data-mol-id': 'image-canvas-surface',
240
+ 'data-loading': image ? 'false' : error ? 'false' : 'true',
241
+ 'data-error': error ? 'true' : 'false',
242
+ style: canvasStyle,
243
+ // `on:<name>` binds the native event verbatim; Vue's `onX` form
244
+ // hyphenates a multi-word name (`onPointerDown` → `pointer-down`).
245
+ 'on:pointerdown': handlePointerDown,
246
+ 'on:pointermove': handlePointerMove,
247
+ 'on:pointerup': endDrag,
248
+ 'on:pointercancel': endDrag,
249
+ 'on:wheel': handleWheel,
250
+ }),
251
+ !image && !error
252
+ ? h('p', { class: noteClass, 'data-mol-id': 'image-canvas-loading' }, loadingLabel)
253
+ : null,
254
+ error
255
+ ? h('p', { class: noteClass, 'data-mol-id': 'image-canvas-error', role: 'alert' }, errorLabel)
256
+ : null,
257
+ ]);
258
+ };
259
+ },
260
+ });
261
+ //# sourceMappingURL=ImageCanvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageCanvas.js","sourceRoot":"","sources":["../src/ImageCanvas.ts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AAK,EAAE,SAAS,EAAE,aAAa,EAAE,sBAAsB,EAAE,EAAE,YAAY,CAAC;oBACnF,CAAC,CAAC,IAAI;gBACR,KAAK;oBACH,CAAC,CAAC,CAAC,CACC,GAAG,EACH,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,EACxE,UAAU,CACX;oBACH,CAAC,CAAC,IAAI;aACT,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Framework-free helpers of the Vue Canvas2D image-editing surface — the same
3
+ * values `@molecule/app-feature-image-canvas-react` exports.
4
+ *
5
+ * @module
6
+ */
7
+ import type { ImageCanvasFilters, PanOffset } from './types.js';
8
+ /**
9
+ * Clamp a numeric value into the closed interval `[min, max]`. Returns
10
+ * `min` for non-finite inputs.
11
+ *
12
+ * @param value - The value to clamp.
13
+ * @param min - Inclusive minimum.
14
+ * @param max - Inclusive maximum.
15
+ * @returns The clamped value.
16
+ */
17
+ export declare function clamp(value: number, min: number, max: number): number;
18
+ /**
19
+ * Compose a CSS filter string from a set of `ImageCanvasFilters` values.
20
+ * Out-of-range values are clamped; omitted / non-finite fields are
21
+ * ignored. Returns `'none'` when no filters are active so callers can
22
+ * assign the result directly to `CanvasRenderingContext2D.filter`.
23
+ *
24
+ * @param filters - The filter parameters. May be `undefined`.
25
+ * @returns A CSS filter string, or `'none'` when nothing applies.
26
+ */
27
+ export declare function composeFilterString(filters?: ImageCanvasFilters): string;
28
+ /**
29
+ * Convert a screen-space (canvas-relative) point into image-space
30
+ * coordinates given the current zoom + pan and the source image
31
+ * dimensions. Useful for tools that need to know which image pixel a
32
+ * pointer event hit (cropping, picking, masking).
33
+ *
34
+ * @param point - The canvas-space point in CSS pixels (origin top-left
35
+ * of the canvas element).
36
+ * @param canvasSize - The canvas size in CSS pixels.
37
+ * @param imageSize - The source image's natural size in pixels.
38
+ * @param zoom - The current zoom factor. Non-positive values fall back
39
+ * to `1`.
40
+ * @param pan - The current pan offset in CSS pixels.
41
+ * @returns The corresponding point in image-space coordinates.
42
+ */
43
+ export declare function screenToCanvas(point: {
44
+ x: number;
45
+ y: number;
46
+ }, canvasSize: {
47
+ width: number;
48
+ height: number;
49
+ }, imageSize: {
50
+ width: number;
51
+ height: number;
52
+ }, zoom: number, pan: PanOffset): {
53
+ x: number;
54
+ y: number;
55
+ };
56
+ /**
57
+ * Clamp a pan offset so the (zoomed) image cannot be dragged entirely
58
+ * off-canvas. The clamp keeps at least half of the image visible in
59
+ * each axis. Non-finite inputs are treated as `0`.
60
+ *
61
+ * @param pan - The desired pan offset, in CSS pixels.
62
+ * @param canvasSize - The canvas size in CSS pixels.
63
+ * @param imageSize - The source image's natural size in pixels.
64
+ * @param zoom - The current zoom factor. Non-positive values fall back
65
+ * to `1`.
66
+ * @returns The clamped pan offset.
67
+ */
68
+ export declare function clampPan(pan: PanOffset, canvasSize: {
69
+ width: number;
70
+ height: number;
71
+ }, imageSize: {
72
+ width: number;
73
+ height: number;
74
+ }, zoom: number): PanOffset;
75
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE/D;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAuCxE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC/B,UAAU,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7C,SAAS,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC5C,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,SAAS,GACb;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAa1B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,SAAS,EACd,UAAU,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7C,SAAS,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC5C,IAAI,EAAE,MAAM,GACX,SAAS,CAgBX"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Framework-free helpers of the Vue Canvas2D image-editing surface — the same
3
+ * values `@molecule/app-feature-image-canvas-react` exports.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * Clamp a numeric value into the closed interval `[min, max]`. Returns
9
+ * `min` for non-finite inputs.
10
+ *
11
+ * @param value - The value to clamp.
12
+ * @param min - Inclusive minimum.
13
+ * @param max - Inclusive maximum.
14
+ * @returns The clamped value.
15
+ */
16
+ export function clamp(value, min, max) {
17
+ if (!Number.isFinite(value))
18
+ return min;
19
+ if (value < min)
20
+ return min;
21
+ if (value > max)
22
+ return max;
23
+ return value;
24
+ }
25
+ /**
26
+ * Compose a CSS filter string from a set of `ImageCanvasFilters` values.
27
+ * Out-of-range values are clamped; omitted / non-finite fields are
28
+ * ignored. Returns `'none'` when no filters are active so callers can
29
+ * assign the result directly to `CanvasRenderingContext2D.filter`.
30
+ *
31
+ * @param filters - The filter parameters. May be `undefined`.
32
+ * @returns A CSS filter string, or `'none'` when nothing applies.
33
+ */
34
+ export function composeFilterString(filters) {
35
+ if (!filters)
36
+ return 'none';
37
+ const parts = [];
38
+ if (filters.brightness !== undefined && Number.isFinite(filters.brightness)) {
39
+ const v = Math.max(0, filters.brightness);
40
+ if (v !== 1)
41
+ parts.push(`brightness(${v})`);
42
+ }
43
+ if (filters.contrast !== undefined && Number.isFinite(filters.contrast)) {
44
+ const v = Math.max(0, filters.contrast);
45
+ if (v !== 1)
46
+ parts.push(`contrast(${v})`);
47
+ }
48
+ if (filters.saturation !== undefined && Number.isFinite(filters.saturation)) {
49
+ const v = Math.max(0, filters.saturation);
50
+ if (v !== 1)
51
+ parts.push(`saturate(${v})`);
52
+ }
53
+ if (filters.hue !== undefined && Number.isFinite(filters.hue)) {
54
+ const v = ((filters.hue % 360) + 360) % 360;
55
+ if (v !== 0)
56
+ parts.push(`hue-rotate(${v}deg)`);
57
+ }
58
+ if (filters.sepia !== undefined && Number.isFinite(filters.sepia)) {
59
+ const v = clamp(filters.sepia, 0, 1);
60
+ if (v > 0)
61
+ parts.push(`sepia(${v})`);
62
+ }
63
+ if (filters.grayscale !== undefined && Number.isFinite(filters.grayscale)) {
64
+ const v = clamp(filters.grayscale, 0, 1);
65
+ if (v > 0)
66
+ parts.push(`grayscale(${v})`);
67
+ }
68
+ if (filters.blur !== undefined && Number.isFinite(filters.blur)) {
69
+ const v = Math.max(0, filters.blur);
70
+ if (v > 0)
71
+ parts.push(`blur(${v}px)`);
72
+ }
73
+ if (filters.sharpen !== undefined && Number.isFinite(filters.sharpen)) {
74
+ const v = clamp(filters.sharpen, 0, 1);
75
+ // Approximate sharpen as a small contrast bump. 1.0 = +50% contrast.
76
+ if (v > 0)
77
+ parts.push(`contrast(${1 + 0.5 * v})`);
78
+ }
79
+ return parts.length === 0 ? 'none' : parts.join(' ');
80
+ }
81
+ /**
82
+ * Convert a screen-space (canvas-relative) point into image-space
83
+ * coordinates given the current zoom + pan and the source image
84
+ * dimensions. Useful for tools that need to know which image pixel a
85
+ * pointer event hit (cropping, picking, masking).
86
+ *
87
+ * @param point - The canvas-space point in CSS pixels (origin top-left
88
+ * of the canvas element).
89
+ * @param canvasSize - The canvas size in CSS pixels.
90
+ * @param imageSize - The source image's natural size in pixels.
91
+ * @param zoom - The current zoom factor. Non-positive values fall back
92
+ * to `1`.
93
+ * @param pan - The current pan offset in CSS pixels.
94
+ * @returns The corresponding point in image-space coordinates.
95
+ */
96
+ export function screenToCanvas(point, canvasSize, imageSize, zoom, pan) {
97
+ const safeZoom = Number.isFinite(zoom) && zoom > 0 ? zoom : 1;
98
+ const cx = canvasSize.width / 2;
99
+ const cy = canvasSize.height / 2;
100
+ // The image is drawn centred at (cx + pan.x, cy + pan.y) and scaled by
101
+ // `safeZoom` from its natural size. Inverting that mapping yields the
102
+ // image-space pixel for an arbitrary canvas-space point.
103
+ const dx = point.x - cx - pan.x;
104
+ const dy = point.y - cy - pan.y;
105
+ return {
106
+ x: dx / safeZoom + imageSize.width / 2,
107
+ y: dy / safeZoom + imageSize.height / 2,
108
+ };
109
+ }
110
+ /**
111
+ * Clamp a pan offset so the (zoomed) image cannot be dragged entirely
112
+ * off-canvas. The clamp keeps at least half of the image visible in
113
+ * each axis. Non-finite inputs are treated as `0`.
114
+ *
115
+ * @param pan - The desired pan offset, in CSS pixels.
116
+ * @param canvasSize - The canvas size in CSS pixels.
117
+ * @param imageSize - The source image's natural size in pixels.
118
+ * @param zoom - The current zoom factor. Non-positive values fall back
119
+ * to `1`.
120
+ * @returns The clamped pan offset.
121
+ */
122
+ export function clampPan(pan, canvasSize, imageSize, zoom) {
123
+ const safeZoom = Number.isFinite(zoom) && zoom > 0 ? zoom : 1;
124
+ const halfImgW = (imageSize.width * safeZoom) / 2;
125
+ const halfImgH = (imageSize.height * safeZoom) / 2;
126
+ const halfCanvasW = canvasSize.width / 2;
127
+ const halfCanvasH = canvasSize.height / 2;
128
+ // Allow the image centre to move up to (halfCanvas + halfImg/2) — i.e.
129
+ // half the image always stays visible.
130
+ const maxX = halfCanvasW + halfImgW / 2;
131
+ const maxY = halfCanvasH + halfImgH / 2;
132
+ const px = Number.isFinite(pan.x) ? pan.x : 0;
133
+ const py = Number.isFinite(pan.y) ? pan.y : 0;
134
+ return {
135
+ x: clamp(px, -maxX, maxX),
136
+ y: clamp(py, -maxY, maxY),
137
+ };
138
+ }
139
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC3D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,CAAA;IACvC,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,GAAG,CAAA;IAC3B,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,GAAG,CAAA;IAC3B,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA4B;IAC9D,IAAI,CAAC,OAAO;QAAE,OAAO,MAAM,CAAA;IAC3B,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5E,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;QACzC,IAAI,CAAC,KAAK,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IAC7C,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxE,MAAM,CAAC,GAAG,IAAI,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CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7C,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7C,OAAO;QACL,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;QACzB,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;KAC1B,CAAA;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Internal source guard of the Vue Canvas2D image-editing surface: whether
3
+ * the `src` prop is an already-loaded element rather than a URL string.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * Determine whether a `src` prop is an `HTMLImageElement` instance. The
9
+ * constructor is tested at call time so jsdom's `HTMLImageElement` shim
10
+ * works in tests.
11
+ *
12
+ * @param src - The `src` value to inspect.
13
+ * @returns `true` if `src` is an `HTMLImageElement`.
14
+ */
15
+ export declare function isImageElement(src: string | HTMLImageElement): src is HTMLImageElement;
16
+ //# sourceMappingURL=image-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-source.d.ts","sourceRoot":"","sources":["../src/image-source.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,GAAG,IAAI,gBAAgB,CAItF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Internal source guard of the Vue Canvas2D image-editing surface: whether
3
+ * the `src` prop is an already-loaded element rather than a URL string.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * Determine whether a `src` prop is an `HTMLImageElement` instance. The
9
+ * constructor is tested at call time so jsdom's `HTMLImageElement` shim
10
+ * works in tests.
11
+ *
12
+ * @param src - The `src` value to inspect.
13
+ * @returns `true` if `src` is an `HTMLImageElement`.
14
+ */
15
+ export function isImageElement(src) {
16
+ if (typeof src === 'string')
17
+ return false;
18
+ if (typeof HTMLImageElement === 'undefined')
19
+ return false;
20
+ return src instanceof HTMLImageElement;
21
+ }
22
+ //# sourceMappingURL=image-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-source.js","sourceRoot":"","sources":["../src/image-source.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,GAA8B;IAC3D,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IACzC,IAAI,OAAO,gBAAgB,KAAK,WAAW;QAAE,OAAO,KAAK,CAAA;IACzD,OAAO,GAAG,YAAY,gBAAgB,CAAA;AACxC,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Vue Canvas2D image-editing surface.
3
+ *
4
+ * Exports `ImageCanvas` — the Vue counterpart of
5
+ * `@molecule/app-feature-image-canvas-react` with the same props and the same
6
+ * DOM: an image rendered onto a canvas with a filter chain (brightness,
7
+ * contrast, saturation, hue, sepia, grayscale, blur, sharpen), pointer-drag
8
+ * panning, wheel zooming, and a `toDataURL()` export handle, plus the
9
+ * framework-free `clamp`, `composeFilterString`, `screenToCanvas` and
10
+ * `clampPan` helpers.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { defineComponent, h, ref } from 'vue'
15
+ * import {
16
+ * ImageCanvas,
17
+ * type ImageCanvasExportHandle,
18
+ * } from '@molecule/app-feature-image-canvas-vue'
19
+ *
20
+ * const Editor = defineComponent({
21
+ * setup() {
22
+ * const exportRef = ref<{ current: ImageCanvasExportHandle | null }>({ current: null })
23
+ * const zoom = ref(1)
24
+ * const pan = ref({ x: 0, y: 0 })
25
+ * return () =>
26
+ * h(ImageCanvas, {
27
+ * src: '/photo.jpg',
28
+ * filters: { brightness: 1.1, contrast: 1.2, sepia: 0.3 },
29
+ * zoom: zoom.value,
30
+ * pan: pan.value,
31
+ * onChange: (next) => {
32
+ * zoom.value = next.zoom
33
+ * pan.value = next.pan
34
+ * },
35
+ * exportRef: exportRef.value,
36
+ * })
37
+ * },
38
+ * })
39
+ * ```
40
+ *
41
+ * @remarks
42
+ * - Pan / zoom interaction is CONTROLLED-ONLY: pointer-drag and wheel events
43
+ * call `onChange` with the proposed `{ zoom, pan }` and never mutate
44
+ * internal state. Without `onChange` and a caller feeding the values back
45
+ * through the `zoom` / `pan` props, dragging and scrolling do nothing.
46
+ * - Requires a bonded ClassMap (the frame and the loading text use ClassMap
47
+ * tokens) and a bonded i18n provider for its aria labels and messages.
48
+ * - URL sources load with `crossOrigin="anonymous"` so `toDataURL()` is never
49
+ * blocked by a tainted canvas — remote images MUST be served with CORS
50
+ * headers. Same-origin and data-URL sources are unaffected.
51
+ * - The canvas bitmap is exactly `width` x `height` device-independent
52
+ * pixels — there is no devicePixelRatio upscaling.
53
+ *
54
+ * @module
55
+ */
56
+ export * from './helpers.js';
57
+ export * from './ImageCanvas.js';
58
+ export * from './types.js';
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Vue Canvas2D image-editing surface.
3
+ *
4
+ * Exports `ImageCanvas` — the Vue counterpart of
5
+ * `@molecule/app-feature-image-canvas-react` with the same props and the same
6
+ * DOM: an image rendered onto a canvas with a filter chain (brightness,
7
+ * contrast, saturation, hue, sepia, grayscale, blur, sharpen), pointer-drag
8
+ * panning, wheel zooming, and a `toDataURL()` export handle, plus the
9
+ * framework-free `clamp`, `composeFilterString`, `screenToCanvas` and
10
+ * `clampPan` helpers.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { defineComponent, h, ref } from 'vue'
15
+ * import {
16
+ * ImageCanvas,
17
+ * type ImageCanvasExportHandle,
18
+ * } from '@molecule/app-feature-image-canvas-vue'
19
+ *
20
+ * const Editor = defineComponent({
21
+ * setup() {
22
+ * const exportRef = ref<{ current: ImageCanvasExportHandle | null }>({ current: null })
23
+ * const zoom = ref(1)
24
+ * const pan = ref({ x: 0, y: 0 })
25
+ * return () =>
26
+ * h(ImageCanvas, {
27
+ * src: '/photo.jpg',
28
+ * filters: { brightness: 1.1, contrast: 1.2, sepia: 0.3 },
29
+ * zoom: zoom.value,
30
+ * pan: pan.value,
31
+ * onChange: (next) => {
32
+ * zoom.value = next.zoom
33
+ * pan.value = next.pan
34
+ * },
35
+ * exportRef: exportRef.value,
36
+ * })
37
+ * },
38
+ * })
39
+ * ```
40
+ *
41
+ * @remarks
42
+ * - Pan / zoom interaction is CONTROLLED-ONLY: pointer-drag and wheel events
43
+ * call `onChange` with the proposed `{ zoom, pan }` and never mutate
44
+ * internal state. Without `onChange` and a caller feeding the values back
45
+ * through the `zoom` / `pan` props, dragging and scrolling do nothing.
46
+ * - Requires a bonded ClassMap (the frame and the loading text use ClassMap
47
+ * tokens) and a bonded i18n provider for its aria labels and messages.
48
+ * - URL sources load with `crossOrigin="anonymous"` so `toDataURL()` is never
49
+ * blocked by a tainted canvas — remote images MUST be served with CORS
50
+ * headers. Same-origin and data-URL sources are unaffected.
51
+ * - The canvas bitmap is exactly `width` x `height` device-independent
52
+ * pixels — there is no devicePixelRatio upscaling.
53
+ *
54
+ * @module
55
+ */
56
+ export * from './helpers.js';
57
+ export * from './ImageCanvas.js';
58
+ export * from './types.js';
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Types for the Vue Canvas2D image-editing surface — the same types
3
+ * `@molecule/app-feature-image-canvas-react` exports.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * A two-dimensional offset, in CSS pixels, applied to the rendered image
9
+ * relative to the centre of the canvas. Positive `x` shifts the image
10
+ * right; positive `y` shifts it down.
11
+ */
12
+ export interface PanOffset {
13
+ /** Horizontal offset, in CSS pixels. */
14
+ x: number;
15
+ /** Vertical offset, in CSS pixels. */
16
+ y: number;
17
+ }
18
+ /**
19
+ * Filter parameters applied to the source image before it is rendered to
20
+ * the canvas. Every field is optional — omitted fields disable that
21
+ * filter. Values are clamped at compose time so out-of-range numbers are
22
+ * safe.
23
+ *
24
+ * Implementation note: composition uses the Canvas2D `filter` property
25
+ * (CSS `<filter-function>` syntax). Compose order is preserved.
26
+ */
27
+ export interface ImageCanvasFilters {
28
+ /**
29
+ * Brightness multiplier. `1` is identity, `0` is black, `2` is twice
30
+ * as bright. Values < 0 are clamped to 0.
31
+ */
32
+ brightness?: number;
33
+ /**
34
+ * Contrast multiplier. `1` is identity, `0` is fully grey, `2` is
35
+ * twice the contrast. Values < 0 are clamped to 0.
36
+ */
37
+ contrast?: number;
38
+ /**
39
+ * Saturation multiplier. `1` is identity, `0` is grayscale, `2` is
40
+ * twice as saturated. Values < 0 are clamped to 0.
41
+ */
42
+ saturation?: number;
43
+ /**
44
+ * Hue rotation in degrees. Normalised modulo 360 — any finite value
45
+ * is accepted.
46
+ */
47
+ hue?: number;
48
+ /**
49
+ * Sepia amount in `[0, 1]`. `0` disables; `1` applies fully. Values
50
+ * outside the range are clamped.
51
+ */
52
+ sepia?: number;
53
+ /**
54
+ * Grayscale amount in `[0, 1]`. `0` disables; `1` applies fully.
55
+ * Values outside the range are clamped.
56
+ */
57
+ grayscale?: number;
58
+ /**
59
+ * Gaussian blur radius in CSS pixels. `0` disables. Negative values
60
+ * are clamped to 0.
61
+ */
62
+ blur?: number;
63
+ /**
64
+ * Sharpen strength in `[0, 1]`. Approximated as a negative-blur
65
+ * contrast bump using the CSS `contrast()` filter; `0` disables.
66
+ * Values outside the range are clamped.
67
+ */
68
+ sharpen?: number;
69
+ }
70
+ /**
71
+ * Imperative export handle exposed via `exportRef`. Callers use this to
72
+ * grab the current rendered image (with all filters, zoom, and pan
73
+ * baked in) as a data URL.
74
+ */
75
+ export interface ImageCanvasExportHandle {
76
+ /**
77
+ * Snapshot the current canvas as a data URL.
78
+ *
79
+ * @param type - Image MIME type. Defaults to `image/png`.
80
+ * @param quality - Lossy quality in `[0, 1]` for `image/jpeg` /
81
+ * `image/webp`. Ignored for `image/png`.
82
+ * @returns A data URL string, or an empty string if the canvas is not
83
+ * yet mounted.
84
+ */
85
+ toDataURL: (type?: string, quality?: number) => string;
86
+ }
87
+ /** ImageCanvas component props (React's prop names). */
88
+ export interface ImageCanvasProps {
89
+ /**
90
+ * Image source. Either a string (URL or data URL) — which the
91
+ * component loads into an internal `HTMLImageElement` — or an
92
+ * already-loaded `HTMLImageElement` the caller manages.
93
+ */
94
+ src: string | HTMLImageElement;
95
+ /** Filter chain applied to the rendered image. */
96
+ filters?: ImageCanvasFilters;
97
+ /**
98
+ * Zoom factor. `1` is identity. Values <= 0 fall back to `1`.
99
+ * Defaults to `1`.
100
+ */
101
+ zoom?: number;
102
+ /**
103
+ * Pan offset in CSS pixels relative to the centre of the canvas.
104
+ * Defaults to `{ x: 0, y: 0 }`.
105
+ */
106
+ pan?: PanOffset;
107
+ /**
108
+ * Optional callback fired when the user pans or zooms the canvas.
109
+ * Use this for controlled-component patterns.
110
+ */
111
+ onChange?: (next: {
112
+ zoom: number;
113
+ pan: PanOffset;
114
+ }) => void;
115
+ /**
116
+ * Imperative handle exposing `toDataURL()` for the caller to grab
117
+ * the rendered result.
118
+ */
119
+ exportRef?: {
120
+ current: ImageCanvasExportHandle | null;
121
+ };
122
+ /** Pixel width of the canvas. Defaults to `512`. */
123
+ width?: number;
124
+ /** Pixel height of the canvas. Defaults to `512`. */
125
+ height?: number;
126
+ /** Extra classes merged onto the root element. */
127
+ className?: string;
128
+ }
129
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,wCAAwC;IACxC,CAAC,EAAE,MAAM,CAAA;IACT,sCAAsC;IACtC,CAAC,EAAE,MAAM,CAAA;CACV;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;OAQG;IACH,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CACvD;AAED,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;IAC9B,kDAAkD;IAClD,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,SAAS,CAAA;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,SAAS,CAAA;KAAE,KAAK,IAAI,CAAA;IAC3D;;;OAGG;IACH,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAAA;KAAE,CAAA;IACvD,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Types for the Vue Canvas2D image-editing surface — the same types
3
+ * `@molecule/app-feature-image-canvas-react` exports.
4
+ *
5
+ * @module
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json CHANGED
@@ -1,6 +1,69 @@
1
1
  {
2
2
  "name": "@molecule/app-feature-image-canvas-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1-stage",
4
+ "description": "Canvas2D image-editing surface — accepts an image source, applies a filter chain (brightness, contrast, saturation, hue, sepia, grayscale, blur, sharpen), supports zoom + pan, exports back to data URL",
5
+ "homepage": "https://www.molecule.dev/packages/app-feature-image-canvas-vue",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "vue-tsc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "image-canvas",
28
+ "image",
29
+ "canvas",
30
+ "filters",
31
+ "photo-editor",
32
+ "vue"
33
+ ],
34
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
35
+ "license": "Apache-2.0",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/molecule-dev/molecule.git",
39
+ "directory": "packages/app/features/feature-image-canvas-vue"
40
+ },
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "peerDependencies": {
49
+ "@molecule/app-ui": "^1.0.1",
50
+ "@molecule/app-ui-vue": "^1.1.0",
51
+ "@molecule/app-vue": "^3.5.0",
52
+ "vue": "^3.4.0"
53
+ },
54
+ "devDependencies": {
55
+ "@molecule/app-framework-conformance": "0.0.0",
56
+ "@molecule/app-i18n": "1.2.2",
57
+ "@molecule/app-icons": "1.0.4",
58
+ "@molecule/app-ui": "1.4.0",
59
+ "@molecule/app-ui-vue": "1.1.5",
60
+ "@molecule/app-vue": "3.7.2",
61
+ "@types/node": "26.6.5",
62
+ "jsdom": "30.1.3",
63
+ "typescript": "6.0.3",
64
+ "vite": "8.3.5",
65
+ "vitest": "4.1.12",
66
+ "vue": "3.5.44",
67
+ "vue-tsc": "3.3.13"
68
+ }
69
+ }