@pacem/pacem-ui 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-ui.js +6343 -0
- package/dist/browser/pacem-ui.js.map +1 -0
- package/dist/browser/pacem-ui.min.js +2 -0
- package/dist/browser/pacem-ui.min.js.map +1 -0
- package/dist/bundle/pacem-ui.min.mjs +168 -0
- package/dist/bundle/pacem-ui.mjs +6276 -0
- package/dist/bundle/pacem-ui.mjs.map +7 -0
- package/dist/esm/adapter.js +360 -0
- package/dist/esm/anchor.js +149 -0
- package/dist/esm/balloon.js +583 -0
- package/dist/esm/binder.js +678 -0
- package/dist/esm/blade.js +31 -0
- package/dist/esm/bottom-sheet.js +277 -0
- package/dist/esm/button.js +100 -0
- package/dist/esm/buttonset.js +41 -0
- package/dist/esm/calendar.js +662 -0
- package/dist/esm/collapse.js +72 -0
- package/dist/esm/dialog-abstractions.js +61 -0
- package/dist/esm/dialog.js +102 -0
- package/dist/esm/divider.js +48 -0
- package/dist/esm/icon.js +131 -0
- package/dist/esm/image.js +109 -0
- package/dist/esm/index-components-ui.js +41 -0
- package/dist/esm/index-components.js +1 -0
- package/dist/esm/index-iife.js +3 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/infinite-scroller.js +137 -0
- package/dist/esm/iterative.js +45 -0
- package/dist/esm/lightbox-abstractions.js +6 -0
- package/dist/esm/lightbox.js +203 -0
- package/dist/esm/loader.js +100 -0
- package/dist/esm/markdown-svc.js +235 -0
- package/dist/esm/markdown.js +35 -0
- package/dist/esm/marquee.js +87 -0
- package/dist/esm/media-query.js +85 -0
- package/dist/esm/menu.js +165 -0
- package/dist/esm/pager.js +111 -0
- package/dist/esm/picture.js +157 -0
- package/dist/esm/progressbar.js +54 -0
- package/dist/esm/sidebar.js +60 -0
- package/dist/esm/slideshow.js +27 -0
- package/dist/esm/social-twitter.js +39 -0
- package/dist/esm/sticky-header.js +113 -0
- package/dist/esm/tabs.js +187 -0
- package/dist/esm/ticker.js +78 -0
- package/dist/esm/toast.js +171 -0
- package/dist/esm/toc.js +171 -0
- package/dist/esm/tuner.js +200 -0
- package/dist/esm/types.js +7 -0
- package/dist/esm/vibration.js +33 -0
- package/dist/esm/view.js +206 -0
- package/dist/esm/window.js +181 -0
- package/package.json +38 -0
- package/typings/index.d.ts +1165 -0
|
@@ -0,0 +1,200 @@
|
|
|
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, ViewChild, Components, Utils, PropertyConverters, UI, Animations } from '@pacem/pacem-core';
|
|
8
|
+
import { Angle } from '@pacem/pacem-foundation';
|
|
9
|
+
//namespace Pacem.Components.UI {
|
|
10
|
+
const TWO_PI = Math.PI * 2;
|
|
11
|
+
function cartesian(cx, cy, r, theta) {
|
|
12
|
+
return {
|
|
13
|
+
x: cx + (r * Math.cos(theta)),
|
|
14
|
+
y: cy + (r * Math.sin(theta))
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
let PacemTunerElement = class PacemTunerElement extends Components.PacemElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
//#region INTERACTIVE
|
|
21
|
+
this.min = 0.0;
|
|
22
|
+
this.max = 100.0;
|
|
23
|
+
this._rotateStartHandler = (evt) => {
|
|
24
|
+
const angle = this.#angle = this._getAngle(evt);
|
|
25
|
+
const r = this._rotate;
|
|
26
|
+
r.minRotation = 0 - angle;
|
|
27
|
+
r.maxRotation = TWO_PI - angle;
|
|
28
|
+
this._setValue(angle);
|
|
29
|
+
};
|
|
30
|
+
this._rotateEndHandler = (evt) => {
|
|
31
|
+
//this.#angle += evt.detail.rotation;
|
|
32
|
+
};
|
|
33
|
+
this._rotateHandler = (evt) => {
|
|
34
|
+
evt.preventDefault();
|
|
35
|
+
const angle = evt.detail.rotation + this.#angle;
|
|
36
|
+
this._setValue(angle);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
#angle;
|
|
40
|
+
viewActivatedCallback() {
|
|
41
|
+
super.viewActivatedCallback();
|
|
42
|
+
const rotate = this._rotate, tween = this._tween;
|
|
43
|
+
rotate.addEventListener(UI.RotateEventType.Start, this._rotateStartHandler, false);
|
|
44
|
+
rotate.addEventListener(UI.RotateEventType.Rotate, this._rotateHandler, false);
|
|
45
|
+
rotate.addEventListener(UI.RotateEventType.End, this._rotateEndHandler, false);
|
|
46
|
+
rotate.register(this._canvas);
|
|
47
|
+
this._toggleRotate();
|
|
48
|
+
//
|
|
49
|
+
requestAnimationFrame(() => this._draw(this.min));
|
|
50
|
+
//
|
|
51
|
+
tween.easing = Animations.Easings.sineInOut;
|
|
52
|
+
tween.delay = 500 + (Math.random() * 100 - 100);
|
|
53
|
+
tween.start = this.value > this.min;
|
|
54
|
+
}
|
|
55
|
+
disconnectedCallback() {
|
|
56
|
+
const rotate = this._rotate, canvas = this._canvas;
|
|
57
|
+
if (!Utils.isNull(rotate)) {
|
|
58
|
+
rotate.removeEventListener(UI.RotateEventType.Rotate, this._rotateHandler, false);
|
|
59
|
+
if (!Utils.isNull(canvas)) {
|
|
60
|
+
rotate.unregister(canvas);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
super.disconnectedCallback();
|
|
64
|
+
}
|
|
65
|
+
propertyChangedCallback(name, old, val, first) {
|
|
66
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
67
|
+
switch (name) {
|
|
68
|
+
case 'interactive':
|
|
69
|
+
this._toggleRotate(val);
|
|
70
|
+
if (!val)
|
|
71
|
+
Utils.removeClass(this, 'tuner-interactive');
|
|
72
|
+
else
|
|
73
|
+
Utils.addClass(this, 'tuner-interactive');
|
|
74
|
+
break;
|
|
75
|
+
case 'round':
|
|
76
|
+
if (Math.round(val) != val || val < 0)
|
|
77
|
+
throw `${this.constructor.name}: round value must be an integer greater or equal to zero.`;
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
// in any other case:
|
|
81
|
+
this._draw();
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
_toggleRotate(interactive = this.interactive) {
|
|
86
|
+
const r = this._rotate;
|
|
87
|
+
if (!Utils.isNull(r)) {
|
|
88
|
+
r.disabled = !interactive;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
_angleToValue(angle) {
|
|
92
|
+
const round = Math.pow(10, this.round || 0);
|
|
93
|
+
const angleValue = this.min + angle * (this.max - this.min) / TWO_PI;
|
|
94
|
+
return Math.round(round * angleValue) / round;
|
|
95
|
+
}
|
|
96
|
+
_valueToAngle(v = this.value ?? this.min) {
|
|
97
|
+
return TWO_PI * (v - this.min) / (this.max - this.min);
|
|
98
|
+
}
|
|
99
|
+
_setValue(angle) {
|
|
100
|
+
const value = this._angleToValue(angle).clamp(this.min, this.max);
|
|
101
|
+
if (value != this.value) {
|
|
102
|
+
this.value = value;
|
|
103
|
+
this.dispatchEvent(new Event("change"));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the angle between the vertical line through 'center' and the line through 'center' and 'currentPosition'.
|
|
108
|
+
* @param evt
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
_getAngle(evt) {
|
|
112
|
+
const angle = {
|
|
113
|
+
vertex: evt.detail.center,
|
|
114
|
+
end: evt.detail.currentPosition,
|
|
115
|
+
start: { x: evt.detail.center.x, y: evt.detail.center.y - 1 }
|
|
116
|
+
};
|
|
117
|
+
const alpha = Angle.value(angle);
|
|
118
|
+
if (alpha > 0) {
|
|
119
|
+
return TWO_PI - alpha;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return -alpha;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
_draw(value = this.value) {
|
|
127
|
+
if (this.disabled || Utils.isNull(this._rail)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
value = (isNaN(value) ? this.min : value).clamp(this.min, this.max);
|
|
131
|
+
const rail = this._rail;
|
|
132
|
+
const counterRail = this._counterRail;
|
|
133
|
+
const isMin = value === this.min, isMax = value === this.max;
|
|
134
|
+
if (isMin || isMax) {
|
|
135
|
+
const d = `M 50 50 m -50,0 a 50,50 0 1,1 100,0 a 50,50 0 1,1 -100,0`;
|
|
136
|
+
rail.setAttribute('d', isMin ? '' : d);
|
|
137
|
+
counterRail.setAttribute('d', isMax ? '' : d);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const mathPI2 = Math.PI * .5;
|
|
141
|
+
// rail
|
|
142
|
+
const from = cartesian(50, 50, 50, -mathPI2);
|
|
143
|
+
const angle /* fraction of the round angle */ = this._valueToAngle(value);
|
|
144
|
+
const to = cartesian(50, 50, 50, -mathPI2 + angle);
|
|
145
|
+
const large = angle > Math.PI ? 1 : 0;
|
|
146
|
+
const d = `M ${to.x} ${to.y} A 50 50 0 ${large} 0 ${from.x} ${from.y}`;
|
|
147
|
+
rail.setAttribute('d', d);
|
|
148
|
+
// counter rail
|
|
149
|
+
const counterFrom = to;
|
|
150
|
+
const counterTo = cartesian(50, 50, 50, 3 * mathPI2);
|
|
151
|
+
const counterAngle /* fraction of the round angle */ = this._valueToAngle(this.max - value);
|
|
152
|
+
const counterLarge = counterAngle > Math.PI ? 1 : 0;
|
|
153
|
+
const counterD = `M ${counterTo.x} ${counterTo.y} A 50 50 0 ${counterLarge} 0 ${counterFrom.x} ${counterFrom.y}`;
|
|
154
|
+
counterRail.setAttribute('d', counterD);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
__decorate([
|
|
159
|
+
ViewChild('svg')
|
|
160
|
+
], PacemTunerElement.prototype, "_canvas", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
ViewChild('path[part=rail]')
|
|
163
|
+
], PacemTunerElement.prototype, "_rail", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
ViewChild('path[part=complementary-rail]')
|
|
166
|
+
], PacemTunerElement.prototype, "_counterRail", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
ViewChild(P + '-tween')
|
|
169
|
+
], PacemTunerElement.prototype, "_tween", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
ViewChild(P + '-rotate')
|
|
172
|
+
], PacemTunerElement.prototype, "_rotate", void 0);
|
|
173
|
+
__decorate([
|
|
174
|
+
Watch({ converter: PropertyConverters.Number })
|
|
175
|
+
], PacemTunerElement.prototype, "value", void 0);
|
|
176
|
+
__decorate([
|
|
177
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
178
|
+
], PacemTunerElement.prototype, "min", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
181
|
+
], PacemTunerElement.prototype, "max", void 0);
|
|
182
|
+
__decorate([
|
|
183
|
+
Watch({ emit: false, converter: PropertyConverters.Boolean })
|
|
184
|
+
], PacemTunerElement.prototype, "interactive", void 0);
|
|
185
|
+
__decorate([
|
|
186
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
187
|
+
], PacemTunerElement.prototype, "round", void 0);
|
|
188
|
+
PacemTunerElement = __decorate([
|
|
189
|
+
CustomElement({
|
|
190
|
+
tagName: P + '-tuner', shadow: true,
|
|
191
|
+
template: `<svg xmlns="http://www.w3.org/2000/svg" class="${PCSS}-tuner" part="tuner" viewBox="0 0 100 100">
|
|
192
|
+
<circle part="track" cx="50" cy="50" r="50" />
|
|
193
|
+
<path part="rail" />
|
|
194
|
+
<path part="complementary-rail" />
|
|
195
|
+
</svg><div class="${PCSS}-content" part="content"><slot></slot></div>
|
|
196
|
+
<${P}-rotate></${P}-rotate>
|
|
197
|
+
<${P}-tween on-step=":host._draw($event.detail.value)" on-end="this.disabled = true" duration="500" to="{{ :host.value }}" from="{{ :host.min }}"></${P}-tween>`
|
|
198
|
+
})
|
|
199
|
+
], PacemTunerElement);
|
|
200
|
+
export { PacemTunerElement };
|
|
@@ -0,0 +1,33 @@
|
|
|
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, CustomElement, Watch, PacemEventTarget, Utils } from '@pacem/pacem-core';
|
|
8
|
+
//namespace Pacem.Components.UI {
|
|
9
|
+
let PacemVibrateElement = class PacemVibrateElement extends PacemEventTarget {
|
|
10
|
+
vibrate() {
|
|
11
|
+
if (this.disabled) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const pattern = this.pattern;
|
|
15
|
+
if (!Utils.isNullOrEmpty(pattern)) {
|
|
16
|
+
if (typeof navigator.vibrate === 'function') {
|
|
17
|
+
navigator.vibrate(pattern);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
__decorate([
|
|
23
|
+
Watch({
|
|
24
|
+
emit: false, converter: {
|
|
25
|
+
convert: (attr) => attr?.split(/[ ,]+/).map(i => parseInt(i)),
|
|
26
|
+
convertBack: (prop) => prop?.join(' ')
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
], PacemVibrateElement.prototype, "pattern", void 0);
|
|
30
|
+
PacemVibrateElement = __decorate([
|
|
31
|
+
CustomElement({ tagName: P + '-vibrate' })
|
|
32
|
+
], PacemVibrateElement);
|
|
33
|
+
export { PacemVibrateElement };
|
package/dist/esm/view.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
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, CustomElement, Watch, PacemEventTarget, Components, Utils, PropertyConverters, Logging } from '@pacem/pacem-core';
|
|
8
|
+
//namespace Pacem.Components.UI {
|
|
9
|
+
const ANIM_TIMEOUT = 500;
|
|
10
|
+
const ElementOrStringPropertyConverter = {
|
|
11
|
+
convert: (attr, element) => {
|
|
12
|
+
try {
|
|
13
|
+
return document.querySelector(attr) ?? (element.isConnected ? attr : null);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return attr;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
convertBack: (prop) => (prop instanceof Element && prop.id) ? ('#' + prop.id) : prop,
|
|
20
|
+
retryConversionWhenReady: true
|
|
21
|
+
};
|
|
22
|
+
let PacemViewElement = class PacemViewElement extends PacemEventTarget {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this._templateChangeHandler = (evt) => {
|
|
26
|
+
const tmplProxy = evt.target;
|
|
27
|
+
this._setTmpl(tmplProxy.target);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
propertyChangedCallback(name, old, val, first) {
|
|
31
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
32
|
+
// url
|
|
33
|
+
if (name === 'url' || name === 'disabled') {
|
|
34
|
+
this._dispose(old);
|
|
35
|
+
this._manage();
|
|
36
|
+
}
|
|
37
|
+
else if (name === 'fetching') {
|
|
38
|
+
(val ? Utils.addClass : Utils.removeClass)(this, 'view-fetching');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
viewActivatedCallback() {
|
|
42
|
+
super.viewActivatedCallback();
|
|
43
|
+
const url = this.url;
|
|
44
|
+
if (this._isReference(url) && !this.disabled) {
|
|
45
|
+
this._manageRef();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_isReference(url) {
|
|
49
|
+
return url instanceof HTMLElement || (typeof url === 'string' && url.trim().startsWith('#'));
|
|
50
|
+
}
|
|
51
|
+
_dispose(url) {
|
|
52
|
+
if (url instanceof Components.PacemTemplateProxyElement) {
|
|
53
|
+
url.removeEventListener('templatechange', this._templateChangeHandler);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
_manage() {
|
|
57
|
+
if (this.disabled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const debounce = this.debounce || 0, url = this.url;
|
|
61
|
+
;
|
|
62
|
+
if (this._isReference(url)) {
|
|
63
|
+
// <template>-based
|
|
64
|
+
clearTimeout(this._fetchHandle);
|
|
65
|
+
this._fetchHandle = setTimeout((() => this._manageRef()), debounce);
|
|
66
|
+
}
|
|
67
|
+
else if (typeof url === 'string' && !Utils.isNullOrEmpty(url)) {
|
|
68
|
+
// url-based
|
|
69
|
+
this.fetching = true;
|
|
70
|
+
clearTimeout(this._fetchHandle);
|
|
71
|
+
this._fetchHandle = setTimeout((() => this._manageUrl(url)), debounce);
|
|
72
|
+
}
|
|
73
|
+
else /* might be a reset */ {
|
|
74
|
+
this.innerHTML = '';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
_manageRef() {
|
|
78
|
+
const url = this.url, tmpl = url instanceof HTMLElement ? url : document.querySelector('template' + url);
|
|
79
|
+
if (tmpl instanceof Components.PacemTemplateProxyElement) {
|
|
80
|
+
tmpl.addEventListener('templatechange', this._templateChangeHandler, false);
|
|
81
|
+
this._setTmpl(tmpl.target);
|
|
82
|
+
}
|
|
83
|
+
else if (tmpl instanceof HTMLTemplateElement) {
|
|
84
|
+
this._setTmpl(tmpl);
|
|
85
|
+
}
|
|
86
|
+
else if (!Utils.isNull(tmpl)) {
|
|
87
|
+
this.log(Logging.LogLevel.Error, `Invalid '${tmpl.constructor.name}' element, HTMLTemplate expected.`);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.log(Logging.LogLevel.Error, `Template element not found.`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
_setTmpl(tmpl) {
|
|
94
|
+
cancelAnimationFrame(this._renderHandle);
|
|
95
|
+
// this way, `this._container.innerHTML = ''` instruction will eventually let the page "scroll up"...
|
|
96
|
+
this.innerHTML = '';
|
|
97
|
+
this._renderHandle = requestAnimationFrame(() => {
|
|
98
|
+
if (Utils.isNull(tmpl)) {
|
|
99
|
+
this.log(Logging.LogLevel.Error, `Template element not found.`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.appendChild(tmpl.cloneNode(true).content);
|
|
103
|
+
this._dispatchRender();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
#aborter;
|
|
107
|
+
_manageUrl(url) {
|
|
108
|
+
if (this.#aborter) {
|
|
109
|
+
this.#aborter.abort();
|
|
110
|
+
}
|
|
111
|
+
const { signal } = this.#aborter = new AbortController();
|
|
112
|
+
fetch(url, { credentials: 'same-origin', signal }).then(async (r) => {
|
|
113
|
+
// inline function
|
|
114
|
+
const manageYield = (r, htmlPromise) => {
|
|
115
|
+
if ((r.status === 301 || r.status === 302) && this.followRedirects) {
|
|
116
|
+
this._manageUrl(r.headers.get("Location"));
|
|
117
|
+
}
|
|
118
|
+
else if (r.ok || this.renderErrors) {
|
|
119
|
+
htmlPromise.then((html) => Utils.addAnimationEndCallback(this, () => this._manageResult(html), ANIM_TIMEOUT));
|
|
120
|
+
}
|
|
121
|
+
// fallback to empty content.
|
|
122
|
+
else
|
|
123
|
+
this._manageResult('');
|
|
124
|
+
};
|
|
125
|
+
const contentLength = +r.headers.get('Content-Length');
|
|
126
|
+
if (contentLength > 0) {
|
|
127
|
+
this.progress = 0;
|
|
128
|
+
let received = 0;
|
|
129
|
+
const chunks = [];
|
|
130
|
+
// progress available
|
|
131
|
+
const reader = r.body.getReader();
|
|
132
|
+
while (true) {
|
|
133
|
+
const { done, value } = await reader.read();
|
|
134
|
+
if (done) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
this.progress = (received += value.length) / contentLength;
|
|
138
|
+
chunks.push(value);
|
|
139
|
+
}
|
|
140
|
+
manageYield(r, new Promise((resolve, reject) => {
|
|
141
|
+
try {
|
|
142
|
+
let allChunks = new Uint8Array(received);
|
|
143
|
+
let position = 0;
|
|
144
|
+
for (let chunk of chunks) {
|
|
145
|
+
allChunks.set(chunk, position);
|
|
146
|
+
position += chunk.length;
|
|
147
|
+
}
|
|
148
|
+
const html = new TextDecoder("utf-8").decode(allChunks);
|
|
149
|
+
resolve(html);
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
reject(e);
|
|
153
|
+
}
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
manageYield(r, r.text());
|
|
158
|
+
}
|
|
159
|
+
}, _ => {
|
|
160
|
+
// do nothing on fail
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
_manageResult(result) {
|
|
164
|
+
// this way, `this._container.innerHTML = ''` instruction will eventually let the page "scroll up"...
|
|
165
|
+
cancelAnimationFrame(this._renderHandle);
|
|
166
|
+
this.scrollTo({ top: 0, left: 0, behavior: 'instant' });
|
|
167
|
+
this.innerHTML = '';
|
|
168
|
+
this._renderHandle = requestAnimationFrame(() => {
|
|
169
|
+
this.innerHTML = result;
|
|
170
|
+
this.fetching = false;
|
|
171
|
+
this.progress = Number.NaN;
|
|
172
|
+
// setting fetching to `false` triggers a css class change that could/should cause a css transition to happen
|
|
173
|
+
// TODO: manage to switch to native in a near future (https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API or https://youtu.be/oDcb3fvtETs)
|
|
174
|
+
Utils.addAnimationEndCallback(this, () => {
|
|
175
|
+
this._dispatchRender();
|
|
176
|
+
}, ANIM_TIMEOUT);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
_dispatchRender() {
|
|
180
|
+
this.dispatchEvent(new CustomEvent("render"));
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
__decorate([
|
|
184
|
+
Watch({ reflectBack: true, converter: ElementOrStringPropertyConverter })
|
|
185
|
+
], PacemViewElement.prototype, "url", void 0);
|
|
186
|
+
__decorate([
|
|
187
|
+
Watch()
|
|
188
|
+
], PacemViewElement.prototype, "fetching", void 0);
|
|
189
|
+
__decorate([
|
|
190
|
+
Watch()
|
|
191
|
+
], PacemViewElement.prototype, "progress", void 0);
|
|
192
|
+
__decorate([
|
|
193
|
+
Watch({ emit: false, converter: PropertyConverters.Boolean })
|
|
194
|
+
], PacemViewElement.prototype, "renderErrors", void 0);
|
|
195
|
+
__decorate([
|
|
196
|
+
Watch({ emit: false, converter: PropertyConverters.Boolean })
|
|
197
|
+
], PacemViewElement.prototype, "followRedirects", void 0);
|
|
198
|
+
__decorate([
|
|
199
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
200
|
+
], PacemViewElement.prototype, "debounce", void 0);
|
|
201
|
+
PacemViewElement = __decorate([
|
|
202
|
+
CustomElement({
|
|
203
|
+
tagName: P + '-view'
|
|
204
|
+
})
|
|
205
|
+
], PacemViewElement);
|
|
206
|
+
export { PacemViewElement };
|
|
@@ -0,0 +1,181 @@
|
|
|
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, Components, UI, Utils, PropertyConverters, Defaults, CustomElementUtils, PropertyChangeEventName } from '@pacem/pacem-core';
|
|
8
|
+
import { AdapterPageButtonRefreshEventName } from './adapter';
|
|
9
|
+
//namespace Pacem.Components.UI {
|
|
10
|
+
const HANDLE_CSS = 'window-title';
|
|
11
|
+
let PacemWindowAreaElement = class PacemWindowAreaElement extends Components.PacemIterativeElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this._zIndex = 1;
|
|
15
|
+
this._startHandler = (evt) => {
|
|
16
|
+
this._incrementZIndex(evt.detail.element);
|
|
17
|
+
Utils.addClass(evt.detail.element, 'window-rescaling');
|
|
18
|
+
};
|
|
19
|
+
this._blurHandler = (evt) => {
|
|
20
|
+
Utils.removeClass(evt.detail.element, 'window-rescaling');
|
|
21
|
+
};
|
|
22
|
+
this._focusHandler = (evt) => {
|
|
23
|
+
this._incrementZIndex(evt.currentTarget);
|
|
24
|
+
};
|
|
25
|
+
this._itemPropertyChangeHandler = (evt) => {
|
|
26
|
+
if (evt.detail.propertyName === 'floating' && evt.detail.currentValue === false) {
|
|
27
|
+
const item = evt.currentTarget, ndx = this.items.indexOf(item);
|
|
28
|
+
Utils.addClass(item, 'docking-in');
|
|
29
|
+
this.adapter.select(ndx);
|
|
30
|
+
Utils.addAnimationEndCallback(item, (e) => {
|
|
31
|
+
Utils.removeClass(e, 'docking-in');
|
|
32
|
+
}, 150);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this._adapterPagerCallback = (evt) => {
|
|
36
|
+
const index = evt.detail.index, item = this.items[index];
|
|
37
|
+
evt.detail.hide = item.hide || item.floating;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
validate(item) {
|
|
41
|
+
return item instanceof PacemWindowElement;
|
|
42
|
+
}
|
|
43
|
+
_incrementZIndex(target) {
|
|
44
|
+
if (this._zIndex != parseInt(target.style.zIndex)) {
|
|
45
|
+
target.style.zIndex = '' + (++this._zIndex);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
connectedCallback() {
|
|
49
|
+
super.connectedCallback();
|
|
50
|
+
let shell = CustomElementUtils.findAncestorShell(this);
|
|
51
|
+
this._behaviors = [
|
|
52
|
+
shell.appendChild(this._dragDrop = document.createElement(P + '-drag-drop')),
|
|
53
|
+
shell.appendChild(this._rescale = document.createElement(P + '-rescale'))
|
|
54
|
+
];
|
|
55
|
+
this._dragDrop.handleSelector = '.' + HANDLE_CSS;
|
|
56
|
+
//this._dragDrop.addEventListener(DragDropEventType.Init, this._focusHandler, false);
|
|
57
|
+
this._rescale.addEventListener(UI.RescaleEventType.Start, this._startHandler, false);
|
|
58
|
+
this._rescale.addEventListener(UI.RescaleEventType.End, this._blurHandler, false);
|
|
59
|
+
}
|
|
60
|
+
viewActivatedCallback() {
|
|
61
|
+
super.viewActivatedCallback();
|
|
62
|
+
// adapter (reuse)
|
|
63
|
+
if (Utils.isNull(this.adapter)) {
|
|
64
|
+
const adapter = this.adapter = this.appendChild(document.createElement(P + '-adapter'));
|
|
65
|
+
Utils.addClass(adapter, 'windows-adapter');
|
|
66
|
+
adapter.labelCallback = (item, _) => {
|
|
67
|
+
return item.caption;
|
|
68
|
+
};
|
|
69
|
+
adapter.swipeEnabled = false;
|
|
70
|
+
adapter.deselectable = true;
|
|
71
|
+
adapter.initialize(this);
|
|
72
|
+
}
|
|
73
|
+
this.adapter.addEventListener(AdapterPageButtonRefreshEventName, this._adapterPagerCallback, false);
|
|
74
|
+
}
|
|
75
|
+
disconnectedCallback() {
|
|
76
|
+
if (!Utils.isNull(this.adapter)) {
|
|
77
|
+
this.adapter.removeEventListener(AdapterPageButtonRefreshEventName, this._adapterPagerCallback, false);
|
|
78
|
+
this.adapter.remove();
|
|
79
|
+
this.adapter = null;
|
|
80
|
+
}
|
|
81
|
+
//this._dragDrop.removeEventListener(DragDropEventType.Init, this._focusHandler, false);
|
|
82
|
+
this._rescale.removeEventListener(UI.RescaleEventType.End, this._blurHandler, false);
|
|
83
|
+
this._rescale.removeEventListener(UI.RescaleEventType.Start, this._startHandler, false);
|
|
84
|
+
for (let b of this._behaviors) {
|
|
85
|
+
b.remove();
|
|
86
|
+
}
|
|
87
|
+
super.disconnectedCallback();
|
|
88
|
+
}
|
|
89
|
+
propertyChangedCallback(name, old, val, first) {
|
|
90
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
91
|
+
if (name === 'index') {
|
|
92
|
+
this._syncVisibility();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
register(item) {
|
|
96
|
+
const retval = super.register(item);
|
|
97
|
+
if (retval) {
|
|
98
|
+
item.addEventListener(PropertyChangeEventName, this._itemPropertyChangeHandler, false);
|
|
99
|
+
item.addEventListener('mousedown', this._focusHandler, false);
|
|
100
|
+
for (let b of this._behaviors) {
|
|
101
|
+
const ndx = item.behaviors.indexOf(b);
|
|
102
|
+
if (ndx === -1) {
|
|
103
|
+
item.behaviors.push(b);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return retval;
|
|
108
|
+
}
|
|
109
|
+
unregister(item) {
|
|
110
|
+
const retval = super.unregister(item);
|
|
111
|
+
if (retval) {
|
|
112
|
+
item.removeEventListener(PropertyChangeEventName, this._itemPropertyChangeHandler, false);
|
|
113
|
+
item.removeEventListener('mousedown', this._focusHandler, false);
|
|
114
|
+
for (let b of this._behaviors) {
|
|
115
|
+
const ndx = item.behaviors.indexOf(b);
|
|
116
|
+
if (ndx >= 0) {
|
|
117
|
+
item.behaviors.splice(ndx, 1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return retval;
|
|
122
|
+
}
|
|
123
|
+
_syncVisibility() {
|
|
124
|
+
let ndx = 0;
|
|
125
|
+
const items = this.items ?? [];
|
|
126
|
+
for (let item of items) {
|
|
127
|
+
if (ndx === this.index) {
|
|
128
|
+
Utils.addClass(item, 'dock-open');
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
Utils.removeClass(item, 'dock-open');
|
|
132
|
+
}
|
|
133
|
+
ndx++;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
PacemWindowAreaElement = __decorate([
|
|
138
|
+
CustomElement({
|
|
139
|
+
tagName: P + '-window-area'
|
|
140
|
+
})
|
|
141
|
+
], PacemWindowAreaElement);
|
|
142
|
+
export { PacemWindowAreaElement };
|
|
143
|
+
let PacemWindowElement = class PacemWindowElement extends Components.PacemIterableElement {
|
|
144
|
+
propertyChangedCallback(name, old, val, first) {
|
|
145
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
146
|
+
if (name === 'minimized' || name === 'floating') {
|
|
147
|
+
this._syncLayout();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
viewActivatedCallback() {
|
|
151
|
+
super.viewActivatedCallback();
|
|
152
|
+
this._syncLayout();
|
|
153
|
+
}
|
|
154
|
+
_syncLayout() {
|
|
155
|
+
(this.minimized ? Utils.addClass : Utils.removeClass).apply(this, [this, 'window-min']);
|
|
156
|
+
(this.floating ? Utils.removeClass : Utils.addClass).apply(this, [this, 'window-dock']);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
__decorate([
|
|
160
|
+
Watch({ converter: PropertyConverters.String })
|
|
161
|
+
], PacemWindowElement.prototype, "caption", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
164
|
+
], PacemWindowElement.prototype, "minimized", void 0);
|
|
165
|
+
__decorate([
|
|
166
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
167
|
+
], PacemWindowElement.prototype, "floating", void 0);
|
|
168
|
+
PacemWindowElement = __decorate([
|
|
169
|
+
CustomElement({
|
|
170
|
+
tagName: P + '-window', shadow: Defaults.USE_SHADOW_ROOT,
|
|
171
|
+
template: `<div class="${HANDLE_CSS}">
|
|
172
|
+
<${P}-text text="{{ :host.caption || 'Window' }}"></${P}-text>
|
|
173
|
+
</div>
|
|
174
|
+
<div class="window-buttons ${PCSS}-buttonset"><div class="buttonset-right">
|
|
175
|
+
<${P}-button class="button" on-click=":host.minimized = !:host.minimized" icon-glyph="{{ :host.minimized ? 'maximize' : 'minimize' }}" hide="{{ !:host.floating }}"></${P}-button>
|
|
176
|
+
<${P}-button class="button" on-click=":host.floating = !:host.floating" css-class="{{ {'buttonset-first': !:host.floating} }}" icon-glyph="{{ :host.floating? 'lock_open' : 'lock' }}"></${P}-button>
|
|
177
|
+
</div></div>
|
|
178
|
+
<div class="window-content"><${P}-content></${P}-content></div>`
|
|
179
|
+
})
|
|
180
|
+
], PacemWindowElement);
|
|
181
|
+
export { PacemWindowElement };
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pacem/pacem-ui",
|
|
3
|
+
"files": [
|
|
4
|
+
"dist/browser/*.*",
|
|
5
|
+
"dist/bundle/*.*",
|
|
6
|
+
"dist/esm/*.*",
|
|
7
|
+
"typings/*.*",
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE",
|
|
10
|
+
"NOTICE",
|
|
11
|
+
"package.json"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@pacem/pacem-foundation": "*",
|
|
16
|
+
"@pacem/pacem-core": "*"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/esm/index.js",
|
|
19
|
+
"module": "./dist/esm/index.js",
|
|
20
|
+
"typings": "./typings/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/esm/index.js",
|
|
24
|
+
"types": "./typings/index.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"version": "1.0.0-abel",
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Pacem",
|
|
30
|
+
"url": "https://pacem.it"
|
|
31
|
+
},
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"homepage": "https://js.pacem.it",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/pacem-it/pacem.git"
|
|
37
|
+
}
|
|
38
|
+
}
|