ngwr 16.8.0 → 16.9.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/descriptions/styles/_index.scss +91 -0
- package/fesm2022/ngwr-anchor.mjs +48 -10
- package/fesm2022/ngwr-anchor.mjs.map +1 -1
- package/fesm2022/ngwr-carousel.mjs +3 -2
- package/fesm2022/ngwr-carousel.mjs.map +1 -1
- package/fesm2022/ngwr-compare.mjs +4 -0
- package/fesm2022/ngwr-compare.mjs.map +1 -1
- package/fesm2022/ngwr-cookie.mjs +6 -3
- package/fesm2022/ngwr-cookie.mjs.map +1 -1
- package/fesm2022/ngwr-date-stamp-testing.mjs +3 -0
- package/fesm2022/ngwr-date-stamp-testing.mjs.map +1 -1
- package/fesm2022/ngwr-date-stamp.mjs +81 -4
- package/fesm2022/ngwr-date-stamp.mjs.map +1 -1
- package/fesm2022/ngwr-date.mjs +16 -2
- package/fesm2022/ngwr-date.mjs.map +1 -1
- package/fesm2022/ngwr-density.mjs +4 -3
- package/fesm2022/ngwr-density.mjs.map +1 -1
- package/fesm2022/ngwr-descriptions.mjs +77 -20
- package/fesm2022/ngwr-descriptions.mjs.map +1 -1
- package/fesm2022/ngwr-directives.mjs +12 -0
- package/fesm2022/ngwr-directives.mjs.map +1 -1
- package/fesm2022/ngwr-editor.mjs +1 -0
- package/fesm2022/ngwr-editor.mjs.map +1 -1
- package/fesm2022/ngwr-file-upload.mjs +2 -3
- package/fesm2022/ngwr-file-upload.mjs.map +1 -1
- package/fesm2022/ngwr-form.mjs.map +1 -1
- package/fesm2022/ngwr-hotkey.mjs +10 -5
- package/fesm2022/ngwr-hotkey.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ar.mjs +9 -3
- package/fesm2022/ngwr-i18n-ar.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-cs.mjs +9 -3
- package/fesm2022/ngwr-i18n-cs.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-de.mjs +9 -3
- package/fesm2022/ngwr-i18n-de.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-en.mjs +9 -3
- package/fesm2022/ngwr-i18n-en.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-es.mjs +9 -3
- package/fesm2022/ngwr-i18n-es.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-fr.mjs +9 -3
- package/fesm2022/ngwr-i18n-fr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-he.mjs +9 -3
- package/fesm2022/ngwr-i18n-he.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-hi.mjs +9 -3
- package/fesm2022/ngwr-i18n-hi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-id.mjs +9 -3
- package/fesm2022/ngwr-i18n-id.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-it.mjs +9 -3
- package/fesm2022/ngwr-i18n-it.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ja.mjs +9 -3
- package/fesm2022/ngwr-i18n-ja.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-kk.mjs +9 -3
- package/fesm2022/ngwr-i18n-kk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ko.mjs +9 -3
- package/fesm2022/ngwr-i18n-ko.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-nl.mjs +9 -3
- package/fesm2022/ngwr-i18n-nl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pl.mjs +9 -3
- package/fesm2022/ngwr-i18n-pl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pt.mjs +9 -3
- package/fesm2022/ngwr-i18n-pt.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ru.mjs +9 -3
- package/fesm2022/ngwr-i18n-ru.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-sv.mjs +9 -3
- package/fesm2022/ngwr-i18n-sv.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-tr.mjs +9 -3
- package/fesm2022/ngwr-i18n-tr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-uk.mjs +9 -3
- package/fesm2022/ngwr-i18n-uk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-vi.mjs +9 -3
- package/fesm2022/ngwr-i18n-vi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh-tw.mjs +9 -3
- package/fesm2022/ngwr-i18n-zh-tw.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh.mjs +9 -3
- package/fesm2022/ngwr-i18n-zh.mjs.map +1 -1
- package/fesm2022/ngwr-i18n.mjs +7 -6
- package/fesm2022/ngwr-i18n.mjs.map +1 -1
- package/fesm2022/ngwr-image-cropper-testing.mjs +33 -0
- package/fesm2022/ngwr-image-cropper-testing.mjs.map +1 -1
- package/fesm2022/ngwr-image-cropper.mjs +536 -30
- package/fesm2022/ngwr-image-cropper.mjs.map +1 -1
- package/fesm2022/ngwr-knob.mjs +5 -0
- package/fesm2022/ngwr-knob.mjs.map +1 -1
- package/fesm2022/ngwr-mention.mjs +2 -0
- package/fesm2022/ngwr-mention.mjs.map +1 -1
- package/fesm2022/ngwr-meta.mjs +43 -8
- package/fesm2022/ngwr-meta.mjs.map +1 -1
- package/fesm2022/ngwr-pagination.mjs +1 -1
- package/fesm2022/ngwr-pagination.mjs.map +1 -1
- package/fesm2022/ngwr-pipes.mjs +160 -8
- package/fesm2022/ngwr-pipes.mjs.map +1 -1
- package/fesm2022/ngwr-qr.mjs +65 -7
- package/fesm2022/ngwr-qr.mjs.map +1 -1
- package/fesm2022/ngwr-schema-form.mjs +2 -2
- package/fesm2022/ngwr-schema-form.mjs.map +1 -1
- package/fesm2022/ngwr-scroll.mjs +1 -2
- package/fesm2022/ngwr-scroll.mjs.map +1 -1
- package/fesm2022/ngwr-speed-dial.mjs +30 -1
- package/fesm2022/ngwr-speed-dial.mjs.map +1 -1
- package/fesm2022/ngwr-statistic.mjs +1 -1
- package/fesm2022/ngwr-stepper-testing.mjs +7 -1
- package/fesm2022/ngwr-stepper-testing.mjs.map +1 -1
- package/fesm2022/ngwr-stepper.mjs +55 -4
- package/fesm2022/ngwr-stepper.mjs.map +1 -1
- package/fesm2022/ngwr-timeline.mjs +4 -0
- package/fesm2022/ngwr-timeline.mjs.map +1 -1
- package/fesm2022/ngwr-toolbar.mjs +171 -16
- package/fesm2022/ngwr-toolbar.mjs.map +1 -1
- package/fesm2022/ngwr-transfer.mjs +3 -2
- package/fesm2022/ngwr-transfer.mjs.map +1 -1
- package/fesm2022/ngwr-tree.mjs +1 -1
- package/fesm2022/ngwr-utils.mjs +46 -8
- package/fesm2022/ngwr-utils.mjs.map +1 -1
- package/fesm2022/ngwr-version.mjs +1 -1
- package/fesm2022/ngwr-version.mjs.map +1 -1
- package/fesm2022/ngwr-virtual-scroll.mjs +2 -2
- package/fesm2022/ngwr-virtual-scroll.mjs.map +1 -1
- package/i18n/ar.json +9 -3
- package/i18n/cs.json +9 -3
- package/i18n/de.json +9 -3
- package/i18n/en.json +9 -3
- package/i18n/es.json +9 -3
- package/i18n/fr.json +9 -3
- package/i18n/he.json +9 -3
- package/i18n/hi.json +9 -3
- package/i18n/id.json +9 -3
- package/i18n/it.json +9 -3
- package/i18n/ja.json +9 -3
- package/i18n/kk.json +9 -3
- package/i18n/ko.json +9 -3
- package/i18n/nl.json +9 -3
- package/i18n/pl.json +9 -3
- package/i18n/pt.json +9 -3
- package/i18n/ru.json +9 -3
- package/i18n/sv.json +9 -3
- package/i18n/tr.json +9 -3
- package/i18n/uk.json +9 -3
- package/i18n/vi.json +9 -3
- package/i18n/zh-TW.json +9 -3
- package/i18n/zh.json +9 -3
- package/image-cropper/styles/_index.scss +30 -1
- package/llms-full.txt +5 -5
- package/package.json +1 -1
- package/schematics/use/symbol-map.json +1 -0
- package/skills/ngwr/SKILL.md +2 -2
- package/stepper/styles/_index.scss +33 -0
- package/types/ngwr-anchor.d.ts +14 -1
- package/types/ngwr-date-stamp-testing.d.ts +2 -0
- package/types/ngwr-date-stamp.d.ts +41 -2
- package/types/ngwr-date.d.ts +3 -1
- package/types/ngwr-descriptions.d.ts +33 -5
- package/types/ngwr-directives.d.ts +1 -0
- package/types/ngwr-form.d.ts +4 -0
- package/types/ngwr-hotkey.d.ts +2 -0
- package/types/ngwr-image-cropper-testing.d.ts +33 -1
- package/types/ngwr-image-cropper.d.ts +214 -6
- package/types/ngwr-meta.d.ts +13 -1
- package/types/ngwr-pipes.d.ts +125 -1
- package/types/ngwr-qr.d.ts +17 -0
- package/types/ngwr-speed-dial.d.ts +10 -0
- package/types/ngwr-stepper-testing.d.ts +10 -0
- package/types/ngwr-stepper.d.ts +47 -1
- package/types/ngwr-toolbar.d.ts +27 -0
- package/types/ngwr-transfer.d.ts +2 -0
- package/types/ngwr-utils.d.ts +61 -2
- package/types/ngwr-version.d.ts +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { Component, DestroyRef, ViewEncapsulation, computed, effect, inject, input, isDevMode, output, signal, viewChild } from "@angular/core";
|
|
2
|
+
import { Component, DestroyRef, Injector, ViewEncapsulation, afterNextRender, computed, effect, inject, input, isDevMode, model, output, signal, untracked, viewChild } from "@angular/core";
|
|
3
3
|
import { coerceNumberProperty } from "@angular/cdk/coercion";
|
|
4
4
|
import { wrCheckStyles, wrClamp, wrFileNameForType, wrRandomId } from "ngwr/utils";
|
|
5
|
-
import { useI18nText } from "ngwr/i18n";
|
|
5
|
+
import { useI18nFormatter, useI18nText } from "ngwr/i18n";
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
8
8
|
*
|
|
@@ -17,12 +17,45 @@ function coerceMaxOutputSize(value) {
|
|
|
17
17
|
const NO_OVERRIDE = signal(null).asReadonly();
|
|
18
18
|
const KEY_STEP = 1;
|
|
19
19
|
const KEY_STEP_COARSE = 10;
|
|
20
|
+
const MAX_ZOOM = 4;
|
|
21
|
+
const ZOOM_KEY_STEP = .1;
|
|
22
|
+
const WHEEL_RATE = .002;
|
|
23
|
+
const WHEEL_RATE_PINCH = .01;
|
|
24
|
+
const EMIT_DELAY = 120;
|
|
25
|
+
function coerceZoom(value) {
|
|
26
|
+
const n = Number(value);
|
|
27
|
+
return Number.isFinite(n) ? wrClamp(n, 1, MAX_ZOOM) : 1;
|
|
28
|
+
}
|
|
29
|
+
function coerceRotation(value) {
|
|
30
|
+
const n = Number(value);
|
|
31
|
+
if (!Number.isFinite(n)) return 0;
|
|
32
|
+
return (Math.round(n / 90) * 90 % 360 + 360) % 360;
|
|
33
|
+
}
|
|
20
34
|
const NO_SIDES = {
|
|
21
35
|
left: 0,
|
|
22
36
|
top: 0,
|
|
23
37
|
right: 0,
|
|
24
38
|
bottom: 0
|
|
25
39
|
};
|
|
40
|
+
function fitWithin(size, box) {
|
|
41
|
+
const k = Math.min(1, box.w / size.w, box.h / size.h);
|
|
42
|
+
return {
|
|
43
|
+
w: size.w * k,
|
|
44
|
+
h: size.h * k
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function pixelSpan(from, to, size) {
|
|
48
|
+
const start = wrClamp(Math.round(from), 0, size);
|
|
49
|
+
const end = wrClamp(Math.round(to), 0, size);
|
|
50
|
+
if (end > start || !(to > from) || size < 1) return [start, end - start];
|
|
51
|
+
return [wrClamp(Math.floor((from + to) / 2), 0, size - 1), 1];
|
|
52
|
+
}
|
|
53
|
+
function panFor(center, zoom, stage) {
|
|
54
|
+
return {
|
|
55
|
+
x: wrClamp(stage.w / 2 - center.x * zoom * stage.w, stage.w - zoom * stage.w, 0),
|
|
56
|
+
y: wrClamp(stage.h / 2 - center.y * zoom * stage.h, stage.h - zoom * stage.h, 0)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
26
59
|
function resizeFrom(r, handle, dx, dy, bounds, min, ratio) {
|
|
27
60
|
const east = handle.includes("e");
|
|
28
61
|
const west = handle.includes("w");
|
|
@@ -78,12 +111,18 @@ var WrImageCropper = class WrImageCropper {
|
|
|
78
111
|
...ngDevMode ? { debugName: "maxOutputSize" } : /* istanbul ignore next */ {},
|
|
79
112
|
transform: coerceMaxOutputSize
|
|
80
113
|
});
|
|
114
|
+
zoom = model(1, ...ngDevMode ? [{ debugName: "zoom" }] : /* istanbul ignore next */ []);
|
|
115
|
+
rotation = model(0, ...ngDevMode ? [{ debugName: "rotation" }] : /* istanbul ignore next */ []);
|
|
81
116
|
cropped = output();
|
|
82
117
|
loadError = output();
|
|
83
118
|
imgEl = viewChild.required("img", ...ngDevMode ? [{ debugName: "imgEl" }] : /* istanbul ignore next */ []);
|
|
119
|
+
sizerEl = viewChild("sizer", ...ngDevMode ? [{ debugName: "sizerEl" }] : /* istanbul ignore next */ []);
|
|
84
120
|
emptyText = useI18nText(NO_OVERRIDE, "imageCropper.empty", "No image");
|
|
85
121
|
resolvedWindowLabel = useI18nText(NO_OVERRIDE, "imageCropper.window", "Crop region");
|
|
86
122
|
resolvedKeyHelp = useI18nText(NO_OVERRIDE, "imageCropper.keyHelp", "Arrow keys move the crop. Hold Alt with an arrow key to resize it, and Shift for larger steps. The crop is announced as left, top, width and height in image pixels.");
|
|
123
|
+
resolvedTransformHelp = useI18nText(NO_OVERRIDE, "imageCropper.transformHelp", "Plus and minus zoom the image. R turns it clockwise, and Shift with R the other way.");
|
|
124
|
+
zoomedText = useI18nFormatter("imageCropper.zoomed", "Zoom {{percent}}%");
|
|
125
|
+
rotatedText = useI18nFormatter("imageCropper.rotated", "Rotated {{degrees}}°");
|
|
87
126
|
helpId = wrRandomId("wr-image-cropper-help");
|
|
88
127
|
announcement = signal("", ...ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []);
|
|
89
128
|
objectUrl = signal(null, ...ngDevMode ? [{ debugName: "objectUrl" }] : /* istanbul ignore next */ []);
|
|
@@ -102,27 +141,68 @@ var WrImageCropper = class WrImageCropper {
|
|
|
102
141
|
w: 0,
|
|
103
142
|
h: 0
|
|
104
143
|
}, ...ngDevMode ? [{ debugName: "cropDisplay" }] : /* istanbul ignore next */ []);
|
|
144
|
+
zoomLevel = computed(() => coerceZoom(this.zoom()), ...ngDevMode ? [{ debugName: "zoomLevel" }] : /* istanbul ignore next */ []);
|
|
145
|
+
angle = computed(() => coerceRotation(this.rotation()), ...ngDevMode ? [{ debugName: "angle" }] : /* istanbul ignore next */ []);
|
|
146
|
+
laidAngle = signal(0, ...ngDevMode ? [{ debugName: "laidAngle" }] : /* istanbul ignore next */ []);
|
|
147
|
+
turned = computed(() => this.laidAngle() % 180 !== 0, ...ngDevMode ? [{ debugName: "turned" }] : /* istanbul ignore next */ []);
|
|
148
|
+
center = signal({
|
|
149
|
+
x: .5,
|
|
150
|
+
y: .5
|
|
151
|
+
}, ...ngDevMode ? [{ debugName: "center" }] : /* istanbul ignore next */ []);
|
|
152
|
+
pan = computed(() => panFor(this.center(), this.zoomLevel(), this.display()), ...ngDevMode ? [{ debugName: "pan" }] : /* istanbul ignore next */ []);
|
|
153
|
+
measured = computed(() => this.display().w > 0, ...ngDevMode ? [{ debugName: "measured" }] : /* istanbul ignore next */ []);
|
|
154
|
+
unmeasured = signal(false, ...ngDevMode ? [{ debugName: "unmeasured" }] : /* istanbul ignore next */ []);
|
|
155
|
+
stageBox = computed(() => this.turned() && this.measured() && this.unmeasured() ? this.display() : null, ...ngDevMode ? [{ debugName: "stageBox" }] : /* istanbul ignore next */ []);
|
|
156
|
+
view = computed(() => {
|
|
157
|
+
const d = this.display();
|
|
158
|
+
if (d.w === 0 || d.h === 0) return null;
|
|
159
|
+
const p = this.pan();
|
|
160
|
+
const zoom = this.zoomLevel();
|
|
161
|
+
const angle = this.laidAngle();
|
|
162
|
+
const w = this.turned() ? d.h : d.w;
|
|
163
|
+
const h = this.turned() ? d.w : d.h;
|
|
164
|
+
const tx = angle === 90 ? h : angle === 180 ? w : 0;
|
|
165
|
+
const ty = angle === 180 ? h : angle === 270 ? w : 0;
|
|
166
|
+
return {
|
|
167
|
+
w,
|
|
168
|
+
h,
|
|
169
|
+
transform: `translate(${p.x}px, ${p.y}px) scale(${zoom}) translate(${tx}px, ${ty}px) rotate(${angle}deg)`
|
|
170
|
+
};
|
|
171
|
+
}, ...ngDevMode ? [{ debugName: "view" }] : /* istanbul ignore next */ []);
|
|
105
172
|
resizeObserver = null;
|
|
106
173
|
active = null;
|
|
107
174
|
startPointer = {
|
|
108
175
|
x: 0,
|
|
109
176
|
y: 0
|
|
110
177
|
};
|
|
178
|
+
lastPointer = {
|
|
179
|
+
x: 0,
|
|
180
|
+
y: 0
|
|
181
|
+
};
|
|
111
182
|
startRect = {
|
|
112
183
|
x: 0,
|
|
113
184
|
y: 0,
|
|
114
185
|
w: 0,
|
|
115
186
|
h: 0
|
|
116
187
|
};
|
|
188
|
+
startPan = {
|
|
189
|
+
x: 0,
|
|
190
|
+
y: 0
|
|
191
|
+
};
|
|
192
|
+
pointers = /* @__PURE__ */ new Map();
|
|
193
|
+
pinch = null;
|
|
194
|
+
emitTimer = null;
|
|
195
|
+
emitRun = 0;
|
|
117
196
|
captureTarget = null;
|
|
118
197
|
pointerId = null;
|
|
119
198
|
overhang = NO_SIDES;
|
|
120
199
|
destroyRef = inject(DestroyRef);
|
|
200
|
+
injector = inject(Injector);
|
|
121
201
|
statusState = signal("empty", ...ngDevMode ? [{ debugName: "statusState" }] : /* istanbul ignore next */ []);
|
|
122
202
|
status = this.statusState.asReadonly();
|
|
123
203
|
cropRect = computed(() => {
|
|
124
204
|
const display = this.display();
|
|
125
|
-
const
|
|
205
|
+
const n = this.natural();
|
|
126
206
|
const c = this.cropDisplay();
|
|
127
207
|
if (display.w === 0 || display.h === 0) return {
|
|
128
208
|
x: 0,
|
|
@@ -130,15 +210,68 @@ var WrImageCropper = class WrImageCropper {
|
|
|
130
210
|
width: 0,
|
|
131
211
|
height: 0
|
|
132
212
|
};
|
|
133
|
-
const
|
|
134
|
-
const
|
|
213
|
+
const turned = this.turned();
|
|
214
|
+
const zoom = this.zoomLevel();
|
|
215
|
+
const pan = this.pan();
|
|
216
|
+
const sx = (turned ? n.h : n.w) / display.w;
|
|
217
|
+
const sy = (turned ? n.w : n.h) / display.h;
|
|
218
|
+
const left = (c.x - pan.x) / zoom * sx;
|
|
219
|
+
const top = (c.y - pan.y) / zoom * sy;
|
|
220
|
+
const right = left + c.w / zoom * sx;
|
|
221
|
+
const bottom = top + c.h / zoom * sy;
|
|
222
|
+
let x;
|
|
223
|
+
let y;
|
|
224
|
+
switch (this.laidAngle()) {
|
|
225
|
+
case 90:
|
|
226
|
+
x = [top, bottom];
|
|
227
|
+
y = [n.h - right, n.h - left];
|
|
228
|
+
break;
|
|
229
|
+
case 180:
|
|
230
|
+
x = [n.w - right, n.w - left];
|
|
231
|
+
y = [n.h - bottom, n.h - top];
|
|
232
|
+
break;
|
|
233
|
+
case 270:
|
|
234
|
+
x = [n.w - bottom, n.w - top];
|
|
235
|
+
y = [left, right];
|
|
236
|
+
break;
|
|
237
|
+
default:
|
|
238
|
+
x = [left, right];
|
|
239
|
+
y = [top, bottom];
|
|
240
|
+
}
|
|
241
|
+
const [x0, width] = pixelSpan(x[0], x[1], n.w);
|
|
242
|
+
const [y0, height] = pixelSpan(y[0], y[1], n.h);
|
|
135
243
|
return {
|
|
136
|
-
x:
|
|
137
|
-
y:
|
|
138
|
-
width
|
|
139
|
-
height
|
|
244
|
+
x: x0,
|
|
245
|
+
y: y0,
|
|
246
|
+
width,
|
|
247
|
+
height
|
|
140
248
|
};
|
|
141
249
|
}, ...ngDevMode ? [{ debugName: "cropRect" }] : /* istanbul ignore next */ []);
|
|
250
|
+
turnedRect = computed(() => {
|
|
251
|
+
const r = this.cropRect();
|
|
252
|
+
const n = this.natural();
|
|
253
|
+
switch (this.laidAngle()) {
|
|
254
|
+
case 90: return {
|
|
255
|
+
x: n.h - r.y - r.height,
|
|
256
|
+
y: r.x,
|
|
257
|
+
width: r.height,
|
|
258
|
+
height: r.width
|
|
259
|
+
};
|
|
260
|
+
case 180: return {
|
|
261
|
+
x: n.w - r.x - r.width,
|
|
262
|
+
y: n.h - r.y - r.height,
|
|
263
|
+
width: r.width,
|
|
264
|
+
height: r.height
|
|
265
|
+
};
|
|
266
|
+
case 270: return {
|
|
267
|
+
x: r.y,
|
|
268
|
+
y: n.w - r.x - r.width,
|
|
269
|
+
width: r.height,
|
|
270
|
+
height: r.width
|
|
271
|
+
};
|
|
272
|
+
default: return r;
|
|
273
|
+
}
|
|
274
|
+
}, ...ngDevMode ? [{ debugName: "turnedRect" }] : /* istanbul ignore next */ []);
|
|
142
275
|
constructor() {
|
|
143
276
|
if (typeof ngDevMode === "undefined" || ngDevMode) wrCheckStyles("image-cropper");
|
|
144
277
|
effect(() => {
|
|
@@ -161,12 +294,29 @@ var WrImageCropper = class WrImageCropper {
|
|
|
161
294
|
this.objectUrl.set(url);
|
|
162
295
|
}
|
|
163
296
|
});
|
|
297
|
+
effect(() => {
|
|
298
|
+
const ratio = this.aspectRatio();
|
|
299
|
+
const angle = this.angle();
|
|
300
|
+
untracked(() => {
|
|
301
|
+
if (!this.turnTo(angle) && this.refit(ratio)) this.emitCropped();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
effect(() => {
|
|
305
|
+
this.zoomLevel();
|
|
306
|
+
this.angle();
|
|
307
|
+
untracked(() => this.scheduleEmit());
|
|
308
|
+
});
|
|
164
309
|
this.destroyRef.onDestroy(() => {
|
|
310
|
+
if (this.emitTimer !== null) clearTimeout(this.emitTimer);
|
|
165
311
|
if (this.previousObjectUrl) URL.revokeObjectURL(this.previousObjectUrl);
|
|
166
312
|
this.resizeObserver?.disconnect();
|
|
167
313
|
});
|
|
168
314
|
}
|
|
169
315
|
resetGeometry() {
|
|
316
|
+
this.endGesture();
|
|
317
|
+
if (this.emitTimer !== null) clearTimeout(this.emitTimer);
|
|
318
|
+
this.emitTimer = null;
|
|
319
|
+
this.emitRun++;
|
|
170
320
|
this.natural.set({
|
|
171
321
|
w: 0,
|
|
172
322
|
h: 0
|
|
@@ -181,23 +331,31 @@ var WrImageCropper = class WrImageCropper {
|
|
|
181
331
|
w: 0,
|
|
182
332
|
h: 0
|
|
183
333
|
});
|
|
334
|
+
this.center.set({
|
|
335
|
+
x: .5,
|
|
336
|
+
y: .5
|
|
337
|
+
});
|
|
338
|
+
this.unmeasured.set(false);
|
|
184
339
|
}
|
|
185
340
|
onImageLoad() {
|
|
186
341
|
const img = this.imgEl().nativeElement;
|
|
187
342
|
const rect = img.getBoundingClientRect();
|
|
188
|
-
const
|
|
343
|
+
const upright = {
|
|
189
344
|
w: rect.width,
|
|
190
345
|
h: rect.height
|
|
191
346
|
};
|
|
192
347
|
const natural = {
|
|
193
|
-
w: img.naturalWidth ||
|
|
194
|
-
h: img.naturalHeight ||
|
|
348
|
+
w: img.naturalWidth || upright.w,
|
|
349
|
+
h: img.naturalHeight || upright.h
|
|
195
350
|
};
|
|
351
|
+
this.laidAngle.set(this.angle());
|
|
352
|
+
const display = this.turned() && upright.w > 0 && upright.h > 0 ? this.turnedGuess(upright) : upright;
|
|
196
353
|
this.statusState.set("loaded");
|
|
197
354
|
this.natural.set(natural);
|
|
198
355
|
this.display.set(display);
|
|
199
356
|
this.cropDisplay.set(this.initialCrop(display));
|
|
200
357
|
this.watchResize(img);
|
|
358
|
+
this.measureAfterRender();
|
|
201
359
|
}
|
|
202
360
|
onImageError() {
|
|
203
361
|
const url = this.objectUrl();
|
|
@@ -216,15 +374,28 @@ var WrImageCropper = class WrImageCropper {
|
|
|
216
374
|
watchResize(el) {
|
|
217
375
|
if (typeof ResizeObserver === "undefined") return;
|
|
218
376
|
this.resizeObserver?.disconnect();
|
|
219
|
-
const ro = new ResizeObserver(() => this.onResize(
|
|
377
|
+
const ro = new ResizeObserver(() => this.onResize());
|
|
220
378
|
ro.observe(el);
|
|
221
379
|
this.resizeObserver = ro;
|
|
222
380
|
}
|
|
223
|
-
onResize(
|
|
381
|
+
onResize() {
|
|
224
382
|
const previous = this.display();
|
|
225
383
|
if (previous.w === 0 || previous.h === 0) return;
|
|
226
|
-
const
|
|
227
|
-
|
|
384
|
+
const turned = this.turned();
|
|
385
|
+
let rect = this.sizerEl()?.nativeElement.getBoundingClientRect();
|
|
386
|
+
if (!rect || rect.width === 0 || rect.height === 0) {
|
|
387
|
+
if (turned) {
|
|
388
|
+
this.unmeasured.set(true);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
rect = this.imgEl().nativeElement.getBoundingClientRect();
|
|
392
|
+
if (rect.width === 0 || rect.height === 0) return;
|
|
393
|
+
}
|
|
394
|
+
if (turned && this.unmeasured()) {
|
|
395
|
+
this.unmeasured.set(false);
|
|
396
|
+
this.measureAfterRender();
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
228
399
|
if (rect.width === previous.w && rect.height === previous.h) return;
|
|
229
400
|
const sx = rect.width / previous.w;
|
|
230
401
|
const sy = rect.height / previous.h;
|
|
@@ -239,6 +410,95 @@ var WrImageCropper = class WrImageCropper {
|
|
|
239
410
|
w: c.w * sx,
|
|
240
411
|
h: c.h * sy
|
|
241
412
|
});
|
|
413
|
+
if (this.active) {
|
|
414
|
+
this.startRect = { ...this.cropDisplay() };
|
|
415
|
+
this.startPan = this.pan();
|
|
416
|
+
this.startPointer = { ...this.lastPointer };
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
measureAfterRender() {
|
|
420
|
+
afterNextRender(() => {
|
|
421
|
+
const sizer = this.sizerEl()?.nativeElement;
|
|
422
|
+
if (sizer) this.resizeObserver?.observe(sizer);
|
|
423
|
+
this.onResize();
|
|
424
|
+
}, { injector: this.injector });
|
|
425
|
+
}
|
|
426
|
+
turnedGuess(box) {
|
|
427
|
+
return fitWithin({
|
|
428
|
+
w: box.h,
|
|
429
|
+
h: box.w
|
|
430
|
+
}, box);
|
|
431
|
+
}
|
|
432
|
+
turnTo(angle) {
|
|
433
|
+
const from = this.laidAngle();
|
|
434
|
+
if (from === angle) return false;
|
|
435
|
+
const d = this.display();
|
|
436
|
+
if (this.statusState() !== "loaded" || d.w === 0 || d.h === 0) {
|
|
437
|
+
this.laidAngle.set(angle);
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
this.endGesture();
|
|
441
|
+
const zoom = this.zoomLevel();
|
|
442
|
+
const pan = this.pan();
|
|
443
|
+
const c = this.cropDisplay();
|
|
444
|
+
let crop = {
|
|
445
|
+
x: (c.x - pan.x) / (zoom * d.w),
|
|
446
|
+
y: (c.y - pan.y) / (zoom * d.h),
|
|
447
|
+
w: c.w / (zoom * d.w),
|
|
448
|
+
h: c.h / (zoom * d.h)
|
|
449
|
+
};
|
|
450
|
+
let center = {
|
|
451
|
+
x: (d.w / 2 - pan.x) / (zoom * d.w),
|
|
452
|
+
y: (d.h / 2 - pan.y) / (zoom * d.h)
|
|
453
|
+
};
|
|
454
|
+
const turns = ((angle - from) / 90 + 4) % 4;
|
|
455
|
+
for (let i = 0; i < turns; i++) {
|
|
456
|
+
crop = {
|
|
457
|
+
x: 1 - crop.y - crop.h,
|
|
458
|
+
y: crop.x,
|
|
459
|
+
w: crop.h,
|
|
460
|
+
h: crop.w
|
|
461
|
+
};
|
|
462
|
+
center = {
|
|
463
|
+
x: 1 - center.y,
|
|
464
|
+
y: center.x
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
const stage = turns % 2 === 1 ? this.turnedGuess(d) : d;
|
|
468
|
+
const next = panFor(center, zoom, stage);
|
|
469
|
+
const w = Math.min(stage.w, crop.w * zoom * stage.w);
|
|
470
|
+
const h = Math.min(stage.h, crop.h * zoom * stage.h);
|
|
471
|
+
this.laidAngle.set(angle);
|
|
472
|
+
this.unmeasured.set(false);
|
|
473
|
+
this.display.set(stage);
|
|
474
|
+
this.center.set(center);
|
|
475
|
+
this.cropDisplay.set({
|
|
476
|
+
x: wrClamp(crop.x * zoom * stage.w + next.x, 0, stage.w - w),
|
|
477
|
+
y: wrClamp(crop.y * zoom * stage.h + next.y, 0, stage.h - h),
|
|
478
|
+
w,
|
|
479
|
+
h
|
|
480
|
+
});
|
|
481
|
+
this.refit(this.aspectRatio());
|
|
482
|
+
this.measureAfterRender();
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
refit(ratio) {
|
|
486
|
+
if (this.statusState() !== "loaded" || !ratio || !(ratio > 0)) return false;
|
|
487
|
+
const c = this.cropDisplay();
|
|
488
|
+
if (c.w <= 0 || c.h <= 0) return false;
|
|
489
|
+
let w = c.w;
|
|
490
|
+
let h = c.h;
|
|
491
|
+
if (w / ratio > h) w = h * ratio;
|
|
492
|
+
else h = w / ratio;
|
|
493
|
+
if (Math.abs(w - c.w) < .01 && Math.abs(h - c.h) < .01) return false;
|
|
494
|
+
this.endDrag();
|
|
495
|
+
this.cropDisplay.set({
|
|
496
|
+
x: c.x + (c.w - w) / 2,
|
|
497
|
+
y: c.y + (c.h - h) / 2,
|
|
498
|
+
w,
|
|
499
|
+
h
|
|
500
|
+
});
|
|
501
|
+
return true;
|
|
242
502
|
}
|
|
243
503
|
initialCrop(display) {
|
|
244
504
|
const ratio = this.aspectRatio();
|
|
@@ -267,6 +527,8 @@ var WrImageCropper = class WrImageCropper {
|
|
|
267
527
|
];
|
|
268
528
|
onPointerDown(handle, event) {
|
|
269
529
|
if (event.button !== 0 || !event.isPrimary) return;
|
|
530
|
+
this.track(event);
|
|
531
|
+
if (this.pinch) return;
|
|
270
532
|
event.preventDefault();
|
|
271
533
|
event.stopPropagation();
|
|
272
534
|
this.active = handle;
|
|
@@ -275,13 +537,18 @@ var WrImageCropper = class WrImageCropper {
|
|
|
275
537
|
x: event.clientX,
|
|
276
538
|
y: event.clientY
|
|
277
539
|
};
|
|
540
|
+
this.lastPointer = { ...this.startPointer };
|
|
278
541
|
this.startRect = { ...this.cropDisplay() };
|
|
279
542
|
this.captureTarget = event.currentTarget;
|
|
280
543
|
this.captureTarget.setPointerCapture(event.pointerId);
|
|
281
544
|
this.overhang = handle === "move" ? NO_SIDES : this.pastCrop(event);
|
|
282
545
|
}
|
|
283
546
|
onPointerMove(event) {
|
|
284
|
-
if (!this.active || event.pointerId !== this.pointerId) return;
|
|
547
|
+
if (!this.active || this.active === "pan" || event.pointerId !== this.pointerId) return;
|
|
548
|
+
this.lastPointer = {
|
|
549
|
+
x: event.clientX,
|
|
550
|
+
y: event.clientY
|
|
551
|
+
};
|
|
285
552
|
const dx = event.clientX - this.startPointer.x;
|
|
286
553
|
const dy = event.clientY - this.startPointer.y;
|
|
287
554
|
if (this.active === "move") {
|
|
@@ -292,17 +559,157 @@ var WrImageCropper = class WrImageCropper {
|
|
|
292
559
|
if (!this.withinImage(event)) this.onPointerUp(event);
|
|
293
560
|
}
|
|
294
561
|
onPointerUp(event) {
|
|
295
|
-
if (!this.active || event.pointerId !== this.pointerId) return;
|
|
562
|
+
if (!this.active || this.active === "pan" || event.pointerId !== this.pointerId) return;
|
|
563
|
+
this.endDrag();
|
|
564
|
+
this.emitCropped();
|
|
565
|
+
}
|
|
566
|
+
endDrag() {
|
|
296
567
|
const target = this.captureTarget;
|
|
568
|
+
const pointerId = this.pointerId;
|
|
297
569
|
this.active = null;
|
|
298
570
|
this.pointerId = null;
|
|
299
571
|
this.captureTarget = null;
|
|
300
572
|
this.overhang = NO_SIDES;
|
|
301
|
-
if (target?.hasPointerCapture(
|
|
573
|
+
if (pointerId !== null && target?.hasPointerCapture(pointerId)) target.releasePointerCapture(pointerId);
|
|
574
|
+
}
|
|
575
|
+
track(event) {
|
|
576
|
+
if (event.isPrimary) for (const [id, pointer] of this.pointers) {
|
|
577
|
+
if (pointer.type !== event.pointerType) continue;
|
|
578
|
+
this.pointers.delete(id);
|
|
579
|
+
if (this.pinch?.ids.includes(id)) this.pinch = null;
|
|
580
|
+
}
|
|
581
|
+
this.pointers.set(event.pointerId, {
|
|
582
|
+
x: event.clientX,
|
|
583
|
+
y: event.clientY,
|
|
584
|
+
type: event.pointerType
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
onStagePointerDown(event) {
|
|
588
|
+
if (event.button !== 0 || this.display().w === 0) return;
|
|
589
|
+
this.track(event);
|
|
590
|
+
if (this.pinch) return;
|
|
591
|
+
const same = [...this.pointers].filter(([, pointer]) => pointer.type === event.pointerType);
|
|
592
|
+
if (same.length === 2) {
|
|
593
|
+
event.preventDefault();
|
|
594
|
+
const [[, a], [, b]] = same;
|
|
595
|
+
this.active = null;
|
|
596
|
+
this.pointerId = null;
|
|
597
|
+
this.captureTarget = null;
|
|
598
|
+
this.overhang = NO_SIDES;
|
|
599
|
+
const ids = [same[0][0], same[1][0]];
|
|
600
|
+
this.pinch = {
|
|
601
|
+
ids,
|
|
602
|
+
distance: Math.hypot(a.x - b.x, a.y - b.y) || 1,
|
|
603
|
+
zoom: this.zoomLevel()
|
|
604
|
+
};
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (!event.isPrimary || this.zoomLevel() === 1) return;
|
|
608
|
+
event.preventDefault();
|
|
609
|
+
this.active = "pan";
|
|
610
|
+
this.pointerId = event.pointerId;
|
|
611
|
+
this.startPointer = {
|
|
612
|
+
x: event.clientX,
|
|
613
|
+
y: event.clientY
|
|
614
|
+
};
|
|
615
|
+
this.lastPointer = { ...this.startPointer };
|
|
616
|
+
this.startPan = this.pan();
|
|
617
|
+
this.captureTarget = event.currentTarget;
|
|
618
|
+
this.captureTarget.setPointerCapture(event.pointerId);
|
|
619
|
+
}
|
|
620
|
+
onStagePointerMove(event) {
|
|
621
|
+
const pointer = this.pointers.get(event.pointerId);
|
|
622
|
+
if (!pointer) return;
|
|
623
|
+
pointer.x = event.clientX;
|
|
624
|
+
pointer.y = event.clientY;
|
|
625
|
+
if (this.pinch) {
|
|
626
|
+
const a = this.pointers.get(this.pinch.ids[0]);
|
|
627
|
+
const b = this.pointers.get(this.pinch.ids[1]);
|
|
628
|
+
if (!a || !b || !this.pinch.ids.includes(event.pointerId)) return;
|
|
629
|
+
const distance = Math.hypot(a.x - b.x, a.y - b.y);
|
|
630
|
+
this.zoomAt(this.pinch.zoom * distance / this.pinch.distance, this.onStage((a.x + b.x) / 2, (a.y + b.y) / 2));
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (this.active !== "pan" || event.pointerId !== this.pointerId) return;
|
|
634
|
+
this.lastPointer = {
|
|
635
|
+
x: event.clientX,
|
|
636
|
+
y: event.clientY
|
|
637
|
+
};
|
|
638
|
+
this.setPan(this.startPan.x + event.clientX - this.startPointer.x, this.startPan.y + event.clientY - this.startPointer.y);
|
|
639
|
+
}
|
|
640
|
+
onStagePointerUp(event) {
|
|
641
|
+
if (!this.pointers.delete(event.pointerId)) return;
|
|
642
|
+
if (this.pinch) {
|
|
643
|
+
if (!this.pinch.ids.includes(event.pointerId)) return;
|
|
644
|
+
this.pinch = null;
|
|
645
|
+
this.scheduleEmit();
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
if (this.active !== "pan" || event.pointerId !== this.pointerId) return;
|
|
649
|
+
this.endDrag();
|
|
302
650
|
this.emitCropped();
|
|
303
651
|
}
|
|
652
|
+
onWheel(event) {
|
|
653
|
+
if (this.display().w === 0 || event.deltaY === 0) return;
|
|
654
|
+
const delta = event.deltaY * (event.deltaMode === 1 ? 16 : 1);
|
|
655
|
+
const rate = event.ctrlKey ? WHEEL_RATE_PINCH : WHEEL_RATE;
|
|
656
|
+
if (this.zoomAt(this.zoomLevel() * Math.exp(-delta * rate), this.onStage(event.clientX, event.clientY))) event.preventDefault();
|
|
657
|
+
}
|
|
658
|
+
stageOrigin() {
|
|
659
|
+
const box = this.sizerEl()?.nativeElement.getBoundingClientRect();
|
|
660
|
+
return box && box.width > 0 ? box : this.imgEl().nativeElement.getBoundingClientRect();
|
|
661
|
+
}
|
|
662
|
+
onStage(clientX, clientY) {
|
|
663
|
+
const box = this.stageOrigin();
|
|
664
|
+
return {
|
|
665
|
+
x: clientX - box.left,
|
|
666
|
+
y: clientY - box.top
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
zoomAt(zoom, at) {
|
|
670
|
+
const from = this.zoomLevel();
|
|
671
|
+
const to = coerceZoom(zoom);
|
|
672
|
+
if (to === from) return false;
|
|
673
|
+
const pan = this.pan();
|
|
674
|
+
this.setPan(at.x - (at.x - pan.x) / from * to, at.y - (at.y - pan.y) / from * to, to);
|
|
675
|
+
this.zoom.set(to);
|
|
676
|
+
return true;
|
|
677
|
+
}
|
|
678
|
+
setPan(x, y, zoom = this.zoomLevel()) {
|
|
679
|
+
const d = this.display();
|
|
680
|
+
if (d.w === 0 || d.h === 0) return;
|
|
681
|
+
const px = wrClamp(x, d.w - zoom * d.w, 0);
|
|
682
|
+
const py = wrClamp(y, d.h - zoom * d.h, 0);
|
|
683
|
+
this.center.set({
|
|
684
|
+
x: (d.w / 2 - px) / (zoom * d.w),
|
|
685
|
+
y: (d.h / 2 - py) / (zoom * d.h)
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
endGesture() {
|
|
689
|
+
this.endDrag();
|
|
690
|
+
this.pinch = null;
|
|
691
|
+
this.pointers.clear();
|
|
692
|
+
}
|
|
693
|
+
scheduleEmit() {
|
|
694
|
+
if (this.statusState() !== "loaded") return;
|
|
695
|
+
if (this.emitTimer !== null) clearTimeout(this.emitTimer);
|
|
696
|
+
this.emitTimer = setTimeout(() => {
|
|
697
|
+
this.emitTimer = null;
|
|
698
|
+
this.emitCropped();
|
|
699
|
+
}, EMIT_DELAY);
|
|
700
|
+
}
|
|
701
|
+
stageRect() {
|
|
702
|
+
const box = this.stageOrigin();
|
|
703
|
+
const d = this.display();
|
|
704
|
+
return {
|
|
705
|
+
left: box.left,
|
|
706
|
+
top: box.top,
|
|
707
|
+
right: box.left + d.w,
|
|
708
|
+
bottom: box.top + d.h
|
|
709
|
+
};
|
|
710
|
+
}
|
|
304
711
|
pastCrop(event) {
|
|
305
|
-
const box = this.
|
|
712
|
+
const box = this.stageRect();
|
|
306
713
|
const c = this.startRect;
|
|
307
714
|
return {
|
|
308
715
|
left: Math.max(0, box.left + c.x - event.clientX),
|
|
@@ -312,12 +719,13 @@ var WrImageCropper = class WrImageCropper {
|
|
|
312
719
|
};
|
|
313
720
|
}
|
|
314
721
|
withinImage(event) {
|
|
315
|
-
const box = this.
|
|
722
|
+
const box = this.stageRect();
|
|
316
723
|
const o = this.overhang;
|
|
317
724
|
return event.clientX >= box.left - o.left && event.clientX <= box.right + o.right && event.clientY >= box.top - o.top && event.clientY <= box.bottom + o.bottom;
|
|
318
725
|
}
|
|
319
726
|
keyboardDirty = false;
|
|
320
727
|
onWindowKeydown(event) {
|
|
728
|
+
if (this.onTransformKey(event)) return;
|
|
321
729
|
const step = event.shiftKey ? KEY_STEP_COARSE : KEY_STEP;
|
|
322
730
|
let dx = 0;
|
|
323
731
|
let dy = 0;
|
|
@@ -339,11 +747,42 @@ var WrImageCropper = class WrImageCropper {
|
|
|
339
747
|
event.preventDefault();
|
|
340
748
|
this.startRect = { ...this.cropDisplay() };
|
|
341
749
|
if (event.altKey) this.applyResize(dx !== 0 ? "e" : "s", dx, dy);
|
|
342
|
-
else
|
|
750
|
+
else {
|
|
751
|
+
this.applyMove(dx, dy);
|
|
752
|
+
const c = this.cropDisplay();
|
|
753
|
+
const restX = this.startRect.x + dx - c.x;
|
|
754
|
+
const restY = this.startRect.y + dy - c.y;
|
|
755
|
+
if (this.zoomLevel() > 1 && (restX !== 0 || restY !== 0)) {
|
|
756
|
+
const pan = this.pan();
|
|
757
|
+
this.setPan(pan.x - restX, pan.y - restY);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
343
760
|
this.keyboardDirty = true;
|
|
344
|
-
const c = this.
|
|
761
|
+
const c = this.turnedRect();
|
|
345
762
|
this.announcement.set(`${c.x}, ${c.y}, ${c.width} × ${c.height}`);
|
|
346
763
|
}
|
|
764
|
+
onTransformKey(event) {
|
|
765
|
+
if (event.ctrlKey || event.metaKey || event.altKey) return false;
|
|
766
|
+
const key = event.key;
|
|
767
|
+
const step = key === "+" || key === "=" ? ZOOM_KEY_STEP : key === "-" || key === "_" ? -.1 : 0;
|
|
768
|
+
if (step !== 0) {
|
|
769
|
+
event.preventDefault();
|
|
770
|
+
const c = this.cropDisplay();
|
|
771
|
+
this.zoomAt(Math.round((this.zoomLevel() + step) * 100) / 100, {
|
|
772
|
+
x: c.x + c.w / 2,
|
|
773
|
+
y: c.y + c.h / 2
|
|
774
|
+
});
|
|
775
|
+
this.announcement.set(this.zoomedText({ percent: Math.round(this.zoomLevel() * 100) }));
|
|
776
|
+
return true;
|
|
777
|
+
}
|
|
778
|
+
if (key === "r" || key === "R") {
|
|
779
|
+
event.preventDefault();
|
|
780
|
+
this.rotate(event.shiftKey ? "ccw" : "cw");
|
|
781
|
+
this.announcement.set(this.rotatedText({ degrees: this.angle() }));
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
347
786
|
onWindowKeyup() {
|
|
348
787
|
if (!this.keyboardDirty) return;
|
|
349
788
|
this.keyboardDirty = false;
|
|
@@ -383,6 +822,10 @@ var WrImageCropper = class WrImageCropper {
|
|
|
383
822
|
toDataUrl(type = this.outputType(), quality = this.outputQuality()) {
|
|
384
823
|
return this.toCanvas().toDataURL(type, quality);
|
|
385
824
|
}
|
|
825
|
+
rotate(direction = "cw") {
|
|
826
|
+
this.rotation.set((this.angle() + (direction === "ccw" ? 270 : 90)) % 360);
|
|
827
|
+
this.turnTo(this.angle());
|
|
828
|
+
}
|
|
386
829
|
async refresh() {
|
|
387
830
|
await this.emitCropped();
|
|
388
831
|
}
|
|
@@ -401,18 +844,29 @@ var WrImageCropper = class WrImageCropper {
|
|
|
401
844
|
const img = this.imgEl().nativeElement;
|
|
402
845
|
const c = this.cropRect();
|
|
403
846
|
const canvas = document.createElement("canvas");
|
|
404
|
-
const size = this.outputSize(
|
|
847
|
+
const size = this.outputSize(this.turnedRect());
|
|
405
848
|
canvas.width = size.width;
|
|
406
849
|
canvas.height = size.height;
|
|
407
850
|
const ctx = canvas.getContext("2d");
|
|
408
|
-
if (ctx)
|
|
851
|
+
if (!ctx) return canvas;
|
|
852
|
+
const angle = this.laidAngle();
|
|
853
|
+
if (angle === 0) {
|
|
854
|
+
ctx.drawImage(img, c.x, c.y, c.width, c.height, 0, 0, canvas.width, canvas.height);
|
|
855
|
+
return canvas;
|
|
856
|
+
}
|
|
857
|
+
const w = this.turned() ? canvas.height : canvas.width;
|
|
858
|
+
const h = this.turned() ? canvas.width : canvas.height;
|
|
859
|
+
ctx.translate(canvas.width / 2, canvas.height / 2);
|
|
860
|
+
ctx.rotate(angle * Math.PI / 180);
|
|
861
|
+
ctx.drawImage(img, c.x, c.y, c.width, c.height, -w / 2, -h / 2, w, h);
|
|
409
862
|
return canvas;
|
|
410
863
|
}
|
|
411
864
|
async emitCropped() {
|
|
412
865
|
if (this.status() !== "loaded") return;
|
|
866
|
+
const run = ++this.emitRun;
|
|
413
867
|
try {
|
|
414
868
|
const blob = await this.toBlob();
|
|
415
|
-
this.cropped.emit(blob);
|
|
869
|
+
if (run === this.emitRun) this.cropped.emit(blob);
|
|
416
870
|
} catch (error) {
|
|
417
871
|
if (isDevMode()) console.warn("[NGWR] <wr-image-cropper>: the crop could not be encoded, so (cropped) did not fire.", error);
|
|
418
872
|
}
|
|
@@ -480,14 +934,33 @@ var WrImageCropper = class WrImageCropper {
|
|
|
480
934
|
isSignal: true,
|
|
481
935
|
isRequired: false,
|
|
482
936
|
transformFunction: null
|
|
937
|
+
},
|
|
938
|
+
zoom: {
|
|
939
|
+
classPropertyName: "zoom",
|
|
940
|
+
publicName: "zoom",
|
|
941
|
+
isSignal: true,
|
|
942
|
+
isRequired: false,
|
|
943
|
+
transformFunction: null
|
|
944
|
+
},
|
|
945
|
+
rotation: {
|
|
946
|
+
classPropertyName: "rotation",
|
|
947
|
+
publicName: "rotation",
|
|
948
|
+
isSignal: true,
|
|
949
|
+
isRequired: false,
|
|
950
|
+
transformFunction: null
|
|
483
951
|
}
|
|
484
952
|
},
|
|
485
953
|
outputs: {
|
|
954
|
+
zoom: "zoomChange",
|
|
955
|
+
rotation: "rotationChange",
|
|
486
956
|
cropped: "cropped",
|
|
487
957
|
loadError: "loadError"
|
|
488
958
|
},
|
|
489
959
|
host: {
|
|
490
|
-
properties: {
|
|
960
|
+
properties: {
|
|
961
|
+
"class.wr-image-cropper--failed": "status() === 'failed'",
|
|
962
|
+
"class.wr-image-cropper--zoomed": "zoomLevel() > 1"
|
|
963
|
+
},
|
|
491
964
|
classAttribute: "wr-image-cropper"
|
|
492
965
|
},
|
|
493
966
|
viewQueries: [{
|
|
@@ -496,9 +969,15 @@ var WrImageCropper = class WrImageCropper {
|
|
|
496
969
|
predicate: ["img"],
|
|
497
970
|
descendants: true,
|
|
498
971
|
isSignal: true
|
|
972
|
+
}, {
|
|
973
|
+
propertyName: "sizerEl",
|
|
974
|
+
first: true,
|
|
975
|
+
predicate: ["sizer"],
|
|
976
|
+
descendants: true,
|
|
977
|
+
isSignal: true
|
|
499
978
|
}],
|
|
500
979
|
ngImport: i0,
|
|
501
|
-
template: "@if (objectUrl(); as url) {\n <div
|
|
980
|
+
template: "@if (objectUrl(); as url) {\n <!--\n The stage. A press on it that the crop window did not take pans the zoomed image, a\n second finger pinches, and the wheel zooms: see `onStagePointerDown` and `onWheel`.\n -->\n <div\n class=\"wr-image-cropper__canvas\"\n [style.width.px]=\"stageBox()?.w\"\n [style.height.px]=\"stageBox()?.h\"\n (pointerdown)=\"onStagePointerDown($event)\"\n (pointermove)=\"onStagePointerMove($event)\"\n (pointerup)=\"onStagePointerUp($event)\"\n (pointercancel)=\"onStagePointerUp($event)\"\n (wheel)=\"onWheel($event)\"\n >\n <!--\n The picture, and the element `toCanvas` draws from. Until it is measured it sits in\n the layout and sizes the stage. From then on the sizer below does that, and this is\n laid over the stage and zoomed, panned and turned. The viewport clips it; the stage\n cannot, or it would clip the handles that overhang its edge.\n\n `crossorigin` is what lets a URL on another origin be exported at all: an image\n fetched without it taints the canvas `toCanvas` draws into, even when the server\n sends CORS headers, and every export then throws a SecurityError. It is static\n so it is in place before `src` starts the request.\n -->\n <div class=\"wr-image-cropper__viewport\" [class.wr-image-cropper__viewport--on]=\"measured()\">\n <img\n #img\n class=\"wr-image-cropper__image\"\n crossorigin=\"anonymous\"\n [class.wr-image-cropper__image--measured]=\"measured()\"\n [style.width.px]=\"view()?.w\"\n [style.height.px]=\"view()?.h\"\n [style.transform]=\"view()?.transform\"\n [src]=\"url\"\n alt=\"\"\n draggable=\"false\"\n (load)=\"onImageLoad()\"\n (error)=\"onImageError()\"\n />\n </div>\n\n <!--\n Holds the stage open once the image is measured: a blank canvas with the source's\n dimensions, swapped while the image is turned, which the stylesheet sizes as it\n sized the image.\n -->\n @if (natural().w > 0) {\n <canvas\n #sizer\n class=\"wr-image-cropper__sizer\"\n aria-hidden=\"true\"\n [width]=\"turned() ? natural().h : natural().w\"\n [height]=\"turned() ? natural().w : natural().h\"\n ></canvas>\n }\n\n @if (display().w > 0) {\n <!-- Semi-transparent backdrop with a cut-out for the crop window. -->\n <div\n class=\"wr-image-cropper__backdrop\"\n [style.clip-path]=\"`polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 ${cropDisplay().y}px, ${cropDisplay().x}px ${cropDisplay().y}px, ${cropDisplay().x}px ${cropDisplay().y + cropDisplay().h}px, ${cropDisplay().x + cropDisplay().w}px ${cropDisplay().y + cropDisplay().h}px, ${cropDisplay().x + cropDisplay().w}px ${cropDisplay().y}px, 0 ${cropDisplay().y}px)`\"\n ></div>\n\n <!--\n Crop window — drag to move, with eight resize handles, and the ONE\n keyboard control the component has (see `onWindowKeydown`). The eight\n handles stay pointer-only and `aria-hidden`: eight extra tab stops per\n cropper would be hostile. The keys resize from the east and south edges\n only, so a west or north drag comes out as a resize plus a move rather\n than as one gesture.\n\n `role=\"group\"` rather than no role at all, because `aria-label` is\n prohibited on a roleless `<div>` and this needs a name; and rather than\n `role=\"application\"`, which would switch the reader out of its own\n browse mode for the whole subtree — far more than one rectangle is worth.\n -->\n <div\n class=\"wr-image-cropper__window\"\n role=\"group\"\n tabindex=\"0\"\n [attr.aria-label]=\"resolvedWindowLabel()\"\n [attr.aria-describedby]=\"helpId\"\n [style.left.px]=\"cropDisplay().x\"\n [style.top.px]=\"cropDisplay().y\"\n [style.width.px]=\"cropDisplay().w\"\n [style.height.px]=\"cropDisplay().h\"\n (pointerdown)=\"onPointerDown('move', $event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerUp($event)\"\n (lostpointercapture)=\"onPointerUp($event)\"\n (keydown)=\"onWindowKeydown($event)\"\n (keyup)=\"onWindowKeyup()\"\n >\n @for (h of handles; track h) {\n <span\n aria-hidden=\"true\"\n [class]=\"`wr-image-cropper__handle wr-image-cropper__handle--${h}`\"\n (pointerdown)=\"onPointerDown(h, $event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerUp($event)\"\n (lostpointercapture)=\"onPointerUp($event)\"\n ></span>\n }\n </div>\n\n <p class=\"wr-image-cropper__sr-only\" [id]=\"helpId\">{{ resolvedKeyHelp() }} {{ resolvedTransformHelp() }}</p>\n\n <!--\n The crop rect in SOURCE pixels (or the new zoom or rotation, as a catalog\n sentence), announced after a keyboard change only:\n a pointer drag already gives sighted feedback and would flood the region,\n and the initial crop is not news. Deliberately bare numbers: a sentence\n here would be a translated string the catalog does not carry, and the\n reader has just been told what the four numbers mean by `helpId`.\n -->\n <p class=\"wr-image-cropper__sr-only\" role=\"status\">{{ announcement() }}</p>\n }\n </div>\n} @else {\n <div class=\"wr-image-cropper__empty\">{{ emptyText() }}</div>\n}\n",
|
|
502
981
|
encapsulation: i0.ViewEncapsulation.None
|
|
503
982
|
});
|
|
504
983
|
};
|
|
@@ -514,9 +993,10 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
514
993
|
encapsulation: ViewEncapsulation.None,
|
|
515
994
|
host: {
|
|
516
995
|
class: "wr-image-cropper",
|
|
517
|
-
"[class.wr-image-cropper--failed]": "status() === 'failed'"
|
|
996
|
+
"[class.wr-image-cropper--failed]": "status() === 'failed'",
|
|
997
|
+
"[class.wr-image-cropper--zoomed]": "zoomLevel() > 1"
|
|
518
998
|
},
|
|
519
|
-
template: "@if (objectUrl(); as url) {\n <div
|
|
999
|
+
template: "@if (objectUrl(); as url) {\n <!--\n The stage. A press on it that the crop window did not take pans the zoomed image, a\n second finger pinches, and the wheel zooms: see `onStagePointerDown` and `onWheel`.\n -->\n <div\n class=\"wr-image-cropper__canvas\"\n [style.width.px]=\"stageBox()?.w\"\n [style.height.px]=\"stageBox()?.h\"\n (pointerdown)=\"onStagePointerDown($event)\"\n (pointermove)=\"onStagePointerMove($event)\"\n (pointerup)=\"onStagePointerUp($event)\"\n (pointercancel)=\"onStagePointerUp($event)\"\n (wheel)=\"onWheel($event)\"\n >\n <!--\n The picture, and the element `toCanvas` draws from. Until it is measured it sits in\n the layout and sizes the stage. From then on the sizer below does that, and this is\n laid over the stage and zoomed, panned and turned. The viewport clips it; the stage\n cannot, or it would clip the handles that overhang its edge.\n\n `crossorigin` is what lets a URL on another origin be exported at all: an image\n fetched without it taints the canvas `toCanvas` draws into, even when the server\n sends CORS headers, and every export then throws a SecurityError. It is static\n so it is in place before `src` starts the request.\n -->\n <div class=\"wr-image-cropper__viewport\" [class.wr-image-cropper__viewport--on]=\"measured()\">\n <img\n #img\n class=\"wr-image-cropper__image\"\n crossorigin=\"anonymous\"\n [class.wr-image-cropper__image--measured]=\"measured()\"\n [style.width.px]=\"view()?.w\"\n [style.height.px]=\"view()?.h\"\n [style.transform]=\"view()?.transform\"\n [src]=\"url\"\n alt=\"\"\n draggable=\"false\"\n (load)=\"onImageLoad()\"\n (error)=\"onImageError()\"\n />\n </div>\n\n <!--\n Holds the stage open once the image is measured: a blank canvas with the source's\n dimensions, swapped while the image is turned, which the stylesheet sizes as it\n sized the image.\n -->\n @if (natural().w > 0) {\n <canvas\n #sizer\n class=\"wr-image-cropper__sizer\"\n aria-hidden=\"true\"\n [width]=\"turned() ? natural().h : natural().w\"\n [height]=\"turned() ? natural().w : natural().h\"\n ></canvas>\n }\n\n @if (display().w > 0) {\n <!-- Semi-transparent backdrop with a cut-out for the crop window. -->\n <div\n class=\"wr-image-cropper__backdrop\"\n [style.clip-path]=\"`polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 ${cropDisplay().y}px, ${cropDisplay().x}px ${cropDisplay().y}px, ${cropDisplay().x}px ${cropDisplay().y + cropDisplay().h}px, ${cropDisplay().x + cropDisplay().w}px ${cropDisplay().y + cropDisplay().h}px, ${cropDisplay().x + cropDisplay().w}px ${cropDisplay().y}px, 0 ${cropDisplay().y}px)`\"\n ></div>\n\n <!--\n Crop window — drag to move, with eight resize handles, and the ONE\n keyboard control the component has (see `onWindowKeydown`). The eight\n handles stay pointer-only and `aria-hidden`: eight extra tab stops per\n cropper would be hostile. The keys resize from the east and south edges\n only, so a west or north drag comes out as a resize plus a move rather\n than as one gesture.\n\n `role=\"group\"` rather than no role at all, because `aria-label` is\n prohibited on a roleless `<div>` and this needs a name; and rather than\n `role=\"application\"`, which would switch the reader out of its own\n browse mode for the whole subtree — far more than one rectangle is worth.\n -->\n <div\n class=\"wr-image-cropper__window\"\n role=\"group\"\n tabindex=\"0\"\n [attr.aria-label]=\"resolvedWindowLabel()\"\n [attr.aria-describedby]=\"helpId\"\n [style.left.px]=\"cropDisplay().x\"\n [style.top.px]=\"cropDisplay().y\"\n [style.width.px]=\"cropDisplay().w\"\n [style.height.px]=\"cropDisplay().h\"\n (pointerdown)=\"onPointerDown('move', $event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerUp($event)\"\n (lostpointercapture)=\"onPointerUp($event)\"\n (keydown)=\"onWindowKeydown($event)\"\n (keyup)=\"onWindowKeyup()\"\n >\n @for (h of handles; track h) {\n <span\n aria-hidden=\"true\"\n [class]=\"`wr-image-cropper__handle wr-image-cropper__handle--${h}`\"\n (pointerdown)=\"onPointerDown(h, $event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerUp($event)\"\n (lostpointercapture)=\"onPointerUp($event)\"\n ></span>\n }\n </div>\n\n <p class=\"wr-image-cropper__sr-only\" [id]=\"helpId\">{{ resolvedKeyHelp() }} {{ resolvedTransformHelp() }}</p>\n\n <!--\n The crop rect in SOURCE pixels (or the new zoom or rotation, as a catalog\n sentence), announced after a keyboard change only:\n a pointer drag already gives sighted feedback and would flood the region,\n and the initial crop is not news. Deliberately bare numbers: a sentence\n here would be a translated string the catalog does not carry, and the\n reader has just been told what the four numbers mean by `helpId`.\n -->\n <p class=\"wr-image-cropper__sr-only\" role=\"status\">{{ announcement() }}</p>\n }\n </div>\n} @else {\n <div class=\"wr-image-cropper__empty\">{{ emptyText() }}</div>\n}\n"
|
|
520
1000
|
}]
|
|
521
1001
|
}],
|
|
522
1002
|
ctorParameters: () => [],
|
|
@@ -577,6 +1057,28 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
577
1057
|
required: false
|
|
578
1058
|
}]
|
|
579
1059
|
}],
|
|
1060
|
+
zoom: [{
|
|
1061
|
+
type: i0.Input,
|
|
1062
|
+
args: [{
|
|
1063
|
+
isSignal: true,
|
|
1064
|
+
alias: "zoom",
|
|
1065
|
+
required: false
|
|
1066
|
+
}]
|
|
1067
|
+
}, {
|
|
1068
|
+
type: i0.Output,
|
|
1069
|
+
args: ["zoomChange"]
|
|
1070
|
+
}],
|
|
1071
|
+
rotation: [{
|
|
1072
|
+
type: i0.Input,
|
|
1073
|
+
args: [{
|
|
1074
|
+
isSignal: true,
|
|
1075
|
+
alias: "rotation",
|
|
1076
|
+
required: false
|
|
1077
|
+
}]
|
|
1078
|
+
}, {
|
|
1079
|
+
type: i0.Output,
|
|
1080
|
+
args: ["rotationChange"]
|
|
1081
|
+
}],
|
|
580
1082
|
cropped: [{
|
|
581
1083
|
type: i0.Output,
|
|
582
1084
|
args: ["cropped"]
|
|
@@ -588,6 +1090,10 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
588
1090
|
imgEl: [{
|
|
589
1091
|
type: i0.ViewChild,
|
|
590
1092
|
args: ["img", { isSignal: true }]
|
|
1093
|
+
}],
|
|
1094
|
+
sizerEl: [{
|
|
1095
|
+
type: i0.ViewChild,
|
|
1096
|
+
args: ["sizer", { isSignal: true }]
|
|
591
1097
|
}]
|
|
592
1098
|
}
|
|
593
1099
|
});
|