@pacem/pacem-scaffolding 1.0.0-abel
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 +191 -0
- package/NOTICE +4 -0
- package/dist/browser/pacem-scaffolding.js +10430 -0
- package/dist/browser/pacem-scaffolding.js.map +1 -0
- package/dist/browser/pacem-scaffolding.min.js +2 -0
- package/dist/browser/pacem-scaffolding.min.js.map +1 -0
- package/dist/bundle/pacem-scaffolding.min.mjs +380 -0
- package/dist/bundle/pacem-scaffolding.mjs +10046 -0
- package/dist/bundle/pacem-scaffolding.mjs.map +7 -0
- package/dist/esm/calendar-picker.js +478 -0
- package/dist/esm/char-counter.js +43 -0
- package/dist/esm/checkbox-list.js +75 -0
- package/dist/esm/checkbox.js +112 -0
- package/dist/esm/childform.js +237 -0
- package/dist/esm/contenteditable.js +326 -0
- package/dist/esm/datetime-picker.js +310 -0
- package/dist/esm/form.js +630 -0
- package/dist/esm/formfield.js +1065 -0
- package/dist/esm/geolocate.js +197 -0
- package/dist/esm/hierarchy.js +509 -0
- package/dist/esm/index-components-scaffolding.js +39 -0
- package/dist/esm/index-components.js +1 -0
- package/dist/esm/index-iife.js +3 -0
- package/dist/esm/index-root.js +2 -0
- package/dist/esm/index-scaffolding.js +3 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/input-chars.js +185 -0
- package/dist/esm/input-color.js +80 -0
- package/dist/esm/input-email.js +32 -0
- package/dist/esm/input-file.js +691 -0
- package/dist/esm/input-hidden.js +25 -0
- package/dist/esm/input-image.js +391 -0
- package/dist/esm/input-number.js +58 -0
- package/dist/esm/input-password.js +71 -0
- package/dist/esm/input-search.js +27 -0
- package/dist/esm/input-tel.js +31 -0
- package/dist/esm/input-text.js +36 -0
- package/dist/esm/input-url.js +32 -0
- package/dist/esm/input.js +215 -0
- package/dist/esm/l10n.js +66 -0
- package/dist/esm/latlng.js +178 -0
- package/dist/esm/namevalue-list.js +139 -0
- package/dist/esm/property-picker.js +84 -0
- package/dist/esm/radio-list.js +70 -0
- package/dist/esm/radio.js +79 -0
- package/dist/esm/select.js +126 -0
- package/dist/esm/slider.js +284 -0
- package/dist/esm/snapshot.js +325 -0
- package/dist/esm/suggest.js +545 -0
- package/dist/esm/tags.js +174 -0
- package/dist/esm/textarea-markdown.js +75 -0
- package/dist/esm/textarea.js +51 -0
- package/dist/esm/types-components.js +611 -0
- package/dist/esm/types.js +8 -0
- package/dist/esm/validators.js +409 -0
- package/package.json +38 -0
- package/typings/index.d.ts +2283 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { P, PCSS, CustomElement, Watch, Defaults, ViewChild, CustomEventUtils, PropertyConverters, Utils, CustomUIEvent, avoidHandler, Logging } from '@pacem/pacem-core';
|
|
8
|
+
import { PacemBaseElement } from './types-components';
|
|
9
|
+
//namespace Pacem.Components.Scaffolding {
|
|
10
|
+
const getUserMediaFunctions = Utils.getUserMediaFunctions();
|
|
11
|
+
export var SnapshotStep;
|
|
12
|
+
(function (SnapshotStep) {
|
|
13
|
+
SnapshotStep["Start"] = "start";
|
|
14
|
+
SnapshotStep["Taking"] = "taking";
|
|
15
|
+
SnapshotStep["Confirm"] = "confirm";
|
|
16
|
+
})(SnapshotStep || (SnapshotStep = {}));
|
|
17
|
+
class ConfirmSnapshotEvent extends CustomUIEvent {
|
|
18
|
+
constructor(buffer) {
|
|
19
|
+
super('confirmsnapshot', { buffer });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let PacemSnapshotElement = class PacemSnapshotElement extends PacemBaseElement {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this._resizeHandler = (evt) => {
|
|
26
|
+
this._renderValue();
|
|
27
|
+
};
|
|
28
|
+
this.step = SnapshotStep.Start;
|
|
29
|
+
/*const*/ this._canUseWebcam = getUserMediaFunctions.length > 0;
|
|
30
|
+
this._countdown = 0;
|
|
31
|
+
this._webcamInitialized = false;
|
|
32
|
+
this._grabberChangeHandler = (e) => {
|
|
33
|
+
const input = this._grabber;
|
|
34
|
+
if (input.files.length > 0) {
|
|
35
|
+
Utils.blobToDataURL(input.files[0]).then(url => {
|
|
36
|
+
Utils.loadImage(url).then(img => {
|
|
37
|
+
this._shutter(img);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
this._snapshooterClickHandler = (e) => {
|
|
43
|
+
avoidHandler(e);
|
|
44
|
+
this.step = SnapshotStep.Taking;
|
|
45
|
+
};
|
|
46
|
+
this._pickerClickHandler = (e) => {
|
|
47
|
+
avoidHandler(e);
|
|
48
|
+
this._grabber.click();
|
|
49
|
+
};
|
|
50
|
+
this._takerClickHandler = (e) => {
|
|
51
|
+
avoidHandler(e);
|
|
52
|
+
this._countdown = 0;
|
|
53
|
+
this._shutter();
|
|
54
|
+
};
|
|
55
|
+
this._timerClickHandler = (e) => {
|
|
56
|
+
avoidHandler(e);
|
|
57
|
+
this._countdown = 3;
|
|
58
|
+
this._shutter();
|
|
59
|
+
};
|
|
60
|
+
this._confirmerClickHandler = (e) => {
|
|
61
|
+
avoidHandler(e);
|
|
62
|
+
this.changeHandler(new ConfirmSnapshotEvent(this._buffer));
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
get inputFields() {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
toggleReadonlyView(readonly) {
|
|
69
|
+
// TODO
|
|
70
|
+
}
|
|
71
|
+
onChange(evt) {
|
|
72
|
+
return new Promise((resolve, _) => {
|
|
73
|
+
if (CustomEventUtils.isInstanceOf(evt, ConfirmSnapshotEvent)) {
|
|
74
|
+
resolve(this.value = evt.detail.buffer);
|
|
75
|
+
this.step = SnapshotStep.Start;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
resolve(this.value);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
acceptValue(val) {
|
|
83
|
+
this._renderValue(val);
|
|
84
|
+
}
|
|
85
|
+
getViewValue(value) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
convertValueAttributeToProperty(attr) {
|
|
89
|
+
return PropertyConverters.String.convert(attr, this);
|
|
90
|
+
}
|
|
91
|
+
get _getUserMedia() {
|
|
92
|
+
return this._canUseWebcam && getUserMediaFunctions[0];
|
|
93
|
+
}
|
|
94
|
+
propertyChangedCallback(name, old, val, first) {
|
|
95
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
96
|
+
switch (name) {
|
|
97
|
+
case 'step':
|
|
98
|
+
switch (val) {
|
|
99
|
+
case SnapshotStep.Start:
|
|
100
|
+
this._buffer = null;
|
|
101
|
+
const input = this._grabber;
|
|
102
|
+
// https://stackoverflow.com/a/35323290
|
|
103
|
+
input.value = '';
|
|
104
|
+
if (!/safari/i.test(navigator.userAgent)) {
|
|
105
|
+
input.type = '';
|
|
106
|
+
input.type = 'file';
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
case SnapshotStep.Taking:
|
|
110
|
+
this._ensureWebcamRunning();
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case '_buffer':
|
|
115
|
+
this._renderValue(val || this.value);
|
|
116
|
+
break;
|
|
117
|
+
case 'width':
|
|
118
|
+
case 'height':
|
|
119
|
+
this._syncSize();
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
viewActivatedCallback() {
|
|
124
|
+
super.viewActivatedCallback();
|
|
125
|
+
this._syncSize();
|
|
126
|
+
this._picker.addEventListener('click', this._pickerClickHandler, false);
|
|
127
|
+
this._snapshooter.addEventListener('click', this._snapshooterClickHandler, false);
|
|
128
|
+
this._taker.addEventListener('click', this._takerClickHandler, false);
|
|
129
|
+
this._timer.addEventListener('click', this._timerClickHandler, false);
|
|
130
|
+
this._confirmer.addEventListener('click', this._confirmerClickHandler, false);
|
|
131
|
+
this._grabber.addEventListener('change', this._grabberChangeHandler, false);
|
|
132
|
+
}
|
|
133
|
+
disconnectedCallback() {
|
|
134
|
+
if (this.isReady) {
|
|
135
|
+
this._picker.removeEventListener('click', this._pickerClickHandler, false);
|
|
136
|
+
this._snapshooter.removeEventListener('click', this._snapshooterClickHandler, false);
|
|
137
|
+
this._taker.removeEventListener('click', this._takerClickHandler, false);
|
|
138
|
+
this._timer.removeEventListener('click', this._timerClickHandler, false);
|
|
139
|
+
this._confirmer.removeEventListener('click', this._confirmerClickHandler, false);
|
|
140
|
+
this._grabber.removeEventListener('change', this._grabberChangeHandler, false);
|
|
141
|
+
}
|
|
142
|
+
super.disconnectedCallback();
|
|
143
|
+
}
|
|
144
|
+
_syncSize() {
|
|
145
|
+
const canvas = this._stage, video = this._player;
|
|
146
|
+
if (!Utils.isNull(canvas) && !Utils.isNull(video)) {
|
|
147
|
+
canvas.style.width = video.style.width = (this.width && this.width + 'px') || '',
|
|
148
|
+
canvas.style.height = video.style.height = (this.height && this.height + 'px') || '';
|
|
149
|
+
this._renderValue(this._buffer || this.value);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
_shutter(el) {
|
|
153
|
+
const me = this, video = this._player, canvas = this._stage;
|
|
154
|
+
me._confirmer.disabled = true;
|
|
155
|
+
if (Utils.isNull(el)) {
|
|
156
|
+
el = me._player;
|
|
157
|
+
}
|
|
158
|
+
var srcWidth, srcHeight;
|
|
159
|
+
if (el instanceof HTMLVideoElement) {
|
|
160
|
+
srcWidth = el.videoWidth;
|
|
161
|
+
srcHeight = el.videoHeight;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
srcWidth = el.naturalWidth;
|
|
165
|
+
srcHeight = el.naturalHeight;
|
|
166
|
+
}
|
|
167
|
+
if (me._countdown <= 0) {
|
|
168
|
+
var cnv = document.createElement('canvas');
|
|
169
|
+
cnv.width = this.width || canvas.clientWidth;
|
|
170
|
+
cnv.height = this.height || canvas.clientHeight;
|
|
171
|
+
var ctx = cnv.getContext('2d');
|
|
172
|
+
Utils.cropImageOntoCanvas(el, ctx, srcWidth, srcHeight);
|
|
173
|
+
let root = me._root;
|
|
174
|
+
root.insertBefore(cnv, video);
|
|
175
|
+
cnv.className = 'snapshot-brightout';
|
|
176
|
+
setTimeout(function () {
|
|
177
|
+
root.removeChild(cnv);
|
|
178
|
+
}, 1000);
|
|
179
|
+
me._refreshBuffer(cnv.toDataURL()).then((b) => {
|
|
180
|
+
me._setToBeConfirmed(b);
|
|
181
|
+
me._confirmer.disabled = false;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
else
|
|
185
|
+
setTimeout(() => { me._countdown--; this._shutter(); }, 1000);
|
|
186
|
+
}
|
|
187
|
+
_renderValue(val = this.value) {
|
|
188
|
+
let cnv = this._stage;
|
|
189
|
+
if (!Utils.isNull(cnv)) {
|
|
190
|
+
cnv.width = cnv.clientWidth;
|
|
191
|
+
cnv.height = cnv.clientHeight;
|
|
192
|
+
let ctx = cnv.getContext('2d');
|
|
193
|
+
if (Utils.isNullOrEmpty(val)) {
|
|
194
|
+
ctx.clearRect(0, 0, cnv.width, cnv.height);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
Utils.loadImage(val).then(img => {
|
|
198
|
+
Utils.cropImageOntoCanvas(img, ctx, img.width, img.height);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
_setToBeConfirmed(buffer) {
|
|
204
|
+
this.step = SnapshotStep.Confirm;
|
|
205
|
+
this._buffer = buffer;
|
|
206
|
+
}
|
|
207
|
+
_refreshBuffer(buffer) {
|
|
208
|
+
var cnv = this._stage;
|
|
209
|
+
cnv.width = /*this.width ||*/ cnv.clientWidth;
|
|
210
|
+
cnv.height = /*this.height ||*/ cnv.clientHeight;
|
|
211
|
+
let quality;
|
|
212
|
+
if (this.quality > 0) {
|
|
213
|
+
quality = Math.min(1, Math.max(0, this.quality));
|
|
214
|
+
}
|
|
215
|
+
return Utils.cropImage(buffer, cnv.width, cnv.height, quality);
|
|
216
|
+
}
|
|
217
|
+
_ensureWebcamRunning() {
|
|
218
|
+
if (this._canUseWebcam && !this._webcamInitialized) {
|
|
219
|
+
var me = this;
|
|
220
|
+
me._webcamInitialized = true;
|
|
221
|
+
me._getUserMedia.apply(navigator, [{ video: true /*, audio: false*/ },
|
|
222
|
+
/* success */ function (localMediaStream) {
|
|
223
|
+
var video = me._player;
|
|
224
|
+
// deprecated:
|
|
225
|
+
//video.src = window.URL.createObjectURL(localMediaStream);
|
|
226
|
+
// replaced with:
|
|
227
|
+
video.srcObject = localMediaStream;
|
|
228
|
+
}, /* fail */ function (e) {
|
|
229
|
+
me.log(Logging.LogLevel.Error, (e || e.message).toString());
|
|
230
|
+
}]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
__decorate([
|
|
235
|
+
ViewChild('.' + PCSS + '-snapshot')
|
|
236
|
+
], PacemSnapshotElement.prototype, "_root", void 0);
|
|
237
|
+
__decorate([
|
|
238
|
+
ViewChild('canvas')
|
|
239
|
+
], PacemSnapshotElement.prototype, "_stage", void 0);
|
|
240
|
+
__decorate([
|
|
241
|
+
ViewChild('input[type=file]')
|
|
242
|
+
], PacemSnapshotElement.prototype, "_grabber", void 0);
|
|
243
|
+
__decorate([
|
|
244
|
+
ViewChild('video')
|
|
245
|
+
], PacemSnapshotElement.prototype, "_player", void 0);
|
|
246
|
+
__decorate([
|
|
247
|
+
ViewChild(P + '-button.button.snapshot-upload')
|
|
248
|
+
], PacemSnapshotElement.prototype, "_picker", void 0);
|
|
249
|
+
__decorate([
|
|
250
|
+
ViewChild(P + '-button.button.snapshot-camera')
|
|
251
|
+
], PacemSnapshotElement.prototype, "_snapshooter", void 0);
|
|
252
|
+
__decorate([
|
|
253
|
+
ViewChild(P + '-button.button.snapshot-take')
|
|
254
|
+
], PacemSnapshotElement.prototype, "_taker", void 0);
|
|
255
|
+
__decorate([
|
|
256
|
+
ViewChild(P + '-button.button.snapshot-timer3s')
|
|
257
|
+
], PacemSnapshotElement.prototype, "_timer", void 0);
|
|
258
|
+
__decorate([
|
|
259
|
+
ViewChild(P + '-button.button.snapshot-confirm')
|
|
260
|
+
], PacemSnapshotElement.prototype, "_confirmer", void 0);
|
|
261
|
+
__decorate([
|
|
262
|
+
Watch({ converter: PropertyConverters.String })
|
|
263
|
+
], PacemSnapshotElement.prototype, "step", void 0);
|
|
264
|
+
__decorate([
|
|
265
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
266
|
+
], PacemSnapshotElement.prototype, "width", void 0);
|
|
267
|
+
__decorate([
|
|
268
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
269
|
+
], PacemSnapshotElement.prototype, "height", void 0);
|
|
270
|
+
__decorate([
|
|
271
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
272
|
+
], PacemSnapshotElement.prototype, "quality", void 0);
|
|
273
|
+
__decorate([
|
|
274
|
+
Watch()
|
|
275
|
+
], PacemSnapshotElement.prototype, "_countdown", void 0);
|
|
276
|
+
__decorate([
|
|
277
|
+
Watch({ emit: false })
|
|
278
|
+
], PacemSnapshotElement.prototype, "_buffer", void 0);
|
|
279
|
+
PacemSnapshotElement = __decorate([
|
|
280
|
+
CustomElement({
|
|
281
|
+
tagName: P + '-snapshot',
|
|
282
|
+
shadow: Defaults.USE_SHADOW_ROOT,
|
|
283
|
+
template: `<${P}-panel class="${PCSS}-snapshot"
|
|
284
|
+
css-class="{{ {
|
|
285
|
+
'snapshot-start': :host.step === '${SnapshotStep.Start}',
|
|
286
|
+
'snapshot-taking': :host.step === '${SnapshotStep.Taking}',
|
|
287
|
+
'snapshot-confirm': :host.step === '${SnapshotStep.Confirm}' } }}">
|
|
288
|
+
|
|
289
|
+
<${P}-resize target="{{ ::_stage }}" on-resize=":host._resizeHandler($event)"></${P}-resize>
|
|
290
|
+
|
|
291
|
+
<canvas class="${PCSS}-viewfinder"></canvas>
|
|
292
|
+
|
|
293
|
+
<video autoplay="autoplay"></video>
|
|
294
|
+
|
|
295
|
+
<input type="file" accept="image/*" />
|
|
296
|
+
|
|
297
|
+
<div class="${PCSS}-buttonset snapshot-step step-start">
|
|
298
|
+
<div class="buttonset-center">
|
|
299
|
+
<${P}-button class="button snapshot-upload" icon-glyph="upload"></${P}-button>
|
|
300
|
+
<${P}-button class="button snapshot-camera" icon-glyph="photo_camera"></${P}-button>
|
|
301
|
+
</div>
|
|
302
|
+
</div>
|
|
303
|
+
|
|
304
|
+
<div class="${PCSS}-buttonset snapshot-step step-taking">
|
|
305
|
+
<div class="buttonset-center">
|
|
306
|
+
<${P}-button class="button snapshot-undo" icon-glyph="undo" on-click=":host.step = '${SnapshotStep.Start}'"></${P}-button>
|
|
307
|
+
<${P}-button class="button snapshot-take" icon-glyph="camera"></${P}-button>
|
|
308
|
+
<${P}-button class="button snapshot-timer3s" icon-glyph="timer_3"></${P}-button>
|
|
309
|
+
</div>
|
|
310
|
+
</div>
|
|
311
|
+
|
|
312
|
+
<div class="${PCSS}-buttonset snapshot-step step-confirm">
|
|
313
|
+
<div class="buttonset-center">
|
|
314
|
+
<${P}-button class="button snapshot-undo" icon-glyph="undo" on-click=":host.step = '${SnapshotStep.Start}'"></${P}-button>
|
|
315
|
+
<${P}-button class="button snapshot-confirm" icon-glyph="done"></${P}-button>
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
|
|
319
|
+
<${P}-span class="snapshot-countdown" text="{{ :host._countdown }}" hide="{{ :host.step !== '${SnapshotStep.Taking}' || !(:host._countdown > 0) }}"></${P}-span>
|
|
320
|
+
<${P}-span hide="{{ :host._canUseWebcam }}"><${P}-content></${P}-content></${P}-span>
|
|
321
|
+
|
|
322
|
+
</${P}-panel>`
|
|
323
|
+
})
|
|
324
|
+
], PacemSnapshotElement);
|
|
325
|
+
export { PacemSnapshotElement };
|