@dnncommunity/dnn-elements 0.13.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/cjs/app-globals-3a1e7e63.js +7 -0
- package/dist/cjs/app-globals-3a1e7e63.js.map +1 -0
- package/dist/cjs/css-shim-3bfdba4f.js +8 -0
- package/dist/cjs/css-shim-3bfdba4f.js.map +1 -0
- package/dist/cjs/debounce-1de79bc7.js +24 -0
- package/dist/cjs/debounce-1de79bc7.js.map +1 -0
- package/dist/cjs/dnn-button.cjs.entry.js +88 -0
- package/dist/cjs/dnn-button.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-button_14.cjs.entry.js +1580 -0
- package/dist/cjs/dnn-button_14.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-checkbox.cjs.entry.js +58 -0
- package/dist/cjs/dnn-checkbox.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-chevron.cjs.entry.js +34 -0
- package/dist/cjs/dnn-chevron.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-collapsible.cjs.entry.js +112 -0
- package/dist/cjs/dnn-collapsible.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-color-picker.cjs.entry.js +508 -0
- package/dist/cjs/dnn-color-picker.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-dropzone.cjs.entry.js +153 -0
- package/dist/cjs/dnn-dropzone.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-image-cropper.cjs.entry.js +424 -0
- package/dist/cjs/dnn-image-cropper.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-modal.cjs.entry.js +62 -0
- package/dist/cjs/dnn-modal.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-searchbox.cjs.entry.js +66 -0
- package/dist/cjs/dnn-searchbox.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-sort-icon.cjs.entry.js +43 -0
- package/dist/cjs/dnn-sort-icon.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-tab.cjs.entry.js +31 -0
- package/dist/cjs/dnn-tab.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-tabs.cjs.entry.js +50 -0
- package/dist/cjs/dnn-tabs.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-toggle.cjs.entry.js +37 -0
- package/dist/cjs/dnn-toggle.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn-treeview-item.cjs.entry.js +48 -0
- package/dist/cjs/dnn-treeview-item.cjs.entry.js.map +1 -0
- package/dist/cjs/dnn.cjs.js +129 -0
- package/dist/cjs/dnn.cjs.js.map +1 -0
- package/dist/cjs/dom-8ac1ad03.js +77 -0
- package/dist/cjs/dom-8ac1ad03.js.map +1 -0
- package/dist/cjs/index-e85ec026.js +1327 -0
- package/dist/cjs/index-e85ec026.js.map +1 -0
- package/dist/cjs/index-eede7745.js +3069 -0
- package/dist/cjs/index-eede7745.js.map +1 -0
- package/dist/cjs/index.cjs.js +52 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/loader.cjs.js +39 -0
- package/dist/cjs/loader.cjs.js.map +1 -0
- package/dist/cjs/shadow-css-41d9783d.js +392 -0
- package/dist/cjs/shadow-css-41d9783d.js.map +1 -0
- package/dist/collection/collection-manifest.json +25 -0
- package/dist/collection/components/dnn-button/dnn-button.css +87 -0
- package/dist/collection/components/dnn-button/dnn-button.js +272 -0
- package/dist/collection/components/dnn-button/dnn-button.js.map +1 -0
- package/dist/collection/components/dnn-checkbox/dnn-checkbox.css +27 -0
- package/dist/collection/components/dnn-checkbox/dnn-checkbox.js +140 -0
- package/dist/collection/components/dnn-checkbox/dnn-checkbox.js.map +1 -0
- package/dist/collection/components/dnn-chevron/dnn-chevron.css +30 -0
- package/dist/collection/components/dnn-chevron/dnn-chevron.js +107 -0
- package/dist/collection/components/dnn-chevron/dnn-chevron.js.map +1 -0
- package/dist/collection/components/dnn-collapsible/dnn-collapsible.css +8 -0
- package/dist/collection/components/dnn-collapsible/dnn-collapsible.js +188 -0
- package/dist/collection/components/dnn-collapsible/dnn-collapsible.js.map +1 -0
- package/dist/collection/components/dnn-color-picker/dnn-color-picker.css +225 -0
- package/dist/collection/components/dnn-color-picker/dnn-color-picker.js +434 -0
- package/dist/collection/components/dnn-color-picker/dnn-color-picker.js.map +1 -0
- package/dist/collection/components/dnn-dropzone/dnn-dropzone.css +62 -0
- package/dist/collection/components/dnn-dropzone/dnn-dropzone.js +266 -0
- package/dist/collection/components/dnn-dropzone/dnn-dropzone.js.map +1 -0
- package/dist/collection/components/dnn-image-cropper/CornerType.js +9 -0
- package/dist/collection/components/dnn-image-cropper/CornerType.js.map +1 -0
- package/dist/collection/components/dnn-image-cropper/dnn-image-cropper.css +80 -0
- package/dist/collection/components/dnn-image-cropper/dnn-image-cropper.js +539 -0
- package/dist/collection/components/dnn-image-cropper/dnn-image-cropper.js.map +1 -0
- package/dist/collection/components/dnn-modal/dnn-modal.css +67 -0
- package/dist/collection/components/dnn-modal/dnn-modal.js +173 -0
- package/dist/collection/components/dnn-modal/dnn-modal.js.map +1 -0
- package/dist/collection/components/dnn-searchbox/dnn-searchbox.css +48 -0
- package/dist/collection/components/dnn-searchbox/dnn-searchbox.js +137 -0
- package/dist/collection/components/dnn-searchbox/dnn-searchbox.js.map +1 -0
- package/dist/collection/components/dnn-sort-icon/dnn-sort-icon.css +32 -0
- package/dist/collection/components/dnn-sort-icon/dnn-sort-icon.js +81 -0
- package/dist/collection/components/dnn-sort-icon/dnn-sort-icon.js.map +1 -0
- package/dist/collection/components/dnn-tab/dnn-tab.css +0 -0
- package/dist/collection/components/dnn-tab/dnn-tab.js +84 -0
- package/dist/collection/components/dnn-tab/dnn-tab.js.map +1 -0
- package/dist/collection/components/dnn-tabs/dnn-tabs.css +40 -0
- package/dist/collection/components/dnn-tabs/dnn-tabs.js +53 -0
- package/dist/collection/components/dnn-tabs/dnn-tabs.js.map +1 -0
- package/dist/collection/components/dnn-toggle/dnn-toggle.css +52 -0
- package/dist/collection/components/dnn-toggle/dnn-toggle.js +94 -0
- package/dist/collection/components/dnn-toggle/dnn-toggle.js.map +1 -0
- package/dist/collection/components/dnn-toggle/toggle-interface.js +2 -0
- package/dist/collection/components/dnn-toggle/toggle-interface.js.map +1 -0
- package/dist/collection/components/dnn-treeview-item/dnn-treeview-item.css +47 -0
- package/dist/collection/components/dnn-treeview-item/dnn-treeview-item.js +77 -0
- package/dist/collection/components/dnn-treeview-item/dnn-treeview-item.js.map +1 -0
- package/dist/collection/index.js +3 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/utilities/colorInfo.js +191 -0
- package/dist/collection/utilities/colorInfo.js.map +1 -0
- package/dist/collection/utilities/debounce.js +19 -0
- package/dist/collection/utilities/debounce.js.map +1 -0
- package/dist/collection/utilities/dnnServicesFramework.js +42 -0
- package/dist/collection/utilities/dnnServicesFramework.js.map +1 -0
- package/dist/dnn/app-globals-0f993ce5.js +5 -0
- package/dist/dnn/app-globals-0f993ce5.js.map +1 -0
- package/dist/dnn/css-shim-20dbffa5.js +6 -0
- package/dist/dnn/css-shim-20dbffa5.js.map +1 -0
- package/dist/dnn/debounce-06f55268.js +22 -0
- package/dist/dnn/debounce-06f55268.js.map +1 -0
- package/dist/dnn/dnn-button.entry.js +84 -0
- package/dist/dnn/dnn-button.entry.js.map +1 -0
- package/dist/dnn/dnn-checkbox.entry.js +54 -0
- package/dist/dnn/dnn-checkbox.entry.js.map +1 -0
- package/dist/dnn/dnn-chevron.entry.js +30 -0
- package/dist/dnn/dnn-chevron.entry.js.map +1 -0
- package/dist/dnn/dnn-collapsible.entry.js +108 -0
- package/dist/dnn/dnn-collapsible.entry.js.map +1 -0
- package/dist/dnn/dnn-color-picker.entry.js +504 -0
- package/dist/dnn/dnn-color-picker.entry.js.map +1 -0
- package/dist/dnn/dnn-dropzone.entry.js +149 -0
- package/dist/dnn/dnn-dropzone.entry.js.map +1 -0
- package/dist/dnn/dnn-image-cropper.entry.js +420 -0
- package/dist/dnn/dnn-image-cropper.entry.js.map +1 -0
- package/dist/dnn/dnn-modal.entry.js +58 -0
- package/dist/dnn/dnn-modal.entry.js.map +1 -0
- package/dist/dnn/dnn-searchbox.entry.js +62 -0
- package/dist/dnn/dnn-searchbox.entry.js.map +1 -0
- package/dist/dnn/dnn-sort-icon.entry.js +39 -0
- package/dist/dnn/dnn-sort-icon.entry.js.map +1 -0
- package/dist/dnn/dnn-tab.entry.js +27 -0
- package/dist/dnn/dnn-tab.entry.js.map +1 -0
- package/dist/dnn/dnn-tabs.entry.js +46 -0
- package/dist/dnn/dnn-tabs.entry.js.map +1 -0
- package/dist/dnn/dnn-toggle.entry.js +33 -0
- package/dist/dnn/dnn-toggle.entry.js.map +1 -0
- package/dist/dnn/dnn-treeview-item.entry.js +44 -0
- package/dist/dnn/dnn-treeview-item.entry.js.map +1 -0
- package/dist/dnn/dnn.esm.js +127 -0
- package/dist/dnn/dnn.esm.js.map +1 -0
- package/dist/dnn/dom-c5ed0ba5.js +75 -0
- package/dist/dnn/dom-c5ed0ba5.js.map +1 -0
- package/dist/dnn/index-6c0764e5.js +3033 -0
- package/dist/dnn/index-6c0764e5.js.map +1 -0
- package/dist/dnn/index.esm.js +47 -0
- package/dist/dnn/index.esm.js.map +1 -0
- package/dist/dnn/p-0e94f5ee.js +2 -0
- package/dist/dnn/p-0e94f5ee.js.map +1 -0
- package/dist/dnn/p-7acf3104.entry.js +11 -0
- package/dist/dnn/p-7acf3104.entry.js.map +1 -0
- package/dist/dnn/p-bd3d3361.js +2 -0
- package/dist/dnn/p-bd3d3361.js.map +1 -0
- package/dist/dnn/shadow-css-8c625855.js +390 -0
- package/dist/dnn/shadow-css-8c625855.js.map +1 -0
- package/dist/esm/app-globals-0f993ce5.js +5 -0
- package/dist/esm/app-globals-0f993ce5.js.map +1 -0
- package/dist/esm/css-shim-20dbffa5.js +6 -0
- package/dist/esm/css-shim-20dbffa5.js.map +1 -0
- package/dist/esm/debounce-06f55268.js +22 -0
- package/dist/esm/debounce-06f55268.js.map +1 -0
- package/dist/esm/dnn-button.entry.js +84 -0
- package/dist/esm/dnn-button.entry.js.map +1 -0
- package/dist/esm/dnn-button_14.entry.js +1563 -0
- package/dist/esm/dnn-button_14.entry.js.map +1 -0
- package/dist/esm/dnn-checkbox.entry.js +54 -0
- package/dist/esm/dnn-checkbox.entry.js.map +1 -0
- package/dist/esm/dnn-chevron.entry.js +30 -0
- package/dist/esm/dnn-chevron.entry.js.map +1 -0
- package/dist/esm/dnn-collapsible.entry.js +108 -0
- package/dist/esm/dnn-collapsible.entry.js.map +1 -0
- package/dist/esm/dnn-color-picker.entry.js +504 -0
- package/dist/esm/dnn-color-picker.entry.js.map +1 -0
- package/dist/esm/dnn-dropzone.entry.js +149 -0
- package/dist/esm/dnn-dropzone.entry.js.map +1 -0
- package/dist/esm/dnn-image-cropper.entry.js +420 -0
- package/dist/esm/dnn-image-cropper.entry.js.map +1 -0
- package/dist/esm/dnn-modal.entry.js +58 -0
- package/dist/esm/dnn-modal.entry.js.map +1 -0
- package/dist/esm/dnn-searchbox.entry.js +62 -0
- package/dist/esm/dnn-searchbox.entry.js.map +1 -0
- package/dist/esm/dnn-sort-icon.entry.js +39 -0
- package/dist/esm/dnn-sort-icon.entry.js.map +1 -0
- package/dist/esm/dnn-tab.entry.js +27 -0
- package/dist/esm/dnn-tab.entry.js.map +1 -0
- package/dist/esm/dnn-tabs.entry.js +46 -0
- package/dist/esm/dnn-tabs.entry.js.map +1 -0
- package/dist/esm/dnn-toggle.entry.js +33 -0
- package/dist/esm/dnn-toggle.entry.js.map +1 -0
- package/dist/esm/dnn-treeview-item.entry.js +44 -0
- package/dist/esm/dnn-treeview-item.entry.js.map +1 -0
- package/dist/esm/dnn.js +127 -0
- package/dist/esm/dnn.js.map +1 -0
- package/dist/esm/dom-c5ed0ba5.js +75 -0
- package/dist/esm/dom-c5ed0ba5.js.map +1 -0
- package/dist/esm/index-6c0764e5.js +3033 -0
- package/dist/esm/index-6c0764e5.js.map +1 -0
- package/dist/esm/index-f79d9e82.js +1299 -0
- package/dist/esm/index-f79d9e82.js.map +1 -0
- package/dist/esm/index.js +47 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/loader.js +35 -0
- package/dist/esm/loader.js.map +1 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/esm/shadow-css-8c625855.js +390 -0
- package/dist/esm/shadow-css-8c625855.js.map +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/components/dnn-button/dnn-button.d.ts +55 -0
- package/dist/types/components/dnn-checkbox/dnn-checkbox.d.ts +16 -0
- package/dist/types/components/dnn-chevron/dnn-chevron.d.ts +13 -0
- package/dist/types/components/dnn-collapsible/dnn-collapsible.d.ts +22 -0
- package/dist/types/components/dnn-color-picker/dnn-color-picker.d.ts +46 -0
- package/dist/types/components/dnn-dropzone/dnn-dropzone.d.ts +45 -0
- package/dist/types/components/dnn-image-cropper/CornerType.d.ts +6 -0
- package/dist/types/components/dnn-image-cropper/dnn-image-cropper.d.ts +62 -0
- package/dist/types/components/dnn-modal/dnn-modal.d.ts +35 -0
- package/dist/types/components/dnn-searchbox/dnn-searchbox.d.ts +22 -0
- package/dist/types/components/dnn-sort-icon/dnn-sort-icon.d.ts +9 -0
- package/dist/types/components/dnn-tab/dnn-tab.d.ts +11 -0
- package/dist/types/components/dnn-tabs/dnn-tabs.d.ts +11 -0
- package/dist/types/components/dnn-toggle/dnn-toggle.d.ts +13 -0
- package/dist/types/components/dnn-toggle/toggle-interface.d.ts +3 -0
- package/dist/types/components/dnn-treeview-item/dnn-treeview-item.d.ts +16 -0
- package/dist/types/components.d.ts +611 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/stencil-public-runtime.d.ts +1565 -0
- package/dist/types/utilities/colorInfo.d.ts +52 -0
- package/dist/types/utilities/debounce.d.ts +5 -0
- package/dist/types/utilities/dnnServicesFramework.d.ts +19 -0
- package/loader/cdn.js +3 -0
- package/loader/index.cjs.js +3 -0
- package/loader/index.d.ts +12 -0
- package/loader/index.es2017.js +3 -0
- package/loader/index.js +4 -0
- package/loader/package.json +10 -0
- package/package.json +48 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { r as registerInstance, e as createEvent, h, f as Host } from './index-6c0764e5.js';
|
|
2
|
+
|
|
3
|
+
const dnnDropzoneCss = ":host{--border-color:var(--dnn-color-tertiary-contrast, lightgray);--border-radius:var(--dnn-controls-radius, 5px);--drop-background-color:var(--dnn-color-tertiary, lightblue);display:flex;flex-direction:column;gap:1rem;text-align:center;border:2px dashed var(--border-color);border-radius:var(--border-radius);padding:1rem;transition:all 300ms ease-in-out}:host(.dropping){background-color:var(--drop-background-color)}p{margin:0;padding:0}button{display:flex;justify-content:center;align-items:center;border:0px;margin:0;padding:0;background-color:transparent}button:hover{cursor:pointer}button svg{margin-right:0.5rem}label.upload-file{display:flex;justify-content:center;align-items:center;cursor:pointer}label.upload-file input{display:none}.video-preview{display:flex;flex-direction:column;align-items:center}.video-preview button{margin:1rem}";
|
|
4
|
+
|
|
5
|
+
let DnnDropzone = class {
|
|
6
|
+
constructor(hostRef) {
|
|
7
|
+
registerInstance(this, hostRef);
|
|
8
|
+
this.filesSelected = createEvent(this, "filesSelected", 7);
|
|
9
|
+
/** Localization strings */
|
|
10
|
+
this.resx = {
|
|
11
|
+
dragAndDropFile: "Drag and drop a file",
|
|
12
|
+
capture: "Capture",
|
|
13
|
+
or: "or",
|
|
14
|
+
takePicture: "Take a picture",
|
|
15
|
+
uploadFile: "Upload a file",
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* If true, will allow the user to take a snapshot
|
|
19
|
+
* using the device camera. (only works over https).
|
|
20
|
+
*/
|
|
21
|
+
this.allowCameraMode = false;
|
|
22
|
+
/**
|
|
23
|
+
* Specifies the jpeg quality for when the device
|
|
24
|
+
* camera is used to generate a picture.
|
|
25
|
+
* Needs to be a number between 0 and 1 and defaults to 0.8
|
|
26
|
+
*/
|
|
27
|
+
this.captureQuality = 0.8;
|
|
28
|
+
this.canTakeSnapshots = false;
|
|
29
|
+
this.takingPicture = false;
|
|
30
|
+
this.handleDragOver = (event) => {
|
|
31
|
+
event.stopPropagation();
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
event.dataTransfer.dropEffect = "copy";
|
|
34
|
+
this.dropzone.classList.add("dropping");
|
|
35
|
+
};
|
|
36
|
+
this.handleDrop = (dropEvent) => {
|
|
37
|
+
dropEvent.stopPropagation();
|
|
38
|
+
dropEvent.preventDefault();
|
|
39
|
+
const files = dropEvent.dataTransfer.files;
|
|
40
|
+
if (this.hasInvalidExtensions(files)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
var fileList = this.getFilesFromFileList(files);
|
|
44
|
+
this.filesSelected.emit(fileList);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
componentDidLoad() {
|
|
48
|
+
if (this.allowCameraMode) {
|
|
49
|
+
this.checkIfBrowserCanTakeSnapshots()
|
|
50
|
+
.then(result => this.canTakeSnapshots = result);
|
|
51
|
+
}
|
|
52
|
+
if (this.allowedExtensions != undefined && this.allowedExtensions.length > 0) {
|
|
53
|
+
var extensionsWithDots = this.allowedExtensions.map(e => `.${e}`);
|
|
54
|
+
var extensionsList = extensionsWithDots.join(",");
|
|
55
|
+
this.fileInput.accept = extensionsList;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
checkIfBrowserCanTakeSnapshots() {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const mediaDevices = navigator.mediaDevices;
|
|
61
|
+
if (mediaDevices == undefined || mediaDevices.enumerateDevices == undefined) {
|
|
62
|
+
resolve(false);
|
|
63
|
+
}
|
|
64
|
+
mediaDevices.enumerateDevices()
|
|
65
|
+
.then(devices => {
|
|
66
|
+
var result = devices.some(device => device.kind == "videoinput");
|
|
67
|
+
resolve(result);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
getFilesFromFileList(files) {
|
|
72
|
+
var fileList = [];
|
|
73
|
+
for (let index = 0; index < files.length; index++) {
|
|
74
|
+
const file = files[index];
|
|
75
|
+
fileList.push(file);
|
|
76
|
+
}
|
|
77
|
+
return fileList;
|
|
78
|
+
}
|
|
79
|
+
handleUploadButton(element) {
|
|
80
|
+
let files = this.getFilesFromFileList(element.files);
|
|
81
|
+
this.filesSelected.emit(files);
|
|
82
|
+
}
|
|
83
|
+
hasInvalidExtensions(files) {
|
|
84
|
+
var hasInvalid = false;
|
|
85
|
+
for (let fileIndex = 0; fileIndex < files.length; fileIndex++) {
|
|
86
|
+
const file = files[fileIndex];
|
|
87
|
+
var regex = /(?:\.([^.]+))?$/;
|
|
88
|
+
const fileExtension = regex.exec(file.name)[1];
|
|
89
|
+
if (fileExtension == undefined) {
|
|
90
|
+
hasInvalid = true;
|
|
91
|
+
}
|
|
92
|
+
if (this.allowedExtensions != undefined && !this.allowedExtensions.includes(fileExtension)) {
|
|
93
|
+
hasInvalid = true;
|
|
94
|
+
}
|
|
95
|
+
return hasInvalid;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
takeSnapshot() {
|
|
99
|
+
this.takingPicture = true;
|
|
100
|
+
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
|
|
101
|
+
.then(stream => {
|
|
102
|
+
stream;
|
|
103
|
+
this.videoPreview.srcObject = stream;
|
|
104
|
+
this.videoPreview.play()
|
|
105
|
+
.then(() => {
|
|
106
|
+
this.videoSettings = stream.getVideoTracks()[0].getSettings();
|
|
107
|
+
});
|
|
108
|
+
})
|
|
109
|
+
.catch(error => alert(error));
|
|
110
|
+
}
|
|
111
|
+
applySnapshot() {
|
|
112
|
+
var canvas = document.createElement("canvas");
|
|
113
|
+
const context = canvas.getContext("2d");
|
|
114
|
+
canvas.width = this.videoSettings.width;
|
|
115
|
+
canvas.height = this.videoSettings.height;
|
|
116
|
+
context.drawImage(this.videoPreview, 0, 0);
|
|
117
|
+
canvas.toBlob(blob => {
|
|
118
|
+
var file = new File([blob], "image.jpeg", { type: "image/jpeg" });
|
|
119
|
+
this.takingPicture = false;
|
|
120
|
+
var fileList = [file];
|
|
121
|
+
this.filesSelected.emit(fileList);
|
|
122
|
+
}, "image/jpeg", this.captureQuality);
|
|
123
|
+
}
|
|
124
|
+
render() {
|
|
125
|
+
var _a, _b, _c, _d, _e, _f;
|
|
126
|
+
return (h(Host, { ref: e => this.dropzone = e, class: "dropzone", onDragOver: this.handleDragOver, onDrop: this.handleDrop, onDragLeave: () => this.dropzone.classList.remove("dropping") }, !this.takingPicture &&
|
|
127
|
+
[
|
|
128
|
+
h("p", null, (_a = this.resx) === null || _a === void 0 ? void 0 : _a.dragAndDropFile),
|
|
129
|
+
h("p", null, "- ", (_b = this.resx) === null || _b === void 0 ? void 0 :
|
|
130
|
+
_b.or, " -"),
|
|
131
|
+
h("label", { class: "upload-file" }, h("input", { type: "file", ref: el => this.fileInput = el, onChange: e => this.handleUploadButton(e.target) }), h("span", null, h("svg", { xmlns: "http://www.w3.org/2000/svg", "enable-background": "new 0 0 24 24", height: "24px", viewBox: "0 0 24 24", width: "24px", fill: "#000000" }, h("g", null, h("rect", { fill: "none", height: "24", width: "24" })), h("g", null, h("path", { d: "M5,20h14v-2H5V20z M5,10h4v6h6v-6h4l-7-7L5,10z" })))), "\u00A0", (_c = this.resx) === null || _c === void 0 ? void 0 :
|
|
132
|
+
_c.uploadFile),
|
|
133
|
+
this.canTakeSnapshots &&
|
|
134
|
+
[
|
|
135
|
+
h("p", null, "- ", (_d = this.resx) === null || _d === void 0 ? void 0 :
|
|
136
|
+
_d.or, " -"),
|
|
137
|
+
h("button", { onClick: () => this.takeSnapshot() }, h("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", viewBox: "0 0 24 24", width: "24px", fill: "#000000" }, h("path", { d: "M0 0h24v24H0z", fill: "none" }), h("circle", { cx: "12", cy: "12", r: "3.2" }), h("path", { d: "M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z" })), (_e = this.resx) === null || _e === void 0 ? void 0 :
|
|
138
|
+
_e.takePicture)
|
|
139
|
+
]
|
|
140
|
+
], this.takingPicture &&
|
|
141
|
+
h("div", { class: "video-preview" }, h("video", { ref: e => this.videoPreview = e }), h("button", { onClick: () => this.applySnapshot() }, h("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", viewBox: "0 0 24 24", width: "24px", fill: "#000000" }, h("path", { d: "M0 0h24v24H0z", fill: "none" }), h("circle", { cx: "12", cy: "12", r: "3.2" }), h("path", { d: "M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z" })), "\u00A0", (_f = this.resx) === null || _f === void 0 ? void 0 :
|
|
142
|
+
_f.capture))));
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
DnnDropzone.style = dnnDropzoneCss;
|
|
146
|
+
|
|
147
|
+
export { DnnDropzone as dnn_dropzone };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=dnn-dropzone.entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"dnn-dropzone.entry.esm.js","mappings":";;AAAA,MAAM,cAAc,GAAG,m1BAAm1B;;ICO71B,WAAW;EALxB;;;;IAOU,SAAI,GAMR;MACF,eAAe,EAAE,sBAAsB;MACvC,OAAO,EAAE,SAAS;MAClB,E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J,GAAE,CAAM,YACtV,MAAA,IAAI,CAAC,IAAI;WAAE,OAAO,CACZ,CACL,CAEH,EACP;GACH;;;;;;","names":[],"sources":["./src/components/dnn-dropzone/dnn-dropzone.scss?tag=dnn-dropzone&encapsulation=shadow","./src/components/dnn-dropzone/dnn-dropzone.tsx"],"sourcesContent":["\r\n:host {\r\n /** \r\n * @prop --border-color: The color of the border.\r\n * @prop --border-radius: The radius of the controls borders.\r\n * @prop --drop-background-color: The color of the background when a file is dropping.\r\n */\r\n --border-color: var(--dnn-color-tertiary-contrast, lightgray);\r\n --border-radius: var(--dnn-controls-radius, 5px);\r\n --drop-background-color: var(--dnn-color-tertiary, lightblue);\r\n\r\n display: flex;\r\n flex-direction: column;\r\n gap: 1rem;\r\n text-align: center;\r\n border: 2px dashed var(--border-color);\r\n border-radius: var(--border-radius);\r\n padding: 1rem;\r\n transition: all 300ms ease-in-out;\r\n}\r\n\r\n:host(.dropping){\r\n background-color: var(--drop-background-color);\r\n}\r\np{\r\n margin: 0;\r\n padding: 0;\r\n}\r\nbutton{\r\n display: flex;\r\n justify-content: center;\r\n align-items: center;\r\n border: 0px;\r\n margin: 0;\r\n padding: 0;\r\n background-color: transparent;\r\n &:hover{\r\n cursor: pointer;\r\n }\r\n svg{\r\n margin-right: 0.5rem;\r\n }\r\n}\r\nlabel.upload-file{\r\n display: flex;\r\n justify-content: center;\r\n align-items: center;\r\n cursor: pointer;\r\n input{\r\n display: none;\r\n }\r\n}\r\n.video-preview{\r\n display: flex;\r\n flex-direction: column;\r\n align-items: center;\r\n button{\r\n margin: 1rem;\r\n }\r\n}\r\n","import { Component, Host, h, Prop, State, Event, EventEmitter } from '@stencil/core';\r\n\r\n@Component({\r\n tag: 'dnn-dropzone',\r\n styleUrl: 'dnn-dropzone.scss',\r\n shadow: true,\r\n})\r\nexport class DnnDropzone {\r\n /** Localization strings */\r\n @Prop() resx:{\r\n dragAndDropFile: string;\r\n capture: string;\r\n or: string;\r\n takePicture: string;\r\n uploadFile: string;\r\n } = {\r\n dragAndDropFile: \"Drag and drop a file\",\r\n capture: \"Capture\",\r\n or: \"or\",\r\n takePicture: \"Take a picture\",\r\n uploadFile: \"Upload a file\",\r\n }\r\n\r\n /** A list of allowed file extensions.\r\n * If not specified, any file is allowed.\r\n * Ex: [\"jpg\", \"jped\", \"gif\", \"png\"]\r\n */\r\n @Prop() allowedExtensions: string[];\r\n\r\n /**\r\n * If true, will allow the user to take a snapshot\r\n * using the device camera. (only works over https).\r\n */\r\n @Prop() allowCameraMode: boolean = false;\r\n\r\n /**\r\n * Specifies the jpeg quality for when the device\r\n * camera is used to generate a picture.\r\n * Needs to be a number between 0 and 1 and defaults to 0.8\r\n */\r\n @Prop() captureQuality: number = 0.8;\r\n\r\n /** Fires when file were selected. */\r\n @Event() filesSelected: EventEmitter<File[]>;\r\n \r\n @State() canTakeSnapshots: boolean = false;\r\n\r\n @State() takingPicture: boolean = false;\r\n \r\n private dropzone: HTMLElement;\r\n private fileInput: HTMLInputElement;\r\n private videoPreview: HTMLVideoElement;\r\n private videoSettings!: MediaTrackSettings;\r\n\r\n\r\n componentDidLoad() {\r\n if (this.allowCameraMode){\r\n this.checkIfBrowserCanTakeSnapshots()\r\n .then(result => this.canTakeSnapshots = result);\r\n }\r\n if (this.allowedExtensions != undefined && this.allowedExtensions.length > 0){\r\n var extensionsWithDots = this.allowedExtensions.map(e => `.${e}`);\r\n var extensionsList = extensionsWithDots.join(\",\");\r\n this.fileInput.accept = extensionsList;\r\n }\r\n }\r\n\r\n private checkIfBrowserCanTakeSnapshots(): Promise<boolean> {\r\n return new Promise((resolve) => {\r\n const mediaDevices = navigator.mediaDevices;\r\n if (mediaDevices == undefined || mediaDevices.enumerateDevices == undefined) {\r\n resolve(false);\r\n }\r\n mediaDevices.enumerateDevices()\r\n .then(devices => {\r\n var result = devices.some(device => device.kind == \"videoinput\");\r\n resolve(result);\r\n });\r\n });\r\n }\r\n\r\n private getFilesFromFileList(files: FileList) : File[] {\r\n var fileList: File[] = [];\r\n for (let index = 0; index < files.length; index++) {\r\n const file = files[index];\r\n fileList.push(file);\r\n }\r\n\r\n return fileList;\r\n }\r\n\r\n private handleUploadButton(element: HTMLInputElement): void {\r\n let files = this.getFilesFromFileList(element.files);\r\n\r\n this.filesSelected.emit(files);\r\n }\r\n\r\n private handleDragOver = (event: DragEvent) => \r\n {\r\n event.stopPropagation();\r\n event.preventDefault();\r\n event.dataTransfer.dropEffect = \"copy\";\r\n this.dropzone.classList.add(\"dropping\");\r\n };\r\n\r\n private hasInvalidExtensions(files: FileList): boolean{\r\n var hasInvalid = false;\r\n for (let fileIndex = 0; fileIndex < files.length; fileIndex++) {\r\n const file = files[fileIndex];\r\n var regex = /(?:\\.([^.]+))?$/;\r\n const fileExtension = regex.exec(file.name)[1];\r\n if (fileExtension == undefined){\r\n hasInvalid = true;\r\n }\r\n\r\n if (this.allowedExtensions != undefined && !this.allowedExtensions.includes(fileExtension)){\r\n hasInvalid = true;\r\n }\r\n\r\n return hasInvalid;\r\n }\r\n }\r\n\r\n private handleDrop = (dropEvent: DragEvent) => {\r\n dropEvent.stopPropagation();\r\n dropEvent.preventDefault();\r\n const files = dropEvent.dataTransfer.files;\r\n\r\n if (this.hasInvalidExtensions(files)){\r\n return;\r\n }\r\n var fileList = this.getFilesFromFileList(files);\r\n this.filesSelected.emit(fileList);\r\n };\r\n\r\n private takeSnapshot(): void {\r\n this.takingPicture = true;\r\n navigator.mediaDevices.getUserMedia({video: true, audio: false})\r\n .then(stream => {\r\n stream\r\n this.videoPreview.srcObject = stream;\r\n this.videoPreview.play()\r\n .then(() => {\r\n this.videoSettings = stream.getVideoTracks()[0].getSettings();\r\n });\r\n })\r\n .catch(error => alert(error));\r\n }\r\n\r\n private applySnapshot(): void {\r\n var canvas = document.createElement(\"canvas\");\r\n const context = canvas.getContext(\"2d\");\r\n canvas.width = this.videoSettings.width;\r\n canvas.height = this.videoSettings.height;\r\n context.drawImage(this.videoPreview, 0, 0);\r\n canvas.toBlob(blob => {\r\n var file = new File([blob], \"image.jpeg\", {type:\"image/jpeg\"});\r\n this.takingPicture = false;\r\n \r\n var fileList = [file];\r\n this.filesSelected.emit(fileList)\r\n }, \"image/jpeg\", this.captureQuality);\r\n }\r\n \r\n render() {\r\n return (\r\n <Host\r\n ref={e => this.dropzone = e}\r\n class=\"dropzone\"\r\n onDragOver={this.handleDragOver}\r\n onDrop={this.handleDrop}\r\n onDragLeave={() => this.dropzone.classList.remove(\"dropping\")}\r\n >\r\n {!this.takingPicture &&\r\n [\r\n <p>{this.resx?.dragAndDropFile}</p>\r\n ,\r\n <p>- {this.resx?.or} -</p>\r\n ,\r\n <label class=\"upload-file\">\r\n <input\r\n type=\"file\"\r\n ref={el => this.fileInput = el}\r\n onChange={e => this.handleUploadButton(e.target as HTMLInputElement)}\r\n >\r\n </input>\r\n <span>\r\n <svg xmlns=\"http://www.w3.org/2000/svg\" enable-background=\"new 0 0 24 24\" height=\"24px\" viewBox=\"0 0 24 24\" width=\"24px\" fill=\"#000000\"><g><rect fill=\"none\" height=\"24\" width=\"24\"/></g><g><path d=\"M5,20h14v-2H5V20z M5,10h4v6h6v-6h4l-7-7L5,10z\"/></g></svg>\r\n </span>\r\n \r\n {this.resx?.uploadFile}\r\n </label>\r\n ,\r\n this.canTakeSnapshots &&\r\n [\r\n <p>- {this.resx?.or} -</p>\r\n ,\r\n <button\r\n onClick={() => this.takeSnapshot()}\r\n >\r\n <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 0 24 24\" width=\"24px\" fill=\"#000000\"><path d=\"M0 0h24v24H0z\" fill=\"none\"/><circle cx=\"12\" cy=\"12\" r=\"3.2\"/><path d=\"M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z\"/></svg>\r\n {this.resx?.takePicture}\r\n </button>\r\n ]\r\n ]\r\n }\r\n {this.takingPicture &&\r\n <div class=\"video-preview\">\r\n <video ref={e => this.videoPreview = e} />\r\n <button\r\n onClick={() => this.applySnapshot()}\r\n >\r\n <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 0 24 24\" width=\"24px\" fill=\"#000000\"><path d=\"M0 0h24v24H0z\" fill=\"none\"/><circle cx=\"12\" cy=\"12\" r=\"3.2\"/><path d=\"M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z\"/></svg> \r\n {this.resx?.capture}\r\n </button>\r\n </div>\r\n }\r\n </Host>\r\n );\r\n }\r\n\r\n}\r\n"],"version":3}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { r as registerInstance, e as createEvent, h, f as Host } from './index-6c0764e5.js';
|
|
2
|
+
|
|
3
|
+
var CornerType;
|
|
4
|
+
(function (CornerType) {
|
|
5
|
+
CornerType[CornerType["nw"] = 0] = "nw";
|
|
6
|
+
CornerType[CornerType["ne"] = 1] = "ne";
|
|
7
|
+
CornerType[CornerType["se"] = 2] = "se";
|
|
8
|
+
CornerType[CornerType["sw"] = 3] = "sw";
|
|
9
|
+
})(CornerType || (CornerType = {}));
|
|
10
|
+
;
|
|
11
|
+
|
|
12
|
+
const dnnImageCropperCss = ":host{display:block}canvas{display:none}.view{visibility:hidden;opacity:0;height:0;overflow:hidden;transition:all 300ms ease-in-out}.view.visible{visibility:visible;opacity:1;height:initial;overflow:visible}.view .cropper{position:relative;width:100%}.view .cropper img{width:100%;display:block;margin:0 auto}.view .cropper .backdrop{backdrop-filter:saturate(0.5);backdrop-filter:brightness(0.5);position:absolute;left:0;top:0;width:100%;height:100%}.view .cropper .crop{position:absolute;top:0;left:0;width:100%;height:100%;outline:2px dashed white;box-shadow:black 0 0 0px 2px;backdrop-filter:saturate(2);backdrop-filter:brightness(2);cursor:move}.view .cropper .crop>div{width:20px;height:20px;background-color:white;border:2px solid rgba(0, 0, 0, 0.5);position:absolute}.view .cropper .crop>div.nw,.view .cropper .crop>div.ne{top:-17px}.view .cropper .crop>div.ne,.view .cropper .crop>div.se{right:-17px}.view .cropper .crop>div.se,.view .cropper .crop>div.sw{bottom:-17px}.view .cropper .crop>div.sw,.view .cropper .crop>div.nw{left:-17px}.view .cropper .crop>div.nw,.view .cropper .crop>div.se{cursor:nwse-resize}.view .cropper .crop>div.ne,.view .cropper .crop>div.sw{cursor:nesw-resize}dnn-modal{--max-width:512px}";
|
|
13
|
+
|
|
14
|
+
let DnnImageCropper = class {
|
|
15
|
+
constructor(hostRef) {
|
|
16
|
+
registerInstance(this, hostRef);
|
|
17
|
+
this.imageCropChanged = createEvent(this, "imageCropChanged", 7);
|
|
18
|
+
/** Sets the desired final image width. */
|
|
19
|
+
this.width = 600;
|
|
20
|
+
/** Sets the desired final image height. */
|
|
21
|
+
this.height = 600;
|
|
22
|
+
/** Can be used to customize controls text.
|
|
23
|
+
* Some values support tokens, see default values for examples.
|
|
24
|
+
*/
|
|
25
|
+
this.resx = {
|
|
26
|
+
capture: "Capture",
|
|
27
|
+
dragAndDropFile: "Drag and drop an image",
|
|
28
|
+
or: "or",
|
|
29
|
+
takePicture: "Take a picture",
|
|
30
|
+
uploadFile: "Upload an image",
|
|
31
|
+
imageTooSmall: "The image you are attempting to upload does not meet the minimum size requirement of {width} pixels by {height} pixels. Please upload a larger image.",
|
|
32
|
+
modalCloseText: "Close",
|
|
33
|
+
};
|
|
34
|
+
/** Sets the output quality of the corpped image (number between 0 and 1). */
|
|
35
|
+
this.quality = 0.8;
|
|
36
|
+
/** When set to true, prevents cropping an image smaller than the required size, which would blow pixel and make the final picture look blurry. */
|
|
37
|
+
this.preventUndersized = false;
|
|
38
|
+
this.handleCropMouseDown = (event) => {
|
|
39
|
+
event.stopPropagation();
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
const element = event.target;
|
|
42
|
+
const className = element.classList[0];
|
|
43
|
+
document.addEventListener("mouseup", this.handleImageCropFinished, false);
|
|
44
|
+
document.addEventListener("touchend", this.handleImageCropFinished, false);
|
|
45
|
+
switch (className) {
|
|
46
|
+
case "crop":
|
|
47
|
+
document.addEventListener("mousemove", this.handleCropDrag, false);
|
|
48
|
+
document.addEventListener("touchmove", this.handleCropDrag, false);
|
|
49
|
+
document.addEventListener("mouseup", () => document.removeEventListener("mousemove", this.handleCropDrag));
|
|
50
|
+
document.addEventListener("touchend", () => document.removeEventListener("touchmove", this.handleCropDrag));
|
|
51
|
+
break;
|
|
52
|
+
case "nw":
|
|
53
|
+
document.addEventListener("mousemove", this.handleNwMouseMove, false);
|
|
54
|
+
document.addEventListener("touchmove", this.handleNwMouseMove, false);
|
|
55
|
+
document.addEventListener("mouseup", () => document.removeEventListener("mousemove", this.handleNwMouseMove));
|
|
56
|
+
document.addEventListener("touchend", () => document.removeEventListener("touchmove", this.handleNwMouseMove));
|
|
57
|
+
break;
|
|
58
|
+
case "ne":
|
|
59
|
+
document.addEventListener("mousemove", this.handleNeMouseMove, false);
|
|
60
|
+
document.addEventListener("touchmove", this.handleNeMouseMove, false);
|
|
61
|
+
document.addEventListener("mouseup", () => document.removeEventListener("mousemove", this.handleNeMouseMove));
|
|
62
|
+
document.addEventListener("touchend", () => document.removeEventListener("touchmove", this.handleNeMouseMove));
|
|
63
|
+
break;
|
|
64
|
+
case "se":
|
|
65
|
+
document.addEventListener("mousemove", this.handleSeMouseMove, false);
|
|
66
|
+
document.addEventListener("touchmove", this.handleSeMouseMove, false);
|
|
67
|
+
document.addEventListener("mouseup", () => document.removeEventListener("mousemove", this.handleSeMouseMove));
|
|
68
|
+
document.addEventListener("touchend", () => document.removeEventListener("touchmove", this.handleSeMouseMove));
|
|
69
|
+
break;
|
|
70
|
+
case "sw":
|
|
71
|
+
document.addEventListener("mousemove", this.handleSwMouseMove, false);
|
|
72
|
+
document.addEventListener("touchmove", this.handleSwMouseMove, false);
|
|
73
|
+
document.addEventListener("mouseup", () => document.removeEventListener("mousemove", this.handleSwMouseMove));
|
|
74
|
+
document.addEventListener("touchend", () => document.removeEventListener("touchmove", this.handleSwMouseMove));
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
this.handleImageCropFinished = (_ev) => {
|
|
81
|
+
this.emitImage();
|
|
82
|
+
document.removeEventListener("mouseup", this.handleImageCropFinished);
|
|
83
|
+
this.previousTouch = undefined;
|
|
84
|
+
};
|
|
85
|
+
this.handleNwMouseMove = (event) => {
|
|
86
|
+
this.handleCornerDrag(event, CornerType.nw);
|
|
87
|
+
};
|
|
88
|
+
this.handleNeMouseMove = (event) => {
|
|
89
|
+
this.handleCornerDrag(event, CornerType.ne);
|
|
90
|
+
};
|
|
91
|
+
this.handleSeMouseMove = (event) => {
|
|
92
|
+
this.handleCornerDrag(event, CornerType.se);
|
|
93
|
+
};
|
|
94
|
+
this.handleSwMouseMove = (event) => {
|
|
95
|
+
this.handleCornerDrag(event, CornerType.sw);
|
|
96
|
+
};
|
|
97
|
+
this.handleCornerDrag = (event, corner) => {
|
|
98
|
+
if (!this.isMouseStillInTarget(event)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let { left, top } = this.getCornerLeftTop(corner);
|
|
102
|
+
let newWidth = 0;
|
|
103
|
+
let newHeight = 0;
|
|
104
|
+
let orientation = "horizontal";
|
|
105
|
+
const wantedRatio = this.width / this.height;
|
|
106
|
+
const cropRect = this.crop.getBoundingClientRect();
|
|
107
|
+
const imageRect = this.image.getBoundingClientRect();
|
|
108
|
+
let { movementX, movementY } = this.getMouvementFromEvent(event);
|
|
109
|
+
if (Math.abs(movementX) < Math.abs(movementY)) {
|
|
110
|
+
orientation = "vertical";
|
|
111
|
+
}
|
|
112
|
+
if (orientation == "horizontal") {
|
|
113
|
+
switch (corner) {
|
|
114
|
+
case CornerType.nw:
|
|
115
|
+
case CornerType.sw:
|
|
116
|
+
newWidth = cropRect.width - movementX;
|
|
117
|
+
newHeight = newWidth / wantedRatio;
|
|
118
|
+
break;
|
|
119
|
+
case CornerType.ne:
|
|
120
|
+
case CornerType.se:
|
|
121
|
+
newWidth = cropRect.width + movementX;
|
|
122
|
+
newHeight = newWidth / wantedRatio;
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
switch (corner) {
|
|
130
|
+
case CornerType.nw:
|
|
131
|
+
case CornerType.ne:
|
|
132
|
+
newHeight = cropRect.height - movementY;
|
|
133
|
+
newWidth = newHeight * wantedRatio;
|
|
134
|
+
break;
|
|
135
|
+
case CornerType.se:
|
|
136
|
+
case CornerType.sw:
|
|
137
|
+
newHeight = cropRect.height + movementY;
|
|
138
|
+
newWidth = newHeight * wantedRatio;
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
switch (corner) {
|
|
145
|
+
case CornerType.ne:
|
|
146
|
+
case CornerType.nw:
|
|
147
|
+
const topOffset = cropRect.height - newHeight;
|
|
148
|
+
top = this.crop.offsetTop + topOffset;
|
|
149
|
+
default:
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
switch (corner) {
|
|
153
|
+
case CornerType.nw:
|
|
154
|
+
case CornerType.sw:
|
|
155
|
+
const leftOffset = cropRect.width - newWidth;
|
|
156
|
+
left = this.crop.offsetLeft + leftOffset;
|
|
157
|
+
if (left < 0)
|
|
158
|
+
left = 0;
|
|
159
|
+
if (left > imageRect.width)
|
|
160
|
+
left = imageRect.width;
|
|
161
|
+
if (top < 0)
|
|
162
|
+
top = 0;
|
|
163
|
+
if (top > imageRect.height)
|
|
164
|
+
top = imageRect.height;
|
|
165
|
+
if (left + newWidth > imageRect.width)
|
|
166
|
+
newWidth = imageRect.width - left;
|
|
167
|
+
if (top + newHeight > imageRect.height)
|
|
168
|
+
newHeight = imageRect.height - top;
|
|
169
|
+
break;
|
|
170
|
+
case CornerType.ne:
|
|
171
|
+
case CornerType.se:
|
|
172
|
+
if (top < 0)
|
|
173
|
+
top = 0;
|
|
174
|
+
if (top > imageRect.height)
|
|
175
|
+
top = imageRect.height;
|
|
176
|
+
if (left + newWidth > imageRect.width)
|
|
177
|
+
newWidth = imageRect.width - left;
|
|
178
|
+
if (top + newHeight > imageRect.height)
|
|
179
|
+
newHeight = imageRect.height - top;
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
if (newWidth / newHeight != wantedRatio) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (this.preventUndersized) {
|
|
188
|
+
const zoomRatio = this.image.width / this.image.naturalWidth;
|
|
189
|
+
if (newWidth / zoomRatio < this.width || newHeight / zoomRatio < this.height) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
switch (corner) {
|
|
194
|
+
case CornerType.ne:
|
|
195
|
+
this.crop.style.top = `${top}px`;
|
|
196
|
+
this.crop.style.width = `${newWidth}px`;
|
|
197
|
+
this.crop.style.height = `${newHeight}px`;
|
|
198
|
+
break;
|
|
199
|
+
case CornerType.nw:
|
|
200
|
+
this.crop.style.left = `${left}px`;
|
|
201
|
+
this.crop.style.top = `${top}px`;
|
|
202
|
+
this.crop.style.width = `${newWidth}px`;
|
|
203
|
+
this.crop.style.height = `${newHeight}px`;
|
|
204
|
+
break;
|
|
205
|
+
case CornerType.se:
|
|
206
|
+
this.crop.style.width = `${newWidth}px`;
|
|
207
|
+
this.crop.style.height = `${newHeight}px`;
|
|
208
|
+
break;
|
|
209
|
+
case CornerType.sw:
|
|
210
|
+
this.crop.style.left = `${left}px`;
|
|
211
|
+
this.crop.style.width = `${newWidth}px`;
|
|
212
|
+
this.crop.style.height = `${newHeight}px`;
|
|
213
|
+
break;
|
|
214
|
+
default:
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
this.handleCropDrag = (ev) => {
|
|
219
|
+
if (!this.isMouseStillInTarget(ev)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
let { movementX, movementY } = this.getMouvementFromEvent(ev);
|
|
223
|
+
let newLeft = this.crop.offsetLeft + movementX;
|
|
224
|
+
let newTop = this.crop.offsetTop + movementY;
|
|
225
|
+
var imageRect = this.image.getBoundingClientRect();
|
|
226
|
+
var cropRect = this.crop.getBoundingClientRect();
|
|
227
|
+
if (newLeft < 0) {
|
|
228
|
+
newLeft = 0;
|
|
229
|
+
}
|
|
230
|
+
if (newTop < 0) {
|
|
231
|
+
newTop = 0;
|
|
232
|
+
}
|
|
233
|
+
if (newLeft + cropRect.width > imageRect.width) {
|
|
234
|
+
newLeft = this.crop.offsetLeft;
|
|
235
|
+
}
|
|
236
|
+
if (newTop + cropRect.height > imageRect.height) {
|
|
237
|
+
newTop = this.crop.offsetTop;
|
|
238
|
+
}
|
|
239
|
+
this.crop.style.left = newLeft + "px";
|
|
240
|
+
this.crop.style.top = newTop + "px";
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
componentDidLoad() {
|
|
244
|
+
this.setView("noPictureView");
|
|
245
|
+
}
|
|
246
|
+
setView(newView) {
|
|
247
|
+
const views = this.host.shadowRoot.querySelectorAll(".view");
|
|
248
|
+
views.forEach(v => v.classList.remove("visible"));
|
|
249
|
+
switch (newView) {
|
|
250
|
+
case "noPictureView":
|
|
251
|
+
this.noPictureView.classList.add("visible");
|
|
252
|
+
break;
|
|
253
|
+
case "hasPictureView":
|
|
254
|
+
this.hasPictureView.classList.add("visible");
|
|
255
|
+
break;
|
|
256
|
+
default:
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
this.view = newView;
|
|
260
|
+
}
|
|
261
|
+
initCrop() {
|
|
262
|
+
var wantedRatio = this.width / this.height;
|
|
263
|
+
var imageRect = this.image.getBoundingClientRect();
|
|
264
|
+
var imageRatio = imageRect.width / imageRect.height;
|
|
265
|
+
if (wantedRatio > imageRatio) {
|
|
266
|
+
var wantedHeight = imageRect.width / wantedRatio;
|
|
267
|
+
var diff = imageRect.height - wantedHeight;
|
|
268
|
+
this.crop.style.top = Math.round(diff / 2).toString() + "px";
|
|
269
|
+
this.crop.style.height = Math.round(wantedHeight).toString() + "px";
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
var wantedWidth = imageRect.height * wantedRatio;
|
|
273
|
+
var diff = imageRect.width - wantedWidth;
|
|
274
|
+
this.crop.style.left = Math.round(diff / 2).toString() + "px";
|
|
275
|
+
this.crop.style.width = Math.round(wantedWidth).toString() + "px";
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
setImage() {
|
|
279
|
+
this.image.addEventListener('load', () => {
|
|
280
|
+
this.initCrop();
|
|
281
|
+
this.emitImage();
|
|
282
|
+
});
|
|
283
|
+
this.image.src = this.canvas.toDataURL();
|
|
284
|
+
}
|
|
285
|
+
handleNewFile(file) {
|
|
286
|
+
if (file.type.split('/')[0] != "image") {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
var reader = new FileReader();
|
|
290
|
+
reader.onload = readerLoadEvent => {
|
|
291
|
+
var img = new Image();
|
|
292
|
+
img.onload = () => {
|
|
293
|
+
this.canvas.width = img.width;
|
|
294
|
+
this.canvas.height = img.height;
|
|
295
|
+
if (this.preventUndersized && (img.width < this.width || img.height < this.height)) {
|
|
296
|
+
this.imageTooSmallModal.show();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
var ctx = this.canvas.getContext("2d");
|
|
300
|
+
ctx.drawImage(img, 0, 0);
|
|
301
|
+
this.setView("hasPictureView");
|
|
302
|
+
this.setImage();
|
|
303
|
+
};
|
|
304
|
+
img.src = readerLoadEvent.target.result.toString();
|
|
305
|
+
};
|
|
306
|
+
reader.readAsDataURL(file);
|
|
307
|
+
}
|
|
308
|
+
emitImage() {
|
|
309
|
+
var x = this.crop.offsetLeft / this.image.width * this.image.naturalWidth;
|
|
310
|
+
var y = this.crop.offsetTop / this.image.height * this.image.naturalHeight;
|
|
311
|
+
var cropRect = this.crop.getBoundingClientRect();
|
|
312
|
+
var width = cropRect.width / this.image.width * this.image.naturalWidth;
|
|
313
|
+
var height = cropRect.height / this.image.height * this.image.naturalHeight;
|
|
314
|
+
if (x < 0)
|
|
315
|
+
x = 0;
|
|
316
|
+
if (x > this.image.naturalWidth)
|
|
317
|
+
x = this.image.naturalWidth;
|
|
318
|
+
if (y < 0)
|
|
319
|
+
y = 0;
|
|
320
|
+
if (y > this.image.naturalWidth)
|
|
321
|
+
y = this.image.naturalWidth;
|
|
322
|
+
if (width > this.image.naturalWidth)
|
|
323
|
+
width = this.image.naturalWidth;
|
|
324
|
+
if (height > this.image.naturalHeight)
|
|
325
|
+
height = this.image.naturalHeight;
|
|
326
|
+
var dataUrl = this.generateCroppedImage(x, y, width, height, this.width, this.height);
|
|
327
|
+
this.imageCropChanged.emit(dataUrl);
|
|
328
|
+
}
|
|
329
|
+
generateCroppedImage(x, y, width, height, desiredWidth, desiredHeight) {
|
|
330
|
+
this.canvas.width = desiredWidth;
|
|
331
|
+
this.canvas.height = desiredHeight;
|
|
332
|
+
const context = this.canvas.getContext("2d");
|
|
333
|
+
context.clearRect(0, 0, desiredWidth, desiredHeight);
|
|
334
|
+
context.drawImage(this.image, x, y, width, height, 0, 0, desiredWidth, desiredHeight);
|
|
335
|
+
return this.canvas.toDataURL("image/jpeg", this.quality);
|
|
336
|
+
}
|
|
337
|
+
getCornerLeftTop(corner) {
|
|
338
|
+
let left = 0;
|
|
339
|
+
let top = 0;
|
|
340
|
+
switch (corner) {
|
|
341
|
+
case CornerType.se:
|
|
342
|
+
left = this.crop.offsetLeft;
|
|
343
|
+
top = this.crop.offsetTop;
|
|
344
|
+
break;
|
|
345
|
+
case CornerType.sw:
|
|
346
|
+
top = this.crop.offsetTop;
|
|
347
|
+
break;
|
|
348
|
+
default:
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
return { top, left };
|
|
352
|
+
}
|
|
353
|
+
getMouvementFromEvent(event) {
|
|
354
|
+
let movementX = 0;
|
|
355
|
+
let movementY = 0;
|
|
356
|
+
if (event instanceof MouseEvent) {
|
|
357
|
+
movementX = event.movementX;
|
|
358
|
+
movementY = event.movementY;
|
|
359
|
+
}
|
|
360
|
+
if (typeof TouchEvent !== "undefined") {
|
|
361
|
+
if (event instanceof TouchEvent) {
|
|
362
|
+
let touch = event.touches[0];
|
|
363
|
+
if (this.previousTouch != undefined) {
|
|
364
|
+
movementX = touch.pageX - this.previousTouch.pageX;
|
|
365
|
+
movementY = touch.pageY - this.previousTouch.pageY;
|
|
366
|
+
}
|
|
367
|
+
this.previousTouch = touch;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return { movementX, movementY };
|
|
371
|
+
}
|
|
372
|
+
isMouseStillInTarget(event) {
|
|
373
|
+
var inside = false;
|
|
374
|
+
let mouseX;
|
|
375
|
+
let mouseY;
|
|
376
|
+
const imageRect = this.image.getBoundingClientRect();
|
|
377
|
+
if (event instanceof MouseEvent) {
|
|
378
|
+
mouseX = event.clientX;
|
|
379
|
+
mouseY = event.clientY;
|
|
380
|
+
}
|
|
381
|
+
if (typeof TouchEvent !== "undefined") {
|
|
382
|
+
if (event instanceof TouchEvent) {
|
|
383
|
+
var touch = event.touches[0];
|
|
384
|
+
mouseX = touch.clientX;
|
|
385
|
+
mouseY = touch.clientY;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (mouseX >= imageRect.x &&
|
|
389
|
+
mouseY >= imageRect.y &&
|
|
390
|
+
mouseX <= imageRect.left + imageRect.width &&
|
|
391
|
+
mouseY <= imageRect.top + imageRect.height) {
|
|
392
|
+
inside = true;
|
|
393
|
+
}
|
|
394
|
+
var corners = this.crop.querySelectorAll("div");
|
|
395
|
+
corners.forEach(corner => {
|
|
396
|
+
var cornerRect = corner.getBoundingClientRect();
|
|
397
|
+
if (mouseX >= cornerRect.x &&
|
|
398
|
+
mouseY >= cornerRect.y &&
|
|
399
|
+
mouseX <= cornerRect.left + cornerRect.width &&
|
|
400
|
+
mouseY <= cornerRect.top + cornerRect.height) {
|
|
401
|
+
inside = true;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
return inside;
|
|
405
|
+
}
|
|
406
|
+
render() {
|
|
407
|
+
return (h(Host, { ref: el => this.host = el }, h("canvas", { ref: el => this.canvas = el }), h("div", { class: "view", ref: el => this.hasPictureView = el }, h("div", { class: "cropper" }, h("img", { ref: el => this.image = el }), h("div", { class: "backdrop" }), h("div", { class: "crop", ref: e => this.crop = e, onMouseDown: this.handleCropMouseDown, onTouchStart: this.handleCropMouseDown }, h("div", { class: "nw" }), h("div", { class: "ne" }), h("div", { class: "se" }), h("div", { class: "sw" })))), h("div", { class: "view", ref: el => this.noPictureView = el }, h("dnn-dropzone", { allowCameraMode: true, onFilesSelected: e => this.handleNewFile(e.detail[0]), resx: {
|
|
408
|
+
capture: this.resx.capture,
|
|
409
|
+
dragAndDropFile: this.resx.dragAndDropFile,
|
|
410
|
+
or: this.resx.or,
|
|
411
|
+
takePicture: this.resx.takePicture,
|
|
412
|
+
uploadFile: this.resx.uploadFile,
|
|
413
|
+
} })), h("dnn-modal", { ref: el => this.imageTooSmallModal = el, "close-text": this.resx.modalCloseText }, h("p", null, this.resx.imageTooSmall.replace("{width}", this.width.toString()).replace("{height}", this.height.toString())))));
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
DnnImageCropper.style = dnnImageCropperCss;
|
|
417
|
+
|
|
418
|
+
export { DnnImageCropper as dnn_image_cropper };
|
|
419
|
+
|
|
420
|
+
//# sourceMappingURL=dnn-image-cropper.entry.js.map
|