16153 lines
595 KiB
JavaScript
16153 lines
595 KiB
JavaScript
(function (exports) {
|
|
'use strict';
|
|
|
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
|
|
function getAugmentedNamespace(n) {
|
|
if (n.__esModule) return n;
|
|
var f = n.default;
|
|
if (typeof f == "function") {
|
|
var a = function a () {
|
|
if (this instanceof a) {
|
|
return Reflect.construct(f, arguments, this.constructor);
|
|
}
|
|
return f.apply(this, arguments);
|
|
};
|
|
a.prototype = f.prototype;
|
|
} else a = {};
|
|
Object.defineProperty(a, '__esModule', {value: true});
|
|
Object.keys(n).forEach(function (k) {
|
|
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
Object.defineProperty(a, k, d.get ? d : {
|
|
enumerable: true,
|
|
get: function () {
|
|
return n[k];
|
|
}
|
|
});
|
|
});
|
|
return a;
|
|
}
|
|
|
|
var main$1 = {};
|
|
|
|
var cjs$3 = {exports: {}};
|
|
|
|
var url$1 = {};
|
|
|
|
var cjs$2 = {};
|
|
|
|
var socket$2 = {};
|
|
|
|
var transports = {};
|
|
|
|
var pollingXhr = {};
|
|
|
|
var polling = {};
|
|
|
|
var transport = {};
|
|
|
|
var cjs$1 = {};
|
|
|
|
var encodePacket_browser = {};
|
|
|
|
var commons = {};
|
|
|
|
Object.defineProperty(commons, "__esModule", { value: true });
|
|
commons.ERROR_PACKET = commons.PACKET_TYPES_REVERSE = commons.PACKET_TYPES = void 0;
|
|
const PACKET_TYPES = Object.create(null); // no Map = no polyfill
|
|
commons.PACKET_TYPES = PACKET_TYPES;
|
|
PACKET_TYPES["open"] = "0";
|
|
PACKET_TYPES["close"] = "1";
|
|
PACKET_TYPES["ping"] = "2";
|
|
PACKET_TYPES["pong"] = "3";
|
|
PACKET_TYPES["message"] = "4";
|
|
PACKET_TYPES["upgrade"] = "5";
|
|
PACKET_TYPES["noop"] = "6";
|
|
const PACKET_TYPES_REVERSE = Object.create(null);
|
|
commons.PACKET_TYPES_REVERSE = PACKET_TYPES_REVERSE;
|
|
Object.keys(PACKET_TYPES).forEach((key) => {
|
|
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
|
|
});
|
|
const ERROR_PACKET = { type: "error", data: "parser error" };
|
|
commons.ERROR_PACKET = ERROR_PACKET;
|
|
|
|
Object.defineProperty(encodePacket_browser, "__esModule", { value: true });
|
|
encodePacket_browser.encodePacket = void 0;
|
|
encodePacket_browser.encodePacketToBinary = encodePacketToBinary;
|
|
const commons_js_1$1 = commons;
|
|
const withNativeBlob$1 = typeof Blob === "function" ||
|
|
(typeof Blob !== "undefined" &&
|
|
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
|
|
const withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
|
|
// ArrayBuffer.isView method is not defined in IE10
|
|
const isView$1 = (obj) => {
|
|
return typeof ArrayBuffer.isView === "function"
|
|
? ArrayBuffer.isView(obj)
|
|
: obj && obj.buffer instanceof ArrayBuffer;
|
|
};
|
|
const encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
if (withNativeBlob$1 && data instanceof Blob) {
|
|
if (supportsBinary) {
|
|
return callback(data);
|
|
}
|
|
else {
|
|
return encodeBlobAsBase64(data, callback);
|
|
}
|
|
}
|
|
else if (withNativeArrayBuffer$2 &&
|
|
(data instanceof ArrayBuffer || isView$1(data))) {
|
|
if (supportsBinary) {
|
|
return callback(data);
|
|
}
|
|
else {
|
|
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
}
|
|
}
|
|
// plain string
|
|
return callback(commons_js_1$1.PACKET_TYPES[type] + (data || ""));
|
|
};
|
|
encodePacket_browser.encodePacket = encodePacket;
|
|
const encodeBlobAsBase64 = (data, callback) => {
|
|
const fileReader = new FileReader();
|
|
fileReader.onload = function () {
|
|
const content = fileReader.result.split(",")[1];
|
|
callback("b" + (content || ""));
|
|
};
|
|
return fileReader.readAsDataURL(data);
|
|
};
|
|
function toArray$1(data) {
|
|
if (data instanceof Uint8Array) {
|
|
return data;
|
|
}
|
|
else if (data instanceof ArrayBuffer) {
|
|
return new Uint8Array(data);
|
|
}
|
|
else {
|
|
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
}
|
|
}
|
|
let TEXT_ENCODER;
|
|
function encodePacketToBinary(packet, callback) {
|
|
if (withNativeBlob$1 && packet.data instanceof Blob) {
|
|
return packet.data.arrayBuffer().then(toArray$1).then(callback);
|
|
}
|
|
else if (withNativeArrayBuffer$2 &&
|
|
(packet.data instanceof ArrayBuffer || isView$1(packet.data))) {
|
|
return callback(toArray$1(packet.data));
|
|
}
|
|
encodePacket(packet, false, (encoded) => {
|
|
if (!TEXT_ENCODER) {
|
|
TEXT_ENCODER = new TextEncoder();
|
|
}
|
|
callback(TEXT_ENCODER.encode(encoded));
|
|
});
|
|
}
|
|
|
|
var decodePacket_browser = {};
|
|
|
|
var base64Arraybuffer = {};
|
|
|
|
Object.defineProperty(base64Arraybuffer, "__esModule", { value: true });
|
|
base64Arraybuffer.decode = base64Arraybuffer.encode = void 0;
|
|
// imported from https://github.com/socketio/base64-arraybuffer
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
// Use a lookup table to find the index.
|
|
const lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
for (let i = 0; i < chars.length; i++) {
|
|
lookup[chars.charCodeAt(i)] = i;
|
|
}
|
|
const encode$1 = (arraybuffer) => {
|
|
let bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
|
|
for (i = 0; i < len; i += 3) {
|
|
base64 += chars[bytes[i] >> 2];
|
|
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
|
|
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
|
|
base64 += chars[bytes[i + 2] & 63];
|
|
}
|
|
if (len % 3 === 2) {
|
|
base64 = base64.substring(0, base64.length - 1) + '=';
|
|
}
|
|
else if (len % 3 === 1) {
|
|
base64 = base64.substring(0, base64.length - 2) + '==';
|
|
}
|
|
return base64;
|
|
};
|
|
base64Arraybuffer.encode = encode$1;
|
|
const decode$1 = (base64) => {
|
|
let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
|
if (base64[base64.length - 1] === '=') {
|
|
bufferLength--;
|
|
if (base64[base64.length - 2] === '=') {
|
|
bufferLength--;
|
|
}
|
|
}
|
|
const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
|
|
for (i = 0; i < len; i += 4) {
|
|
encoded1 = lookup[base64.charCodeAt(i)];
|
|
encoded2 = lookup[base64.charCodeAt(i + 1)];
|
|
encoded3 = lookup[base64.charCodeAt(i + 2)];
|
|
encoded4 = lookup[base64.charCodeAt(i + 3)];
|
|
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
}
|
|
return arraybuffer;
|
|
};
|
|
base64Arraybuffer.decode = decode$1;
|
|
|
|
Object.defineProperty(decodePacket_browser, "__esModule", { value: true });
|
|
decodePacket_browser.decodePacket = void 0;
|
|
const commons_js_1 = commons;
|
|
const base64_arraybuffer_js_1 = base64Arraybuffer;
|
|
const withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
|
|
const decodePacket = (encodedPacket, binaryType) => {
|
|
if (typeof encodedPacket !== "string") {
|
|
return {
|
|
type: "message",
|
|
data: mapBinary(encodedPacket, binaryType),
|
|
};
|
|
}
|
|
const type = encodedPacket.charAt(0);
|
|
if (type === "b") {
|
|
return {
|
|
type: "message",
|
|
data: decodeBase64Packet(encodedPacket.substring(1), binaryType),
|
|
};
|
|
}
|
|
const packetType = commons_js_1.PACKET_TYPES_REVERSE[type];
|
|
if (!packetType) {
|
|
return commons_js_1.ERROR_PACKET;
|
|
}
|
|
return encodedPacket.length > 1
|
|
? {
|
|
type: commons_js_1.PACKET_TYPES_REVERSE[type],
|
|
data: encodedPacket.substring(1),
|
|
}
|
|
: {
|
|
type: commons_js_1.PACKET_TYPES_REVERSE[type],
|
|
};
|
|
};
|
|
decodePacket_browser.decodePacket = decodePacket;
|
|
const decodeBase64Packet = (data, binaryType) => {
|
|
if (withNativeArrayBuffer$1) {
|
|
const decoded = (0, base64_arraybuffer_js_1.decode)(data);
|
|
return mapBinary(decoded, binaryType);
|
|
}
|
|
else {
|
|
return { base64: true, data }; // fallback for old browsers
|
|
}
|
|
};
|
|
const mapBinary = (data, binaryType) => {
|
|
switch (binaryType) {
|
|
case "blob":
|
|
if (data instanceof Blob) {
|
|
// from WebSocket + binaryType "blob"
|
|
return data;
|
|
}
|
|
else {
|
|
// from HTTP long-polling or WebTransport
|
|
return new Blob([data]);
|
|
}
|
|
case "arraybuffer":
|
|
default:
|
|
if (data instanceof ArrayBuffer) {
|
|
// from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
|
|
return data;
|
|
}
|
|
else {
|
|
// from WebTransport (Uint8Array)
|
|
return data.buffer;
|
|
}
|
|
}
|
|
};
|
|
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.decodePayload = exports.decodePacket = exports.encodePayload = exports.encodePacket = exports.protocol = void 0;
|
|
exports.createPacketEncoderStream = createPacketEncoderStream;
|
|
exports.createPacketDecoderStream = createPacketDecoderStream;
|
|
const encodePacket_js_1 = encodePacket_browser;
|
|
Object.defineProperty(exports, "encodePacket", { enumerable: true, get: function () { return encodePacket_js_1.encodePacket; } });
|
|
const decodePacket_js_1 = decodePacket_browser;
|
|
Object.defineProperty(exports, "decodePacket", { enumerable: true, get: function () { return decodePacket_js_1.decodePacket; } });
|
|
const commons_js_1 = commons;
|
|
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
|
|
const encodePayload = (packets, callback) => {
|
|
// some packets may be added to the array while encoding, so the initial length must be saved
|
|
const length = packets.length;
|
|
const encodedPackets = new Array(length);
|
|
let count = 0;
|
|
packets.forEach((packet, i) => {
|
|
// force base64 encoding for binary packets
|
|
(0, encodePacket_js_1.encodePacket)(packet, false, (encodedPacket) => {
|
|
encodedPackets[i] = encodedPacket;
|
|
if (++count === length) {
|
|
callback(encodedPackets.join(SEPARATOR));
|
|
}
|
|
});
|
|
});
|
|
};
|
|
exports.encodePayload = encodePayload;
|
|
const decodePayload = (encodedPayload, binaryType) => {
|
|
const encodedPackets = encodedPayload.split(SEPARATOR);
|
|
const packets = [];
|
|
for (let i = 0; i < encodedPackets.length; i++) {
|
|
const decodedPacket = (0, decodePacket_js_1.decodePacket)(encodedPackets[i], binaryType);
|
|
packets.push(decodedPacket);
|
|
if (decodedPacket.type === "error") {
|
|
break;
|
|
}
|
|
}
|
|
return packets;
|
|
};
|
|
exports.decodePayload = decodePayload;
|
|
function createPacketEncoderStream() {
|
|
return new TransformStream({
|
|
transform(packet, controller) {
|
|
(0, encodePacket_js_1.encodePacketToBinary)(packet, (encodedPacket) => {
|
|
const payloadLength = encodedPacket.length;
|
|
let header;
|
|
// inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
|
|
if (payloadLength < 126) {
|
|
header = new Uint8Array(1);
|
|
new DataView(header.buffer).setUint8(0, payloadLength);
|
|
}
|
|
else if (payloadLength < 65536) {
|
|
header = new Uint8Array(3);
|
|
const view = new DataView(header.buffer);
|
|
view.setUint8(0, 126);
|
|
view.setUint16(1, payloadLength);
|
|
}
|
|
else {
|
|
header = new Uint8Array(9);
|
|
const view = new DataView(header.buffer);
|
|
view.setUint8(0, 127);
|
|
view.setBigUint64(1, BigInt(payloadLength));
|
|
}
|
|
// first bit indicates whether the payload is plain text (0) or binary (1)
|
|
if (packet.data && typeof packet.data !== "string") {
|
|
header[0] |= 0x80;
|
|
}
|
|
controller.enqueue(header);
|
|
controller.enqueue(encodedPacket);
|
|
});
|
|
},
|
|
});
|
|
}
|
|
let TEXT_DECODER;
|
|
function totalLength(chunks) {
|
|
return chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
}
|
|
function concatChunks(chunks, size) {
|
|
if (chunks[0].length === size) {
|
|
return chunks.shift();
|
|
}
|
|
const buffer = new Uint8Array(size);
|
|
let j = 0;
|
|
for (let i = 0; i < size; i++) {
|
|
buffer[i] = chunks[0][j++];
|
|
if (j === chunks[0].length) {
|
|
chunks.shift();
|
|
j = 0;
|
|
}
|
|
}
|
|
if (chunks.length && j < chunks[0].length) {
|
|
chunks[0] = chunks[0].slice(j);
|
|
}
|
|
return buffer;
|
|
}
|
|
function createPacketDecoderStream(maxPayload, binaryType) {
|
|
if (!TEXT_DECODER) {
|
|
TEXT_DECODER = new TextDecoder();
|
|
}
|
|
const chunks = [];
|
|
let state = 0 /* State.READ_HEADER */;
|
|
let expectedLength = -1;
|
|
let isBinary = false;
|
|
return new TransformStream({
|
|
transform(chunk, controller) {
|
|
chunks.push(chunk);
|
|
while (true) {
|
|
if (state === 0 /* State.READ_HEADER */) {
|
|
if (totalLength(chunks) < 1) {
|
|
break;
|
|
}
|
|
const header = concatChunks(chunks, 1);
|
|
isBinary = (header[0] & 0x80) === 0x80;
|
|
expectedLength = header[0] & 0x7f;
|
|
if (expectedLength < 126) {
|
|
state = 3 /* State.READ_PAYLOAD */;
|
|
}
|
|
else if (expectedLength === 126) {
|
|
state = 1 /* State.READ_EXTENDED_LENGTH_16 */;
|
|
}
|
|
else {
|
|
state = 2 /* State.READ_EXTENDED_LENGTH_64 */;
|
|
}
|
|
}
|
|
else if (state === 1 /* State.READ_EXTENDED_LENGTH_16 */) {
|
|
if (totalLength(chunks) < 2) {
|
|
break;
|
|
}
|
|
const headerArray = concatChunks(chunks, 2);
|
|
expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
|
|
state = 3 /* State.READ_PAYLOAD */;
|
|
}
|
|
else if (state === 2 /* State.READ_EXTENDED_LENGTH_64 */) {
|
|
if (totalLength(chunks) < 8) {
|
|
break;
|
|
}
|
|
const headerArray = concatChunks(chunks, 8);
|
|
const view = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length);
|
|
const n = view.getUint32(0);
|
|
if (n > Math.pow(2, 53 - 32) - 1) {
|
|
// the maximum safe integer in JavaScript is 2^53 - 1
|
|
controller.enqueue(commons_js_1.ERROR_PACKET);
|
|
break;
|
|
}
|
|
expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
|
|
state = 3 /* State.READ_PAYLOAD */;
|
|
}
|
|
else {
|
|
if (totalLength(chunks) < expectedLength) {
|
|
break;
|
|
}
|
|
const data = concatChunks(chunks, expectedLength);
|
|
controller.enqueue((0, decodePacket_js_1.decodePacket)(isBinary ? data : TEXT_DECODER.decode(data), binaryType));
|
|
state = 0 /* State.READ_HEADER */;
|
|
}
|
|
if (expectedLength === 0 || expectedLength > maxPayload) {
|
|
controller.enqueue(commons_js_1.ERROR_PACKET);
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
});
|
|
}
|
|
exports.protocol = 4;
|
|
} (cjs$1));
|
|
|
|
/**
|
|
* Initialize a new `Emitter`.
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
function Emitter(obj) {
|
|
if (obj) return mixin(obj);
|
|
}
|
|
|
|
/**
|
|
* Mixin the emitter properties.
|
|
*
|
|
* @param {Object} obj
|
|
* @return {Object}
|
|
* @api private
|
|
*/
|
|
|
|
function mixin(obj) {
|
|
for (var key in Emitter.prototype) {
|
|
obj[key] = Emitter.prototype[key];
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
/**
|
|
* Listen on the given `event` with `fn`.
|
|
*
|
|
* @param {String} event
|
|
* @param {Function} fn
|
|
* @return {Emitter}
|
|
* @api public
|
|
*/
|
|
|
|
Emitter.prototype.on =
|
|
Emitter.prototype.addEventListener = function(event, fn){
|
|
this._callbacks = this._callbacks || {};
|
|
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
.push(fn);
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Adds an `event` listener that will be invoked a single
|
|
* time then automatically removed.
|
|
*
|
|
* @param {String} event
|
|
* @param {Function} fn
|
|
* @return {Emitter}
|
|
* @api public
|
|
*/
|
|
|
|
Emitter.prototype.once = function(event, fn){
|
|
function on() {
|
|
this.off(event, on);
|
|
fn.apply(this, arguments);
|
|
}
|
|
|
|
on.fn = fn;
|
|
this.on(event, on);
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Remove the given callback for `event` or all
|
|
* registered callbacks.
|
|
*
|
|
* @param {String} event
|
|
* @param {Function} fn
|
|
* @return {Emitter}
|
|
* @api public
|
|
*/
|
|
|
|
Emitter.prototype.off =
|
|
Emitter.prototype.removeListener =
|
|
Emitter.prototype.removeAllListeners =
|
|
Emitter.prototype.removeEventListener = function(event, fn){
|
|
this._callbacks = this._callbacks || {};
|
|
|
|
// all
|
|
if (0 == arguments.length) {
|
|
this._callbacks = {};
|
|
return this;
|
|
}
|
|
|
|
// specific event
|
|
var callbacks = this._callbacks['$' + event];
|
|
if (!callbacks) return this;
|
|
|
|
// remove all handlers
|
|
if (1 == arguments.length) {
|
|
delete this._callbacks['$' + event];
|
|
return this;
|
|
}
|
|
|
|
// remove specific handler
|
|
var cb;
|
|
for (var i = 0; i < callbacks.length; i++) {
|
|
cb = callbacks[i];
|
|
if (cb === fn || cb.fn === fn) {
|
|
callbacks.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Remove event specific arrays for event types that no
|
|
// one is subscribed for to avoid memory leak.
|
|
if (callbacks.length === 0) {
|
|
delete this._callbacks['$' + event];
|
|
}
|
|
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Emit `event` with the given args.
|
|
*
|
|
* @param {String} event
|
|
* @param {Mixed} ...
|
|
* @return {Emitter}
|
|
*/
|
|
|
|
Emitter.prototype.emit = function(event){
|
|
this._callbacks = this._callbacks || {};
|
|
|
|
var args = new Array(arguments.length - 1)
|
|
, callbacks = this._callbacks['$' + event];
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
args[i - 1] = arguments[i];
|
|
}
|
|
|
|
if (callbacks) {
|
|
callbacks = callbacks.slice(0);
|
|
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
callbacks[i].apply(this, args);
|
|
}
|
|
}
|
|
|
|
return this;
|
|
};
|
|
|
|
// alias used for reserved events (protected method)
|
|
Emitter.prototype.emitReserved = Emitter.prototype.emit;
|
|
|
|
/**
|
|
* Return array of callbacks for `event`.
|
|
*
|
|
* @param {String} event
|
|
* @return {Array}
|
|
* @api public
|
|
*/
|
|
|
|
Emitter.prototype.listeners = function(event){
|
|
this._callbacks = this._callbacks || {};
|
|
return this._callbacks['$' + event] || [];
|
|
};
|
|
|
|
/**
|
|
* Check if this emitter has `event` handlers.
|
|
*
|
|
* @param {String} event
|
|
* @return {Boolean}
|
|
* @api public
|
|
*/
|
|
|
|
Emitter.prototype.hasListeners = function(event){
|
|
return !! this.listeners(event).length;
|
|
};
|
|
|
|
var esm = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
Emitter: Emitter
|
|
});
|
|
|
|
var require$$5 = /*@__PURE__*/getAugmentedNamespace(esm);
|
|
|
|
var util = {};
|
|
|
|
var globals = {};
|
|
|
|
Object.defineProperty(globals, "__esModule", { value: true });
|
|
globals.defaultBinaryType = globals.globalThisShim = globals.nextTick = void 0;
|
|
globals.createCookieJar = createCookieJar;
|
|
globals.nextTick = (() => {
|
|
const isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
|
|
if (isPromiseAvailable) {
|
|
return (cb) => Promise.resolve().then(cb);
|
|
}
|
|
else {
|
|
return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
|
|
}
|
|
})();
|
|
globals.globalThisShim = (() => {
|
|
if (typeof self !== "undefined") {
|
|
return self;
|
|
}
|
|
else if (typeof window !== "undefined") {
|
|
return window;
|
|
}
|
|
else {
|
|
return Function("return this")();
|
|
}
|
|
})();
|
|
globals.defaultBinaryType = "arraybuffer";
|
|
function createCookieJar() { }
|
|
|
|
Object.defineProperty(util, "__esModule", { value: true });
|
|
util.pick = pick;
|
|
util.installTimerFunctions = installTimerFunctions;
|
|
util.byteLength = byteLength;
|
|
util.randomString = randomString;
|
|
const globals_node_js_1$4 = globals;
|
|
function pick(obj, ...attr) {
|
|
return attr.reduce((acc, k) => {
|
|
if (obj.hasOwnProperty(k)) {
|
|
acc[k] = obj[k];
|
|
}
|
|
return acc;
|
|
}, {});
|
|
}
|
|
// Keep a reference to the real timeout functions so they can be used when overridden
|
|
const NATIVE_SET_TIMEOUT = globals_node_js_1$4.globalThisShim.setTimeout;
|
|
const NATIVE_CLEAR_TIMEOUT = globals_node_js_1$4.globalThisShim.clearTimeout;
|
|
function installTimerFunctions(obj, opts) {
|
|
if (opts.useNativeTimers) {
|
|
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globals_node_js_1$4.globalThisShim);
|
|
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globals_node_js_1$4.globalThisShim);
|
|
}
|
|
else {
|
|
obj.setTimeoutFn = globals_node_js_1$4.globalThisShim.setTimeout.bind(globals_node_js_1$4.globalThisShim);
|
|
obj.clearTimeoutFn = globals_node_js_1$4.globalThisShim.clearTimeout.bind(globals_node_js_1$4.globalThisShim);
|
|
}
|
|
}
|
|
// base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
|
|
const BASE64_OVERHEAD = 1.33;
|
|
// we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
|
|
function byteLength(obj) {
|
|
if (typeof obj === "string") {
|
|
return utf8Length(obj);
|
|
}
|
|
// arraybuffer or blob
|
|
return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
|
|
}
|
|
function utf8Length(str) {
|
|
let c = 0, length = 0;
|
|
for (let i = 0, l = str.length; i < l; i++) {
|
|
c = str.charCodeAt(i);
|
|
if (c < 0x80) {
|
|
length += 1;
|
|
}
|
|
else if (c < 0x800) {
|
|
length += 2;
|
|
}
|
|
else if (c < 0xd800 || c >= 0xe000) {
|
|
length += 3;
|
|
}
|
|
else {
|
|
i++;
|
|
length += 4;
|
|
}
|
|
}
|
|
return length;
|
|
}
|
|
/**
|
|
* Generates a random 8-characters string.
|
|
*/
|
|
function randomString() {
|
|
return (Date.now().toString(36).substring(3) +
|
|
Math.random().toString(36).substring(2, 5));
|
|
}
|
|
|
|
var parseqs = {};
|
|
|
|
// imported from https://github.com/galkn/querystring
|
|
/**
|
|
* Compiles a querystring
|
|
* Returns string representation of the object
|
|
*
|
|
* @param {Object}
|
|
* @api private
|
|
*/
|
|
Object.defineProperty(parseqs, "__esModule", { value: true });
|
|
parseqs.encode = encode;
|
|
parseqs.decode = decode;
|
|
function encode(obj) {
|
|
let str = '';
|
|
for (let i in obj) {
|
|
if (obj.hasOwnProperty(i)) {
|
|
if (str.length)
|
|
str += '&';
|
|
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
/**
|
|
* Parses a simple querystring into an object
|
|
*
|
|
* @param {String} qs
|
|
* @api private
|
|
*/
|
|
function decode(qs) {
|
|
let qry = {};
|
|
let pairs = qs.split('&');
|
|
for (let i = 0, l = pairs.length; i < l; i++) {
|
|
let pair = pairs[i].split('=');
|
|
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
|
}
|
|
return qry;
|
|
}
|
|
|
|
var browser = {exports: {}};
|
|
|
|
/**
|
|
* Helpers.
|
|
*/
|
|
|
|
var ms;
|
|
var hasRequiredMs;
|
|
|
|
function requireMs () {
|
|
if (hasRequiredMs) return ms;
|
|
hasRequiredMs = 1;
|
|
var s = 1000;
|
|
var m = s * 60;
|
|
var h = m * 60;
|
|
var d = h * 24;
|
|
var w = d * 7;
|
|
var y = d * 365.25;
|
|
|
|
/**
|
|
* Parse or format the given `val`.
|
|
*
|
|
* Options:
|
|
*
|
|
* - `long` verbose formatting [false]
|
|
*
|
|
* @param {String|Number} val
|
|
* @param {Object} [options]
|
|
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
* @return {String|Number}
|
|
* @api public
|
|
*/
|
|
|
|
ms = function (val, options) {
|
|
options = options || {};
|
|
var type = typeof val;
|
|
if (type === 'string' && val.length > 0) {
|
|
return parse(val);
|
|
} else if (type === 'number' && isFinite(val)) {
|
|
return options.long ? fmtLong(val) : fmtShort(val);
|
|
}
|
|
throw new Error(
|
|
'val is not a non-empty string or a valid number. val=' +
|
|
JSON.stringify(val)
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Parse the given `str` and return milliseconds.
|
|
*
|
|
* @param {String} str
|
|
* @return {Number}
|
|
* @api private
|
|
*/
|
|
|
|
function parse(str) {
|
|
str = String(str);
|
|
if (str.length > 100) {
|
|
return;
|
|
}
|
|
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
str
|
|
);
|
|
if (!match) {
|
|
return;
|
|
}
|
|
var n = parseFloat(match[1]);
|
|
var type = (match[2] || 'ms').toLowerCase();
|
|
switch (type) {
|
|
case 'years':
|
|
case 'year':
|
|
case 'yrs':
|
|
case 'yr':
|
|
case 'y':
|
|
return n * y;
|
|
case 'weeks':
|
|
case 'week':
|
|
case 'w':
|
|
return n * w;
|
|
case 'days':
|
|
case 'day':
|
|
case 'd':
|
|
return n * d;
|
|
case 'hours':
|
|
case 'hour':
|
|
case 'hrs':
|
|
case 'hr':
|
|
case 'h':
|
|
return n * h;
|
|
case 'minutes':
|
|
case 'minute':
|
|
case 'mins':
|
|
case 'min':
|
|
case 'm':
|
|
return n * m;
|
|
case 'seconds':
|
|
case 'second':
|
|
case 'secs':
|
|
case 'sec':
|
|
case 's':
|
|
return n * s;
|
|
case 'milliseconds':
|
|
case 'millisecond':
|
|
case 'msecs':
|
|
case 'msec':
|
|
case 'ms':
|
|
return n;
|
|
default:
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Short format for `ms`.
|
|
*
|
|
* @param {Number} ms
|
|
* @return {String}
|
|
* @api private
|
|
*/
|
|
|
|
function fmtShort(ms) {
|
|
var msAbs = Math.abs(ms);
|
|
if (msAbs >= d) {
|
|
return Math.round(ms / d) + 'd';
|
|
}
|
|
if (msAbs >= h) {
|
|
return Math.round(ms / h) + 'h';
|
|
}
|
|
if (msAbs >= m) {
|
|
return Math.round(ms / m) + 'm';
|
|
}
|
|
if (msAbs >= s) {
|
|
return Math.round(ms / s) + 's';
|
|
}
|
|
return ms + 'ms';
|
|
}
|
|
|
|
/**
|
|
* Long format for `ms`.
|
|
*
|
|
* @param {Number} ms
|
|
* @return {String}
|
|
* @api private
|
|
*/
|
|
|
|
function fmtLong(ms) {
|
|
var msAbs = Math.abs(ms);
|
|
if (msAbs >= d) {
|
|
return plural(ms, msAbs, d, 'day');
|
|
}
|
|
if (msAbs >= h) {
|
|
return plural(ms, msAbs, h, 'hour');
|
|
}
|
|
if (msAbs >= m) {
|
|
return plural(ms, msAbs, m, 'minute');
|
|
}
|
|
if (msAbs >= s) {
|
|
return plural(ms, msAbs, s, 'second');
|
|
}
|
|
return ms + ' ms';
|
|
}
|
|
|
|
/**
|
|
* Pluralization helper.
|
|
*/
|
|
|
|
function plural(ms, msAbs, n, name) {
|
|
var isPlural = msAbs >= n * 1.5;
|
|
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
}
|
|
return ms;
|
|
}
|
|
|
|
/**
|
|
* This is the common logic for both the Node.js and web browser
|
|
* implementations of `debug()`.
|
|
*/
|
|
|
|
function setup(env) {
|
|
createDebug.debug = createDebug;
|
|
createDebug.default = createDebug;
|
|
createDebug.coerce = coerce;
|
|
createDebug.disable = disable;
|
|
createDebug.enable = enable;
|
|
createDebug.enabled = enabled;
|
|
createDebug.humanize = requireMs();
|
|
createDebug.destroy = destroy;
|
|
|
|
Object.keys(env).forEach(key => {
|
|
createDebug[key] = env[key];
|
|
});
|
|
|
|
/**
|
|
* The currently active debug mode names, and names to skip.
|
|
*/
|
|
|
|
createDebug.names = [];
|
|
createDebug.skips = [];
|
|
|
|
/**
|
|
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
*
|
|
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
*/
|
|
createDebug.formatters = {};
|
|
|
|
/**
|
|
* Selects a color for a debug namespace
|
|
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
* @return {Number|String} An ANSI color code for the given namespace
|
|
* @api private
|
|
*/
|
|
function selectColor(namespace) {
|
|
let hash = 0;
|
|
|
|
for (let i = 0; i < namespace.length; i++) {
|
|
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
hash |= 0; // Convert to 32bit integer
|
|
}
|
|
|
|
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
}
|
|
createDebug.selectColor = selectColor;
|
|
|
|
/**
|
|
* Create a debugger with the given `namespace`.
|
|
*
|
|
* @param {String} namespace
|
|
* @return {Function}
|
|
* @api public
|
|
*/
|
|
function createDebug(namespace) {
|
|
let prevTime;
|
|
let enableOverride = null;
|
|
let namespacesCache;
|
|
let enabledCache;
|
|
|
|
function debug(...args) {
|
|
// Disabled?
|
|
if (!debug.enabled) {
|
|
return;
|
|
}
|
|
|
|
const self = debug;
|
|
|
|
// Set `diff` timestamp
|
|
const curr = Number(new Date());
|
|
const ms = curr - (prevTime || curr);
|
|
self.diff = ms;
|
|
self.prev = prevTime;
|
|
self.curr = curr;
|
|
prevTime = curr;
|
|
|
|
args[0] = createDebug.coerce(args[0]);
|
|
|
|
if (typeof args[0] !== 'string') {
|
|
// Anything else let's inspect with %O
|
|
args.unshift('%O');
|
|
}
|
|
|
|
// Apply any `formatters` transformations
|
|
let index = 0;
|
|
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
// If we encounter an escaped % then don't increase the array index
|
|
if (match === '%%') {
|
|
return '%';
|
|
}
|
|
index++;
|
|
const formatter = createDebug.formatters[format];
|
|
if (typeof formatter === 'function') {
|
|
const val = args[index];
|
|
match = formatter.call(self, val);
|
|
|
|
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
args.splice(index, 1);
|
|
index--;
|
|
}
|
|
return match;
|
|
});
|
|
|
|
// Apply env-specific formatting (colors, etc.)
|
|
createDebug.formatArgs.call(self, args);
|
|
|
|
const logFn = self.log || createDebug.log;
|
|
logFn.apply(self, args);
|
|
}
|
|
|
|
debug.namespace = namespace;
|
|
debug.useColors = createDebug.useColors();
|
|
debug.color = createDebug.selectColor(namespace);
|
|
debug.extend = extend;
|
|
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
|
|
Object.defineProperty(debug, 'enabled', {
|
|
enumerable: true,
|
|
configurable: false,
|
|
get: () => {
|
|
if (enableOverride !== null) {
|
|
return enableOverride;
|
|
}
|
|
if (namespacesCache !== createDebug.namespaces) {
|
|
namespacesCache = createDebug.namespaces;
|
|
enabledCache = createDebug.enabled(namespace);
|
|
}
|
|
|
|
return enabledCache;
|
|
},
|
|
set: v => {
|
|
enableOverride = v;
|
|
}
|
|
});
|
|
|
|
// Env-specific initialization logic for debug instances
|
|
if (typeof createDebug.init === 'function') {
|
|
createDebug.init(debug);
|
|
}
|
|
|
|
return debug;
|
|
}
|
|
|
|
function extend(namespace, delimiter) {
|
|
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
newDebug.log = this.log;
|
|
return newDebug;
|
|
}
|
|
|
|
/**
|
|
* Enables a debug mode by namespaces. This can include modes
|
|
* separated by a colon and wildcards.
|
|
*
|
|
* @param {String} namespaces
|
|
* @api public
|
|
*/
|
|
function enable(namespaces) {
|
|
createDebug.save(namespaces);
|
|
createDebug.namespaces = namespaces;
|
|
|
|
createDebug.names = [];
|
|
createDebug.skips = [];
|
|
|
|
let i;
|
|
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
const len = split.length;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
if (!split[i]) {
|
|
// ignore empty strings
|
|
continue;
|
|
}
|
|
|
|
namespaces = split[i].replace(/\*/g, '.*?');
|
|
|
|
if (namespaces[0] === '-') {
|
|
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
|
} else {
|
|
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Disable debug output.
|
|
*
|
|
* @return {String} namespaces
|
|
* @api public
|
|
*/
|
|
function disable() {
|
|
const namespaces = [
|
|
...createDebug.names.map(toNamespace),
|
|
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
].join(',');
|
|
createDebug.enable('');
|
|
return namespaces;
|
|
}
|
|
|
|
/**
|
|
* Returns true if the given mode name is enabled, false otherwise.
|
|
*
|
|
* @param {String} name
|
|
* @return {Boolean}
|
|
* @api public
|
|
*/
|
|
function enabled(name) {
|
|
if (name[name.length - 1] === '*') {
|
|
return true;
|
|
}
|
|
|
|
let i;
|
|
let len;
|
|
|
|
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
if (createDebug.skips[i].test(name)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
if (createDebug.names[i].test(name)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Convert regexp to namespace
|
|
*
|
|
* @param {RegExp} regxep
|
|
* @return {String} namespace
|
|
* @api private
|
|
*/
|
|
function toNamespace(regexp) {
|
|
return regexp.toString()
|
|
.substring(2, regexp.toString().length - 2)
|
|
.replace(/\.\*\?$/, '*');
|
|
}
|
|
|
|
/**
|
|
* Coerce `val`.
|
|
*
|
|
* @param {Mixed} val
|
|
* @return {Mixed}
|
|
* @api private
|
|
*/
|
|
function coerce(val) {
|
|
if (val instanceof Error) {
|
|
return val.stack || val.message;
|
|
}
|
|
return val;
|
|
}
|
|
|
|
/**
|
|
* XXX DO NOT USE. This is a temporary stub function.
|
|
* XXX It WILL be removed in the next major release.
|
|
*/
|
|
function destroy() {
|
|
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
}
|
|
|
|
createDebug.enable(createDebug.load());
|
|
|
|
return createDebug;
|
|
}
|
|
|
|
var common = setup;
|
|
|
|
/* eslint-env browser */
|
|
browser.exports;
|
|
|
|
(function (module, exports) {
|
|
/**
|
|
* This is the web browser implementation of `debug()`.
|
|
*/
|
|
|
|
exports.formatArgs = formatArgs;
|
|
exports.save = save;
|
|
exports.load = load;
|
|
exports.useColors = useColors;
|
|
exports.storage = localstorage();
|
|
exports.destroy = (() => {
|
|
let warned = false;
|
|
|
|
return () => {
|
|
if (!warned) {
|
|
warned = true;
|
|
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
}
|
|
};
|
|
})();
|
|
|
|
/**
|
|
* Colors.
|
|
*/
|
|
|
|
exports.colors = [
|
|
'#0000CC',
|
|
'#0000FF',
|
|
'#0033CC',
|
|
'#0033FF',
|
|
'#0066CC',
|
|
'#0066FF',
|
|
'#0099CC',
|
|
'#0099FF',
|
|
'#00CC00',
|
|
'#00CC33',
|
|
'#00CC66',
|
|
'#00CC99',
|
|
'#00CCCC',
|
|
'#00CCFF',
|
|
'#3300CC',
|
|
'#3300FF',
|
|
'#3333CC',
|
|
'#3333FF',
|
|
'#3366CC',
|
|
'#3366FF',
|
|
'#3399CC',
|
|
'#3399FF',
|
|
'#33CC00',
|
|
'#33CC33',
|
|
'#33CC66',
|
|
'#33CC99',
|
|
'#33CCCC',
|
|
'#33CCFF',
|
|
'#6600CC',
|
|
'#6600FF',
|
|
'#6633CC',
|
|
'#6633FF',
|
|
'#66CC00',
|
|
'#66CC33',
|
|
'#9900CC',
|
|
'#9900FF',
|
|
'#9933CC',
|
|
'#9933FF',
|
|
'#99CC00',
|
|
'#99CC33',
|
|
'#CC0000',
|
|
'#CC0033',
|
|
'#CC0066',
|
|
'#CC0099',
|
|
'#CC00CC',
|
|
'#CC00FF',
|
|
'#CC3300',
|
|
'#CC3333',
|
|
'#CC3366',
|
|
'#CC3399',
|
|
'#CC33CC',
|
|
'#CC33FF',
|
|
'#CC6600',
|
|
'#CC6633',
|
|
'#CC9900',
|
|
'#CC9933',
|
|
'#CCCC00',
|
|
'#CCCC33',
|
|
'#FF0000',
|
|
'#FF0033',
|
|
'#FF0066',
|
|
'#FF0099',
|
|
'#FF00CC',
|
|
'#FF00FF',
|
|
'#FF3300',
|
|
'#FF3333',
|
|
'#FF3366',
|
|
'#FF3399',
|
|
'#FF33CC',
|
|
'#FF33FF',
|
|
'#FF6600',
|
|
'#FF6633',
|
|
'#FF9900',
|
|
'#FF9933',
|
|
'#FFCC00',
|
|
'#FFCC33'
|
|
];
|
|
|
|
/**
|
|
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
* and the Firebug extension (any Firefox version) are known
|
|
* to support "%c" CSS customizations.
|
|
*
|
|
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
*/
|
|
|
|
// eslint-disable-next-line complexity
|
|
function useColors() {
|
|
// NB: In an Electron preload script, document will be defined but not fully
|
|
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
// explicitly
|
|
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
return true;
|
|
}
|
|
|
|
// Internet Explorer and Edge do not support colors.
|
|
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
return false;
|
|
}
|
|
|
|
let m;
|
|
|
|
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
// Is firefox >= v31?
|
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
(typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
|
|
// Double check webkit in userAgent just in case we are in a worker
|
|
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
}
|
|
|
|
/**
|
|
* Colorize log arguments if enabled.
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
function formatArgs(args) {
|
|
args[0] = (this.useColors ? '%c' : '') +
|
|
this.namespace +
|
|
(this.useColors ? ' %c' : ' ') +
|
|
args[0] +
|
|
(this.useColors ? '%c ' : ' ') +
|
|
'+' + module.exports.humanize(this.diff);
|
|
|
|
if (!this.useColors) {
|
|
return;
|
|
}
|
|
|
|
const c = 'color: ' + this.color;
|
|
args.splice(1, 0, c, 'color: inherit');
|
|
|
|
// The final "%c" is somewhat tricky, because there could be other
|
|
// arguments passed either before or after the %c, so we need to
|
|
// figure out the correct index to insert the CSS into
|
|
let index = 0;
|
|
let lastC = 0;
|
|
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
if (match === '%%') {
|
|
return;
|
|
}
|
|
index++;
|
|
if (match === '%c') {
|
|
// We only are interested in the *last* %c
|
|
// (the user may have provided their own)
|
|
lastC = index;
|
|
}
|
|
});
|
|
|
|
args.splice(lastC, 0, c);
|
|
}
|
|
|
|
/**
|
|
* Invokes `console.debug()` when available.
|
|
* No-op when `console.debug` is not a "function".
|
|
* If `console.debug` is not available, falls back
|
|
* to `console.log`.
|
|
*
|
|
* @api public
|
|
*/
|
|
exports.log = console.debug || console.log || (() => {});
|
|
|
|
/**
|
|
* Save `namespaces`.
|
|
*
|
|
* @param {String} namespaces
|
|
* @api private
|
|
*/
|
|
function save(namespaces) {
|
|
try {
|
|
if (namespaces) {
|
|
exports.storage.setItem('debug', namespaces);
|
|
} else {
|
|
exports.storage.removeItem('debug');
|
|
}
|
|
} catch (error) {
|
|
// Swallow
|
|
// XXX (@Qix-) should we be logging these?
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Load `namespaces`.
|
|
*
|
|
* @return {String} returns the previously persisted debug modes
|
|
* @api private
|
|
*/
|
|
function load() {
|
|
let r;
|
|
try {
|
|
r = exports.storage.getItem('debug');
|
|
} catch (error) {
|
|
// Swallow
|
|
// XXX (@Qix-) should we be logging these?
|
|
}
|
|
|
|
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
r = process.env.DEBUG;
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
/**
|
|
* Localstorage attempts to return the localstorage.
|
|
*
|
|
* This is necessary because safari throws
|
|
* when a user disables cookies/localstorage
|
|
* and you attempt to access it.
|
|
*
|
|
* @return {LocalStorage}
|
|
* @api private
|
|
*/
|
|
|
|
function localstorage() {
|
|
try {
|
|
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
// The Browser also has localStorage in the global context.
|
|
return localStorage;
|
|
} catch (error) {
|
|
// Swallow
|
|
// XXX (@Qix-) should we be logging these?
|
|
}
|
|
}
|
|
|
|
module.exports = common(exports);
|
|
|
|
const {formatters} = module.exports;
|
|
|
|
/**
|
|
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
*/
|
|
|
|
formatters.j = function (v) {
|
|
try {
|
|
return JSON.stringify(v);
|
|
} catch (error) {
|
|
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
}
|
|
};
|
|
} (browser, browser.exports));
|
|
|
|
var browserExports = browser.exports;
|
|
|
|
var __importDefault$8 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(transport, "__esModule", { value: true });
|
|
transport.Transport = transport.TransportError = void 0;
|
|
const engine_io_parser_1$4 = cjs$1;
|
|
const component_emitter_1$4 = require$$5;
|
|
const util_js_1$4 = util;
|
|
const parseqs_js_1$1 = parseqs;
|
|
const debug_1$8 = __importDefault$8(browserExports); // debug()
|
|
const debug$8 = (0, debug_1$8.default)("engine.io-client:transport"); // debug()
|
|
class TransportError extends Error {
|
|
constructor(reason, description, context) {
|
|
super(reason);
|
|
this.description = description;
|
|
this.context = context;
|
|
this.type = "TransportError";
|
|
}
|
|
}
|
|
transport.TransportError = TransportError;
|
|
class Transport extends component_emitter_1$4.Emitter {
|
|
/**
|
|
* Transport abstract constructor.
|
|
*
|
|
* @param {Object} opts - options
|
|
* @protected
|
|
*/
|
|
constructor(opts) {
|
|
super();
|
|
this.writable = false;
|
|
(0, util_js_1$4.installTimerFunctions)(this, opts);
|
|
this.opts = opts;
|
|
this.query = opts.query;
|
|
this.socket = opts.socket;
|
|
this.supportsBinary = !opts.forceBase64;
|
|
}
|
|
/**
|
|
* Emits an error.
|
|
*
|
|
* @param {String} reason
|
|
* @param description
|
|
* @param context - the error context
|
|
* @return {Transport} for chaining
|
|
* @protected
|
|
*/
|
|
onError(reason, description, context) {
|
|
super.emitReserved("error", new TransportError(reason, description, context));
|
|
return this;
|
|
}
|
|
/**
|
|
* Opens the transport.
|
|
*/
|
|
open() {
|
|
this.readyState = "opening";
|
|
this.doOpen();
|
|
return this;
|
|
}
|
|
/**
|
|
* Closes the transport.
|
|
*/
|
|
close() {
|
|
if (this.readyState === "opening" || this.readyState === "open") {
|
|
this.doClose();
|
|
this.onClose();
|
|
}
|
|
return this;
|
|
}
|
|
/**
|
|
* Sends multiple packets.
|
|
*
|
|
* @param {Array} packets
|
|
*/
|
|
send(packets) {
|
|
if (this.readyState === "open") {
|
|
this.write(packets);
|
|
}
|
|
else {
|
|
// this might happen if the transport was silently closed in the beforeunload event handler
|
|
debug$8("transport is not open, discarding packets");
|
|
}
|
|
}
|
|
/**
|
|
* Called upon open
|
|
*
|
|
* @protected
|
|
*/
|
|
onOpen() {
|
|
this.readyState = "open";
|
|
this.writable = true;
|
|
super.emitReserved("open");
|
|
}
|
|
/**
|
|
* Called with data.
|
|
*
|
|
* @param {String} data
|
|
* @protected
|
|
*/
|
|
onData(data) {
|
|
const packet = (0, engine_io_parser_1$4.decodePacket)(data, this.socket.binaryType);
|
|
this.onPacket(packet);
|
|
}
|
|
/**
|
|
* Called with a decoded packet.
|
|
*
|
|
* @protected
|
|
*/
|
|
onPacket(packet) {
|
|
super.emitReserved("packet", packet);
|
|
}
|
|
/**
|
|
* Called upon close.
|
|
*
|
|
* @protected
|
|
*/
|
|
onClose(details) {
|
|
this.readyState = "closed";
|
|
super.emitReserved("close", details);
|
|
}
|
|
/**
|
|
* Pauses the transport, in order not to lose packets during an upgrade.
|
|
*
|
|
* @param onPause
|
|
*/
|
|
pause(onPause) { }
|
|
createUri(schema, query = {}) {
|
|
return (schema +
|
|
"://" +
|
|
this._hostname() +
|
|
this._port() +
|
|
this.opts.path +
|
|
this._query(query));
|
|
}
|
|
_hostname() {
|
|
const hostname = this.opts.hostname;
|
|
return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]";
|
|
}
|
|
_port() {
|
|
if (this.opts.port &&
|
|
((this.opts.secure && Number(this.opts.port !== 443)) ||
|
|
(!this.opts.secure && Number(this.opts.port) !== 80))) {
|
|
return ":" + this.opts.port;
|
|
}
|
|
else {
|
|
return "";
|
|
}
|
|
}
|
|
_query(query) {
|
|
const encodedQuery = (0, parseqs_js_1$1.encode)(query);
|
|
return encodedQuery.length ? "?" + encodedQuery : "";
|
|
}
|
|
}
|
|
transport.Transport = Transport;
|
|
|
|
var __importDefault$7 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(polling, "__esModule", { value: true });
|
|
polling.Polling = void 0;
|
|
const transport_js_1$2 = transport;
|
|
const util_js_1$3 = util;
|
|
const engine_io_parser_1$3 = cjs$1;
|
|
const debug_1$7 = __importDefault$7(browserExports); // debug()
|
|
const debug$7 = (0, debug_1$7.default)("engine.io-client:polling"); // debug()
|
|
class Polling extends transport_js_1$2.Transport {
|
|
constructor() {
|
|
super(...arguments);
|
|
this._polling = false;
|
|
}
|
|
get name() {
|
|
return "polling";
|
|
}
|
|
/**
|
|
* Opens the socket (triggers polling). We write a PING message to determine
|
|
* when the transport is open.
|
|
*
|
|
* @protected
|
|
*/
|
|
doOpen() {
|
|
this._poll();
|
|
}
|
|
/**
|
|
* Pauses polling.
|
|
*
|
|
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
|
* @package
|
|
*/
|
|
pause(onPause) {
|
|
this.readyState = "pausing";
|
|
const pause = () => {
|
|
debug$7("paused");
|
|
this.readyState = "paused";
|
|
onPause();
|
|
};
|
|
if (this._polling || !this.writable) {
|
|
let total = 0;
|
|
if (this._polling) {
|
|
debug$7("we are currently polling - waiting to pause");
|
|
total++;
|
|
this.once("pollComplete", function () {
|
|
debug$7("pre-pause polling complete");
|
|
--total || pause();
|
|
});
|
|
}
|
|
if (!this.writable) {
|
|
debug$7("we are currently writing - waiting to pause");
|
|
total++;
|
|
this.once("drain", function () {
|
|
debug$7("pre-pause writing complete");
|
|
--total || pause();
|
|
});
|
|
}
|
|
}
|
|
else {
|
|
pause();
|
|
}
|
|
}
|
|
/**
|
|
* Starts polling cycle.
|
|
*
|
|
* @private
|
|
*/
|
|
_poll() {
|
|
debug$7("polling");
|
|
this._polling = true;
|
|
this.doPoll();
|
|
this.emitReserved("poll");
|
|
}
|
|
/**
|
|
* Overloads onData to detect payloads.
|
|
*
|
|
* @protected
|
|
*/
|
|
onData(data) {
|
|
debug$7("polling got data %s", data);
|
|
const callback = (packet) => {
|
|
// if its the first message we consider the transport open
|
|
if ("opening" === this.readyState && packet.type === "open") {
|
|
this.onOpen();
|
|
}
|
|
// if its a close packet, we close the ongoing requests
|
|
if ("close" === packet.type) {
|
|
this.onClose({ description: "transport closed by the server" });
|
|
return false;
|
|
}
|
|
// otherwise bypass onData and handle the message
|
|
this.onPacket(packet);
|
|
};
|
|
// decode payload
|
|
(0, engine_io_parser_1$3.decodePayload)(data, this.socket.binaryType).forEach(callback);
|
|
// if an event did not trigger closing
|
|
if ("closed" !== this.readyState) {
|
|
// if we got data we're not polling
|
|
this._polling = false;
|
|
this.emitReserved("pollComplete");
|
|
if ("open" === this.readyState) {
|
|
this._poll();
|
|
}
|
|
else {
|
|
debug$7('ignoring poll - transport state "%s"', this.readyState);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* For polling, send a close packet.
|
|
*
|
|
* @protected
|
|
*/
|
|
doClose() {
|
|
const close = () => {
|
|
debug$7("writing close packet");
|
|
this.write([{ type: "close" }]);
|
|
};
|
|
if ("open" === this.readyState) {
|
|
debug$7("transport open - closing");
|
|
close();
|
|
}
|
|
else {
|
|
// in case we're trying to close while
|
|
// handshaking is in progress (GH-164)
|
|
debug$7("transport not open - deferring close");
|
|
this.once("open", close);
|
|
}
|
|
}
|
|
/**
|
|
* Writes a packets payload.
|
|
*
|
|
* @param {Array} packets - data packets
|
|
* @protected
|
|
*/
|
|
write(packets) {
|
|
this.writable = false;
|
|
(0, engine_io_parser_1$3.encodePayload)(packets, (data) => {
|
|
this.doWrite(data, () => {
|
|
this.writable = true;
|
|
this.emitReserved("drain");
|
|
});
|
|
});
|
|
}
|
|
/**
|
|
* Generates uri for connection.
|
|
*
|
|
* @private
|
|
*/
|
|
uri() {
|
|
const schema = this.opts.secure ? "https" : "http";
|
|
const query = this.query || {};
|
|
// cache busting is forced
|
|
if (false !== this.opts.timestampRequests) {
|
|
query[this.opts.timestampParam] = (0, util_js_1$3.randomString)();
|
|
}
|
|
if (!this.supportsBinary && !query.sid) {
|
|
query.b64 = 1;
|
|
}
|
|
return this.createUri(schema, query);
|
|
}
|
|
}
|
|
polling.Polling = Polling;
|
|
|
|
var hasCors = {};
|
|
|
|
Object.defineProperty(hasCors, "__esModule", { value: true });
|
|
hasCors.hasCORS = void 0;
|
|
// imported from https://github.com/component/has-cors
|
|
let value = false;
|
|
try {
|
|
value = typeof XMLHttpRequest !== 'undefined' &&
|
|
'withCredentials' in new XMLHttpRequest();
|
|
}
|
|
catch (err) {
|
|
// if XMLHttp support is disabled in IE then it will throw
|
|
// when trying to create
|
|
}
|
|
hasCors.hasCORS = value;
|
|
|
|
var __importDefault$6 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(pollingXhr, "__esModule", { value: true });
|
|
pollingXhr.XHR = pollingXhr.Request = pollingXhr.BaseXHR = void 0;
|
|
const polling_js_1$1 = polling;
|
|
const component_emitter_1$3 = require$$5;
|
|
const util_js_1$2 = util;
|
|
const globals_node_js_1$3 = globals;
|
|
const has_cors_js_1 = hasCors;
|
|
const debug_1$6 = __importDefault$6(browserExports); // debug()
|
|
const debug$6 = (0, debug_1$6.default)("engine.io-client:polling"); // debug()
|
|
function empty() { }
|
|
class BaseXHR extends polling_js_1$1.Polling {
|
|
/**
|
|
* XHR Polling constructor.
|
|
*
|
|
* @param {Object} opts
|
|
* @package
|
|
*/
|
|
constructor(opts) {
|
|
super(opts);
|
|
if (typeof location !== "undefined") {
|
|
const isSSL = "https:" === location.protocol;
|
|
let port = location.port;
|
|
// some user agents have empty `location.port`
|
|
if (!port) {
|
|
port = isSSL ? "443" : "80";
|
|
}
|
|
this.xd =
|
|
(typeof location !== "undefined" &&
|
|
opts.hostname !== location.hostname) ||
|
|
port !== opts.port;
|
|
}
|
|
}
|
|
/**
|
|
* Sends data.
|
|
*
|
|
* @param {String} data to send.
|
|
* @param {Function} called upon flush.
|
|
* @private
|
|
*/
|
|
doWrite(data, fn) {
|
|
const req = this.request({
|
|
method: "POST",
|
|
data: data,
|
|
});
|
|
req.on("success", fn);
|
|
req.on("error", (xhrStatus, context) => {
|
|
this.onError("xhr post error", xhrStatus, context);
|
|
});
|
|
}
|
|
/**
|
|
* Starts a poll cycle.
|
|
*
|
|
* @private
|
|
*/
|
|
doPoll() {
|
|
debug$6("xhr poll");
|
|
const req = this.request();
|
|
req.on("data", this.onData.bind(this));
|
|
req.on("error", (xhrStatus, context) => {
|
|
this.onError("xhr poll error", xhrStatus, context);
|
|
});
|
|
this.pollXhr = req;
|
|
}
|
|
}
|
|
pollingXhr.BaseXHR = BaseXHR;
|
|
class Request extends component_emitter_1$3.Emitter {
|
|
/**
|
|
* Request constructor
|
|
*
|
|
* @param {Object} options
|
|
* @package
|
|
*/
|
|
constructor(createRequest, uri, opts) {
|
|
super();
|
|
this.createRequest = createRequest;
|
|
(0, util_js_1$2.installTimerFunctions)(this, opts);
|
|
this._opts = opts;
|
|
this._method = opts.method || "GET";
|
|
this._uri = uri;
|
|
this._data = undefined !== opts.data ? opts.data : null;
|
|
this._create();
|
|
}
|
|
/**
|
|
* Creates the XHR object and sends the request.
|
|
*
|
|
* @private
|
|
*/
|
|
_create() {
|
|
var _a;
|
|
const opts = (0, util_js_1$2.pick)(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
opts.xdomain = !!this._opts.xd;
|
|
const xhr = (this._xhr = this.createRequest(opts));
|
|
try {
|
|
debug$6("xhr open %s: %s", this._method, this._uri);
|
|
xhr.open(this._method, this._uri, true);
|
|
try {
|
|
if (this._opts.extraHeaders) {
|
|
// @ts-ignore
|
|
xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
|
|
for (let i in this._opts.extraHeaders) {
|
|
if (this._opts.extraHeaders.hasOwnProperty(i)) {
|
|
xhr.setRequestHeader(i, this._opts.extraHeaders[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (e) { }
|
|
if ("POST" === this._method) {
|
|
try {
|
|
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
}
|
|
catch (e) { }
|
|
}
|
|
try {
|
|
xhr.setRequestHeader("Accept", "*/*");
|
|
}
|
|
catch (e) { }
|
|
(_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
|
|
// ie6 check
|
|
if ("withCredentials" in xhr) {
|
|
xhr.withCredentials = this._opts.withCredentials;
|
|
}
|
|
if (this._opts.requestTimeout) {
|
|
xhr.timeout = this._opts.requestTimeout;
|
|
}
|
|
xhr.onreadystatechange = () => {
|
|
var _a;
|
|
if (xhr.readyState === 3) {
|
|
(_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(
|
|
// @ts-ignore
|
|
xhr.getResponseHeader("set-cookie"));
|
|
}
|
|
if (4 !== xhr.readyState)
|
|
return;
|
|
if (200 === xhr.status || 1223 === xhr.status) {
|
|
this._onLoad();
|
|
}
|
|
else {
|
|
// make sure the `error` event handler that's user-set
|
|
// does not throw in the same tick and gets caught here
|
|
this.setTimeoutFn(() => {
|
|
this._onError(typeof xhr.status === "number" ? xhr.status : 0);
|
|
}, 0);
|
|
}
|
|
};
|
|
debug$6("xhr data %s", this._data);
|
|
xhr.send(this._data);
|
|
}
|
|
catch (e) {
|
|
// Need to defer since .create() is called directly from the constructor
|
|
// and thus the 'error' event can only be only bound *after* this exception
|
|
// occurs. Therefore, also, we cannot throw here at all.
|
|
this.setTimeoutFn(() => {
|
|
this._onError(e);
|
|
}, 0);
|
|
return;
|
|
}
|
|
if (typeof document !== "undefined") {
|
|
this._index = Request.requestsCount++;
|
|
Request.requests[this._index] = this;
|
|
}
|
|
}
|
|
/**
|
|
* Called upon error.
|
|
*
|
|
* @private
|
|
*/
|
|
_onError(err) {
|
|
this.emitReserved("error", err, this._xhr);
|
|
this._cleanup(true);
|
|
}
|
|
/**
|
|
* Cleans up house.
|
|
*
|
|
* @private
|
|
*/
|
|
_cleanup(fromError) {
|
|
if ("undefined" === typeof this._xhr || null === this._xhr) {
|
|
return;
|
|
}
|
|
this._xhr.onreadystatechange = empty;
|
|
if (fromError) {
|
|
try {
|
|
this._xhr.abort();
|
|
}
|
|
catch (e) { }
|
|
}
|
|
if (typeof document !== "undefined") {
|
|
delete Request.requests[this._index];
|
|
}
|
|
this._xhr = null;
|
|
}
|
|
/**
|
|
* Called upon load.
|
|
*
|
|
* @private
|
|
*/
|
|
_onLoad() {
|
|
const data = this._xhr.responseText;
|
|
if (data !== null) {
|
|
this.emitReserved("data", data);
|
|
this.emitReserved("success");
|
|
this._cleanup();
|
|
}
|
|
}
|
|
/**
|
|
* Aborts the request.
|
|
*
|
|
* @package
|
|
*/
|
|
abort() {
|
|
this._cleanup();
|
|
}
|
|
}
|
|
pollingXhr.Request = Request;
|
|
Request.requestsCount = 0;
|
|
Request.requests = {};
|
|
/**
|
|
* Aborts pending requests when unloading the window. This is needed to prevent
|
|
* memory leaks (e.g. when using IE) and to ensure that no spurious error is
|
|
* emitted.
|
|
*/
|
|
if (typeof document !== "undefined") {
|
|
// @ts-ignore
|
|
if (typeof attachEvent === "function") {
|
|
// @ts-ignore
|
|
attachEvent("onunload", unloadHandler);
|
|
}
|
|
else if (typeof addEventListener === "function") {
|
|
const terminationEvent = "onpagehide" in globals_node_js_1$3.globalThisShim ? "pagehide" : "unload";
|
|
addEventListener(terminationEvent, unloadHandler, false);
|
|
}
|
|
}
|
|
function unloadHandler() {
|
|
for (let i in Request.requests) {
|
|
if (Request.requests.hasOwnProperty(i)) {
|
|
Request.requests[i].abort();
|
|
}
|
|
}
|
|
}
|
|
const hasXHR2 = (function () {
|
|
const xhr = newRequest({
|
|
xdomain: false,
|
|
});
|
|
return xhr && xhr.responseType !== null;
|
|
})();
|
|
/**
|
|
* HTTP long-polling based on the built-in `XMLHttpRequest` object.
|
|
*
|
|
* Usage: browser
|
|
*
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
|
|
*/
|
|
class XHR extends BaseXHR {
|
|
constructor(opts) {
|
|
super(opts);
|
|
const forceBase64 = opts && opts.forceBase64;
|
|
this.supportsBinary = hasXHR2 && !forceBase64;
|
|
}
|
|
request(opts = {}) {
|
|
Object.assign(opts, { xd: this.xd }, this.opts);
|
|
return new Request(newRequest, this.uri(), opts);
|
|
}
|
|
}
|
|
pollingXhr.XHR = XHR;
|
|
function newRequest(opts) {
|
|
const xdomain = opts.xdomain;
|
|
// XMLHttpRequest can be disabled on IE
|
|
try {
|
|
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || has_cors_js_1.hasCORS)) {
|
|
return new XMLHttpRequest();
|
|
}
|
|
}
|
|
catch (e) { }
|
|
if (!xdomain) {
|
|
try {
|
|
return new globals_node_js_1$3.globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
}
|
|
catch (e) { }
|
|
}
|
|
}
|
|
|
|
var websocket = {};
|
|
|
|
var __importDefault$5 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(websocket, "__esModule", { value: true });
|
|
websocket.WS = websocket.BaseWS = void 0;
|
|
const transport_js_1$1 = transport;
|
|
const util_js_1$1 = util;
|
|
const engine_io_parser_1$2 = cjs$1;
|
|
const globals_node_js_1$2 = globals;
|
|
const debug_1$5 = __importDefault$5(browserExports); // debug()
|
|
const debug$5 = (0, debug_1$5.default)("engine.io-client:websocket"); // debug()
|
|
// detect ReactNative environment
|
|
const isReactNative = typeof navigator !== "undefined" &&
|
|
typeof navigator.product === "string" &&
|
|
navigator.product.toLowerCase() === "reactnative";
|
|
class BaseWS extends transport_js_1$1.Transport {
|
|
get name() {
|
|
return "websocket";
|
|
}
|
|
doOpen() {
|
|
const uri = this.uri();
|
|
const protocols = this.opts.protocols;
|
|
// React Native only supports the 'headers' option, and will print a warning if anything else is passed
|
|
const opts = isReactNative
|
|
? {}
|
|
: (0, util_js_1$1.pick)(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
if (this.opts.extraHeaders) {
|
|
opts.headers = this.opts.extraHeaders;
|
|
}
|
|
try {
|
|
this.ws = this.createSocket(uri, protocols, opts);
|
|
}
|
|
catch (err) {
|
|
return this.emitReserved("error", err);
|
|
}
|
|
this.ws.binaryType = this.socket.binaryType;
|
|
this.addEventListeners();
|
|
}
|
|
/**
|
|
* Adds event listeners to the socket
|
|
*
|
|
* @private
|
|
*/
|
|
addEventListeners() {
|
|
this.ws.onopen = () => {
|
|
if (this.opts.autoUnref) {
|
|
this.ws._socket.unref();
|
|
}
|
|
this.onOpen();
|
|
};
|
|
this.ws.onclose = (closeEvent) => this.onClose({
|
|
description: "websocket connection closed",
|
|
context: closeEvent,
|
|
});
|
|
this.ws.onmessage = (ev) => this.onData(ev.data);
|
|
this.ws.onerror = (e) => this.onError("websocket error", e);
|
|
}
|
|
write(packets) {
|
|
this.writable = false;
|
|
// encodePacket efficient as it uses WS framing
|
|
// no need for encodePayload
|
|
for (let i = 0; i < packets.length; i++) {
|
|
const packet = packets[i];
|
|
const lastPacket = i === packets.length - 1;
|
|
(0, engine_io_parser_1$2.encodePacket)(packet, this.supportsBinary, (data) => {
|
|
// Sometimes the websocket has already been closed but the browser didn't
|
|
// have a chance of informing us about it yet, in that case send will
|
|
// throw an error
|
|
try {
|
|
this.doWrite(packet, data);
|
|
}
|
|
catch (e) {
|
|
debug$5("websocket closed before onclose event");
|
|
}
|
|
if (lastPacket) {
|
|
// fake drain
|
|
// defer to next tick to allow Socket to clear writeBuffer
|
|
(0, globals_node_js_1$2.nextTick)(() => {
|
|
this.writable = true;
|
|
this.emitReserved("drain");
|
|
}, this.setTimeoutFn);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
doClose() {
|
|
if (typeof this.ws !== "undefined") {
|
|
this.ws.onerror = () => { };
|
|
this.ws.close();
|
|
this.ws = null;
|
|
}
|
|
}
|
|
/**
|
|
* Generates uri for connection.
|
|
*
|
|
* @private
|
|
*/
|
|
uri() {
|
|
const schema = this.opts.secure ? "wss" : "ws";
|
|
const query = this.query || {};
|
|
// append timestamp to URI
|
|
if (this.opts.timestampRequests) {
|
|
query[this.opts.timestampParam] = (0, util_js_1$1.randomString)();
|
|
}
|
|
// communicate binary support capabilities
|
|
if (!this.supportsBinary) {
|
|
query.b64 = 1;
|
|
}
|
|
return this.createUri(schema, query);
|
|
}
|
|
}
|
|
websocket.BaseWS = BaseWS;
|
|
const WebSocketCtor = globals_node_js_1$2.globalThisShim.WebSocket || globals_node_js_1$2.globalThisShim.MozWebSocket;
|
|
/**
|
|
* WebSocket transport based on the built-in `WebSocket` object.
|
|
*
|
|
* Usage: browser, Node.js (since v21), Deno, Bun
|
|
*
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
|
* @see https://caniuse.com/mdn-api_websocket
|
|
* @see https://nodejs.org/api/globals.html#websocket
|
|
*/
|
|
class WS extends BaseWS {
|
|
createSocket(uri, protocols, opts) {
|
|
return !isReactNative
|
|
? protocols
|
|
? new WebSocketCtor(uri, protocols)
|
|
: new WebSocketCtor(uri)
|
|
: new WebSocketCtor(uri, protocols, opts);
|
|
}
|
|
doWrite(_packet, data) {
|
|
this.ws.send(data);
|
|
}
|
|
}
|
|
websocket.WS = WS;
|
|
|
|
var webtransport = {};
|
|
|
|
var __importDefault$4 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(webtransport, "__esModule", { value: true });
|
|
webtransport.WT = void 0;
|
|
const transport_js_1 = transport;
|
|
const globals_node_js_1$1 = globals;
|
|
const engine_io_parser_1$1 = cjs$1;
|
|
const debug_1$4 = __importDefault$4(browserExports); // debug()
|
|
const debug$4 = (0, debug_1$4.default)("engine.io-client:webtransport"); // debug()
|
|
/**
|
|
* WebTransport transport based on the built-in `WebTransport` object.
|
|
*
|
|
* Usage: browser, Node.js (with the `@fails-components/webtransport` package)
|
|
*
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
|
|
* @see https://caniuse.com/webtransport
|
|
*/
|
|
class WT extends transport_js_1.Transport {
|
|
get name() {
|
|
return "webtransport";
|
|
}
|
|
doOpen() {
|
|
try {
|
|
// @ts-ignore
|
|
this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
|
|
}
|
|
catch (err) {
|
|
return this.emitReserved("error", err);
|
|
}
|
|
this._transport.closed
|
|
.then(() => {
|
|
debug$4("transport closed gracefully");
|
|
this.onClose();
|
|
})
|
|
.catch((err) => {
|
|
debug$4("transport closed due to %s", err);
|
|
this.onError("webtransport error", err);
|
|
});
|
|
// note: we could have used async/await, but that would require some additional polyfills
|
|
this._transport.ready.then(() => {
|
|
this._transport.createBidirectionalStream().then((stream) => {
|
|
const decoderStream = (0, engine_io_parser_1$1.createPacketDecoderStream)(Number.MAX_SAFE_INTEGER, this.socket.binaryType);
|
|
const reader = stream.readable.pipeThrough(decoderStream).getReader();
|
|
const encoderStream = (0, engine_io_parser_1$1.createPacketEncoderStream)();
|
|
encoderStream.readable.pipeTo(stream.writable);
|
|
this._writer = encoderStream.writable.getWriter();
|
|
const read = () => {
|
|
reader
|
|
.read()
|
|
.then(({ done, value }) => {
|
|
if (done) {
|
|
debug$4("session is closed");
|
|
return;
|
|
}
|
|
debug$4("received chunk: %o", value);
|
|
this.onPacket(value);
|
|
read();
|
|
})
|
|
.catch((err) => {
|
|
debug$4("an error occurred while reading: %s", err);
|
|
});
|
|
};
|
|
read();
|
|
const packet = { type: "open" };
|
|
if (this.query.sid) {
|
|
packet.data = `{"sid":"${this.query.sid}"}`;
|
|
}
|
|
this._writer.write(packet).then(() => this.onOpen());
|
|
});
|
|
});
|
|
}
|
|
write(packets) {
|
|
this.writable = false;
|
|
for (let i = 0; i < packets.length; i++) {
|
|
const packet = packets[i];
|
|
const lastPacket = i === packets.length - 1;
|
|
this._writer.write(packet).then(() => {
|
|
if (lastPacket) {
|
|
(0, globals_node_js_1$1.nextTick)(() => {
|
|
this.writable = true;
|
|
this.emitReserved("drain");
|
|
}, this.setTimeoutFn);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
doClose() {
|
|
var _a;
|
|
(_a = this._transport) === null || _a === void 0 ? void 0 : _a.close();
|
|
}
|
|
}
|
|
webtransport.WT = WT;
|
|
|
|
Object.defineProperty(transports, "__esModule", { value: true });
|
|
transports.transports = void 0;
|
|
const polling_xhr_node_js_1 = pollingXhr;
|
|
const websocket_node_js_1 = websocket;
|
|
const webtransport_js_1 = webtransport;
|
|
transports.transports = {
|
|
websocket: websocket_node_js_1.WS,
|
|
webtransport: webtransport_js_1.WT,
|
|
polling: polling_xhr_node_js_1.XHR,
|
|
};
|
|
|
|
var parseuri = {};
|
|
|
|
Object.defineProperty(parseuri, "__esModule", { value: true });
|
|
parseuri.parse = parse;
|
|
// imported from https://github.com/galkn/parseuri
|
|
/**
|
|
* Parses a URI
|
|
*
|
|
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms.
|
|
*
|
|
* See:
|
|
* - https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
* - https://caniuse.com/url
|
|
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B
|
|
*
|
|
* History of the parse() method:
|
|
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c
|
|
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3
|
|
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242
|
|
*
|
|
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
|
* @api private
|
|
*/
|
|
const re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
const parts = [
|
|
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
|
|
];
|
|
function parse(str) {
|
|
if (str.length > 8000) {
|
|
throw "URI too long";
|
|
}
|
|
const src = str, b = str.indexOf('['), e = str.indexOf(']');
|
|
if (b != -1 && e != -1) {
|
|
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
|
|
}
|
|
let m = re.exec(str || ''), uri = {}, i = 14;
|
|
while (i--) {
|
|
uri[parts[i]] = m[i] || '';
|
|
}
|
|
if (b != -1 && e != -1) {
|
|
uri.source = src;
|
|
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
|
|
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
|
|
uri.ipv6uri = true;
|
|
}
|
|
uri.pathNames = pathNames(uri, uri['path']);
|
|
uri.queryKey = queryKey(uri, uri['query']);
|
|
return uri;
|
|
}
|
|
function pathNames(obj, path) {
|
|
const regx = /\/{2,9}/g, names = path.replace(regx, "/").split("/");
|
|
if (path.slice(0, 1) == '/' || path.length === 0) {
|
|
names.splice(0, 1);
|
|
}
|
|
if (path.slice(-1) == '/') {
|
|
names.splice(names.length - 1, 1);
|
|
}
|
|
return names;
|
|
}
|
|
function queryKey(uri, query) {
|
|
const data = {};
|
|
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
|
|
if ($1) {
|
|
data[$1] = $2;
|
|
}
|
|
});
|
|
return data;
|
|
}
|
|
|
|
var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(socket$2, "__esModule", { value: true });
|
|
socket$2.Socket = socket$2.SocketWithUpgrade = socket$2.SocketWithoutUpgrade = void 0;
|
|
const index_js_1 = transports;
|
|
const util_js_1 = util;
|
|
const parseqs_js_1 = parseqs;
|
|
const parseuri_js_1 = parseuri;
|
|
const component_emitter_1$2 = require$$5;
|
|
const engine_io_parser_1 = cjs$1;
|
|
const globals_node_js_1 = globals;
|
|
const debug_1$3 = __importDefault$3(browserExports); // debug()
|
|
const debug$3 = (0, debug_1$3.default)("engine.io-client:socket"); // debug()
|
|
const withEventListeners = typeof addEventListener === "function" &&
|
|
typeof removeEventListener === "function";
|
|
const OFFLINE_EVENT_LISTENERS = [];
|
|
if (withEventListeners) {
|
|
// within a ServiceWorker, any event handler for the 'offline' event must be added on the initial evaluation of the
|
|
// script, so we create one single event listener here which will forward the event to the socket instances
|
|
addEventListener("offline", () => {
|
|
debug$3("closing %d connection(s) because the network was lost", OFFLINE_EVENT_LISTENERS.length);
|
|
OFFLINE_EVENT_LISTENERS.forEach((listener) => listener());
|
|
}, false);
|
|
}
|
|
/**
|
|
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
*
|
|
* This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
|
|
* successfully establishes the connection.
|
|
*
|
|
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
*
|
|
* @example
|
|
* import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
|
|
*
|
|
* const socket = new SocketWithoutUpgrade({
|
|
* transports: [WebSocket]
|
|
* });
|
|
*
|
|
* socket.on("open", () => {
|
|
* socket.send("hello");
|
|
* });
|
|
*
|
|
* @see SocketWithUpgrade
|
|
* @see Socket
|
|
*/
|
|
class SocketWithoutUpgrade extends component_emitter_1$2.Emitter {
|
|
/**
|
|
* Socket constructor.
|
|
*
|
|
* @param {String|Object} uri - uri or options
|
|
* @param {Object} opts - options
|
|
*/
|
|
constructor(uri, opts) {
|
|
super();
|
|
this.binaryType = globals_node_js_1.defaultBinaryType;
|
|
this.writeBuffer = [];
|
|
this._prevBufferLen = 0;
|
|
this._pingInterval = -1;
|
|
this._pingTimeout = -1;
|
|
this._maxPayload = -1;
|
|
/**
|
|
* The expiration timestamp of the {@link _pingTimeoutTimer} object is tracked, in case the timer is throttled and the
|
|
* callback is not fired on time. This can happen for example when a laptop is suspended or when a phone is locked.
|
|
*/
|
|
this._pingTimeoutTime = Infinity;
|
|
if (uri && "object" === typeof uri) {
|
|
opts = uri;
|
|
uri = null;
|
|
}
|
|
if (uri) {
|
|
const parsedUri = (0, parseuri_js_1.parse)(uri);
|
|
opts.hostname = parsedUri.host;
|
|
opts.secure =
|
|
parsedUri.protocol === "https" || parsedUri.protocol === "wss";
|
|
opts.port = parsedUri.port;
|
|
if (parsedUri.query)
|
|
opts.query = parsedUri.query;
|
|
}
|
|
else if (opts.host) {
|
|
opts.hostname = (0, parseuri_js_1.parse)(opts.host).host;
|
|
}
|
|
(0, util_js_1.installTimerFunctions)(this, opts);
|
|
this.secure =
|
|
null != opts.secure
|
|
? opts.secure
|
|
: typeof location !== "undefined" && "https:" === location.protocol;
|
|
if (opts.hostname && !opts.port) {
|
|
// if no port is specified manually, use the protocol default
|
|
opts.port = this.secure ? "443" : "80";
|
|
}
|
|
this.hostname =
|
|
opts.hostname ||
|
|
(typeof location !== "undefined" ? location.hostname : "localhost");
|
|
this.port =
|
|
opts.port ||
|
|
(typeof location !== "undefined" && location.port
|
|
? location.port
|
|
: this.secure
|
|
? "443"
|
|
: "80");
|
|
this.transports = [];
|
|
this._transportsByName = {};
|
|
opts.transports.forEach((t) => {
|
|
const transportName = t.prototype.name;
|
|
this.transports.push(transportName);
|
|
this._transportsByName[transportName] = t;
|
|
});
|
|
this.opts = Object.assign({
|
|
path: "/engine.io",
|
|
agent: false,
|
|
withCredentials: false,
|
|
upgrade: true,
|
|
timestampParam: "t",
|
|
rememberUpgrade: false,
|
|
addTrailingSlash: true,
|
|
rejectUnauthorized: true,
|
|
perMessageDeflate: {
|
|
threshold: 1024,
|
|
},
|
|
transportOptions: {},
|
|
closeOnBeforeunload: false,
|
|
}, opts);
|
|
this.opts.path =
|
|
this.opts.path.replace(/\/$/, "") +
|
|
(this.opts.addTrailingSlash ? "/" : "");
|
|
if (typeof this.opts.query === "string") {
|
|
this.opts.query = (0, parseqs_js_1.decode)(this.opts.query);
|
|
}
|
|
if (withEventListeners) {
|
|
if (this.opts.closeOnBeforeunload) {
|
|
// Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
|
|
// ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
|
|
// closed/reloaded)
|
|
this._beforeunloadEventListener = () => {
|
|
if (this.transport) {
|
|
// silently close the transport
|
|
this.transport.removeAllListeners();
|
|
this.transport.close();
|
|
}
|
|
};
|
|
addEventListener("beforeunload", this._beforeunloadEventListener, false);
|
|
}
|
|
if (this.hostname !== "localhost") {
|
|
debug$3("adding listener for the 'offline' event");
|
|
this._offlineEventListener = () => {
|
|
this._onClose("transport close", {
|
|
description: "network connection lost",
|
|
});
|
|
};
|
|
OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
|
|
}
|
|
}
|
|
if (this.opts.withCredentials) {
|
|
this._cookieJar = (0, globals_node_js_1.createCookieJar)();
|
|
}
|
|
this._open();
|
|
}
|
|
/**
|
|
* Creates transport of the given type.
|
|
*
|
|
* @param {String} name - transport name
|
|
* @return {Transport}
|
|
* @private
|
|
*/
|
|
createTransport(name) {
|
|
debug$3('creating transport "%s"', name);
|
|
const query = Object.assign({}, this.opts.query);
|
|
// append engine.io protocol identifier
|
|
query.EIO = engine_io_parser_1.protocol;
|
|
// transport name
|
|
query.transport = name;
|
|
// session id if we already have one
|
|
if (this.id)
|
|
query.sid = this.id;
|
|
const opts = Object.assign({}, this.opts, {
|
|
query,
|
|
socket: this,
|
|
hostname: this.hostname,
|
|
secure: this.secure,
|
|
port: this.port,
|
|
}, this.opts.transportOptions[name]);
|
|
debug$3("options: %j", opts);
|
|
return new this._transportsByName[name](opts);
|
|
}
|
|
/**
|
|
* Initializes transport to use and starts probe.
|
|
*
|
|
* @private
|
|
*/
|
|
_open() {
|
|
if (this.transports.length === 0) {
|
|
// Emit error on next tick so it can be listened to
|
|
this.setTimeoutFn(() => {
|
|
this.emitReserved("error", "No transports available");
|
|
}, 0);
|
|
return;
|
|
}
|
|
const transportName = this.opts.rememberUpgrade &&
|
|
SocketWithoutUpgrade.priorWebsocketSuccess &&
|
|
this.transports.indexOf("websocket") !== -1
|
|
? "websocket"
|
|
: this.transports[0];
|
|
this.readyState = "opening";
|
|
const transport = this.createTransport(transportName);
|
|
transport.open();
|
|
this.setTransport(transport);
|
|
}
|
|
/**
|
|
* Sets the current transport. Disables the existing one (if any).
|
|
*
|
|
* @private
|
|
*/
|
|
setTransport(transport) {
|
|
debug$3("setting transport %s", transport.name);
|
|
if (this.transport) {
|
|
debug$3("clearing existing transport %s", this.transport.name);
|
|
this.transport.removeAllListeners();
|
|
}
|
|
// set up transport
|
|
this.transport = transport;
|
|
// set up transport listeners
|
|
transport
|
|
.on("drain", this._onDrain.bind(this))
|
|
.on("packet", this._onPacket.bind(this))
|
|
.on("error", this._onError.bind(this))
|
|
.on("close", (reason) => this._onClose("transport close", reason));
|
|
}
|
|
/**
|
|
* Called when connection is deemed open.
|
|
*
|
|
* @private
|
|
*/
|
|
onOpen() {
|
|
debug$3("socket open");
|
|
this.readyState = "open";
|
|
SocketWithoutUpgrade.priorWebsocketSuccess =
|
|
"websocket" === this.transport.name;
|
|
this.emitReserved("open");
|
|
this.flush();
|
|
}
|
|
/**
|
|
* Handles a packet.
|
|
*
|
|
* @private
|
|
*/
|
|
_onPacket(packet) {
|
|
if ("opening" === this.readyState ||
|
|
"open" === this.readyState ||
|
|
"closing" === this.readyState) {
|
|
debug$3('socket receive: type "%s", data "%s"', packet.type, packet.data);
|
|
this.emitReserved("packet", packet);
|
|
// Socket is live - any packet counts
|
|
this.emitReserved("heartbeat");
|
|
switch (packet.type) {
|
|
case "open":
|
|
this.onHandshake(JSON.parse(packet.data));
|
|
break;
|
|
case "ping":
|
|
this._sendPacket("pong");
|
|
this.emitReserved("ping");
|
|
this.emitReserved("pong");
|
|
this._resetPingTimeout();
|
|
break;
|
|
case "error":
|
|
const err = new Error("server error");
|
|
// @ts-ignore
|
|
err.code = packet.data;
|
|
this._onError(err);
|
|
break;
|
|
case "message":
|
|
this.emitReserved("data", packet.data);
|
|
this.emitReserved("message", packet.data);
|
|
break;
|
|
}
|
|
}
|
|
else {
|
|
debug$3('packet received with socket readyState "%s"', this.readyState);
|
|
}
|
|
}
|
|
/**
|
|
* Called upon handshake completion.
|
|
*
|
|
* @param {Object} data - handshake obj
|
|
* @private
|
|
*/
|
|
onHandshake(data) {
|
|
this.emitReserved("handshake", data);
|
|
this.id = data.sid;
|
|
this.transport.query.sid = data.sid;
|
|
this._pingInterval = data.pingInterval;
|
|
this._pingTimeout = data.pingTimeout;
|
|
this._maxPayload = data.maxPayload;
|
|
this.onOpen();
|
|
// In case open handler closes socket
|
|
if ("closed" === this.readyState)
|
|
return;
|
|
this._resetPingTimeout();
|
|
}
|
|
/**
|
|
* Sets and resets ping timeout timer based on server pings.
|
|
*
|
|
* @private
|
|
*/
|
|
_resetPingTimeout() {
|
|
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
const delay = this._pingInterval + this._pingTimeout;
|
|
this._pingTimeoutTime = Date.now() + delay;
|
|
this._pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
this._onClose("ping timeout");
|
|
}, delay);
|
|
if (this.opts.autoUnref) {
|
|
this._pingTimeoutTimer.unref();
|
|
}
|
|
}
|
|
/**
|
|
* Called on `drain` event
|
|
*
|
|
* @private
|
|
*/
|
|
_onDrain() {
|
|
this.writeBuffer.splice(0, this._prevBufferLen);
|
|
// setting prevBufferLen = 0 is very important
|
|
// for example, when upgrading, upgrade packet is sent over,
|
|
// and a nonzero prevBufferLen could cause problems on `drain`
|
|
this._prevBufferLen = 0;
|
|
if (0 === this.writeBuffer.length) {
|
|
this.emitReserved("drain");
|
|
}
|
|
else {
|
|
this.flush();
|
|
}
|
|
}
|
|
/**
|
|
* Flush write buffers.
|
|
*
|
|
* @private
|
|
*/
|
|
flush() {
|
|
if ("closed" !== this.readyState &&
|
|
this.transport.writable &&
|
|
!this.upgrading &&
|
|
this.writeBuffer.length) {
|
|
const packets = this._getWritablePackets();
|
|
debug$3("flushing %d packets in socket", packets.length);
|
|
this.transport.send(packets);
|
|
// keep track of current length of writeBuffer
|
|
// splice writeBuffer and callbackBuffer on `drain`
|
|
this._prevBufferLen = packets.length;
|
|
this.emitReserved("flush");
|
|
}
|
|
}
|
|
/**
|
|
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
* long-polling)
|
|
*
|
|
* @private
|
|
*/
|
|
_getWritablePackets() {
|
|
const shouldCheckPayloadSize = this._maxPayload &&
|
|
this.transport.name === "polling" &&
|
|
this.writeBuffer.length > 1;
|
|
if (!shouldCheckPayloadSize) {
|
|
return this.writeBuffer;
|
|
}
|
|
let payloadSize = 1; // first packet type
|
|
for (let i = 0; i < this.writeBuffer.length; i++) {
|
|
const data = this.writeBuffer[i].data;
|
|
if (data) {
|
|
payloadSize += (0, util_js_1.byteLength)(data);
|
|
}
|
|
if (i > 0 && payloadSize > this._maxPayload) {
|
|
debug$3("only send %d out of %d packets", i, this.writeBuffer.length);
|
|
return this.writeBuffer.slice(0, i);
|
|
}
|
|
payloadSize += 2; // separator + packet type
|
|
}
|
|
debug$3("payload size is %d (max: %d)", payloadSize, this._maxPayload);
|
|
return this.writeBuffer;
|
|
}
|
|
/**
|
|
* Checks whether the heartbeat timer has expired but the socket has not yet been notified.
|
|
*
|
|
* Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
|
|
* `write()` method then the message would not be buffered by the Socket.IO client.
|
|
*
|
|
* @return {boolean}
|
|
* @private
|
|
*/
|
|
/* private */ _hasPingExpired() {
|
|
if (!this._pingTimeoutTime)
|
|
return true;
|
|
const hasExpired = Date.now() > this._pingTimeoutTime;
|
|
if (hasExpired) {
|
|
debug$3("throttled timer detected, scheduling connection close");
|
|
this._pingTimeoutTime = 0;
|
|
(0, globals_node_js_1.nextTick)(() => {
|
|
this._onClose("ping timeout");
|
|
}, this.setTimeoutFn);
|
|
}
|
|
return hasExpired;
|
|
}
|
|
/**
|
|
* Sends a message.
|
|
*
|
|
* @param {String} msg - message.
|
|
* @param {Object} options.
|
|
* @param {Function} fn - callback function.
|
|
* @return {Socket} for chaining.
|
|
*/
|
|
write(msg, options, fn) {
|
|
this._sendPacket("message", msg, options, fn);
|
|
return this;
|
|
}
|
|
/**
|
|
* Sends a message. Alias of {@link Socket#write}.
|
|
*
|
|
* @param {String} msg - message.
|
|
* @param {Object} options.
|
|
* @param {Function} fn - callback function.
|
|
* @return {Socket} for chaining.
|
|
*/
|
|
send(msg, options, fn) {
|
|
this._sendPacket("message", msg, options, fn);
|
|
return this;
|
|
}
|
|
/**
|
|
* Sends a packet.
|
|
*
|
|
* @param {String} type: packet type.
|
|
* @param {String} data.
|
|
* @param {Object} options.
|
|
* @param {Function} fn - callback function.
|
|
* @private
|
|
*/
|
|
_sendPacket(type, data, options, fn) {
|
|
if ("function" === typeof data) {
|
|
fn = data;
|
|
data = undefined;
|
|
}
|
|
if ("function" === typeof options) {
|
|
fn = options;
|
|
options = null;
|
|
}
|
|
if ("closing" === this.readyState || "closed" === this.readyState) {
|
|
return;
|
|
}
|
|
options = options || {};
|
|
options.compress = false !== options.compress;
|
|
const packet = {
|
|
type: type,
|
|
data: data,
|
|
options: options,
|
|
};
|
|
this.emitReserved("packetCreate", packet);
|
|
this.writeBuffer.push(packet);
|
|
if (fn)
|
|
this.once("flush", fn);
|
|
this.flush();
|
|
}
|
|
/**
|
|
* Closes the connection.
|
|
*/
|
|
close() {
|
|
const close = () => {
|
|
this._onClose("forced close");
|
|
debug$3("socket closing - telling transport to close");
|
|
this.transport.close();
|
|
};
|
|
const cleanupAndClose = () => {
|
|
this.off("upgrade", cleanupAndClose);
|
|
this.off("upgradeError", cleanupAndClose);
|
|
close();
|
|
};
|
|
const waitForUpgrade = () => {
|
|
// wait for upgrade to finish since we can't send packets while pausing a transport
|
|
this.once("upgrade", cleanupAndClose);
|
|
this.once("upgradeError", cleanupAndClose);
|
|
};
|
|
if ("opening" === this.readyState || "open" === this.readyState) {
|
|
this.readyState = "closing";
|
|
if (this.writeBuffer.length) {
|
|
this.once("drain", () => {
|
|
if (this.upgrading) {
|
|
waitForUpgrade();
|
|
}
|
|
else {
|
|
close();
|
|
}
|
|
});
|
|
}
|
|
else if (this.upgrading) {
|
|
waitForUpgrade();
|
|
}
|
|
else {
|
|
close();
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
/**
|
|
* Called upon transport error
|
|
*
|
|
* @private
|
|
*/
|
|
_onError(err) {
|
|
debug$3("socket error %j", err);
|
|
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
if (this.opts.tryAllTransports &&
|
|
this.transports.length > 1 &&
|
|
this.readyState === "opening") {
|
|
debug$3("trying next transport");
|
|
this.transports.shift();
|
|
return this._open();
|
|
}
|
|
this.emitReserved("error", err);
|
|
this._onClose("transport error", err);
|
|
}
|
|
/**
|
|
* Called upon transport close.
|
|
*
|
|
* @private
|
|
*/
|
|
_onClose(reason, description) {
|
|
if ("opening" === this.readyState ||
|
|
"open" === this.readyState ||
|
|
"closing" === this.readyState) {
|
|
debug$3('socket close with reason: "%s"', reason);
|
|
// clear timers
|
|
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
// stop event from firing again for transport
|
|
this.transport.removeAllListeners("close");
|
|
// ensure transport won't stay open
|
|
this.transport.close();
|
|
// ignore further transport communication
|
|
this.transport.removeAllListeners();
|
|
if (withEventListeners) {
|
|
if (this._beforeunloadEventListener) {
|
|
removeEventListener("beforeunload", this._beforeunloadEventListener, false);
|
|
}
|
|
if (this._offlineEventListener) {
|
|
const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
|
|
if (i !== -1) {
|
|
debug$3("removing listener for the 'offline' event");
|
|
OFFLINE_EVENT_LISTENERS.splice(i, 1);
|
|
}
|
|
}
|
|
}
|
|
// set ready state
|
|
this.readyState = "closed";
|
|
// clear session id
|
|
this.id = null;
|
|
// emit close event
|
|
this.emitReserved("close", reason, description);
|
|
// clean buffers after, so users can still
|
|
// grab the buffers on `close` event
|
|
this.writeBuffer = [];
|
|
this._prevBufferLen = 0;
|
|
}
|
|
}
|
|
}
|
|
socket$2.SocketWithoutUpgrade = SocketWithoutUpgrade;
|
|
SocketWithoutUpgrade.protocol = engine_io_parser_1.protocol;
|
|
/**
|
|
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
*
|
|
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
* low-level transport, it will try to upgrade to a better transport.
|
|
*
|
|
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
*
|
|
* @example
|
|
* import { SocketWithUpgrade, WebSocket } from "engine.io-client";
|
|
*
|
|
* const socket = new SocketWithUpgrade({
|
|
* transports: [WebSocket]
|
|
* });
|
|
*
|
|
* socket.on("open", () => {
|
|
* socket.send("hello");
|
|
* });
|
|
*
|
|
* @see SocketWithoutUpgrade
|
|
* @see Socket
|
|
*/
|
|
class SocketWithUpgrade extends SocketWithoutUpgrade {
|
|
constructor() {
|
|
super(...arguments);
|
|
this._upgrades = [];
|
|
}
|
|
onOpen() {
|
|
super.onOpen();
|
|
if ("open" === this.readyState && this.opts.upgrade) {
|
|
debug$3("starting upgrade probes");
|
|
for (let i = 0; i < this._upgrades.length; i++) {
|
|
this._probe(this._upgrades[i]);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Probes a transport.
|
|
*
|
|
* @param {String} name - transport name
|
|
* @private
|
|
*/
|
|
_probe(name) {
|
|
debug$3('probing transport "%s"', name);
|
|
let transport = this.createTransport(name);
|
|
let failed = false;
|
|
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
const onTransportOpen = () => {
|
|
if (failed)
|
|
return;
|
|
debug$3('probe transport "%s" opened', name);
|
|
transport.send([{ type: "ping", data: "probe" }]);
|
|
transport.once("packet", (msg) => {
|
|
if (failed)
|
|
return;
|
|
if ("pong" === msg.type && "probe" === msg.data) {
|
|
debug$3('probe transport "%s" pong', name);
|
|
this.upgrading = true;
|
|
this.emitReserved("upgrading", transport);
|
|
if (!transport)
|
|
return;
|
|
SocketWithoutUpgrade.priorWebsocketSuccess =
|
|
"websocket" === transport.name;
|
|
debug$3('pausing current transport "%s"', this.transport.name);
|
|
this.transport.pause(() => {
|
|
if (failed)
|
|
return;
|
|
if ("closed" === this.readyState)
|
|
return;
|
|
debug$3("changing transport and sending upgrade packet");
|
|
cleanup();
|
|
this.setTransport(transport);
|
|
transport.send([{ type: "upgrade" }]);
|
|
this.emitReserved("upgrade", transport);
|
|
transport = null;
|
|
this.upgrading = false;
|
|
this.flush();
|
|
});
|
|
}
|
|
else {
|
|
debug$3('probe transport "%s" failed', name);
|
|
const err = new Error("probe error");
|
|
// @ts-ignore
|
|
err.transport = transport.name;
|
|
this.emitReserved("upgradeError", err);
|
|
}
|
|
});
|
|
};
|
|
function freezeTransport() {
|
|
if (failed)
|
|
return;
|
|
// Any callback called by transport should be ignored since now
|
|
failed = true;
|
|
cleanup();
|
|
transport.close();
|
|
transport = null;
|
|
}
|
|
// Handle any error that happens while probing
|
|
const onerror = (err) => {
|
|
const error = new Error("probe error: " + err);
|
|
// @ts-ignore
|
|
error.transport = transport.name;
|
|
freezeTransport();
|
|
debug$3('probe transport "%s" failed because of error: %s', name, err);
|
|
this.emitReserved("upgradeError", error);
|
|
};
|
|
function onTransportClose() {
|
|
onerror("transport closed");
|
|
}
|
|
// When the socket is closed while we're probing
|
|
function onclose() {
|
|
onerror("socket closed");
|
|
}
|
|
// When the socket is upgraded while we're probing
|
|
function onupgrade(to) {
|
|
if (transport && to.name !== transport.name) {
|
|
debug$3('"%s" works - aborting "%s"', to.name, transport.name);
|
|
freezeTransport();
|
|
}
|
|
}
|
|
// Remove all listeners on the transport and on self
|
|
const cleanup = () => {
|
|
transport.removeListener("open", onTransportOpen);
|
|
transport.removeListener("error", onerror);
|
|
transport.removeListener("close", onTransportClose);
|
|
this.off("close", onclose);
|
|
this.off("upgrading", onupgrade);
|
|
};
|
|
transport.once("open", onTransportOpen);
|
|
transport.once("error", onerror);
|
|
transport.once("close", onTransportClose);
|
|
this.once("close", onclose);
|
|
this.once("upgrading", onupgrade);
|
|
if (this._upgrades.indexOf("webtransport") !== -1 &&
|
|
name !== "webtransport") {
|
|
// favor WebTransport
|
|
this.setTimeoutFn(() => {
|
|
if (!failed) {
|
|
transport.open();
|
|
}
|
|
}, 200);
|
|
}
|
|
else {
|
|
transport.open();
|
|
}
|
|
}
|
|
onHandshake(data) {
|
|
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
super.onHandshake(data);
|
|
}
|
|
/**
|
|
* Filters upgrades, returning only those matching client transports.
|
|
*
|
|
* @param {Array} upgrades - server upgrades
|
|
* @private
|
|
*/
|
|
_filterUpgrades(upgrades) {
|
|
const filteredUpgrades = [];
|
|
for (let i = 0; i < upgrades.length; i++) {
|
|
if (~this.transports.indexOf(upgrades[i]))
|
|
filteredUpgrades.push(upgrades[i]);
|
|
}
|
|
return filteredUpgrades;
|
|
}
|
|
}
|
|
socket$2.SocketWithUpgrade = SocketWithUpgrade;
|
|
/**
|
|
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
*
|
|
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
* low-level transport, it will try to upgrade to a better transport.
|
|
*
|
|
* @example
|
|
* import { Socket } from "engine.io-client";
|
|
*
|
|
* const socket = new Socket();
|
|
*
|
|
* socket.on("open", () => {
|
|
* socket.send("hello");
|
|
* });
|
|
*
|
|
* @see SocketWithoutUpgrade
|
|
* @see SocketWithUpgrade
|
|
*/
|
|
class Socket$1 extends SocketWithUpgrade {
|
|
constructor(uri, opts = {}) {
|
|
const o = typeof uri === "object" ? uri : opts;
|
|
if (!o.transports ||
|
|
(o.transports && typeof o.transports[0] === "string")) {
|
|
o.transports = (o.transports || ["polling", "websocket", "webtransport"])
|
|
.map((transportName) => index_js_1.transports[transportName])
|
|
.filter((t) => !!t);
|
|
}
|
|
super(uri, o);
|
|
}
|
|
}
|
|
socket$2.Socket = Socket$1;
|
|
|
|
var pollingFetch = {};
|
|
|
|
Object.defineProperty(pollingFetch, "__esModule", { value: true });
|
|
pollingFetch.Fetch = void 0;
|
|
const polling_js_1 = polling;
|
|
/**
|
|
* HTTP long-polling based on the built-in `fetch()` method.
|
|
*
|
|
* Usage: browser, Node.js (since v18), Deno, Bun
|
|
*
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
|
* @see https://caniuse.com/fetch
|
|
* @see https://nodejs.org/api/globals.html#fetch
|
|
*/
|
|
class Fetch extends polling_js_1.Polling {
|
|
doPoll() {
|
|
this._fetch()
|
|
.then((res) => {
|
|
if (!res.ok) {
|
|
return this.onError("fetch read error", res.status, res);
|
|
}
|
|
res.text().then((data) => this.onData(data));
|
|
})
|
|
.catch((err) => {
|
|
this.onError("fetch read error", err);
|
|
});
|
|
}
|
|
doWrite(data, callback) {
|
|
this._fetch(data)
|
|
.then((res) => {
|
|
if (!res.ok) {
|
|
return this.onError("fetch write error", res.status, res);
|
|
}
|
|
callback();
|
|
})
|
|
.catch((err) => {
|
|
this.onError("fetch write error", err);
|
|
});
|
|
}
|
|
_fetch(data) {
|
|
var _a;
|
|
const isPost = data !== undefined;
|
|
const headers = new Headers(this.opts.extraHeaders);
|
|
if (isPost) {
|
|
headers.set("content-type", "text/plain;charset=UTF-8");
|
|
}
|
|
(_a = this.socket._cookieJar) === null || _a === void 0 ? void 0 : _a.appendCookies(headers);
|
|
return fetch(this.uri(), {
|
|
method: isPost ? "POST" : "GET",
|
|
body: isPost ? data : null,
|
|
headers,
|
|
credentials: this.opts.withCredentials ? "include" : "omit",
|
|
}).then((res) => {
|
|
var _a;
|
|
// @ts-ignore getSetCookie() was added in Node.js v19.7.0
|
|
(_a = this.socket._cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(res.headers.getSetCookie());
|
|
return res;
|
|
});
|
|
}
|
|
}
|
|
pollingFetch.Fetch = Fetch;
|
|
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.WebTransport = exports.WebSocket = exports.NodeWebSocket = exports.XHR = exports.NodeXHR = exports.Fetch = exports.nextTick = exports.parse = exports.installTimerFunctions = exports.transports = exports.TransportError = exports.Transport = exports.protocol = exports.SocketWithUpgrade = exports.SocketWithoutUpgrade = exports.Socket = void 0;
|
|
const socket_js_1 = socket$2;
|
|
Object.defineProperty(exports, "Socket", { enumerable: true, get: function () { return socket_js_1.Socket; } });
|
|
var socket_js_2 = socket$2;
|
|
Object.defineProperty(exports, "SocketWithoutUpgrade", { enumerable: true, get: function () { return socket_js_2.SocketWithoutUpgrade; } });
|
|
Object.defineProperty(exports, "SocketWithUpgrade", { enumerable: true, get: function () { return socket_js_2.SocketWithUpgrade; } });
|
|
exports.protocol = socket_js_1.Socket.protocol;
|
|
var transport_js_1 = transport;
|
|
Object.defineProperty(exports, "Transport", { enumerable: true, get: function () { return transport_js_1.Transport; } });
|
|
Object.defineProperty(exports, "TransportError", { enumerable: true, get: function () { return transport_js_1.TransportError; } });
|
|
var index_js_1 = transports;
|
|
Object.defineProperty(exports, "transports", { enumerable: true, get: function () { return index_js_1.transports; } });
|
|
var util_js_1 = util;
|
|
Object.defineProperty(exports, "installTimerFunctions", { enumerable: true, get: function () { return util_js_1.installTimerFunctions; } });
|
|
var parseuri_js_1 = parseuri;
|
|
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parseuri_js_1.parse; } });
|
|
var globals_node_js_1 = globals;
|
|
Object.defineProperty(exports, "nextTick", { enumerable: true, get: function () { return globals_node_js_1.nextTick; } });
|
|
var polling_fetch_js_1 = pollingFetch;
|
|
Object.defineProperty(exports, "Fetch", { enumerable: true, get: function () { return polling_fetch_js_1.Fetch; } });
|
|
var polling_xhr_node_js_1 = pollingXhr;
|
|
Object.defineProperty(exports, "NodeXHR", { enumerable: true, get: function () { return polling_xhr_node_js_1.XHR; } });
|
|
var polling_xhr_js_1 = pollingXhr;
|
|
Object.defineProperty(exports, "XHR", { enumerable: true, get: function () { return polling_xhr_js_1.XHR; } });
|
|
var websocket_node_js_1 = websocket;
|
|
Object.defineProperty(exports, "NodeWebSocket", { enumerable: true, get: function () { return websocket_node_js_1.WS; } });
|
|
var websocket_js_1 = websocket;
|
|
Object.defineProperty(exports, "WebSocket", { enumerable: true, get: function () { return websocket_js_1.WS; } });
|
|
var webtransport_js_1 = webtransport;
|
|
Object.defineProperty(exports, "WebTransport", { enumerable: true, get: function () { return webtransport_js_1.WT; } });
|
|
} (cjs$2));
|
|
|
|
var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(url$1, "__esModule", { value: true });
|
|
url$1.url = url;
|
|
const engine_io_client_1$1 = cjs$2;
|
|
const debug_1$2 = __importDefault$2(browserExports); // debug()
|
|
const debug$2 = (0, debug_1$2.default)("socket.io-client:url"); // debug()
|
|
/**
|
|
* URL parser.
|
|
*
|
|
* @param uri - url
|
|
* @param path - the request path of the connection
|
|
* @param loc - An object meant to mimic window.location.
|
|
* Defaults to window.location.
|
|
* @public
|
|
*/
|
|
function url(uri, path = "", loc) {
|
|
let obj = uri;
|
|
// default to window.location
|
|
loc = loc || (typeof location !== "undefined" && location);
|
|
if (null == uri)
|
|
uri = loc.protocol + "//" + loc.host;
|
|
// relative path support
|
|
if (typeof uri === "string") {
|
|
if ("/" === uri.charAt(0)) {
|
|
if ("/" === uri.charAt(1)) {
|
|
uri = loc.protocol + uri;
|
|
}
|
|
else {
|
|
uri = loc.host + uri;
|
|
}
|
|
}
|
|
if (!/^(https?|wss?):\/\//.test(uri)) {
|
|
debug$2("protocol-less url %s", uri);
|
|
if ("undefined" !== typeof loc) {
|
|
uri = loc.protocol + "//" + uri;
|
|
}
|
|
else {
|
|
uri = "https://" + uri;
|
|
}
|
|
}
|
|
// parse
|
|
debug$2("parse %s", uri);
|
|
obj = (0, engine_io_client_1$1.parse)(uri);
|
|
}
|
|
// make sure we treat `localhost:80` and `localhost` equally
|
|
if (!obj.port) {
|
|
if (/^(http|ws)$/.test(obj.protocol)) {
|
|
obj.port = "80";
|
|
}
|
|
else if (/^(http|ws)s$/.test(obj.protocol)) {
|
|
obj.port = "443";
|
|
}
|
|
}
|
|
obj.path = obj.path || "/";
|
|
const ipv6 = obj.host.indexOf(":") !== -1;
|
|
const host = ipv6 ? "[" + obj.host + "]" : obj.host;
|
|
// define unique id
|
|
obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
|
|
// define href
|
|
obj.href =
|
|
obj.protocol +
|
|
"://" +
|
|
host +
|
|
(loc && loc.port === obj.port ? "" : ":" + obj.port);
|
|
return obj;
|
|
}
|
|
|
|
var manager = {};
|
|
|
|
var socket$1 = {};
|
|
|
|
var cjs = {};
|
|
|
|
var binary = {};
|
|
|
|
var isBinary$1 = {};
|
|
|
|
Object.defineProperty(isBinary$1, "__esModule", { value: true });
|
|
isBinary$1.hasBinary = isBinary$1.isBinary = void 0;
|
|
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
const isView = (obj) => {
|
|
return typeof ArrayBuffer.isView === "function"
|
|
? ArrayBuffer.isView(obj)
|
|
: obj.buffer instanceof ArrayBuffer;
|
|
};
|
|
const toString = Object.prototype.toString;
|
|
const withNativeBlob = typeof Blob === "function" ||
|
|
(typeof Blob !== "undefined" &&
|
|
toString.call(Blob) === "[object BlobConstructor]");
|
|
const withNativeFile = typeof File === "function" ||
|
|
(typeof File !== "undefined" &&
|
|
toString.call(File) === "[object FileConstructor]");
|
|
/**
|
|
* Returns true if obj is a Buffer, an ArrayBuffer, a Blob or a File.
|
|
*
|
|
* @private
|
|
*/
|
|
function isBinary(obj) {
|
|
return ((withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj))) ||
|
|
(withNativeBlob && obj instanceof Blob) ||
|
|
(withNativeFile && obj instanceof File));
|
|
}
|
|
isBinary$1.isBinary = isBinary;
|
|
function hasBinary(obj, toJSON) {
|
|
if (!obj || typeof obj !== "object") {
|
|
return false;
|
|
}
|
|
if (Array.isArray(obj)) {
|
|
for (let i = 0, l = obj.length; i < l; i++) {
|
|
if (hasBinary(obj[i])) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
if (isBinary(obj)) {
|
|
return true;
|
|
}
|
|
if (obj.toJSON &&
|
|
typeof obj.toJSON === "function" &&
|
|
arguments.length === 1) {
|
|
return hasBinary(obj.toJSON(), true);
|
|
}
|
|
for (const key in obj) {
|
|
if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
isBinary$1.hasBinary = hasBinary;
|
|
|
|
Object.defineProperty(binary, "__esModule", { value: true });
|
|
binary.reconstructPacket = binary.deconstructPacket = void 0;
|
|
const is_binary_js_1 = isBinary$1;
|
|
/**
|
|
* Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
|
|
*
|
|
* @param {Object} packet - socket.io event packet
|
|
* @return {Object} with deconstructed packet and list of buffers
|
|
* @public
|
|
*/
|
|
function deconstructPacket(packet) {
|
|
const buffers = [];
|
|
const packetData = packet.data;
|
|
const pack = packet;
|
|
pack.data = _deconstructPacket(packetData, buffers);
|
|
pack.attachments = buffers.length; // number of binary 'attachments'
|
|
return { packet: pack, buffers: buffers };
|
|
}
|
|
binary.deconstructPacket = deconstructPacket;
|
|
function _deconstructPacket(data, buffers) {
|
|
if (!data)
|
|
return data;
|
|
if ((0, is_binary_js_1.isBinary)(data)) {
|
|
const placeholder = { _placeholder: true, num: buffers.length };
|
|
buffers.push(data);
|
|
return placeholder;
|
|
}
|
|
else if (Array.isArray(data)) {
|
|
const newData = new Array(data.length);
|
|
for (let i = 0; i < data.length; i++) {
|
|
newData[i] = _deconstructPacket(data[i], buffers);
|
|
}
|
|
return newData;
|
|
}
|
|
else if (typeof data === "object" && !(data instanceof Date)) {
|
|
const newData = {};
|
|
for (const key in data) {
|
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
newData[key] = _deconstructPacket(data[key], buffers);
|
|
}
|
|
}
|
|
return newData;
|
|
}
|
|
return data;
|
|
}
|
|
/**
|
|
* Reconstructs a binary packet from its placeholder packet and buffers
|
|
*
|
|
* @param {Object} packet - event packet with placeholders
|
|
* @param {Array} buffers - binary buffers to put in placeholder positions
|
|
* @return {Object} reconstructed packet
|
|
* @public
|
|
*/
|
|
function reconstructPacket(packet, buffers) {
|
|
packet.data = _reconstructPacket(packet.data, buffers);
|
|
delete packet.attachments; // no longer useful
|
|
return packet;
|
|
}
|
|
binary.reconstructPacket = reconstructPacket;
|
|
function _reconstructPacket(data, buffers) {
|
|
if (!data)
|
|
return data;
|
|
if (data && data._placeholder === true) {
|
|
const isIndexValid = typeof data.num === "number" &&
|
|
data.num >= 0 &&
|
|
data.num < buffers.length;
|
|
if (isIndexValid) {
|
|
return buffers[data.num]; // appropriate buffer (should be natural order anyway)
|
|
}
|
|
else {
|
|
throw new Error("illegal attachments");
|
|
}
|
|
}
|
|
else if (Array.isArray(data)) {
|
|
for (let i = 0; i < data.length; i++) {
|
|
data[i] = _reconstructPacket(data[i], buffers);
|
|
}
|
|
}
|
|
else if (typeof data === "object") {
|
|
for (const key in data) {
|
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
data[key] = _reconstructPacket(data[key], buffers);
|
|
}
|
|
}
|
|
}
|
|
return data;
|
|
}
|
|
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Decoder = exports.Encoder = exports.PacketType = exports.protocol = void 0;
|
|
const component_emitter_1 = require$$5;
|
|
const binary_js_1 = binary;
|
|
const is_binary_js_1 = isBinary$1;
|
|
const debug_1 = browserExports; // debug()
|
|
const debug = (0, debug_1.default)("socket.io-parser"); // debug()
|
|
/**
|
|
* These strings must not be used as event names, as they have a special meaning.
|
|
*/
|
|
const RESERVED_EVENTS = [
|
|
"connect",
|
|
"connect_error",
|
|
"disconnect",
|
|
"disconnecting",
|
|
"newListener",
|
|
"removeListener", // used by the Node.js EventEmitter
|
|
];
|
|
/**
|
|
* Protocol version.
|
|
*
|
|
* @public
|
|
*/
|
|
exports.protocol = 5;
|
|
var PacketType;
|
|
(function (PacketType) {
|
|
PacketType[PacketType["CONNECT"] = 0] = "CONNECT";
|
|
PacketType[PacketType["DISCONNECT"] = 1] = "DISCONNECT";
|
|
PacketType[PacketType["EVENT"] = 2] = "EVENT";
|
|
PacketType[PacketType["ACK"] = 3] = "ACK";
|
|
PacketType[PacketType["CONNECT_ERROR"] = 4] = "CONNECT_ERROR";
|
|
PacketType[PacketType["BINARY_EVENT"] = 5] = "BINARY_EVENT";
|
|
PacketType[PacketType["BINARY_ACK"] = 6] = "BINARY_ACK";
|
|
})(PacketType = exports.PacketType || (exports.PacketType = {}));
|
|
/**
|
|
* A socket.io Encoder instance
|
|
*/
|
|
class Encoder {
|
|
/**
|
|
* Encoder constructor
|
|
*
|
|
* @param {function} replacer - custom replacer to pass down to JSON.parse
|
|
*/
|
|
constructor(replacer) {
|
|
this.replacer = replacer;
|
|
}
|
|
/**
|
|
* Encode a packet as a single string if non-binary, or as a
|
|
* buffer sequence, depending on packet type.
|
|
*
|
|
* @param {Object} obj - packet object
|
|
*/
|
|
encode(obj) {
|
|
debug("encoding packet %j", obj);
|
|
if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
|
|
if ((0, is_binary_js_1.hasBinary)(obj)) {
|
|
return this.encodeAsBinary({
|
|
type: obj.type === PacketType.EVENT
|
|
? PacketType.BINARY_EVENT
|
|
: PacketType.BINARY_ACK,
|
|
nsp: obj.nsp,
|
|
data: obj.data,
|
|
id: obj.id,
|
|
});
|
|
}
|
|
}
|
|
return [this.encodeAsString(obj)];
|
|
}
|
|
/**
|
|
* Encode packet as string.
|
|
*/
|
|
encodeAsString(obj) {
|
|
// first is type
|
|
let str = "" + obj.type;
|
|
// attachments if we have them
|
|
if (obj.type === PacketType.BINARY_EVENT ||
|
|
obj.type === PacketType.BINARY_ACK) {
|
|
str += obj.attachments + "-";
|
|
}
|
|
// if we have a namespace other than `/`
|
|
// we append it followed by a comma `,`
|
|
if (obj.nsp && "/" !== obj.nsp) {
|
|
str += obj.nsp + ",";
|
|
}
|
|
// immediately followed by the id
|
|
if (null != obj.id) {
|
|
str += obj.id;
|
|
}
|
|
// json data
|
|
if (null != obj.data) {
|
|
str += JSON.stringify(obj.data, this.replacer);
|
|
}
|
|
debug("encoded %j as %s", obj, str);
|
|
return str;
|
|
}
|
|
/**
|
|
* Encode packet as 'buffer sequence' by removing blobs, and
|
|
* deconstructing packet into object with placeholders and
|
|
* a list of buffers.
|
|
*/
|
|
encodeAsBinary(obj) {
|
|
const deconstruction = (0, binary_js_1.deconstructPacket)(obj);
|
|
const pack = this.encodeAsString(deconstruction.packet);
|
|
const buffers = deconstruction.buffers;
|
|
buffers.unshift(pack); // add packet info to beginning of data list
|
|
return buffers; // write all the buffers
|
|
}
|
|
}
|
|
exports.Encoder = Encoder;
|
|
// see https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript
|
|
function isObject(value) {
|
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
}
|
|
/**
|
|
* A socket.io Decoder instance
|
|
*
|
|
* @return {Object} decoder
|
|
*/
|
|
class Decoder extends component_emitter_1.Emitter {
|
|
/**
|
|
* Decoder constructor
|
|
*
|
|
* @param {function} reviver - custom reviver to pass down to JSON.stringify
|
|
*/
|
|
constructor(reviver) {
|
|
super();
|
|
this.reviver = reviver;
|
|
}
|
|
/**
|
|
* Decodes an encoded packet string into packet JSON.
|
|
*
|
|
* @param {String} obj - encoded packet
|
|
*/
|
|
add(obj) {
|
|
let packet;
|
|
if (typeof obj === "string") {
|
|
if (this.reconstructor) {
|
|
throw new Error("got plaintext data when reconstructing a packet");
|
|
}
|
|
packet = this.decodeString(obj);
|
|
const isBinaryEvent = packet.type === PacketType.BINARY_EVENT;
|
|
if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
|
|
packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
|
|
// binary packet's json
|
|
this.reconstructor = new BinaryReconstructor(packet);
|
|
// no attachments, labeled binary but no binary data to follow
|
|
if (packet.attachments === 0) {
|
|
super.emitReserved("decoded", packet);
|
|
}
|
|
}
|
|
else {
|
|
// non-binary full packet
|
|
super.emitReserved("decoded", packet);
|
|
}
|
|
}
|
|
else if ((0, is_binary_js_1.isBinary)(obj) || obj.base64) {
|
|
// raw binary data
|
|
if (!this.reconstructor) {
|
|
throw new Error("got binary data when not reconstructing a packet");
|
|
}
|
|
else {
|
|
packet = this.reconstructor.takeBinaryData(obj);
|
|
if (packet) {
|
|
// received final buffer
|
|
this.reconstructor = null;
|
|
super.emitReserved("decoded", packet);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
throw new Error("Unknown type: " + obj);
|
|
}
|
|
}
|
|
/**
|
|
* Decode a packet String (JSON data)
|
|
*
|
|
* @param {String} str
|
|
* @return {Object} packet
|
|
*/
|
|
decodeString(str) {
|
|
let i = 0;
|
|
// look up type
|
|
const p = {
|
|
type: Number(str.charAt(0)),
|
|
};
|
|
if (PacketType[p.type] === undefined) {
|
|
throw new Error("unknown packet type " + p.type);
|
|
}
|
|
// look up attachments if type binary
|
|
if (p.type === PacketType.BINARY_EVENT ||
|
|
p.type === PacketType.BINARY_ACK) {
|
|
const start = i + 1;
|
|
while (str.charAt(++i) !== "-" && i != str.length) { }
|
|
const buf = str.substring(start, i);
|
|
if (buf != Number(buf) || str.charAt(i) !== "-") {
|
|
throw new Error("Illegal attachments");
|
|
}
|
|
p.attachments = Number(buf);
|
|
}
|
|
// look up namespace (if any)
|
|
if ("/" === str.charAt(i + 1)) {
|
|
const start = i + 1;
|
|
while (++i) {
|
|
const c = str.charAt(i);
|
|
if ("," === c)
|
|
break;
|
|
if (i === str.length)
|
|
break;
|
|
}
|
|
p.nsp = str.substring(start, i);
|
|
}
|
|
else {
|
|
p.nsp = "/";
|
|
}
|
|
// look up id
|
|
const next = str.charAt(i + 1);
|
|
if ("" !== next && Number(next) == next) {
|
|
const start = i + 1;
|
|
while (++i) {
|
|
const c = str.charAt(i);
|
|
if (null == c || Number(c) != c) {
|
|
--i;
|
|
break;
|
|
}
|
|
if (i === str.length)
|
|
break;
|
|
}
|
|
p.id = Number(str.substring(start, i + 1));
|
|
}
|
|
// look up json data
|
|
if (str.charAt(++i)) {
|
|
const payload = this.tryParse(str.substr(i));
|
|
if (Decoder.isPayloadValid(p.type, payload)) {
|
|
p.data = payload;
|
|
}
|
|
else {
|
|
throw new Error("invalid payload");
|
|
}
|
|
}
|
|
debug("decoded %s as %j", str, p);
|
|
return p;
|
|
}
|
|
tryParse(str) {
|
|
try {
|
|
return JSON.parse(str, this.reviver);
|
|
}
|
|
catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
static isPayloadValid(type, payload) {
|
|
switch (type) {
|
|
case PacketType.CONNECT:
|
|
return isObject(payload);
|
|
case PacketType.DISCONNECT:
|
|
return payload === undefined;
|
|
case PacketType.CONNECT_ERROR:
|
|
return typeof payload === "string" || isObject(payload);
|
|
case PacketType.EVENT:
|
|
case PacketType.BINARY_EVENT:
|
|
return (Array.isArray(payload) &&
|
|
(typeof payload[0] === "number" ||
|
|
(typeof payload[0] === "string" &&
|
|
RESERVED_EVENTS.indexOf(payload[0]) === -1)));
|
|
case PacketType.ACK:
|
|
case PacketType.BINARY_ACK:
|
|
return Array.isArray(payload);
|
|
}
|
|
}
|
|
/**
|
|
* Deallocates a parser's resources
|
|
*/
|
|
destroy() {
|
|
if (this.reconstructor) {
|
|
this.reconstructor.finishedReconstruction();
|
|
this.reconstructor = null;
|
|
}
|
|
}
|
|
}
|
|
exports.Decoder = Decoder;
|
|
/**
|
|
* A manager of a binary event's 'buffer sequence'. Should
|
|
* be constructed whenever a packet of type BINARY_EVENT is
|
|
* decoded.
|
|
*
|
|
* @param {Object} packet
|
|
* @return {BinaryReconstructor} initialized reconstructor
|
|
*/
|
|
class BinaryReconstructor {
|
|
constructor(packet) {
|
|
this.packet = packet;
|
|
this.buffers = [];
|
|
this.reconPack = packet;
|
|
}
|
|
/**
|
|
* Method to be called when binary data received from connection
|
|
* after a BINARY_EVENT packet.
|
|
*
|
|
* @param {Buffer | ArrayBuffer} binData - the raw binary data received
|
|
* @return {null | Object} returns null if more binary data is expected or
|
|
* a reconstructed packet object if all buffers have been received.
|
|
*/
|
|
takeBinaryData(binData) {
|
|
this.buffers.push(binData);
|
|
if (this.buffers.length === this.reconPack.attachments) {
|
|
// done with buffer list
|
|
const packet = (0, binary_js_1.reconstructPacket)(this.reconPack, this.buffers);
|
|
this.finishedReconstruction();
|
|
return packet;
|
|
}
|
|
return null;
|
|
}
|
|
/**
|
|
* Cleans up binary packet reconstruction variables.
|
|
*/
|
|
finishedReconstruction() {
|
|
this.reconPack = null;
|
|
this.buffers = [];
|
|
}
|
|
}
|
|
} (cjs));
|
|
|
|
var on$1 = {};
|
|
|
|
Object.defineProperty(on$1, "__esModule", { value: true });
|
|
on$1.on = on;
|
|
function on(obj, ev, fn) {
|
|
obj.on(ev, fn);
|
|
return function subDestroy() {
|
|
obj.off(ev, fn);
|
|
};
|
|
}
|
|
|
|
var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(socket$1, "__esModule", { value: true });
|
|
socket$1.Socket = void 0;
|
|
const socket_io_parser_1 = cjs;
|
|
const on_js_1$1 = on$1;
|
|
const component_emitter_1$1 = require$$5;
|
|
const debug_1$1 = __importDefault$1(browserExports); // debug()
|
|
const debug$1 = (0, debug_1$1.default)("socket.io-client:socket"); // debug()
|
|
/**
|
|
* Internal events.
|
|
* These events can't be emitted by the user.
|
|
*/
|
|
const RESERVED_EVENTS = Object.freeze({
|
|
connect: 1,
|
|
connect_error: 1,
|
|
disconnect: 1,
|
|
disconnecting: 1,
|
|
// EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
|
|
newListener: 1,
|
|
removeListener: 1,
|
|
});
|
|
/**
|
|
* A Socket is the fundamental class for interacting with the server.
|
|
*
|
|
* A Socket belongs to a certain Namespace (by default /) and uses an underlying {@link Manager} to communicate.
|
|
*
|
|
* @example
|
|
* const socket = io();
|
|
*
|
|
* socket.on("connect", () => {
|
|
* console.log("connected");
|
|
* });
|
|
*
|
|
* // send an event to the server
|
|
* socket.emit("foo", "bar");
|
|
*
|
|
* socket.on("foobar", () => {
|
|
* // an event was received from the server
|
|
* });
|
|
*
|
|
* // upon disconnection
|
|
* socket.on("disconnect", (reason) => {
|
|
* console.log(`disconnected due to ${reason}`);
|
|
* });
|
|
*/
|
|
class Socket extends component_emitter_1$1.Emitter {
|
|
/**
|
|
* `Socket` constructor.
|
|
*/
|
|
constructor(io, nsp, opts) {
|
|
super();
|
|
/**
|
|
* Whether the socket is currently connected to the server.
|
|
*
|
|
* @example
|
|
* const socket = io();
|
|
*
|
|
* socket.on("connect", () => {
|
|
* console.log(socket.connected); // true
|
|
* });
|
|
*
|
|
* socket.on("disconnect", () => {
|
|
* console.log(socket.connected); // false
|
|
* });
|
|
*/
|
|
this.connected = false;
|
|
/**
|
|
* Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
|
|
* be transmitted by the server.
|
|
*/
|
|
this.recovered = false;
|
|
/**
|
|
* Buffer for packets received before the CONNECT packet
|
|
*/
|
|
this.receiveBuffer = [];
|
|
/**
|
|
* Buffer for packets that will be sent once the socket is connected
|
|
*/
|
|
this.sendBuffer = [];
|
|
/**
|
|
* The queue of packets to be sent with retry in case of failure.
|
|
*
|
|
* Packets are sent one by one, each waiting for the server acknowledgement, in order to guarantee the delivery order.
|
|
* @private
|
|
*/
|
|
this._queue = [];
|
|
/**
|
|
* A sequence to generate the ID of the {@link QueuedPacket}.
|
|
* @private
|
|
*/
|
|
this._queueSeq = 0;
|
|
this.ids = 0;
|
|
/**
|
|
* A map containing acknowledgement handlers.
|
|
*
|
|
* The `withError` attribute is used to differentiate handlers that accept an error as first argument:
|
|
*
|
|
* - `socket.emit("test", (err, value) => { ... })` with `ackTimeout` option
|
|
* - `socket.timeout(5000).emit("test", (err, value) => { ... })`
|
|
* - `const value = await socket.emitWithAck("test")`
|
|
*
|
|
* From those that don't:
|
|
*
|
|
* - `socket.emit("test", (value) => { ... });`
|
|
*
|
|
* In the first case, the handlers will be called with an error when:
|
|
*
|
|
* - the timeout is reached
|
|
* - the socket gets disconnected
|
|
*
|
|
* In the second case, the handlers will be simply discarded upon disconnection, since the client will never receive
|
|
* an acknowledgement from the server.
|
|
*
|
|
* @private
|
|
*/
|
|
this.acks = {};
|
|
this.flags = {};
|
|
this.io = io;
|
|
this.nsp = nsp;
|
|
if (opts && opts.auth) {
|
|
this.auth = opts.auth;
|
|
}
|
|
this._opts = Object.assign({}, opts);
|
|
if (this.io._autoConnect)
|
|
this.open();
|
|
}
|
|
/**
|
|
* Whether the socket is currently disconnected
|
|
*
|
|
* @example
|
|
* const socket = io();
|
|
*
|
|
* socket.on("connect", () => {
|
|
* console.log(socket.disconnected); // false
|
|
* });
|
|
*
|
|
* socket.on("disconnect", () => {
|
|
* console.log(socket.disconnected); // true
|
|
* });
|
|
*/
|
|
get disconnected() {
|
|
return !this.connected;
|
|
}
|
|
/**
|
|
* Subscribe to open, close and packet events
|
|
*
|
|
* @private
|
|
*/
|
|
subEvents() {
|
|
if (this.subs)
|
|
return;
|
|
const io = this.io;
|
|
this.subs = [
|
|
(0, on_js_1$1.on)(io, "open", this.onopen.bind(this)),
|
|
(0, on_js_1$1.on)(io, "packet", this.onpacket.bind(this)),
|
|
(0, on_js_1$1.on)(io, "error", this.onerror.bind(this)),
|
|
(0, on_js_1$1.on)(io, "close", this.onclose.bind(this)),
|
|
];
|
|
}
|
|
/**
|
|
* Whether the Socket will try to reconnect when its Manager connects or reconnects.
|
|
*
|
|
* @example
|
|
* const socket = io();
|
|
*
|
|
* console.log(socket.active); // true
|
|
*
|
|
* socket.on("disconnect", (reason) => {
|
|
* if (reason === "io server disconnect") {
|
|
* // the disconnection was initiated by the server, you need to manually reconnect
|
|
* console.log(socket.active); // false
|
|
* }
|
|
* // else the socket will automatically try to reconnect
|
|
* console.log(socket.active); // true
|
|
* });
|
|
*/
|
|
get active() {
|
|
return !!this.subs;
|
|
}
|
|
/**
|
|
* "Opens" the socket.
|
|
*
|
|
* @example
|
|
* const socket = io({
|
|
* autoConnect: false
|
|
* });
|
|
*
|
|
* socket.connect();
|
|
*/
|
|
connect() {
|
|
if (this.connected)
|
|
return this;
|
|
this.subEvents();
|
|
if (!this.io["_reconnecting"])
|
|
this.io.open(); // ensure open
|
|
if ("open" === this.io._readyState)
|
|
this.onopen();
|
|
return this;
|
|
}
|
|
/**
|
|
* Alias for {@link connect()}.
|
|
*/
|
|
open() {
|
|
return this.connect();
|
|
}
|
|
/**
|
|
* Sends a `message` event.
|
|
*
|
|
* This method mimics the WebSocket.send() method.
|
|
*
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
*
|
|
* @example
|
|
* socket.send("hello");
|
|
*
|
|
* // this is equivalent to
|
|
* socket.emit("message", "hello");
|
|
*
|
|
* @return self
|
|
*/
|
|
send(...args) {
|
|
args.unshift("message");
|
|
this.emit.apply(this, args);
|
|
return this;
|
|
}
|
|
/**
|
|
* Override `emit`.
|
|
* If the event is in `events`, it's emitted normally.
|
|
*
|
|
* @example
|
|
* socket.emit("hello", "world");
|
|
*
|
|
* // all serializable datastructures are supported (no need to call JSON.stringify)
|
|
* socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
|
|
*
|
|
* // with an acknowledgement from the server
|
|
* socket.emit("hello", "world", (val) => {
|
|
* // ...
|
|
* });
|
|
*
|
|
* @return self
|
|
*/
|
|
emit(ev, ...args) {
|
|
var _a, _b, _c;
|
|
if (RESERVED_EVENTS.hasOwnProperty(ev)) {
|
|
throw new Error('"' + ev.toString() + '" is a reserved event name');
|
|
}
|
|
args.unshift(ev);
|
|
if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) {
|
|
this._addToQueue(args);
|
|
return this;
|
|
}
|
|
const packet = {
|
|
type: socket_io_parser_1.PacketType.EVENT,
|
|
data: args,
|
|
};
|
|
packet.options = {};
|
|
packet.options.compress = this.flags.compress !== false;
|
|
// event ack callback
|
|
if ("function" === typeof args[args.length - 1]) {
|
|
const id = this.ids++;
|
|
debug$1("emitting packet with ack id %d", id);
|
|
const ack = args.pop();
|
|
this._registerAckCallback(id, ack);
|
|
packet.id = id;
|
|
}
|
|
const isTransportWritable = (_b = (_a = this.io.engine) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.writable;
|
|
const isConnected = this.connected && !((_c = this.io.engine) === null || _c === void 0 ? void 0 : _c._hasPingExpired());
|
|
const discardPacket = this.flags.volatile && !isTransportWritable;
|
|
if (discardPacket) {
|
|
debug$1("discard packet as the transport is not currently writable");
|
|
}
|
|
else if (isConnected) {
|
|
this.notifyOutgoingListeners(packet);
|
|
this.packet(packet);
|
|
}
|
|
else {
|
|
this.sendBuffer.push(packet);
|
|
}
|
|
this.flags = {};
|
|
return this;
|
|
}
|
|
/**
|
|
* @private
|
|
*/
|
|
_registerAckCallback(id, ack) {
|
|
var _a;
|
|
const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
|
|
if (timeout === undefined) {
|
|
this.acks[id] = ack;
|
|
return;
|
|
}
|
|
// @ts-ignore
|
|
const timer = this.io.setTimeoutFn(() => {
|
|
delete this.acks[id];
|
|
for (let i = 0; i < this.sendBuffer.length; i++) {
|
|
if (this.sendBuffer[i].id === id) {
|
|
debug$1("removing packet with ack id %d from the buffer", id);
|
|
this.sendBuffer.splice(i, 1);
|
|
}
|
|
}
|
|
debug$1("event with ack id %d has timed out after %d ms", id, timeout);
|
|
ack.call(this, new Error("operation has timed out"));
|
|
}, timeout);
|
|
const fn = (...args) => {
|
|
// @ts-ignore
|
|
this.io.clearTimeoutFn(timer);
|
|
ack.apply(this, args);
|
|
};
|
|
fn.withError = true;
|
|
this.acks[id] = fn;
|
|
}
|
|
/**
|
|
* Emits an event and waits for an acknowledgement
|
|
*
|
|
* @example
|
|
* // without timeout
|
|
* const response = await socket.emitWithAck("hello", "world");
|
|
*
|
|
* // with a specific timeout
|
|
* try {
|
|
* const response = await socket.timeout(1000).emitWithAck("hello", "world");
|
|
* } catch (err) {
|
|
* // the server did not acknowledge the event in the given delay
|
|
* }
|
|
*
|
|
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
*/
|
|
emitWithAck(ev, ...args) {
|
|
return new Promise((resolve, reject) => {
|
|
const fn = (arg1, arg2) => {
|
|
return arg1 ? reject(arg1) : resolve(arg2);
|
|
};
|
|
fn.withError = true;
|
|
args.push(fn);
|
|
this.emit(ev, ...args);
|
|
});
|
|
}
|
|
/**
|
|
* Add the packet to the queue.
|
|
* @param args
|
|
* @private
|
|
*/
|
|
_addToQueue(args) {
|
|
let ack;
|
|
if (typeof args[args.length - 1] === "function") {
|
|
ack = args.pop();
|
|
}
|
|
const packet = {
|
|
id: this._queueSeq++,
|
|
tryCount: 0,
|
|
pending: false,
|
|
args,
|
|
flags: Object.assign({ fromQueue: true }, this.flags),
|
|
};
|
|
args.push((err, ...responseArgs) => {
|
|
if (packet !== this._queue[0]) {
|
|
// the packet has already been acknowledged
|
|
return;
|
|
}
|
|
const hasError = err !== null;
|
|
if (hasError) {
|
|
if (packet.tryCount > this._opts.retries) {
|
|
debug$1("packet [%d] is discarded after %d tries", packet.id, packet.tryCount);
|
|
this._queue.shift();
|
|
if (ack) {
|
|
ack(err);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
debug$1("packet [%d] was successfully sent", packet.id);
|
|
this._queue.shift();
|
|
if (ack) {
|
|
ack(null, ...responseArgs);
|
|
}
|
|
}
|
|
packet.pending = false;
|
|
return this._drainQueue();
|
|
});
|
|
this._queue.push(packet);
|
|
this._drainQueue();
|
|
}
|
|
/**
|
|
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
* @param force - whether to resend a packet that has not been acknowledged yet
|
|
*
|
|
* @private
|
|
*/
|
|
_drainQueue(force = false) {
|
|
debug$1("draining queue");
|
|
if (!this.connected || this._queue.length === 0) {
|
|
return;
|
|
}
|
|
const packet = this._queue[0];
|
|
if (packet.pending && !force) {
|
|
debug$1("packet [%d] has already been sent and is waiting for an ack", packet.id);
|
|
return;
|
|
}
|
|
packet.pending = true;
|
|
packet.tryCount++;
|
|
debug$1("sending packet [%d] (try n°%d)", packet.id, packet.tryCount);
|
|
this.flags = packet.flags;
|
|
this.emit.apply(this, packet.args);
|
|
}
|
|
/**
|
|
* Sends a packet.
|
|
*
|
|
* @param packet
|
|
* @private
|
|
*/
|
|
packet(packet) {
|
|
packet.nsp = this.nsp;
|
|
this.io._packet(packet);
|
|
}
|
|
/**
|
|
* Called upon engine `open`.
|
|
*
|
|
* @private
|
|
*/
|
|
onopen() {
|
|
debug$1("transport is open - connecting");
|
|
if (typeof this.auth == "function") {
|
|
this.auth((data) => {
|
|
this._sendConnectPacket(data);
|
|
});
|
|
}
|
|
else {
|
|
this._sendConnectPacket(this.auth);
|
|
}
|
|
}
|
|
/**
|
|
* Sends a CONNECT packet to initiate the Socket.IO session.
|
|
*
|
|
* @param data
|
|
* @private
|
|
*/
|
|
_sendConnectPacket(data) {
|
|
this.packet({
|
|
type: socket_io_parser_1.PacketType.CONNECT,
|
|
data: this._pid
|
|
? Object.assign({ pid: this._pid, offset: this._lastOffset }, data)
|
|
: data,
|
|
});
|
|
}
|
|
/**
|
|
* Called upon engine or manager `error`.
|
|
*
|
|
* @param err
|
|
* @private
|
|
*/
|
|
onerror(err) {
|
|
if (!this.connected) {
|
|
this.emitReserved("connect_error", err);
|
|
}
|
|
}
|
|
/**
|
|
* Called upon engine `close`.
|
|
*
|
|
* @param reason
|
|
* @param description
|
|
* @private
|
|
*/
|
|
onclose(reason, description) {
|
|
debug$1("close (%s)", reason);
|
|
this.connected = false;
|
|
delete this.id;
|
|
this.emitReserved("disconnect", reason, description);
|
|
this._clearAcks();
|
|
}
|
|
/**
|
|
* Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
|
|
* the server.
|
|
*
|
|
* @private
|
|
*/
|
|
_clearAcks() {
|
|
Object.keys(this.acks).forEach((id) => {
|
|
const isBuffered = this.sendBuffer.some((packet) => String(packet.id) === id);
|
|
if (!isBuffered) {
|
|
// note: handlers that do not accept an error as first argument are ignored here
|
|
const ack = this.acks[id];
|
|
delete this.acks[id];
|
|
if (ack.withError) {
|
|
ack.call(this, new Error("socket has been disconnected"));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* Called with socket packet.
|
|
*
|
|
* @param packet
|
|
* @private
|
|
*/
|
|
onpacket(packet) {
|
|
const sameNamespace = packet.nsp === this.nsp;
|
|
if (!sameNamespace)
|
|
return;
|
|
switch (packet.type) {
|
|
case socket_io_parser_1.PacketType.CONNECT:
|
|
if (packet.data && packet.data.sid) {
|
|
this.onconnect(packet.data.sid, packet.data.pid);
|
|
}
|
|
else {
|
|
this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
|
|
}
|
|
break;
|
|
case socket_io_parser_1.PacketType.EVENT:
|
|
case socket_io_parser_1.PacketType.BINARY_EVENT:
|
|
this.onevent(packet);
|
|
break;
|
|
case socket_io_parser_1.PacketType.ACK:
|
|
case socket_io_parser_1.PacketType.BINARY_ACK:
|
|
this.onack(packet);
|
|
break;
|
|
case socket_io_parser_1.PacketType.DISCONNECT:
|
|
this.ondisconnect();
|
|
break;
|
|
case socket_io_parser_1.PacketType.CONNECT_ERROR:
|
|
this.destroy();
|
|
const err = new Error(packet.data.message);
|
|
// @ts-ignore
|
|
err.data = packet.data.data;
|
|
this.emitReserved("connect_error", err);
|
|
break;
|
|
}
|
|
}
|
|
/**
|
|
* Called upon a server event.
|
|
*
|
|
* @param packet
|
|
* @private
|
|
*/
|
|
onevent(packet) {
|
|
const args = packet.data || [];
|
|
debug$1("emitting event %j", args);
|
|
if (null != packet.id) {
|
|
debug$1("attaching ack callback to event");
|
|
args.push(this.ack(packet.id));
|
|
}
|
|
if (this.connected) {
|
|
this.emitEvent(args);
|
|
}
|
|
else {
|
|
this.receiveBuffer.push(Object.freeze(args));
|
|
}
|
|
}
|
|
emitEvent(args) {
|
|
if (this._anyListeners && this._anyListeners.length) {
|
|
const listeners = this._anyListeners.slice();
|
|
for (const listener of listeners) {
|
|
listener.apply(this, args);
|
|
}
|
|
}
|
|
super.emit.apply(this, args);
|
|
if (this._pid && args.length && typeof args[args.length - 1] === "string") {
|
|
this._lastOffset = args[args.length - 1];
|
|
}
|
|
}
|
|
/**
|
|
* Produces an ack callback to emit with an event.
|
|
*
|
|
* @private
|
|
*/
|
|
ack(id) {
|
|
const self = this;
|
|
let sent = false;
|
|
return function (...args) {
|
|
// prevent double callbacks
|
|
if (sent)
|
|
return;
|
|
sent = true;
|
|
debug$1("sending ack %j", args);
|
|
self.packet({
|
|
type: socket_io_parser_1.PacketType.ACK,
|
|
id: id,
|
|
data: args,
|
|
});
|
|
};
|
|
}
|
|
/**
|
|
* Called upon a server acknowledgement.
|
|
*
|
|
* @param packet
|
|
* @private
|
|
*/
|
|
onack(packet) {
|
|
const ack = this.acks[packet.id];
|
|
if (typeof ack !== "function") {
|
|
debug$1("bad ack %s", packet.id);
|
|
return;
|
|
}
|
|
delete this.acks[packet.id];
|
|
debug$1("calling ack %s with %j", packet.id, packet.data);
|
|
// @ts-ignore FIXME ack is incorrectly inferred as 'never'
|
|
if (ack.withError) {
|
|
packet.data.unshift(null);
|
|
}
|
|
// @ts-ignore
|
|
ack.apply(this, packet.data);
|
|
}
|
|
/**
|
|
* Called upon server connect.
|
|
*
|
|
* @private
|
|
*/
|
|
onconnect(id, pid) {
|
|
debug$1("socket connected with id %s", id);
|
|
this.id = id;
|
|
this.recovered = pid && this._pid === pid;
|
|
this._pid = pid; // defined only if connection state recovery is enabled
|
|
this.connected = true;
|
|
this.emitBuffered();
|
|
this.emitReserved("connect");
|
|
this._drainQueue(true);
|
|
}
|
|
/**
|
|
* Emit buffered events (received and emitted).
|
|
*
|
|
* @private
|
|
*/
|
|
emitBuffered() {
|
|
this.receiveBuffer.forEach((args) => this.emitEvent(args));
|
|
this.receiveBuffer = [];
|
|
this.sendBuffer.forEach((packet) => {
|
|
this.notifyOutgoingListeners(packet);
|
|
this.packet(packet);
|
|
});
|
|
this.sendBuffer = [];
|
|
}
|
|
/**
|
|
* Called upon server disconnect.
|
|
*
|
|
* @private
|
|
*/
|
|
ondisconnect() {
|
|
debug$1("server disconnect (%s)", this.nsp);
|
|
this.destroy();
|
|
this.onclose("io server disconnect");
|
|
}
|
|
/**
|
|
* Called upon forced client/server side disconnections,
|
|
* this method ensures the manager stops tracking us and
|
|
* that reconnections don't get triggered for this.
|
|
*
|
|
* @private
|
|
*/
|
|
destroy() {
|
|
if (this.subs) {
|
|
// clean subscriptions to avoid reconnections
|
|
this.subs.forEach((subDestroy) => subDestroy());
|
|
this.subs = undefined;
|
|
}
|
|
this.io["_destroy"](this);
|
|
}
|
|
/**
|
|
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
*
|
|
* If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
|
|
*
|
|
* @example
|
|
* const socket = io();
|
|
*
|
|
* socket.on("disconnect", (reason) => {
|
|
* // console.log(reason); prints "io client disconnect"
|
|
* });
|
|
*
|
|
* socket.disconnect();
|
|
*
|
|
* @return self
|
|
*/
|
|
disconnect() {
|
|
if (this.connected) {
|
|
debug$1("performing disconnect (%s)", this.nsp);
|
|
this.packet({ type: socket_io_parser_1.PacketType.DISCONNECT });
|
|
}
|
|
// remove socket from pool
|
|
this.destroy();
|
|
if (this.connected) {
|
|
// fire events
|
|
this.onclose("io client disconnect");
|
|
}
|
|
return this;
|
|
}
|
|
/**
|
|
* Alias for {@link disconnect()}.
|
|
*
|
|
* @return self
|
|
*/
|
|
close() {
|
|
return this.disconnect();
|
|
}
|
|
/**
|
|
* Sets the compress flag.
|
|
*
|
|
* @example
|
|
* socket.compress(false).emit("hello");
|
|
*
|
|
* @param compress - if `true`, compresses the sending data
|
|
* @return self
|
|
*/
|
|
compress(compress) {
|
|
this.flags.compress = compress;
|
|
return this;
|
|
}
|
|
/**
|
|
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
* ready to send messages.
|
|
*
|
|
* @example
|
|
* socket.volatile.emit("hello"); // the server may or may not receive it
|
|
*
|
|
* @returns self
|
|
*/
|
|
get volatile() {
|
|
this.flags.volatile = true;
|
|
return this;
|
|
}
|
|
/**
|
|
* Sets a modifier for a subsequent event emission that the callback will be called with an error when the
|
|
* given number of milliseconds have elapsed without an acknowledgement from the server:
|
|
*
|
|
* @example
|
|
* socket.timeout(5000).emit("my-event", (err) => {
|
|
* if (err) {
|
|
* // the server did not acknowledge the event in the given delay
|
|
* }
|
|
* });
|
|
*
|
|
* @returns self
|
|
*/
|
|
timeout(timeout) {
|
|
this.flags.timeout = timeout;
|
|
return this;
|
|
}
|
|
/**
|
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
* callback.
|
|
*
|
|
* @example
|
|
* socket.onAny((event, ...args) => {
|
|
* console.log(`got ${event}`);
|
|
* });
|
|
*
|
|
* @param listener
|
|
*/
|
|
onAny(listener) {
|
|
this._anyListeners = this._anyListeners || [];
|
|
this._anyListeners.push(listener);
|
|
return this;
|
|
}
|
|
/**
|
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
* callback. The listener is added to the beginning of the listeners array.
|
|
*
|
|
* @example
|
|
* socket.prependAny((event, ...args) => {
|
|
* console.log(`got event ${event}`);
|
|
* });
|
|
*
|
|
* @param listener
|
|
*/
|
|
prependAny(listener) {
|
|
this._anyListeners = this._anyListeners || [];
|
|
this._anyListeners.unshift(listener);
|
|
return this;
|
|
}
|
|
/**
|
|
* Removes the listener that will be fired when any event is emitted.
|
|
*
|
|
* @example
|
|
* const catchAllListener = (event, ...args) => {
|
|
* console.log(`got event ${event}`);
|
|
* }
|
|
*
|
|
* socket.onAny(catchAllListener);
|
|
*
|
|
* // remove a specific listener
|
|
* socket.offAny(catchAllListener);
|
|
*
|
|
* // or remove all listeners
|
|
* socket.offAny();
|
|
*
|
|
* @param listener
|
|
*/
|
|
offAny(listener) {
|
|
if (!this._anyListeners) {
|
|
return this;
|
|
}
|
|
if (listener) {
|
|
const listeners = this._anyListeners;
|
|
for (let i = 0; i < listeners.length; i++) {
|
|
if (listener === listeners[i]) {
|
|
listeners.splice(i, 1);
|
|
return this;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
this._anyListeners = [];
|
|
}
|
|
return this;
|
|
}
|
|
/**
|
|
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
* e.g. to remove listeners.
|
|
*/
|
|
listenersAny() {
|
|
return this._anyListeners || [];
|
|
}
|
|
/**
|
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
* callback.
|
|
*
|
|
* Note: acknowledgements sent to the server are not included.
|
|
*
|
|
* @example
|
|
* socket.onAnyOutgoing((event, ...args) => {
|
|
* console.log(`sent event ${event}`);
|
|
* });
|
|
*
|
|
* @param listener
|
|
*/
|
|
onAnyOutgoing(listener) {
|
|
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
this._anyOutgoingListeners.push(listener);
|
|
return this;
|
|
}
|
|
/**
|
|
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
* callback. The listener is added to the beginning of the listeners array.
|
|
*
|
|
* Note: acknowledgements sent to the server are not included.
|
|
*
|
|
* @example
|
|
* socket.prependAnyOutgoing((event, ...args) => {
|
|
* console.log(`sent event ${event}`);
|
|
* });
|
|
*
|
|
* @param listener
|
|
*/
|
|
prependAnyOutgoing(listener) {
|
|
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
this._anyOutgoingListeners.unshift(listener);
|
|
return this;
|
|
}
|
|
/**
|
|
* Removes the listener that will be fired when any event is emitted.
|
|
*
|
|
* @example
|
|
* const catchAllListener = (event, ...args) => {
|
|
* console.log(`sent event ${event}`);
|
|
* }
|
|
*
|
|
* socket.onAnyOutgoing(catchAllListener);
|
|
*
|
|
* // remove a specific listener
|
|
* socket.offAnyOutgoing(catchAllListener);
|
|
*
|
|
* // or remove all listeners
|
|
* socket.offAnyOutgoing();
|
|
*
|
|
* @param [listener] - the catch-all listener (optional)
|
|
*/
|
|
offAnyOutgoing(listener) {
|
|
if (!this._anyOutgoingListeners) {
|
|
return this;
|
|
}
|
|
if (listener) {
|
|
const listeners = this._anyOutgoingListeners;
|
|
for (let i = 0; i < listeners.length; i++) {
|
|
if (listener === listeners[i]) {
|
|
listeners.splice(i, 1);
|
|
return this;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
this._anyOutgoingListeners = [];
|
|
}
|
|
return this;
|
|
}
|
|
/**
|
|
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
* e.g. to remove listeners.
|
|
*/
|
|
listenersAnyOutgoing() {
|
|
return this._anyOutgoingListeners || [];
|
|
}
|
|
/**
|
|
* Notify the listeners for each packet sent
|
|
*
|
|
* @param packet
|
|
*
|
|
* @private
|
|
*/
|
|
notifyOutgoingListeners(packet) {
|
|
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
const listeners = this._anyOutgoingListeners.slice();
|
|
for (const listener of listeners) {
|
|
listener.apply(this, packet.data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
socket$1.Socket = Socket;
|
|
|
|
var backo2 = {};
|
|
|
|
/**
|
|
* Initialize backoff timer with `opts`.
|
|
*
|
|
* - `min` initial timeout in milliseconds [100]
|
|
* - `max` max timeout [10000]
|
|
* - `jitter` [0]
|
|
* - `factor` [2]
|
|
*
|
|
* @param {Object} opts
|
|
* @api public
|
|
*/
|
|
Object.defineProperty(backo2, "__esModule", { value: true });
|
|
backo2.Backoff = Backoff;
|
|
function Backoff(opts) {
|
|
opts = opts || {};
|
|
this.ms = opts.min || 100;
|
|
this.max = opts.max || 10000;
|
|
this.factor = opts.factor || 2;
|
|
this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
|
|
this.attempts = 0;
|
|
}
|
|
/**
|
|
* Return the backoff duration.
|
|
*
|
|
* @return {Number}
|
|
* @api public
|
|
*/
|
|
Backoff.prototype.duration = function () {
|
|
var ms = this.ms * Math.pow(this.factor, this.attempts++);
|
|
if (this.jitter) {
|
|
var rand = Math.random();
|
|
var deviation = Math.floor(rand * this.jitter * ms);
|
|
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
|
|
}
|
|
return Math.min(ms, this.max) | 0;
|
|
};
|
|
/**
|
|
* Reset the number of attempts.
|
|
*
|
|
* @api public
|
|
*/
|
|
Backoff.prototype.reset = function () {
|
|
this.attempts = 0;
|
|
};
|
|
/**
|
|
* Set the minimum duration
|
|
*
|
|
* @api public
|
|
*/
|
|
Backoff.prototype.setMin = function (min) {
|
|
this.ms = min;
|
|
};
|
|
/**
|
|
* Set the maximum duration
|
|
*
|
|
* @api public
|
|
*/
|
|
Backoff.prototype.setMax = function (max) {
|
|
this.max = max;
|
|
};
|
|
/**
|
|
* Set the jitter
|
|
*
|
|
* @api public
|
|
*/
|
|
Backoff.prototype.setJitter = function (jitter) {
|
|
this.jitter = jitter;
|
|
};
|
|
|
|
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(manager, "__esModule", { value: true });
|
|
manager.Manager = void 0;
|
|
const engine_io_client_1 = cjs$2;
|
|
const socket_js_1 = socket$1;
|
|
const parser = __importStar(cjs);
|
|
const on_js_1 = on$1;
|
|
const backo2_js_1 = backo2;
|
|
const component_emitter_1 = require$$5;
|
|
const debug_1 = __importDefault(browserExports); // debug()
|
|
const debug = (0, debug_1.default)("socket.io-client:manager"); // debug()
|
|
class Manager$1 extends component_emitter_1.Emitter {
|
|
constructor(uri, opts) {
|
|
var _a;
|
|
super();
|
|
this.nsps = {};
|
|
this.subs = [];
|
|
if (uri && "object" === typeof uri) {
|
|
opts = uri;
|
|
uri = undefined;
|
|
}
|
|
opts = opts || {};
|
|
opts.path = opts.path || "/socket.io";
|
|
this.opts = opts;
|
|
(0, engine_io_client_1.installTimerFunctions)(this, opts);
|
|
this.reconnection(opts.reconnection !== false);
|
|
this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
|
|
this.reconnectionDelay(opts.reconnectionDelay || 1000);
|
|
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
|
|
this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
|
|
this.backoff = new backo2_js_1.Backoff({
|
|
min: this.reconnectionDelay(),
|
|
max: this.reconnectionDelayMax(),
|
|
jitter: this.randomizationFactor(),
|
|
});
|
|
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
|
|
this._readyState = "closed";
|
|
this.uri = uri;
|
|
const _parser = opts.parser || parser;
|
|
this.encoder = new _parser.Encoder();
|
|
this.decoder = new _parser.Decoder();
|
|
this._autoConnect = opts.autoConnect !== false;
|
|
if (this._autoConnect)
|
|
this.open();
|
|
}
|
|
reconnection(v) {
|
|
if (!arguments.length)
|
|
return this._reconnection;
|
|
this._reconnection = !!v;
|
|
if (!v) {
|
|
this.skipReconnect = true;
|
|
}
|
|
return this;
|
|
}
|
|
reconnectionAttempts(v) {
|
|
if (v === undefined)
|
|
return this._reconnectionAttempts;
|
|
this._reconnectionAttempts = v;
|
|
return this;
|
|
}
|
|
reconnectionDelay(v) {
|
|
var _a;
|
|
if (v === undefined)
|
|
return this._reconnectionDelay;
|
|
this._reconnectionDelay = v;
|
|
(_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);
|
|
return this;
|
|
}
|
|
randomizationFactor(v) {
|
|
var _a;
|
|
if (v === undefined)
|
|
return this._randomizationFactor;
|
|
this._randomizationFactor = v;
|
|
(_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);
|
|
return this;
|
|
}
|
|
reconnectionDelayMax(v) {
|
|
var _a;
|
|
if (v === undefined)
|
|
return this._reconnectionDelayMax;
|
|
this._reconnectionDelayMax = v;
|
|
(_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);
|
|
return this;
|
|
}
|
|
timeout(v) {
|
|
if (!arguments.length)
|
|
return this._timeout;
|
|
this._timeout = v;
|
|
return this;
|
|
}
|
|
/**
|
|
* Starts trying to reconnect if reconnection is enabled and we have not
|
|
* started reconnecting yet
|
|
*
|
|
* @private
|
|
*/
|
|
maybeReconnectOnOpen() {
|
|
// Only try to reconnect if it's the first time we're connecting
|
|
if (!this._reconnecting &&
|
|
this._reconnection &&
|
|
this.backoff.attempts === 0) {
|
|
// keeps reconnection from firing twice for the same reconnection loop
|
|
this.reconnect();
|
|
}
|
|
}
|
|
/**
|
|
* Sets the current transport `socket`.
|
|
*
|
|
* @param {Function} fn - optional, callback
|
|
* @return self
|
|
* @public
|
|
*/
|
|
open(fn) {
|
|
debug("readyState %s", this._readyState);
|
|
if (~this._readyState.indexOf("open"))
|
|
return this;
|
|
debug("opening %s", this.uri);
|
|
this.engine = new engine_io_client_1.Socket(this.uri, this.opts);
|
|
const socket = this.engine;
|
|
const self = this;
|
|
this._readyState = "opening";
|
|
this.skipReconnect = false;
|
|
// emit `open`
|
|
const openSubDestroy = (0, on_js_1.on)(socket, "open", function () {
|
|
self.onopen();
|
|
fn && fn();
|
|
});
|
|
const onError = (err) => {
|
|
debug("error");
|
|
this.cleanup();
|
|
this._readyState = "closed";
|
|
this.emitReserved("error", err);
|
|
if (fn) {
|
|
fn(err);
|
|
}
|
|
else {
|
|
// Only do this if there is no fn to handle the error
|
|
this.maybeReconnectOnOpen();
|
|
}
|
|
};
|
|
// emit `error`
|
|
const errorSub = (0, on_js_1.on)(socket, "error", onError);
|
|
if (false !== this._timeout) {
|
|
const timeout = this._timeout;
|
|
debug("connect attempt will timeout after %d", timeout);
|
|
// set timer
|
|
const timer = this.setTimeoutFn(() => {
|
|
debug("connect attempt timed out after %d", timeout);
|
|
openSubDestroy();
|
|
onError(new Error("timeout"));
|
|
socket.close();
|
|
}, timeout);
|
|
if (this.opts.autoUnref) {
|
|
timer.unref();
|
|
}
|
|
this.subs.push(() => {
|
|
this.clearTimeoutFn(timer);
|
|
});
|
|
}
|
|
this.subs.push(openSubDestroy);
|
|
this.subs.push(errorSub);
|
|
return this;
|
|
}
|
|
/**
|
|
* Alias for open()
|
|
*
|
|
* @return self
|
|
* @public
|
|
*/
|
|
connect(fn) {
|
|
return this.open(fn);
|
|
}
|
|
/**
|
|
* Called upon transport open.
|
|
*
|
|
* @private
|
|
*/
|
|
onopen() {
|
|
debug("open");
|
|
// clear old subs
|
|
this.cleanup();
|
|
// mark as open
|
|
this._readyState = "open";
|
|
this.emitReserved("open");
|
|
// add new subs
|
|
const socket = this.engine;
|
|
this.subs.push((0, on_js_1.on)(socket, "ping", this.onping.bind(this)), (0, on_js_1.on)(socket, "data", this.ondata.bind(this)), (0, on_js_1.on)(socket, "error", this.onerror.bind(this)), (0, on_js_1.on)(socket, "close", this.onclose.bind(this)),
|
|
// @ts-ignore
|
|
(0, on_js_1.on)(this.decoder, "decoded", this.ondecoded.bind(this)));
|
|
}
|
|
/**
|
|
* Called upon a ping.
|
|
*
|
|
* @private
|
|
*/
|
|
onping() {
|
|
this.emitReserved("ping");
|
|
}
|
|
/**
|
|
* Called with data.
|
|
*
|
|
* @private
|
|
*/
|
|
ondata(data) {
|
|
try {
|
|
this.decoder.add(data);
|
|
}
|
|
catch (e) {
|
|
this.onclose("parse error", e);
|
|
}
|
|
}
|
|
/**
|
|
* Called when parser fully decodes a packet.
|
|
*
|
|
* @private
|
|
*/
|
|
ondecoded(packet) {
|
|
// the nextTick call prevents an exception in a user-provided event listener from triggering a disconnection due to a "parse error"
|
|
(0, engine_io_client_1.nextTick)(() => {
|
|
this.emitReserved("packet", packet);
|
|
}, this.setTimeoutFn);
|
|
}
|
|
/**
|
|
* Called upon socket error.
|
|
*
|
|
* @private
|
|
*/
|
|
onerror(err) {
|
|
debug("error", err);
|
|
this.emitReserved("error", err);
|
|
}
|
|
/**
|
|
* Creates a new socket for the given `nsp`.
|
|
*
|
|
* @return {Socket}
|
|
* @public
|
|
*/
|
|
socket(nsp, opts) {
|
|
let socket = this.nsps[nsp];
|
|
if (!socket) {
|
|
socket = new socket_js_1.Socket(this, nsp, opts);
|
|
this.nsps[nsp] = socket;
|
|
}
|
|
else if (this._autoConnect && !socket.active) {
|
|
socket.connect();
|
|
}
|
|
return socket;
|
|
}
|
|
/**
|
|
* Called upon a socket close.
|
|
*
|
|
* @param socket
|
|
* @private
|
|
*/
|
|
_destroy(socket) {
|
|
const nsps = Object.keys(this.nsps);
|
|
for (const nsp of nsps) {
|
|
const socket = this.nsps[nsp];
|
|
if (socket.active) {
|
|
debug("socket %s is still active, skipping close", nsp);
|
|
return;
|
|
}
|
|
}
|
|
this._close();
|
|
}
|
|
/**
|
|
* Writes a packet.
|
|
*
|
|
* @param packet
|
|
* @private
|
|
*/
|
|
_packet(packet) {
|
|
debug("writing packet %j", packet);
|
|
const encodedPackets = this.encoder.encode(packet);
|
|
for (let i = 0; i < encodedPackets.length; i++) {
|
|
this.engine.write(encodedPackets[i], packet.options);
|
|
}
|
|
}
|
|
/**
|
|
* Clean up transport subscriptions and packet buffer.
|
|
*
|
|
* @private
|
|
*/
|
|
cleanup() {
|
|
debug("cleanup");
|
|
this.subs.forEach((subDestroy) => subDestroy());
|
|
this.subs.length = 0;
|
|
this.decoder.destroy();
|
|
}
|
|
/**
|
|
* Close the current socket.
|
|
*
|
|
* @private
|
|
*/
|
|
_close() {
|
|
debug("disconnect");
|
|
this.skipReconnect = true;
|
|
this._reconnecting = false;
|
|
this.onclose("forced close");
|
|
}
|
|
/**
|
|
* Alias for close()
|
|
*
|
|
* @private
|
|
*/
|
|
disconnect() {
|
|
return this._close();
|
|
}
|
|
/**
|
|
* Called when:
|
|
*
|
|
* - the low-level engine is closed
|
|
* - the parser encountered a badly formatted packet
|
|
* - all sockets are disconnected
|
|
*
|
|
* @private
|
|
*/
|
|
onclose(reason, description) {
|
|
var _a;
|
|
debug("closed due to %s", reason);
|
|
this.cleanup();
|
|
(_a = this.engine) === null || _a === void 0 ? void 0 : _a.close();
|
|
this.backoff.reset();
|
|
this._readyState = "closed";
|
|
this.emitReserved("close", reason, description);
|
|
if (this._reconnection && !this.skipReconnect) {
|
|
this.reconnect();
|
|
}
|
|
}
|
|
/**
|
|
* Attempt a reconnection.
|
|
*
|
|
* @private
|
|
*/
|
|
reconnect() {
|
|
if (this._reconnecting || this.skipReconnect)
|
|
return this;
|
|
const self = this;
|
|
if (this.backoff.attempts >= this._reconnectionAttempts) {
|
|
debug("reconnect failed");
|
|
this.backoff.reset();
|
|
this.emitReserved("reconnect_failed");
|
|
this._reconnecting = false;
|
|
}
|
|
else {
|
|
const delay = this.backoff.duration();
|
|
debug("will wait %dms before reconnect attempt", delay);
|
|
this._reconnecting = true;
|
|
const timer = this.setTimeoutFn(() => {
|
|
if (self.skipReconnect)
|
|
return;
|
|
debug("attempting reconnect");
|
|
this.emitReserved("reconnect_attempt", self.backoff.attempts);
|
|
// check again for the case socket closed in above events
|
|
if (self.skipReconnect)
|
|
return;
|
|
self.open((err) => {
|
|
if (err) {
|
|
debug("reconnect attempt error");
|
|
self._reconnecting = false;
|
|
self.reconnect();
|
|
this.emitReserved("reconnect_error", err);
|
|
}
|
|
else {
|
|
debug("reconnect success");
|
|
self.onreconnect();
|
|
}
|
|
});
|
|
}, delay);
|
|
if (this.opts.autoUnref) {
|
|
timer.unref();
|
|
}
|
|
this.subs.push(() => {
|
|
this.clearTimeoutFn(timer);
|
|
});
|
|
}
|
|
}
|
|
/**
|
|
* Called upon successful reconnect.
|
|
*
|
|
* @private
|
|
*/
|
|
onreconnect() {
|
|
const attempt = this.backoff.attempts;
|
|
this._reconnecting = false;
|
|
this.backoff.reset();
|
|
this.emitReserved("reconnect", attempt);
|
|
}
|
|
}
|
|
manager.Manager = Manager$1;
|
|
|
|
cjs$3.exports;
|
|
|
|
(function (module, exports) {
|
|
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.WebTransport = exports.WebSocket = exports.NodeWebSocket = exports.XHR = exports.NodeXHR = exports.Fetch = exports.Socket = exports.Manager = exports.protocol = void 0;
|
|
exports.io = lookup;
|
|
exports.connect = lookup;
|
|
exports.default = lookup;
|
|
const url_js_1 = url$1;
|
|
const manager_js_1 = manager;
|
|
Object.defineProperty(exports, "Manager", { enumerable: true, get: function () { return manager_js_1.Manager; } });
|
|
const socket_js_1 = socket$1;
|
|
Object.defineProperty(exports, "Socket", { enumerable: true, get: function () { return socket_js_1.Socket; } });
|
|
const debug_1 = __importDefault(browserExports); // debug()
|
|
const debug = (0, debug_1.default)("socket.io-client"); // debug()
|
|
/**
|
|
* Managers cache.
|
|
*/
|
|
const cache = {};
|
|
function lookup(uri, opts) {
|
|
if (typeof uri === "object") {
|
|
opts = uri;
|
|
uri = undefined;
|
|
}
|
|
opts = opts || {};
|
|
const parsed = (0, url_js_1.url)(uri, opts.path || "/socket.io");
|
|
const source = parsed.source;
|
|
const id = parsed.id;
|
|
const path = parsed.path;
|
|
const sameNamespace = cache[id] && path in cache[id]["nsps"];
|
|
const newConnection = opts.forceNew ||
|
|
opts["force new connection"] ||
|
|
false === opts.multiplex ||
|
|
sameNamespace;
|
|
let io;
|
|
if (newConnection) {
|
|
debug("ignoring socket cache for %s", source);
|
|
io = new manager_js_1.Manager(source, opts);
|
|
}
|
|
else {
|
|
if (!cache[id]) {
|
|
debug("new io instance for %s", source);
|
|
cache[id] = new manager_js_1.Manager(source, opts);
|
|
}
|
|
io = cache[id];
|
|
}
|
|
if (parsed.query && !opts.query) {
|
|
opts.query = parsed.queryKey;
|
|
}
|
|
return io.socket(parsed.path, opts);
|
|
}
|
|
// so that "lookup" can be used both as a function (e.g. `io(...)`) and as a
|
|
// namespace (e.g. `io.connect(...)`), for backward compatibility
|
|
Object.assign(lookup, {
|
|
Manager: manager_js_1.Manager,
|
|
Socket: socket_js_1.Socket,
|
|
io: lookup,
|
|
connect: lookup,
|
|
});
|
|
/**
|
|
* Protocol version.
|
|
*
|
|
* @public
|
|
*/
|
|
var socket_io_parser_1 = cjs;
|
|
Object.defineProperty(exports, "protocol", { enumerable: true, get: function () { return socket_io_parser_1.protocol; } });
|
|
var engine_io_client_1 = cjs$2;
|
|
Object.defineProperty(exports, "Fetch", { enumerable: true, get: function () { return engine_io_client_1.Fetch; } });
|
|
Object.defineProperty(exports, "NodeXHR", { enumerable: true, get: function () { return engine_io_client_1.NodeXHR; } });
|
|
Object.defineProperty(exports, "XHR", { enumerable: true, get: function () { return engine_io_client_1.XHR; } });
|
|
Object.defineProperty(exports, "NodeWebSocket", { enumerable: true, get: function () { return engine_io_client_1.NodeWebSocket; } });
|
|
Object.defineProperty(exports, "WebSocket", { enumerable: true, get: function () { return engine_io_client_1.WebSocket; } });
|
|
Object.defineProperty(exports, "WebTransport", { enumerable: true, get: function () { return engine_io_client_1.WebTransport; } });
|
|
|
|
module.exports = lookup;
|
|
} (cjs$3, cjs$3.exports));
|
|
|
|
var cjsExports = cjs$3.exports;
|
|
|
|
var menuBar = {};
|
|
|
|
var Index = {};
|
|
|
|
var name = "morphux";
|
|
var version = "2025.11.5";
|
|
var description = "Standardized Morphix UX framework.";
|
|
var main = "dist/Index.js";
|
|
var types = "dist/index.d.ts";
|
|
var scripts = {
|
|
build: "sass scss/index.scss style.css && tsc && npm run bundle",
|
|
"watch-ts": "tsc -w",
|
|
"watch-scss": "sass scss/index.scss style.css -w",
|
|
"watch-rollup": "rollup -c --watch",
|
|
bundle: "npm run bundle-ts && npm run bundle-defenitions",
|
|
"bundle-ts": "rollup --config rollup.config.js",
|
|
"bundle-defenitions": "dts-bundle-generator dist/index.d.ts -o bundle.d.ts --no-check"
|
|
};
|
|
var author = "";
|
|
var license = "ISC";
|
|
var dependencies = {
|
|
"@egjs/hammerjs": "^2.0.17",
|
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
"@rollup/plugin-json": "^6.1.0",
|
|
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
"@types/node": "^20.12.8",
|
|
"material-symbols": "^0.17.4",
|
|
rollup: "^2.79.1",
|
|
"rollup-plugin-terser": "^7.0.2",
|
|
sortablejs: "^1.2.1"
|
|
};
|
|
var devDependencies = {
|
|
"@types/sortablejs": "^1.15.8",
|
|
"dts-bundle-generator": "^9.5.1"
|
|
};
|
|
var require$$0$1 = {
|
|
name: name,
|
|
version: version,
|
|
description: description,
|
|
main: main,
|
|
types: types,
|
|
scripts: scripts,
|
|
author: author,
|
|
license: license,
|
|
dependencies: dependencies,
|
|
devDependencies: devDependencies
|
|
};
|
|
|
|
var Morph_Components = {};
|
|
|
|
var Component_Button = {};
|
|
|
|
var CE = {};
|
|
|
|
Object.defineProperty(CE, "__esModule", { value: true });
|
|
CE.ce = void 0;
|
|
function ce(tagName, classList, attributes, innerText, innerHTML, style) {
|
|
var _a;
|
|
var element = document.createElement(tagName);
|
|
if (classList)
|
|
if (typeof classList == 'string')
|
|
element.classList.add(classList);
|
|
else
|
|
(_a = element.classList).add.apply(_a, classList);
|
|
if (attributes)
|
|
for (var key in attributes)
|
|
if (element[key] != undefined)
|
|
element[key] = attributes[key];
|
|
else
|
|
element.setAttribute(key, String(attributes[key]));
|
|
if (innerText)
|
|
element.innerText = innerText;
|
|
if (innerHTML)
|
|
element.innerHTML = innerHTML;
|
|
if (style != undefined)
|
|
for (var key in style)
|
|
element.style[key] = style[key];
|
|
return element;
|
|
}
|
|
CE.ce = ce;
|
|
|
|
var baseComponent = {};
|
|
|
|
Object.defineProperty(baseComponent, "__esModule", { value: true });
|
|
baseComponent.MUXComponent = void 0;
|
|
var MUXComponent = /** @class */ (function () {
|
|
function MUXComponent() {
|
|
this._events = {};
|
|
}
|
|
MUXComponent.prototype.callEvent = function (event) {
|
|
var _a;
|
|
var args = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
args[_i - 1] = arguments[_i];
|
|
}
|
|
if (this._events[event] != undefined) {
|
|
(_a = this._events)[event].apply(_a, args);
|
|
}
|
|
};
|
|
MUXComponent.prototype.on = function (event, callback) {
|
|
this._events[event] = callback;
|
|
};
|
|
MUXComponent.prototype.destroy = function () {
|
|
this.container.remove();
|
|
};
|
|
return MUXComponent;
|
|
}());
|
|
baseComponent.MUXComponent = MUXComponent;
|
|
|
|
var __extends$9 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Button, "__esModule", { value: true });
|
|
Component_Button.ComponentButton = void 0;
|
|
var CE_1$9 = CE;
|
|
var baseComponent_1$9 = baseComponent;
|
|
var ComponentButton = /** @class */ (function (_super) {
|
|
__extends$9(ComponentButton, _super);
|
|
function ComponentButton(options) {
|
|
var _a, _b;
|
|
var _this = _super.call(this) || this;
|
|
_this.mode = 'normal';
|
|
_this.mode = (_a = options === null || options === void 0 ? void 0 : options.mode) !== null && _a !== void 0 ? _a : 'normal';
|
|
var target = (_b = options === null || options === void 0 ? void 0 : options.target) !== null && _b !== void 0 ? _b : '';
|
|
_this.container = (0, CE_1$9.ce)(typeof target === 'string' ? 'a' : 'div', [
|
|
'mux_button',
|
|
"mux_".concat(_this.mode),
|
|
]);
|
|
if ((options === null || options === void 0 ? void 0 : options.materialIcon) != undefined)
|
|
_this.container.append((0, CE_1$9.ce)('span', 'material-symbols-outlined', null, options.materialIcon));
|
|
_this.container.appendChild((0, CE_1$9.ce)('span', ['mux_text', 'mux_normal'], null, options.content));
|
|
_this.container.onclick = function (e) {
|
|
e.preventDefault();
|
|
if (_this.mode == 'disabled')
|
|
return;
|
|
if (typeof target === 'function')
|
|
target();
|
|
else {
|
|
if ((options === null || options === void 0 ? void 0 : options.openInNewTab) == true)
|
|
window.open(target, '_blank');
|
|
else
|
|
window.location.href = target;
|
|
}
|
|
};
|
|
if (typeof target === 'string')
|
|
_this.container.setAttribute('href', target);
|
|
return _this;
|
|
}
|
|
ComponentButton.prototype.updateContent = function (content) {
|
|
this.container.innerHTML = content;
|
|
};
|
|
ComponentButton.prototype.updateMode = function (mode) {
|
|
this.mode = mode;
|
|
this.container.classList.remove('mux_normal');
|
|
this.container.classList.remove('mux_highlight');
|
|
this.container.classList.remove('mux_secondary');
|
|
this.container.classList.remove('mux_disabled');
|
|
this.container.classList.add("mux_".concat(mode));
|
|
};
|
|
return ComponentButton;
|
|
}(baseComponent_1$9.MUXComponent));
|
|
Component_Button.ComponentButton = ComponentButton;
|
|
|
|
var Component_Cards = {};
|
|
|
|
var TextHighlighter = {};
|
|
|
|
Object.defineProperty(TextHighlighter, "__esModule", { value: true });
|
|
TextHighlighter.generateTextHighlights = void 0;
|
|
function generateTextHighlights(originalText, additionalClassnames) {
|
|
var _a;
|
|
if (additionalClassnames === void 0) { additionalClassnames = []; }
|
|
var div = document.createElement('div');
|
|
(_a = div.classList).add.apply(_a, additionalClassnames);
|
|
var remainingStr = originalText;
|
|
var regex = /\<(.*?)\>/;
|
|
while (remainingStr.length) {
|
|
var match = regex.exec(remainingStr);
|
|
if (match) {
|
|
var normalText = remainingStr.substring(0, match.index);
|
|
if (normalText) {
|
|
var normalSpan = document.createElement('span');
|
|
normalSpan.className = 'normal';
|
|
normalSpan.textContent = normalText;
|
|
div.appendChild(normalSpan);
|
|
}
|
|
var highlightSpan = document.createElement('span');
|
|
highlightSpan.className = 'highlight';
|
|
highlightSpan.textContent = match[1];
|
|
div.appendChild(highlightSpan);
|
|
remainingStr = remainingStr.substring(match.index + match[0].length);
|
|
}
|
|
else {
|
|
var normalSpan = document.createElement('span');
|
|
normalSpan.className = 'normal';
|
|
normalSpan.textContent = remainingStr;
|
|
div.appendChild(normalSpan);
|
|
break;
|
|
}
|
|
}
|
|
return div;
|
|
}
|
|
TextHighlighter.generateTextHighlights = generateTextHighlights;
|
|
|
|
var Sortable$2 = {exports: {}};
|
|
|
|
/**!
|
|
* Sortable
|
|
* @author RubaXa <trash@rubaxa.org>
|
|
* @license MIT
|
|
*/
|
|
Sortable$2.exports;
|
|
|
|
(function (module) {
|
|
(function (factory) {
|
|
|
|
{
|
|
module.exports = factory();
|
|
}
|
|
})(function () {
|
|
|
|
var dragEl,
|
|
ghostEl,
|
|
cloneEl,
|
|
rootEl,
|
|
nextEl,
|
|
|
|
scrollEl,
|
|
scrollParentEl,
|
|
|
|
lastEl,
|
|
lastCSS,
|
|
|
|
oldIndex,
|
|
newIndex,
|
|
|
|
activeGroup,
|
|
autoScroll = {},
|
|
|
|
tapEvt,
|
|
touchEvt,
|
|
|
|
/** @const */
|
|
RSPACE = /\s+/g,
|
|
|
|
expando = 'Sortable' + (new Date).getTime(),
|
|
|
|
win = window,
|
|
document = win.document,
|
|
parseInt = win.parseInt,
|
|
|
|
supportDraggable = !!('draggable' in document.createElement('div')),
|
|
|
|
_silent = false,
|
|
|
|
abs = Math.abs,
|
|
slice = [].slice,
|
|
|
|
touchDragOverListeners = [],
|
|
|
|
_autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) {
|
|
// Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
|
|
if (rootEl && options.scroll) {
|
|
var el,
|
|
rect,
|
|
sens = options.scrollSensitivity,
|
|
speed = options.scrollSpeed,
|
|
|
|
x = evt.clientX,
|
|
y = evt.clientY,
|
|
|
|
winWidth = window.innerWidth,
|
|
winHeight = window.innerHeight,
|
|
|
|
vx,
|
|
vy
|
|
;
|
|
|
|
// Delect scrollEl
|
|
if (scrollParentEl !== rootEl) {
|
|
scrollEl = options.scroll;
|
|
scrollParentEl = rootEl;
|
|
|
|
if (scrollEl === true) {
|
|
scrollEl = rootEl;
|
|
|
|
do {
|
|
if ((scrollEl.offsetWidth < scrollEl.scrollWidth) ||
|
|
(scrollEl.offsetHeight < scrollEl.scrollHeight)
|
|
) {
|
|
break;
|
|
}
|
|
/* jshint boss:true */
|
|
} while (scrollEl = scrollEl.parentNode);
|
|
}
|
|
}
|
|
|
|
if (scrollEl) {
|
|
el = scrollEl;
|
|
rect = scrollEl.getBoundingClientRect();
|
|
vx = (abs(rect.right - x) <= sens) - (abs(rect.left - x) <= sens);
|
|
vy = (abs(rect.bottom - y) <= sens) - (abs(rect.top - y) <= sens);
|
|
}
|
|
|
|
|
|
if (!(vx || vy)) {
|
|
vx = (winWidth - x <= sens) - (x <= sens);
|
|
vy = (winHeight - y <= sens) - (y <= sens);
|
|
|
|
/* jshint expr:true */
|
|
(vx || vy) && (el = win);
|
|
}
|
|
|
|
|
|
if (autoScroll.vx !== vx || autoScroll.vy !== vy || autoScroll.el !== el) {
|
|
autoScroll.el = el;
|
|
autoScroll.vx = vx;
|
|
autoScroll.vy = vy;
|
|
|
|
clearInterval(autoScroll.pid);
|
|
|
|
if (el) {
|
|
autoScroll.pid = setInterval(function () {
|
|
if (el === win) {
|
|
win.scrollTo(win.pageXOffset + vx * speed, win.pageYOffset + vy * speed);
|
|
} else {
|
|
vy && (el.scrollTop += vy * speed);
|
|
vx && (el.scrollLeft += vx * speed);
|
|
}
|
|
}, 24);
|
|
}
|
|
}
|
|
}
|
|
}, 30)
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
* @class Sortable
|
|
* @param {HTMLElement} el
|
|
* @param {Object} [options]
|
|
*/
|
|
function Sortable(el, options) {
|
|
this.el = el; // root element
|
|
this.options = options = _extend({}, options);
|
|
|
|
|
|
// Export instance
|
|
el[expando] = this;
|
|
|
|
|
|
// Default options
|
|
var defaults = {
|
|
group: Math.random(),
|
|
sort: true,
|
|
disabled: false,
|
|
store: null,
|
|
handle: null,
|
|
scroll: true,
|
|
scrollSensitivity: 30,
|
|
scrollSpeed: 10,
|
|
draggable: /[uo]l/i.test(el.nodeName) ? 'li' : '>*',
|
|
ghostClass: 'sortable-ghost',
|
|
ignore: 'a, img',
|
|
filter: null,
|
|
animation: 0,
|
|
setData: function (dataTransfer, dragEl) {
|
|
dataTransfer.setData('Text', dragEl.textContent);
|
|
},
|
|
dropBubble: false,
|
|
dragoverBubble: false,
|
|
dataIdAttr: 'data-id',
|
|
delay: 0
|
|
};
|
|
|
|
|
|
// Set default options
|
|
for (var name in defaults) {
|
|
!(name in options) && (options[name] = defaults[name]);
|
|
}
|
|
|
|
|
|
var group = options.group;
|
|
|
|
if (!group || typeof group != 'object') {
|
|
group = options.group = { name: group };
|
|
}
|
|
|
|
|
|
['pull', 'put'].forEach(function (key) {
|
|
if (!(key in group)) {
|
|
group[key] = true;
|
|
}
|
|
});
|
|
|
|
|
|
options.groups = ' ' + group.name + (group.put.join ? ' ' + group.put.join(' ') : '') + ' ';
|
|
|
|
|
|
// Bind all private methods
|
|
for (var fn in this) {
|
|
if (fn.charAt(0) === '_') {
|
|
this[fn] = _bind(this, this[fn]);
|
|
}
|
|
}
|
|
|
|
|
|
// Bind events
|
|
_on(el, 'mousedown', this._onTapStart);
|
|
_on(el, 'touchstart', this._onTapStart);
|
|
|
|
_on(el, 'dragover', this);
|
|
_on(el, 'dragenter', this);
|
|
|
|
touchDragOverListeners.push(this._onDragOver);
|
|
|
|
// Restore sorting
|
|
options.store && this.sort(options.store.get(this));
|
|
}
|
|
|
|
|
|
Sortable.prototype = /** @lends Sortable.prototype */ {
|
|
constructor: Sortable,
|
|
|
|
_onTapStart: function (/** Event|TouchEvent */evt) {
|
|
var _this = this,
|
|
el = this.el,
|
|
options = this.options,
|
|
type = evt.type,
|
|
touch = evt.touches && evt.touches[0],
|
|
target = (touch || evt).target,
|
|
originalTarget = target,
|
|
filter = options.filter;
|
|
|
|
|
|
if (type === 'mousedown' && evt.button !== 0 || options.disabled) {
|
|
return; // only left button or enabled
|
|
}
|
|
|
|
target = _closest(target, options.draggable, el);
|
|
|
|
if (!target) {
|
|
return;
|
|
}
|
|
|
|
// get the index of the dragged element within its parent
|
|
oldIndex = _index(target);
|
|
|
|
// Check filter
|
|
if (typeof filter === 'function') {
|
|
if (filter.call(this, evt, target, this)) {
|
|
_dispatchEvent(_this, originalTarget, 'filter', target, el, oldIndex);
|
|
evt.preventDefault();
|
|
return; // cancel dnd
|
|
}
|
|
}
|
|
else if (filter) {
|
|
filter = filter.split(',').some(function (criteria) {
|
|
criteria = _closest(originalTarget, criteria.trim(), el);
|
|
|
|
if (criteria) {
|
|
_dispatchEvent(_this, criteria, 'filter', target, el, oldIndex);
|
|
return true;
|
|
}
|
|
});
|
|
|
|
if (filter) {
|
|
evt.preventDefault();
|
|
return; // cancel dnd
|
|
}
|
|
}
|
|
|
|
|
|
if (options.handle && !_closest(originalTarget, options.handle, el)) {
|
|
return;
|
|
}
|
|
|
|
|
|
// Prepare `dragstart`
|
|
this._prepareDragStart(evt, touch, target);
|
|
},
|
|
|
|
_prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
|
|
var _this = this,
|
|
el = _this.el,
|
|
options = _this.options,
|
|
ownerDocument = el.ownerDocument,
|
|
dragStartFn;
|
|
|
|
if (target && !dragEl && (target.parentNode === el)) {
|
|
tapEvt = evt;
|
|
|
|
rootEl = el;
|
|
dragEl = target;
|
|
nextEl = dragEl.nextSibling;
|
|
activeGroup = options.group;
|
|
|
|
dragStartFn = function () {
|
|
// Delayed drag has been triggered
|
|
// we can re-enable the events: touchmove/mousemove
|
|
_this._disableDelayedDrag();
|
|
|
|
// Make the element draggable
|
|
dragEl.draggable = true;
|
|
|
|
// Disable "draggable"
|
|
options.ignore.split(',').forEach(function (criteria) {
|
|
_find(dragEl, criteria.trim(), _disableDraggable);
|
|
});
|
|
|
|
// Bind the events: dragstart/dragend
|
|
_this._triggerDragStart(touch);
|
|
};
|
|
|
|
_on(ownerDocument, 'mouseup', _this._onDrop);
|
|
_on(ownerDocument, 'touchend', _this._onDrop);
|
|
_on(ownerDocument, 'touchcancel', _this._onDrop);
|
|
|
|
if (options.delay) {
|
|
// If the user moves the pointer before the delay has been reached:
|
|
// disable the delayed drag
|
|
_on(ownerDocument, 'mousemove', _this._disableDelayedDrag);
|
|
_on(ownerDocument, 'touchmove', _this._disableDelayedDrag);
|
|
|
|
_this._dragStartTimer = setTimeout(dragStartFn, options.delay);
|
|
} else {
|
|
dragStartFn();
|
|
}
|
|
}
|
|
},
|
|
|
|
_disableDelayedDrag: function () {
|
|
var ownerDocument = this.el.ownerDocument;
|
|
|
|
clearTimeout(this._dragStartTimer);
|
|
|
|
_off(ownerDocument, 'mousemove', this._disableDelayedDrag);
|
|
_off(ownerDocument, 'touchmove', this._disableDelayedDrag);
|
|
},
|
|
|
|
_triggerDragStart: function (/** Touch */touch) {
|
|
if (touch) {
|
|
// Touch device support
|
|
tapEvt = {
|
|
target: dragEl,
|
|
clientX: touch.clientX,
|
|
clientY: touch.clientY
|
|
};
|
|
|
|
this._onDragStart(tapEvt, 'touch');
|
|
}
|
|
else if (!supportDraggable) {
|
|
this._onDragStart(tapEvt, true);
|
|
}
|
|
else {
|
|
_on(dragEl, 'dragend', this);
|
|
_on(rootEl, 'dragstart', this._onDragStart);
|
|
}
|
|
|
|
try {
|
|
if (document.selection) {
|
|
document.selection.empty();
|
|
} else {
|
|
window.getSelection().removeAllRanges();
|
|
}
|
|
} catch (err) {
|
|
}
|
|
},
|
|
|
|
_dragStarted: function () {
|
|
if (rootEl && dragEl) {
|
|
// Apply effect
|
|
_toggleClass(dragEl, this.options.ghostClass, true);
|
|
|
|
Sortable.active = this;
|
|
|
|
// Drag start event
|
|
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex);
|
|
}
|
|
},
|
|
|
|
_emulateDragOver: function () {
|
|
if (touchEvt) {
|
|
_css(ghostEl, 'display', 'none');
|
|
|
|
var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY),
|
|
parent = target,
|
|
groupName = ' ' + this.options.group.name + '',
|
|
i = touchDragOverListeners.length;
|
|
|
|
if (parent) {
|
|
do {
|
|
if (parent[expando] && parent[expando].options.groups.indexOf(groupName) > -1) {
|
|
while (i--) {
|
|
touchDragOverListeners[i]({
|
|
clientX: touchEvt.clientX,
|
|
clientY: touchEvt.clientY,
|
|
target: target,
|
|
rootEl: parent
|
|
});
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
target = parent; // store last element
|
|
}
|
|
/* jshint boss:true */
|
|
while (parent = parent.parentNode);
|
|
}
|
|
|
|
_css(ghostEl, 'display', '');
|
|
}
|
|
},
|
|
|
|
|
|
_onTouchMove: function (/**TouchEvent*/evt) {
|
|
if (tapEvt) {
|
|
var touch = evt.touches ? evt.touches[0] : evt,
|
|
dx = touch.clientX - tapEvt.clientX,
|
|
dy = touch.clientY - tapEvt.clientY,
|
|
translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)';
|
|
|
|
touchEvt = touch;
|
|
|
|
_css(ghostEl, 'webkitTransform', translate3d);
|
|
_css(ghostEl, 'mozTransform', translate3d);
|
|
_css(ghostEl, 'msTransform', translate3d);
|
|
_css(ghostEl, 'transform', translate3d);
|
|
|
|
evt.preventDefault();
|
|
}
|
|
},
|
|
|
|
|
|
_onDragStart: function (/**Event*/evt, /**boolean*/useFallback) {
|
|
var dataTransfer = evt.dataTransfer,
|
|
options = this.options;
|
|
|
|
this._offUpEvents();
|
|
|
|
if (activeGroup.pull == 'clone') {
|
|
cloneEl = dragEl.cloneNode(true);
|
|
_css(cloneEl, 'display', 'none');
|
|
rootEl.insertBefore(cloneEl, dragEl);
|
|
}
|
|
|
|
if (useFallback) {
|
|
var rect = dragEl.getBoundingClientRect(),
|
|
css = _css(dragEl),
|
|
ghostRect;
|
|
|
|
ghostEl = dragEl.cloneNode(true);
|
|
|
|
_css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10));
|
|
_css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10));
|
|
_css(ghostEl, 'width', rect.width);
|
|
_css(ghostEl, 'height', rect.height);
|
|
_css(ghostEl, 'opacity', '0.8');
|
|
_css(ghostEl, 'position', 'fixed');
|
|
_css(ghostEl, 'zIndex', '100000');
|
|
|
|
rootEl.appendChild(ghostEl);
|
|
|
|
// Fixing dimensions.
|
|
ghostRect = ghostEl.getBoundingClientRect();
|
|
_css(ghostEl, 'width', rect.width * 2 - ghostRect.width);
|
|
_css(ghostEl, 'height', rect.height * 2 - ghostRect.height);
|
|
|
|
if (useFallback === 'touch') {
|
|
// Bind touch events
|
|
_on(document, 'touchmove', this._onTouchMove);
|
|
_on(document, 'touchend', this._onDrop);
|
|
_on(document, 'touchcancel', this._onDrop);
|
|
} else {
|
|
// Old brwoser
|
|
_on(document, 'mousemove', this._onTouchMove);
|
|
_on(document, 'mouseup', this._onDrop);
|
|
}
|
|
|
|
this._loopId = setInterval(this._emulateDragOver, 150);
|
|
}
|
|
else {
|
|
if (dataTransfer) {
|
|
dataTransfer.effectAllowed = 'move';
|
|
options.setData && options.setData.call(this, dataTransfer, dragEl);
|
|
}
|
|
|
|
_on(document, 'drop', this);
|
|
}
|
|
|
|
setTimeout(this._dragStarted, 0);
|
|
},
|
|
|
|
_onDragOver: function (/**Event*/evt) {
|
|
var el = this.el,
|
|
target,
|
|
dragRect,
|
|
revert,
|
|
options = this.options,
|
|
group = options.group,
|
|
groupPut = group.put,
|
|
isOwner = (activeGroup === group),
|
|
canSort = options.sort;
|
|
|
|
if (evt.preventDefault !== void 0) {
|
|
evt.preventDefault();
|
|
!options.dragoverBubble && evt.stopPropagation();
|
|
}
|
|
|
|
if (activeGroup && !options.disabled &&
|
|
(isOwner
|
|
? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
|
|
: activeGroup.pull && groupPut && (
|
|
(activeGroup.name === group.name) || // by Name
|
|
(groupPut.indexOf && ~groupPut.indexOf(activeGroup.name)) // by Array
|
|
)
|
|
) &&
|
|
(evt.rootEl === void 0 || evt.rootEl === this.el) // touch fallback
|
|
) {
|
|
// Smart auto-scrolling
|
|
_autoScroll(evt, options, this.el);
|
|
|
|
if (_silent) {
|
|
return;
|
|
}
|
|
|
|
target = _closest(evt.target, options.draggable, el);
|
|
dragRect = dragEl.getBoundingClientRect();
|
|
|
|
|
|
if (revert) {
|
|
_cloneHide(true);
|
|
|
|
if (cloneEl || nextEl) {
|
|
rootEl.insertBefore(dragEl, cloneEl || nextEl);
|
|
}
|
|
else if (!canSort) {
|
|
rootEl.appendChild(dragEl);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
if ((el.children.length === 0) || (el.children[0] === ghostEl) ||
|
|
(el === evt.target) && (target = _ghostInBottom(el, evt))
|
|
) {
|
|
if (target) {
|
|
if (target.animated) {
|
|
return;
|
|
}
|
|
targetRect = target.getBoundingClientRect();
|
|
}
|
|
|
|
_cloneHide(isOwner);
|
|
|
|
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect) !== false) {
|
|
el.appendChild(dragEl);
|
|
this._animate(dragRect, dragEl);
|
|
target && this._animate(targetRect, target);
|
|
}
|
|
}
|
|
else if (target && !target.animated && target !== dragEl && (target.parentNode[expando] !== void 0)) {
|
|
if (lastEl !== target) {
|
|
lastEl = target;
|
|
lastCSS = _css(target);
|
|
}
|
|
|
|
|
|
var targetRect = target.getBoundingClientRect(),
|
|
width = targetRect.right - targetRect.left,
|
|
height = targetRect.bottom - targetRect.top,
|
|
floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display),
|
|
isWide = (target.offsetWidth > dragEl.offsetWidth),
|
|
isLong = (target.offsetHeight > dragEl.offsetHeight),
|
|
halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5,
|
|
nextSibling = target.nextElementSibling,
|
|
moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect),
|
|
after
|
|
;
|
|
|
|
if (moveVector !== false) {
|
|
_silent = true;
|
|
setTimeout(_unsilent, 30);
|
|
|
|
_cloneHide(isOwner);
|
|
|
|
if (moveVector === 1 || moveVector === -1) {
|
|
after = (moveVector === 1);
|
|
}
|
|
else if (floating) {
|
|
after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide;
|
|
} else {
|
|
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
|
|
}
|
|
|
|
if (after && !nextSibling) {
|
|
el.appendChild(dragEl);
|
|
} else {
|
|
target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
|
|
}
|
|
|
|
this._animate(dragRect, dragEl);
|
|
this._animate(targetRect, target);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
_animate: function (prevRect, target) {
|
|
var ms = this.options.animation;
|
|
|
|
if (ms) {
|
|
var currentRect = target.getBoundingClientRect();
|
|
|
|
_css(target, 'transition', 'none');
|
|
_css(target, 'transform', 'translate3d('
|
|
+ (prevRect.left - currentRect.left) + 'px,'
|
|
+ (prevRect.top - currentRect.top) + 'px,0)'
|
|
);
|
|
|
|
target.offsetWidth; // repaint
|
|
|
|
_css(target, 'transition', 'all ' + ms + 'ms');
|
|
_css(target, 'transform', 'translate3d(0,0,0)');
|
|
|
|
clearTimeout(target.animated);
|
|
target.animated = setTimeout(function () {
|
|
_css(target, 'transition', '');
|
|
_css(target, 'transform', '');
|
|
target.animated = false;
|
|
}, ms);
|
|
}
|
|
},
|
|
|
|
_offUpEvents: function () {
|
|
var ownerDocument = this.el.ownerDocument;
|
|
|
|
_off(document, 'touchmove', this._onTouchMove);
|
|
_off(ownerDocument, 'mouseup', this._onDrop);
|
|
_off(ownerDocument, 'touchend', this._onDrop);
|
|
_off(ownerDocument, 'touchcancel', this._onDrop);
|
|
},
|
|
|
|
_onDrop: function (/**Event*/evt) {
|
|
var el = this.el,
|
|
options = this.options;
|
|
|
|
clearInterval(this._loopId);
|
|
clearInterval(autoScroll.pid);
|
|
clearTimeout(this._dragStartTimer);
|
|
|
|
// Unbind events
|
|
_off(document, 'drop', this);
|
|
_off(document, 'mousemove', this._onTouchMove);
|
|
_off(el, 'dragstart', this._onDragStart);
|
|
|
|
this._offUpEvents();
|
|
|
|
if (evt) {
|
|
evt.preventDefault();
|
|
!options.dropBubble && evt.stopPropagation();
|
|
|
|
ghostEl && ghostEl.parentNode.removeChild(ghostEl);
|
|
|
|
if (dragEl) {
|
|
_off(dragEl, 'dragend', this);
|
|
|
|
_disableDraggable(dragEl);
|
|
_toggleClass(dragEl, this.options.ghostClass, false);
|
|
|
|
if (rootEl !== dragEl.parentNode) {
|
|
newIndex = _index(dragEl);
|
|
|
|
// drag from one list and drop into another
|
|
_dispatchEvent(null, dragEl.parentNode, 'sort', dragEl, rootEl, oldIndex, newIndex);
|
|
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
|
|
|
|
// Add event
|
|
_dispatchEvent(null, dragEl.parentNode, 'add', dragEl, rootEl, oldIndex, newIndex);
|
|
|
|
// Remove event
|
|
_dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex);
|
|
}
|
|
else {
|
|
// Remove clone
|
|
cloneEl && cloneEl.parentNode.removeChild(cloneEl);
|
|
|
|
if (dragEl.nextSibling !== nextEl) {
|
|
// Get the index of the dragged element within its parent
|
|
newIndex = _index(dragEl);
|
|
|
|
// drag & drop within the same list
|
|
_dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex);
|
|
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
|
|
}
|
|
}
|
|
|
|
if (Sortable.active) {
|
|
// Drag end event
|
|
_dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex);
|
|
|
|
// Save sorting
|
|
this.save();
|
|
}
|
|
}
|
|
|
|
// Nulling
|
|
rootEl =
|
|
dragEl =
|
|
ghostEl =
|
|
nextEl =
|
|
cloneEl =
|
|
|
|
scrollEl =
|
|
scrollParentEl =
|
|
|
|
tapEvt =
|
|
touchEvt =
|
|
|
|
lastEl =
|
|
lastCSS =
|
|
|
|
activeGroup =
|
|
Sortable.active = null;
|
|
}
|
|
},
|
|
|
|
|
|
handleEvent: function (/**Event*/evt) {
|
|
var type = evt.type;
|
|
|
|
if (type === 'dragover' || type === 'dragenter') {
|
|
if (dragEl) {
|
|
this._onDragOver(evt);
|
|
_globalDragOver(evt);
|
|
}
|
|
}
|
|
else if (type === 'drop' || type === 'dragend') {
|
|
this._onDrop(evt);
|
|
}
|
|
},
|
|
|
|
|
|
/**
|
|
* Serializes the item into an array of string.
|
|
* @returns {String[]}
|
|
*/
|
|
toArray: function () {
|
|
var order = [],
|
|
el,
|
|
children = this.el.children,
|
|
i = 0,
|
|
n = children.length,
|
|
options = this.options;
|
|
|
|
for (; i < n; i++) {
|
|
el = children[i];
|
|
if (_closest(el, options.draggable, this.el)) {
|
|
order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
|
|
}
|
|
}
|
|
|
|
return order;
|
|
},
|
|
|
|
|
|
/**
|
|
* Sorts the elements according to the array.
|
|
* @param {String[]} order order of the items
|
|
*/
|
|
sort: function (order) {
|
|
var items = {}, rootEl = this.el;
|
|
|
|
this.toArray().forEach(function (id, i) {
|
|
var el = rootEl.children[i];
|
|
|
|
if (_closest(el, this.options.draggable, rootEl)) {
|
|
items[id] = el;
|
|
}
|
|
}, this);
|
|
|
|
order.forEach(function (id) {
|
|
if (items[id]) {
|
|
rootEl.removeChild(items[id]);
|
|
rootEl.appendChild(items[id]);
|
|
}
|
|
});
|
|
},
|
|
|
|
|
|
/**
|
|
* Save the current sorting
|
|
*/
|
|
save: function () {
|
|
var store = this.options.store;
|
|
store && store.set(this);
|
|
},
|
|
|
|
|
|
/**
|
|
* For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
|
|
* @param {HTMLElement} el
|
|
* @param {String} [selector] default: `options.draggable`
|
|
* @returns {HTMLElement|null}
|
|
*/
|
|
closest: function (el, selector) {
|
|
return _closest(el, selector || this.options.draggable, this.el);
|
|
},
|
|
|
|
|
|
/**
|
|
* Set/get option
|
|
* @param {string} name
|
|
* @param {*} [value]
|
|
* @returns {*}
|
|
*/
|
|
option: function (name, value) {
|
|
var options = this.options;
|
|
|
|
if (value === void 0) {
|
|
return options[name];
|
|
} else {
|
|
options[name] = value;
|
|
}
|
|
},
|
|
|
|
|
|
/**
|
|
* Destroy
|
|
*/
|
|
destroy: function () {
|
|
var el = this.el;
|
|
|
|
el[expando] = null;
|
|
|
|
_off(el, 'mousedown', this._onTapStart);
|
|
_off(el, 'touchstart', this._onTapStart);
|
|
|
|
_off(el, 'dragover', this);
|
|
_off(el, 'dragenter', this);
|
|
|
|
// Remove draggable attributes
|
|
Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
|
|
el.removeAttribute('draggable');
|
|
});
|
|
|
|
touchDragOverListeners.splice(touchDragOverListeners.indexOf(this._onDragOver), 1);
|
|
|
|
this._onDrop();
|
|
|
|
this.el = el = null;
|
|
}
|
|
};
|
|
|
|
|
|
function _cloneHide(state) {
|
|
if (cloneEl && (cloneEl.state !== state)) {
|
|
_css(cloneEl, 'display', state ? 'none' : '');
|
|
!state && cloneEl.state && rootEl.insertBefore(cloneEl, dragEl);
|
|
cloneEl.state = state;
|
|
}
|
|
}
|
|
|
|
|
|
function _bind(ctx, fn) {
|
|
var args = slice.call(arguments, 2);
|
|
return fn.bind ? fn.bind.apply(fn, [ctx].concat(args)) : function () {
|
|
return fn.apply(ctx, args.concat(slice.call(arguments)));
|
|
};
|
|
}
|
|
|
|
|
|
function _closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx) {
|
|
if (el) {
|
|
ctx = ctx || document;
|
|
selector = selector.split('.');
|
|
|
|
var tag = selector.shift().toUpperCase(),
|
|
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');
|
|
|
|
do {
|
|
if (
|
|
(tag === '>*' && el.parentNode === ctx) || (
|
|
(tag === '' || el.nodeName.toUpperCase() == tag) &&
|
|
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
|
|
)
|
|
) {
|
|
return el;
|
|
}
|
|
}
|
|
while (el !== ctx && (el = el.parentNode));
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
function _globalDragOver(/**Event*/evt) {
|
|
evt.dataTransfer.dropEffect = 'move';
|
|
evt.preventDefault();
|
|
}
|
|
|
|
|
|
function _on(el, event, fn) {
|
|
el.addEventListener(event, fn, false);
|
|
}
|
|
|
|
|
|
function _off(el, event, fn) {
|
|
el.removeEventListener(event, fn, false);
|
|
}
|
|
|
|
|
|
function _toggleClass(el, name, state) {
|
|
if (el) {
|
|
if (el.classList) {
|
|
el.classList[state ? 'add' : 'remove'](name);
|
|
}
|
|
else {
|
|
var className = (' ' + el.className + ' ').replace(RSPACE, ' ').replace(' ' + name + ' ', ' ');
|
|
el.className = (className + (state ? ' ' + name : '')).replace(RSPACE, ' ');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function _css(el, prop, val) {
|
|
var style = el && el.style;
|
|
|
|
if (style) {
|
|
if (val === void 0) {
|
|
if (document.defaultView && document.defaultView.getComputedStyle) {
|
|
val = document.defaultView.getComputedStyle(el, '');
|
|
}
|
|
else if (el.currentStyle) {
|
|
val = el.currentStyle;
|
|
}
|
|
|
|
return prop === void 0 ? val : val[prop];
|
|
}
|
|
else {
|
|
if (!(prop in style)) {
|
|
prop = '-webkit-' + prop;
|
|
}
|
|
|
|
style[prop] = val + (typeof val === 'string' ? '' : 'px');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function _find(ctx, tagName, iterator) {
|
|
if (ctx) {
|
|
var list = ctx.getElementsByTagName(tagName), i = 0, n = list.length;
|
|
|
|
if (iterator) {
|
|
for (; i < n; i++) {
|
|
iterator(list[i], i);
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
|
|
|
|
function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) {
|
|
var evt = document.createEvent('Event'),
|
|
options = (sortable || rootEl[expando]).options,
|
|
onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
|
|
|
|
evt.initEvent(name, true, true);
|
|
|
|
evt.to = rootEl;
|
|
evt.from = fromEl || rootEl;
|
|
evt.item = targetEl || rootEl;
|
|
evt.clone = cloneEl;
|
|
|
|
evt.oldIndex = startIndex;
|
|
evt.newIndex = newIndex;
|
|
|
|
rootEl.dispatchEvent(evt);
|
|
|
|
if (options[onName]) {
|
|
options[onName].call(sortable, evt);
|
|
}
|
|
}
|
|
|
|
|
|
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect) {
|
|
var evt,
|
|
sortable = fromEl[expando],
|
|
onMoveFn = sortable.options.onMove,
|
|
retVal;
|
|
|
|
if (onMoveFn) {
|
|
evt = document.createEvent('Event');
|
|
evt.initEvent('move', true, true);
|
|
|
|
evt.to = toEl;
|
|
evt.from = fromEl;
|
|
evt.dragged = dragEl;
|
|
evt.draggedRect = dragRect;
|
|
evt.related = targetEl || toEl;
|
|
evt.relatedRect = targetRect || toEl.getBoundingClientRect();
|
|
|
|
retVal = onMoveFn.call(sortable, evt);
|
|
}
|
|
|
|
return retVal;
|
|
}
|
|
|
|
|
|
function _disableDraggable(el) {
|
|
el.draggable = false;
|
|
}
|
|
|
|
|
|
function _unsilent() {
|
|
_silent = false;
|
|
}
|
|
|
|
|
|
/** @returns {HTMLElement|false} */
|
|
function _ghostInBottom(el, evt) {
|
|
var lastEl = el.lastElementChild,
|
|
rect = lastEl.getBoundingClientRect();
|
|
|
|
return (evt.clientY - (rect.top + rect.height) > 5) && lastEl; // min delta
|
|
}
|
|
|
|
|
|
/**
|
|
* Generate id
|
|
* @param {HTMLElement} el
|
|
* @returns {String}
|
|
* @private
|
|
*/
|
|
function _generateId(el) {
|
|
var str = el.tagName + el.className + el.src + el.href + el.textContent,
|
|
i = str.length,
|
|
sum = 0;
|
|
|
|
while (i--) {
|
|
sum += str.charCodeAt(i);
|
|
}
|
|
|
|
return sum.toString(36);
|
|
}
|
|
|
|
/**
|
|
* Returns the index of an element within its parent
|
|
* @param el
|
|
* @returns {number}
|
|
* @private
|
|
*/
|
|
function _index(/**HTMLElement*/el) {
|
|
var index = 0;
|
|
while (el && (el = el.previousElementSibling)) {
|
|
if (el.nodeName.toUpperCase() !== 'TEMPLATE') {
|
|
index++;
|
|
}
|
|
}
|
|
return index;
|
|
}
|
|
|
|
function _throttle(callback, ms) {
|
|
var args, _this;
|
|
|
|
return function () {
|
|
if (args === void 0) {
|
|
args = arguments;
|
|
_this = this;
|
|
|
|
setTimeout(function () {
|
|
if (args.length === 1) {
|
|
callback.call(_this, args[0]);
|
|
} else {
|
|
callback.apply(_this, args);
|
|
}
|
|
|
|
args = void 0;
|
|
}, ms);
|
|
}
|
|
};
|
|
}
|
|
|
|
function _extend(dst, src) {
|
|
if (dst && src) {
|
|
for (var key in src) {
|
|
if (src.hasOwnProperty(key)) {
|
|
dst[key] = src[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
return dst;
|
|
}
|
|
|
|
|
|
// Export utils
|
|
Sortable.utils = {
|
|
on: _on,
|
|
off: _off,
|
|
css: _css,
|
|
find: _find,
|
|
bind: _bind,
|
|
is: function (el, selector) {
|
|
return !!_closest(el, selector, el);
|
|
},
|
|
extend: _extend,
|
|
throttle: _throttle,
|
|
closest: _closest,
|
|
toggleClass: _toggleClass,
|
|
index: _index
|
|
};
|
|
|
|
|
|
Sortable.version = '1.2.1';
|
|
|
|
|
|
/**
|
|
* Create sortable instance
|
|
* @param {HTMLElement} el
|
|
* @param {Object} [options]
|
|
*/
|
|
Sortable.create = function (el, options) {
|
|
return new Sortable(el, options);
|
|
};
|
|
|
|
// Export
|
|
return Sortable;
|
|
});
|
|
} (Sortable$2));
|
|
|
|
var SortableExports = Sortable$2.exports;
|
|
|
|
var __extends$8 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Cards, "__esModule", { value: true });
|
|
Component_Cards.ComponentCards = void 0;
|
|
var CE_1$8 = CE;
|
|
var TextHighlighter_1 = TextHighlighter;
|
|
var baseComponent_1$8 = baseComponent;
|
|
var Sortable$1 = SortableExports;
|
|
var ComponentCards = /** @class */ (function (_super) {
|
|
__extends$8(ComponentCards, _super);
|
|
function ComponentCards(options) {
|
|
var _a, _b;
|
|
var _this = _super.call(this) || this;
|
|
_this.entries = {};
|
|
_this.container = (0, CE_1$8.ce)('div', 'mux_cards');
|
|
if (options.onePerRow === true)
|
|
_this.container.classList.add('mux_cards-oneperrow');
|
|
if (options.dragable !== false)
|
|
_this.sortable = new Sortable$1(_this.container, {
|
|
ghostClass: 'mux_cards-item-dragging',
|
|
onStart: function () {
|
|
_this.container.classList.add('mux_cards-dragging');
|
|
},
|
|
onEnd: function (evt) {
|
|
_this.container.classList.remove('mux_cards-dragging');
|
|
_this.callEvent('orderUpdated', _this.getOrder());
|
|
},
|
|
});
|
|
_this.highlightText = (_a = options === null || options === void 0 ? void 0 : options.highlightText) !== null && _a !== void 0 ? _a : false;
|
|
_this.setItems((_b = options === null || options === void 0 ? void 0 : options.items) !== null && _b !== void 0 ? _b : []);
|
|
return _this;
|
|
}
|
|
ComponentCards.prototype.setItems = function (items) {
|
|
var _this = this;
|
|
this.container.innerHTML = '';
|
|
this.entries = {};
|
|
items.forEach(function (item) { return _this.addItem(item); });
|
|
};
|
|
ComponentCards.prototype.addItem = function (item) {
|
|
var _this = this;
|
|
var _a, _b;
|
|
var element = (0, CE_1$8.ce)(item.href != undefined ? 'a' : 'div', 'mux_cards-item', {
|
|
uid: item.uniqueIdentifier,
|
|
});
|
|
if (item.href != undefined)
|
|
element.href = item.href;
|
|
if (item.click != undefined)
|
|
element.onclick = function () { return item.click(); };
|
|
if (item.tooltip != undefined)
|
|
element.title = item.title;
|
|
if (item.enabled == false)
|
|
element.classList.add('mux_cards-item-disabled');
|
|
if (item.uniqueIdentifier != undefined)
|
|
this.entries[item.uniqueIdentifier] = element;
|
|
if (item.thumbnail != null) {
|
|
var thumbnailType = (_a = item.thumbnailType) !== null && _a !== void 0 ? _a : 'image';
|
|
if (thumbnailType == 'image') {
|
|
element.appendChild((0, CE_1$8.ce)('img', 'mux_cards-item-thumbnail', {
|
|
src: item.thumbnail,
|
|
}));
|
|
}
|
|
else if (thumbnailType == 'frame') {
|
|
var ratio = (_b = item.thumbnailWidthRatio) !== null && _b !== void 0 ? _b : 1;
|
|
var frame = (0, CE_1$8.ce)('iframe', 'mux_cards-item-thumbnail', {
|
|
scrolling: 'no',
|
|
src: item.thumbnail,
|
|
});
|
|
element.appendChild(frame);
|
|
var scaleClock = setInterval(function () {
|
|
if (element == null ||
|
|
element.parentElement == null ||
|
|
frame == null)
|
|
return clearInterval(scaleClock);
|
|
frame.style.width = "".concat(frame.clientHeight * ratio, "px");
|
|
}, 100);
|
|
}
|
|
}
|
|
var info = (0, CE_1$8.ce)('div', 'mux_cards-item-info');
|
|
info.appendChild(this.highlightText
|
|
? (0, TextHighlighter_1.generateTextHighlights)(item.title, [
|
|
'mux_header',
|
|
'mux_small',
|
|
])
|
|
: (0, CE_1$8.ce)('div', ['mux_header', 'mux_small'], null, item.title));
|
|
if (item.sublines != undefined && item.sublines.length > 0)
|
|
item.sublines.forEach(function (subline) {
|
|
if (subline != null)
|
|
info.appendChild(_this.highlightText
|
|
? (0, TextHighlighter_1.generateTextHighlights)(subline, [
|
|
'mux_text',
|
|
'mux_small',
|
|
])
|
|
: (0, CE_1$8.ce)('div', ['mux_text', 'mux_small'], null, subline));
|
|
});
|
|
element.appendChild(info);
|
|
if (item.actions != undefined && item.actions.length > 0) {
|
|
var buttons = (0, CE_1$8.ce)('div', 'mux_cards-item-buttons');
|
|
item.actions.forEach(function (action) {
|
|
var buttonelem = (0, CE_1$8.ce)(action.href != undefined ? 'a' : 'div', 'mux_cards-item-button');
|
|
if (action.href != undefined)
|
|
buttonelem.href = action.href;
|
|
if (action.click != undefined)
|
|
buttonelem.onclick = function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
e.stopImmediatePropagation();
|
|
action.click();
|
|
};
|
|
if (action.tooltip != undefined)
|
|
buttonelem.title = action.tooltip;
|
|
buttonelem.appendChild((0, CE_1$8.ce)('span', 'material-symbols-outlined', null, action.materialIcon));
|
|
buttons.appendChild(buttonelem);
|
|
});
|
|
element.appendChild(buttons);
|
|
}
|
|
this.container.appendChild(element);
|
|
};
|
|
ComponentCards.prototype.removeItem = function (uniqueIdentifier) {
|
|
if (this.entries[uniqueIdentifier] != undefined) {
|
|
this.entries[uniqueIdentifier].parentElement.removeChild(this.entries[uniqueIdentifier]);
|
|
delete this.entries[uniqueIdentifier];
|
|
}
|
|
};
|
|
ComponentCards.prototype.hasItem = function (uniqueIdentifier) {
|
|
return this.entries[uniqueIdentifier] != undefined;
|
|
};
|
|
ComponentCards.prototype.clear = function () {
|
|
this.container.innerHTML = '';
|
|
this.entries = {};
|
|
};
|
|
ComponentCards.prototype.updateItemTitle = function (uniqueIdentifier, newTitle) {
|
|
if (this.entries[uniqueIdentifier] == undefined)
|
|
return;
|
|
var existingHeader = this.entries[uniqueIdentifier].querySelector('.mux_header');
|
|
var container = existingHeader.parentElement;
|
|
container.insertBefore(this.highlightText
|
|
? (0, TextHighlighter_1.generateTextHighlights)(newTitle, ['mux_header', 'mux_small'])
|
|
: (0, CE_1$8.ce)('div', ['mux_header', 'mux_small'], null, newTitle), existingHeader);
|
|
container.removeChild(existingHeader);
|
|
};
|
|
ComponentCards.prototype.updateSublines = function (uniqueIdentifier, newSublines) {
|
|
var _this = this;
|
|
if (this.entries[uniqueIdentifier] == undefined)
|
|
return;
|
|
var info = this.entries[uniqueIdentifier].querySelector('.mux_cards-item-info');
|
|
info.querySelectorAll('.mux_text.mux_small').forEach(function (existingSubline) {
|
|
return existingSubline.parentElement.removeChild(existingSubline);
|
|
});
|
|
if (newSublines != undefined && newSublines.length > 0)
|
|
newSublines.forEach(function (subline) {
|
|
info.appendChild(_this.highlightText
|
|
? (0, TextHighlighter_1.generateTextHighlights)(subline, [
|
|
'mux_text',
|
|
'mux_small',
|
|
])
|
|
: (0, CE_1$8.ce)('div', ['mux_text', 'mux_small'], null, subline));
|
|
});
|
|
};
|
|
ComponentCards.prototype.updateThumbnail = function (uniqueIdentifier, thumbnailSrc) {
|
|
if (this.entries[uniqueIdentifier] == undefined)
|
|
return;
|
|
var thumbnail = this.entries[uniqueIdentifier].querySelector('.mux_cards-item-thumbnail');
|
|
thumbnail.src = thumbnailSrc;
|
|
};
|
|
ComponentCards.prototype.getOrder = function () {
|
|
var order = [];
|
|
this.container
|
|
.querySelectorAll('.mux_cards-item')
|
|
.forEach(function (item) { return order.push(item.getAttribute('uid')); });
|
|
return order;
|
|
};
|
|
return ComponentCards;
|
|
}(baseComponent_1$8.MUXComponent));
|
|
Component_Cards.ComponentCards = ComponentCards;
|
|
|
|
var Component_ContextMenu = {};
|
|
|
|
var Morph_Keys = {};
|
|
|
|
var KeyBinderBase$1 = {};
|
|
|
|
var KeyBinderOverwrite$1 = {};
|
|
|
|
var __spreadArray$1 = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
|
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
if (ar || !(i in from)) {
|
|
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
ar[i] = from[i];
|
|
}
|
|
}
|
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
};
|
|
Object.defineProperty(KeyBinderOverwrite$1, "__esModule", { value: true });
|
|
KeyBinderOverwrite$1.KeyBinderOverwrite = void 0;
|
|
var KeyBinderOverwrite = /** @class */ (function () {
|
|
function KeyBinderOverwrite(id, KeyBinder) {
|
|
this.binds = {};
|
|
this.id = id;
|
|
this._KeyBinder = KeyBinder;
|
|
}
|
|
KeyBinderOverwrite.prototype.log = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (window.location.search.includes('debug'))
|
|
console.log.apply(console, __spreadArray$1(['[KeyBinder]'], args, false));
|
|
};
|
|
KeyBinderOverwrite.prototype.close = function () {
|
|
this._KeyBinder.closeOverwrite(this.id);
|
|
};
|
|
KeyBinderOverwrite.prototype.bind = function (key, callback, settings) {
|
|
if (settings == undefined)
|
|
settings = {};
|
|
var query = this._KeyBinder.createKeyQuery(key, settings.controlKey, settings.shiftKey, settings.altKey);
|
|
if (this.binds[query] != undefined)
|
|
return this.log("Unable to bind key query '".concat(query, "' in overwrite because it already has a bind"));
|
|
if ((settings === null || settings === void 0 ? void 0 : settings.disableInElementsWithTags) != undefined)
|
|
settings.disableInElementsWithTags =
|
|
settings.disableInElementsWithTags.map(function (tagname) {
|
|
return tagname.toUpperCase();
|
|
});
|
|
this.binds[query] = { callback: callback, key: key, settings: settings };
|
|
};
|
|
return KeyBinderOverwrite;
|
|
}());
|
|
KeyBinderOverwrite$1.KeyBinderOverwrite = KeyBinderOverwrite;
|
|
|
|
var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
|
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
if (ar || !(i in from)) {
|
|
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
ar[i] = from[i];
|
|
}
|
|
}
|
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
};
|
|
Object.defineProperty(KeyBinderBase$1, "__esModule", { value: true });
|
|
KeyBinderBase$1.KeyBinderBase = void 0;
|
|
var KeyBinderOverwrite_1 = KeyBinderOverwrite$1;
|
|
var KeyBinderBase = /** @class */ (function () {
|
|
function KeyBinderBase() {
|
|
this.binds = {};
|
|
this.overwrites = [];
|
|
this.log('Preparing KeyBinder');
|
|
this.registerListeners();
|
|
}
|
|
KeyBinderBase.prototype.log = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (window.location.search.includes('debug'))
|
|
console.log.apply(console, __spreadArray(['[KeyBinder]'], args, false));
|
|
};
|
|
KeyBinderBase.prototype.multiBind = function (keys, callback, settings) {
|
|
for (var i = 0; i < keys.length; i++)
|
|
this.bind(keys[i], callback, settings);
|
|
};
|
|
KeyBinderBase.prototype.bind = function (key, callback, settings) {
|
|
if (settings == undefined)
|
|
settings = {};
|
|
var query = this.createKeyQuery(key, settings.controlKey, settings.shiftKey, settings.altKey);
|
|
if (this.binds[query] != undefined)
|
|
return this.log("Unable to bind key query '".concat(query, "' because it already has a bind"));
|
|
if ((settings === null || settings === void 0 ? void 0 : settings.disableInElementsWithTags) != undefined)
|
|
settings.disableInElementsWithTags =
|
|
settings.disableInElementsWithTags.map(function (tagname) {
|
|
return tagname.toUpperCase();
|
|
});
|
|
this.binds[query] = { callback: callback, key: key, settings: settings };
|
|
};
|
|
KeyBinderBase.prototype.unbind = function (key, settings) {
|
|
if (settings == undefined)
|
|
settings = {};
|
|
var query = this.createKeyQuery(key, settings.controlKey, settings.shiftKey, settings.altKey);
|
|
if (this.binds[query] == undefined)
|
|
return this.log("Unable to unbind key query '".concat(query, "' because it has no bind"));
|
|
};
|
|
KeyBinderBase.prototype.createOverwrite = function () {
|
|
var id = this.generateOverwriteId();
|
|
var overwrite = new KeyBinderOverwrite_1.KeyBinderOverwrite(id, this);
|
|
this.overwrites.push(overwrite);
|
|
this.log("Overwrite with id '".concat(id, "' was created"));
|
|
return overwrite;
|
|
};
|
|
KeyBinderBase.prototype.closeOverwrite = function (id) {
|
|
for (var i = 0; i < this.overwrites.length; i++)
|
|
if (this.overwrites[i].id == id) {
|
|
this.overwrites.splice(i, 1);
|
|
this.log("Overwrite with id '".concat(id, "' was closed"));
|
|
return;
|
|
}
|
|
};
|
|
KeyBinderBase.prototype.createKeyQuery = function (key, ctrlKey, shiftKey, altKey) {
|
|
if (ctrlKey === void 0) { ctrlKey = false; }
|
|
if (shiftKey === void 0) { shiftKey = false; }
|
|
if (altKey === void 0) { altKey = false; }
|
|
var queryParts = [key.toLowerCase()];
|
|
if (ctrlKey)
|
|
queryParts.push('ctrl');
|
|
if (shiftKey)
|
|
queryParts.push('shft');
|
|
if (altKey)
|
|
queryParts.push('alt');
|
|
return queryParts.join(':');
|
|
};
|
|
KeyBinderBase.prototype.getAllBinds = function () {
|
|
return Array.from(new Set(this.overwrites
|
|
.map(function (overwrite) { return Object.keys(overwrite.binds); })
|
|
.concat(Object.keys(this.binds))
|
|
.flat()));
|
|
};
|
|
KeyBinderBase.prototype.getBindsOverview = function () {
|
|
return Object.values(this.binds).map(function (_a) {
|
|
var key = _a.key, settings = _a.settings;
|
|
var combo = [];
|
|
if (settings === null || settings === void 0 ? void 0 : settings.controlKey)
|
|
combo.push('Ctrl');
|
|
if (settings === null || settings === void 0 ? void 0 : settings.shiftKey)
|
|
combo.push('Shift');
|
|
if (settings === null || settings === void 0 ? void 0 : settings.altKey)
|
|
combo.push('Alt');
|
|
combo.push(key.length < 3 ? key.toUpperCase() : key);
|
|
return [combo.join('+'), settings === null || settings === void 0 ? void 0 : settings.name];
|
|
});
|
|
};
|
|
KeyBinderBase.prototype.generateOverwriteId = function () {
|
|
while (true) {
|
|
var id = (Math.random() + 1).toString(36).substring(7);
|
|
if (!this.overwriteIdExists(id))
|
|
return id;
|
|
}
|
|
};
|
|
KeyBinderBase.prototype.overwriteIdExists = function (id) {
|
|
for (var i = 0; i < this.overwrites.length; i++)
|
|
if (this.overwrites[i].id == id)
|
|
return true;
|
|
return false;
|
|
};
|
|
KeyBinderBase.prototype.registerListeners = function () {
|
|
var _this = this;
|
|
window.addEventListener('keydown', function (e) {
|
|
var _a;
|
|
var query = _this.createKeyQuery(e.key, e.ctrlKey || e.metaKey, e.shiftKey, e.altKey);
|
|
if (window.location.search.includes('keydebug'))
|
|
_this.log("Got keypress: ".concat(query));
|
|
var binds = _this.binds;
|
|
if (_this.overwrites.length > 0) {
|
|
binds = _this.overwrites[_this.overwrites.length - 1].binds;
|
|
}
|
|
if (binds[query] == undefined)
|
|
return;
|
|
var bind = binds[query];
|
|
if (((_a = bind === null || bind === void 0 ? void 0 : bind.settings) === null || _a === void 0 ? void 0 : _a.disableInElementsWithTags) != undefined &&
|
|
bind.settings.disableInElementsWithTags.includes(document.activeElement.tagName))
|
|
return;
|
|
e.preventDefault();
|
|
bind.callback();
|
|
});
|
|
};
|
|
return KeyBinderBase;
|
|
}());
|
|
KeyBinderBase$1.KeyBinderBase = KeyBinderBase;
|
|
|
|
Object.defineProperty(Morph_Keys, "__esModule", { value: true });
|
|
Morph_Keys.MorphKey = void 0;
|
|
var KeyBinderBase_1 = KeyBinderBase$1;
|
|
Morph_Keys.MorphKey = new KeyBinderBase_1.KeyBinderBase();
|
|
|
|
var __extends$7 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_ContextMenu, "__esModule", { value: true });
|
|
Component_ContextMenu.ComponentContextMenu = void 0;
|
|
var Morph_Keys_1 = Morph_Keys;
|
|
var CE_1$7 = CE;
|
|
var baseComponent_1$7 = baseComponent;
|
|
var ComponentContextMenu = /** @class */ (function (_super) {
|
|
__extends$7(ComponentContextMenu, _super);
|
|
function ComponentContextMenu(options) {
|
|
var _a, _b;
|
|
var _this = _super.call(this) || this;
|
|
_this.open = true;
|
|
_this.container = (0, CE_1$7.ce)('div', 'mux_contextmenu');
|
|
if ((options === null || options === void 0 ? void 0 : options.width) != undefined) {
|
|
_this.container.style.minWidth = "".concat(options.width, "px");
|
|
_this.container.style.width = "".concat(options.width, "px");
|
|
}
|
|
var align = (_a = options === null || options === void 0 ? void 0 : options.align) !== null && _a !== void 0 ? _a : 'center';
|
|
if ((options === null || options === void 0 ? void 0 : options.materialIconColor) != undefined)
|
|
_this.container.style.setProperty('--mux-contextmenu-iconcolor', options.materialIconColor);
|
|
_this.setItems((_b = options === null || options === void 0 ? void 0 : options.items) !== null && _b !== void 0 ? _b : [], options === null || options === void 0 ? void 0 : options.selected);
|
|
var parentContainer = document.body;
|
|
parentContainer.appendChild(_this.container);
|
|
_this.container.style.top = "".concat(options.y - parentContainer.getBoundingClientRect().top, "px");
|
|
var left = options.x;
|
|
var maxLeft = document.body.clientWidth - _this.container.clientWidth - 20;
|
|
var minLeft = 10;
|
|
if (align == 'center') {
|
|
left -= _this.container.clientWidth / 2;
|
|
_this.container.style.transformOrigin = 'top center';
|
|
}
|
|
else if (align == 'left') {
|
|
_this.container.style.transformOrigin = 'top left';
|
|
}
|
|
else if (align == 'right') {
|
|
left -= _this.container.clientWidth;
|
|
_this.container.style.transformOrigin = 'top right';
|
|
}
|
|
left = Math.min(left, maxLeft);
|
|
left = Math.max(left, minLeft);
|
|
var maxHeight = document.body.clientHeight - options.y - 20;
|
|
_this.container.style.left = "".concat(left, "px");
|
|
_this.container.style.transitionDuration = '.2s';
|
|
_this.container.style.transform = 'scale(1)';
|
|
_this.container.style.opacity = '1';
|
|
_this.container.style.maxHeight = "".concat(maxHeight, "px");
|
|
if ((options === null || options === void 0 ? void 0 : options.highlightedItem) != undefined &&
|
|
_this.container.querySelector("[uid=\"".concat(options.highlightedItem, "\"]")) != null) {
|
|
var selected = _this.container.querySelector("[uid=\"".concat(options.highlightedItem, "\"]"));
|
|
selected.classList.add('mux_contextmenu-item-selected');
|
|
setTimeout(function () {
|
|
selected.scrollIntoView();
|
|
}, 100);
|
|
}
|
|
if ((options === null || options === void 0 ? void 0 : options.selected) != undefined &&
|
|
_this.container.querySelector("[uid=\"".concat(options.selected, "\"]")) != null) {
|
|
var selected = _this.container.querySelector("[uid=\"".concat(options.selected, "\"]"));
|
|
setTimeout(function () {
|
|
selected.scrollIntoView({
|
|
block: 'center',
|
|
inline: 'center',
|
|
});
|
|
}, 100);
|
|
}
|
|
var delay = function (duration, callback) {
|
|
setTimeout(function () {
|
|
callback();
|
|
}, duration);
|
|
};
|
|
_this.handleClick = function (e) {
|
|
var _a, _b;
|
|
if (e.target == undefined)
|
|
return delay(100, function () { return _this.close('outside'); });
|
|
var target = e.target;
|
|
if (target.classList.length == 0)
|
|
return delay(100, function () { return _this.close('outsideclick'); });
|
|
if (!target.classList[0].startsWith('mux_contextmenu') &&
|
|
!((_b = (_a = target.parentElement) === null || _a === void 0 ? void 0 : _a.classList[0]) === null || _b === void 0 ? void 0 : _b.startsWith('mux_contextmenu')))
|
|
return delay(100, function () { return _this.close('outsideparentclick'); });
|
|
};
|
|
setTimeout(function () {
|
|
window.addEventListener('click', _this.handleClick);
|
|
window.addEventListener('mousedown', _this.handleClick);
|
|
window.addEventListener('touchstart', _this.handleClick);
|
|
}, 100);
|
|
_this.overwrite = Morph_Keys_1.MorphKey.createOverwrite();
|
|
if ((options === null || options === void 0 ? void 0 : options.highlightedItem) == undefined) {
|
|
_this.overwrite.bind('ArrowUp', function () {
|
|
var selected = _this.container.querySelector('.mux_contextmenu-item-selected');
|
|
if (selected == null) {
|
|
var elements = _this.container.querySelectorAll('.mux_contextmenu-item');
|
|
if (elements.length > 0) {
|
|
var first = elements[elements.length - 1];
|
|
first.classList.add('mux_contextmenu-item-selected');
|
|
first.scrollIntoView();
|
|
}
|
|
}
|
|
else {
|
|
var previous = selected.previousElementSibling;
|
|
if (previous != null) {
|
|
selected.classList.remove('mux_contextmenu-item-selected');
|
|
previous.classList.add('mux_contextmenu-item-selected');
|
|
previous.scrollIntoView();
|
|
}
|
|
}
|
|
});
|
|
_this.overwrite.bind('ArrowDown', function () {
|
|
var selected = _this.container.querySelector('.mux_contextmenu-item-selected');
|
|
if (selected == null) {
|
|
var elements = _this.container.querySelectorAll('.mux_contextmenu-item');
|
|
if (elements.length > 0) {
|
|
var first = elements[0];
|
|
first.classList.add('mux_contextmenu-item-selected');
|
|
first.scrollIntoView();
|
|
}
|
|
}
|
|
else {
|
|
var next = selected.nextElementSibling;
|
|
if (next != null) {
|
|
selected.classList.remove('mux_contextmenu-item-selected');
|
|
next.classList.add('mux_contextmenu-item-selected');
|
|
next.scrollIntoView();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
_this.overwrite.bind('Enter', function () {
|
|
var selected = _this.container.querySelector('.mux_contextmenu-item-selected');
|
|
if (selected != null) {
|
|
selected.click();
|
|
}
|
|
});
|
|
_this.overwrite.bind('Escape', function () {
|
|
_this.close('escape');
|
|
});
|
|
return _this;
|
|
}
|
|
ComponentContextMenu.prototype.close = function (origin, byClick) {
|
|
var _this = this;
|
|
if (origin === void 0) { origin = 'integrator?'; }
|
|
if (byClick === void 0) { byClick = false; }
|
|
this.overwrite.close();
|
|
this.open = false;
|
|
this.killSubContexts();
|
|
window.removeEventListener('click', this.handleClick);
|
|
window.removeEventListener('mousedown', this.handleClick);
|
|
window.removeEventListener('touchstart', this.handleClick);
|
|
this.callEvent('close', byClick, origin);
|
|
this.container.style.transform = 'scale(0)';
|
|
this.container.style.opacity = '0';
|
|
setTimeout(function () {
|
|
_this.destroy();
|
|
}, 200);
|
|
};
|
|
ComponentContextMenu.prototype.enable = function (uniqueIdentifier) {
|
|
if (this.container.querySelector("[uid=\"".concat(uniqueIdentifier, "\"]"))) {
|
|
var element = this.container.querySelector("[uid=\"".concat(uniqueIdentifier, "\"]"));
|
|
element.classList.remove('mux_contextmenu-item-disabled');
|
|
}
|
|
};
|
|
ComponentContextMenu.prototype.disable = function (uniqueIdentifier) {
|
|
if (this.container.querySelector("[uid=\"".concat(uniqueIdentifier, "\"]"))) {
|
|
var element = this.container.querySelector("[uid=\"".concat(uniqueIdentifier, "\"]"));
|
|
element.classList.add('mux_contextmenu-item-disabled');
|
|
}
|
|
};
|
|
ComponentContextMenu.prototype.isOpen = function () {
|
|
return this.open;
|
|
};
|
|
ComponentContextMenu.prototype.setItems = function (items, selectedId) {
|
|
var _this = this;
|
|
this.container.innerHTML = '';
|
|
items.forEach(function (item) {
|
|
return _this.addItem(item, selectedId != null && selectedId == item.uniqueIdentifier);
|
|
});
|
|
};
|
|
ComponentContextMenu.prototype.addItem = function (item, selected) {
|
|
var _this = this;
|
|
var _a, _b, _c;
|
|
if (selected === void 0) { selected = false; }
|
|
switch (item.type) {
|
|
case 'separator':
|
|
var separator = (0, CE_1$7.ce)('div', 'mux_contextmenu-separator');
|
|
if (item.text != undefined && item.text.trim().length > 0)
|
|
separator.appendChild((0, CE_1$7.ce)('span', null, null, item.text));
|
|
this.container.appendChild(separator);
|
|
break;
|
|
case 'normal':
|
|
var element = (0, CE_1$7.ce)(item.href != undefined ? 'a' : 'div', 'mux_contextmenu-item');
|
|
if (selected)
|
|
element.classList.add('mux_contextmenu-item-selected');
|
|
var itemId = (_a = item.uniqueIdentifier) !== null && _a !== void 0 ? _a : (Math.random() + 1).toString(36).substring(7);
|
|
if (item.href != undefined)
|
|
element.setAttribute('href', item.href);
|
|
if (item.tooltip != undefined)
|
|
element.title = item.tooltip;
|
|
if (item.uniqueIdentifier != undefined) {
|
|
element.setAttribute('uid', item.uniqueIdentifier);
|
|
}
|
|
if (item.enabled == false)
|
|
element.classList.add('mux_contextmenu-item-disabled');
|
|
var textContent = (0, CE_1$7.ce)('div', 'mux_contextmenu-item-content');
|
|
element.appendChild(textContent);
|
|
var itemContent = (0, CE_1$7.ce)('div', ['mux_text', 'mux_small'], null, (_b = item.text) !== null && _b !== void 0 ? _b : '');
|
|
if (item.customFontSize != undefined)
|
|
itemContent.style.fontSize = "".concat(item.customFontSize, "px");
|
|
textContent.appendChild(itemContent);
|
|
if (item.children == undefined && item.shortcut != undefined)
|
|
textContent.appendChild((0, CE_1$7.ce)('div', [
|
|
'mux_contextmenu-shortcut',
|
|
'mux_text',
|
|
'mux_tiny',
|
|
], null, (_c = item.shortcut) !== null && _c !== void 0 ? _c : ''));
|
|
if (item.children != undefined && item.children.length > 0) {
|
|
textContent.appendChild((0, CE_1$7.ce)('span', [
|
|
'material-symbols-outlined',
|
|
'mux_contextmenu-item-arrow',
|
|
], null, 'keyboard_arrow_right'));
|
|
}
|
|
if (item.materialIcon != undefined) {
|
|
var materialIcon = (0, CE_1$7.ce)('span', [
|
|
'mux_contextmenu-item-materialicon',
|
|
'material-symbols-outlined',
|
|
], null, item.materialIcon);
|
|
if (item.materialIconTransform != undefined)
|
|
materialIcon.style.transform =
|
|
item.materialIconTransform;
|
|
element.appendChild(materialIcon);
|
|
}
|
|
else if (item.icon != undefined)
|
|
element.appendChild((0, CE_1$7.ce)('img', 'mux_contextmenu-item-icon', {
|
|
src: item.icon,
|
|
}));
|
|
element.onmousemove = function () {
|
|
if (_this.subContextParent == itemId)
|
|
return;
|
|
_this.killSubContexts();
|
|
if (item.children != undefined &&
|
|
item.children.length > 0) {
|
|
var bounds = element.getBoundingClientRect();
|
|
_this.subContextParent = itemId;
|
|
_this.subContext = new ComponentContextMenu({
|
|
items: item.children,
|
|
x: bounds.x + bounds.width + 1,
|
|
y: bounds.y,
|
|
align: 'left',
|
|
});
|
|
_this.subContext.on('close', function (byClick) {
|
|
if (byClick)
|
|
_this.close('parentkillchildhover', true);
|
|
});
|
|
}
|
|
};
|
|
if (item.click != undefined && item.href == undefined) {
|
|
element.onclick = function () {
|
|
if (item.stayOpenOnClick != true) {
|
|
_this.close('itemclick', true);
|
|
_this.killSubContexts();
|
|
}
|
|
item.click();
|
|
};
|
|
}
|
|
this.container.appendChild(element);
|
|
break;
|
|
}
|
|
};
|
|
ComponentContextMenu.prototype.killSubContexts = function () {
|
|
if (this.subContext != null) {
|
|
this.subContext.close('parentkillchild');
|
|
this.subContext = null;
|
|
}
|
|
this.subContextParent = null;
|
|
};
|
|
return ComponentContextMenu;
|
|
}(baseComponent_1$7.MUXComponent));
|
|
Component_ContextMenu.ComponentContextMenu = ComponentContextMenu;
|
|
|
|
var Component_Dialog = {};
|
|
|
|
var hasRequiredComponent_Dialog;
|
|
|
|
function requireComponent_Dialog () {
|
|
if (hasRequiredComponent_Dialog) return Component_Dialog;
|
|
hasRequiredComponent_Dialog = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Dialog, "__esModule", { value: true });
|
|
Component_Dialog.ComponentDialog = void 0;
|
|
var Index_1 = requireIndex();
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var ComponentDialog = /** @class */ (function (_super) {
|
|
__extends(ComponentDialog, _super);
|
|
function ComponentDialog(options) {
|
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
var _this = _super.call(this) || this;
|
|
var width = (_a = options === null || options === void 0 ? void 0 : options.width) !== null && _a !== void 0 ? _a : 'small';
|
|
var height = (_b = options === null || options === void 0 ? void 0 : options.height) !== null && _b !== void 0 ? _b : 'auto';
|
|
_this.container = (0, CE_1.ce)('div', 'mux_dialogcontainer');
|
|
_this.dialog = (0, CE_1.ce)('div', 'mux_dialog');
|
|
_this.dialog.classList.add("mux_w-".concat(width), "mux_h-".concat(height));
|
|
var openDialogs = document.querySelectorAll(".mux_dialog.mux_w-".concat(width, ".mux_h-").concat(height)).length;
|
|
_this.dialog.style.marginLeft = "".concat(openDialogs * 30, "px");
|
|
_this.dialog.style.marginTop = "".concat(openDialogs * 30, "px");
|
|
_this.container.append(_this.dialog);
|
|
var titlebar = (0, CE_1.ce)('div', 'mux_dialog-titlebar');
|
|
titlebar.appendChild((0, CE_1.ce)('div', ['mux_dialog-title', 'mux_header'], null, options.title));
|
|
var titlesettings = (0, CE_1.ce)('div', 'mux_dialog-titlesettings');
|
|
titlebar.appendChild(titlesettings);
|
|
_this.titlebar = titlesettings;
|
|
if ((options === null || options === void 0 ? void 0 : options.closeable) !== false) {
|
|
var close = (0, CE_1.ce)('div', 'mux_dialog-close');
|
|
close.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'close'));
|
|
close.onclick = function () {
|
|
_this.callEvent('close', new CloseEvent(_this));
|
|
};
|
|
titlebar.appendChild(close);
|
|
}
|
|
_this.dialog.appendChild(titlebar);
|
|
_this.content = (0, CE_1.ce)('div', 'mux_dialog-content');
|
|
_this.dialog.appendChild(_this.content);
|
|
var okButtonVisible = (_c = options === null || options === void 0 ? void 0 : options.okButtonVisible) !== null && _c !== void 0 ? _c : true;
|
|
var cancelButtonVisible = (_d = options === null || options === void 0 ? void 0 : options.cancelButtonVisible) !== null && _d !== void 0 ? _d : true;
|
|
if (okButtonVisible || cancelButtonVisible) {
|
|
var actionbar = (0, CE_1.ce)('div', 'mux_dialog-actionbar');
|
|
var buttons = (0, CE_1.ce)('div', 'mux_dialog-buttons');
|
|
if (cancelButtonVisible) {
|
|
var cancelButtonEnabled = (_e = options === null || options === void 0 ? void 0 : options.cancelButtonEnabled) !== null && _e !== void 0 ? _e : true;
|
|
_this.cancelButton = new Index_1.MorphComponent.Button({
|
|
content: (_f = options === null || options === void 0 ? void 0 : options.cancelButtonText) !== null && _f !== void 0 ? _f : 'Cancel',
|
|
mode: cancelButtonEnabled ? 'normal' : 'disabled',
|
|
target: function () {
|
|
_this.callEvent('cancel', new CloseEvent(_this));
|
|
},
|
|
});
|
|
buttons.appendChild(_this.cancelButton.container);
|
|
}
|
|
if (okButtonVisible) {
|
|
var okButtonEnabled = (_g = options === null || options === void 0 ? void 0 : options.okButtonEnabled) !== null && _g !== void 0 ? _g : true;
|
|
_this.okButton = new Index_1.MorphComponent.Button({
|
|
content: (_h = options === null || options === void 0 ? void 0 : options.okButtonText) !== null && _h !== void 0 ? _h : 'OK',
|
|
mode: okButtonEnabled ? 'highlight' : 'disabled',
|
|
target: function () {
|
|
_this.callEvent('ok', new CloseEvent(_this));
|
|
},
|
|
});
|
|
buttons.appendChild(_this.okButton.container);
|
|
}
|
|
actionbar.appendChild(buttons);
|
|
_this.dialog.appendChild(actionbar);
|
|
}
|
|
else
|
|
_this.content.classList.add('mux_dialog-content-nobuttons');
|
|
document.body.appendChild(_this.container);
|
|
setTimeout(function () {
|
|
_this.container.style.opacity = '1';
|
|
_this.dialog.style.opacity = '1';
|
|
_this.dialog.style.transform = 'scale(1)';
|
|
}, 20);
|
|
_this.keyOverwrite = Index_1.MorphKey.createOverwrite();
|
|
_this.keyOverwrite.bind('Escape', function () {
|
|
_this.callEvent('cancel', new CloseEvent(_this));
|
|
});
|
|
_this.keyOverwrite.bind('Enter', function () {
|
|
_this.callEvent('ok', new CloseEvent(_this));
|
|
});
|
|
return _this;
|
|
}
|
|
ComponentDialog.prototype.close = function () {
|
|
var _this = this;
|
|
this.dialog.style.transitionTimingFunction = 'ease-out';
|
|
this.dialog.style.transform = 'scale(0.8)';
|
|
this.dialog.style.opacity = '0';
|
|
this.container.style.opacity = '0';
|
|
this.container.style.pointerEvents = 'none';
|
|
this.keyOverwrite.close();
|
|
setTimeout(function () {
|
|
_this.destroy();
|
|
}, 200);
|
|
};
|
|
ComponentDialog.prototype.setOkButtonMode = function (mode) {
|
|
this.okButton.updateMode(mode);
|
|
};
|
|
ComponentDialog.prototype.setCancelButtonMode = function (mode) {
|
|
this.cancelButton.updateMode(mode);
|
|
};
|
|
return ComponentDialog;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_Dialog.ComponentDialog = ComponentDialog;
|
|
var CloseEvent = /** @class */ (function () {
|
|
function DialogCloseEvent(origin) {
|
|
var _this = this;
|
|
this.origin = origin;
|
|
this.autoCloseInterval = setTimeout(function () {
|
|
_this.close();
|
|
}, 50);
|
|
}
|
|
DialogCloseEvent.prototype.preventClose = function () {
|
|
clearInterval(this.autoCloseInterval);
|
|
};
|
|
DialogCloseEvent.prototype.close = function () {
|
|
clearInterval(this.autoCloseInterval);
|
|
this.origin.close();
|
|
};
|
|
return DialogCloseEvent;
|
|
}());
|
|
|
|
return Component_Dialog;
|
|
}
|
|
|
|
var Component_Group = {};
|
|
|
|
var __extends$6 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Group, "__esModule", { value: true });
|
|
Component_Group.ComponentGroup = void 0;
|
|
var CE_1$6 = CE;
|
|
var baseComponent_1$6 = baseComponent;
|
|
var ComponentGroup = /** @class */ (function (_super) {
|
|
__extends$6(ComponentGroup, _super);
|
|
function ComponentGroup(options) {
|
|
var _a, _b, _c;
|
|
var _this = _super.call(this) || this;
|
|
_this.container = (0, CE_1$6.ce)('div', ['mux_group', 'mux_group-open']);
|
|
var closeable = (_a = options === null || options === void 0 ? void 0 : options.closeable) !== null && _a !== void 0 ? _a : false;
|
|
if ((options === null || options === void 0 ? void 0 : options.open) == false && closeable) {
|
|
_this.container.classList.remove('mux_group-open');
|
|
}
|
|
var header = (0, CE_1$6.ce)('div', 'mux_group-header');
|
|
if ((options === null || options === void 0 ? void 0 : options.materialIcon) != undefined)
|
|
header.appendChild((0, CE_1$6.ce)('span', 'material-symbols-outlined', null, options.materialIcon));
|
|
_this.title = (0, CE_1$6.ce)('div', ['mux_header', 'mux_small'], null, (_b = options === null || options === void 0 ? void 0 : options.title) !== null && _b !== void 0 ? _b : '');
|
|
_this.subTitle = (0, CE_1$6.ce)('div', ['mux_text', 'mux_small'], null, (_c = options === null || options === void 0 ? void 0 : options.subTitle) !== null && _c !== void 0 ? _c : '');
|
|
header.append(_this.title, _this.subTitle);
|
|
if ((options === null || options === void 0 ? void 0 : options.actions) != undefined && options.actions.length > 0) {
|
|
var actions = (0, CE_1$6.ce)('div', 'mux_group-actions');
|
|
options.actions.forEach(function (action) {
|
|
var element = (0, CE_1$6.ce)('div', 'mux_group-iconbutton');
|
|
element.appendChild((0, CE_1$6.ce)('span', 'material-symbols-outlined', null, action.materialIcon));
|
|
element.onclick = function (e) {
|
|
e.stopPropagation();
|
|
action.click();
|
|
};
|
|
actions.appendChild(element);
|
|
});
|
|
header.appendChild(actions);
|
|
}
|
|
if (closeable) {
|
|
var foldIcon = (0, CE_1$6.ce)('span', ['material-symbols-outlined', 'mux_group-fold'], null, 'keyboard_arrow_right');
|
|
header.appendChild(foldIcon);
|
|
header.onclick = function () {
|
|
if (_this.container.classList.contains('mux_group-open'))
|
|
_this.container.classList.remove('mux_group-open');
|
|
else
|
|
_this.container.classList.add('mux_group-open');
|
|
_this.callEvent('openState', _this.container.classList.contains('mux_group-open'));
|
|
};
|
|
}
|
|
_this.container.appendChild(header);
|
|
_this.content = (0, CE_1$6.ce)('div', 'mux_group-content');
|
|
var contentwrapper = (0, CE_1$6.ce)('div', 'mux_group-contentwrapper');
|
|
contentwrapper.appendChild(_this.content);
|
|
_this.container.appendChild(contentwrapper);
|
|
return _this;
|
|
}
|
|
ComponentGroup.prototype.setTitle = function (title) {
|
|
this.title.innerText = title !== null && title !== void 0 ? title : '';
|
|
};
|
|
ComponentGroup.prototype.setSubTitle = function (subTitle) {
|
|
this.subTitle.innerText = subTitle !== null && subTitle !== void 0 ? subTitle : '';
|
|
};
|
|
return ComponentGroup;
|
|
}(baseComponent_1$6.MUXComponent));
|
|
Component_Group.ComponentGroup = ComponentGroup;
|
|
|
|
var Component_Header = {};
|
|
|
|
var __extends$5 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Header, "__esModule", { value: true });
|
|
Component_Header.ComponentHeader = void 0;
|
|
var CE_1$5 = CE;
|
|
var baseComponent_1$5 = baseComponent;
|
|
var ComponentHeader = /** @class */ (function (_super) {
|
|
__extends$5(ComponentHeader, _super);
|
|
function ComponentHeader(options) {
|
|
var _a;
|
|
var _this = _super.call(this) || this;
|
|
var size = (_a = options === null || options === void 0 ? void 0 : options.size) !== null && _a !== void 0 ? _a : 'normal';
|
|
_this.container = (0, CE_1$5.ce)('div', ['mux_header', "mux_".concat(size)], null, options === null || options === void 0 ? void 0 : options.content);
|
|
return _this;
|
|
}
|
|
ComponentHeader.prototype.update = function (content) {
|
|
this.container.innerHTML = content;
|
|
};
|
|
return ComponentHeader;
|
|
}(baseComponent_1$5.MUXComponent));
|
|
Component_Header.ComponentHeader = ComponentHeader;
|
|
|
|
var Component_IconGrid = {};
|
|
|
|
var __extends$4 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_IconGrid, "__esModule", { value: true });
|
|
Component_IconGrid.ComponentIconGrid = void 0;
|
|
var CE_1$4 = CE;
|
|
var baseComponent_1$4 = baseComponent;
|
|
var Sortable = SortableExports;
|
|
var ComponentIconGrid = /** @class */ (function (_super) {
|
|
__extends$4(ComponentIconGrid, _super);
|
|
function ComponentIconGrid(options) {
|
|
var _a;
|
|
var _this = _super.call(this) || this;
|
|
_this.container = (0, CE_1$4.ce)('div', 'mux_icongrid');
|
|
if ((options === null || options === void 0 ? void 0 : options.sortable) === true) {
|
|
_this.sortable = new Sortable(_this.container, {
|
|
ghostClass: 'mux_icongrid-item-dragging',
|
|
onStart: function () {
|
|
_this.container.classList.add('mux_icongrid-dragging');
|
|
},
|
|
onEnd: function (evt) {
|
|
_this.container.classList.remove('mux_icongrid-dragging');
|
|
_this.callEvent('orderUpdated', _this.getOrder());
|
|
},
|
|
});
|
|
}
|
|
_this.setItems((_a = options === null || options === void 0 ? void 0 : options.items) !== null && _a !== void 0 ? _a : []);
|
|
return _this;
|
|
}
|
|
ComponentIconGrid.prototype.setItems = function (items) {
|
|
var _this = this;
|
|
this.container.innerHTML = '';
|
|
items.forEach(function (item) { return _this.addItem(item); });
|
|
};
|
|
ComponentIconGrid.prototype.addItem = function (item) {
|
|
var element = (0, CE_1$4.ce)('div', 'mux_icongrid-item');
|
|
if (item.uniqueIdentifier != undefined)
|
|
element.setAttribute('uid', item.uniqueIdentifier);
|
|
if (!item.enabled)
|
|
element.classList.add('mux_icongrid-item-disabled');
|
|
if (item.click != undefined)
|
|
element.onclick = item.click;
|
|
if (item.materialIcon != undefined)
|
|
element.appendChild((0, CE_1$4.ce)('span', ['mux_icongrid-item-icon', 'material-symbols-outline'], null, item.materialIcon));
|
|
else if (item.icon != undefined)
|
|
element.appendChild((0, CE_1$4.ce)('img', 'mux_icongrid-item-icon', { src: item.icon }));
|
|
element.appendChild((0, CE_1$4.ce)('div', ['mux_text', 'mux_small'], null, item.text));
|
|
this.container.appendChild(element);
|
|
};
|
|
ComponentIconGrid.prototype.getOrder = function () {
|
|
return Array.from(this.container.querySelectorAll('.mux_icongrid-item')).map(function (item) { return item.getAttribute('uid'); });
|
|
};
|
|
ComponentIconGrid.prototype.enable = function (uniqueIdentifier) {
|
|
var item = this.container.querySelector("[uid=\"".concat(uniqueIdentifier, "\"]"));
|
|
if (item != undefined)
|
|
item.classList.remove('mux_icongrid-item-disabled');
|
|
};
|
|
ComponentIconGrid.prototype.disable = function (uniqueIdentifier) {
|
|
var item = this.container.querySelector("[uid=\"".concat(uniqueIdentifier, "\"]"));
|
|
if (item != undefined)
|
|
item.classList.add('mux_icongrid-item-disabled');
|
|
};
|
|
return ComponentIconGrid;
|
|
}(baseComponent_1$4.MUXComponent));
|
|
Component_IconGrid.ComponentIconGrid = ComponentIconGrid;
|
|
|
|
var Component_ImageViewer = {};
|
|
|
|
/*! Hammer.JS - v2.0.17-rc - 2019-12-16
|
|
* http://naver.github.io/egjs
|
|
*
|
|
* Forked By Naver egjs
|
|
* Copyright (c) hammerjs
|
|
* Licensed under the MIT license */
|
|
function _extends() {
|
|
_extends = Object.assign || function (target) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
var source = arguments[i];
|
|
|
|
for (var key in source) {
|
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
target[key] = source[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
return target;
|
|
};
|
|
|
|
return _extends.apply(this, arguments);
|
|
}
|
|
|
|
function _inheritsLoose(subClass, superClass) {
|
|
subClass.prototype = Object.create(superClass.prototype);
|
|
subClass.prototype.constructor = subClass;
|
|
subClass.__proto__ = superClass;
|
|
}
|
|
|
|
function _assertThisInitialized(self) {
|
|
if (self === void 0) {
|
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* extend object.
|
|
* means that properties in dest will be overwritten by the ones in src.
|
|
* @param {Object} target
|
|
* @param {...Object} objects_to_assign
|
|
* @returns {Object} target
|
|
*/
|
|
var assign;
|
|
|
|
if (typeof Object.assign !== 'function') {
|
|
assign = function assign(target) {
|
|
if (target === undefined || target === null) {
|
|
throw new TypeError('Cannot convert undefined or null to object');
|
|
}
|
|
|
|
var output = Object(target);
|
|
|
|
for (var index = 1; index < arguments.length; index++) {
|
|
var source = arguments[index];
|
|
|
|
if (source !== undefined && source !== null) {
|
|
for (var nextKey in source) {
|
|
if (source.hasOwnProperty(nextKey)) {
|
|
output[nextKey] = source[nextKey];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return output;
|
|
};
|
|
} else {
|
|
assign = Object.assign;
|
|
}
|
|
|
|
var assign$1 = assign;
|
|
|
|
var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
|
|
var TEST_ELEMENT = typeof document === "undefined" ? {
|
|
style: {}
|
|
} : document.createElement('div');
|
|
var TYPE_FUNCTION = 'function';
|
|
var round = Math.round,
|
|
abs = Math.abs;
|
|
var now = Date.now;
|
|
|
|
/**
|
|
* @private
|
|
* get the prefixed property
|
|
* @param {Object} obj
|
|
* @param {String} property
|
|
* @returns {String|Undefined} prefixed
|
|
*/
|
|
|
|
function prefixed(obj, property) {
|
|
var prefix;
|
|
var prop;
|
|
var camelProp = property[0].toUpperCase() + property.slice(1);
|
|
var i = 0;
|
|
|
|
while (i < VENDOR_PREFIXES.length) {
|
|
prefix = VENDOR_PREFIXES[i];
|
|
prop = prefix ? prefix + camelProp : property;
|
|
|
|
if (prop in obj) {
|
|
return prop;
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
/* eslint-disable no-new-func, no-nested-ternary */
|
|
var win;
|
|
|
|
if (typeof window === "undefined") {
|
|
// window is undefined in node.js
|
|
win = {};
|
|
} else {
|
|
win = window;
|
|
}
|
|
|
|
var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
|
|
var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
|
|
function getTouchActionProps() {
|
|
if (!NATIVE_TOUCH_ACTION) {
|
|
return false;
|
|
}
|
|
|
|
var touchMap = {};
|
|
var cssSupports = win.CSS && win.CSS.supports;
|
|
['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function (val) {
|
|
// If css.supports is not supported but there is native touch-action assume it supports
|
|
// all values. This is the case for IE 10 and 11.
|
|
return touchMap[val] = cssSupports ? win.CSS.supports('touch-action', val) : true;
|
|
});
|
|
return touchMap;
|
|
}
|
|
|
|
var TOUCH_ACTION_COMPUTE = 'compute';
|
|
var TOUCH_ACTION_AUTO = 'auto';
|
|
var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented
|
|
|
|
var TOUCH_ACTION_NONE = 'none';
|
|
var TOUCH_ACTION_PAN_X = 'pan-x';
|
|
var TOUCH_ACTION_PAN_Y = 'pan-y';
|
|
var TOUCH_ACTION_MAP = getTouchActionProps();
|
|
|
|
var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
|
var SUPPORT_TOUCH = 'ontouchstart' in win;
|
|
var SUPPORT_POINTER_EVENTS = prefixed(win, 'PointerEvent') !== undefined;
|
|
var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
|
|
var INPUT_TYPE_TOUCH = 'touch';
|
|
var INPUT_TYPE_PEN = 'pen';
|
|
var INPUT_TYPE_MOUSE = 'mouse';
|
|
var INPUT_TYPE_KINECT = 'kinect';
|
|
var COMPUTE_INTERVAL = 25;
|
|
var INPUT_START = 1;
|
|
var INPUT_MOVE = 2;
|
|
var INPUT_END = 4;
|
|
var INPUT_CANCEL = 8;
|
|
var DIRECTION_NONE = 1;
|
|
var DIRECTION_LEFT = 2;
|
|
var DIRECTION_RIGHT = 4;
|
|
var DIRECTION_UP = 8;
|
|
var DIRECTION_DOWN = 16;
|
|
var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
|
|
var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
|
|
var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
|
|
var PROPS_XY = ['x', 'y'];
|
|
var PROPS_CLIENT_XY = ['clientX', 'clientY'];
|
|
|
|
/**
|
|
* @private
|
|
* walk objects and arrays
|
|
* @param {Object} obj
|
|
* @param {Function} iterator
|
|
* @param {Object} context
|
|
*/
|
|
function each(obj, iterator, context) {
|
|
var i;
|
|
|
|
if (!obj) {
|
|
return;
|
|
}
|
|
|
|
if (obj.forEach) {
|
|
obj.forEach(iterator, context);
|
|
} else if (obj.length !== undefined) {
|
|
i = 0;
|
|
|
|
while (i < obj.length) {
|
|
iterator.call(context, obj[i], i, obj);
|
|
i++;
|
|
}
|
|
} else {
|
|
for (i in obj) {
|
|
obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* let a boolean value also be a function that must return a boolean
|
|
* this first item in args will be used as the context
|
|
* @param {Boolean|Function} val
|
|
* @param {Array} [args]
|
|
* @returns {Boolean}
|
|
*/
|
|
|
|
function boolOrFn(val, args) {
|
|
if (typeof val === TYPE_FUNCTION) {
|
|
return val.apply(args ? args[0] || undefined : undefined, args);
|
|
}
|
|
|
|
return val;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* small indexOf wrapper
|
|
* @param {String} str
|
|
* @param {String} find
|
|
* @returns {Boolean} found
|
|
*/
|
|
function inStr(str, find) {
|
|
return str.indexOf(find) > -1;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* when the touchActions are collected they are not a valid value, so we need to clean things up. *
|
|
* @param {String} actions
|
|
* @returns {*}
|
|
*/
|
|
|
|
function cleanTouchActions(actions) {
|
|
// none
|
|
if (inStr(actions, TOUCH_ACTION_NONE)) {
|
|
return TOUCH_ACTION_NONE;
|
|
}
|
|
|
|
var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
|
|
var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y); // if both pan-x and pan-y are set (different recognizers
|
|
// for different directions, e.g. horizontal pan but vertical swipe?)
|
|
// we need none (as otherwise with pan-x pan-y combined none of these
|
|
// recognizers will work, since the browser would handle all panning
|
|
|
|
if (hasPanX && hasPanY) {
|
|
return TOUCH_ACTION_NONE;
|
|
} // pan-x OR pan-y
|
|
|
|
|
|
if (hasPanX || hasPanY) {
|
|
return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
|
|
} // manipulation
|
|
|
|
|
|
if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
|
|
return TOUCH_ACTION_MANIPULATION;
|
|
}
|
|
|
|
return TOUCH_ACTION_AUTO;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* Touch Action
|
|
* sets the touchAction property or uses the js alternative
|
|
* @param {Manager} manager
|
|
* @param {String} value
|
|
* @constructor
|
|
*/
|
|
|
|
var TouchAction =
|
|
/*#__PURE__*/
|
|
function () {
|
|
function TouchAction(manager, value) {
|
|
this.manager = manager;
|
|
this.set(value);
|
|
}
|
|
/**
|
|
* @private
|
|
* set the touchAction value on the element or enable the polyfill
|
|
* @param {String} value
|
|
*/
|
|
|
|
|
|
var _proto = TouchAction.prototype;
|
|
|
|
_proto.set = function set(value) {
|
|
// find out the touch-action by the event handlers
|
|
if (value === TOUCH_ACTION_COMPUTE) {
|
|
value = this.compute();
|
|
}
|
|
|
|
if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
|
|
this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
|
|
}
|
|
|
|
this.actions = value.toLowerCase().trim();
|
|
};
|
|
/**
|
|
* @private
|
|
* just re-set the touchAction value
|
|
*/
|
|
|
|
|
|
_proto.update = function update() {
|
|
this.set(this.manager.options.touchAction);
|
|
};
|
|
/**
|
|
* @private
|
|
* compute the value for the touchAction property based on the recognizer's settings
|
|
* @returns {String} value
|
|
*/
|
|
|
|
|
|
_proto.compute = function compute() {
|
|
var actions = [];
|
|
each(this.manager.recognizers, function (recognizer) {
|
|
if (boolOrFn(recognizer.options.enable, [recognizer])) {
|
|
actions = actions.concat(recognizer.getTouchAction());
|
|
}
|
|
});
|
|
return cleanTouchActions(actions.join(' '));
|
|
};
|
|
/**
|
|
* @private
|
|
* this method is called on each input cycle and provides the preventing of the browser behavior
|
|
* @param {Object} input
|
|
*/
|
|
|
|
|
|
_proto.preventDefaults = function preventDefaults(input) {
|
|
var srcEvent = input.srcEvent;
|
|
var direction = input.offsetDirection; // if the touch action did prevented once this session
|
|
|
|
if (this.manager.session.prevented) {
|
|
srcEvent.preventDefault();
|
|
return;
|
|
}
|
|
|
|
var actions = this.actions;
|
|
var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
|
|
var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
|
|
var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
|
|
|
|
if (hasNone) {
|
|
// do not prevent defaults if this is a tap gesture
|
|
var isTapPointer = input.pointers.length === 1;
|
|
var isTapMovement = input.distance < 2;
|
|
var isTapTouchTime = input.deltaTime < 250;
|
|
|
|
if (isTapPointer && isTapMovement && isTapTouchTime) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (hasPanX && hasPanY) {
|
|
// `pan-x pan-y` means browser handles all scrolling/panning, do not prevent
|
|
return;
|
|
}
|
|
|
|
if (hasNone || hasPanY && direction & DIRECTION_HORIZONTAL || hasPanX && direction & DIRECTION_VERTICAL) {
|
|
return this.preventSrc(srcEvent);
|
|
}
|
|
};
|
|
/**
|
|
* @private
|
|
* call preventDefault to prevent the browser's default behavior (scrolling in most cases)
|
|
* @param {Object} srcEvent
|
|
*/
|
|
|
|
|
|
_proto.preventSrc = function preventSrc(srcEvent) {
|
|
this.manager.session.prevented = true;
|
|
srcEvent.preventDefault();
|
|
};
|
|
|
|
return TouchAction;
|
|
}();
|
|
|
|
/**
|
|
* @private
|
|
* find if a node is in the given parent
|
|
* @method hasParent
|
|
* @param {HTMLElement} node
|
|
* @param {HTMLElement} parent
|
|
* @return {Boolean} found
|
|
*/
|
|
function hasParent(node, parent) {
|
|
while (node) {
|
|
if (node === parent) {
|
|
return true;
|
|
}
|
|
|
|
node = node.parentNode;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* get the center of all the pointers
|
|
* @param {Array} pointers
|
|
* @return {Object} center contains `x` and `y` properties
|
|
*/
|
|
|
|
function getCenter(pointers) {
|
|
var pointersLength = pointers.length; // no need to loop when only one touch
|
|
|
|
if (pointersLength === 1) {
|
|
return {
|
|
x: round(pointers[0].clientX),
|
|
y: round(pointers[0].clientY)
|
|
};
|
|
}
|
|
|
|
var x = 0;
|
|
var y = 0;
|
|
var i = 0;
|
|
|
|
while (i < pointersLength) {
|
|
x += pointers[i].clientX;
|
|
y += pointers[i].clientY;
|
|
i++;
|
|
}
|
|
|
|
return {
|
|
x: round(x / pointersLength),
|
|
y: round(y / pointersLength)
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* create a simple clone from the input used for storage of firstInput and firstMultiple
|
|
* @param {Object} input
|
|
* @returns {Object} clonedInputData
|
|
*/
|
|
|
|
function simpleCloneInputData(input) {
|
|
// make a simple copy of the pointers because we will get a reference if we don't
|
|
// we only need clientXY for the calculations
|
|
var pointers = [];
|
|
var i = 0;
|
|
|
|
while (i < input.pointers.length) {
|
|
pointers[i] = {
|
|
clientX: round(input.pointers[i].clientX),
|
|
clientY: round(input.pointers[i].clientY)
|
|
};
|
|
i++;
|
|
}
|
|
|
|
return {
|
|
timeStamp: now(),
|
|
pointers: pointers,
|
|
center: getCenter(pointers),
|
|
deltaX: input.deltaX,
|
|
deltaY: input.deltaY
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* calculate the absolute distance between two points
|
|
* @param {Object} p1 {x, y}
|
|
* @param {Object} p2 {x, y}
|
|
* @param {Array} [props] containing x and y keys
|
|
* @return {Number} distance
|
|
*/
|
|
|
|
function getDistance(p1, p2, props) {
|
|
if (!props) {
|
|
props = PROPS_XY;
|
|
}
|
|
|
|
var x = p2[props[0]] - p1[props[0]];
|
|
var y = p2[props[1]] - p1[props[1]];
|
|
return Math.sqrt(x * x + y * y);
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* calculate the angle between two coordinates
|
|
* @param {Object} p1
|
|
* @param {Object} p2
|
|
* @param {Array} [props] containing x and y keys
|
|
* @return {Number} angle
|
|
*/
|
|
|
|
function getAngle(p1, p2, props) {
|
|
if (!props) {
|
|
props = PROPS_XY;
|
|
}
|
|
|
|
var x = p2[props[0]] - p1[props[0]];
|
|
var y = p2[props[1]] - p1[props[1]];
|
|
return Math.atan2(y, x) * 180 / Math.PI;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* get the direction between two points
|
|
* @param {Number} x
|
|
* @param {Number} y
|
|
* @return {Number} direction
|
|
*/
|
|
|
|
function getDirection(x, y) {
|
|
if (x === y) {
|
|
return DIRECTION_NONE;
|
|
}
|
|
|
|
if (abs(x) >= abs(y)) {
|
|
return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
|
}
|
|
|
|
return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
|
}
|
|
|
|
function computeDeltaXY(session, input) {
|
|
var center = input.center; // let { offsetDelta:offset = {}, prevDelta = {}, prevInput = {} } = session;
|
|
// jscs throwing error on defalut destructured values and without defaults tests fail
|
|
|
|
var offset = session.offsetDelta || {};
|
|
var prevDelta = session.prevDelta || {};
|
|
var prevInput = session.prevInput || {};
|
|
|
|
if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
|
|
prevDelta = session.prevDelta = {
|
|
x: prevInput.deltaX || 0,
|
|
y: prevInput.deltaY || 0
|
|
};
|
|
offset = session.offsetDelta = {
|
|
x: center.x,
|
|
y: center.y
|
|
};
|
|
}
|
|
|
|
input.deltaX = prevDelta.x + (center.x - offset.x);
|
|
input.deltaY = prevDelta.y + (center.y - offset.y);
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* calculate the velocity between two points. unit is in px per ms.
|
|
* @param {Number} deltaTime
|
|
* @param {Number} x
|
|
* @param {Number} y
|
|
* @return {Object} velocity `x` and `y`
|
|
*/
|
|
function getVelocity(deltaTime, x, y) {
|
|
return {
|
|
x: x / deltaTime || 0,
|
|
y: y / deltaTime || 0
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* calculate the scale factor between two pointersets
|
|
* no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
|
|
* @param {Array} start array of pointers
|
|
* @param {Array} end array of pointers
|
|
* @return {Number} scale
|
|
*/
|
|
|
|
function getScale(start, end) {
|
|
return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* calculate the rotation degrees between two pointersets
|
|
* @param {Array} start array of pointers
|
|
* @param {Array} end array of pointers
|
|
* @return {Number} rotation
|
|
*/
|
|
|
|
function getRotation(start, end) {
|
|
return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* velocity is calculated every x ms
|
|
* @param {Object} session
|
|
* @param {Object} input
|
|
*/
|
|
|
|
function computeIntervalInputData(session, input) {
|
|
var last = session.lastInterval || input;
|
|
var deltaTime = input.timeStamp - last.timeStamp;
|
|
var velocity;
|
|
var velocityX;
|
|
var velocityY;
|
|
var direction;
|
|
|
|
if (input.eventType !== INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
|
|
var deltaX = input.deltaX - last.deltaX;
|
|
var deltaY = input.deltaY - last.deltaY;
|
|
var v = getVelocity(deltaTime, deltaX, deltaY);
|
|
velocityX = v.x;
|
|
velocityY = v.y;
|
|
velocity = abs(v.x) > abs(v.y) ? v.x : v.y;
|
|
direction = getDirection(deltaX, deltaY);
|
|
session.lastInterval = input;
|
|
} else {
|
|
// use latest velocity info if it doesn't overtake a minimum period
|
|
velocity = last.velocity;
|
|
velocityX = last.velocityX;
|
|
velocityY = last.velocityY;
|
|
direction = last.direction;
|
|
}
|
|
|
|
input.velocity = velocity;
|
|
input.velocityX = velocityX;
|
|
input.velocityY = velocityY;
|
|
input.direction = direction;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* extend the data with some usable properties like scale, rotate, velocity etc
|
|
* @param {Object} manager
|
|
* @param {Object} input
|
|
*/
|
|
|
|
function computeInputData(manager, input) {
|
|
var session = manager.session;
|
|
var pointers = input.pointers;
|
|
var pointersLength = pointers.length; // store the first input to calculate the distance and direction
|
|
|
|
if (!session.firstInput) {
|
|
session.firstInput = simpleCloneInputData(input);
|
|
} // to compute scale and rotation we need to store the multiple touches
|
|
|
|
|
|
if (pointersLength > 1 && !session.firstMultiple) {
|
|
session.firstMultiple = simpleCloneInputData(input);
|
|
} else if (pointersLength === 1) {
|
|
session.firstMultiple = false;
|
|
}
|
|
|
|
var firstInput = session.firstInput,
|
|
firstMultiple = session.firstMultiple;
|
|
var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
|
|
var center = input.center = getCenter(pointers);
|
|
input.timeStamp = now();
|
|
input.deltaTime = input.timeStamp - firstInput.timeStamp;
|
|
input.angle = getAngle(offsetCenter, center);
|
|
input.distance = getDistance(offsetCenter, center);
|
|
computeDeltaXY(session, input);
|
|
input.offsetDirection = getDirection(input.deltaX, input.deltaY);
|
|
var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
|
|
input.overallVelocityX = overallVelocity.x;
|
|
input.overallVelocityY = overallVelocity.y;
|
|
input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
|
|
input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
|
|
input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
|
|
input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
|
|
computeIntervalInputData(session, input); // find the correct target
|
|
|
|
var target = manager.element;
|
|
var srcEvent = input.srcEvent;
|
|
var srcEventTarget;
|
|
|
|
if (srcEvent.composedPath) {
|
|
srcEventTarget = srcEvent.composedPath()[0];
|
|
} else if (srcEvent.path) {
|
|
srcEventTarget = srcEvent.path[0];
|
|
} else {
|
|
srcEventTarget = srcEvent.target;
|
|
}
|
|
|
|
if (hasParent(srcEventTarget, target)) {
|
|
target = srcEventTarget;
|
|
}
|
|
|
|
input.target = target;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* handle input events
|
|
* @param {Manager} manager
|
|
* @param {String} eventType
|
|
* @param {Object} input
|
|
*/
|
|
|
|
function inputHandler(manager, eventType, input) {
|
|
var pointersLen = input.pointers.length;
|
|
var changedPointersLen = input.changedPointers.length;
|
|
var isFirst = eventType & INPUT_START && pointersLen - changedPointersLen === 0;
|
|
var isFinal = eventType & (INPUT_END | INPUT_CANCEL) && pointersLen - changedPointersLen === 0;
|
|
input.isFirst = !!isFirst;
|
|
input.isFinal = !!isFinal;
|
|
|
|
if (isFirst) {
|
|
manager.session = {};
|
|
} // source event is the normalized value of the domEvents
|
|
// like 'touchstart, mouseup, pointerdown'
|
|
|
|
|
|
input.eventType = eventType; // compute scale, rotation etc
|
|
|
|
computeInputData(manager, input); // emit secret event
|
|
|
|
manager.emit('hammer.input', input);
|
|
manager.recognize(input);
|
|
manager.session.prevInput = input;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* split string on whitespace
|
|
* @param {String} str
|
|
* @returns {Array} words
|
|
*/
|
|
function splitStr(str) {
|
|
return str.trim().split(/\s+/g);
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* addEventListener with multiple events at once
|
|
* @param {EventTarget} target
|
|
* @param {String} types
|
|
* @param {Function} handler
|
|
*/
|
|
|
|
function addEventListeners(target, types, handler) {
|
|
each(splitStr(types), function (type) {
|
|
target.addEventListener(type, handler, false);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* removeEventListener with multiple events at once
|
|
* @param {EventTarget} target
|
|
* @param {String} types
|
|
* @param {Function} handler
|
|
*/
|
|
|
|
function removeEventListeners(target, types, handler) {
|
|
each(splitStr(types), function (type) {
|
|
target.removeEventListener(type, handler, false);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* get the window object of an element
|
|
* @param {HTMLElement} element
|
|
* @returns {DocumentView|Window}
|
|
*/
|
|
function getWindowForElement(element) {
|
|
var doc = element.ownerDocument || element;
|
|
return doc.defaultView || doc.parentWindow || window;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* create new input type manager
|
|
* @param {Manager} manager
|
|
* @param {Function} callback
|
|
* @returns {Input}
|
|
* @constructor
|
|
*/
|
|
|
|
var Input =
|
|
/*#__PURE__*/
|
|
function () {
|
|
function Input(manager, callback) {
|
|
var self = this;
|
|
this.manager = manager;
|
|
this.callback = callback;
|
|
this.element = manager.element;
|
|
this.target = manager.options.inputTarget; // smaller wrapper around the handler, for the scope and the enabled state of the manager,
|
|
// so when disabled the input events are completely bypassed.
|
|
|
|
this.domHandler = function (ev) {
|
|
if (boolOrFn(manager.options.enable, [manager])) {
|
|
self.handler(ev);
|
|
}
|
|
};
|
|
|
|
this.init();
|
|
}
|
|
/**
|
|
* @private
|
|
* should handle the inputEvent data and trigger the callback
|
|
* @virtual
|
|
*/
|
|
|
|
|
|
var _proto = Input.prototype;
|
|
|
|
_proto.handler = function handler() {};
|
|
/**
|
|
* @private
|
|
* bind the events
|
|
*/
|
|
|
|
|
|
_proto.init = function init() {
|
|
this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
|
|
this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
|
|
this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
|
};
|
|
/**
|
|
* @private
|
|
* unbind the events
|
|
*/
|
|
|
|
|
|
_proto.destroy = function destroy() {
|
|
this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
|
|
this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
|
|
this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
|
};
|
|
|
|
return Input;
|
|
}();
|
|
|
|
/**
|
|
* @private
|
|
* find if a array contains the object using indexOf or a simple polyFill
|
|
* @param {Array} src
|
|
* @param {String} find
|
|
* @param {String} [findByKey]
|
|
* @return {Boolean|Number} false when not found, or the index
|
|
*/
|
|
function inArray(src, find, findByKey) {
|
|
if (src.indexOf && !findByKey) {
|
|
return src.indexOf(find);
|
|
} else {
|
|
var i = 0;
|
|
|
|
while (i < src.length) {
|
|
if (findByKey && src[i][findByKey] == find || !findByKey && src[i] === find) {
|
|
// do not use === here, test fails
|
|
return i;
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
var POINTER_INPUT_MAP = {
|
|
pointerdown: INPUT_START,
|
|
pointermove: INPUT_MOVE,
|
|
pointerup: INPUT_END,
|
|
pointercancel: INPUT_CANCEL,
|
|
pointerout: INPUT_CANCEL
|
|
}; // in IE10 the pointer types is defined as an enum
|
|
|
|
var IE10_POINTER_TYPE_ENUM = {
|
|
2: INPUT_TYPE_TOUCH,
|
|
3: INPUT_TYPE_PEN,
|
|
4: INPUT_TYPE_MOUSE,
|
|
5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816
|
|
|
|
};
|
|
var POINTER_ELEMENT_EVENTS = 'pointerdown';
|
|
var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel'; // IE10 has prefixed support, and case-sensitive
|
|
|
|
if (win.MSPointerEvent && !win.PointerEvent) {
|
|
POINTER_ELEMENT_EVENTS = 'MSPointerDown';
|
|
POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
|
|
}
|
|
/**
|
|
* @private
|
|
* Pointer events input
|
|
* @constructor
|
|
* @extends Input
|
|
*/
|
|
|
|
|
|
var PointerEventInput =
|
|
/*#__PURE__*/
|
|
function (_Input) {
|
|
_inheritsLoose(PointerEventInput, _Input);
|
|
|
|
function PointerEventInput() {
|
|
var _this;
|
|
|
|
var proto = PointerEventInput.prototype;
|
|
proto.evEl = POINTER_ELEMENT_EVENTS;
|
|
proto.evWin = POINTER_WINDOW_EVENTS;
|
|
_this = _Input.apply(this, arguments) || this;
|
|
_this.store = _this.manager.session.pointerEvents = [];
|
|
return _this;
|
|
}
|
|
/**
|
|
* @private
|
|
* handle mouse events
|
|
* @param {Object} ev
|
|
*/
|
|
|
|
|
|
var _proto = PointerEventInput.prototype;
|
|
|
|
_proto.handler = function handler(ev) {
|
|
var store = this.store;
|
|
var removePointer = false;
|
|
var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
|
|
var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
|
|
var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
|
|
var isTouch = pointerType === INPUT_TYPE_TOUCH; // get index of the event in the store
|
|
|
|
var storeIndex = inArray(store, ev.pointerId, 'pointerId'); // start and mouse must be down
|
|
|
|
if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
|
|
if (storeIndex < 0) {
|
|
store.push(ev);
|
|
storeIndex = store.length - 1;
|
|
}
|
|
} else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
|
removePointer = true;
|
|
} // it not found, so the pointer hasn't been down (so it's probably a hover)
|
|
|
|
|
|
if (storeIndex < 0) {
|
|
return;
|
|
} // update the event in the store
|
|
|
|
|
|
store[storeIndex] = ev;
|
|
this.callback(this.manager, eventType, {
|
|
pointers: store,
|
|
changedPointers: [ev],
|
|
pointerType: pointerType,
|
|
srcEvent: ev
|
|
});
|
|
|
|
if (removePointer) {
|
|
// remove from the store
|
|
store.splice(storeIndex, 1);
|
|
}
|
|
};
|
|
|
|
return PointerEventInput;
|
|
}(Input);
|
|
|
|
/**
|
|
* @private
|
|
* convert array-like objects to real arrays
|
|
* @param {Object} obj
|
|
* @returns {Array}
|
|
*/
|
|
function toArray(obj) {
|
|
return Array.prototype.slice.call(obj, 0);
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* unique array with objects based on a key (like 'id') or just by the array's value
|
|
* @param {Array} src [{id:1},{id:2},{id:1}]
|
|
* @param {String} [key]
|
|
* @param {Boolean} [sort=False]
|
|
* @returns {Array} [{id:1},{id:2}]
|
|
*/
|
|
|
|
function uniqueArray(src, key, sort) {
|
|
var results = [];
|
|
var values = [];
|
|
var i = 0;
|
|
|
|
while (i < src.length) {
|
|
var val = key ? src[i][key] : src[i];
|
|
|
|
if (inArray(values, val) < 0) {
|
|
results.push(src[i]);
|
|
}
|
|
|
|
values[i] = val;
|
|
i++;
|
|
}
|
|
|
|
if (sort) {
|
|
if (!key) {
|
|
results = results.sort();
|
|
} else {
|
|
results = results.sort(function (a, b) {
|
|
return a[key] > b[key];
|
|
});
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
var TOUCH_INPUT_MAP = {
|
|
touchstart: INPUT_START,
|
|
touchmove: INPUT_MOVE,
|
|
touchend: INPUT_END,
|
|
touchcancel: INPUT_CANCEL
|
|
};
|
|
var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
|
|
/**
|
|
* @private
|
|
* Multi-user touch events input
|
|
* @constructor
|
|
* @extends Input
|
|
*/
|
|
|
|
var TouchInput =
|
|
/*#__PURE__*/
|
|
function (_Input) {
|
|
_inheritsLoose(TouchInput, _Input);
|
|
|
|
function TouchInput() {
|
|
var _this;
|
|
|
|
TouchInput.prototype.evTarget = TOUCH_TARGET_EVENTS;
|
|
_this = _Input.apply(this, arguments) || this;
|
|
_this.targetIds = {}; // this.evTarget = TOUCH_TARGET_EVENTS;
|
|
|
|
return _this;
|
|
}
|
|
|
|
var _proto = TouchInput.prototype;
|
|
|
|
_proto.handler = function handler(ev) {
|
|
var type = TOUCH_INPUT_MAP[ev.type];
|
|
var touches = getTouches.call(this, ev, type);
|
|
|
|
if (!touches) {
|
|
return;
|
|
}
|
|
|
|
this.callback(this.manager, type, {
|
|
pointers: touches[0],
|
|
changedPointers: touches[1],
|
|
pointerType: INPUT_TYPE_TOUCH,
|
|
srcEvent: ev
|
|
});
|
|
};
|
|
|
|
return TouchInput;
|
|
}(Input);
|
|
|
|
function getTouches(ev, type) {
|
|
var allTouches = toArray(ev.touches);
|
|
var targetIds = this.targetIds; // when there is only one touch, the process can be simplified
|
|
|
|
if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
|
|
targetIds[allTouches[0].identifier] = true;
|
|
return [allTouches, allTouches];
|
|
}
|
|
|
|
var i;
|
|
var targetTouches;
|
|
var changedTouches = toArray(ev.changedTouches);
|
|
var changedTargetTouches = [];
|
|
var target = this.target; // get target touches from touches
|
|
|
|
targetTouches = allTouches.filter(function (touch) {
|
|
return hasParent(touch.target, target);
|
|
}); // collect touches
|
|
|
|
if (type === INPUT_START) {
|
|
i = 0;
|
|
|
|
while (i < targetTouches.length) {
|
|
targetIds[targetTouches[i].identifier] = true;
|
|
i++;
|
|
}
|
|
} // filter changed touches to only contain touches that exist in the collected target ids
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < changedTouches.length) {
|
|
if (targetIds[changedTouches[i].identifier]) {
|
|
changedTargetTouches.push(changedTouches[i]);
|
|
} // cleanup removed touches
|
|
|
|
|
|
if (type & (INPUT_END | INPUT_CANCEL)) {
|
|
delete targetIds[changedTouches[i].identifier];
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
if (!changedTargetTouches.length) {
|
|
return;
|
|
}
|
|
|
|
return [// merge targetTouches with changedTargetTouches so it contains ALL touches, including 'end' and 'cancel'
|
|
uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true), changedTargetTouches];
|
|
}
|
|
|
|
var MOUSE_INPUT_MAP = {
|
|
mousedown: INPUT_START,
|
|
mousemove: INPUT_MOVE,
|
|
mouseup: INPUT_END
|
|
};
|
|
var MOUSE_ELEMENT_EVENTS = 'mousedown';
|
|
var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
|
|
/**
|
|
* @private
|
|
* Mouse events input
|
|
* @constructor
|
|
* @extends Input
|
|
*/
|
|
|
|
var MouseInput =
|
|
/*#__PURE__*/
|
|
function (_Input) {
|
|
_inheritsLoose(MouseInput, _Input);
|
|
|
|
function MouseInput() {
|
|
var _this;
|
|
|
|
var proto = MouseInput.prototype;
|
|
proto.evEl = MOUSE_ELEMENT_EVENTS;
|
|
proto.evWin = MOUSE_WINDOW_EVENTS;
|
|
_this = _Input.apply(this, arguments) || this;
|
|
_this.pressed = false; // mousedown state
|
|
|
|
return _this;
|
|
}
|
|
/**
|
|
* @private
|
|
* handle mouse events
|
|
* @param {Object} ev
|
|
*/
|
|
|
|
|
|
var _proto = MouseInput.prototype;
|
|
|
|
_proto.handler = function handler(ev) {
|
|
var eventType = MOUSE_INPUT_MAP[ev.type]; // on start we want to have the left mouse button down
|
|
|
|
if (eventType & INPUT_START && ev.button === 0) {
|
|
this.pressed = true;
|
|
}
|
|
|
|
if (eventType & INPUT_MOVE && ev.which !== 1) {
|
|
eventType = INPUT_END;
|
|
} // mouse must be down
|
|
|
|
|
|
if (!this.pressed) {
|
|
return;
|
|
}
|
|
|
|
if (eventType & INPUT_END) {
|
|
this.pressed = false;
|
|
}
|
|
|
|
this.callback(this.manager, eventType, {
|
|
pointers: [ev],
|
|
changedPointers: [ev],
|
|
pointerType: INPUT_TYPE_MOUSE,
|
|
srcEvent: ev
|
|
});
|
|
};
|
|
|
|
return MouseInput;
|
|
}(Input);
|
|
|
|
/**
|
|
* @private
|
|
* Combined touch and mouse input
|
|
*
|
|
* Touch has a higher priority then mouse, and while touching no mouse events are allowed.
|
|
* This because touch devices also emit mouse events while doing a touch.
|
|
*
|
|
* @constructor
|
|
* @extends Input
|
|
*/
|
|
|
|
var DEDUP_TIMEOUT = 2500;
|
|
var DEDUP_DISTANCE = 25;
|
|
|
|
function setLastTouch(eventData) {
|
|
var _eventData$changedPoi = eventData.changedPointers,
|
|
touch = _eventData$changedPoi[0];
|
|
|
|
if (touch.identifier === this.primaryTouch) {
|
|
var lastTouch = {
|
|
x: touch.clientX,
|
|
y: touch.clientY
|
|
};
|
|
var lts = this.lastTouches;
|
|
this.lastTouches.push(lastTouch);
|
|
|
|
var removeLastTouch = function removeLastTouch() {
|
|
var i = lts.indexOf(lastTouch);
|
|
|
|
if (i > -1) {
|
|
lts.splice(i, 1);
|
|
}
|
|
};
|
|
|
|
setTimeout(removeLastTouch, DEDUP_TIMEOUT);
|
|
}
|
|
}
|
|
|
|
function recordTouches(eventType, eventData) {
|
|
if (eventType & INPUT_START) {
|
|
this.primaryTouch = eventData.changedPointers[0].identifier;
|
|
setLastTouch.call(this, eventData);
|
|
} else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
|
setLastTouch.call(this, eventData);
|
|
}
|
|
}
|
|
|
|
function isSyntheticEvent(eventData) {
|
|
var x = eventData.srcEvent.clientX;
|
|
var y = eventData.srcEvent.clientY;
|
|
|
|
for (var i = 0; i < this.lastTouches.length; i++) {
|
|
var t = this.lastTouches[i];
|
|
var dx = Math.abs(x - t.x);
|
|
var dy = Math.abs(y - t.y);
|
|
|
|
if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
var TouchMouseInput =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var TouchMouseInput =
|
|
/*#__PURE__*/
|
|
function (_Input) {
|
|
_inheritsLoose(TouchMouseInput, _Input);
|
|
|
|
function TouchMouseInput(_manager, callback) {
|
|
var _this;
|
|
|
|
_this = _Input.call(this, _manager, callback) || this;
|
|
|
|
_this.handler = function (manager, inputEvent, inputData) {
|
|
var isTouch = inputData.pointerType === INPUT_TYPE_TOUCH;
|
|
var isMouse = inputData.pointerType === INPUT_TYPE_MOUSE;
|
|
|
|
if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
|
|
return;
|
|
} // when we're in a touch event, record touches to de-dupe synthetic mouse event
|
|
|
|
|
|
if (isTouch) {
|
|
recordTouches.call(_assertThisInitialized(_assertThisInitialized(_this)), inputEvent, inputData);
|
|
} else if (isMouse && isSyntheticEvent.call(_assertThisInitialized(_assertThisInitialized(_this)), inputData)) {
|
|
return;
|
|
}
|
|
|
|
_this.callback(manager, inputEvent, inputData);
|
|
};
|
|
|
|
_this.touch = new TouchInput(_this.manager, _this.handler);
|
|
_this.mouse = new MouseInput(_this.manager, _this.handler);
|
|
_this.primaryTouch = null;
|
|
_this.lastTouches = [];
|
|
return _this;
|
|
}
|
|
/**
|
|
* @private
|
|
* handle mouse and touch events
|
|
* @param {Hammer} manager
|
|
* @param {String} inputEvent
|
|
* @param {Object} inputData
|
|
*/
|
|
|
|
|
|
var _proto = TouchMouseInput.prototype;
|
|
|
|
/**
|
|
* @private
|
|
* remove the event listeners
|
|
*/
|
|
_proto.destroy = function destroy() {
|
|
this.touch.destroy();
|
|
this.mouse.destroy();
|
|
};
|
|
|
|
return TouchMouseInput;
|
|
}(Input);
|
|
|
|
return TouchMouseInput;
|
|
}();
|
|
|
|
/**
|
|
* @private
|
|
* create new input type manager
|
|
* called by the Manager constructor
|
|
* @param {Hammer} manager
|
|
* @returns {Input}
|
|
*/
|
|
|
|
function createInputInstance(manager) {
|
|
var Type; // let inputClass = manager.options.inputClass;
|
|
|
|
var inputClass = manager.options.inputClass;
|
|
|
|
if (inputClass) {
|
|
Type = inputClass;
|
|
} else if (SUPPORT_POINTER_EVENTS) {
|
|
Type = PointerEventInput;
|
|
} else if (SUPPORT_ONLY_TOUCH) {
|
|
Type = TouchInput;
|
|
} else if (!SUPPORT_TOUCH) {
|
|
Type = MouseInput;
|
|
} else {
|
|
Type = TouchMouseInput;
|
|
}
|
|
|
|
return new Type(manager, inputHandler);
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* if the argument is an array, we want to execute the fn on each entry
|
|
* if it aint an array we don't want to do a thing.
|
|
* this is used by all the methods that accept a single and array argument.
|
|
* @param {*|Array} arg
|
|
* @param {String} fn
|
|
* @param {Object} [context]
|
|
* @returns {Boolean}
|
|
*/
|
|
|
|
function invokeArrayArg(arg, fn, context) {
|
|
if (Array.isArray(arg)) {
|
|
each(arg, context[fn], context);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
var STATE_POSSIBLE = 1;
|
|
var STATE_BEGAN = 2;
|
|
var STATE_CHANGED = 4;
|
|
var STATE_ENDED = 8;
|
|
var STATE_RECOGNIZED = STATE_ENDED;
|
|
var STATE_CANCELLED = 16;
|
|
var STATE_FAILED = 32;
|
|
|
|
/**
|
|
* @private
|
|
* get a unique id
|
|
* @returns {number} uniqueId
|
|
*/
|
|
var _uniqueId = 1;
|
|
function uniqueId() {
|
|
return _uniqueId++;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* get a recognizer by name if it is bound to a manager
|
|
* @param {Recognizer|String} otherRecognizer
|
|
* @param {Recognizer} recognizer
|
|
* @returns {Recognizer}
|
|
*/
|
|
function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
|
|
var manager = recognizer.manager;
|
|
|
|
if (manager) {
|
|
return manager.get(otherRecognizer);
|
|
}
|
|
|
|
return otherRecognizer;
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* get a usable string, used as event postfix
|
|
* @param {constant} state
|
|
* @returns {String} state
|
|
*/
|
|
|
|
function stateStr(state) {
|
|
if (state & STATE_CANCELLED) {
|
|
return 'cancel';
|
|
} else if (state & STATE_ENDED) {
|
|
return 'end';
|
|
} else if (state & STATE_CHANGED) {
|
|
return 'move';
|
|
} else if (state & STATE_BEGAN) {
|
|
return 'start';
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* Recognizer flow explained; *
|
|
* All recognizers have the initial state of POSSIBLE when a input session starts.
|
|
* The definition of a input session is from the first input until the last input, with all it's movement in it. *
|
|
* Example session for mouse-input: mousedown -> mousemove -> mouseup
|
|
*
|
|
* On each recognizing cycle (see Manager.recognize) the .recognize() method is executed
|
|
* which determines with state it should be.
|
|
*
|
|
* If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to
|
|
* POSSIBLE to give it another change on the next cycle.
|
|
*
|
|
* Possible
|
|
* |
|
|
* +-----+---------------+
|
|
* | |
|
|
* +-----+-----+ |
|
|
* | | |
|
|
* Failed Cancelled |
|
|
* +-------+------+
|
|
* | |
|
|
* Recognized Began
|
|
* |
|
|
* Changed
|
|
* |
|
|
* Ended/Recognized
|
|
*/
|
|
|
|
/**
|
|
* @private
|
|
* Recognizer
|
|
* Every recognizer needs to extend from this class.
|
|
* @constructor
|
|
* @param {Object} options
|
|
*/
|
|
|
|
var Recognizer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
function Recognizer(options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
this.options = _extends({
|
|
enable: true
|
|
}, options);
|
|
this.id = uniqueId();
|
|
this.manager = null; // default is enable true
|
|
|
|
this.state = STATE_POSSIBLE;
|
|
this.simultaneous = {};
|
|
this.requireFail = [];
|
|
}
|
|
/**
|
|
* @private
|
|
* set options
|
|
* @param {Object} options
|
|
* @return {Recognizer}
|
|
*/
|
|
|
|
|
|
var _proto = Recognizer.prototype;
|
|
|
|
_proto.set = function set(options) {
|
|
assign$1(this.options, options); // also update the touchAction, in case something changed about the directions/enabled state
|
|
|
|
this.manager && this.manager.touchAction.update();
|
|
return this;
|
|
};
|
|
/**
|
|
* @private
|
|
* recognize simultaneous with an other recognizer.
|
|
* @param {Recognizer} otherRecognizer
|
|
* @returns {Recognizer} this
|
|
*/
|
|
|
|
|
|
_proto.recognizeWith = function recognizeWith(otherRecognizer) {
|
|
if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
|
|
return this;
|
|
}
|
|
|
|
var simultaneous = this.simultaneous;
|
|
otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
|
|
|
if (!simultaneous[otherRecognizer.id]) {
|
|
simultaneous[otherRecognizer.id] = otherRecognizer;
|
|
otherRecognizer.recognizeWith(this);
|
|
}
|
|
|
|
return this;
|
|
};
|
|
/**
|
|
* @private
|
|
* drop the simultaneous link. it doesnt remove the link on the other recognizer.
|
|
* @param {Recognizer} otherRecognizer
|
|
* @returns {Recognizer} this
|
|
*/
|
|
|
|
|
|
_proto.dropRecognizeWith = function dropRecognizeWith(otherRecognizer) {
|
|
if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
|
|
return this;
|
|
}
|
|
|
|
otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
|
delete this.simultaneous[otherRecognizer.id];
|
|
return this;
|
|
};
|
|
/**
|
|
* @private
|
|
* recognizer can only run when an other is failing
|
|
* @param {Recognizer} otherRecognizer
|
|
* @returns {Recognizer} this
|
|
*/
|
|
|
|
|
|
_proto.requireFailure = function requireFailure(otherRecognizer) {
|
|
if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
|
|
return this;
|
|
}
|
|
|
|
var requireFail = this.requireFail;
|
|
otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
|
|
|
if (inArray(requireFail, otherRecognizer) === -1) {
|
|
requireFail.push(otherRecognizer);
|
|
otherRecognizer.requireFailure(this);
|
|
}
|
|
|
|
return this;
|
|
};
|
|
/**
|
|
* @private
|
|
* drop the requireFailure link. it does not remove the link on the other recognizer.
|
|
* @param {Recognizer} otherRecognizer
|
|
* @returns {Recognizer} this
|
|
*/
|
|
|
|
|
|
_proto.dropRequireFailure = function dropRequireFailure(otherRecognizer) {
|
|
if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
|
|
return this;
|
|
}
|
|
|
|
otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
|
var index = inArray(this.requireFail, otherRecognizer);
|
|
|
|
if (index > -1) {
|
|
this.requireFail.splice(index, 1);
|
|
}
|
|
|
|
return this;
|
|
};
|
|
/**
|
|
* @private
|
|
* has require failures boolean
|
|
* @returns {boolean}
|
|
*/
|
|
|
|
|
|
_proto.hasRequireFailures = function hasRequireFailures() {
|
|
return this.requireFail.length > 0;
|
|
};
|
|
/**
|
|
* @private
|
|
* if the recognizer can recognize simultaneous with an other recognizer
|
|
* @param {Recognizer} otherRecognizer
|
|
* @returns {Boolean}
|
|
*/
|
|
|
|
|
|
_proto.canRecognizeWith = function canRecognizeWith(otherRecognizer) {
|
|
return !!this.simultaneous[otherRecognizer.id];
|
|
};
|
|
/**
|
|
* @private
|
|
* You should use `tryEmit` instead of `emit` directly to check
|
|
* that all the needed recognizers has failed before emitting.
|
|
* @param {Object} input
|
|
*/
|
|
|
|
|
|
_proto.emit = function emit(input) {
|
|
var self = this;
|
|
var state = this.state;
|
|
|
|
function emit(event) {
|
|
self.manager.emit(event, input);
|
|
} // 'panstart' and 'panmove'
|
|
|
|
|
|
if (state < STATE_ENDED) {
|
|
emit(self.options.event + stateStr(state));
|
|
}
|
|
|
|
emit(self.options.event); // simple 'eventName' events
|
|
|
|
if (input.additionalEvent) {
|
|
// additional event(panleft, panright, pinchin, pinchout...)
|
|
emit(input.additionalEvent);
|
|
} // panend and pancancel
|
|
|
|
|
|
if (state >= STATE_ENDED) {
|
|
emit(self.options.event + stateStr(state));
|
|
}
|
|
};
|
|
/**
|
|
* @private
|
|
* Check that all the require failure recognizers has failed,
|
|
* if true, it emits a gesture event,
|
|
* otherwise, setup the state to FAILED.
|
|
* @param {Object} input
|
|
*/
|
|
|
|
|
|
_proto.tryEmit = function tryEmit(input) {
|
|
if (this.canEmit()) {
|
|
return this.emit(input);
|
|
} // it's failing anyway
|
|
|
|
|
|
this.state = STATE_FAILED;
|
|
};
|
|
/**
|
|
* @private
|
|
* can we emit?
|
|
* @returns {boolean}
|
|
*/
|
|
|
|
|
|
_proto.canEmit = function canEmit() {
|
|
var i = 0;
|
|
|
|
while (i < this.requireFail.length) {
|
|
if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
|
|
return false;
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
/**
|
|
* @private
|
|
* update the recognizer
|
|
* @param {Object} inputData
|
|
*/
|
|
|
|
|
|
_proto.recognize = function recognize(inputData) {
|
|
// make a new copy of the inputData
|
|
// so we can change the inputData without messing up the other recognizers
|
|
var inputDataClone = assign$1({}, inputData); // is is enabled and allow recognizing?
|
|
|
|
if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
|
|
this.reset();
|
|
this.state = STATE_FAILED;
|
|
return;
|
|
} // reset when we've reached the end
|
|
|
|
|
|
if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
|
|
this.state = STATE_POSSIBLE;
|
|
}
|
|
|
|
this.state = this.process(inputDataClone); // the recognizer has recognized a gesture
|
|
// so trigger an event
|
|
|
|
if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
|
|
this.tryEmit(inputDataClone);
|
|
}
|
|
};
|
|
/**
|
|
* @private
|
|
* return the state of the recognizer
|
|
* the actual recognizing happens in this method
|
|
* @virtual
|
|
* @param {Object} inputData
|
|
* @returns {constant} STATE
|
|
*/
|
|
|
|
/* jshint ignore:start */
|
|
|
|
|
|
_proto.process = function process(inputData) {};
|
|
/* jshint ignore:end */
|
|
|
|
/**
|
|
* @private
|
|
* return the preferred touch-action
|
|
* @virtual
|
|
* @returns {Array}
|
|
*/
|
|
|
|
|
|
_proto.getTouchAction = function getTouchAction() {};
|
|
/**
|
|
* @private
|
|
* called when the gesture isn't allowed to recognize
|
|
* like when another is being recognized or it is disabled
|
|
* @virtual
|
|
*/
|
|
|
|
|
|
_proto.reset = function reset() {};
|
|
|
|
return Recognizer;
|
|
}();
|
|
|
|
/**
|
|
* @private
|
|
* A tap is recognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur
|
|
* between the given interval and position. The delay option can be used to recognize multi-taps without firing
|
|
* a single tap.
|
|
*
|
|
* The eventData from the emitted event contains the property `tapCount`, which contains the amount of
|
|
* multi-taps being recognized.
|
|
* @constructor
|
|
* @extends Recognizer
|
|
*/
|
|
|
|
var TapRecognizer =
|
|
/*#__PURE__*/
|
|
function (_Recognizer) {
|
|
_inheritsLoose(TapRecognizer, _Recognizer);
|
|
|
|
function TapRecognizer(options) {
|
|
var _this;
|
|
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
_this = _Recognizer.call(this, _extends({
|
|
event: 'tap',
|
|
pointers: 1,
|
|
taps: 1,
|
|
interval: 300,
|
|
// max time between the multi-tap taps
|
|
time: 250,
|
|
// max time of the pointer to be down (like finger on the screen)
|
|
threshold: 9,
|
|
// a minimal movement is ok, but keep it low
|
|
posThreshold: 10
|
|
}, options)) || this; // previous time and center,
|
|
// used for tap counting
|
|
|
|
_this.pTime = false;
|
|
_this.pCenter = false;
|
|
_this._timer = null;
|
|
_this._input = null;
|
|
_this.count = 0;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = TapRecognizer.prototype;
|
|
|
|
_proto.getTouchAction = function getTouchAction() {
|
|
return [TOUCH_ACTION_MANIPULATION];
|
|
};
|
|
|
|
_proto.process = function process(input) {
|
|
var _this2 = this;
|
|
|
|
var options = this.options;
|
|
var validPointers = input.pointers.length === options.pointers;
|
|
var validMovement = input.distance < options.threshold;
|
|
var validTouchTime = input.deltaTime < options.time;
|
|
this.reset();
|
|
|
|
if (input.eventType & INPUT_START && this.count === 0) {
|
|
return this.failTimeout();
|
|
} // we only allow little movement
|
|
// and we've reached an end event, so a tap is possible
|
|
|
|
|
|
if (validMovement && validTouchTime && validPointers) {
|
|
if (input.eventType !== INPUT_END) {
|
|
return this.failTimeout();
|
|
}
|
|
|
|
var validInterval = this.pTime ? input.timeStamp - this.pTime < options.interval : true;
|
|
var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
|
|
this.pTime = input.timeStamp;
|
|
this.pCenter = input.center;
|
|
|
|
if (!validMultiTap || !validInterval) {
|
|
this.count = 1;
|
|
} else {
|
|
this.count += 1;
|
|
}
|
|
|
|
this._input = input; // if tap count matches we have recognized it,
|
|
// else it has began recognizing...
|
|
|
|
var tapCount = this.count % options.taps;
|
|
|
|
if (tapCount === 0) {
|
|
// no failing requirements, immediately trigger the tap event
|
|
// or wait as long as the multitap interval to trigger
|
|
if (!this.hasRequireFailures()) {
|
|
return STATE_RECOGNIZED;
|
|
} else {
|
|
this._timer = setTimeout(function () {
|
|
_this2.state = STATE_RECOGNIZED;
|
|
|
|
_this2.tryEmit();
|
|
}, options.interval);
|
|
return STATE_BEGAN;
|
|
}
|
|
}
|
|
}
|
|
|
|
return STATE_FAILED;
|
|
};
|
|
|
|
_proto.failTimeout = function failTimeout() {
|
|
var _this3 = this;
|
|
|
|
this._timer = setTimeout(function () {
|
|
_this3.state = STATE_FAILED;
|
|
}, this.options.interval);
|
|
return STATE_FAILED;
|
|
};
|
|
|
|
_proto.reset = function reset() {
|
|
clearTimeout(this._timer);
|
|
};
|
|
|
|
_proto.emit = function emit() {
|
|
if (this.state === STATE_RECOGNIZED) {
|
|
this._input.tapCount = this.count;
|
|
this.manager.emit(this.options.event, this._input);
|
|
}
|
|
};
|
|
|
|
return TapRecognizer;
|
|
}(Recognizer);
|
|
|
|
/**
|
|
* @private
|
|
* This recognizer is just used as a base for the simple attribute recognizers.
|
|
* @constructor
|
|
* @extends Recognizer
|
|
*/
|
|
|
|
var AttrRecognizer =
|
|
/*#__PURE__*/
|
|
function (_Recognizer) {
|
|
_inheritsLoose(AttrRecognizer, _Recognizer);
|
|
|
|
function AttrRecognizer(options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
return _Recognizer.call(this, _extends({
|
|
pointers: 1
|
|
}, options)) || this;
|
|
}
|
|
/**
|
|
* @private
|
|
* Used to check if it the recognizer receives valid input, like input.distance > 10.
|
|
* @memberof AttrRecognizer
|
|
* @param {Object} input
|
|
* @returns {Boolean} recognized
|
|
*/
|
|
|
|
|
|
var _proto = AttrRecognizer.prototype;
|
|
|
|
_proto.attrTest = function attrTest(input) {
|
|
var optionPointers = this.options.pointers;
|
|
return optionPointers === 0 || input.pointers.length === optionPointers;
|
|
};
|
|
/**
|
|
* @private
|
|
* Process the input and return the state for the recognizer
|
|
* @memberof AttrRecognizer
|
|
* @param {Object} input
|
|
* @returns {*} State
|
|
*/
|
|
|
|
|
|
_proto.process = function process(input) {
|
|
var state = this.state;
|
|
var eventType = input.eventType;
|
|
var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
|
|
var isValid = this.attrTest(input); // on cancel input and we've recognized before, return STATE_CANCELLED
|
|
|
|
if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
|
|
return state | STATE_CANCELLED;
|
|
} else if (isRecognized || isValid) {
|
|
if (eventType & INPUT_END) {
|
|
return state | STATE_ENDED;
|
|
} else if (!(state & STATE_BEGAN)) {
|
|
return STATE_BEGAN;
|
|
}
|
|
|
|
return state | STATE_CHANGED;
|
|
}
|
|
|
|
return STATE_FAILED;
|
|
};
|
|
|
|
return AttrRecognizer;
|
|
}(Recognizer);
|
|
|
|
/**
|
|
* @private
|
|
* direction cons to string
|
|
* @param {constant} direction
|
|
* @returns {String}
|
|
*/
|
|
|
|
function directionStr(direction) {
|
|
if (direction === DIRECTION_DOWN) {
|
|
return 'down';
|
|
} else if (direction === DIRECTION_UP) {
|
|
return 'up';
|
|
} else if (direction === DIRECTION_LEFT) {
|
|
return 'left';
|
|
} else if (direction === DIRECTION_RIGHT) {
|
|
return 'right';
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* Pan
|
|
* Recognized when the pointer is down and moved in the allowed direction.
|
|
* @constructor
|
|
* @extends AttrRecognizer
|
|
*/
|
|
|
|
var PanRecognizer =
|
|
/*#__PURE__*/
|
|
function (_AttrRecognizer) {
|
|
_inheritsLoose(PanRecognizer, _AttrRecognizer);
|
|
|
|
function PanRecognizer(options) {
|
|
var _this;
|
|
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
_this = _AttrRecognizer.call(this, _extends({
|
|
event: 'pan',
|
|
threshold: 10,
|
|
pointers: 1,
|
|
direction: DIRECTION_ALL
|
|
}, options)) || this;
|
|
_this.pX = null;
|
|
_this.pY = null;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = PanRecognizer.prototype;
|
|
|
|
_proto.getTouchAction = function getTouchAction() {
|
|
var direction = this.options.direction;
|
|
var actions = [];
|
|
|
|
if (direction & DIRECTION_HORIZONTAL) {
|
|
actions.push(TOUCH_ACTION_PAN_Y);
|
|
}
|
|
|
|
if (direction & DIRECTION_VERTICAL) {
|
|
actions.push(TOUCH_ACTION_PAN_X);
|
|
}
|
|
|
|
return actions;
|
|
};
|
|
|
|
_proto.directionTest = function directionTest(input) {
|
|
var options = this.options;
|
|
var hasMoved = true;
|
|
var distance = input.distance;
|
|
var direction = input.direction;
|
|
var x = input.deltaX;
|
|
var y = input.deltaY; // lock to axis?
|
|
|
|
if (!(direction & options.direction)) {
|
|
if (options.direction & DIRECTION_HORIZONTAL) {
|
|
direction = x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
|
hasMoved = x !== this.pX;
|
|
distance = Math.abs(input.deltaX);
|
|
} else {
|
|
direction = y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
|
hasMoved = y !== this.pY;
|
|
distance = Math.abs(input.deltaY);
|
|
}
|
|
}
|
|
|
|
input.direction = direction;
|
|
return hasMoved && distance > options.threshold && direction & options.direction;
|
|
};
|
|
|
|
_proto.attrTest = function attrTest(input) {
|
|
return AttrRecognizer.prototype.attrTest.call(this, input) && ( // replace with a super call
|
|
this.state & STATE_BEGAN || !(this.state & STATE_BEGAN) && this.directionTest(input));
|
|
};
|
|
|
|
_proto.emit = function emit(input) {
|
|
this.pX = input.deltaX;
|
|
this.pY = input.deltaY;
|
|
var direction = directionStr(input.direction);
|
|
|
|
if (direction) {
|
|
input.additionalEvent = this.options.event + direction;
|
|
}
|
|
|
|
_AttrRecognizer.prototype.emit.call(this, input);
|
|
};
|
|
|
|
return PanRecognizer;
|
|
}(AttrRecognizer);
|
|
|
|
/**
|
|
* @private
|
|
* Swipe
|
|
* Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction.
|
|
* @constructor
|
|
* @extends AttrRecognizer
|
|
*/
|
|
|
|
var SwipeRecognizer =
|
|
/*#__PURE__*/
|
|
function (_AttrRecognizer) {
|
|
_inheritsLoose(SwipeRecognizer, _AttrRecognizer);
|
|
|
|
function SwipeRecognizer(options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
return _AttrRecognizer.call(this, _extends({
|
|
event: 'swipe',
|
|
threshold: 10,
|
|
velocity: 0.3,
|
|
direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
|
|
pointers: 1
|
|
}, options)) || this;
|
|
}
|
|
|
|
var _proto = SwipeRecognizer.prototype;
|
|
|
|
_proto.getTouchAction = function getTouchAction() {
|
|
return PanRecognizer.prototype.getTouchAction.call(this);
|
|
};
|
|
|
|
_proto.attrTest = function attrTest(input) {
|
|
var direction = this.options.direction;
|
|
var velocity;
|
|
|
|
if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
|
|
velocity = input.overallVelocity;
|
|
} else if (direction & DIRECTION_HORIZONTAL) {
|
|
velocity = input.overallVelocityX;
|
|
} else if (direction & DIRECTION_VERTICAL) {
|
|
velocity = input.overallVelocityY;
|
|
}
|
|
|
|
return _AttrRecognizer.prototype.attrTest.call(this, input) && direction & input.offsetDirection && input.distance > this.options.threshold && input.maxPointers === this.options.pointers && abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
|
|
};
|
|
|
|
_proto.emit = function emit(input) {
|
|
var direction = directionStr(input.offsetDirection);
|
|
|
|
if (direction) {
|
|
this.manager.emit(this.options.event + direction, input);
|
|
}
|
|
|
|
this.manager.emit(this.options.event, input);
|
|
};
|
|
|
|
return SwipeRecognizer;
|
|
}(AttrRecognizer);
|
|
|
|
/**
|
|
* @private
|
|
* Pinch
|
|
* Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out).
|
|
* @constructor
|
|
* @extends AttrRecognizer
|
|
*/
|
|
|
|
var PinchRecognizer =
|
|
/*#__PURE__*/
|
|
function (_AttrRecognizer) {
|
|
_inheritsLoose(PinchRecognizer, _AttrRecognizer);
|
|
|
|
function PinchRecognizer(options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
return _AttrRecognizer.call(this, _extends({
|
|
event: 'pinch',
|
|
threshold: 0,
|
|
pointers: 2
|
|
}, options)) || this;
|
|
}
|
|
|
|
var _proto = PinchRecognizer.prototype;
|
|
|
|
_proto.getTouchAction = function getTouchAction() {
|
|
return [TOUCH_ACTION_NONE];
|
|
};
|
|
|
|
_proto.attrTest = function attrTest(input) {
|
|
return _AttrRecognizer.prototype.attrTest.call(this, input) && (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
|
|
};
|
|
|
|
_proto.emit = function emit(input) {
|
|
if (input.scale !== 1) {
|
|
var inOut = input.scale < 1 ? 'in' : 'out';
|
|
input.additionalEvent = this.options.event + inOut;
|
|
}
|
|
|
|
_AttrRecognizer.prototype.emit.call(this, input);
|
|
};
|
|
|
|
return PinchRecognizer;
|
|
}(AttrRecognizer);
|
|
|
|
/**
|
|
* @private
|
|
* Rotate
|
|
* Recognized when two or more pointer are moving in a circular motion.
|
|
* @constructor
|
|
* @extends AttrRecognizer
|
|
*/
|
|
|
|
var RotateRecognizer =
|
|
/*#__PURE__*/
|
|
function (_AttrRecognizer) {
|
|
_inheritsLoose(RotateRecognizer, _AttrRecognizer);
|
|
|
|
function RotateRecognizer(options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
return _AttrRecognizer.call(this, _extends({
|
|
event: 'rotate',
|
|
threshold: 0,
|
|
pointers: 2
|
|
}, options)) || this;
|
|
}
|
|
|
|
var _proto = RotateRecognizer.prototype;
|
|
|
|
_proto.getTouchAction = function getTouchAction() {
|
|
return [TOUCH_ACTION_NONE];
|
|
};
|
|
|
|
_proto.attrTest = function attrTest(input) {
|
|
return _AttrRecognizer.prototype.attrTest.call(this, input) && (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
|
|
};
|
|
|
|
return RotateRecognizer;
|
|
}(AttrRecognizer);
|
|
|
|
/**
|
|
* @private
|
|
* Press
|
|
* Recognized when the pointer is down for x ms without any movement.
|
|
* @constructor
|
|
* @extends Recognizer
|
|
*/
|
|
|
|
var PressRecognizer =
|
|
/*#__PURE__*/
|
|
function (_Recognizer) {
|
|
_inheritsLoose(PressRecognizer, _Recognizer);
|
|
|
|
function PressRecognizer(options) {
|
|
var _this;
|
|
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
_this = _Recognizer.call(this, _extends({
|
|
event: 'press',
|
|
pointers: 1,
|
|
time: 251,
|
|
// minimal time of the pointer to be pressed
|
|
threshold: 9
|
|
}, options)) || this;
|
|
_this._timer = null;
|
|
_this._input = null;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = PressRecognizer.prototype;
|
|
|
|
_proto.getTouchAction = function getTouchAction() {
|
|
return [TOUCH_ACTION_AUTO];
|
|
};
|
|
|
|
_proto.process = function process(input) {
|
|
var _this2 = this;
|
|
|
|
var options = this.options;
|
|
var validPointers = input.pointers.length === options.pointers;
|
|
var validMovement = input.distance < options.threshold;
|
|
var validTime = input.deltaTime > options.time;
|
|
this._input = input; // we only allow little movement
|
|
// and we've reached an end event, so a tap is possible
|
|
|
|
if (!validMovement || !validPointers || input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime) {
|
|
this.reset();
|
|
} else if (input.eventType & INPUT_START) {
|
|
this.reset();
|
|
this._timer = setTimeout(function () {
|
|
_this2.state = STATE_RECOGNIZED;
|
|
|
|
_this2.tryEmit();
|
|
}, options.time);
|
|
} else if (input.eventType & INPUT_END) {
|
|
return STATE_RECOGNIZED;
|
|
}
|
|
|
|
return STATE_FAILED;
|
|
};
|
|
|
|
_proto.reset = function reset() {
|
|
clearTimeout(this._timer);
|
|
};
|
|
|
|
_proto.emit = function emit(input) {
|
|
if (this.state !== STATE_RECOGNIZED) {
|
|
return;
|
|
}
|
|
|
|
if (input && input.eventType & INPUT_END) {
|
|
this.manager.emit(this.options.event + "up", input);
|
|
} else {
|
|
this._input.timeStamp = now();
|
|
this.manager.emit(this.options.event, this._input);
|
|
}
|
|
};
|
|
|
|
return PressRecognizer;
|
|
}(Recognizer);
|
|
|
|
var defaults = {
|
|
/**
|
|
* @private
|
|
* set if DOM events are being triggered.
|
|
* But this is slower and unused by simple implementations, so disabled by default.
|
|
* @type {Boolean}
|
|
* @default false
|
|
*/
|
|
domEvents: false,
|
|
|
|
/**
|
|
* @private
|
|
* The value for the touchAction property/fallback.
|
|
* When set to `compute` it will magically set the correct value based on the added recognizers.
|
|
* @type {String}
|
|
* @default compute
|
|
*/
|
|
touchAction: TOUCH_ACTION_COMPUTE,
|
|
|
|
/**
|
|
* @private
|
|
* @type {Boolean}
|
|
* @default true
|
|
*/
|
|
enable: true,
|
|
|
|
/**
|
|
* @private
|
|
* EXPERIMENTAL FEATURE -- can be removed/changed
|
|
* Change the parent input target element.
|
|
* If Null, then it is being set the to main element.
|
|
* @type {Null|EventTarget}
|
|
* @default null
|
|
*/
|
|
inputTarget: null,
|
|
|
|
/**
|
|
* @private
|
|
* force an input class
|
|
* @type {Null|Function}
|
|
* @default null
|
|
*/
|
|
inputClass: null,
|
|
|
|
/**
|
|
* @private
|
|
* Some CSS properties can be used to improve the working of Hammer.
|
|
* Add them to this method and they will be set when creating a new Manager.
|
|
* @namespace
|
|
*/
|
|
cssProps: {
|
|
/**
|
|
* @private
|
|
* Disables text selection to improve the dragging gesture. Mainly for desktop browsers.
|
|
* @type {String}
|
|
* @default 'none'
|
|
*/
|
|
userSelect: "none",
|
|
|
|
/**
|
|
* @private
|
|
* Disable the Windows Phone grippers when pressing an element.
|
|
* @type {String}
|
|
* @default 'none'
|
|
*/
|
|
touchSelect: "none",
|
|
|
|
/**
|
|
* @private
|
|
* Disables the default callout shown when you touch and hold a touch target.
|
|
* On iOS, when you touch and hold a touch target such as a link, Safari displays
|
|
* a callout containing information about the link. This property allows you to disable that callout.
|
|
* @type {String}
|
|
* @default 'none'
|
|
*/
|
|
touchCallout: "none",
|
|
|
|
/**
|
|
* @private
|
|
* Specifies whether zooming is enabled. Used by IE10>
|
|
* @type {String}
|
|
* @default 'none'
|
|
*/
|
|
contentZooming: "none",
|
|
|
|
/**
|
|
* @private
|
|
* Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers.
|
|
* @type {String}
|
|
* @default 'none'
|
|
*/
|
|
userDrag: "none",
|
|
|
|
/**
|
|
* @private
|
|
* Overrides the highlight color shown when the user taps a link or a JavaScript
|
|
* clickable element in iOS. This property obeys the alpha value, if specified.
|
|
* @type {String}
|
|
* @default 'rgba(0,0,0,0)'
|
|
*/
|
|
tapHighlightColor: "rgba(0,0,0,0)"
|
|
}
|
|
};
|
|
/**
|
|
* @private
|
|
* Default recognizer setup when calling `Hammer()`
|
|
* When creating a new Manager these will be skipped.
|
|
* This is separated with other defaults because of tree-shaking.
|
|
* @type {Array}
|
|
*/
|
|
|
|
var preset = [[RotateRecognizer, {
|
|
enable: false
|
|
}], [PinchRecognizer, {
|
|
enable: false
|
|
}, ['rotate']], [SwipeRecognizer, {
|
|
direction: DIRECTION_HORIZONTAL
|
|
}], [PanRecognizer, {
|
|
direction: DIRECTION_HORIZONTAL
|
|
}, ['swipe']], [TapRecognizer], [TapRecognizer, {
|
|
event: 'doubletap',
|
|
taps: 2
|
|
}, ['tap']], [PressRecognizer]];
|
|
|
|
var STOP = 1;
|
|
var FORCED_STOP = 2;
|
|
/**
|
|
* @private
|
|
* add/remove the css properties as defined in manager.options.cssProps
|
|
* @param {Manager} manager
|
|
* @param {Boolean} add
|
|
*/
|
|
|
|
function toggleCssProps(manager, add) {
|
|
var element = manager.element;
|
|
|
|
if (!element.style) {
|
|
return;
|
|
}
|
|
|
|
var prop;
|
|
each(manager.options.cssProps, function (value, name) {
|
|
prop = prefixed(element.style, name);
|
|
|
|
if (add) {
|
|
manager.oldCssProps[prop] = element.style[prop];
|
|
element.style[prop] = value;
|
|
} else {
|
|
element.style[prop] = manager.oldCssProps[prop] || "";
|
|
}
|
|
});
|
|
|
|
if (!add) {
|
|
manager.oldCssProps = {};
|
|
}
|
|
}
|
|
/**
|
|
* @private
|
|
* trigger dom event
|
|
* @param {String} event
|
|
* @param {Object} data
|
|
*/
|
|
|
|
|
|
function triggerDomEvent(event, data) {
|
|
var gestureEvent = document.createEvent("Event");
|
|
gestureEvent.initEvent(event, true, true);
|
|
gestureEvent.gesture = data;
|
|
data.target.dispatchEvent(gestureEvent);
|
|
}
|
|
/**
|
|
* @private
|
|
* Manager
|
|
* @param {HTMLElement} element
|
|
* @param {Object} [options]
|
|
* @constructor
|
|
*/
|
|
|
|
|
|
var Manager =
|
|
/*#__PURE__*/
|
|
function () {
|
|
function Manager(element, options) {
|
|
var _this = this;
|
|
|
|
this.options = assign$1({}, defaults, options || {});
|
|
this.options.inputTarget = this.options.inputTarget || element;
|
|
this.handlers = {};
|
|
this.session = {};
|
|
this.recognizers = [];
|
|
this.oldCssProps = {};
|
|
this.element = element;
|
|
this.input = createInputInstance(this);
|
|
this.touchAction = new TouchAction(this, this.options.touchAction);
|
|
toggleCssProps(this, true);
|
|
each(this.options.recognizers, function (item) {
|
|
var recognizer = _this.add(new item[0](item[1]));
|
|
|
|
item[2] && recognizer.recognizeWith(item[2]);
|
|
item[3] && recognizer.requireFailure(item[3]);
|
|
}, this);
|
|
}
|
|
/**
|
|
* @private
|
|
* set options
|
|
* @param {Object} options
|
|
* @returns {Manager}
|
|
*/
|
|
|
|
|
|
var _proto = Manager.prototype;
|
|
|
|
_proto.set = function set(options) {
|
|
assign$1(this.options, options); // Options that need a little more setup
|
|
|
|
if (options.touchAction) {
|
|
this.touchAction.update();
|
|
}
|
|
|
|
if (options.inputTarget) {
|
|
// Clean up existing event listeners and reinitialize
|
|
this.input.destroy();
|
|
this.input.target = options.inputTarget;
|
|
this.input.init();
|
|
}
|
|
|
|
return this;
|
|
};
|
|
/**
|
|
* @private
|
|
* stop recognizing for this session.
|
|
* This session will be discarded, when a new [input]start event is fired.
|
|
* When forced, the recognizer cycle is stopped immediately.
|
|
* @param {Boolean} [force]
|
|
*/
|
|
|
|
|
|
_proto.stop = function stop(force) {
|
|
this.session.stopped = force ? FORCED_STOP : STOP;
|
|
};
|
|
/**
|
|
* @private
|
|
* run the recognizers!
|
|
* called by the inputHandler function on every movement of the pointers (touches)
|
|
* it walks through all the recognizers and tries to detect the gesture that is being made
|
|
* @param {Object} inputData
|
|
*/
|
|
|
|
|
|
_proto.recognize = function recognize(inputData) {
|
|
var session = this.session;
|
|
|
|
if (session.stopped) {
|
|
return;
|
|
} // run the touch-action polyfill
|
|
|
|
|
|
this.touchAction.preventDefaults(inputData);
|
|
var recognizer;
|
|
var recognizers = this.recognizers; // this holds the recognizer that is being recognized.
|
|
// so the recognizer's state needs to be BEGAN, CHANGED, ENDED or RECOGNIZED
|
|
// if no recognizer is detecting a thing, it is set to `null`
|
|
|
|
var curRecognizer = session.curRecognizer; // reset when the last recognizer is recognized
|
|
// or when we're in a new session
|
|
|
|
if (!curRecognizer || curRecognizer && curRecognizer.state & STATE_RECOGNIZED) {
|
|
session.curRecognizer = null;
|
|
curRecognizer = null;
|
|
}
|
|
|
|
var i = 0;
|
|
|
|
while (i < recognizers.length) {
|
|
recognizer = recognizers[i]; // find out if we are allowed try to recognize the input for this one.
|
|
// 1. allow if the session is NOT forced stopped (see the .stop() method)
|
|
// 2. allow if we still haven't recognized a gesture in this session, or the this recognizer is the one
|
|
// that is being recognized.
|
|
// 3. allow if the recognizer is allowed to run simultaneous with the current recognized recognizer.
|
|
// this can be setup with the `recognizeWith()` method on the recognizer.
|
|
|
|
if (session.stopped !== FORCED_STOP && ( // 1
|
|
!curRecognizer || recognizer === curRecognizer || // 2
|
|
recognizer.canRecognizeWith(curRecognizer))) {
|
|
// 3
|
|
recognizer.recognize(inputData);
|
|
} else {
|
|
recognizer.reset();
|
|
} // if the recognizer has been recognizing the input as a valid gesture, we want to store this one as the
|
|
// current active recognizer. but only if we don't already have an active recognizer
|
|
|
|
|
|
if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
|
|
session.curRecognizer = recognizer;
|
|
curRecognizer = recognizer;
|
|
}
|
|
|
|
i++;
|
|
}
|
|
};
|
|
/**
|
|
* @private
|
|
* get a recognizer by its event name.
|
|
* @param {Recognizer|String} recognizer
|
|
* @returns {Recognizer|Null}
|
|
*/
|
|
|
|
|
|
_proto.get = function get(recognizer) {
|
|
if (recognizer instanceof Recognizer) {
|
|
return recognizer;
|
|
}
|
|
|
|
var recognizers = this.recognizers;
|
|
|
|
for (var i = 0; i < recognizers.length; i++) {
|
|
if (recognizers[i].options.event === recognizer) {
|
|
return recognizers[i];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
};
|
|
/**
|
|
* @private add a recognizer to the manager
|
|
* existing recognizers with the same event name will be removed
|
|
* @param {Recognizer} recognizer
|
|
* @returns {Recognizer|Manager}
|
|
*/
|
|
|
|
|
|
_proto.add = function add(recognizer) {
|
|
if (invokeArrayArg(recognizer, "add", this)) {
|
|
return this;
|
|
} // remove existing
|
|
|
|
|
|
var existing = this.get(recognizer.options.event);
|
|
|
|
if (existing) {
|
|
this.remove(existing);
|
|
}
|
|
|
|
this.recognizers.push(recognizer);
|
|
recognizer.manager = this;
|
|
this.touchAction.update();
|
|
return recognizer;
|
|
};
|
|
/**
|
|
* @private
|
|
* remove a recognizer by name or instance
|
|
* @param {Recognizer|String} recognizer
|
|
* @returns {Manager}
|
|
*/
|
|
|
|
|
|
_proto.remove = function remove(recognizer) {
|
|
if (invokeArrayArg(recognizer, "remove", this)) {
|
|
return this;
|
|
}
|
|
|
|
var targetRecognizer = this.get(recognizer); // let's make sure this recognizer exists
|
|
|
|
if (recognizer) {
|
|
var recognizers = this.recognizers;
|
|
var index = inArray(recognizers, targetRecognizer);
|
|
|
|
if (index !== -1) {
|
|
recognizers.splice(index, 1);
|
|
this.touchAction.update();
|
|
}
|
|
}
|
|
|
|
return this;
|
|
};
|
|
/**
|
|
* @private
|
|
* bind event
|
|
* @param {String} events
|
|
* @param {Function} handler
|
|
* @returns {EventEmitter} this
|
|
*/
|
|
|
|
|
|
_proto.on = function on(events, handler) {
|
|
if (events === undefined || handler === undefined) {
|
|
return this;
|
|
}
|
|
|
|
var handlers = this.handlers;
|
|
each(splitStr(events), function (event) {
|
|
handlers[event] = handlers[event] || [];
|
|
handlers[event].push(handler);
|
|
});
|
|
return this;
|
|
};
|
|
/**
|
|
* @private unbind event, leave emit blank to remove all handlers
|
|
* @param {String} events
|
|
* @param {Function} [handler]
|
|
* @returns {EventEmitter} this
|
|
*/
|
|
|
|
|
|
_proto.off = function off(events, handler) {
|
|
if (events === undefined) {
|
|
return this;
|
|
}
|
|
|
|
var handlers = this.handlers;
|
|
each(splitStr(events), function (event) {
|
|
if (!handler) {
|
|
delete handlers[event];
|
|
} else {
|
|
handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
|
|
}
|
|
});
|
|
return this;
|
|
};
|
|
/**
|
|
* @private emit event to the listeners
|
|
* @param {String} event
|
|
* @param {Object} data
|
|
*/
|
|
|
|
|
|
_proto.emit = function emit(event, data) {
|
|
// we also want to trigger dom events
|
|
if (this.options.domEvents) {
|
|
triggerDomEvent(event, data);
|
|
} // no handlers, so skip it all
|
|
|
|
|
|
var handlers = this.handlers[event] && this.handlers[event].slice();
|
|
|
|
if (!handlers || !handlers.length) {
|
|
return;
|
|
}
|
|
|
|
data.type = event;
|
|
|
|
data.preventDefault = function () {
|
|
data.srcEvent.preventDefault();
|
|
};
|
|
|
|
var i = 0;
|
|
|
|
while (i < handlers.length) {
|
|
handlers[i](data);
|
|
i++;
|
|
}
|
|
};
|
|
/**
|
|
* @private
|
|
* destroy the manager and unbinds all events
|
|
* it doesn't unbind dom events, that is the user own responsibility
|
|
*/
|
|
|
|
|
|
_proto.destroy = function destroy() {
|
|
this.element && toggleCssProps(this, false);
|
|
this.handlers = {};
|
|
this.session = {};
|
|
this.input.destroy();
|
|
this.element = null;
|
|
};
|
|
|
|
return Manager;
|
|
}();
|
|
|
|
var SINGLE_TOUCH_INPUT_MAP = {
|
|
touchstart: INPUT_START,
|
|
touchmove: INPUT_MOVE,
|
|
touchend: INPUT_END,
|
|
touchcancel: INPUT_CANCEL
|
|
};
|
|
var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
|
|
var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
|
|
/**
|
|
* @private
|
|
* Touch events input
|
|
* @constructor
|
|
* @extends Input
|
|
*/
|
|
|
|
var SingleTouchInput =
|
|
/*#__PURE__*/
|
|
function (_Input) {
|
|
_inheritsLoose(SingleTouchInput, _Input);
|
|
|
|
function SingleTouchInput() {
|
|
var _this;
|
|
|
|
var proto = SingleTouchInput.prototype;
|
|
proto.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
|
|
proto.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
|
|
_this = _Input.apply(this, arguments) || this;
|
|
_this.started = false;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = SingleTouchInput.prototype;
|
|
|
|
_proto.handler = function handler(ev) {
|
|
var type = SINGLE_TOUCH_INPUT_MAP[ev.type]; // should we handle the touch events?
|
|
|
|
if (type === INPUT_START) {
|
|
this.started = true;
|
|
}
|
|
|
|
if (!this.started) {
|
|
return;
|
|
}
|
|
|
|
var touches = normalizeSingleTouches.call(this, ev, type); // when done, reset the started state
|
|
|
|
if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
|
|
this.started = false;
|
|
}
|
|
|
|
this.callback(this.manager, type, {
|
|
pointers: touches[0],
|
|
changedPointers: touches[1],
|
|
pointerType: INPUT_TYPE_TOUCH,
|
|
srcEvent: ev
|
|
});
|
|
};
|
|
|
|
return SingleTouchInput;
|
|
}(Input);
|
|
|
|
function normalizeSingleTouches(ev, type) {
|
|
var all = toArray(ev.touches);
|
|
var changed = toArray(ev.changedTouches);
|
|
|
|
if (type & (INPUT_END | INPUT_CANCEL)) {
|
|
all = uniqueArray(all.concat(changed), 'identifier', true);
|
|
}
|
|
|
|
return [all, changed];
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* wrap a method with a deprecation warning and stack trace
|
|
* @param {Function} method
|
|
* @param {String} name
|
|
* @param {String} message
|
|
* @returns {Function} A new function wrapping the supplied method.
|
|
*/
|
|
function deprecate(method, name, message) {
|
|
var deprecationMessage = "DEPRECATED METHOD: " + name + "\n" + message + " AT \n";
|
|
return function () {
|
|
var e = new Error('get-stack-trace');
|
|
var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '').replace(/^\s+at\s+/gm, '').replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
|
|
var log = window.console && (window.console.warn || window.console.log);
|
|
|
|
if (log) {
|
|
log.call(window.console, deprecationMessage, stack);
|
|
}
|
|
|
|
return method.apply(this, arguments);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* extend object.
|
|
* means that properties in dest will be overwritten by the ones in src.
|
|
* @param {Object} dest
|
|
* @param {Object} src
|
|
* @param {Boolean} [merge=false]
|
|
* @returns {Object} dest
|
|
*/
|
|
|
|
var extend = deprecate(function (dest, src, merge) {
|
|
var keys = Object.keys(src);
|
|
var i = 0;
|
|
|
|
while (i < keys.length) {
|
|
if (!merge || merge && dest[keys[i]] === undefined) {
|
|
dest[keys[i]] = src[keys[i]];
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
return dest;
|
|
}, 'extend', 'Use `assign`.');
|
|
|
|
/**
|
|
* @private
|
|
* merge the values from src in the dest.
|
|
* means that properties that exist in dest will not be overwritten by src
|
|
* @param {Object} dest
|
|
* @param {Object} src
|
|
* @returns {Object} dest
|
|
*/
|
|
|
|
var merge = deprecate(function (dest, src) {
|
|
return extend(dest, src, true);
|
|
}, 'merge', 'Use `assign`.');
|
|
|
|
/**
|
|
* @private
|
|
* simple class inheritance
|
|
* @param {Function} child
|
|
* @param {Function} base
|
|
* @param {Object} [properties]
|
|
*/
|
|
|
|
function inherit(child, base, properties) {
|
|
var baseP = base.prototype;
|
|
var childP;
|
|
childP = child.prototype = Object.create(baseP);
|
|
childP.constructor = child;
|
|
childP._super = baseP;
|
|
|
|
if (properties) {
|
|
assign$1(childP, properties);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* simple function bind
|
|
* @param {Function} fn
|
|
* @param {Object} context
|
|
* @returns {Function}
|
|
*/
|
|
function bindFn(fn, context) {
|
|
return function boundFn() {
|
|
return fn.apply(context, arguments);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* Simple way to create a manager with a default set of recognizers.
|
|
* @param {HTMLElement} element
|
|
* @param {Object} [options]
|
|
* @constructor
|
|
*/
|
|
|
|
var Hammer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var Hammer =
|
|
/**
|
|
* @private
|
|
* @const {string}
|
|
*/
|
|
function Hammer(element, options) {
|
|
if (options === void 0) {
|
|
options = {};
|
|
}
|
|
|
|
return new Manager(element, _extends({
|
|
recognizers: preset.concat()
|
|
}, options));
|
|
};
|
|
|
|
Hammer.VERSION = "2.0.17-rc";
|
|
Hammer.DIRECTION_ALL = DIRECTION_ALL;
|
|
Hammer.DIRECTION_DOWN = DIRECTION_DOWN;
|
|
Hammer.DIRECTION_LEFT = DIRECTION_LEFT;
|
|
Hammer.DIRECTION_RIGHT = DIRECTION_RIGHT;
|
|
Hammer.DIRECTION_UP = DIRECTION_UP;
|
|
Hammer.DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL;
|
|
Hammer.DIRECTION_VERTICAL = DIRECTION_VERTICAL;
|
|
Hammer.DIRECTION_NONE = DIRECTION_NONE;
|
|
Hammer.DIRECTION_DOWN = DIRECTION_DOWN;
|
|
Hammer.INPUT_START = INPUT_START;
|
|
Hammer.INPUT_MOVE = INPUT_MOVE;
|
|
Hammer.INPUT_END = INPUT_END;
|
|
Hammer.INPUT_CANCEL = INPUT_CANCEL;
|
|
Hammer.STATE_POSSIBLE = STATE_POSSIBLE;
|
|
Hammer.STATE_BEGAN = STATE_BEGAN;
|
|
Hammer.STATE_CHANGED = STATE_CHANGED;
|
|
Hammer.STATE_ENDED = STATE_ENDED;
|
|
Hammer.STATE_RECOGNIZED = STATE_RECOGNIZED;
|
|
Hammer.STATE_CANCELLED = STATE_CANCELLED;
|
|
Hammer.STATE_FAILED = STATE_FAILED;
|
|
Hammer.Manager = Manager;
|
|
Hammer.Input = Input;
|
|
Hammer.TouchAction = TouchAction;
|
|
Hammer.TouchInput = TouchInput;
|
|
Hammer.MouseInput = MouseInput;
|
|
Hammer.PointerEventInput = PointerEventInput;
|
|
Hammer.TouchMouseInput = TouchMouseInput;
|
|
Hammer.SingleTouchInput = SingleTouchInput;
|
|
Hammer.Recognizer = Recognizer;
|
|
Hammer.AttrRecognizer = AttrRecognizer;
|
|
Hammer.Tap = TapRecognizer;
|
|
Hammer.Pan = PanRecognizer;
|
|
Hammer.Swipe = SwipeRecognizer;
|
|
Hammer.Pinch = PinchRecognizer;
|
|
Hammer.Rotate = RotateRecognizer;
|
|
Hammer.Press = PressRecognizer;
|
|
Hammer.on = addEventListeners;
|
|
Hammer.off = removeEventListeners;
|
|
Hammer.each = each;
|
|
Hammer.merge = merge;
|
|
Hammer.extend = extend;
|
|
Hammer.bindFn = bindFn;
|
|
Hammer.assign = assign$1;
|
|
Hammer.inherit = inherit;
|
|
Hammer.bindFn = bindFn;
|
|
Hammer.prefixed = prefixed;
|
|
Hammer.toArray = toArray;
|
|
Hammer.inArray = inArray;
|
|
Hammer.uniqueArray = uniqueArray;
|
|
Hammer.splitStr = splitStr;
|
|
Hammer.boolOrFn = boolOrFn;
|
|
Hammer.hasParent = hasParent;
|
|
Hammer.addEventListeners = addEventListeners;
|
|
Hammer.removeEventListeners = removeEventListeners;
|
|
Hammer.defaults = assign$1({}, defaults, {
|
|
preset: preset
|
|
});
|
|
return Hammer;
|
|
}();
|
|
|
|
// style loader but by script tag, not by the loader.
|
|
|
|
var defaults$1 = Hammer.defaults;
|
|
|
|
var hammer_esm = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
'default': Hammer,
|
|
INPUT_START: INPUT_START,
|
|
INPUT_MOVE: INPUT_MOVE,
|
|
INPUT_END: INPUT_END,
|
|
INPUT_CANCEL: INPUT_CANCEL,
|
|
STATE_POSSIBLE: STATE_POSSIBLE,
|
|
STATE_BEGAN: STATE_BEGAN,
|
|
STATE_CHANGED: STATE_CHANGED,
|
|
STATE_ENDED: STATE_ENDED,
|
|
STATE_RECOGNIZED: STATE_RECOGNIZED,
|
|
STATE_CANCELLED: STATE_CANCELLED,
|
|
STATE_FAILED: STATE_FAILED,
|
|
DIRECTION_NONE: DIRECTION_NONE,
|
|
DIRECTION_LEFT: DIRECTION_LEFT,
|
|
DIRECTION_RIGHT: DIRECTION_RIGHT,
|
|
DIRECTION_UP: DIRECTION_UP,
|
|
DIRECTION_DOWN: DIRECTION_DOWN,
|
|
DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
|
|
DIRECTION_VERTICAL: DIRECTION_VERTICAL,
|
|
DIRECTION_ALL: DIRECTION_ALL,
|
|
Manager: Manager,
|
|
Input: Input,
|
|
TouchAction: TouchAction,
|
|
TouchInput: TouchInput,
|
|
MouseInput: MouseInput,
|
|
PointerEventInput: PointerEventInput,
|
|
TouchMouseInput: TouchMouseInput,
|
|
SingleTouchInput: SingleTouchInput,
|
|
Recognizer: Recognizer,
|
|
AttrRecognizer: AttrRecognizer,
|
|
Tap: TapRecognizer,
|
|
Pan: PanRecognizer,
|
|
Swipe: SwipeRecognizer,
|
|
Pinch: PinchRecognizer,
|
|
Rotate: RotateRecognizer,
|
|
Press: PressRecognizer,
|
|
on: addEventListeners,
|
|
off: removeEventListeners,
|
|
each: each,
|
|
merge: merge,
|
|
extend: extend,
|
|
assign: assign$1,
|
|
inherit: inherit,
|
|
bindFn: bindFn,
|
|
prefixed: prefixed,
|
|
toArray: toArray,
|
|
inArray: inArray,
|
|
uniqueArray: uniqueArray,
|
|
splitStr: splitStr,
|
|
boolOrFn: boolOrFn,
|
|
hasParent: hasParent,
|
|
addEventListeners: addEventListeners,
|
|
removeEventListeners: removeEventListeners,
|
|
defaults: defaults$1
|
|
});
|
|
|
|
var require$$0 = /*@__PURE__*/getAugmentedNamespace(hammer_esm);
|
|
|
|
var Utils = {};
|
|
|
|
Object.defineProperty(Utils, "__esModule", { value: true });
|
|
Utils.delay = Utils.blackPixel = Utils.isMobile = void 0;
|
|
function isMobile() {
|
|
return /Android|iPhone|iPad|iPod|Opera Mini|IEMobile|WPDesktop/i.test(navigator.userAgent);
|
|
}
|
|
Utils.isMobile = isMobile;
|
|
Utils.blackPixel = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
|
|
function delay(duration) {
|
|
return new Promise(function (resolve) { return setTimeout(resolve, duration); });
|
|
}
|
|
Utils.delay = delay;
|
|
|
|
var hasRequiredComponent_ImageViewer;
|
|
|
|
function requireComponent_ImageViewer () {
|
|
if (hasRequiredComponent_ImageViewer) return Component_ImageViewer;
|
|
hasRequiredComponent_ImageViewer = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
function step(op) {
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
switch (op[0]) {
|
|
case 0: case 1: t = op; break;
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
default:
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
if (t[2]) _.ops.pop();
|
|
_.trys.pop(); continue;
|
|
}
|
|
op = body.call(thisArg, _);
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
}
|
|
};
|
|
Object.defineProperty(Component_ImageViewer, "__esModule", { value: true });
|
|
Component_ImageViewer.ComponentImageViewer = void 0;
|
|
var hammerjs_1 = require$$0;
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var Utils_1 = Utils;
|
|
var Morph_Components_1 = requireMorph_Components();
|
|
var ComponentImageViewer = /** @class */ (function (_super) {
|
|
__extends(ComponentImageViewer, _super);
|
|
function ComponentImageViewer(options) {
|
|
var _a, _b, _c, _d, _e;
|
|
var _this = _super.call(this) || this;
|
|
_this._rawScale = 1;
|
|
_this._relativeScale = 1;
|
|
_this._relativeScaleBase = 1;
|
|
_this._left = 0;
|
|
_this._top = 0;
|
|
_this._firstLoad = true;
|
|
_this._dragging = false;
|
|
_this._dragStart = { originX: 0, originY: 0, startX: 0, startY: 0 };
|
|
window.viewer = _this;
|
|
_this.background = (_a = options === null || options === void 0 ? void 0 : options.background) !== null && _a !== void 0 ? _a : true;
|
|
_this.container = (0, CE_1.ce)('div', 'mux_imageviewer');
|
|
if (options.background != false)
|
|
_this.container.style.background = 'var(--mux-panel-sub-color)';
|
|
_this._wrapper = (0, CE_1.ce)('div', 'mux_imageviewer-wrapper');
|
|
_this._image = (0, CE_1.ce)('img', 'mux_imageviewer-image');
|
|
_this._image.style.display = 'none';
|
|
_this._image.addEventListener('load', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
this._stopLoader();
|
|
return [4 /*yield*/, (0, Utils_1.delay)(10)];
|
|
case 1:
|
|
_a.sent();
|
|
this._image.style.display = 'block';
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
}); });
|
|
_this._unsupported = (0, CE_1.ce)('div', 'mux_imageviewer-unsupported');
|
|
_this._unsupportedIcon = (0, CE_1.ce)('span', [
|
|
'material-symbols-outlined',
|
|
'mux_imageviewer-unsupported-icon',
|
|
]);
|
|
_this._unsupportedText = (0, CE_1.ce)('div', 'mux_text');
|
|
_this._unsupportedButton = new Morph_Components_1.MorphComponent.Button({
|
|
mode: 'normal',
|
|
content: 'Open externally',
|
|
materialIcon: 'open_in_new',
|
|
target: function () {
|
|
window.open(_this._unsupportedTarget, '_blank');
|
|
},
|
|
}).container;
|
|
_this._unsupported.append(_this._unsupportedIcon, _this._unsupportedText, _this._unsupportedButton);
|
|
_this._wrapper.appendChild(_this._unsupported);
|
|
_this._wrapper.appendChild(_this._image);
|
|
_this._loader = (0, CE_1.ce)('div', 'mux_imageviewer-loader');
|
|
_this._loader.append((0, CE_1.ce)('div', 'mux_imageviewer-loader-dot'), (0, CE_1.ce)('div', 'mux_imageviewer-loader-dot'), (0, CE_1.ce)('div', 'mux_imageviewer-loader-dot'), (0, CE_1.ce)('div', 'mux_imageviewer-loader-dot'));
|
|
_this._wrapper.appendChild(_this._loader);
|
|
var controlscontainer = (0, CE_1.ce)('div', 'mux_imageviewer-controlscontainer');
|
|
var controls = (0, CE_1.ce)('div', 'mux_imageviewer-controls');
|
|
controlscontainer.appendChild(controls);
|
|
if ((options === null || options === void 0 ? void 0 : options.controls) != false) {
|
|
var srcCount = (_c = (_b = options === null || options === void 0 ? void 0 : options.src) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
if (srcCount > 1) {
|
|
_this._thumbnails = (0, CE_1.ce)('div', [
|
|
'mux_imageviewer-control',
|
|
'mux_active',
|
|
]);
|
|
_this._thumbnails.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'photo_library'));
|
|
_this._thumbnails.appendChild((0, CE_1.ce)('span', [
|
|
'mux_imageviewer-control-badge',
|
|
'mux_text',
|
|
'mux_tiny',
|
|
], null, String(srcCount)));
|
|
controls.appendChild(_this._thumbnails);
|
|
}
|
|
_this._zoomIn = (0, CE_1.ce)('div', 'mux_imageviewer-control');
|
|
_this._zoomIn.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'zoom_in'));
|
|
_this._zoomOut = (0, CE_1.ce)('div', 'mux_imageviewer-control');
|
|
_this._zoomOut.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'zoom_out'));
|
|
_this._fit = (0, CE_1.ce)('div', 'mux_imageviewer-control');
|
|
_this._fit.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'fit_screen'));
|
|
_this._highRes = (0, CE_1.ce)('div', 'mux_imageviewer-control');
|
|
_this._highRes.style.display = 'none';
|
|
_this._highRes.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'high_res'));
|
|
controls.append(_this._zoomIn, _this._zoomOut, _this._fit, _this._highRes);
|
|
}
|
|
if ((options === null || options === void 0 ? void 0 : options.downloadable) == true) {
|
|
var download = (0, CE_1.ce)('div', 'mux_imageviewer-control');
|
|
download.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'download'));
|
|
download.addEventListener('click', function () {
|
|
var a = document.createElement('a');
|
|
a.href = _this._image.src;
|
|
a.download = 'image';
|
|
a.click();
|
|
});
|
|
controls.appendChild(download);
|
|
}
|
|
if (controls.childNodes.length > 0)
|
|
_this._wrapper.appendChild(controlscontainer);
|
|
_this.container.appendChild(_this._wrapper);
|
|
if ((options === null || options === void 0 ? void 0 : options.src) instanceof Array) {
|
|
var sources = options.src;
|
|
if (sources.length == 0)
|
|
return _this;
|
|
if (sources.length == 1) {
|
|
_this.setImage(sources[0]);
|
|
}
|
|
else {
|
|
_this._sources = sources;
|
|
_this._drawThumbnails(sources, (_d = options === null || options === void 0 ? void 0 : options.thumbnailsOpen) !== null && _d !== void 0 ? _d : ((0, Utils_1.isMobile)() ? false : true));
|
|
_this._drawNavigationControls();
|
|
_this._imageCount = sources.length;
|
|
var startIndex = (_e = options === null || options === void 0 ? void 0 : options.startSrc) !== null && _e !== void 0 ? _e : 0;
|
|
_this.setImage(sources[startIndex], startIndex);
|
|
}
|
|
}
|
|
else {
|
|
var source = options.src;
|
|
_this.setImage(source);
|
|
}
|
|
_this.registerListeners();
|
|
return _this;
|
|
}
|
|
ComponentImageViewer.prototype.setImage = function (source, index) {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var extention;
|
|
var _this = this;
|
|
var _a, _b, _c;
|
|
return __generator(this, function (_d) {
|
|
switch (_d.label) {
|
|
case 0:
|
|
this._startLoader();
|
|
return [4 /*yield*/, (0, Utils_1.delay)(10)];
|
|
case 1:
|
|
_d.sent();
|
|
this._updateUI(index);
|
|
if (source.normal.split('/').pop().split('.').length > 1) {
|
|
extention = (_b = (_a = source.normal.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
|
|
if (!['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(extention)) {
|
|
this._unsupportedTarget = (_c = source.full) !== null && _c !== void 0 ? _c : source.normal;
|
|
if (['mp4', 'webm'].includes(extention)) {
|
|
return [2 /*return*/, this._showUnsupported('play_arrow', "Videos are not supported yet. Please open the file in a new tab.")];
|
|
}
|
|
return [2 /*return*/, this._showUnsupported('error_outline', "File extention ".concat(extention, " is not supported!"))];
|
|
}
|
|
}
|
|
else
|
|
this._image.onerror = function () {
|
|
_this._showUnsupported('error_outline', "File extention ".concat(extention, " is not supported!"));
|
|
};
|
|
this._image.src = source.normal;
|
|
if (source.full != undefined) {
|
|
this._fullSrc = source.full;
|
|
this._highRes.style.display = 'flex';
|
|
}
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
ComponentImageViewer.prototype.next = function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var current, next;
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
current = this.container.querySelector('.mux_imageviewer-gallery-thumb.active');
|
|
if (current == null)
|
|
return [2 /*return*/];
|
|
next = current.nextElementSibling;
|
|
if (next == null)
|
|
return [2 /*return*/];
|
|
this._startLoader();
|
|
return [4 /*yield*/, (0, Utils_1.delay)(10)];
|
|
case 1:
|
|
_a.sent();
|
|
next.click();
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
ComponentImageViewer.prototype.previous = function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var current, prev;
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
current = this.container.querySelector('.mux_imageviewer-gallery-thumb.active');
|
|
if (current == null)
|
|
return [2 /*return*/];
|
|
prev = current.previousElementSibling;
|
|
if (prev == null)
|
|
return [2 /*return*/];
|
|
this._startLoader();
|
|
return [4 /*yield*/, (0, Utils_1.delay)(10)];
|
|
case 1:
|
|
_a.sent();
|
|
prev.click();
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
ComponentImageViewer.prototype._updateUI = function (index) {
|
|
if (index != undefined) {
|
|
this.callEvent('imageIndexChanged', index);
|
|
var previousThumb = this.container.querySelector('.mux_imageviewer-gallery-thumb.active');
|
|
if (previousThumb != null)
|
|
previousThumb.classList.remove('active');
|
|
var thumb = this.container.querySelector(".mux_imageviewer-gallery-thumb[index=\"".concat(index, "\"]"));
|
|
if (thumb != null) {
|
|
thumb.classList.add('active');
|
|
thumb.scrollIntoView({
|
|
behavior: 'smooth',
|
|
inline: 'center',
|
|
});
|
|
if (this._firstLoad) {
|
|
this._firstLoad = false;
|
|
setTimeout(function () {
|
|
thumb.scrollIntoView({
|
|
behavior: 'smooth',
|
|
inline: 'center',
|
|
});
|
|
}, 500);
|
|
}
|
|
}
|
|
}
|
|
if (this._prev != undefined)
|
|
if (index == 0)
|
|
this._prev.classList.add('disabled');
|
|
else
|
|
this._prev.classList.remove('disabled');
|
|
if (this._next != undefined)
|
|
if (index == this._imageCount - 1)
|
|
this._next.classList.add('disabled');
|
|
else
|
|
this._next.classList.remove('disabled');
|
|
};
|
|
ComponentImageViewer.prototype._showUnsupported = function (icon, text) {
|
|
this._unsupportedIcon.innerText = icon;
|
|
this._unsupportedText.innerText = text;
|
|
this._stopLoader();
|
|
this._unsupported.style.display = 'flex';
|
|
};
|
|
ComponentImageViewer.prototype._startLoader = function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
this._loader.style.display = 'flex';
|
|
this._unsupported.style.display = 'none';
|
|
this._image.style.display = 'none';
|
|
return [4 /*yield*/, (0, Utils_1.delay)(10)];
|
|
case 1:
|
|
_a.sent();
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
ComponentImageViewer.prototype._stopLoader = function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
this._loader.style.display = 'none';
|
|
this._restartScaling();
|
|
return [2 /*return*/];
|
|
});
|
|
});
|
|
};
|
|
ComponentImageViewer.prototype._handleStart = function (originX, originY) {
|
|
this._dragging = true;
|
|
this._dragStart = {
|
|
originX: originX,
|
|
originY: originY,
|
|
startX: this._image.offsetLeft,
|
|
startY: this._image.offsetTop,
|
|
};
|
|
};
|
|
ComponentImageViewer.prototype._handleMove = function (x, y) {
|
|
var newX = this._validateX(this._dragStart.startX + x - this._dragStart.originX);
|
|
var newY = this._validateY(this._dragStart.startY + y - this._dragStart.originY);
|
|
this._left = newX;
|
|
this._top = newY;
|
|
this._image.style.left = "".concat(newX, "px");
|
|
this._image.style.top = "".concat(newY, "px");
|
|
};
|
|
ComponentImageViewer.prototype.registerListeners = function () {
|
|
var _this = this;
|
|
//Start
|
|
this.container.addEventListener('mousedown', function (e) {
|
|
_this._handleStart(e.clientX, e.clientY);
|
|
});
|
|
this.container.addEventListener('touchstart', function (e) {
|
|
_this._handleStart(e.touches[0].clientX, e.touches[0].clientY);
|
|
});
|
|
//Move
|
|
this.container.addEventListener('mousemove', function (e) {
|
|
if (!_this._dragging)
|
|
return;
|
|
if (e.buttons != 1) {
|
|
_this._dragging = false;
|
|
return;
|
|
}
|
|
_this._handleMove(e.clientX, e.clientY);
|
|
});
|
|
this.container.addEventListener('touchmove', function (e) {
|
|
if (!_this._dragging)
|
|
return;
|
|
_this._handleMove(e.touches[0].clientX, e.touches[0].clientY);
|
|
});
|
|
//End
|
|
this.container.addEventListener('mouseup', function (e) {
|
|
_this._dragging = false;
|
|
});
|
|
this.container.addEventListener('touchend', function (e) {
|
|
_this._dragging = false;
|
|
});
|
|
//Zoom
|
|
this.container.addEventListener('wheel', function (e) {
|
|
e.preventDefault();
|
|
_this._setScale(_this._relativeScale + e.deltaY * -0.003);
|
|
});
|
|
var mc = new hammerjs_1.default(this._wrapper);
|
|
mc.add(new hammerjs_1.default.Pinch());
|
|
var beforeScale = this._relativeScale;
|
|
mc.on('pinchstart', function (e) {
|
|
beforeScale = _this._relativeScale;
|
|
});
|
|
mc.on('pinch', function (e) {
|
|
_this._setScale(beforeScale * e.scale);
|
|
});
|
|
//Controls
|
|
if (this._thumbnails != undefined)
|
|
this._thumbnails.addEventListener('click', function () {
|
|
if (_this.container.classList.contains('mux_imageviewer-galleryopen')) {
|
|
_this.container.classList.remove('mux_imageviewer-galleryopen');
|
|
_this._thumbnails.classList.remove('mux_active');
|
|
_this.callEvent('thumbnailsOpen', false);
|
|
}
|
|
else {
|
|
_this.container.classList.add('mux_imageviewer-galleryopen');
|
|
_this._thumbnails.classList.add('mux_active');
|
|
_this.callEvent('thumbnailsOpen', true);
|
|
}
|
|
});
|
|
if (this._zoomIn != undefined)
|
|
this._zoomIn.addEventListener('click', function () { return _this.zoomIn(); });
|
|
if (this._zoomOut != undefined)
|
|
this._zoomOut.addEventListener('click', function () { return _this.zoomOut(); });
|
|
if (this._fit != undefined)
|
|
this._fit.addEventListener('click', function () { return _this.fitToContainer(); });
|
|
if (this._highRes != undefined)
|
|
this._highRes.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
this._startLoader();
|
|
this._image.style.display = 'none';
|
|
return [4 /*yield*/, (0, Utils_1.delay)(10)];
|
|
case 1:
|
|
_a.sent();
|
|
this._image.src = this._fullSrc;
|
|
this._highRes.style.display = 'none';
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
}); });
|
|
};
|
|
ComponentImageViewer.prototype._drawNavigationControls = function () {
|
|
var _this = this;
|
|
this._next = (0, CE_1.ce)('div', [
|
|
'mux_imageviewer-navigation',
|
|
'mux_imageviewer-navigation-right',
|
|
]);
|
|
this._next.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'navigate_next'));
|
|
this._next.addEventListener('click', function () {
|
|
if (_this._next.classList.contains('disabled'))
|
|
return;
|
|
_this.next();
|
|
});
|
|
this._wrapper.appendChild(this._next);
|
|
this._prev = (0, CE_1.ce)('div', [
|
|
'mux_imageviewer-navigation',
|
|
'mux_imageviewer-navigation-left',
|
|
]);
|
|
this._prev.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'navigate_before'));
|
|
this._prev.addEventListener('click', function () {
|
|
if (_this._prev.classList.contains('disabled'))
|
|
return;
|
|
_this.previous();
|
|
});
|
|
this._wrapper.appendChild(this._prev);
|
|
};
|
|
ComponentImageViewer.prototype._drawThumbnails = function (sources, openThumbnails) {
|
|
var _this = this;
|
|
var gallery = (0, CE_1.ce)('div', 'mux_imageviewer-gallery');
|
|
if (this.background != false)
|
|
gallery.style.background = 'var(--mux-panel-color)';
|
|
sources.forEach(function (source, index) {
|
|
var _a;
|
|
var thumb = (0, CE_1.ce)('img', 'mux_imageviewer-gallery-thumb', {
|
|
index: index,
|
|
src: (_a = source.thumbnail) !== null && _a !== void 0 ? _a : source.normal,
|
|
});
|
|
thumb.addEventListener('click', function () {
|
|
_this.setImage(source, index);
|
|
});
|
|
gallery.appendChild(thumb);
|
|
});
|
|
this.container.appendChild(gallery);
|
|
if (openThumbnails)
|
|
this.container.classList.add('mux_imageviewer-galleryopen');
|
|
this.fitToContainer();
|
|
};
|
|
ComponentImageViewer.prototype._validateX = function (x) {
|
|
var bounds = this._image.getBoundingClientRect();
|
|
var minInlay = this._wrapper.clientWidth - 10;
|
|
if (bounds.width < this._wrapper.clientWidth) {
|
|
x = (this._wrapper.clientWidth - bounds.width) / 2;
|
|
}
|
|
else {
|
|
x = Math.max(x, (bounds.width - minInlay) * -1);
|
|
x = Math.min(x, this._wrapper.clientWidth - minInlay);
|
|
}
|
|
return x;
|
|
};
|
|
ComponentImageViewer.prototype._validateY = function (y) {
|
|
var bounds = this._image.getBoundingClientRect();
|
|
var minInlay = this._wrapper.clientHeight - 10;
|
|
if (bounds.height < this._wrapper.clientHeight) {
|
|
y = (this._wrapper.clientHeight - bounds.height) / 2;
|
|
}
|
|
else {
|
|
y = Math.max(y, (bounds.height - minInlay) * -1);
|
|
y = Math.min(y, this._wrapper.clientHeight - minInlay);
|
|
}
|
|
return y;
|
|
};
|
|
ComponentImageViewer.prototype._restartScaling = function () {
|
|
var _this = this;
|
|
this._calculateRelativeScale(function () {
|
|
_this.fitToContainer();
|
|
_this._startScaleClock();
|
|
});
|
|
clearTimeout(this._restartScalingRepeat);
|
|
this._restartScalingRepeat = setTimeout(function () {
|
|
_this._calculateRelativeScale(function () {
|
|
_this.fitToContainer();
|
|
_this._startScaleClock();
|
|
});
|
|
}, 1000);
|
|
};
|
|
ComponentImageViewer.prototype._calculateRelativeScale = function (readyCallback) {
|
|
var _this = this;
|
|
var bounds = this._image.getBoundingClientRect();
|
|
clearTimeout(this._fitToContainerRetry);
|
|
if (bounds.width == 0 ||
|
|
bounds.height == 0 ||
|
|
this._image.width == 0 ||
|
|
this._image.height == 0)
|
|
return (this._fitToContainerRetry = setTimeout(function () { return _this._calculateRelativeScale(readyCallback); }, 100));
|
|
var maxWidth = this._wrapper.clientWidth - 20;
|
|
var maxHeight = this._wrapper.clientHeight - 20;
|
|
this._relativeScaleBase = Math.min(maxWidth / this._image.width, maxHeight / this._image.height);
|
|
this._setScale(this._relativeScale);
|
|
if (typeof readyCallback == 'function')
|
|
readyCallback();
|
|
};
|
|
ComponentImageViewer.prototype._setScale = function (factor) {
|
|
this._relativeScale = Math.min(Math.max(factor, 1), 10);
|
|
this._setRawScale(this._relativeScaleBase * factor);
|
|
};
|
|
ComponentImageViewer.prototype._setRawScale = function (scale) {
|
|
var bounds = this._image.getBoundingClientRect();
|
|
this._rawScale = Math.max(scale, this._relativeScaleBase);
|
|
var widthDiff = bounds.width - this._rawScale * this._image.clientWidth;
|
|
var heightDiff = bounds.height - this._rawScale * this._image.clientHeight;
|
|
this._image.style.transform = "scale(".concat(this._rawScale, ")");
|
|
this._left = this._validateX(this._left + widthDiff / 2);
|
|
this._image.style.left = "".concat(this._left, "px");
|
|
this._top = this._validateY(this._top + heightDiff / 2);
|
|
this._image.style.top = "".concat(this._top, "px");
|
|
};
|
|
ComponentImageViewer.prototype._startScaleClock = function () {
|
|
var _this = this;
|
|
if (this._startScaleClockInt != undefined)
|
|
return;
|
|
var lastWidth = this._wrapper.clientWidth;
|
|
var lastHeight = this._wrapper.clientHeight;
|
|
clearInterval(this._startScaleClockInt);
|
|
this._startScaleClockInt = setInterval(function () {
|
|
if (_this.container.parentElement == null)
|
|
return clearInterval(_this._startScaleClockInt);
|
|
if (lastWidth != _this._wrapper.clientWidth ||
|
|
lastHeight != _this._wrapper.clientHeight) {
|
|
lastWidth = _this._wrapper.clientWidth;
|
|
lastHeight = _this._wrapper.clientHeight;
|
|
_this._calculateRelativeScale();
|
|
}
|
|
}, 100);
|
|
};
|
|
ComponentImageViewer.prototype.setImageIndex = function (index) {
|
|
if (this._sources == undefined)
|
|
return;
|
|
if (this._sources[index] == undefined)
|
|
return;
|
|
this.setImage(this._sources[index], index);
|
|
};
|
|
ComponentImageViewer.prototype.fitToContainer = function () {
|
|
this._setScale(1);
|
|
this._left = this._validateX((this._wrapper.clientWidth - this._image.width * this._rawScale) / 2);
|
|
this._top = this._validateY((this._wrapper.clientHeight - this._image.height * this._rawScale) /
|
|
2);
|
|
this._image.style.left = "".concat(this._left, "px");
|
|
this._image.style.top = "".concat(this._top, "px");
|
|
this._image.style.opacity = '1';
|
|
};
|
|
ComponentImageViewer.prototype.zoomIn = function () {
|
|
this._setScale(this._relativeScale + 0.3);
|
|
};
|
|
ComponentImageViewer.prototype.zoomOut = function () {
|
|
this._setScale(this._relativeScale - 0.3);
|
|
};
|
|
return ComponentImageViewer;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_ImageViewer.ComponentImageViewer = ComponentImageViewer;
|
|
|
|
return Component_ImageViewer;
|
|
}
|
|
|
|
var Component_Input = {};
|
|
|
|
var __extends$3 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Input, "__esModule", { value: true });
|
|
Component_Input.ComponentInput = void 0;
|
|
var CE_1$3 = CE;
|
|
var baseComponent_1$3 = baseComponent;
|
|
var ComponentInput = /** @class */ (function (_super) {
|
|
__extends$3(ComponentInput, _super);
|
|
function ComponentInput(options) {
|
|
var _a;
|
|
var _this = _super.call(this) || this;
|
|
_this.container = (0, CE_1$3.ce)('input', 'mux_input', {
|
|
type: options.type,
|
|
});
|
|
var border = (_a = options.border) !== null && _a !== void 0 ? _a : 'hover';
|
|
if (border == 'always')
|
|
_this.container.classList.add('mux_input-alwaysborder');
|
|
else if (border == 'never')
|
|
_this.container.classList.add('mux_input-noborder');
|
|
if ((options === null || options === void 0 ? void 0 : options.min) != undefined)
|
|
_this.container.min = String(options.min);
|
|
if ((options === null || options === void 0 ? void 0 : options.max) != undefined)
|
|
_this.container.max = String(options.max);
|
|
if ((options === null || options === void 0 ? void 0 : options.step) != undefined)
|
|
_this.container.step = String(options.step);
|
|
if ((options === null || options === void 0 ? void 0 : options.maxLength) != undefined)
|
|
_this.container.maxLength = options.maxLength;
|
|
if ((options === null || options === void 0 ? void 0 : options.readOnly) != undefined)
|
|
_this.container.readOnly = options.readOnly;
|
|
if ((options === null || options === void 0 ? void 0 : options.placeholder) != undefined)
|
|
_this.container.placeholder = options.placeholder;
|
|
if ((options === null || options === void 0 ? void 0 : options.value) != undefined)
|
|
_this.container.value = options.value;
|
|
if ((options === null || options === void 0 ? void 0 : options.valueAsNumber) != undefined)
|
|
_this.container.valueAsNumber = options.valueAsNumber;
|
|
if (options.enabled == false)
|
|
_this.container.setAttribute('disabled', '');
|
|
_this.container.oninput = function () {
|
|
return _this.callEvent('input', _this.container.value);
|
|
};
|
|
_this.container.onfocus = function () { return _this.callEvent('focus'); };
|
|
_this.container.onblur = function () { return _this.callEvent('blur'); };
|
|
return _this;
|
|
}
|
|
ComponentInput.prototype.getValue = function () {
|
|
return this.container.value;
|
|
};
|
|
ComponentInput.prototype.getValueAsNumber = function () {
|
|
return this.container.valueAsNumber;
|
|
};
|
|
ComponentInput.prototype.setValue = function (value) {
|
|
this.container.value = value;
|
|
};
|
|
ComponentInput.prototype.setValueAsNumber = function (value) {
|
|
this.container.valueAsNumber = value;
|
|
};
|
|
return ComponentInput;
|
|
}(baseComponent_1$3.MUXComponent));
|
|
Component_Input.ComponentInput = ComponentInput;
|
|
|
|
var Component_List = {};
|
|
|
|
var hasRequiredComponent_List;
|
|
|
|
function requireComponent_List () {
|
|
if (hasRequiredComponent_List) return Component_List;
|
|
hasRequiredComponent_List = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_List, "__esModule", { value: true });
|
|
Component_List.ComponentList = void 0;
|
|
var Index_1 = requireIndex();
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var Sortable = SortableExports;
|
|
var ComponentList = /** @class */ (function (_super) {
|
|
__extends(ComponentList, _super);
|
|
function ComponentList(options) {
|
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
var _this = _super.call(this) || this;
|
|
_this.openGroups = [];
|
|
_this.groupComponents = new Map();
|
|
_this.options = options;
|
|
_this.dragable = (_a = options === null || options === void 0 ? void 0 : options.dragable) !== null && _a !== void 0 ? _a : false;
|
|
_this.hover = (_b = options === null || options === void 0 ? void 0 : options.hover) !== null && _b !== void 0 ? _b : false;
|
|
_this.grouped = (_c = options === null || options === void 0 ? void 0 : options.grouped) !== null && _c !== void 0 ? _c : false;
|
|
_this.groupsCloseable = (_d = options === null || options === void 0 ? void 0 : options.groupsCloseable) !== null && _d !== void 0 ? _d : false;
|
|
_this.sortGroupsAlphabetically =
|
|
(_e = options === null || options === void 0 ? void 0 : options.sortGroupsAlphabetically) !== null && _e !== void 0 ? _e : false;
|
|
_this.openGroups = (_f = options === null || options === void 0 ? void 0 : options.groupsOpen) !== null && _f !== void 0 ? _f : [];
|
|
_this.allowSingleItemGroups = (_g = options === null || options === void 0 ? void 0 : options.allowSingleItemGroups) !== null && _g !== void 0 ? _g : false;
|
|
_this.highlighted = (_h = options === null || options === void 0 ? void 0 : options.highlightedItem) !== null && _h !== void 0 ? _h : null;
|
|
if (_this.dragable == true && _this.grouped == true)
|
|
throw new Error("Unable to use 'grouped' for list component when 'canReorderByDrag' is also enabled. ");
|
|
_this.container = (0, CE_1.ce)('div', 'mux_list');
|
|
_this.updateItems((_j = options === null || options === void 0 ? void 0 : options.items) !== null && _j !== void 0 ? _j : []);
|
|
if (_this.dragable == true) {
|
|
_this.sortable = new Sortable(_this.container, {
|
|
ghostClass: 'mux_list-item-dragging',
|
|
onStart: function () {
|
|
_this.container.classList.add('mux_list-dragging');
|
|
},
|
|
onEnd: function (evt) {
|
|
_this.container.classList.remove('mux_list-dragging');
|
|
_this.callEvent('orderUpdated', _this.getCurrentOrder());
|
|
},
|
|
});
|
|
}
|
|
return _this;
|
|
}
|
|
ComponentList.prototype.updateItems = function (items) {
|
|
var _this = this;
|
|
var _a;
|
|
this.container.innerHTML = '';
|
|
this.groupComponents.clear();
|
|
if (items == undefined || items.length == 0)
|
|
return;
|
|
if (this.grouped) {
|
|
var groups = [];
|
|
for (var i = 0; i < items.length; i++) {
|
|
var group = (_a = items[i].group) !== null && _a !== void 0 ? _a : 'Ungrouped';
|
|
if (!groups.includes(group)) {
|
|
groups.push(group);
|
|
}
|
|
}
|
|
if (this.sortGroupsAlphabetically == true)
|
|
groups.sort();
|
|
for (var i = 0; i < groups.length; i++) {
|
|
this.ensureGroup(groups[i]);
|
|
}
|
|
}
|
|
items.forEach(function (item) { return _this.addItem(item); });
|
|
this.groupComponents.forEach(function (_a, group) {
|
|
var container = _a.container, content = _a.content;
|
|
if (content.children.length == 0) {
|
|
container.parentElement.removeChild(container);
|
|
_this.groupComponents.delete(group);
|
|
}
|
|
else {
|
|
if (content.children.length == 1 &&
|
|
_this.allowSingleItemGroups == false) {
|
|
container.classList.add('mux_group-singular');
|
|
}
|
|
else
|
|
container.classList.remove('mux_group-singular');
|
|
}
|
|
});
|
|
};
|
|
ComponentList.prototype.getCurrentOrder = function () {
|
|
return Array.from(this.container.querySelectorAll('.mux_list-item')).map(function (item) {
|
|
return item.getAttribute('uid');
|
|
});
|
|
};
|
|
ComponentList.prototype.removeItem = function (uniqueIdentifier) {
|
|
var match = this.container.querySelector(".mux_list-item[uid=\"".concat(uniqueIdentifier, "\"]"));
|
|
if (match != null)
|
|
match.remove();
|
|
this.callEvent('orderUpdated', this.getCurrentOrder());
|
|
};
|
|
ComponentList.prototype.addItem = function (item) {
|
|
var _this = this;
|
|
var _a, _b;
|
|
var element = (0, CE_1.ce)('div', 'mux_list-item', {
|
|
uid: item.uniqueIdentifier,
|
|
});
|
|
if (this.hover)
|
|
element.classList.add('mux_list-item-hover');
|
|
// if (showSeperator) element.classList.add('mux_list-item-separator');
|
|
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.overwriteCursor) != null)
|
|
element.style.cursor = this.options.overwriteCursor;
|
|
if (this.highlighted != null &&
|
|
this.highlighted == item.uniqueIdentifier)
|
|
element.classList.add('mux_list-item-selected');
|
|
if (item.tooltip != undefined)
|
|
element.title = item.tooltip;
|
|
if (item.enabled == false)
|
|
element.classList.add('mux_list-item-disabled');
|
|
var content = (0, CE_1.ce)('div', 'mux_list-item-content');
|
|
element.appendChild(content);
|
|
element.onclick = function (e) {
|
|
var _a;
|
|
if (((_a = _this.options) === null || _a === void 0 ? void 0 : _a.highlightOnClick) == true)
|
|
_this.highlight(item.uniqueIdentifier);
|
|
if (item.click != undefined)
|
|
item.click();
|
|
};
|
|
if (item.materialIcon != undefined) {
|
|
var mi = (0, CE_1.ce)('span', ['mux_list-item-icon', 'material-symbols-outlined'], null, item.materialIcon);
|
|
content.appendChild(mi);
|
|
if (item.materialIconColor != undefined)
|
|
mi.style.color = item.materialIconColor;
|
|
}
|
|
else if (item.icon != undefined)
|
|
content.appendChild((0, CE_1.ce)('img', 'mux_list-item-icon', { src: item.icon }));
|
|
var text = (0, CE_1.ce)('div', 'mux_list-item-text');
|
|
if (item.text != undefined)
|
|
text.appendChild((0, CE_1.ce)('div', ['mux_text', 'mux_normal'], null, item.text));
|
|
if (item.subText != undefined)
|
|
text.appendChild((0, CE_1.ce)('div', ['mux_text', 'mux_small'], null, item.subText));
|
|
content.appendChild(text);
|
|
if (item.actions != undefined && item.actions.length > 0) {
|
|
var actions = (0, CE_1.ce)('div', 'mux_list-item-actions');
|
|
var _loop_1 = function (i) {
|
|
action = (0, CE_1.ce)('div', 'mux_list-item-action');
|
|
if (item.actions[i].tooltip != undefined)
|
|
action.title = item.actions[i].tooltip;
|
|
if (item.actions[i].materialIcon != undefined)
|
|
action.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, item.actions[i].materialIcon));
|
|
else if (item.actions[i].icon != undefined)
|
|
action.appendChild((0, CE_1.ce)('img', null, { src: item.actions[i].icon }));
|
|
action.onclick = function (e) {
|
|
e.stopPropagation();
|
|
e.stopImmediatePropagation();
|
|
item.actions[i].click();
|
|
};
|
|
actions.appendChild(action);
|
|
};
|
|
var action;
|
|
for (var i = 0; i < item.actions.length; i++) {
|
|
_loop_1(i);
|
|
}
|
|
content.appendChild(actions);
|
|
}
|
|
if (this.grouped == true) {
|
|
var group = (_b = item.group) !== null && _b !== void 0 ? _b : 'Ungrouped';
|
|
var content = this.ensureGroup(group).content;
|
|
content.appendChild(element);
|
|
}
|
|
else
|
|
this.container.appendChild(element);
|
|
this.size = this.container.querySelectorAll('.mux_list-item').length;
|
|
};
|
|
ComponentList.prototype.highlight = function (uniqueIdentifier) {
|
|
this.highlighted = uniqueIdentifier;
|
|
this.container
|
|
.querySelectorAll('.mux_list-item')
|
|
.forEach(function (item) {
|
|
var uid = item.getAttribute('uid');
|
|
if (uid == uniqueIdentifier) {
|
|
item.classList.add('mux_list-item-selected');
|
|
item.scrollIntoView({
|
|
behavior: 'smooth',
|
|
block: 'center',
|
|
});
|
|
}
|
|
else
|
|
item.classList.remove('mux_list-item-selected');
|
|
});
|
|
};
|
|
ComponentList.prototype.ensureGroup = function (group) {
|
|
var _this = this;
|
|
if (this.groupComponents.has(group))
|
|
return this.groupComponents.get(group);
|
|
var groupComponent = new Index_1.MorphComponent.Group({
|
|
title: group,
|
|
open: this.openGroups.includes(group) ||
|
|
this.openGroups.includes('*') ||
|
|
this.groupsCloseable == false,
|
|
closeable: this.groupsCloseable,
|
|
});
|
|
groupComponent.on('openState', function (state) {
|
|
if (state) {
|
|
if (!_this.openGroups.includes(group))
|
|
_this.openGroups.push(group);
|
|
}
|
|
else {
|
|
if (_this.openGroups.includes(group))
|
|
_this.openGroups.splice(_this.openGroups.indexOf(group), 1);
|
|
}
|
|
_this.callEvent('openGroupsUpdated', _this.openGroups);
|
|
});
|
|
this.container.appendChild(groupComponent.container);
|
|
this.groupComponents.set(group, groupComponent);
|
|
return this.groupComponents.get(group);
|
|
};
|
|
return ComponentList;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_List.ComponentList = ComponentList;
|
|
|
|
return Component_List;
|
|
}
|
|
|
|
var Component_MenuBar = {};
|
|
|
|
var hasRequiredComponent_MenuBar;
|
|
|
|
function requireComponent_MenuBar () {
|
|
if (hasRequiredComponent_MenuBar) return Component_MenuBar;
|
|
hasRequiredComponent_MenuBar = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
|
__assign = Object.assign || function(t) {
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
s = arguments[i];
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
t[p] = s[p];
|
|
}
|
|
return t;
|
|
};
|
|
return __assign.apply(this, arguments);
|
|
};
|
|
Object.defineProperty(Component_MenuBar, "__esModule", { value: true });
|
|
Component_MenuBar.ComponentMenuBar = void 0;
|
|
var Index_1 = requireIndex();
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var ComponentMenuBar = /** @class */ (function (_super) {
|
|
__extends(ComponentMenuBar, _super);
|
|
function ComponentMenuBar(options) {
|
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
var _this = _super.call(this) || this;
|
|
_this.enabledStates = {};
|
|
_this._leftItems = [];
|
|
_this._rightItems = [];
|
|
_this.mobileIgnoreItems = [];
|
|
_this._leftItems = (_a = options.left) !== null && _a !== void 0 ? _a : [];
|
|
_this._rightItems = (_b = options.right) !== null && _b !== void 0 ? _b : [];
|
|
_this.contextMaterialIconColor =
|
|
(_c = options.contextMaterialIconColor) !== null && _c !== void 0 ? _c : 'var(--mux-primary-color)';
|
|
_this.contextMenuAlign = (_d = options.contextMenuAlign) !== null && _d !== void 0 ? _d : 'below';
|
|
_this.contextAlignSide = {
|
|
below: 'center',
|
|
left: 'right',
|
|
right: 'left',
|
|
}[_this.contextMenuAlign];
|
|
_this.container = (0, CE_1.ce)('div', 'mux_menubar');
|
|
_this.size = (_e = options.size) !== null && _e !== void 0 ? _e : 'normal';
|
|
_this.container.classList.add("mux_menubar-".concat(_this.size));
|
|
_this.direction = (_f = options === null || options === void 0 ? void 0 : options.direction) !== null && _f !== void 0 ? _f : 'horizontal';
|
|
_this.container.classList.add("mux_menubar-direction-".concat(_this.direction));
|
|
_this.leftContainer = (0, CE_1.ce)('div', ['mux_menubar-locater', 'mux_left']);
|
|
_this.rightContainer = (0, CE_1.ce)('div', ['mux_menubar-locater', 'mux_right']);
|
|
_this.mobileContainer = (0, CE_1.ce)('div', 'mux_menubar-mobile');
|
|
var mobileRightItems = (0, CE_1.ce)('div', [
|
|
'mux_menubar-mobile-items',
|
|
'mux_right',
|
|
]);
|
|
((_h = (_g = options === null || options === void 0 ? void 0 : options.mobile) === null || _g === void 0 ? void 0 : _g.right) !== null && _h !== void 0 ? _h : []).forEach(function (item) {
|
|
return _this.addItem(item, mobileRightItems);
|
|
});
|
|
var mobileLeftItems = (0, CE_1.ce)('div', [
|
|
'mux_menubar-mobile-items',
|
|
'mux_left',
|
|
]);
|
|
((_k = (_j = options === null || options === void 0 ? void 0 : options.mobile) === null || _j === void 0 ? void 0 : _j.left) !== null && _k !== void 0 ? _k : []).forEach(function (item) {
|
|
return _this.addItem(item, mobileLeftItems);
|
|
});
|
|
if (((_l = options === null || options === void 0 ? void 0 : options.mobile) === null || _l === void 0 ? void 0 : _l.logo) != undefined) {
|
|
mobileLeftItems.style.left = '50px';
|
|
var logo = (0, CE_1.ce)('a', 'mux_menubar-mobile-logo', {
|
|
href: options.mobile.logo.href,
|
|
});
|
|
logo.appendChild((0, CE_1.ce)('img', null, { src: options.mobile.logo.src }));
|
|
_this.mobileContainer.appendChild(logo);
|
|
}
|
|
_this.mobileIgnoreItems = (_o = (_m = options === null || options === void 0 ? void 0 : options.mobile) === null || _m === void 0 ? void 0 : _m.ignoreItems) !== null && _o !== void 0 ? _o : [];
|
|
_this.addItem({
|
|
type: 'icon',
|
|
materialIcon: 'menu',
|
|
click: function () {
|
|
_this.openMobileMenu();
|
|
// this.rightContainer.classList.toggle('mux_menubar-visible');
|
|
},
|
|
}, mobileRightItems);
|
|
_this.mobileContainer.append(mobileLeftItems, mobileRightItems);
|
|
_this.container.append(_this.leftContainer, _this.rightContainer, _this.mobileContainer);
|
|
if ((options === null || options === void 0 ? void 0 : options.left) != undefined)
|
|
options.left.forEach(function (item) {
|
|
return _this.addItem(item, _this.leftContainer);
|
|
});
|
|
if ((options === null || options === void 0 ? void 0 : options.right) != undefined)
|
|
options.right.forEach(function (item) {
|
|
return _this.addItem(item, _this.rightContainer);
|
|
});
|
|
if (_this.direction == 'horizontal') {
|
|
_this.calculateSizing();
|
|
window.addEventListener('resize', function () {
|
|
_this.calculateSizing();
|
|
});
|
|
var c = 0;
|
|
_this.sizeClock = setInterval(function () {
|
|
if (c++ > 200)
|
|
clearInterval(_this.sizeClock);
|
|
if (_this.container.parentElement != null) {
|
|
clearInterval(_this.sizeClock);
|
|
_this.calculateSizing();
|
|
}
|
|
}, 10);
|
|
}
|
|
else {
|
|
_this.leftContainer.classList.add('mux_menubar-visible');
|
|
_this.rightContainer.classList.add('mux_menubar-visible');
|
|
}
|
|
return _this;
|
|
}
|
|
ComponentMenuBar.prototype.calculateSizing = function () {
|
|
var menuSize = this.leftContainer.clientWidth + this.rightContainer.clientWidth;
|
|
var containerWidth = this.container.clientWidth;
|
|
if (menuSize != 0 && containerWidth != 0)
|
|
clearInterval(this.sizeClock);
|
|
if (menuSize > containerWidth) {
|
|
this.leftContainer.classList.remove('mux_menubar-visible');
|
|
this.rightContainer.classList.remove('mux_menubar-visible');
|
|
this.mobileContainer.classList.add('mux_menubar-visible');
|
|
}
|
|
else {
|
|
this.leftContainer.classList.add('mux_menubar-visible');
|
|
this.rightContainer.classList.add('mux_menubar-visible');
|
|
this.mobileContainer.classList.remove('mux_menubar-visible');
|
|
}
|
|
};
|
|
ComponentMenuBar.prototype.addItem = function (item, target) {
|
|
var _this = this;
|
|
if (item.type != 'image') {
|
|
var element = (0, CE_1.ce)(item.href != undefined ? 'a' : 'div', 'mux_menubar-item');
|
|
if (item.uniqueIdentifier != undefined)
|
|
element.setAttribute('uid', item.uniqueIdentifier);
|
|
if (item.enabled != undefined && item.enabled == false)
|
|
element.classList.add('mux_menubar-item-disabled');
|
|
if (item.href != undefined)
|
|
element.setAttribute('href', item.href);
|
|
if (item.tooltip != undefined)
|
|
element.title = item.tooltip;
|
|
if (item.selected == true)
|
|
element.classList.add('mux_menubar-item-selected');
|
|
if (item.materialIcon != undefined) {
|
|
var materialIcon = (0, CE_1.ce)('span', [
|
|
'mux_menubar-item-materialicon',
|
|
'material-symbols-outlined',
|
|
], null, item.materialIcon);
|
|
if (item.materialIconTransform != undefined)
|
|
materialIcon.style.transform = item.materialIconTransform;
|
|
element.appendChild(materialIcon);
|
|
}
|
|
switch (item.type) {
|
|
case 'icon':
|
|
element.classList.add('mux_menubar-item-icon');
|
|
element.onclick = item.click;
|
|
break;
|
|
case 'normal':
|
|
element.classList.add('mux_menubar-item-normal');
|
|
element.appendChild((0, CE_1.ce)('p', ['mux_text', "mux_".concat(this.size)], null, item.text));
|
|
break;
|
|
}
|
|
if (item.children == undefined || item.children.length == 0) {
|
|
if (item.click != undefined && item.href == undefined)
|
|
element.onclick = item.click;
|
|
}
|
|
else {
|
|
// if (item.type == 'normal')
|
|
element.appendChild((0, CE_1.ce)('span', ['material-symbols-outlined', 'mux_menubar-item-arrow'], null, "keyboard_arrow_".concat({ below: 'down', left: 'left', right: 'right' }[this.contextMenuAlign])));
|
|
element.onclick = function () {
|
|
var _a;
|
|
if (element.classList.contains('mux_menubar-item-disabled'))
|
|
return;
|
|
var bounds = element.getBoundingClientRect();
|
|
element.classList.add('mux_menubar-item-selected');
|
|
for (var i = 0; i < item.children.length; i++)
|
|
if (((_a = item.children[i]) === null || _a === void 0 ? void 0 : _a.uniqueIdentifier) != undefined) {
|
|
if (_this.enabledStates[item.children[i].uniqueIdentifier] != undefined)
|
|
item.children[i].enabled =
|
|
_this.enabledStates[item.children[i].uniqueIdentifier];
|
|
}
|
|
var x;
|
|
var y;
|
|
if (_this.contextMenuAlign == 'below') {
|
|
x = bounds.x + bounds.width / 2;
|
|
y = bounds.y + bounds.height;
|
|
}
|
|
else if (_this.contextMenuAlign == 'left') {
|
|
x = bounds.x;
|
|
y = bounds.y;
|
|
}
|
|
else if (_this.contextMenuAlign == 'right') {
|
|
x = bounds.x + bounds.width;
|
|
y = bounds.y;
|
|
}
|
|
_this.dropdown = new Index_1.MorphComponent.ContextMenu({
|
|
x: x,
|
|
y: y,
|
|
align: _this.contextAlignSide,
|
|
items: item.children,
|
|
materialIconColor: _this.contextMaterialIconColor,
|
|
});
|
|
_this.dropdown.on('close', function () {
|
|
element.classList.remove('mux_menubar-item-selected');
|
|
});
|
|
};
|
|
}
|
|
target.appendChild(element);
|
|
}
|
|
else {
|
|
var icon = (0, CE_1.ce)(item.href != undefined ? 'a' : 'div', 'mux_menubar-image');
|
|
if (item.href != undefined)
|
|
icon.href = item.href;
|
|
icon.appendChild((0, CE_1.ce)('img', null, { src: item.url }));
|
|
target.appendChild(icon);
|
|
}
|
|
};
|
|
ComponentMenuBar.prototype.setSelected = function (uniqueIdentifier) {
|
|
this.selected = uniqueIdentifier;
|
|
this.container
|
|
.querySelectorAll('.mux_menubar-item')
|
|
.forEach(function (item) {
|
|
if (item.getAttribute('uid') == uniqueIdentifier &&
|
|
uniqueIdentifier != null)
|
|
item.classList.add('mux_menubar-item-selected');
|
|
else
|
|
item.classList.remove('mux_menubar-item-selected');
|
|
});
|
|
if (this.mobileMenu != null)
|
|
this.mobileMenu.setSelected(uniqueIdentifier);
|
|
};
|
|
ComponentMenuBar.prototype.setEnabled = function (uniqueIdentifier, enabled) {
|
|
var item = this.container.querySelector(".mux_menubar-item[uid=\"".concat(uniqueIdentifier, "\"]"));
|
|
if (item == null)
|
|
return;
|
|
if (enabled)
|
|
item.classList.remove('mux_menubar-item-disabled');
|
|
else
|
|
item.classList.add('mux_menubar-item-disabled');
|
|
};
|
|
ComponentMenuBar.prototype.openMobileMenu = function () {
|
|
var _this = this;
|
|
var container = (0, CE_1.ce)('div', 'mux_mobilemenu');
|
|
var inner = (0, CE_1.ce)('div', 'mux_mobilemenu-inner');
|
|
this.mobileMenu = new ComponentMenuBar({
|
|
direction: 'vertical',
|
|
left: this._leftItems
|
|
.filter(function (item) {
|
|
if (item.uniqueIdentifier == undefined)
|
|
return true;
|
|
return !_this.mobileIgnoreItems.includes(item.uniqueIdentifier);
|
|
})
|
|
.map(function (item) {
|
|
if (item.type !== 'icon')
|
|
return item;
|
|
return __assign(__assign({}, item), { type: 'normal' });
|
|
}),
|
|
right: this._rightItems
|
|
.filter(function (item) {
|
|
if (item.uniqueIdentifier == undefined)
|
|
return true;
|
|
return !_this.mobileIgnoreItems.includes(item.uniqueIdentifier);
|
|
})
|
|
.map(function (item) {
|
|
if (item.type !== 'icon')
|
|
return item;
|
|
return __assign(__assign({}, item), { type: 'normal' });
|
|
}),
|
|
});
|
|
this.mobileMenu.setSelected(this.selected);
|
|
inner.appendChild(this.mobileMenu.container);
|
|
container.appendChild(inner);
|
|
document.body.appendChild(container);
|
|
container.animate({ opacity: '1' }, { duration: 200 }).onfinish =
|
|
function () {
|
|
container.style.opacity = '1';
|
|
};
|
|
inner.animate({ transform: 'translateX(0%)' }, { duration: 200, easing: 'ease-out' }).onfinish = function () {
|
|
inner.style.transform = 'translateX(0%)';
|
|
};
|
|
container.onclick = function () {
|
|
container.animate({ opacity: '0' }, { duration: 200 }).onfinish =
|
|
function () {
|
|
container.style.opacity = '0';
|
|
};
|
|
inner.animate({ transform: 'translateX(100%)' }, { duration: 200, easing: 'ease-in' }).onfinish = function () {
|
|
inner.style.transform = 'translateX(100%)';
|
|
_this.mobileMenu = null;
|
|
container.remove();
|
|
};
|
|
};
|
|
inner.onclick = function (e) {
|
|
e.stopPropagation();
|
|
};
|
|
};
|
|
return ComponentMenuBar;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_MenuBar.ComponentMenuBar = ComponentMenuBar;
|
|
|
|
return Component_MenuBar;
|
|
}
|
|
|
|
var Component_PaletteCheckbox = {};
|
|
|
|
var hasRequiredComponent_PaletteCheckbox;
|
|
|
|
function requireComponent_PaletteCheckbox () {
|
|
if (hasRequiredComponent_PaletteCheckbox) return Component_PaletteCheckbox;
|
|
hasRequiredComponent_PaletteCheckbox = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_PaletteCheckbox, "__esModule", { value: true });
|
|
Component_PaletteCheckbox.ComponentPaletteCheckbox = void 0;
|
|
var Index_1 = requireIndex();
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var ComponentPaletteCheckbox = /** @class */ (function (_super) {
|
|
__extends(ComponentPaletteCheckbox, _super);
|
|
function ComponentPaletteCheckbox(options) {
|
|
var _a;
|
|
var _this = _super.call(this) || this;
|
|
_this.defaultView = 'recent_and_rest';
|
|
_this.lastChecked = [];
|
|
_this.recents = [];
|
|
_this.pid = options === null || options === void 0 ? void 0 : options.paletteUniqueIdentifier;
|
|
// if (pid != undefined && pid.length > 0)
|
|
// lastChecked = Validator.array(
|
|
// FieldStorage.getChannelValue('palette_checkbox', pid),
|
|
// []
|
|
// );
|
|
_this.container = (0, CE_1.ce)('div', ['mux_palette', 'mux_palette-checkboxes']);
|
|
_this.container.onclick = function () { return _this.close(); };
|
|
_this.inner = (0, CE_1.ce)('div', 'mux_palette-inner');
|
|
_this.inner.onclick = function (e) { return e.stopPropagation(); };
|
|
_this.results = (0, CE_1.ce)('div', ['mux_palette-results']);
|
|
_this.inner.appendChild(_this.results);
|
|
_this.container.appendChild(_this.inner);
|
|
if ((options === null || options === void 0 ? void 0 : options.title) != undefined && options.title.trim().length > 0) {
|
|
_this.showResultLabel(options.title);
|
|
}
|
|
((_a = options === null || options === void 0 ? void 0 : options.items) !== null && _a !== void 0 ? _a : []).forEach(function (item, i) {
|
|
return _this.renderSearchResult(item, i);
|
|
});
|
|
document.body.appendChild(_this.container);
|
|
setTimeout(function () {
|
|
_this.container.style.opacity = '1';
|
|
_this.inner.style.opacity = '1';
|
|
_this.inner.style.transform = 'scale(1)';
|
|
}, 20);
|
|
_this.registerKeyListener();
|
|
return _this;
|
|
}
|
|
ComponentPaletteCheckbox.prototype.close = function () {
|
|
var _this = this;
|
|
this.overwrite.close();
|
|
this.container.style.pointerEvents = 'none';
|
|
this.container.style.opacity = '0';
|
|
this.inner.style.opacity = '0';
|
|
this.inner.style.transform = 'scale(0.8)';
|
|
setTimeout(function () { return _this.destroy(); }, 400);
|
|
this.callEvent('close');
|
|
};
|
|
ComponentPaletteCheckbox.prototype.getChecked = function () {
|
|
var selected = Array.from(this.results.querySelectorAll('.mux_palette-results-item-checked')).map(function (item) {
|
|
return item.getAttribute('uid');
|
|
});
|
|
this.lastChecked = selected;
|
|
// FieldStorage.setChannelValue('palette_checkbox', this.pid, selected);
|
|
return selected;
|
|
};
|
|
ComponentPaletteCheckbox.prototype.renderSearchResult = function (result, index) {
|
|
var _this = this;
|
|
if (result.uniqueIdentifier == undefined)
|
|
throw new Error("Missing property 'uniqueIdentifier' inside one or more items of component 'PaletteCheckbox'");
|
|
var item = (0, CE_1.ce)('div', 'mux_palette-results-item', {
|
|
uid: result.uniqueIdentifier,
|
|
});
|
|
if (this.lastChecked.length == 0 && result.defaultValue == true)
|
|
item.classList.add('mux_palette-results-item-checked');
|
|
if (this.lastChecked.includes(result.uniqueIdentifier))
|
|
item.classList.add('mux_palette-results-item-checked');
|
|
if (index == 0)
|
|
item.classList.add('mux_palette-results-item-selected');
|
|
item.addEventListener('click', function () {
|
|
if (item.classList.contains('mux_palette-results-item-checked'))
|
|
item.classList.remove('mux_palette-results-item-checked');
|
|
else
|
|
item.classList.add('mux_palette-results-item-checked');
|
|
_this.getChecked();
|
|
});
|
|
var checkbox = (0, CE_1.ce)('div', 'mux_palette-results-item-checkbox');
|
|
checkbox.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, 'done'));
|
|
item.appendChild(checkbox);
|
|
if (result.materialIcon != undefined) {
|
|
var icon = (0, CE_1.ce)('div', 'material-symbols-outlined', null, result.materialIcon);
|
|
if (result.materialIconTransform != undefined)
|
|
icon.style.transform = result.materialIconTransform;
|
|
item.appendChild(icon);
|
|
}
|
|
else if (result.iconSrc != undefined)
|
|
item.appendChild((0, CE_1.ce)('img', 'mux_palette-results-item-icon', {
|
|
src: result.iconSrc,
|
|
}));
|
|
var text = (0, CE_1.ce)('div', [
|
|
'mux_palette-results-item-text',
|
|
'mux_text',
|
|
'mux_small',
|
|
]);
|
|
if (result.prefix != undefined)
|
|
text.appendChild((0, CE_1.ce)('span', 'mux_palette-results-item-text-sub', null, result.prefix.trim()));
|
|
text.appendChild((0, CE_1.ce)('span', 'mux_palette-results-item-text-main', null, result.name.trim()));
|
|
if (result.suffix != undefined)
|
|
text.appendChild((0, CE_1.ce)('span', 'mux_palette-results-item-text-sub', null, result.suffix.trim()));
|
|
item.appendChild(text);
|
|
item.appendChild((0, CE_1.ce)('div', [
|
|
'mux_palette-results-item-selectedtext',
|
|
'mux_text',
|
|
'mux_tiny',
|
|
], null, '<space> to toggle'));
|
|
this.results.appendChild(item);
|
|
return item;
|
|
};
|
|
ComponentPaletteCheckbox.prototype.registerKeyListener = function () {
|
|
var _this = this;
|
|
this.overwrite = Index_1.MorphKey.createOverwrite();
|
|
this.overwrite.bind('Escape', function () { return _this.close(); });
|
|
this.overwrite.bind('Enter', function () {
|
|
var checked = _this.getChecked();
|
|
_this.callEvent('selected', checked);
|
|
_this.close();
|
|
});
|
|
this.overwrite.bind(' ', function () {
|
|
var selected = _this.getSelectedResult();
|
|
if (selected != null)
|
|
selected.click();
|
|
});
|
|
this.overwrite.bind('ArrowUp', function () {
|
|
var selected = _this.getSelectedResult();
|
|
if (selected != null &&
|
|
selected.previousElementSibling != null &&
|
|
selected.previousElementSibling.classList.contains('mux_palette-results-item')) {
|
|
selected.classList.remove('mux_palette-results-item-selected');
|
|
selected.previousElementSibling.classList.add('mux_palette-results-item-selected');
|
|
setTimeout(function () {
|
|
if ((selected === null || selected === void 0 ? void 0 : selected.previousElementSibling) != null)
|
|
selected.previousElementSibling.scrollIntoView({
|
|
behavior: 'auto',
|
|
block: 'center',
|
|
inline: 'center',
|
|
});
|
|
}, 50);
|
|
}
|
|
});
|
|
this.overwrite.bind('ArrowDown', function () {
|
|
var selected = _this.getSelectedResult();
|
|
if (selected != null &&
|
|
selected.nextElementSibling != null &&
|
|
selected.nextElementSibling.classList.contains('mux_palette-results-item')) {
|
|
selected.classList.remove('mux_palette-results-item-selected');
|
|
selected.nextElementSibling.classList.add('mux_palette-results-item-selected');
|
|
setTimeout(function () {
|
|
if ((selected === null || selected === void 0 ? void 0 : selected.previousElementSibling) != null)
|
|
selected.previousElementSibling.scrollIntoView({
|
|
behavior: 'auto',
|
|
block: 'center',
|
|
inline: 'center',
|
|
});
|
|
}, 50);
|
|
}
|
|
});
|
|
};
|
|
ComponentPaletteCheckbox.prototype.showResultLabel = function (text, materialIcon) {
|
|
var label = (0, CE_1.ce)('div', 'mux_palette-results-header');
|
|
if (materialIcon != undefined)
|
|
label.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, materialIcon));
|
|
label.appendChild((0, CE_1.ce)('span', null, null, text));
|
|
this.results.appendChild(label);
|
|
};
|
|
ComponentPaletteCheckbox.prototype.getSelectedResult = function () {
|
|
if (this.results == null)
|
|
return null;
|
|
return this.results.querySelector('.mux_palette-results-item-selected');
|
|
};
|
|
return ComponentPaletteCheckbox;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_PaletteCheckbox.ComponentPaletteCheckbox = ComponentPaletteCheckbox;
|
|
|
|
return Component_PaletteCheckbox;
|
|
}
|
|
|
|
var Component_PaletteSearch = {};
|
|
|
|
var hasRequiredComponent_PaletteSearch;
|
|
|
|
function requireComponent_PaletteSearch () {
|
|
if (hasRequiredComponent_PaletteSearch) return Component_PaletteSearch;
|
|
hasRequiredComponent_PaletteSearch = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
|
__assign = Object.assign || function(t) {
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
s = arguments[i];
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
t[p] = s[p];
|
|
}
|
|
return t;
|
|
};
|
|
return __assign.apply(this, arguments);
|
|
};
|
|
var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
|
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
if (ar || !(i in from)) {
|
|
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
ar[i] = from[i];
|
|
}
|
|
}
|
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
};
|
|
Object.defineProperty(Component_PaletteSearch, "__esModule", { value: true });
|
|
Component_PaletteSearch.ComponentPaletteSearch = void 0;
|
|
var Index_1 = requireIndex();
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var ComponentPaletteSearch = /** @class */ (function (_super) {
|
|
__extends(ComponentPaletteSearch, _super);
|
|
function ComponentPaletteSearch(options) {
|
|
var _a, _b, _c;
|
|
var _this = _super.call(this) || this;
|
|
_this.defaultView = 'recent_and_rest';
|
|
_this.recents = [];
|
|
_this.pid = options === null || options === void 0 ? void 0 : options.paletteUniqueIdentifier;
|
|
_this.defaultView = (_a = options === null || options === void 0 ? void 0 : options.defaultView) !== null && _a !== void 0 ? _a : 'recent_and_rest';
|
|
if ((_this.defaultView == 'recent' ||
|
|
_this.defaultView == 'recent_and_rest') &&
|
|
(_this.pid == undefined || _this.pid.trim().length == 0))
|
|
throw new Error("Property 'paletteUniqueIdentifier' is required in component 'PaletteSearch' to use recents.");
|
|
// if (pid != undefined && pid.length > 0)
|
|
// recents = Validator.array(
|
|
// FieldStorage.getChannelValue('palette_search', pid),
|
|
// []
|
|
// );
|
|
_this.container = (0, CE_1.ce)('div', 'mux_palette');
|
|
_this.container.onclick = function () { return _this.close(); };
|
|
_this.inner = (0, CE_1.ce)('div', 'mux_palette-inner');
|
|
_this.inner.onclick = function (e) { return e.stopPropagation(); };
|
|
var input = (0, CE_1.ce)('input', 'mux_palette-input', {
|
|
type: 'text',
|
|
placeholder: (_b = options === null || options === void 0 ? void 0 : options.placeholder) !== null && _b !== void 0 ? _b : 'Starting typing to search...',
|
|
});
|
|
input.oninput = function () { return _this.handleInputUpdate(input.value); };
|
|
_this.inner.appendChild(input);
|
|
_this.results = (0, CE_1.ce)('div', ['mux_palette-results']);
|
|
_this.inner.appendChild(_this.results);
|
|
_this.container.appendChild(_this.inner);
|
|
document.body.appendChild(_this.container);
|
|
_this.items = (_c = options === null || options === void 0 ? void 0 : options.items) !== null && _c !== void 0 ? _c : [];
|
|
_this.registerKeyListener();
|
|
_this.showDefaultView();
|
|
setTimeout(function () {
|
|
_this.container.style.opacity = '1';
|
|
_this.inner.style.opacity = '1';
|
|
_this.inner.style.transform = 'scale(1)';
|
|
input.focus();
|
|
}, 20);
|
|
return _this;
|
|
}
|
|
ComponentPaletteSearch.prototype.close = function () {
|
|
var _this = this;
|
|
this.overwrite.close();
|
|
this.container.style.pointerEvents = 'none';
|
|
this.container.style.opacity = '0';
|
|
this.inner.style.opacity = '0';
|
|
this.inner.style.transform = 'scale(0.8)';
|
|
setTimeout(function () { return _this.destroy(); }, 400);
|
|
this.callEvent('close');
|
|
};
|
|
ComponentPaletteSearch.prototype.registerKeyListener = function () {
|
|
var _this = this;
|
|
this.overwrite = Index_1.MorphKey.createOverwrite();
|
|
this.overwrite.bind('Escape', function () { return _this.close(); });
|
|
this.overwrite.bind('Enter', function () {
|
|
var selected = _this.getSelectedResult();
|
|
if (selected != null)
|
|
selected.click();
|
|
});
|
|
this.overwrite.bind('ArrowUp', function () {
|
|
var selected = _this.getSelectedResult();
|
|
if (selected != null &&
|
|
selected.previousElementSibling != null &&
|
|
selected.previousElementSibling.classList.contains('mux_palette-results-item')) {
|
|
selected.classList.remove('mux_palette-results-item-selected');
|
|
selected.previousElementSibling.classList.add('mux_palette-results-item-selected');
|
|
setTimeout(function () {
|
|
if ((selected === null || selected === void 0 ? void 0 : selected.previousElementSibling) != null)
|
|
selected.previousElementSibling.scrollIntoView({
|
|
behavior: 'auto',
|
|
block: 'center',
|
|
inline: 'center',
|
|
});
|
|
}, 50);
|
|
}
|
|
});
|
|
this.overwrite.bind('ArrowDown', function () {
|
|
var selected = _this.getSelectedResult();
|
|
if (selected != null &&
|
|
selected.nextElementSibling != null &&
|
|
selected.nextElementSibling.classList.contains('mux_palette-results-item')) {
|
|
selected.classList.remove('mux_palette-results-item-selected');
|
|
selected.nextElementSibling.classList.add('mux_palette-results-item-selected');
|
|
setTimeout(function () {
|
|
if ((selected === null || selected === void 0 ? void 0 : selected.previousElementSibling) != null)
|
|
selected.previousElementSibling.scrollIntoView({
|
|
behavior: 'auto',
|
|
block: 'center',
|
|
inline: 'center',
|
|
});
|
|
}, 50);
|
|
}
|
|
});
|
|
};
|
|
ComponentPaletteSearch.prototype.search = function (query) {
|
|
var tagwords = this.getTags(query);
|
|
var results = [];
|
|
for (var i = 0; i < this.items.length; i++) {
|
|
var item = this.items[i];
|
|
var score = this.getScore(tagwords, item.tags != undefined ? item.tags : this.getTags(item.name)) *
|
|
(item.scoreWeight != undefined && !isNaN(item.scoreWeight)
|
|
? item.scoreWeight
|
|
: 1);
|
|
if (score > 0)
|
|
results.push(__assign({ score: score }, item));
|
|
}
|
|
return results;
|
|
};
|
|
ComponentPaletteSearch.prototype.addToRecents = function (recentId) {
|
|
var newRecents = [];
|
|
__spreadArray([recentId], this.recents, true).forEach(function (id) {
|
|
if (!newRecents.includes(id))
|
|
newRecents.push(id);
|
|
});
|
|
if (newRecents.length > 5)
|
|
newRecents.splice(5, newRecents.length - 5);
|
|
this.recents = newRecents;
|
|
// FieldStorage.setChannelValue('palette_search', pid, this.recents);
|
|
};
|
|
ComponentPaletteSearch.prototype.renderSearchResult = function (result, index) {
|
|
var _this = this;
|
|
var item = (0, CE_1.ce)(result.href != undefined ? 'a' : 'div', 'mux_palette-results-item');
|
|
if (result.href != undefined)
|
|
item.href = result.href;
|
|
else if (result.click != undefined)
|
|
item.addEventListener('click', function () {
|
|
result.click();
|
|
_this.close();
|
|
});
|
|
if (this.pid != undefined &&
|
|
this.pid.length > 0 &&
|
|
(result.uniqueIdentifier != undefined || result.href != undefined)) {
|
|
item.addEventListener('click', function () {
|
|
var _a;
|
|
return _this.addToRecents((_a = result.uniqueIdentifier) !== null && _a !== void 0 ? _a : "address:".concat(result.href));
|
|
});
|
|
}
|
|
if (index == 0)
|
|
item.classList.add('mux_palette-results-item-selected');
|
|
if (result.materialIcon != undefined) {
|
|
var icon = (0, CE_1.ce)('span', 'material-symbols-outlined', null, result.materialIcon);
|
|
if (result.materialIconTransform != undefined)
|
|
icon.style.transform = result.materialIconTransform;
|
|
item.appendChild(icon);
|
|
}
|
|
else if (result.iconSrc != undefined)
|
|
item.appendChild((0, CE_1.ce)('img', 'mux_palette-results-item-icon', {
|
|
src: result.iconSrc,
|
|
}));
|
|
var text = (0, CE_1.ce)('div', [
|
|
'mux_palette-results-item-text',
|
|
'mux_text',
|
|
'mux_small',
|
|
]);
|
|
if (result.prefix != undefined)
|
|
text.appendChild((0, CE_1.ce)('span', 'mux_palette-results-item-text-sub', null, result.prefix.trim()));
|
|
text.appendChild((0, CE_1.ce)('span', 'mux_palette-results-item-text-main', null, result.name.trim()));
|
|
if (result.suffix != undefined)
|
|
text.appendChild((0, CE_1.ce)('span', 'mux_palette-results-item-text-sub', null, result.suffix.trim()));
|
|
item.appendChild(text);
|
|
// if (result.selectedText != undefined) {
|
|
// item.appendChild(
|
|
// ce(
|
|
// 'div',
|
|
// ['mux_palette-results-item-selectedtext', 'mux_text', 'mux_tiny'],
|
|
// null,
|
|
// result.selectedText
|
|
// )
|
|
// );
|
|
// }
|
|
this.results.appendChild(item);
|
|
return item;
|
|
};
|
|
ComponentPaletteSearch.prototype.showDefaultView = function () {
|
|
var _this = this;
|
|
this.results.innerHTML = '';
|
|
switch (this.defaultView) {
|
|
case 'all':
|
|
this.items.forEach(function (item, i) {
|
|
return _this.renderSearchResult(item, i);
|
|
});
|
|
break;
|
|
case 'none':
|
|
return;
|
|
case 'recent_and_rest':
|
|
var recentItems = this.getRecentItems();
|
|
if (recentItems.length > 0)
|
|
this.showResultLabel('Recent actions', 'schedule');
|
|
recentItems.forEach(function (item, i) {
|
|
return _this.renderSearchResult(item, i);
|
|
});
|
|
var otherItems = this.items.filter(function (item) {
|
|
var _a;
|
|
if (item.uniqueIdentifier == undefined && item.href == null)
|
|
return true;
|
|
return !_this.recents.includes((_a = item.uniqueIdentifier) !== null && _a !== void 0 ? _a : "address:".concat(item.href));
|
|
});
|
|
if (otherItems.length > 0) {
|
|
otherItems.forEach(function (item, i) {
|
|
var itemElement = _this.renderSearchResult(item, i + recentItems.length);
|
|
if (i == 0 && recentItems.length > 0)
|
|
itemElement.classList.add('mux_palette-results-item-separator');
|
|
});
|
|
}
|
|
break;
|
|
case 'recent':
|
|
default:
|
|
this.showResultLabel('Recent actions', 'schedule');
|
|
this.getRecentItems().forEach(function (item, i) {
|
|
return _this.renderSearchResult(item, i);
|
|
});
|
|
break;
|
|
}
|
|
};
|
|
ComponentPaletteSearch.prototype.getRecentItems = function () {
|
|
if (this.recents == undefined || this.recents.length == 0)
|
|
return [];
|
|
var addressMap = new Map();
|
|
var uidMap = new Map();
|
|
this.items.forEach(function (item) {
|
|
if (item.uniqueIdentifier != undefined &&
|
|
item.uniqueIdentifier.trim().length > 0)
|
|
uidMap.set(item.uniqueIdentifier.trim(), item);
|
|
if (item.href != undefined && item.href.trim().length > 0)
|
|
addressMap.set(item.href.trim(), item);
|
|
});
|
|
var recentItems = [];
|
|
this.recents.forEach(function (recentId) {
|
|
if (recentId.startsWith('address:')) {
|
|
if (addressMap.has(recentId.replace('address:', '')))
|
|
recentItems.push(addressMap.get(recentId.replace('address:', '')));
|
|
}
|
|
else {
|
|
if (uidMap.has(recentId))
|
|
recentItems.push(uidMap.get(recentId));
|
|
}
|
|
});
|
|
return recentItems;
|
|
};
|
|
ComponentPaletteSearch.prototype.handleInputUpdate = function (value) {
|
|
var _this = this;
|
|
if (value.trim().length < 1)
|
|
return this.showDefaultView();
|
|
this.results.innerHTML = '';
|
|
var searchresults = this.search(value.trim());
|
|
if (searchresults.length == 0)
|
|
return this.showResultLabel('No results based on your search query.', 'warning');
|
|
searchresults
|
|
.sort(function (a, b) {
|
|
return b.score - a.score;
|
|
})
|
|
.forEach(function (result, index) { return _this.renderSearchResult(result, index); });
|
|
};
|
|
ComponentPaletteSearch.prototype.showResultLabel = function (text, materialIcon) {
|
|
var label = (0, CE_1.ce)('div', 'mux_palette-results-label');
|
|
if (materialIcon != undefined)
|
|
label.appendChild((0, CE_1.ce)('span', 'material-symbols-outlined', null, materialIcon));
|
|
label.appendChild((0, CE_1.ce)('span', null, null, text));
|
|
this.results.appendChild(label);
|
|
};
|
|
ComponentPaletteSearch.prototype.getSelectedResult = function () {
|
|
if (this.results == null)
|
|
return null;
|
|
return this.results.querySelector('.mux_palette-results-item-selected');
|
|
};
|
|
ComponentPaletteSearch.prototype.getScore = function (queryWords, tagWords) {
|
|
var score = 0;
|
|
var _loop_1 = function (i) {
|
|
tagWords.forEach(function (tagWord) {
|
|
if (tagWord.includes(queryWords[i])) {
|
|
score += tagWord.startsWith(queryWords[i]) ? 2 : 1;
|
|
}
|
|
});
|
|
};
|
|
for (var i = 0; i < queryWords.length; i++) {
|
|
_loop_1(i);
|
|
}
|
|
return score;
|
|
};
|
|
ComponentPaletteSearch.prototype.getTags = function (query) {
|
|
var tags = [];
|
|
query
|
|
.toLowerCase()
|
|
.split(' ')
|
|
.map(function (word) {
|
|
return word.trim();
|
|
})
|
|
.filter(function (word) {
|
|
return word.length > 0;
|
|
})
|
|
.forEach(function (tag) {
|
|
if (!tags.includes(tag))
|
|
tags.push(tag);
|
|
});
|
|
return tags;
|
|
};
|
|
return ComponentPaletteSearch;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_PaletteSearch.ComponentPaletteSearch = ComponentPaletteSearch;
|
|
|
|
return Component_PaletteSearch;
|
|
}
|
|
|
|
var Component_Resizer = {};
|
|
|
|
var __extends$2 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Resizer, "__esModule", { value: true });
|
|
Component_Resizer.ComponentResizer = void 0;
|
|
var CE_1$2 = CE;
|
|
var baseComponent_1$2 = baseComponent;
|
|
var ComponentResizer = /** @class */ (function (_super) {
|
|
__extends$2(ComponentResizer, _super);
|
|
function ComponentResizer(options) {
|
|
var _a, _b, _c;
|
|
var _this = _super.call(this) || this;
|
|
_this.startPoint = null;
|
|
_this.startSize = null;
|
|
_this.preMove = true;
|
|
_this.moveEvent = function (e) {
|
|
_this.handleMove(e);
|
|
};
|
|
_this.touchEndEvent = function (e) {
|
|
_this.stopResize();
|
|
};
|
|
_this.direction = (_a = options === null || options === void 0 ? void 0 : options.direction) !== null && _a !== void 0 ? _a : 'right';
|
|
_this.closeable = (_b = options === null || options === void 0 ? void 0 : options.closeable) !== null && _b !== void 0 ? _b : false;
|
|
_this.min = options === null || options === void 0 ? void 0 : options.min;
|
|
_this.max = options === null || options === void 0 ? void 0 : options.max;
|
|
_this.relative = (_c = options === null || options === void 0 ? void 0 : options.relative) !== null && _c !== void 0 ? _c : false;
|
|
_this.container = (0, CE_1$2.ce)('div', 'mux_resizer');
|
|
var area = (0, CE_1$2.ce)('div', 'mux_resizer-area');
|
|
var grab = (0, CE_1$2.ce)('div', 'mux_resizer-grab');
|
|
var grabHandle = (0, CE_1$2.ce)('span', ['material-symbols-outlined', 'mux_resizer-grab-handle'], null, 'drag_handle');
|
|
if (options.direction == 'left' || options.direction == 'right')
|
|
grabHandle.style.transform = 'rotate(90deg)';
|
|
grab.appendChild(grabHandle);
|
|
var grabOpen = (0, CE_1$2.ce)('span', ['material-symbols-outlined', 'mux_resizer-grab-open'], null, {
|
|
left: 'arrow_left',
|
|
right: 'arrow_right',
|
|
up: 'arrow_drop_up',
|
|
down: 'arrow_drop_down',
|
|
}[_this.direction]);
|
|
grab.appendChild(grabOpen);
|
|
area.appendChild(grab);
|
|
if ((options === null || options === void 0 ? void 0 : options.existingContainer) != undefined) {
|
|
if (!options.existingContainer.classList.contains('mux_resizer'))
|
|
throw new Error('Container of registered resizer does not contain mux_resizer classname');
|
|
_this.container = options.existingContainer;
|
|
if (_this.container.querySelector('.mux_resizer-area') != null) {
|
|
var existingArea = _this.container.querySelector('.mux_resizer-area');
|
|
_this.container.removeChild(existingArea);
|
|
}
|
|
}
|
|
_this.container.appendChild(area);
|
|
_this.container.classList.add("mux_resizer-direction-".concat(_this.direction));
|
|
_this.currentSize =
|
|
_this.direction == 'left' || _this.direction == 'right'
|
|
? _this.container.clientWidth
|
|
: _this.container.clientHeight;
|
|
area.addEventListener('mousedown', function (e) { return _this.startResize(e); });
|
|
area.addEventListener('touchstart', function (e) { return _this.startResize(e); });
|
|
grab.addEventListener('mousedown', function (e) { return _this.startResize(e); });
|
|
area.addEventListener('touchstart', function (e) { return _this.startResize(e); });
|
|
grab.addEventListener('click', function () {
|
|
if (!_this.container.classList.contains('mux_resizer-closed'))
|
|
return;
|
|
var size = typeof _this.min === 'function' ? _this.min() : _this.min;
|
|
if (_this.direction == 'left' || _this.direction == 'right')
|
|
_this.container.style.width = _this.toSize(size);
|
|
else if (_this.direction == 'up' || _this.direction == 'down')
|
|
_this.container.style.height = _this.toSize(size);
|
|
_this.currentSize = size;
|
|
_this.callEvent('resized', size);
|
|
_this.container.classList.remove('mux_resizer-closed');
|
|
});
|
|
if (!_this.relative)
|
|
window.addEventListener('resize', function () {
|
|
_this.setSize(_this.currentSize);
|
|
});
|
|
return _this;
|
|
}
|
|
ComponentResizer.prototype.toSize = function (value) {
|
|
if (!this.relative)
|
|
return "".concat(value, "px");
|
|
var parentSize = this.direction == 'left' || this.direction == 'right'
|
|
? this.container.parentElement.clientWidth
|
|
: this.container.parentElement.clientHeight;
|
|
var percent = (value / parentSize) * 100;
|
|
return "".concat(percent, "%");
|
|
};
|
|
ComponentResizer.prototype.setSize = function (size) {
|
|
var value = this.parseNewValue(size);
|
|
if (this.direction == 'left' || this.direction == 'right')
|
|
this.container.style.width = this.toSize(value);
|
|
else if (this.direction == 'up' || this.direction == 'down')
|
|
this.container.style.height = this.toSize(value);
|
|
this.currentSize = value;
|
|
this.callEvent('resized', value);
|
|
};
|
|
ComponentResizer.prototype.getSize = function () {
|
|
return this.currentSize;
|
|
};
|
|
ComponentResizer.prototype.parseNewValue = function (value) {
|
|
var _min = typeof this.min === 'function' ? this.min() : this.min;
|
|
var _max = typeof this.max === 'function' ? this.max() : this.max;
|
|
value >= _min
|
|
? this.container.classList.remove('mux_resizer-block')
|
|
: this.container.classList.add('mux_resizer-block');
|
|
if (_min >= 0) {
|
|
if (this.closeable == true && value < _min * 0.5) {
|
|
this.container.classList.add('mux_resizer-closed');
|
|
this.callEvent('resized', 0);
|
|
return 0;
|
|
}
|
|
else
|
|
value = Math.max(_min, value);
|
|
}
|
|
if (_max > 0)
|
|
value = Math.min(_max, value);
|
|
this.container.classList.remove('mux_resizer-closed');
|
|
return value;
|
|
};
|
|
ComponentResizer.prototype.startResize = function (e) {
|
|
var _a = this.pageCoords(e), x = _a.x, y = _a.y;
|
|
var bounds = this.container.getBoundingClientRect();
|
|
if (this.direction == 'left' || this.direction == 'right') {
|
|
this.startPoint = x;
|
|
this.startSize = bounds.width;
|
|
}
|
|
else if (this.direction == 'up' || this.direction == 'down') {
|
|
this.startPoint = y;
|
|
this.startSize = bounds.height;
|
|
}
|
|
window.addEventListener('mousemove', this.moveEvent);
|
|
window.addEventListener('touchmove', this.moveEvent);
|
|
window.addEventListener('touchend', this.touchEndEvent);
|
|
};
|
|
ComponentResizer.prototype.stopResize = function () {
|
|
this.startPoint = null;
|
|
this.startSize = null;
|
|
this.preMove = true;
|
|
this.container.classList.remove('mux_resizer-moving');
|
|
window.removeEventListener('mousemove', this.moveEvent);
|
|
window.removeEventListener('touchmove', this.moveEvent);
|
|
window.removeEventListener('touchend', this.touchEndEvent);
|
|
};
|
|
ComponentResizer.prototype.handleMove = function (e) {
|
|
var _a, _b, _c;
|
|
if (((_a = e === null || e === void 0 ? void 0 : e.buttons) !== null && _a !== void 0 ? _a : 1) != 1 ||
|
|
((_c = (_b = e === null || e === void 0 ? void 0 : e.touches) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 1) == 0 ||
|
|
this.startPoint == null ||
|
|
this.startSize == null) {
|
|
this.stopResize();
|
|
return;
|
|
}
|
|
var _d = this.pageCoords(e), x = _d.x, y = _d.y;
|
|
if (this.preMove) {
|
|
var startSpan = Math.abs(this.startPoint -
|
|
(this.direction == 'left' || this.direction == 'right'
|
|
? x
|
|
: y));
|
|
if (startSpan >= 10) {
|
|
this.preMove = false;
|
|
this.container.classList.add('mux_resizer-moving');
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
var value = null;
|
|
if (this.direction == 'left' || this.direction == 'right') {
|
|
value = this.parseNewValue(this.startSize +
|
|
(this.direction == 'left'
|
|
? this.startPoint - x
|
|
: x - this.startPoint));
|
|
this.container.style.width = this.toSize(value);
|
|
}
|
|
else if (this.direction == 'up' || this.direction == 'down') {
|
|
value = this.parseNewValue(this.startSize +
|
|
(this.direction == 'up'
|
|
? this.startPoint - y
|
|
: y - this.startPoint));
|
|
this.container.style.height = this.toSize(value);
|
|
}
|
|
this.currentSize = value;
|
|
this.callEvent('resized', value);
|
|
};
|
|
ComponentResizer.prototype.pageCoords = function (e) {
|
|
var _a, _b, _c, _d;
|
|
return {
|
|
x: (_a = e.pageX) !== null && _a !== void 0 ? _a : (_b = e.touches[0]) === null || _b === void 0 ? void 0 : _b.pageX,
|
|
y: (_c = e.pageY) !== null && _c !== void 0 ? _c : (_d = e.touches[0]) === null || _d === void 0 ? void 0 : _d.pageY,
|
|
};
|
|
};
|
|
return ComponentResizer;
|
|
}(baseComponent_1$2.MUXComponent));
|
|
Component_Resizer.ComponentResizer = ComponentResizer;
|
|
|
|
var Component_Row = {};
|
|
|
|
var __extends$1 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Row, "__esModule", { value: true });
|
|
Component_Row.ComponentRow = void 0;
|
|
var CE_1$1 = CE;
|
|
var baseComponent_1$1 = baseComponent;
|
|
var ComponentRow = /** @class */ (function (_super) {
|
|
__extends$1(ComponentRow, _super);
|
|
function ComponentRow(options) {
|
|
var _this = _super.call(this) || this;
|
|
_this.container = (0, CE_1$1.ce)('div', 'mux_row');
|
|
if ((options === null || options === void 0 ? void 0 : options.spreadEven) == true)
|
|
_this.container.classList.add('mux_spread');
|
|
if ((options === null || options === void 0 ? void 0 : options.indent) == true)
|
|
_this.container.classList.add('mux_indent');
|
|
if ((options === null || options === void 0 ? void 0 : options.disabled) == true)
|
|
_this.container.classList.add('mux_disabled');
|
|
if ((options === null || options === void 0 ? void 0 : options.tooltip) != undefined)
|
|
_this.container.title = options.tooltip;
|
|
_this.content = (0, CE_1$1.ce)('div', 'mux_row-content');
|
|
var label = (0, CE_1$1.ce)('div', ['mux_row-label', 'mux_text'], null, options.label);
|
|
if ((options === null || options === void 0 ? void 0 : options.layout) != undefined && options.layout == 'valueFirst') {
|
|
_this.container.appendChild(_this.content);
|
|
_this.container.appendChild(label);
|
|
}
|
|
else {
|
|
_this.container.appendChild(label);
|
|
_this.container.appendChild(_this.content);
|
|
}
|
|
if (options.content != undefined)
|
|
_this.content.appendChild(options.content);
|
|
return _this;
|
|
}
|
|
ComponentRow.prototype.setEnabled = function (state) {
|
|
if (state)
|
|
this.container.classList.remove('mux_disabled');
|
|
else
|
|
this.container.classList.add('mux_disabled');
|
|
};
|
|
ComponentRow.prototype.setTooltip = function (tooltip) {
|
|
if (tooltip == null)
|
|
this.container.removeAttribute('title');
|
|
else
|
|
this.container.title = tooltip;
|
|
};
|
|
return ComponentRow;
|
|
}(baseComponent_1$1.MUXComponent));
|
|
Component_Row.ComponentRow = ComponentRow;
|
|
|
|
var Component_Select = {};
|
|
|
|
var hasRequiredComponent_Select;
|
|
|
|
function requireComponent_Select () {
|
|
if (hasRequiredComponent_Select) return Component_Select;
|
|
hasRequiredComponent_Select = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Select, "__esModule", { value: true });
|
|
Component_Select.ComponentSelect = void 0;
|
|
var Index_1 = requireIndex();
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var ComponentSelect = /** @class */ (function (_super) {
|
|
__extends(ComponentSelect, _super);
|
|
function ComponentSelect(options) {
|
|
var _a, _b, _c;
|
|
var _this = _super.call(this) || this;
|
|
_this.show = 'name';
|
|
_this.show = (_a = options.show) !== null && _a !== void 0 ? _a : 'name';
|
|
_this.container = (0, CE_1.ce)('div', 'mux_select');
|
|
var border = (_b = options.border) !== null && _b !== void 0 ? _b : 'hover';
|
|
if (border == 'always')
|
|
_this.container.classList.add('mux_select-alwaysborder');
|
|
else if (border == 'never')
|
|
_this.container.classList.add('mux_select-noborder');
|
|
_this.input = new Index_1.MorphComponent.Input({
|
|
type: 'text',
|
|
border: 'never',
|
|
});
|
|
_this.input.container.onkeydown = function (e) {
|
|
e.preventDefault();
|
|
};
|
|
_this.container.appendChild(_this.input.container);
|
|
_this.content = (0, CE_1.ce)('div', 'mux_select-content');
|
|
_this.container.appendChild(_this.content);
|
|
_this.container.appendChild((0, CE_1.ce)('span', ['material-symbols-outlined', 'mux_select-arrow'], null, 'keyboard_arrow_down'));
|
|
_this.input.container.onfocus = function () {
|
|
_this.input.container.blur();
|
|
_this.toggleContext();
|
|
};
|
|
_this.input.container.onblur = function () {
|
|
_this.context.close('selectblur');
|
|
};
|
|
_this.container.onclick = function () { return _this.toggleContext(); };
|
|
_this.items = (_c = options === null || options === void 0 ? void 0 : options.items) !== null && _c !== void 0 ? _c : [];
|
|
_this.select(options.selectedId, false);
|
|
return _this;
|
|
}
|
|
ComponentSelect.prototype.setItems = function (items) {
|
|
this.items = items;
|
|
};
|
|
ComponentSelect.prototype.select = function (id, dispatchEvent) {
|
|
var _a;
|
|
if (dispatchEvent === void 0) { dispatchEvent = true; }
|
|
var item = this.items.find(function (i) {
|
|
if (i.type == 'separator')
|
|
return false;
|
|
return i.id == id;
|
|
});
|
|
this.selectedId = id;
|
|
this.content.innerHTML = '';
|
|
if (item == null) {
|
|
this.content.appendChild((0, CE_1.ce)('div', ['mux_text', 'mux_small', 'mux_select-none'], null, 'None selected'));
|
|
return;
|
|
}
|
|
if (item.materialIcon != undefined) {
|
|
var materialIcon = (0, CE_1.ce)('span', 'material-symbols-outlined', null, item.materialIcon);
|
|
if (item.materialIconTransform != undefined)
|
|
materialIcon.style.transform = item.materialIconTransform;
|
|
this.content.appendChild(materialIcon);
|
|
}
|
|
else if (item.icon != undefined) {
|
|
this.content.appendChild((0, CE_1.ce)('img', 'mux_select-content-icon', { src: item.icon }));
|
|
}
|
|
this.content.appendChild((0, CE_1.ce)('div', ['mux_text', 'mux_small'], null, (_a = item.text) !== null && _a !== void 0 ? _a : item.id));
|
|
if (dispatchEvent)
|
|
this.callEvent('input', id);
|
|
};
|
|
ComponentSelect.prototype.setSelected = function (id) {
|
|
this.select(id, false);
|
|
};
|
|
ComponentSelect.prototype.getSelected = function () {
|
|
return this.selectedId;
|
|
};
|
|
ComponentSelect.prototype.toggleContext = function () {
|
|
var _this = this;
|
|
if (this.context != null) {
|
|
return this.context.close('selecttoggle');
|
|
}
|
|
var bounds = this.container.getBoundingClientRect();
|
|
this.context = new Index_1.MorphComponent.ContextMenu({
|
|
x: bounds.x + bounds.width / 2,
|
|
y: bounds.y + bounds.height,
|
|
align: 'center',
|
|
selected: this.selectedId,
|
|
items: this.items.map(function (item) {
|
|
var _a, _b;
|
|
if (item.type == 'separator') {
|
|
return { type: 'separator' };
|
|
}
|
|
return {
|
|
type: (_a = item.type) !== null && _a !== void 0 ? _a : 'normal',
|
|
uniqueIdentifier: item.id,
|
|
text: (_b = item.text) !== null && _b !== void 0 ? _b : item.id,
|
|
materialIcon: item.materialIcon,
|
|
materialIconTransform: item.materialIconTransform,
|
|
icon: item.icon,
|
|
click: function () {
|
|
_this.select(item.id, true);
|
|
},
|
|
};
|
|
}),
|
|
});
|
|
this.container.classList.add('mux_select-open');
|
|
this.context.on('close', function () {
|
|
_this.container.classList.remove('mux_select-open');
|
|
_this.context = null;
|
|
});
|
|
};
|
|
return ComponentSelect;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_Select.ComponentSelect = ComponentSelect;
|
|
|
|
return Component_Select;
|
|
}
|
|
|
|
var Component_Table = {};
|
|
|
|
var Component_Table_Button = {};
|
|
|
|
var Component_Table__base = {};
|
|
|
|
Object.defineProperty(Component_Table__base, "__esModule", { value: true });
|
|
Component_Table__base.ComponentTable_Base = void 0;
|
|
var ComponentTable_Base = /** @class */ (function () {
|
|
function ComponentTable_Base() {
|
|
}
|
|
ComponentTable_Base.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
return null;
|
|
};
|
|
return ComponentTable_Base;
|
|
}());
|
|
Component_Table__base.ComponentTable_Base = ComponentTable_Base;
|
|
|
|
var hasRequiredComponent_Table_Button;
|
|
|
|
function requireComponent_Table_Button () {
|
|
if (hasRequiredComponent_Table_Button) return Component_Table_Button;
|
|
hasRequiredComponent_Table_Button = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Table_Button, "__esModule", { value: true });
|
|
Component_Table_Button.ComponentTable_Button = void 0;
|
|
var Index_1 = requireIndex();
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_Button = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_Button, _super);
|
|
function ComponentTable_Button() {
|
|
return _super.call(this) || this;
|
|
}
|
|
ComponentTable_Button.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var container = (0, Index_1.ce)('div', ['mux_table-button']);
|
|
var btn = (0, Index_1.ce)('div', [
|
|
'mux_table-button-btn',
|
|
'mux_text',
|
|
'mux_small',
|
|
"mux_table-button-btn-".concat(encodeURI(cell.text)),
|
|
], { title: cell.tooltip }, cell.text);
|
|
btn.onclick = function (e) {
|
|
e.stopPropagation();
|
|
component.callEvent('buttonClick', rowId, column.uniqueIdentifier);
|
|
};
|
|
container.appendChild(btn);
|
|
return container;
|
|
};
|
|
return ComponentTable_Button;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_Button.ComponentTable_Button = ComponentTable_Button;
|
|
|
|
return Component_Table_Button;
|
|
}
|
|
|
|
var Component_Table_Duration = {};
|
|
|
|
var Component_Table_Text = {};
|
|
|
|
var hasRequiredComponent_Table_Text;
|
|
|
|
function requireComponent_Table_Text () {
|
|
if (hasRequiredComponent_Table_Text) return Component_Table_Text;
|
|
hasRequiredComponent_Table_Text = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Table_Text, "__esModule", { value: true });
|
|
Component_Table_Text.ComponentTable_Text = void 0;
|
|
var Index_1 = requireIndex();
|
|
var TextHighlighter_1 = TextHighlighter;
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_Text = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_Text, _super);
|
|
function ComponentTable_Text(allowHighlighting) {
|
|
var _this = _super.call(this) || this;
|
|
_this.allowHighlighting = allowHighlighting;
|
|
return _this;
|
|
}
|
|
ComponentTable_Text.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var _a, _b, _c, _d, _e, _f;
|
|
if (asNumber === void 0) { asNumber = false; }
|
|
var wrapper = (0, Index_1.ce)('div', 'mux_table-wrapper');
|
|
var container = (0, Index_1.ce)('div', 'mux_table-text', {
|
|
title: (_a = cell === null || cell === void 0 ? void 0 : cell.tooltip) !== null && _a !== void 0 ? _a : '',
|
|
});
|
|
var text = this.allowHighlighting
|
|
? (0, TextHighlighter_1.generateTextHighlights)(String(cell.value).trim())
|
|
: (0, Index_1.ce)('div', ['mux_text', 'mux_small'], null, "".concat((_b = cell.prefix) !== null && _b !== void 0 ? _b : '', " ").concat(cell.value).trim());
|
|
text.prepend((0, Index_1.ce)('span', null, null, cell.prefix));
|
|
text.style.justifyContent = {
|
|
left: 'flex-Start',
|
|
right: 'flex-end',
|
|
center: 'center',
|
|
}[(_c = cell.align) !== null && _c !== void 0 ? _c : 'left'];
|
|
var editonly = column.editonly;
|
|
container.appendChild(text);
|
|
if (column.editable) {
|
|
var inputContainer = (0, Index_1.ce)('div', 'mux_table-edit-input');
|
|
var inputPrefix = (0, Index_1.ce)('div', ['mux_text', 'mux_small', 'mux_table-edit-input-prefix'], null, (_d = cell.prefix) !== null && _d !== void 0 ? _d : '');
|
|
var input = new Index_1.MorphComponent.Input({
|
|
type: 'text',
|
|
value: String((_e = cell === null || cell === void 0 ? void 0 : cell.value) !== null && _e !== void 0 ? _e : '').trim(),
|
|
border: 'always',
|
|
});
|
|
if (editonly)
|
|
input.on('input', function () {
|
|
component.callEvent('valueUpdated', rowId, column.uniqueIdentifier, !asNumber
|
|
? input.container.value
|
|
: parseFloat(input.container.value));
|
|
});
|
|
input.container.style.textAlign = (_f = cell.align) !== null && _f !== void 0 ? _f : 'left';
|
|
inputContainer.appendChild(inputPrefix);
|
|
inputContainer.appendChild(input.container);
|
|
container.appendChild(inputContainer);
|
|
container.style.cursor = 'pointer';
|
|
var hasFirst = false;
|
|
var clickTimeout;
|
|
container.onclick = function () {
|
|
clearTimeout(clickTimeout);
|
|
if (hasFirst == false) {
|
|
hasFirst = true;
|
|
clickTimeout = setTimeout(function () {
|
|
hasFirst = false;
|
|
}, 1000);
|
|
}
|
|
else {
|
|
openEdit();
|
|
hasFirst = false;
|
|
}
|
|
};
|
|
var openEdit = function () {
|
|
text.style.display = 'none';
|
|
inputContainer.style.display = 'flex';
|
|
input.container.focus();
|
|
input.container.setSelectionRange(input.container.value.length, input.container.value.length);
|
|
var initValue = input.container.value;
|
|
var close = function () {
|
|
if (editonly)
|
|
return;
|
|
window.removeEventListener('click', onclick);
|
|
component.callEvent('valueUpdated', rowId, column.uniqueIdentifier, !asNumber
|
|
? input.container.value
|
|
: parseFloat(input.container.value));
|
|
text.innerText = input.container.value;
|
|
text.style.display = 'flex';
|
|
inputContainer.style.display = 'none';
|
|
};
|
|
input.container.onkeydown = function (e) {
|
|
if (editonly)
|
|
return;
|
|
if (e.key == 'Enter')
|
|
close();
|
|
else if (e.key == 'Escape') {
|
|
input.container.value = initValue;
|
|
text.innerText = input.container.value;
|
|
close();
|
|
}
|
|
};
|
|
if (!editonly) {
|
|
var onclick = function (e) {
|
|
if (e.target == undefined ||
|
|
e.target != input.container)
|
|
close();
|
|
};
|
|
setTimeout(function () { return window.addEventListener('click', onclick); }, 100);
|
|
}
|
|
};
|
|
if (editonly)
|
|
openEdit();
|
|
}
|
|
wrapper.appendChild(container);
|
|
if (cell.subText != undefined) {
|
|
wrapper.appendChild((0, Index_1.ce)('div', ['mux_text', 'mux_tiny', 'mux_table-subtext'], null, cell.subText.trim()));
|
|
}
|
|
return wrapper;
|
|
};
|
|
return ComponentTable_Text;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_Text.ComponentTable_Text = ComponentTable_Text;
|
|
|
|
return Component_Table_Text;
|
|
}
|
|
|
|
var hasRequiredComponent_Table_Duration;
|
|
|
|
function requireComponent_Table_Duration () {
|
|
if (hasRequiredComponent_Table_Duration) return Component_Table_Duration;
|
|
hasRequiredComponent_Table_Duration = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Table_Duration, "__esModule", { value: true });
|
|
Component_Table_Duration.ComponentTable_Duration = void 0;
|
|
var Component_Table_Text_1 = requireComponent_Table_Text();
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_Duration = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_Duration, _super);
|
|
function ComponentTable_Duration() {
|
|
var _this = _super.call(this) || this;
|
|
_this._text = new Component_Table_Text_1.ComponentTable_Text(false);
|
|
return _this;
|
|
}
|
|
ComponentTable_Duration.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var element = this._text.createElement(cell, rowId, column, component, true);
|
|
var elementText = element.querySelector('.mux_text');
|
|
if (elementText != null)
|
|
elementText.style.justifyContent = 'center';
|
|
element.classList.add('mux_table-duration');
|
|
var input = element.querySelector('input');
|
|
var regex = /^[0-9.]+$/;
|
|
element.addEventListener('input', function () {
|
|
var currentValue = input.value;
|
|
if (!regex.test(currentValue)) {
|
|
input.value = currentValue.slice(0, -1);
|
|
}
|
|
});
|
|
return element;
|
|
};
|
|
return ComponentTable_Duration;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_Duration.ComponentTable_Duration = ComponentTable_Duration;
|
|
|
|
return Component_Table_Duration;
|
|
}
|
|
|
|
var Component_Table_Icons = {};
|
|
|
|
var hasRequiredComponent_Table_Icons;
|
|
|
|
function requireComponent_Table_Icons () {
|
|
if (hasRequiredComponent_Table_Icons) return Component_Table_Icons;
|
|
hasRequiredComponent_Table_Icons = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Table_Icons, "__esModule", { value: true });
|
|
Component_Table_Icons.ComponentTable_Icons = void 0;
|
|
var Index_1 = requireIndex();
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_Icons = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_Icons, _super);
|
|
function ComponentTable_Icons() {
|
|
return _super.call(this) || this;
|
|
}
|
|
ComponentTable_Icons.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var _a;
|
|
var container = (0, Index_1.ce)('div', ['mux_table-icons']);
|
|
((_a = cell === null || cell === void 0 ? void 0 : cell.items) !== null && _a !== void 0 ? _a : []).forEach(function (item) {
|
|
var itemElement = (0, Index_1.ce)('div', 'mux_table-icon');
|
|
itemElement.appendChild((0, Index_1.ce)('span', 'material-symbols-outlined', null, item.materialIcon));
|
|
if (item.color != undefined)
|
|
itemElement.style.color = item.color;
|
|
itemElement.onclick = function (e) {
|
|
e.stopPropagation();
|
|
item.click();
|
|
};
|
|
container.appendChild(itemElement);
|
|
});
|
|
return container;
|
|
};
|
|
return ComponentTable_Icons;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_Icons.ComponentTable_Icons = ComponentTable_Icons;
|
|
|
|
return Component_Table_Icons;
|
|
}
|
|
|
|
var Component_Table_MaterialSymbol = {};
|
|
|
|
var hasRequiredComponent_Table_MaterialSymbol;
|
|
|
|
function requireComponent_Table_MaterialSymbol () {
|
|
if (hasRequiredComponent_Table_MaterialSymbol) return Component_Table_MaterialSymbol;
|
|
hasRequiredComponent_Table_MaterialSymbol = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Table_MaterialSymbol, "__esModule", { value: true });
|
|
Component_Table_MaterialSymbol.ComponentTable_MaterialSymbol = void 0;
|
|
var Index_1 = requireIndex();
|
|
var TextHighlighter_1 = TextHighlighter;
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_MaterialSymbol = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_MaterialSymbol, _super);
|
|
function ComponentTable_MaterialSymbol() {
|
|
return _super.call(this) || this;
|
|
}
|
|
ComponentTable_MaterialSymbol.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var _a, _b, _c, _d;
|
|
if (asNumber === void 0) { asNumber = false; }
|
|
var wrapper = (0, Index_1.ce)('div', 'mux_table-wrapper');
|
|
var container = (0, Index_1.ce)('div', 'mux_table-text', {
|
|
title: (_a = cell === null || cell === void 0 ? void 0 : cell.tooltip) !== null && _a !== void 0 ? _a : '',
|
|
});
|
|
var text = this.allowHighlighting
|
|
? (0, TextHighlighter_1.generateTextHighlights)(String(cell.materialIcon).trim())
|
|
: (0, Index_1.ce)('span', ['material-symbols-outlined', 'g_text'], null, cell.materialIcon);
|
|
text.style.justifyContent = {
|
|
left: 'flex-Start',
|
|
right: 'flex-end',
|
|
center: 'center',
|
|
}[(_b = cell.align) !== null && _b !== void 0 ? _b : 'left'];
|
|
container.appendChild(text);
|
|
if (column.editable) {
|
|
var inputContainer = (0, Index_1.ce)('div', 'mux_table-edit-input');
|
|
var input = (0, Index_1.ce)('input', null, {
|
|
type: 'text',
|
|
value: String((_c = cell === null || cell === void 0 ? void 0 : cell.materialIcon) !== null && _c !== void 0 ? _c : '').trim(),
|
|
});
|
|
input.style.textAlign = (_d = cell.align) !== null && _d !== void 0 ? _d : 'left';
|
|
inputContainer.appendChild(input);
|
|
container.appendChild(inputContainer);
|
|
container.style.cursor = 'pointer';
|
|
var hasFirst = false;
|
|
var clickTimeout;
|
|
container.onclick = function () {
|
|
clearTimeout(clickTimeout);
|
|
if (hasFirst == false) {
|
|
hasFirst = true;
|
|
clickTimeout = setTimeout(function () {
|
|
hasFirst = false;
|
|
}, 1000);
|
|
}
|
|
else {
|
|
openEdit();
|
|
hasFirst = false;
|
|
}
|
|
};
|
|
var openEdit = function () {
|
|
text.style.display = 'none';
|
|
inputContainer.style.display = 'flex';
|
|
input.focus();
|
|
input.setSelectionRange(input.value.length, input.value.length);
|
|
var initValue = input.value;
|
|
var close = function () {
|
|
window.removeEventListener('click', onclick);
|
|
component.callEvent('valueUpdated', rowId, column.uniqueIdentifier, !asNumber ? input.value : parseFloat(input.value));
|
|
text.innerText = input.value;
|
|
text.style.display = 'flex';
|
|
inputContainer.style.display = 'none';
|
|
};
|
|
input.onkeydown = function (e) {
|
|
if (e.key == 'Enter')
|
|
close();
|
|
else if (e.key == 'Escape') {
|
|
input.value = initValue;
|
|
text.innerText = input.value;
|
|
close();
|
|
}
|
|
};
|
|
var onclick = function (e) {
|
|
if (e.target == undefined || e.target != input)
|
|
close();
|
|
};
|
|
setTimeout(function () { return window.addEventListener('click', onclick); }, 100);
|
|
};
|
|
}
|
|
wrapper.appendChild(container);
|
|
// if (cell.materialIcon != undefined) {
|
|
// wrapper.appendChild(
|
|
// ce(
|
|
// 'div',
|
|
// ['mux_text', 'mux_tiny', 'mux_table-subtext'],
|
|
// null,
|
|
// cell.subMaterialSymbol.trim()
|
|
// )
|
|
// );
|
|
// }
|
|
return wrapper;
|
|
};
|
|
return ComponentTable_MaterialSymbol;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_MaterialSymbol.ComponentTable_MaterialSymbol = ComponentTable_MaterialSymbol;
|
|
|
|
return Component_Table_MaterialSymbol;
|
|
}
|
|
|
|
var Component_Table_Number = {};
|
|
|
|
var hasRequiredComponent_Table_Number;
|
|
|
|
function requireComponent_Table_Number () {
|
|
if (hasRequiredComponent_Table_Number) return Component_Table_Number;
|
|
hasRequiredComponent_Table_Number = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Table_Number, "__esModule", { value: true });
|
|
Component_Table_Number.ComponentTable_Number = void 0;
|
|
var Component_Table_Text_1 = requireComponent_Table_Text();
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_Number = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_Number, _super);
|
|
function ComponentTable_Number() {
|
|
var _this = _super.call(this) || this;
|
|
_this._text = new Component_Table_Text_1.ComponentTable_Text(false);
|
|
return _this;
|
|
}
|
|
ComponentTable_Number.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var element = this._text.createElement(cell, rowId, column, component);
|
|
element.classList.add('mux_table-number');
|
|
var input = element.querySelector('input');
|
|
var regex = /^[0-9.]+$/;
|
|
element.addEventListener('input', function () {
|
|
var currentValue = input.value;
|
|
if (!regex.test(currentValue)) {
|
|
input.value = currentValue.slice(0, -1);
|
|
component.callEvent('valueUpdated', rowId, column.uniqueIdentifier, input.value);
|
|
}
|
|
});
|
|
return element;
|
|
};
|
|
return ComponentTable_Number;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_Number.ComponentTable_Number = ComponentTable_Number;
|
|
|
|
return Component_Table_Number;
|
|
}
|
|
|
|
var Component_Table_Select = {};
|
|
|
|
var hasRequiredComponent_Table_Select;
|
|
|
|
function requireComponent_Table_Select () {
|
|
if (hasRequiredComponent_Table_Select) return Component_Table_Select;
|
|
hasRequiredComponent_Table_Select = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
|
__assign = Object.assign || function(t) {
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
s = arguments[i];
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
t[p] = s[p];
|
|
}
|
|
return t;
|
|
};
|
|
return __assign.apply(this, arguments);
|
|
};
|
|
Object.defineProperty(Component_Table_Select, "__esModule", { value: true });
|
|
Component_Table_Select.ComponentTable_Select = void 0;
|
|
var Index_1 = requireIndex();
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_Select = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_Select, _super);
|
|
function ComponentTable_Select() {
|
|
return _super.call(this) || this;
|
|
}
|
|
ComponentTable_Select.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var container = (0, Index_1.ce)('div', 'mux_table-select', { title: cell.tooltip });
|
|
var options = {};
|
|
for (var i = 0; i < column.options.length; i++)
|
|
options[column.options[i].uniqueIdentifier] = column.options[i];
|
|
var setSelected = function (uniqueIdentifier) {
|
|
var _a, _b, _c, _d, _e, _f;
|
|
var selected = (options === null || options === void 0 ? void 0 : options[uniqueIdentifier]) != undefined
|
|
? uniqueIdentifier
|
|
: column.options[0].uniqueIdentifier;
|
|
var selectedTransform = (_a = options === null || options === void 0 ? void 0 : options[selected].materialIconTransform) !== null && _a !== void 0 ? _a : 'unset';
|
|
var option = options === null || options === void 0 ? void 0 : options[selected];
|
|
textSpan.innerText = (_b = option === null || option === void 0 ? void 0 : option.text) !== null && _b !== void 0 ? _b : '';
|
|
iconSpan.innerText = (_d = (_c = options === null || options === void 0 ? void 0 : options[selected]) === null || _c === void 0 ? void 0 : _c.materialIcon) !== null && _d !== void 0 ? _d : '';
|
|
iconSpan.style.transform = selectedTransform !== null && selectedTransform !== void 0 ? selectedTransform : '';
|
|
container.title = "".concat((_f = (_e = options === null || options === void 0 ? void 0 : options[selected]) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : '', " | Click to change");
|
|
};
|
|
var iconSpan = (0, Index_1.ce)('span', 'material-symbols-outlined', null);
|
|
var textSpan = (0, Index_1.ce)('span', ['mux_text', 'mux_small'], null);
|
|
var arrow = (0, Index_1.ce)('span', ['mux_table-select-arrow', 'material-symbols-outlined'], null, 'keyboard_arrow_down');
|
|
container.append(iconSpan, textSpan);
|
|
container.appendChild(arrow);
|
|
setSelected(cell.value);
|
|
container.onclick = function () {
|
|
var bounds = container.getBoundingClientRect();
|
|
var items = column.options.map(function (item) {
|
|
return __assign({ click: function () {
|
|
component.callEvent('valueUpdated', rowId, column.uniqueIdentifier, item.uniqueIdentifier);
|
|
setSelected(item.uniqueIdentifier);
|
|
} }, item);
|
|
});
|
|
new Index_1.MorphComponent.ContextMenu({
|
|
x: bounds.x + bounds.width / 2,
|
|
y: bounds.y + bounds.height,
|
|
items: items,
|
|
});
|
|
};
|
|
return container;
|
|
};
|
|
return ComponentTable_Select;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_Select.ComponentTable_Select = ComponentTable_Select;
|
|
|
|
return Component_Table_Select;
|
|
}
|
|
|
|
var Component_Table_TextSuggestions = {};
|
|
|
|
var hasRequiredComponent_Table_TextSuggestions;
|
|
|
|
function requireComponent_Table_TextSuggestions () {
|
|
if (hasRequiredComponent_Table_TextSuggestions) return Component_Table_TextSuggestions;
|
|
hasRequiredComponent_Table_TextSuggestions = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
|
__assign = Object.assign || function(t) {
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
s = arguments[i];
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
t[p] = s[p];
|
|
}
|
|
return t;
|
|
};
|
|
return __assign.apply(this, arguments);
|
|
};
|
|
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
function step(op) {
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
switch (op[0]) {
|
|
case 0: case 1: t = op; break;
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
default:
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
if (t[2]) _.ops.pop();
|
|
_.trys.pop(); continue;
|
|
}
|
|
op = body.call(thisArg, _);
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
}
|
|
};
|
|
Object.defineProperty(Component_Table_TextSuggestions, "__esModule", { value: true });
|
|
Component_Table_TextSuggestions.ComponentTable_TextSuggestions = void 0;
|
|
var Index_1 = requireIndex();
|
|
var Component_ContextMenu_1 = Component_ContextMenu;
|
|
var Component_Table__base_1 = Component_Table__base;
|
|
var ComponentTable_TextSuggestions = /** @class */ (function (_super) {
|
|
__extends(ComponentTable_TextSuggestions, _super);
|
|
function ComponentTable_TextSuggestions() {
|
|
return _super.call(this) || this;
|
|
}
|
|
ComponentTable_TextSuggestions.prototype.createElement = function (cell, rowId, column, component, asNumber) {
|
|
var _a, _b, _c, _d;
|
|
var wrapper = (0, Index_1.ce)('div', 'mux_table-wrapper');
|
|
var container = (0, Index_1.ce)('div', 'mux_table-textsuggestions');
|
|
var optionTitles = {};
|
|
var optionIds = column.options.map(function (option) {
|
|
optionTitles[option.uniqueIdentifier] = option.text;
|
|
return option.uniqueIdentifier;
|
|
});
|
|
var input = new Index_1.MorphComponent.Input({
|
|
type: 'text',
|
|
value: (_b = optionTitles[String((_a = cell === null || cell === void 0 ? void 0 : cell.value) !== null && _a !== void 0 ? _a : '').trim()]) !== null && _b !== void 0 ? _b : String((_c = cell === null || cell === void 0 ? void 0 : cell.value) !== null && _c !== void 0 ? _c : '').trim(),
|
|
border: 'always',
|
|
});
|
|
input.container.setAttribute('valueId', String((_d = cell === null || cell === void 0 ? void 0 : cell.value) !== null && _d !== void 0 ? _d : '').trim());
|
|
var arrow = (0, Index_1.ce)('span', 'material-symbols-outlined', null, 'arrow_drop_down');
|
|
arrow.onclick = function () {
|
|
input.container.focus();
|
|
showContext();
|
|
};
|
|
input.container.addEventListener('focus', function () {
|
|
var _a;
|
|
input.setValue((_a = input.container.getAttribute('valueId')) !== null && _a !== void 0 ? _a : '');
|
|
});
|
|
input.on('blur', function () {
|
|
var optionTitle = optionTitles[input.container.getAttribute('valueId')];
|
|
if (optionTitle == null) {
|
|
if (input.getValue().length > 0)
|
|
component.callEvent('textSuggestionFailed', rowId, column.uniqueIdentifier);
|
|
input.setValue('');
|
|
input.container.removeAttribute('valueId');
|
|
}
|
|
else {
|
|
input.setValue(optionTitle);
|
|
}
|
|
component.callEvent('valueUpdated', rowId, column.uniqueIdentifier, input.container.getAttribute('valueId'));
|
|
setTimeout(function () {
|
|
context === null || context === void 0 ? void 0 : context.destroy();
|
|
}, 250);
|
|
});
|
|
input.container.addEventListener('keydown', function (e) {
|
|
if (e.key != ' ' || !e.ctrlKey)
|
|
return;
|
|
e.preventDefault();
|
|
showContext();
|
|
});
|
|
input.on('input', function () { return showContext(); });
|
|
var context;
|
|
var showContextTimeout;
|
|
function showContext() {
|
|
return __awaiter(this, arguments, void 0, function (instant) {
|
|
if (instant === void 0) { instant = false; }
|
|
return __generator(this, function (_a) {
|
|
context === null || context === void 0 ? void 0 : context.close('blur');
|
|
if (optionIds.includes(input.getValue())) {
|
|
input.container.setAttribute('valueId', input.getValue());
|
|
return [2 /*return*/];
|
|
}
|
|
input.container.removeAttribute('valueId');
|
|
clearTimeout(showContextTimeout);
|
|
showContextTimeout = setTimeout(function () {
|
|
var _a;
|
|
var firstId;
|
|
var value = ((_a = input.getValue()) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
var options = value.length == 0
|
|
? []
|
|
: column.options
|
|
.map(function (option) {
|
|
var _a, _b;
|
|
var text = ((_a = option === null || option === void 0 ? void 0 : option.text) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
var id = ((_b = option === null || option === void 0 ? void 0 : option.uniqueIdentifier) !== null && _b !== void 0 ? _b : '').toLowerCase();
|
|
return { text: text, id: id, option: option };
|
|
})
|
|
.filter(function (_a) {
|
|
var text = _a.text, id = _a.id; _a.option;
|
|
return (text.includes(value) ||
|
|
id.includes(value));
|
|
})
|
|
.map(function (_a) {
|
|
var text = _a.text, id = _a.id, option = _a.option;
|
|
var score = 1;
|
|
if (text.startsWith(value) ||
|
|
id.startsWith(value))
|
|
score += 1;
|
|
if (text.includes(value) ||
|
|
id.includes(value))
|
|
score += 1;
|
|
if (text == value || id == value)
|
|
score += 1;
|
|
return { score: score, option: option };
|
|
})
|
|
.sort(function (a, b) { return b.score - a.score; })
|
|
.map(function (_a, index) {
|
|
_a.score; var option = _a.option;
|
|
if (index == 0)
|
|
firstId = option.uniqueIdentifier;
|
|
return __assign(__assign({}, option), { click: function () {
|
|
input.setValue(option.text);
|
|
input.container.setAttribute('valueId', option.uniqueIdentifier);
|
|
component.callEvent('valueUpdated', rowId, column.uniqueIdentifier, input.getValue());
|
|
component.callEvent('textSuggestionCompleted');
|
|
} });
|
|
});
|
|
if (options.length == 0)
|
|
return;
|
|
var bounds = input.container.getBoundingClientRect();
|
|
context = new Component_ContextMenu_1.ComponentContextMenu({
|
|
items: options,
|
|
selected: firstId,
|
|
x: bounds.x + bounds.width / 2,
|
|
y: bounds.y + bounds.height,
|
|
});
|
|
}, instant ? 0 : 200);
|
|
return [2 /*return*/];
|
|
});
|
|
});
|
|
}
|
|
container.appendChild(input.container);
|
|
container.appendChild(arrow);
|
|
wrapper.appendChild(container);
|
|
return wrapper;
|
|
};
|
|
return ComponentTable_TextSuggestions;
|
|
}(Component_Table__base_1.ComponentTable_Base));
|
|
Component_Table_TextSuggestions.ComponentTable_TextSuggestions = ComponentTable_TextSuggestions;
|
|
|
|
return Component_Table_TextSuggestions;
|
|
}
|
|
|
|
var hasRequiredComponent_Table;
|
|
|
|
function requireComponent_Table () {
|
|
if (hasRequiredComponent_Table) return Component_Table;
|
|
hasRequiredComponent_Table = 1;
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Table, "__esModule", { value: true });
|
|
Component_Table.ComponentTable = void 0;
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var Component_Table_Button_1 = requireComponent_Table_Button();
|
|
var Component_Table_Duration_1 = requireComponent_Table_Duration();
|
|
var Component_Table_Icons_1 = requireComponent_Table_Icons();
|
|
var Component_Table_MaterialSymbol_1 = requireComponent_Table_MaterialSymbol();
|
|
var Component_Table_Number_1 = requireComponent_Table_Number();
|
|
var Component_Table_Select_1 = requireComponent_Table_Select();
|
|
var Component_Table_Text_1 = requireComponent_Table_Text();
|
|
var Component_Table_TextSuggestions_1 = requireComponent_Table_TextSuggestions();
|
|
var Sortable = SortableExports;
|
|
var ComponentTable = /** @class */ (function (_super) {
|
|
__extends(ComponentTable, _super);
|
|
function ComponentTable(options) {
|
|
var _a, _b;
|
|
var _this_1 = _super.call(this) || this;
|
|
_this_1.columns = [];
|
|
_this_1.rows = [];
|
|
_this_1.hiddenRows = [];
|
|
_this_1.columnMap = {};
|
|
_this_1.highlight = function (uniqueIdentifier, style, scrollIntoView, deselectOther) {
|
|
var _a, _b, _c;
|
|
if (scrollIntoView === void 0) { scrollIntoView = false; }
|
|
if (deselectOther === void 0) { deselectOther = true; }
|
|
var rows = _this_1.table.querySelectorAll('tr');
|
|
var styles = typeof style == 'string' ? [style] : style;
|
|
for (var i = 0; i < rows.length; i++) {
|
|
if (uniqueIdentifier != null &&
|
|
rows[i].getAttribute('uid') == uniqueIdentifier) {
|
|
(_a = rows[i].classList).remove.apply(_a, ['selected', 'active', 'outline'].map(function (st) {
|
|
return "mux_table-row-".concat(st);
|
|
}));
|
|
if (style != 'none') {
|
|
(_b = rows[i].classList).add.apply(_b, styles.map(function (st) {
|
|
return "mux_table-row-".concat(st);
|
|
}));
|
|
if (scrollIntoView)
|
|
rows[i].scrollIntoView({
|
|
block: 'center',
|
|
behavior: 'smooth',
|
|
});
|
|
}
|
|
}
|
|
else if (deselectOther)
|
|
(_c = rows[i].classList).remove.apply(_c, ['selected', 'active', 'outline'].map(function (st) {
|
|
return "mux_table-row-".concat(st);
|
|
}));
|
|
}
|
|
};
|
|
_this_1.container = (0, CE_1.ce)('div', 'mux_table');
|
|
_this_1.columns = (_a = options === null || options === void 0 ? void 0 : options.columns) !== null && _a !== void 0 ? _a : [];
|
|
_this_1.table = (0, CE_1.ce)('table');
|
|
var headerRow = (0, CE_1.ce)('tr');
|
|
_this_1.columns.forEach(function (column) {
|
|
var cell = (0, CE_1.ce)('th', null, { uid: column.uniqueIdentifier });
|
|
_this_1.columnMap[column.uniqueIdentifier] = column;
|
|
if (column.width != undefined)
|
|
cell.style.width = column.width;
|
|
if (column.noLeftBorder == true)
|
|
cell.classList.add('mux_table-noborder');
|
|
if (column.title != undefined) {
|
|
var title = (0, CE_1.ce)('div', ['mux_table-text', 'mux_header', 'mux_small'], null, column.title);
|
|
cell.appendChild(title);
|
|
if (column.headerAlign != undefined)
|
|
title.style.textAlign = column.headerAlign;
|
|
}
|
|
headerRow.appendChild(cell);
|
|
});
|
|
_this_1.table.appendChild(headerRow);
|
|
_this_1.container.appendChild(_this_1.table);
|
|
var _this = _this_1;
|
|
var sortable = new Sortable(_this_1.table, {
|
|
filter: ((_b = options === null || options === void 0 ? void 0 : options.dragableIgnore) !== null && _b !== void 0 ? _b : []).join(', '),
|
|
preventOnFilter: false,
|
|
handle: options === null || options === void 0 ? void 0 : options.dragableHandle,
|
|
ghostClass: 'mux_table-row-dragging',
|
|
onStart: function () {
|
|
_this.table.classList.add('mux_table-dragging');
|
|
_this.callEvent('dragStart');
|
|
},
|
|
onEnd: function (evt) {
|
|
_this.callEvent('dragEnd');
|
|
_this.table.classList.remove('mux_table-dragging');
|
|
_this.callEvent('orderUpdated', _this.getOrder());
|
|
_this.updateRowBackgrounds();
|
|
},
|
|
});
|
|
if (options.dragable != true) {
|
|
sortable.option('disabled', true);
|
|
}
|
|
if (options.rows != undefined) {
|
|
options.rows.forEach(function (row) { return _this_1.addRow(row, true); });
|
|
_this_1.updateRowBackgrounds();
|
|
}
|
|
return _this_1;
|
|
}
|
|
ComponentTable.prototype.getOrder = function () {
|
|
var order = [];
|
|
var rows = this.table.querySelectorAll('tr');
|
|
for (var i = 1; i < rows.length; i++)
|
|
order.push(rows[i].getAttribute('uid'));
|
|
return order;
|
|
};
|
|
ComponentTable.prototype.clear = function () {
|
|
this.rows = [];
|
|
var rows = this.table.querySelectorAll('tr');
|
|
if (rows.length > 1)
|
|
for (var i = 1; i < rows.length; i++)
|
|
rows[i].parentElement.removeChild(rows[i]);
|
|
};
|
|
ComponentTable.prototype.addRows = function (rows) {
|
|
var _this_1 = this;
|
|
rows.forEach(function (row) { return _this_1.addRow(row, true); });
|
|
this.updateRowBackgrounds();
|
|
};
|
|
ComponentTable.prototype.addRow = function (row, silent) {
|
|
if (silent === void 0) { silent = false; }
|
|
return this._createRow(row, null, silent);
|
|
};
|
|
ComponentTable.prototype.insertRow = function (index, row, silent) {
|
|
if (silent === void 0) { silent = false; }
|
|
if (index < 0 || index > this.rows.length)
|
|
return;
|
|
return this._createRow(row, index + 1, silent);
|
|
};
|
|
ComponentTable.prototype._createRow = function (row, insertIndex, silent) {
|
|
var _this_1 = this;
|
|
this.rows.push(row.uniqueIdentifier);
|
|
var rowElement = (0, CE_1.ce)('tr', 'mux_table-row', {
|
|
uid: row.uniqueIdentifier,
|
|
});
|
|
if (!this.hiddenRows.includes(row.uniqueIdentifier))
|
|
rowElement.classList.add('mux_table-row-visible');
|
|
rowElement.onclick = function (e) {
|
|
_this_1.callEvent('click', row.uniqueIdentifier, e);
|
|
};
|
|
if (row.child)
|
|
rowElement.classList.add('mux_table-row-child');
|
|
if (row.highlight != undefined)
|
|
rowElement.classList.add("mux_table-row-".concat(row.highlight));
|
|
this.columns.forEach(function (columnSettings) {
|
|
var cellElement = (0, CE_1.ce)('td', null, {
|
|
uid: columnSettings.uniqueIdentifier,
|
|
});
|
|
if (columnSettings.width != undefined)
|
|
cellElement.style.width = columnSettings.width;
|
|
var handler = columnTypes[columnSettings.type];
|
|
var cell = row.cells[columnSettings.uniqueIdentifier];
|
|
if (cell == undefined)
|
|
return;
|
|
cellElement.appendChild(handler.createElement(cell, row.uniqueIdentifier, columnSettings, _this_1));
|
|
rowElement.appendChild(cellElement);
|
|
});
|
|
if (insertIndex != null) {
|
|
var rows = this.table.querySelectorAll('tr');
|
|
if (insertIndex >= rows.length)
|
|
this.table.appendChild(rowElement);
|
|
else
|
|
this.table.insertBefore(rowElement, rows[insertIndex]);
|
|
}
|
|
else
|
|
this.table.appendChild(rowElement);
|
|
if (!silent)
|
|
this.updateRowBackgrounds();
|
|
};
|
|
ComponentTable.prototype.updateCell = function (rowId, columnId, value) {
|
|
var row = this.table.querySelector("tr[uid=\"".concat(rowId, "\"]"));
|
|
if (row == null)
|
|
return;
|
|
var cell = row.querySelector("td[uid=\"".concat(columnId, "\""));
|
|
if (cell == null)
|
|
return;
|
|
var columnSettings = this.columnMap[columnId];
|
|
var handler = columnTypes[columnSettings.type];
|
|
cell.innerHTML = '';
|
|
cell.appendChild(handler.createElement(value, rowId, columnSettings, this));
|
|
};
|
|
ComponentTable.prototype.setDragable = function (dragable) {
|
|
this.Sortable.option('disabled', !dragable);
|
|
};
|
|
ComponentTable.prototype.updateRowBackgrounds = function () {
|
|
var rows = this.table.querySelectorAll('.mux_table-row-visible');
|
|
var counter = 0;
|
|
var insideChild = false;
|
|
for (var i = 0; i < rows.length; i++) {
|
|
var isChild = rows[i].classList.contains('mux_table-row-child');
|
|
if (insideChild != isChild) {
|
|
insideChild = isChild;
|
|
counter = 0;
|
|
}
|
|
var odd = (counter + 1) % 2 == 0;
|
|
counter++;
|
|
if (odd)
|
|
rows[i].classList.add('mux_table-row-odd');
|
|
else
|
|
rows[i].classList.remove('mux_table-row-odd');
|
|
}
|
|
};
|
|
ComponentTable.extendTypes = function (type, handler) {
|
|
columnTypes[type] = handler;
|
|
};
|
|
return ComponentTable;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_Table.ComponentTable = ComponentTable;
|
|
var columnTypes = {
|
|
text: new Component_Table_Text_1.ComponentTable_Text(true),
|
|
textsuggestions: new Component_Table_TextSuggestions_1.ComponentTable_TextSuggestions(),
|
|
number: new Component_Table_Number_1.ComponentTable_Number(),
|
|
button: new Component_Table_Button_1.ComponentTable_Button(),
|
|
duration: new Component_Table_Duration_1.ComponentTable_Duration(),
|
|
icons: new Component_Table_Icons_1.ComponentTable_Icons(),
|
|
select: new Component_Table_Select_1.ComponentTable_Select(),
|
|
materialSymbol: new Component_Table_MaterialSymbol_1.ComponentTable_MaterialSymbol(),
|
|
};
|
|
|
|
return Component_Table;
|
|
}
|
|
|
|
var Component_Text = {};
|
|
|
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
var extendStatics = function (d, b) {
|
|
extendStatics = Object.setPrototypeOf ||
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
return extendStatics(d, b);
|
|
};
|
|
return function (d, b) {
|
|
if (typeof b !== "function" && b !== null)
|
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
extendStatics(d, b);
|
|
function __() { this.constructor = d; }
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
};
|
|
})();
|
|
Object.defineProperty(Component_Text, "__esModule", { value: true });
|
|
Component_Text.ComponentText = void 0;
|
|
var CE_1 = CE;
|
|
var baseComponent_1 = baseComponent;
|
|
var ComponentText = /** @class */ (function (_super) {
|
|
__extends(ComponentText, _super);
|
|
function ComponentText(options) {
|
|
var _a;
|
|
var _this = _super.call(this) || this;
|
|
var size = (_a = options === null || options === void 0 ? void 0 : options.size) !== null && _a !== void 0 ? _a : 'normal';
|
|
_this.container = (0, CE_1.ce)('div', ['mux_text', "mux_".concat(size)], null, options === null || options === void 0 ? void 0 : options.content);
|
|
return _this;
|
|
}
|
|
ComponentText.prototype.update = function (content) {
|
|
this.container.innerHTML = content;
|
|
};
|
|
return ComponentText;
|
|
}(baseComponent_1.MUXComponent));
|
|
Component_Text.ComponentText = ComponentText;
|
|
|
|
var hasRequiredMorph_Components;
|
|
|
|
function requireMorph_Components () {
|
|
if (hasRequiredMorph_Components) return Morph_Components;
|
|
hasRequiredMorph_Components = 1;
|
|
Object.defineProperty(Morph_Components, "__esModule", { value: true });
|
|
Morph_Components.MorphComponent = void 0;
|
|
var Component_Button_1 = Component_Button;
|
|
var Component_Cards_1 = Component_Cards;
|
|
var Component_ContextMenu_1 = Component_ContextMenu;
|
|
var Component_Dialog_1 = requireComponent_Dialog();
|
|
var Component_Group_1 = Component_Group;
|
|
var Component_Header_1 = Component_Header;
|
|
var Component_IconGrid_1 = Component_IconGrid;
|
|
var Component_ImageViewer_1 = requireComponent_ImageViewer();
|
|
var Component_Input_1 = Component_Input;
|
|
var Component_List_1 = requireComponent_List();
|
|
var Component_MenuBar_1 = requireComponent_MenuBar();
|
|
var Component_PaletteCheckbox_1 = requireComponent_PaletteCheckbox();
|
|
var Component_PaletteSearch_1 = requireComponent_PaletteSearch();
|
|
var Component_Resizer_1 = Component_Resizer;
|
|
var Component_Row_1 = Component_Row;
|
|
var Component_Select_1 = requireComponent_Select();
|
|
var Component_Table_1 = requireComponent_Table();
|
|
var Component_Text_1 = Component_Text;
|
|
Morph_Components.MorphComponent = {
|
|
Header: Component_Header_1.ComponentHeader,
|
|
Text: Component_Text_1.ComponentText,
|
|
Button: Component_Button_1.ComponentButton,
|
|
Input: Component_Input_1.ComponentInput,
|
|
Select: Component_Select_1.ComponentSelect,
|
|
Group: Component_Group_1.ComponentGroup,
|
|
List: Component_List_1.ComponentList,
|
|
Cards: Component_Cards_1.ComponentCards,
|
|
IconGrid: Component_IconGrid_1.ComponentIconGrid,
|
|
Table: Component_Table_1.ComponentTable,
|
|
Row: Component_Row_1.ComponentRow,
|
|
Dialog: Component_Dialog_1.ComponentDialog,
|
|
PaletteSearch: Component_PaletteSearch_1.ComponentPaletteSearch,
|
|
PaletteCheckbox: Component_PaletteCheckbox_1.ComponentPaletteCheckbox,
|
|
ImageViewer: Component_ImageViewer_1.ComponentImageViewer,
|
|
MenuBar: Component_MenuBar_1.ComponentMenuBar,
|
|
ContextMenu: Component_ContextMenu_1.ComponentContextMenu,
|
|
Resizer: Component_Resizer_1.ComponentResizer,
|
|
extend: function (name, component) {
|
|
this[name] = component;
|
|
},
|
|
};
|
|
|
|
return Morph_Components;
|
|
}
|
|
|
|
var Morph_Features = {};
|
|
|
|
var Feature_Alert = {};
|
|
|
|
var hasRequiredFeature_Alert;
|
|
|
|
function requireFeature_Alert () {
|
|
if (hasRequiredFeature_Alert) return Feature_Alert;
|
|
hasRequiredFeature_Alert = 1;
|
|
Object.defineProperty(Feature_Alert, "__esModule", { value: true });
|
|
Feature_Alert.FeatureAlert = void 0;
|
|
var Index_1 = requireIndex();
|
|
function FeatureAlert(options, callback) {
|
|
return new Promise(function (resolve) {
|
|
var _a;
|
|
var dialog = new Index_1.MorphComponent.Dialog({
|
|
title: (_a = options === null || options === void 0 ? void 0 : options.title) !== null && _a !== void 0 ? _a : 'Alert',
|
|
width: 'small',
|
|
height: 'auto',
|
|
cancelButtonVisible: false,
|
|
});
|
|
dialog.content.appendChild((0, Index_1.ce)('div', 'mux_text', null, options.message));
|
|
var res = function () {
|
|
if (typeof callback == 'function')
|
|
callback();
|
|
resolve();
|
|
};
|
|
dialog.on('close', function () { return res(); });
|
|
dialog.on('ok', function () { return res(); });
|
|
});
|
|
}
|
|
Feature_Alert.FeatureAlert = FeatureAlert;
|
|
|
|
return Feature_Alert;
|
|
}
|
|
|
|
var Feature_Confirm = {};
|
|
|
|
var hasRequiredFeature_Confirm;
|
|
|
|
function requireFeature_Confirm () {
|
|
if (hasRequiredFeature_Confirm) return Feature_Confirm;
|
|
hasRequiredFeature_Confirm = 1;
|
|
Object.defineProperty(Feature_Confirm, "__esModule", { value: true });
|
|
Feature_Confirm.FeatureConfirm = void 0;
|
|
var Index_1 = requireIndex();
|
|
function FeatureConfirm(options, callback) {
|
|
return new Promise(function (resolve) {
|
|
var _a;
|
|
var dialog = new Index_1.MorphComponent.Dialog({
|
|
title: (_a = options === null || options === void 0 ? void 0 : options.title) !== null && _a !== void 0 ? _a : 'Confirm',
|
|
width: 'small',
|
|
height: 'auto',
|
|
});
|
|
dialog.content.appendChild((0, Index_1.ce)('div', 'mux_text', null, options.message));
|
|
var res = function (state) {
|
|
if (typeof callback == 'function')
|
|
callback(state);
|
|
resolve(state);
|
|
};
|
|
dialog.on('close', function () { return res(null); });
|
|
dialog.on('cancel', function () { return res(false); });
|
|
dialog.on('ok', function () { return res(true); });
|
|
});
|
|
}
|
|
Feature_Confirm.FeatureConfirm = FeatureConfirm;
|
|
|
|
return Feature_Confirm;
|
|
}
|
|
|
|
var Feature_Loader = {};
|
|
|
|
var hasRequiredFeature_Loader;
|
|
|
|
function requireFeature_Loader () {
|
|
if (hasRequiredFeature_Loader) return Feature_Loader;
|
|
hasRequiredFeature_Loader = 1;
|
|
Object.defineProperty(Feature_Loader, "__esModule", { value: true });
|
|
Feature_Loader.FeatureLoader = void 0;
|
|
var Index_1 = requireIndex();
|
|
function FeatureLoader(options) {
|
|
var _a, _b;
|
|
var active = (_a = options === null || options === void 0 ? void 0 : options.active) !== null && _a !== void 0 ? _a : false;
|
|
var message = (_b = options === null || options === void 0 ? void 0 : options.message) !== null && _b !== void 0 ? _b : '';
|
|
var progress = options === null || options === void 0 ? void 0 : options.progress;
|
|
if (active == true)
|
|
showLoader(message, progress);
|
|
else
|
|
removeExisting();
|
|
}
|
|
Feature_Loader.FeatureLoader = FeatureLoader;
|
|
function showLoader(message, progress) {
|
|
var loader = document.querySelector('.mux_loader');
|
|
if (loader == null) {
|
|
loader = (0, Index_1.ce)('div', 'mux_loader');
|
|
loader.appendChild((0, Index_1.ce)('span', 'material-symbols-outlined', null, 'circle'));
|
|
document.body.appendChild(loader);
|
|
}
|
|
var existingProgress = loader.querySelector('.mux_loader-progress');
|
|
if (progress == null) {
|
|
if (existingProgress != null)
|
|
existingProgress.remove();
|
|
}
|
|
else {
|
|
if (existingProgress != null) {
|
|
existingProgress.style.setProperty('--progress', "".concat(progress, "%"));
|
|
existingProgress.querySelector('.mux_loader-progress-label').innerText = "".concat(Math.round(progress), "%");
|
|
}
|
|
else {
|
|
var progressBar = (0, Index_1.ce)('div', 'mux_loader-progress');
|
|
progressBar.style.setProperty('--progress', "".concat(progress, "%"));
|
|
var value = (0, Index_1.ce)('div', 'mux_loader-progress-value');
|
|
value.appendChild((0, Index_1.ce)('div', 'mux_loader-progress-label', null, "".concat(Math.round(progress), "%")));
|
|
progressBar.appendChild(value);
|
|
loader.appendChild(progressBar);
|
|
}
|
|
}
|
|
var existingText = loader.querySelector('.mux_loader-message');
|
|
if (message.trim().length == 0) {
|
|
if (existingText != null)
|
|
existingText.remove();
|
|
}
|
|
else {
|
|
if (existingText != null)
|
|
existingText.innerText = message;
|
|
else {
|
|
if (loader.querySelector('.mux_loader-progress') != null)
|
|
loader.insertBefore((0, Index_1.ce)('div', ['mux_text', 'mux_loader-message'], null, message), loader.querySelector('.mux_loader-progress'));
|
|
else
|
|
loader.appendChild((0, Index_1.ce)('div', ['mux_text', 'mux_loader-message'], null, message));
|
|
}
|
|
}
|
|
}
|
|
function removeExisting() {
|
|
var existing = document.querySelector('.mux_loader');
|
|
if (existing != null)
|
|
existing.remove();
|
|
}
|
|
|
|
return Feature_Loader;
|
|
}
|
|
|
|
var Feature_Notification = {};
|
|
|
|
var hasRequiredFeature_Notification;
|
|
|
|
function requireFeature_Notification () {
|
|
if (hasRequiredFeature_Notification) return Feature_Notification;
|
|
hasRequiredFeature_Notification = 1;
|
|
Object.defineProperty(Feature_Notification, "__esModule", { value: true });
|
|
Feature_Notification.FeatureNotification = void 0;
|
|
var Index_1 = requireIndex();
|
|
var NotificationHandler = new (/** @class */ (function () {
|
|
function class_1() {
|
|
var _this = this;
|
|
window.addEventListener('DOMContentLoaded', function () { return _this.prepare(); });
|
|
}
|
|
class_1.prototype.prepare = function () {
|
|
this.container = (0, Index_1.ce)('div', 'mux_notifications');
|
|
document.body.appendChild(this.container);
|
|
};
|
|
class_1.prototype.append = function (notification) {
|
|
var _a, _b, _c;
|
|
var element = (0, Index_1.ce)('div', 'mux_notification');
|
|
element.classList.add('mux_notification-' + notification.level);
|
|
var icon = (0, Index_1.ce)('span', ['material-symbols-outlined', 'mux_notification-icon'], null, {
|
|
info: 'exclamation',
|
|
warning: 'exclamation',
|
|
error: 'close',
|
|
success: 'check',
|
|
}[(_a = notification.level) !== null && _a !== void 0 ? _a : 'info']);
|
|
if (notification.level == 'info')
|
|
icon.style.transform = 'rotate(180deg)';
|
|
element.appendChild(icon);
|
|
element.appendChild((0, Index_1.ce)('div', 'mux_text', null, notification.message));
|
|
if ((notification === null || notification === void 0 ? void 0 : notification.action) != null) {
|
|
var action = (0, Index_1.ce)('span', ['material-symbols-outlined', 'mux_notification-action'], null, notification.action.materialIcon);
|
|
action.onclick = function () {
|
|
notification.action.click();
|
|
clearTimeout(hideTimeout);
|
|
closeNotification();
|
|
};
|
|
element.appendChild(action);
|
|
}
|
|
if ((_b = notification === null || notification === void 0 ? void 0 : notification.closeable) !== null && _b !== void 0 ? _b : true) {
|
|
element.onclick = function () {
|
|
closeNotification();
|
|
};
|
|
}
|
|
this.container.prepend(element);
|
|
var openNotification = function () {
|
|
element.style.opacity = '1';
|
|
element.style.transform = 'translateX(0px)';
|
|
};
|
|
var closeNotification = function () {
|
|
clearTimeout(hideTimeout);
|
|
element.style.marginTop = "-".concat(element.clientHeight + 6, "px");
|
|
element.style.opacity = '0';
|
|
element.style.transform = 'translateX(100%)';
|
|
element.style.pointerEvents = 'none';
|
|
element.ontransitionend = function () { return element.remove(); };
|
|
};
|
|
setTimeout(function () { return openNotification(); }, 100);
|
|
var hideTimeout = setTimeout(function () { return closeNotification(); }, ((_c = notification === null || notification === void 0 ? void 0 : notification.seconds) !== null && _c !== void 0 ? _c : 10) * 1000);
|
|
return new NotificationInstance(closeNotification);
|
|
};
|
|
return class_1;
|
|
}()))();
|
|
var NotificationInstance = /** @class */ (function () {
|
|
function NotificationInstance(close) {
|
|
this._close = close;
|
|
}
|
|
NotificationInstance.prototype.close = function () {
|
|
this._close();
|
|
};
|
|
return NotificationInstance;
|
|
}());
|
|
function FeatureNotification(notification) {
|
|
var _a;
|
|
if (((_a = notification === null || notification === void 0 ? void 0 : notification.message) !== null && _a !== void 0 ? _a : '').trim().length == 0)
|
|
return;
|
|
return NotificationHandler.append(notification);
|
|
}
|
|
Feature_Notification.FeatureNotification = FeatureNotification;
|
|
|
|
return Feature_Notification;
|
|
}
|
|
|
|
var Feature_Prompt = {};
|
|
|
|
var hasRequiredFeature_Prompt;
|
|
|
|
function requireFeature_Prompt () {
|
|
if (hasRequiredFeature_Prompt) return Feature_Prompt;
|
|
hasRequiredFeature_Prompt = 1;
|
|
Object.defineProperty(Feature_Prompt, "__esModule", { value: true });
|
|
Feature_Prompt.FeaturePrompt = void 0;
|
|
var Index_1 = requireIndex();
|
|
function FeaturePrompt(options, callback) {
|
|
return new Promise(function (resolve) {
|
|
var _a, _b, _c, _d;
|
|
var dialog = new Index_1.MorphComponent.Dialog({
|
|
title: (_a = options === null || options === void 0 ? void 0 : options.title) !== null && _a !== void 0 ? _a : 'Prompt',
|
|
width: 'small',
|
|
height: 'auto',
|
|
});
|
|
dialog.content.appendChild((0, Index_1.ce)('div', 'mux_text', null, options.message));
|
|
var input = new Index_1.MorphComponent.Input({
|
|
type: (_b = options.type) !== null && _b !== void 0 ? _b : 'text',
|
|
value: (_c = options.default) !== null && _c !== void 0 ? _c : '',
|
|
placeholder: (_d = options.placeholder) !== null && _d !== void 0 ? _d : '',
|
|
border: 'always',
|
|
});
|
|
input.container.style.margin = 'var(--mux-edge-offset-tiny) 0px';
|
|
input.container.onfocus = function () {
|
|
errorMessage.style.height = '0px';
|
|
};
|
|
dialog.content.appendChild(input.container);
|
|
var errorMessage = (0, Index_1.ce)('div', ['mux_text', 'mux_small'], null, 'Value can not be empty!');
|
|
errorMessage.style.height = '0px';
|
|
errorMessage.style.transitionDuration =
|
|
'var(--mux-transition-animation)';
|
|
errorMessage.style.overflow = 'hidden';
|
|
errorMessage.style.color = 'var(--mux-color-red)';
|
|
dialog.content.appendChild(errorMessage);
|
|
var res = function (value) {
|
|
if (typeof callback == 'function')
|
|
callback(value);
|
|
resolve(value);
|
|
};
|
|
dialog.on('close', function () { return res(null); });
|
|
dialog.on('cancel', function () { return res(null); });
|
|
dialog.on('ok', function (closeEvent) {
|
|
if (!options.canBeEmpty && input.getValue().trim() == '') {
|
|
errorMessage.style.height = '14px';
|
|
return closeEvent.preventClose();
|
|
}
|
|
res(input.getValue());
|
|
});
|
|
input.container.focus();
|
|
});
|
|
}
|
|
Feature_Prompt.FeaturePrompt = FeaturePrompt;
|
|
|
|
return Feature_Prompt;
|
|
}
|
|
|
|
var hasRequiredMorph_Features;
|
|
|
|
function requireMorph_Features () {
|
|
if (hasRequiredMorph_Features) return Morph_Features;
|
|
hasRequiredMorph_Features = 1;
|
|
Object.defineProperty(Morph_Features, "__esModule", { value: true });
|
|
Morph_Features.MorphFeature = void 0;
|
|
var Feature_Alert_1 = requireFeature_Alert();
|
|
var Feature_Confirm_1 = requireFeature_Confirm();
|
|
var Feature_Loader_1 = requireFeature_Loader();
|
|
var Feature_Notification_1 = requireFeature_Notification();
|
|
var Feature_Prompt_1 = requireFeature_Prompt();
|
|
Morph_Features.MorphFeature = {
|
|
Confirm: Feature_Confirm_1.FeatureConfirm,
|
|
Alert: Feature_Alert_1.FeatureAlert,
|
|
Prompt: Feature_Prompt_1.FeaturePrompt,
|
|
Notification: Feature_Notification_1.FeatureNotification,
|
|
Loader: Feature_Loader_1.FeatureLoader,
|
|
extend: function (name, component) {
|
|
this[name] = component;
|
|
},
|
|
};
|
|
|
|
return Morph_Features;
|
|
}
|
|
|
|
var Morph_Utils = {};
|
|
|
|
var clone$1 = {};
|
|
|
|
Object.defineProperty(clone$1, "__esModule", { value: true });
|
|
clone$1.clone = void 0;
|
|
function clone(object) {
|
|
if (typeof object !== 'object')
|
|
return object;
|
|
return JSON.parse(JSON.stringify(object !== null && object !== void 0 ? object : {}));
|
|
}
|
|
clone$1.clone = clone;
|
|
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ce = exports.clone = void 0;
|
|
var clone_1 = clone$1;
|
|
Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return clone_1.clone; } });
|
|
var CE_1 = CE;
|
|
Object.defineProperty(exports, "ce", { enumerable: true, get: function () { return CE_1.ce; } });
|
|
|
|
} (Morph_Utils));
|
|
|
|
var hasRequiredIndex;
|
|
|
|
function requireIndex () {
|
|
if (hasRequiredIndex) return Index;
|
|
hasRequiredIndex = 1;
|
|
(function (exports) {
|
|
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
|
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.MUXComponent = void 0;
|
|
var version = require$$0$1.version;
|
|
if (window._MorphUXInitialized === undefined) {
|
|
console.log('MorphUX Loaded');
|
|
console.log("Version ".concat(version));
|
|
window._MorphUXInitialized = true;
|
|
}
|
|
__exportStar(requireMorph_Components(), exports);
|
|
__exportStar(requireMorph_Features(), exports);
|
|
__exportStar(Morph_Keys, exports);
|
|
__exportStar(Morph_Utils, exports);
|
|
var baseComponent_1 = baseComponent;
|
|
Object.defineProperty(exports, "MUXComponent", { enumerable: true, get: function () { return baseComponent_1.MUXComponent; } });
|
|
|
|
} (Index));
|
|
return Index;
|
|
}
|
|
|
|
var __awaiter$4 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __generator$4 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
function step(op) {
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
switch (op[0]) {
|
|
case 0: case 1: t = op; break;
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
default:
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
if (t[2]) _.ops.pop();
|
|
_.trys.pop(); continue;
|
|
}
|
|
op = body.call(thisArg, _);
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
}
|
|
};
|
|
Object.defineProperty(menuBar, "__esModule", { value: true });
|
|
menuBar.MenuBar = void 0;
|
|
var morphux_1$5 = requireIndex();
|
|
var Component_MenuBar_1 = requireComponent_MenuBar();
|
|
var MenuBar = /** @class */ (function () {
|
|
function MenuBar(main) {
|
|
var _this = this;
|
|
this.container = document.querySelector('.ntsh_menubar');
|
|
this._Main = main;
|
|
this.build();
|
|
this._Main.socket.on('supportNumber', function (number) {
|
|
_this.supportNumber = number;
|
|
});
|
|
setTimeout(function () {
|
|
if ((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem('serviceMode')) === 'true')
|
|
_this.toggleServiceMode(true, true);
|
|
}, 10);
|
|
}
|
|
MenuBar.prototype.build = function () {
|
|
var _this = this;
|
|
this.menubar = new Component_MenuBar_1.ComponentMenuBar({
|
|
mobile: {
|
|
left: [
|
|
{
|
|
type: 'icon',
|
|
text: 'Restart',
|
|
materialIcon: 'restart_alt',
|
|
uniqueIdentifier: 'restart_installation',
|
|
click: function () { return __awaiter$4(_this, void 0, void 0, function () {
|
|
var mobileMenu;
|
|
return __generator$4(this, function (_a) {
|
|
mobileMenu = document.querySelector('.mux_mobilemenu');
|
|
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click();
|
|
this.restartInstallation();
|
|
return [2 /*return*/];
|
|
});
|
|
}); },
|
|
},
|
|
// {
|
|
// type: 'icon',
|
|
// text: 'Shutdown',
|
|
// materialIcon: 'power_settings_new',
|
|
// uniqueIdentifier: 'shutdown_installation',
|
|
// click: async () => {
|
|
// const mobileMenu: HTMLDivElement =
|
|
// document.querySelector('.mux_mobilemenu');
|
|
// mobileMenu?.click();
|
|
// this.shutdownInstallation();
|
|
// },
|
|
// },
|
|
],
|
|
right: [
|
|
{
|
|
type: 'icon',
|
|
text: 'Support',
|
|
materialIcon: 'call_quality',
|
|
uniqueIdentifier: 'call_support',
|
|
click: function () { return _this.showSupport(); },
|
|
},
|
|
],
|
|
},
|
|
left: [
|
|
{
|
|
type: 'normal',
|
|
text: 'Restart',
|
|
materialIcon: 'restart_alt',
|
|
uniqueIdentifier: 'restart_installation',
|
|
click: function () { return __awaiter$4(_this, void 0, void 0, function () {
|
|
var mobileMenu;
|
|
return __generator$4(this, function (_a) {
|
|
mobileMenu = document.querySelector('.mux_mobilemenu');
|
|
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click();
|
|
this.restartInstallation();
|
|
return [2 /*return*/];
|
|
});
|
|
}); },
|
|
},
|
|
// {
|
|
// type: 'normal',
|
|
// text: 'Shutdown',
|
|
// materialIcon: 'power_settings_new',
|
|
// uniqueIdentifier: 'shutdown_installation',
|
|
// click: async () => {
|
|
// const mobileMenu: HTMLDivElement =
|
|
// document.querySelector('.mux_mobilemenu');
|
|
// mobileMenu?.click();
|
|
// this.shutdownInstallation();
|
|
// },
|
|
// },
|
|
{
|
|
type: 'normal',
|
|
text: 'Dashboard',
|
|
materialIcon: 'dashboard',
|
|
uniqueIdentifier: 'dashboard',
|
|
selected: true,
|
|
click: function () { return _this._Main.TabController.showTab('dashboard'); },
|
|
},
|
|
{
|
|
type: 'normal',
|
|
text: 'Calibration',
|
|
uniqueIdentifier: 'calibration',
|
|
materialIcon: 'crop_free',
|
|
click: function () {
|
|
return _this._Main.TabController.showTab('calibration');
|
|
},
|
|
},
|
|
{
|
|
type: 'normal',
|
|
text: 'Unity Logs',
|
|
uniqueIdentifier: 'unitylogs',
|
|
materialIcon: 'deployed_code',
|
|
click: function () { return _this._Main.TabController.showTab('unitylogs'); },
|
|
},
|
|
{
|
|
type: 'normal',
|
|
text: 'Camera Logs',
|
|
uniqueIdentifier: 'cameralogs',
|
|
materialIcon: 'photo_camera',
|
|
click: function () { return _this._Main.TabController.showTab('cameralogs'); },
|
|
},
|
|
],
|
|
right: [
|
|
{
|
|
type: 'icon',
|
|
text: 'Support',
|
|
materialIcon: 'call_quality',
|
|
uniqueIdentifier: 'call_support',
|
|
click: function () { return _this.showSupport(); },
|
|
},
|
|
{
|
|
type: document.body.classList.contains('ntsh_service')
|
|
? 'normal'
|
|
: 'icon',
|
|
text: document.body.classList.contains('ntsh_service')
|
|
? 'Exit Service'
|
|
: 'Service Mode',
|
|
uniqueIdentifier: 'serviceMode',
|
|
materialIcon: document.body.classList.contains('ntsh_service')
|
|
? 'logout'
|
|
: 'engineering',
|
|
click: function () { return __awaiter$4(_this, void 0, void 0, function () {
|
|
var mobileMenu;
|
|
return __generator$4(this, function (_a) {
|
|
mobileMenu = document.querySelector('.mux_mobilemenu');
|
|
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click();
|
|
this.toggleServiceMode();
|
|
return [2 /*return*/];
|
|
});
|
|
}); },
|
|
},
|
|
],
|
|
});
|
|
this.container.innerHTML = '';
|
|
this.container.appendChild(this.menubar.container);
|
|
};
|
|
MenuBar.prototype.showSupport = function () {
|
|
return __awaiter$4(this, void 0, void 0, function () {
|
|
var dialog, callAnchor;
|
|
return __generator$4(this, function (_a) {
|
|
dialog = new morphux_1$5.MorphComponent.Dialog({
|
|
title: 'Contact Support',
|
|
width: 'medium',
|
|
height: 'auto',
|
|
okButtonVisible: false,
|
|
cancelButtonVisible: false,
|
|
});
|
|
this.supportNumber.slice();
|
|
callAnchor = (0, morphux_1$5.ce)('a', 'ntsh_callanchor', { href: "tel:".concat(this.supportNumber) }, "+".concat(this.supportNumber));
|
|
dialog.content.appendChild(callAnchor);
|
|
setTimeout(function () { return callAnchor.click(); }, 100);
|
|
return [2 /*return*/];
|
|
});
|
|
});
|
|
};
|
|
MenuBar.prototype.restartInstallation = function () {
|
|
return __awaiter$4(this, void 0, void 0, function () {
|
|
var confirmed;
|
|
return __generator$4(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0: return [4 /*yield*/, morphux_1$5.MorphFeature.Confirm({
|
|
title: 'Restart Installation',
|
|
message: 'Are you sure you want to restart the installation?',
|
|
})];
|
|
case 1:
|
|
confirmed = _a.sent();
|
|
if (!confirmed)
|
|
return [2 /*return*/];
|
|
morphux_1$5.MorphFeature.Loader({
|
|
active: true,
|
|
message: 'Restarting installation...',
|
|
});
|
|
this._Main.socket.emit('restartInstallation', function (response) {
|
|
morphux_1$5.MorphFeature.Loader({ active: false });
|
|
if (!response.succeed)
|
|
return morphux_1$5.MorphFeature.Alert({
|
|
title: 'Error',
|
|
message: response.message,
|
|
});
|
|
});
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
MenuBar.prototype.shutdownInstallation = function () {
|
|
return __awaiter$4(this, void 0, void 0, function () {
|
|
var confirmed, shutdownContainer;
|
|
return __generator$4(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0: return [4 /*yield*/, morphux_1$5.MorphFeature.Confirm({
|
|
title: 'Shutdown Installation',
|
|
message: 'Are you sure you want to shutdown the installation?',
|
|
})];
|
|
case 1:
|
|
confirmed = _a.sent();
|
|
if (!confirmed)
|
|
return [2 /*return*/];
|
|
morphux_1$5.MorphFeature.Loader({
|
|
active: true,
|
|
message: 'Shutting down installation...',
|
|
});
|
|
shutdownContainer = document.querySelector('.ntsh_shutdown');
|
|
this._Main.socket.emit('shutdownInstallation', function (response) {
|
|
morphux_1$5.MorphFeature.Loader({ active: false });
|
|
if (!response.succeed)
|
|
return morphux_1$5.MorphFeature.Alert({
|
|
title: 'Error',
|
|
message: response.message,
|
|
});
|
|
shutdownContainer.style.display = 'flex';
|
|
});
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
MenuBar.prototype.toggleServiceMode = function (mode, skipPin) {
|
|
return __awaiter$4(this, void 0, void 0, function () {
|
|
var newMode, servicePin;
|
|
return __generator$4(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
newMode = mode !== null && mode !== void 0 ? mode : !document.body.classList.contains('ntsh_service');
|
|
if (!newMode) return [3 /*break*/, 3];
|
|
if (!(skipPin !== true)) return [3 /*break*/, 2];
|
|
return [4 /*yield*/, morphux_1$5.MorphFeature.Prompt({
|
|
title: 'Service Mode',
|
|
message: 'Enter the service PIN:',
|
|
type: 'number',
|
|
canBeEmpty: false,
|
|
placeholder: '****',
|
|
})];
|
|
case 1:
|
|
servicePin = _a.sent();
|
|
if (servicePin !== '4252') {
|
|
morphux_1$5.MorphFeature.Alert({
|
|
title: 'Error',
|
|
message: 'Incorrect PIN provided.',
|
|
});
|
|
return [2 /*return*/, false];
|
|
}
|
|
_a.label = 2;
|
|
case 2:
|
|
document.body.classList.add('ntsh_service');
|
|
localStorage.setItem('serviceMode', 'true');
|
|
morphux_1$5.MorphFeature.Notification({
|
|
level: 'success',
|
|
message: 'Service mode activated.',
|
|
});
|
|
return [3 /*break*/, 4];
|
|
case 3:
|
|
document.body.classList.remove('ntsh_service');
|
|
this._Main.TabController.showTab('dashboard');
|
|
localStorage.setItem('serviceMode', 'false');
|
|
morphux_1$5.MorphFeature.Notification({
|
|
level: 'success',
|
|
message: 'Service mode deactivated.',
|
|
});
|
|
_a.label = 4;
|
|
case 4:
|
|
this.build();
|
|
return [2 /*return*/, true];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
return MenuBar;
|
|
}());
|
|
menuBar.MenuBar = MenuBar;
|
|
|
|
var tabController = {};
|
|
|
|
var __awaiter$3 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __generator$3 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
function step(op) {
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
switch (op[0]) {
|
|
case 0: case 1: t = op; break;
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
default:
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
if (t[2]) _.ops.pop();
|
|
_.trys.pop(); continue;
|
|
}
|
|
op = body.call(thisArg, _);
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
}
|
|
};
|
|
Object.defineProperty(tabController, "__esModule", { value: true });
|
|
tabController.TabController = void 0;
|
|
var morphux_1$4 = requireIndex();
|
|
var TabController = /** @class */ (function () {
|
|
function TabController(main) {
|
|
this.container = document.querySelector('.ntsh_tabs');
|
|
this.tabListeners = new Map();
|
|
this._Main = main;
|
|
this.registerNavigationListener();
|
|
}
|
|
TabController.prototype.registerListener = function (tabId, callback) {
|
|
if (this.tabListeners.has(tabId))
|
|
throw new Error("Listener for tab id ".concat(tabId, " has already been registered!"));
|
|
this.tabListeners.set(tabId, callback);
|
|
callback(this.currentTabId == tabId);
|
|
};
|
|
TabController.prototype.showTab = function (tabId) {
|
|
return __awaiter$3(this, void 0, void 0, function () {
|
|
var confirmed, succeed, tabName;
|
|
return __generator$3(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
if (this.currentTabId == tabId)
|
|
return [2 /*return*/];
|
|
if (!(tabId !== 'dashboard' &&
|
|
!document.body.classList.contains('ntsh_service'))) return [3 /*break*/, 3];
|
|
return [4 /*yield*/, morphux_1$4.MorphFeature.Confirm({
|
|
title: 'Service Mode Required',
|
|
message: "You need to be in service mode to access tab ".concat(tabId, ", switch to Service Mode now?"),
|
|
})];
|
|
case 1:
|
|
confirmed = _a.sent();
|
|
if (!confirmed)
|
|
return [2 /*return*/, this.showTab('dashboard')];
|
|
return [4 /*yield*/, this._Main.MenuBar.toggleServiceMode(true)];
|
|
case 2:
|
|
succeed = _a.sent();
|
|
if (!succeed)
|
|
return [2 /*return*/, this.showTab('dashboard')];
|
|
_a.label = 3;
|
|
case 3:
|
|
this._Main.MenuBar.menubar.setSelected(tabId);
|
|
if (this.tabListeners.has(this.currentTabId))
|
|
this.tabListeners.get(this.currentTabId)(false);
|
|
if (this.tabListeners.has(tabId))
|
|
this.tabListeners.get(tabId)(true);
|
|
this.currentTabId = tabId;
|
|
this.container
|
|
.querySelectorAll('.ntsh_tab')
|
|
.forEach(function (tab) { return tab.classList.remove('ntsh_tab-visible'); });
|
|
this.container
|
|
.querySelector(".ntsh_tab[tabid=\"".concat(tabId, "\"]"))
|
|
.classList.add('ntsh_tab-visible');
|
|
window.history.pushState({ tab: tabId }, '', "/".concat(tabId).concat(window.location.search));
|
|
tabName = {
|
|
dashboard: 'Dashboard',
|
|
calibration: 'Calibration',
|
|
cameralogs: 'Camera Logs',
|
|
unitylogs: 'Unity Logs',
|
|
}[tabId];
|
|
document.title = "NTSH Control - ".concat(tabName);
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
TabController.prototype.registerNavigationListener = function () {
|
|
var _this = this;
|
|
window.addEventListener('popstate', function (event) {
|
|
var state = event.state;
|
|
if (state && state.tab)
|
|
_this.showTab(state.tab);
|
|
});
|
|
var startTab = window.location.pathname
|
|
.replace('/', '')
|
|
.split('/')
|
|
.shift();
|
|
this.showTab(startTab.length > 0 ? startTab : 'dashboard');
|
|
};
|
|
return TabController;
|
|
}());
|
|
tabController.TabController = TabController;
|
|
|
|
var dashboard_camerarunner = {};
|
|
|
|
var utils = {};
|
|
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.createProgress = exports.setProgressState = exports.setStatusState = exports.lerp = void 0;
|
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
exports.formatUptime = formatUptime;
|
|
exports.delay = delay;
|
|
var morphux_1 = requireIndex();
|
|
/**
|
|
* A linear interpolation helper function.
|
|
* @param a The start value.
|
|
* @param b The end value.
|
|
* @param t The interpolation factor (0 to 1).
|
|
* @returns The interpolated value.
|
|
*/
|
|
var lerp = function (a, b, t) {
|
|
return a + (b - a) * t;
|
|
};
|
|
exports.lerp = lerp;
|
|
var setStatusState = function (statusElement, state) {
|
|
statusElement.classList.remove('ntsh_status-green', 'ntsh_status-yellow', 'ntsh_status-red', 'ntsh_status-gray');
|
|
statusElement.classList.add("ntsh_status-".concat(state));
|
|
};
|
|
exports.setStatusState = setStatusState;
|
|
var setProgressState = function (progressElement, value, min, max, unit) {
|
|
var percentage = (value - min) / (max - min);
|
|
var progressValue = progressElement.querySelector('.ntsh_progress-value');
|
|
progressValue.style.width = "".concat(percentage * 100, "%");
|
|
var label = progressElement.querySelector('.ntsh_progress-label');
|
|
label.innerText = "".concat(value).concat(unit);
|
|
};
|
|
exports.setProgressState = setProgressState;
|
|
var createProgress = function (value, min, max, unit) {
|
|
var progress = (0, morphux_1.ce)('div', 'ntsh_progress');
|
|
progress.appendChild((0, morphux_1.ce)('div', 'ntsh_progress-value'));
|
|
progress.appendChild((0, morphux_1.ce)('div', 'ntsh_progress-label'));
|
|
(0, exports.setProgressState)(progress, value, min, max, unit);
|
|
return progress;
|
|
};
|
|
exports.createProgress = createProgress;
|
|
function capitalizeFirstLetter(string) {
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
}
|
|
function formatUptime(seconds) {
|
|
if (seconds < 0)
|
|
return '';
|
|
var days = Math.floor(seconds / 86400);
|
|
seconds %= 86400;
|
|
var hours = Math.floor(seconds / 3600);
|
|
seconds %= 3600;
|
|
var minutes = Math.floor(seconds / 60);
|
|
seconds = Math.floor(seconds % 60);
|
|
var parts = [];
|
|
if (days > 0)
|
|
parts.push("".concat(days, "d"));
|
|
parts.push("".concat(hours.toString().padStart(2, '0'), ":").concat(minutes
|
|
.toString()
|
|
.padStart(2, '0'), ":").concat(seconds.toString().padStart(2, '0')));
|
|
return parts.join(' ');
|
|
}
|
|
function delay(duration) {
|
|
return new Promise(function (resolve) { return setTimeout(resolve, duration); });
|
|
}
|
|
|
|
} (utils));
|
|
|
|
var __awaiter$2 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __generator$2 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
function step(op) {
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
switch (op[0]) {
|
|
case 0: case 1: t = op; break;
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
default:
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
if (t[2]) _.ops.pop();
|
|
_.trys.pop(); continue;
|
|
}
|
|
op = body.call(thisArg, _);
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
}
|
|
};
|
|
Object.defineProperty(dashboard_camerarunner, "__esModule", { value: true });
|
|
dashboard_camerarunner.DashboardCameraRunner = void 0;
|
|
var morphux_1$3 = requireIndex();
|
|
var utils_1$1 = utils;
|
|
var DashboardCameraRunner = /** @class */ (function () {
|
|
function DashboardCameraRunner(Main) {
|
|
this.container = document.querySelector('.ntsh_dashboard-camerarunner');
|
|
this.connectionStatus = this.container.querySelector('.ntsh_dashboard-camerarunner-connectionstatus');
|
|
this.connectionInfo = this.container.querySelector('.ntsh_dashboard-camerarunner-connectioninfo');
|
|
this.rebootButton = this.container.querySelector('.ntsh_dashboard-camerarunner-reboot');
|
|
this.processStatus = this.container.querySelector('.ntsh_dashboard-camerarunner-processstatus');
|
|
this.processInfo = this.container.querySelector('.ntsh_dashboard-camerarunner-processinfo');
|
|
this.restartButton = this.container.querySelector('.ntsh_dashboard-camerarunner-restart');
|
|
this.uptimeInfo = this.container.querySelector('.ntsh_dashboard-camerarunner-uptime');
|
|
this.errorContainer = this.container.querySelector('.ntsh_dashboard-camerarunner-error');
|
|
this.errorText = this.container.querySelector('.ntsh_dashboard-camerarunner-errortext');
|
|
this._Main = Main;
|
|
this.registerListeners();
|
|
}
|
|
DashboardCameraRunner.prototype.updateState = function (state) {
|
|
var _a, _b, _c, _d, _e;
|
|
// ----------- Connection -----------
|
|
(0, utils_1$1.setStatusState)(this.connectionStatus, {
|
|
CONNECTING: 'yellow',
|
|
CONNECTED: 'green',
|
|
DISCONNECTED: 'red',
|
|
FAILED: 'red',
|
|
}[state.state]);
|
|
this.connectionInfo.innerText = (_a = state.message) !== null && _a !== void 0 ? _a : '';
|
|
// ----------- Process -----------
|
|
if (state.state != 'CONNECTED') {
|
|
state.processStatus.state = 'STOPPED';
|
|
state.processStatus.message = 'Not connected';
|
|
state.processStatus.startTime = -1;
|
|
this.restartButton.style.display = 'none';
|
|
this.rebootButton.style.display = 'none';
|
|
}
|
|
else {
|
|
this.rebootButton.style.display = 'flex';
|
|
if (state.processStatus.state == 'RUNNING')
|
|
this.restartButton.style.display = 'flex';
|
|
else
|
|
this.restartButton.style.display = 'none';
|
|
}
|
|
(0, utils_1$1.setStatusState)(this.processStatus, {
|
|
RUNNING: 'green',
|
|
STOPPED: 'gray',
|
|
STARTING: 'yellow',
|
|
PROBLEM: 'red',
|
|
}[state.processStatus.state]);
|
|
this.processInfo.innerText = (_b = state.processStatus.message) !== null && _b !== void 0 ? _b : '';
|
|
// ----------- Uptime -----------
|
|
var uptimeSeconds = state.processStatus.startTime == -1
|
|
? -1
|
|
: (Date.now() - state.processStatus.startTime) / 1000;
|
|
this.uptimeInfo.innerText = (0, utils_1$1.formatUptime)(uptimeSeconds);
|
|
// ----------- Error -----------
|
|
var errors = [];
|
|
if (((_c = state === null || state === void 0 ? void 0 : state.error) !== null && _c !== void 0 ? _c : '').trim().length > 0)
|
|
errors.push(state.error);
|
|
if (((_e = (_d = state === null || state === void 0 ? void 0 : state.processStatus) === null || _d === void 0 ? void 0 : _d.error) !== null && _e !== void 0 ? _e : '').trim().length > 0)
|
|
errors.push(state.processStatus.error);
|
|
if (errors.length > 0) {
|
|
this.errorText.innerText = errors.join('\n');
|
|
this.errorContainer.style.display = 'block';
|
|
}
|
|
else {
|
|
this.errorContainer.style.display = 'none';
|
|
this.errorText.innerText = '';
|
|
}
|
|
this._Main.Logs.setCameraLogs(state.processStatus.output.current);
|
|
};
|
|
DashboardCameraRunner.prototype.registerListeners = function () {
|
|
var _this = this;
|
|
this._Main.socket.on('cameraRunnerState', function (state) {
|
|
_this.updateState(state);
|
|
});
|
|
this.restartButton.addEventListener('click', function () { return __awaiter$2(_this, void 0, void 0, function () {
|
|
return __generator$2(this, function (_a) {
|
|
this.executeCommand('restart', 'Are you sure you want to restart the Camera Runner process?');
|
|
return [2 /*return*/];
|
|
});
|
|
}); });
|
|
this.rebootButton.addEventListener('click', function () { return __awaiter$2(_this, void 0, void 0, function () {
|
|
return __generator$2(this, function (_a) {
|
|
this.executeCommand('reboot', 'Are you sure you want to reboot the Camera Runner machine?');
|
|
return [2 /*return*/];
|
|
});
|
|
}); });
|
|
};
|
|
DashboardCameraRunner.prototype.executeCommand = function (command, message) {
|
|
return __awaiter$2(this, void 0, void 0, function () {
|
|
var confirmed;
|
|
return __generator$2(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0: return [4 /*yield*/, morphux_1$3.MorphFeature.Confirm({
|
|
title: 'Are you sure?',
|
|
message: message,
|
|
})];
|
|
case 1:
|
|
confirmed = _a.sent();
|
|
if (!confirmed)
|
|
return [2 /*return*/];
|
|
morphux_1$3.MorphFeature.Loader({
|
|
active: true,
|
|
message: "Requesting Camera Runner ".concat(command, "..."),
|
|
});
|
|
this._Main.socket.emit('cameraRunner', command, function (response) {
|
|
morphux_1$3.MorphFeature.Loader({ active: false });
|
|
if (!response.succeed)
|
|
return morphux_1$3.MorphFeature.Alert({
|
|
title: 'Error',
|
|
message: response.message,
|
|
});
|
|
morphux_1$3.MorphFeature.Notification({
|
|
level: 'success',
|
|
message: "Camera Runner is ".concat(command, "ing..."),
|
|
});
|
|
});
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
return DashboardCameraRunner;
|
|
}());
|
|
dashboard_camerarunner.DashboardCameraRunner = DashboardCameraRunner;
|
|
|
|
var logsHandler = {};
|
|
|
|
var __makeTemplateObject = (undefined && undefined.__makeTemplateObject) || function (cooked, raw) {
|
|
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
return cooked;
|
|
};
|
|
var PacketKind;
|
|
(function (PacketKind) {
|
|
PacketKind[PacketKind["EOS"] = 0] = "EOS";
|
|
PacketKind[PacketKind["Text"] = 1] = "Text";
|
|
PacketKind[PacketKind["Incomplete"] = 2] = "Incomplete";
|
|
PacketKind[PacketKind["ESC"] = 3] = "ESC";
|
|
PacketKind[PacketKind["Unknown"] = 4] = "Unknown";
|
|
PacketKind[PacketKind["SGR"] = 5] = "SGR";
|
|
PacketKind[PacketKind["OSCURL"] = 6] = "OSCURL";
|
|
})(PacketKind || (PacketKind = {}));
|
|
class AnsiUp {
|
|
constructor() {
|
|
this.VERSION = "6.0.6";
|
|
this.setup_palettes();
|
|
this._use_classes = false;
|
|
this.bold = false;
|
|
this.faint = false;
|
|
this.italic = false;
|
|
this.underline = false;
|
|
this.fg = this.bg = null;
|
|
this._buffer = '';
|
|
this._url_allowlist = { 'http': 1, 'https': 1 };
|
|
this._escape_html = true;
|
|
this.boldStyle = 'font-weight:bold';
|
|
this.faintStyle = 'opacity:0.7';
|
|
this.italicStyle = 'font-style:italic';
|
|
this.underlineStyle = 'text-decoration:underline';
|
|
}
|
|
set use_classes(arg) {
|
|
this._use_classes = arg;
|
|
}
|
|
get use_classes() {
|
|
return this._use_classes;
|
|
}
|
|
set url_allowlist(arg) {
|
|
this._url_allowlist = arg;
|
|
}
|
|
get url_allowlist() {
|
|
return this._url_allowlist;
|
|
}
|
|
set escape_html(arg) {
|
|
this._escape_html = arg;
|
|
}
|
|
get escape_html() {
|
|
return this._escape_html;
|
|
}
|
|
set boldStyle(arg) { this._boldStyle = arg; }
|
|
get boldStyle() { return this._boldStyle; }
|
|
set faintStyle(arg) { this._faintStyle = arg; }
|
|
get faintStyle() { return this._faintStyle; }
|
|
set italicStyle(arg) { this._italicStyle = arg; }
|
|
get italicStyle() { return this._italicStyle; }
|
|
set underlineStyle(arg) { this._underlineStyle = arg; }
|
|
get underlineStyle() { return this._underlineStyle; }
|
|
setup_palettes() {
|
|
this.ansi_colors =
|
|
[
|
|
[
|
|
{ rgb: [0, 0, 0], class_name: "ansi-black" },
|
|
{ rgb: [187, 0, 0], class_name: "ansi-red" },
|
|
{ rgb: [0, 187, 0], class_name: "ansi-green" },
|
|
{ rgb: [187, 187, 0], class_name: "ansi-yellow" },
|
|
{ rgb: [0, 0, 187], class_name: "ansi-blue" },
|
|
{ rgb: [187, 0, 187], class_name: "ansi-magenta" },
|
|
{ rgb: [0, 187, 187], class_name: "ansi-cyan" },
|
|
{ rgb: [255, 255, 255], class_name: "ansi-white" }
|
|
],
|
|
[
|
|
{ rgb: [85, 85, 85], class_name: "ansi-bright-black" },
|
|
{ rgb: [255, 85, 85], class_name: "ansi-bright-red" },
|
|
{ rgb: [0, 255, 0], class_name: "ansi-bright-green" },
|
|
{ rgb: [255, 255, 85], class_name: "ansi-bright-yellow" },
|
|
{ rgb: [85, 85, 255], class_name: "ansi-bright-blue" },
|
|
{ rgb: [255, 85, 255], class_name: "ansi-bright-magenta" },
|
|
{ rgb: [85, 255, 255], class_name: "ansi-bright-cyan" },
|
|
{ rgb: [255, 255, 255], class_name: "ansi-bright-white" }
|
|
]
|
|
];
|
|
this.palette_256 = [];
|
|
this.ansi_colors.forEach(palette => {
|
|
palette.forEach(rec => {
|
|
this.palette_256.push(rec);
|
|
});
|
|
});
|
|
let levels = [0, 95, 135, 175, 215, 255];
|
|
for (let r = 0; r < 6; ++r) {
|
|
for (let g = 0; g < 6; ++g) {
|
|
for (let b = 0; b < 6; ++b) {
|
|
let col = { rgb: [levels[r], levels[g], levels[b]], class_name: 'truecolor' };
|
|
this.palette_256.push(col);
|
|
}
|
|
}
|
|
}
|
|
let grey_level = 8;
|
|
for (let i = 0; i < 24; ++i, grey_level += 10) {
|
|
let gry = { rgb: [grey_level, grey_level, grey_level], class_name: 'truecolor' };
|
|
this.palette_256.push(gry);
|
|
}
|
|
}
|
|
escape_txt_for_html(txt) {
|
|
if (!this._escape_html)
|
|
return txt;
|
|
return txt.replace(/[&<>"']/gm, (str) => {
|
|
if (str === "&")
|
|
return "&";
|
|
if (str === "<")
|
|
return "<";
|
|
if (str === ">")
|
|
return ">";
|
|
if (str === "\"")
|
|
return """;
|
|
if (str === "'")
|
|
return "'";
|
|
});
|
|
}
|
|
append_buffer(txt) {
|
|
var str = this._buffer + txt;
|
|
this._buffer = str;
|
|
}
|
|
get_next_packet() {
|
|
var pkt = {
|
|
kind: PacketKind.EOS,
|
|
text: '',
|
|
url: ''
|
|
};
|
|
var len = this._buffer.length;
|
|
if (len == 0)
|
|
return pkt;
|
|
var pos = this._buffer.indexOf("\x1B");
|
|
if (pos == -1) {
|
|
pkt.kind = PacketKind.Text;
|
|
pkt.text = this._buffer;
|
|
this._buffer = '';
|
|
return pkt;
|
|
}
|
|
if (pos > 0) {
|
|
pkt.kind = PacketKind.Text;
|
|
pkt.text = this._buffer.slice(0, pos);
|
|
this._buffer = this._buffer.slice(pos);
|
|
return pkt;
|
|
}
|
|
if (pos == 0) {
|
|
if (len < 3) {
|
|
pkt.kind = PacketKind.Incomplete;
|
|
return pkt;
|
|
}
|
|
var next_char = this._buffer.charAt(1);
|
|
if ((next_char != '[') && (next_char != ']') && (next_char != '(')) {
|
|
pkt.kind = PacketKind.ESC;
|
|
pkt.text = this._buffer.slice(0, 1);
|
|
this._buffer = this._buffer.slice(1);
|
|
return pkt;
|
|
}
|
|
if (next_char == '[') {
|
|
if (!this._csi_regex) {
|
|
this._csi_regex = rgx(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ^ # beginning of line\n #\n # First attempt\n (?: # legal sequence\n \u001B[ # CSI\n ([<-?]?) # private-mode char\n ([d;]*) # any digits or semicolons\n ([ -/]? # an intermediate modifier\n [@-~]) # the command\n )\n | # alternate (second attempt)\n (?: # illegal sequence\n \u001B[ # CSI\n [ -~]* # anything legal\n ([\0-\u001F:]) # anything illegal\n )\n "], ["\n ^ # beginning of line\n #\n # First attempt\n (?: # legal sequence\n \\x1b\\[ # CSI\n ([\\x3c-\\x3f]?) # private-mode char\n ([\\d;]*) # any digits or semicolons\n ([\\x20-\\x2f]? # an intermediate modifier\n [\\x40-\\x7e]) # the command\n )\n | # alternate (second attempt)\n (?: # illegal sequence\n \\x1b\\[ # CSI\n [\\x20-\\x7e]* # anything legal\n ([\\x00-\\x1f:]) # anything illegal\n )\n "])));
|
|
}
|
|
let match = this._buffer.match(this._csi_regex);
|
|
if (match === null) {
|
|
pkt.kind = PacketKind.Incomplete;
|
|
return pkt;
|
|
}
|
|
if (match[4]) {
|
|
pkt.kind = PacketKind.ESC;
|
|
pkt.text = this._buffer.slice(0, 1);
|
|
this._buffer = this._buffer.slice(1);
|
|
return pkt;
|
|
}
|
|
if ((match[1] != '') || (match[3] != 'm'))
|
|
pkt.kind = PacketKind.Unknown;
|
|
else
|
|
pkt.kind = PacketKind.SGR;
|
|
pkt.text = match[2];
|
|
var rpos = match[0].length;
|
|
this._buffer = this._buffer.slice(rpos);
|
|
return pkt;
|
|
}
|
|
else if (next_char == ']') {
|
|
if (len < 4) {
|
|
pkt.kind = PacketKind.Incomplete;
|
|
return pkt;
|
|
}
|
|
if ((this._buffer.charAt(2) != '8')
|
|
|| (this._buffer.charAt(3) != ';')) {
|
|
pkt.kind = PacketKind.ESC;
|
|
pkt.text = this._buffer.slice(0, 1);
|
|
this._buffer = this._buffer.slice(1);
|
|
return pkt;
|
|
}
|
|
if (!this._osc_st) {
|
|
this._osc_st = rgxG(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n (?: # legal sequence\n (\u001B\\) # ESC | # alternate\n (\u0007) # BEL (what xterm did)\n )\n | # alternate (second attempt)\n ( # illegal sequence\n [\0-\u0006] # anything illegal\n | # alternate\n [\b-\u001A] # anything illegal\n | # alternate\n [\u001C-\u001F] # anything illegal\n )\n "], ["\n (?: # legal sequence\n (\\x1b\\\\) # ESC \\\n | # alternate\n (\\x07) # BEL (what xterm did)\n )\n | # alternate (second attempt)\n ( # illegal sequence\n [\\x00-\\x06] # anything illegal\n | # alternate\n [\\x08-\\x1a] # anything illegal\n | # alternate\n [\\x1c-\\x1f] # anything illegal\n )\n "])));
|
|
}
|
|
this._osc_st.lastIndex = 0;
|
|
{
|
|
let match = this._osc_st.exec(this._buffer);
|
|
if (match === null) {
|
|
pkt.kind = PacketKind.Incomplete;
|
|
return pkt;
|
|
}
|
|
if (match[3]) {
|
|
pkt.kind = PacketKind.ESC;
|
|
pkt.text = this._buffer.slice(0, 1);
|
|
this._buffer = this._buffer.slice(1);
|
|
return pkt;
|
|
}
|
|
}
|
|
{
|
|
let match = this._osc_st.exec(this._buffer);
|
|
if (match === null) {
|
|
pkt.kind = PacketKind.Incomplete;
|
|
return pkt;
|
|
}
|
|
if (match[3]) {
|
|
pkt.kind = PacketKind.ESC;
|
|
pkt.text = this._buffer.slice(0, 1);
|
|
this._buffer = this._buffer.slice(1);
|
|
return pkt;
|
|
}
|
|
}
|
|
if (!this._osc_regex) {
|
|
this._osc_regex = rgx(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n ^ # beginning of line\n #\n \u001B]8; # OSC Hyperlink\n [ -:<-~]* # params (excluding ;)\n ; # end of params\n ([!-~]{0,512}) # URL capture\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n ([ -~]+) # TEXT capture\n \u001B]8;; # OSC Hyperlink End\n (?: # ST\n (?:\u001B\\) # ESC | # alternate\n (?:\u0007) # BEL (what xterm did)\n )\n "], ["\n ^ # beginning of line\n #\n \\x1b\\]8; # OSC Hyperlink\n [\\x20-\\x3a\\x3c-\\x7e]* # params (excluding ;)\n ; # end of params\n ([\\x21-\\x7e]{0,512}) # URL capture\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n ([\\x20-\\x7e]+) # TEXT capture\n \\x1b\\]8;; # OSC Hyperlink End\n (?: # ST\n (?:\\x1b\\\\) # ESC \\\n | # alternate\n (?:\\x07) # BEL (what xterm did)\n )\n "])));
|
|
}
|
|
let match = this._buffer.match(this._osc_regex);
|
|
if (match === null) {
|
|
pkt.kind = PacketKind.ESC;
|
|
pkt.text = this._buffer.slice(0, 1);
|
|
this._buffer = this._buffer.slice(1);
|
|
return pkt;
|
|
}
|
|
pkt.kind = PacketKind.OSCURL;
|
|
pkt.url = match[1];
|
|
pkt.text = match[2];
|
|
var rpos = match[0].length;
|
|
this._buffer = this._buffer.slice(rpos);
|
|
return pkt;
|
|
}
|
|
else if (next_char == '(') {
|
|
pkt.kind = PacketKind.Unknown;
|
|
this._buffer = this._buffer.slice(3);
|
|
return pkt;
|
|
}
|
|
}
|
|
}
|
|
ansi_to_html(txt) {
|
|
this.append_buffer(txt);
|
|
var blocks = [];
|
|
while (true) {
|
|
var packet = this.get_next_packet();
|
|
if ((packet.kind == PacketKind.EOS)
|
|
|| (packet.kind == PacketKind.Incomplete))
|
|
break;
|
|
if ((packet.kind == PacketKind.ESC)
|
|
|| (packet.kind == PacketKind.Unknown))
|
|
continue;
|
|
if (packet.kind == PacketKind.Text)
|
|
blocks.push(this.transform_to_html(this.with_state(packet)));
|
|
else if (packet.kind == PacketKind.SGR)
|
|
this.process_ansi(packet);
|
|
else if (packet.kind == PacketKind.OSCURL)
|
|
blocks.push(this.process_hyperlink(packet));
|
|
}
|
|
return blocks.join("");
|
|
}
|
|
with_state(pkt) {
|
|
return { bold: this.bold, faint: this.faint, italic: this.italic, underline: this.underline, fg: this.fg, bg: this.bg, text: pkt.text };
|
|
}
|
|
process_ansi(pkt) {
|
|
let sgr_cmds = pkt.text.split(';');
|
|
while (sgr_cmds.length > 0) {
|
|
let sgr_cmd_str = sgr_cmds.shift();
|
|
let num = parseInt(sgr_cmd_str, 10);
|
|
if (isNaN(num) || num === 0) {
|
|
this.fg = null;
|
|
this.bg = null;
|
|
this.bold = false;
|
|
this.faint = false;
|
|
this.italic = false;
|
|
this.underline = false;
|
|
}
|
|
else if (num === 1) {
|
|
this.bold = true;
|
|
}
|
|
else if (num === 2) {
|
|
this.faint = true;
|
|
}
|
|
else if (num === 3) {
|
|
this.italic = true;
|
|
}
|
|
else if (num === 4) {
|
|
this.underline = true;
|
|
}
|
|
else if (num === 21) {
|
|
this.bold = false;
|
|
}
|
|
else if (num === 22) {
|
|
this.faint = false;
|
|
this.bold = false;
|
|
}
|
|
else if (num === 23) {
|
|
this.italic = false;
|
|
}
|
|
else if (num === 24) {
|
|
this.underline = false;
|
|
}
|
|
else if (num === 39) {
|
|
this.fg = null;
|
|
}
|
|
else if (num === 49) {
|
|
this.bg = null;
|
|
}
|
|
else if ((num >= 30) && (num < 38)) {
|
|
this.fg = this.ansi_colors[0][(num - 30)];
|
|
}
|
|
else if ((num >= 40) && (num < 48)) {
|
|
this.bg = this.ansi_colors[0][(num - 40)];
|
|
}
|
|
else if ((num >= 90) && (num < 98)) {
|
|
this.fg = this.ansi_colors[1][(num - 90)];
|
|
}
|
|
else if ((num >= 100) && (num < 108)) {
|
|
this.bg = this.ansi_colors[1][(num - 100)];
|
|
}
|
|
else if (num === 38 || num === 48) {
|
|
if (sgr_cmds.length > 0) {
|
|
let is_foreground = (num === 38);
|
|
let mode_cmd = sgr_cmds.shift();
|
|
if (mode_cmd === '5' && sgr_cmds.length > 0) {
|
|
let palette_index = parseInt(sgr_cmds.shift(), 10);
|
|
if (palette_index >= 0 && palette_index <= 255) {
|
|
if (is_foreground)
|
|
this.fg = this.palette_256[palette_index];
|
|
else
|
|
this.bg = this.palette_256[palette_index];
|
|
}
|
|
}
|
|
if (mode_cmd === '2' && sgr_cmds.length > 2) {
|
|
let r = parseInt(sgr_cmds.shift(), 10);
|
|
let g = parseInt(sgr_cmds.shift(), 10);
|
|
let b = parseInt(sgr_cmds.shift(), 10);
|
|
if ((r >= 0 && r <= 255) && (g >= 0 && g <= 255) && (b >= 0 && b <= 255)) {
|
|
let c = { rgb: [r, g, b], class_name: 'truecolor' };
|
|
if (is_foreground)
|
|
this.fg = c;
|
|
else
|
|
this.bg = c;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
transform_to_html(fragment) {
|
|
let txt = fragment.text;
|
|
if (txt.length === 0)
|
|
return txt;
|
|
txt = this.escape_txt_for_html(txt);
|
|
if (!fragment.bold && !fragment.italic && !fragment.faint && !fragment.underline && fragment.fg === null && fragment.bg === null)
|
|
return txt;
|
|
let styles = [];
|
|
let classes = [];
|
|
let fg = fragment.fg;
|
|
let bg = fragment.bg;
|
|
if (fragment.bold)
|
|
styles.push(this._boldStyle);
|
|
if (fragment.faint)
|
|
styles.push(this._faintStyle);
|
|
if (fragment.italic)
|
|
styles.push(this._italicStyle);
|
|
if (fragment.underline)
|
|
styles.push(this._underlineStyle);
|
|
if (!this._use_classes) {
|
|
if (fg)
|
|
styles.push(`color:rgb(${fg.rgb.join(',')})`);
|
|
if (bg)
|
|
styles.push(`background-color:rgb(${bg.rgb})`);
|
|
}
|
|
else {
|
|
if (fg) {
|
|
if (fg.class_name !== 'truecolor') {
|
|
classes.push(`${fg.class_name}-fg`);
|
|
}
|
|
else {
|
|
styles.push(`color:rgb(${fg.rgb.join(',')})`);
|
|
}
|
|
}
|
|
if (bg) {
|
|
if (bg.class_name !== 'truecolor') {
|
|
classes.push(`${bg.class_name}-bg`);
|
|
}
|
|
else {
|
|
styles.push(`background-color:rgb(${bg.rgb.join(',')})`);
|
|
}
|
|
}
|
|
}
|
|
let class_string = '';
|
|
let style_string = '';
|
|
if (classes.length)
|
|
class_string = ` class="${classes.join(' ')}"`;
|
|
if (styles.length)
|
|
style_string = ` style="${styles.join(';')}"`;
|
|
return `<span${style_string}${class_string}>${txt}</span>`;
|
|
}
|
|
;
|
|
process_hyperlink(pkt) {
|
|
let parts = pkt.url.split(':');
|
|
if (parts.length < 1)
|
|
return '';
|
|
if (!this._url_allowlist[parts[0]])
|
|
return '';
|
|
let result = `<a href="${this.escape_txt_for_html(pkt.url)}">${this.escape_txt_for_html(pkt.text)}</a>`;
|
|
return result;
|
|
}
|
|
}
|
|
function rgx(tmplObj, ...subst) {
|
|
let regexText = tmplObj.raw[0];
|
|
let wsrgx = /^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm;
|
|
let txt2 = regexText.replace(wsrgx, '');
|
|
return new RegExp(txt2);
|
|
}
|
|
function rgxG(tmplObj, ...subst) {
|
|
let regexText = tmplObj.raw[0];
|
|
let wsrgx = /^\s+|\s+\n|\s*#[\s\S]*?\n|\n/gm;
|
|
let txt2 = regexText.replace(wsrgx, '');
|
|
return new RegExp(txt2, 'g');
|
|
}
|
|
var templateObject_1, templateObject_2, templateObject_3;
|
|
|
|
var ansi_up = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
AnsiUp: AnsiUp
|
|
});
|
|
|
|
var require$$1 = /*@__PURE__*/getAugmentedNamespace(ansi_up);
|
|
|
|
var __awaiter$1 = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __generator$1 = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
function step(op) {
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
switch (op[0]) {
|
|
case 0: case 1: t = op; break;
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
default:
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
if (t[2]) _.ops.pop();
|
|
_.trys.pop(); continue;
|
|
}
|
|
op = body.call(thisArg, _);
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
}
|
|
};
|
|
Object.defineProperty(logsHandler, "__esModule", { value: true });
|
|
logsHandler.LogsHandler = void 0;
|
|
var morphux_1$2 = requireIndex();
|
|
var ansi_up_1 = require$$1;
|
|
var LogsHandler = /** @class */ (function () {
|
|
function LogsHandler(Main) {
|
|
this.ansiUp = new ansi_up_1.AnsiUp();
|
|
this.cameraLogsContainer = document.querySelector('.ntsh_tab[tabid="cameralogs"] .ntsh_logs');
|
|
this.unityLogsContainer = document.querySelector('.ntsh_tab[tabid="unitylogs"] .ntsh_logs');
|
|
this.firstTime = new Set();
|
|
this._Main = Main;
|
|
this.registerListeners();
|
|
}
|
|
LogsHandler.prototype.setCameraLogs = function (logs) {
|
|
this.applyLogs(this.cameraLogsContainer, logs);
|
|
};
|
|
LogsHandler.prototype.setUnityLogs = function (logs) {
|
|
this.applyLogs(this.unityLogsContainer, logs);
|
|
};
|
|
LogsHandler.prototype.applyLogs = function (container, logs) {
|
|
return __awaiter$1(this, void 0, void 0, function () {
|
|
var logCount, isAtBottom;
|
|
var _this = this;
|
|
return __generator$1(this, function (_a) {
|
|
logCount = container.querySelectorAll('.ntsh_log.ntsh_log-normal').length;
|
|
if (logCount === logs.length)
|
|
return [2 /*return*/];
|
|
if (logCount > logs.length)
|
|
logCount = 0;
|
|
isAtBottom = !this.firstTime.has(container) ||
|
|
container.scrollTop + container.clientHeight >=
|
|
container.scrollHeight;
|
|
container.innerHTML = '';
|
|
logs.forEach(function (log, i) {
|
|
var element = (0, morphux_1$2.ce)('div', ['ntsh_log', 'ntsh_log-normal'], null, null, _this.ansiUp.ansi_to_html(log));
|
|
if (_this.firstTime.has(container) && i > logCount - 1) {
|
|
element.style.display = 'none';
|
|
var spawnDelay = (i - logCount) * 10;
|
|
setTimeout(function () {
|
|
element.style.display = 'block';
|
|
if (isAtBottom)
|
|
container.scrollTop = container.scrollHeight;
|
|
}, spawnDelay);
|
|
}
|
|
container.appendChild(element);
|
|
if (isAtBottom)
|
|
container.scrollTop = container.scrollHeight;
|
|
});
|
|
if (!this.firstTime.has(container)) {
|
|
container.scrollTop = container.scrollHeight;
|
|
this.firstTime.add(container);
|
|
}
|
|
return [2 /*return*/];
|
|
});
|
|
});
|
|
};
|
|
LogsHandler.prototype.registerListeners = function () {
|
|
var _this = this;
|
|
this._Main.TabController.registerListener('cameralogs', function (visible) {
|
|
if (!visible)
|
|
return;
|
|
setTimeout(function () {
|
|
_this.cameraLogsContainer.scrollTop =
|
|
_this.cameraLogsContainer.scrollHeight;
|
|
}, 10);
|
|
});
|
|
this._Main.TabController.registerListener('unitylogs', function (visible) {
|
|
if (!visible)
|
|
return;
|
|
setTimeout(function () {
|
|
_this.unityLogsContainer.scrollTop =
|
|
_this.unityLogsContainer.scrollHeight;
|
|
}, 10);
|
|
});
|
|
};
|
|
return LogsHandler;
|
|
}());
|
|
logsHandler.LogsHandler = LogsHandler;
|
|
|
|
var calibration = {};
|
|
|
|
Object.defineProperty(calibration, "__esModule", { value: true });
|
|
calibration.Calibration = void 0;
|
|
var Calibration = /** @class */ (function () {
|
|
function Calibration(Main) {
|
|
this.container = document.querySelector('.ntsh_calibration');
|
|
this.image = this.container.querySelector('img');
|
|
this.fullscreenButton = this.container.querySelector('.ntsh_calibration-fullscreen');
|
|
this._Main = Main;
|
|
this.registerListeners();
|
|
}
|
|
Calibration.prototype.startFetchClock = function () {
|
|
var _this = this;
|
|
this.image.src = "/calibrationImage?t=".concat(Date.now());
|
|
this.fetchClock = setInterval(function () {
|
|
_this.image.src = "/calibrationImage?t=".concat(Date.now());
|
|
}, 1000);
|
|
};
|
|
Calibration.prototype.stopFetchClock = function () {
|
|
clearInterval(this.fetchClock);
|
|
};
|
|
Calibration.prototype.registerListeners = function () {
|
|
var _this = this;
|
|
this._Main.TabController.registerListener('calibration', function (visible) {
|
|
if (visible)
|
|
_this.startFetchClock();
|
|
else
|
|
_this.stopFetchClock();
|
|
});
|
|
this.fullscreenButton.addEventListener('click', function () {
|
|
_this.image.requestFullscreen();
|
|
});
|
|
};
|
|
return Calibration;
|
|
}());
|
|
calibration.Calibration = Calibration;
|
|
|
|
var dashboard_unity = {};
|
|
|
|
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
|
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
function step(op) {
|
|
if (f) throw new TypeError("Generator is already executing.");
|
|
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
switch (op[0]) {
|
|
case 0: case 1: t = op; break;
|
|
case 4: _.label++; return { value: op[1], done: false };
|
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
default:
|
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
if (t[2]) _.ops.pop();
|
|
_.trys.pop(); continue;
|
|
}
|
|
op = body.call(thisArg, _);
|
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
}
|
|
};
|
|
Object.defineProperty(dashboard_unity, "__esModule", { value: true });
|
|
dashboard_unity.DashboardUnity = void 0;
|
|
var morphux_1$1 = requireIndex();
|
|
var utils_1 = utils;
|
|
var DashboardUnity = /** @class */ (function () {
|
|
function DashboardUnity(Main) {
|
|
this.container = document.querySelector('.ntsh_dashboard-unity');
|
|
this.processStatus = document.querySelector('.ntsh_dashboard-unity-processstatus');
|
|
this.processInfo = document.querySelector('.ntsh_dashboard-unity-processinfo');
|
|
this.restartButton = document.querySelector('.ntsh_dashboard-unity-restart');
|
|
this.startButton = document.querySelector('.ntsh_dashboard-unity-start');
|
|
this.stopButton = document.querySelector('.ntsh_dashboard-unity-stop');
|
|
this.uptimeInfo = document.querySelector('.ntsh_dashboard-unity-uptime');
|
|
this.webSocketStatus = document.querySelector('.ntsh_dashboard-unity-websocketstatus');
|
|
this.webSocketInfo = document.querySelector('.ntsh_dashboard-unity-websocketinfo');
|
|
this.outOfServiceStatus = document.querySelector('.ntsh_dashboard-unity-outofservicestatus');
|
|
this.outOfServiceInfo = document.querySelector('.ntsh_dashboard-unity-outofserviceinfo');
|
|
this.enableOutOfServiceButton = document.querySelector('.ntsh_dashboard-unity-enableoutofservice');
|
|
this.disableOutOfServiceButton = document.querySelector('.ntsh_dashboard-unity-disableoutofservice');
|
|
this.zedStreamStatus = document.querySelector('.ntsh_dashboard-unity-zedstreamstatus');
|
|
this.zedStreamInfo = document.querySelector('.ntsh_dashboard-unity-zedstreaminfo');
|
|
this.zedStreamFps = document.querySelector('.ntsh_dashboard-unity-zedstreamfps');
|
|
this.zedStreamPath = document.querySelector('.ntsh_dashboard-unity-zedstreampath');
|
|
this.timelineWatching = document.querySelector('.ntsh_dashboard-unity-timeline-watching');
|
|
this.timelineStanding = document.querySelector('.ntsh_dashboard-unity-timeline-standing');
|
|
this.timelineProgress = document.querySelector('.ntsh_dashboard-unity-timeline-progress');
|
|
this.parametersTable = document.querySelector('.ntsh_dashboard-unity-parameters');
|
|
this.advancedParametersTable = document.querySelector('.ntsh_dashboard-unity-advancedparameters');
|
|
this.sensorsTable = document.querySelector('.ntsh_dashboard-unity-sensors');
|
|
this.errorContainer = document.querySelector('.ntsh_dashboard-unity-error');
|
|
this.errorText = document.querySelector('.ntsh_dashboard-unity-errortext');
|
|
this._Main = Main;
|
|
this.registerListeners();
|
|
}
|
|
DashboardUnity.prototype.updateRunnerState = function (state) {
|
|
var _a, _b;
|
|
// ----------- Process -----------
|
|
if (state.state != 'RUNNING') {
|
|
state.startTime = -1;
|
|
this.restartButton.style.display = 'none';
|
|
this.stopButton.style.display = 'none';
|
|
}
|
|
else {
|
|
this.restartButton.style.display = 'flex';
|
|
this.stopButton.style.display = 'flex';
|
|
}
|
|
this.startButton.style.display =
|
|
state.state == 'STOPPED' ? 'flex' : 'none';
|
|
(0, utils_1.setStatusState)(this.processStatus, {
|
|
RUNNING: 'green',
|
|
STOPPED: 'gray',
|
|
STARTING: 'yellow',
|
|
PROBLEM: 'red',
|
|
}[state.state]);
|
|
this.processInfo.innerText = (_a = state.message) !== null && _a !== void 0 ? _a : '';
|
|
// ----------- Uptime -----------
|
|
var uptimeSeconds = state.startTime == -1 ? -1 : (Date.now() - state.startTime) / 1000;
|
|
this.uptimeInfo.innerText = (0, utils_1.formatUptime)(uptimeSeconds);
|
|
// ----------- Error -----------
|
|
if (((_b = state === null || state === void 0 ? void 0 : state.error) !== null && _b !== void 0 ? _b : '').trim().length > 0)
|
|
this.runnerError = state.error;
|
|
else
|
|
this.runnerError = null;
|
|
this.updateError();
|
|
this._Main.Logs.setUnityLogs(state.output.current);
|
|
};
|
|
DashboardUnity.prototype.updateWebSocketState = function (state) {
|
|
var _a, _b;
|
|
// ----------- WebSocket -----------
|
|
(0, utils_1.setStatusState)(this.webSocketStatus, {
|
|
CONNECTING: 'yellow',
|
|
CONNECTED: 'green',
|
|
DISCONNECTED: 'gray',
|
|
FAILED: 'red',
|
|
}[state.state]);
|
|
this.webSocketInfo.innerText = (_a = state.message) !== null && _a !== void 0 ? _a : '';
|
|
// ----------- Out of Service -----------
|
|
(0, utils_1.setStatusState)(this.outOfServiceStatus, state.parameters.outOfService == null
|
|
? 'gray'
|
|
: state.parameters.outOfService
|
|
? 'red'
|
|
: 'green');
|
|
this.outOfServiceInfo.innerText =
|
|
state.parameters.outOfService == null
|
|
? ''
|
|
: state.parameters.outOfService
|
|
? 'Out of Service'
|
|
: 'Operational';
|
|
this.enableOutOfServiceButton.style.display =
|
|
state.parameters.outOfService == null ||
|
|
state.parameters.outOfService
|
|
? 'none'
|
|
: 'flex';
|
|
this.disableOutOfServiceButton.style.display =
|
|
state.parameters.outOfService &&
|
|
state.parameters.outOfService != null
|
|
? 'flex'
|
|
: 'none';
|
|
// ----------- ZED Stream -----------
|
|
(0, utils_1.setStatusState)(this.zedStreamStatus, state.parameters.zedReady ? 'green' : 'red');
|
|
this.zedStreamInfo.innerText = state.parameters.zedReady
|
|
? "Connected to ".concat(state.parameters.zedPath)
|
|
: 'Not ready';
|
|
this.zedStreamFps.innerText =
|
|
state.parameters.zedFPS == '-' ? '' : state.parameters.zedFPS;
|
|
// ----------- Timeline -----------
|
|
this.timelineWatching.innerText = state.parameters.timelineWatching
|
|
? 'Yes'
|
|
: 'No';
|
|
this.timelineStanding.innerText = state.parameters.timelineStanding
|
|
? 'Yes'
|
|
: 'No';
|
|
(0, utils_1.setProgressState)(this.timelineProgress, Math.round(state.parameters.timelineProgress * 100), 0, 100, '%');
|
|
// ----------- Parameters -----------
|
|
this.renderParameterSliders(state.state == 'CONNECTED' ? state.parameters.sliders : []);
|
|
this.renderAdvancedParameterSliders(state.state == 'CONNECTED' ? state.parameters.advancedSliders : []);
|
|
this.renderParameterSensors(state.state == 'CONNECTED' ? state.parameters.sensors : []);
|
|
// ----------- Error -----------
|
|
if (((_b = state === null || state === void 0 ? void 0 : state.error) !== null && _b !== void 0 ? _b : '').trim().length > 0)
|
|
this.webSocketError = state.error;
|
|
else
|
|
this.webSocketError = null;
|
|
this.updateError();
|
|
};
|
|
DashboardUnity.prototype.renderParameterSliders = function (sliders) {
|
|
var _this = this;
|
|
var existingSliders = this.parametersTable.querySelectorAll('.ntsh_dashboard-unity-parameter-row');
|
|
if (existingSliders.length !== sliders.length) {
|
|
this.parametersTable.innerHTML = '';
|
|
if (sliders.length === 0) {
|
|
var row = (0, morphux_1$1.ce)('tr');
|
|
var cell = (0, morphux_1$1.ce)('td');
|
|
cell.appendChild((0, morphux_1$1.ce)('div', ['mux_text', 'ntsh_dashboard-unity-parameters-loading'], null, 'Waiting for Unity...'));
|
|
row.appendChild(cell);
|
|
this.parametersTable.appendChild(row);
|
|
}
|
|
else
|
|
sliders.forEach(function (slider) {
|
|
var _a, _b;
|
|
var multiplierFactor = (_a = slider.visualMultiplier) !== null && _a !== void 0 ? _a : 1;
|
|
var decimalPlacesFactor = Math.pow(10, ((_b = slider.decimalPlaces) !== null && _b !== void 0 ? _b : 0));
|
|
var value = Math.round(slider.outputValue *
|
|
multiplierFactor *
|
|
decimalPlacesFactor) / decimalPlacesFactor;
|
|
var row = (0, morphux_1$1.ce)('tr', 'ntsh_dashboard-unity-parameter-row');
|
|
var nameCell = (0, morphux_1$1.ce)('td');
|
|
nameCell.appendChild((0, morphux_1$1.ce)('div', 'mux_text', null, slider.sliderName));
|
|
row.appendChild(nameCell);
|
|
var progressCell = (0, morphux_1$1.ce)('td', 'no-service');
|
|
progressCell.appendChild((0, utils_1.createProgress)(value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit));
|
|
row.appendChild(progressCell);
|
|
var sliderCell = (0, morphux_1$1.ce)('td', 'only-service');
|
|
var sliderProgress = (0, utils_1.createProgress)(value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
var sliderValue = sliderProgress.querySelector('.ntsh_progress-value');
|
|
sliderValue.classList.add('mux_resizer');
|
|
sliderCell.appendChild(sliderProgress);
|
|
var resizer = new morphux_1$1.MorphComponent.Resizer({
|
|
existingContainer: sliderValue,
|
|
direction: 'right',
|
|
relative: true,
|
|
min: 0,
|
|
max: function () { return sliderProgress.clientWidth; },
|
|
});
|
|
var lastValue = -1;
|
|
resizer.on('resized', function (size) {
|
|
var percentage = Math.round((size / sliderProgress.clientWidth) * 100) / 100;
|
|
var actualValue = slider.min + percentage * (slider.max - slider.min);
|
|
if (actualValue === lastValue)
|
|
return;
|
|
lastValue = actualValue;
|
|
_this._Main.socket.emit('unityWebSocket', 'parameterValue', slider.sliderIndex, actualValue);
|
|
(0, utils_1.setProgressState)(sliderProgress, Math.round(actualValue *
|
|
multiplierFactor *
|
|
decimalPlacesFactor) / decimalPlacesFactor, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
});
|
|
row.appendChild(sliderCell);
|
|
_this.parametersTable.appendChild(row);
|
|
});
|
|
}
|
|
else {
|
|
existingSliders.forEach(function (row, index) {
|
|
var _a, _b;
|
|
var slider = sliders[index];
|
|
var multiplierFactor = (_a = slider.visualMultiplier) !== null && _a !== void 0 ? _a : 1;
|
|
var decimalPlacesFactor = Math.pow(10, ((_b = slider.decimalPlaces) !== null && _b !== void 0 ? _b : 0));
|
|
var value = Math.round(slider.outputValue *
|
|
multiplierFactor *
|
|
decimalPlacesFactor) / decimalPlacesFactor;
|
|
var progressElement = row.querySelector('.no-service .ntsh_progress');
|
|
(0, utils_1.setProgressState)(progressElement, value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
var sliderElement = row.querySelector('.only-service .ntsh_progress');
|
|
if (sliderElement.querySelector('.mux_resizer-moving') == null)
|
|
(0, utils_1.setProgressState)(sliderElement, value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
});
|
|
}
|
|
};
|
|
DashboardUnity.prototype.renderAdvancedParameterSliders = function (sliders) {
|
|
var _this = this;
|
|
var existingSliders = this.advancedParametersTable.querySelectorAll('.ntsh_dashboard-unity-parameter-row');
|
|
if (existingSliders.length !== sliders.length) {
|
|
this.advancedParametersTable.innerHTML = '';
|
|
if (sliders.length === 0) {
|
|
var row = (0, morphux_1$1.ce)('tr');
|
|
var cell = (0, morphux_1$1.ce)('td');
|
|
cell.appendChild((0, morphux_1$1.ce)('div', ['mux_text', 'ntsh_dashboard-unity-parameters-loading'], null, 'Waiting for Unity...'));
|
|
row.appendChild(cell);
|
|
this.advancedParametersTable.appendChild(row);
|
|
}
|
|
else
|
|
sliders.forEach(function (slider) {
|
|
var _a, _b;
|
|
var multiplierFactor = (_a = slider.visualMultiplier) !== null && _a !== void 0 ? _a : 1;
|
|
var decimalPlacesFactor = Math.pow(10, ((_b = slider.decimalPlaces) !== null && _b !== void 0 ? _b : 0));
|
|
var value = Math.round(slider.outputValue *
|
|
multiplierFactor *
|
|
decimalPlacesFactor) / decimalPlacesFactor;
|
|
var row = (0, morphux_1$1.ce)('tr', 'ntsh_dashboard-unity-parameter-row');
|
|
var nameCell = (0, morphux_1$1.ce)('td');
|
|
nameCell.appendChild((0, morphux_1$1.ce)('div', 'mux_text', null, slider.sliderName));
|
|
row.appendChild(nameCell);
|
|
var progressCell = (0, morphux_1$1.ce)('td', 'no-service');
|
|
progressCell.appendChild((0, utils_1.createProgress)(value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit));
|
|
row.appendChild(progressCell);
|
|
var sliderCell = (0, morphux_1$1.ce)('td', 'only-service');
|
|
var sliderProgress = (0, utils_1.createProgress)(value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
var sliderValue = sliderProgress.querySelector('.ntsh_progress-value');
|
|
sliderValue.classList.add('mux_resizer');
|
|
sliderCell.appendChild(sliderProgress);
|
|
var resizer = new morphux_1$1.MorphComponent.Resizer({
|
|
existingContainer: sliderValue,
|
|
direction: 'right',
|
|
relative: true,
|
|
min: 0,
|
|
max: function () { return sliderProgress.clientWidth; },
|
|
});
|
|
var lastValue = -1;
|
|
resizer.on('resized', function (size) {
|
|
var percentage = Math.round((size / sliderProgress.clientWidth) * 100) / 100;
|
|
var actualValue = slider.min + percentage * (slider.max - slider.min);
|
|
if (actualValue === lastValue)
|
|
return;
|
|
lastValue = actualValue;
|
|
_this._Main.socket.emit('unityWebSocket', 'advancedParameterValue', slider.sliderIndex, actualValue);
|
|
(0, utils_1.setProgressState)(sliderProgress, Math.round(actualValue *
|
|
multiplierFactor *
|
|
decimalPlacesFactor) / decimalPlacesFactor, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
});
|
|
row.appendChild(sliderCell);
|
|
_this.advancedParametersTable.appendChild(row);
|
|
});
|
|
}
|
|
else {
|
|
existingSliders.forEach(function (row, index) {
|
|
var _a, _b;
|
|
var slider = sliders[index];
|
|
var multiplierFactor = (_a = slider.visualMultiplier) !== null && _a !== void 0 ? _a : 1;
|
|
var decimalPlacesFactor = Math.pow(10, ((_b = slider.decimalPlaces) !== null && _b !== void 0 ? _b : 0));
|
|
var value = Math.round(slider.outputValue *
|
|
multiplierFactor *
|
|
decimalPlacesFactor) / decimalPlacesFactor;
|
|
var progressElement = row.querySelector('.no-service .ntsh_progress');
|
|
(0, utils_1.setProgressState)(progressElement, value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
var sliderElement = row.querySelector('.only-service .ntsh_progress');
|
|
if (sliderElement.querySelector('.mux_resizer-moving') == null)
|
|
(0, utils_1.setProgressState)(sliderElement, value, slider.min * multiplierFactor, slider.max * multiplierFactor, slider.unit);
|
|
});
|
|
}
|
|
};
|
|
DashboardUnity.prototype.renderParameterSensors = function (sensors) {
|
|
var _this = this;
|
|
var existingSensors = this.sensorsTable.querySelectorAll('.ntsh_dashboard-unity-sensor-row');
|
|
if (existingSensors.length !== sensors.length) {
|
|
this.sensorsTable.innerHTML = '';
|
|
if (sensors.length === 0) {
|
|
var row = (0, morphux_1$1.ce)('tr');
|
|
var cell = (0, morphux_1$1.ce)('td');
|
|
cell.appendChild((0, morphux_1$1.ce)('div', ['mux_text', 'ntsh_dashboard-unity-sensors-loading'], null, 'Waiting for Unity...'));
|
|
row.appendChild(cell);
|
|
this.sensorsTable.appendChild(row);
|
|
}
|
|
else
|
|
sensors.forEach(function (sensor) {
|
|
var row = (0, morphux_1$1.ce)('tr', 'ntsh_dashboard-unity-sensor-row');
|
|
var nameCell = (0, morphux_1$1.ce)('td');
|
|
nameCell.appendChild((0, morphux_1$1.ce)('div', 'mux_text', null, sensor.deviceName));
|
|
row.appendChild(nameCell);
|
|
var progressCell = (0, morphux_1$1.ce)('td');
|
|
progressCell.appendChild((0, utils_1.createProgress)(Math.round(sensor.outputValue * 100), 0, 100, '%'));
|
|
row.appendChild(progressCell);
|
|
_this.sensorsTable.appendChild(row);
|
|
});
|
|
}
|
|
else {
|
|
existingSensors.forEach(function (row, index) {
|
|
var value = sensors[index].outputValue;
|
|
var progressElement = row.querySelector('.ntsh_progress');
|
|
(0, utils_1.setProgressState)(progressElement, Math.round(value * 100), 0, 100, '%');
|
|
});
|
|
}
|
|
};
|
|
DashboardUnity.prototype.updateError = function () {
|
|
var errors = [];
|
|
if (this.runnerError != null)
|
|
errors.push(this.runnerError);
|
|
if (this.webSocketError != null)
|
|
errors.push(this.webSocketError);
|
|
if (errors.length > 0) {
|
|
this.errorText.innerText = errors.join('\n');
|
|
this.errorContainer.style.display = 'block';
|
|
}
|
|
else {
|
|
this.errorContainer.style.display = 'none';
|
|
this.errorText.innerText = '';
|
|
}
|
|
};
|
|
DashboardUnity.prototype.registerListeners = function () {
|
|
var _this = this;
|
|
this._Main.socket.on('unityRunnerState', function (state) {
|
|
return _this.updateRunnerState(state);
|
|
});
|
|
this._Main.socket.on('unityWebSocketState', function (state) { return _this.updateWebSocketState(state); });
|
|
this.restartButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
this.executeCommand('restart', 'Are you sure you want to restart the Unity Runner process?');
|
|
return [2 /*return*/];
|
|
});
|
|
}); });
|
|
this.startButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
this.executeCommand('start', 'Are you sure you want to start the Unity Runner process?');
|
|
return [2 /*return*/];
|
|
});
|
|
}); });
|
|
this.stopButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
this.executeCommand('stop', 'Are you sure you want to stop the Unity Runner process?');
|
|
return [2 /*return*/];
|
|
});
|
|
}); });
|
|
this.enableOutOfServiceButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
this.executeCommand('enableOutOfService', 'Are you sure you want to set the installation to "Out of Service"?', 'unityWebSocket');
|
|
return [2 /*return*/];
|
|
});
|
|
}); });
|
|
this.disableOutOfServiceButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
this.executeCommand('disableOutOfService', 'Are you sure you want to set the installation to "Operational"?', 'unityWebSocket');
|
|
return [2 /*return*/];
|
|
});
|
|
}); });
|
|
};
|
|
DashboardUnity.prototype.executeCommand = function (command_1, message_1) {
|
|
return __awaiter(this, arguments, void 0, function (command, message, type) {
|
|
var confirmed;
|
|
if (type === void 0) { type = 'unityRunner'; }
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0: return [4 /*yield*/, morphux_1$1.MorphFeature.Confirm({
|
|
title: 'Are you sure?',
|
|
message: message,
|
|
})];
|
|
case 1:
|
|
confirmed = _a.sent();
|
|
if (!confirmed)
|
|
return [2 /*return*/];
|
|
morphux_1$1.MorphFeature.Loader({
|
|
active: true,
|
|
message: "Dispatching command...",
|
|
});
|
|
this._Main.socket.emit(type, command, function (response) {
|
|
morphux_1$1.MorphFeature.Loader({ active: false });
|
|
if (!response.succeed)
|
|
return morphux_1$1.MorphFeature.Alert({
|
|
title: 'Error',
|
|
message: response.message,
|
|
});
|
|
morphux_1$1.MorphFeature.Notification({
|
|
level: 'success',
|
|
message: "Dispatched command",
|
|
});
|
|
});
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
return DashboardUnity;
|
|
}());
|
|
dashboard_unity.DashboardUnity = DashboardUnity;
|
|
|
|
Object.defineProperty(main$1, "__esModule", { value: true });
|
|
exports.Main = main$1.Main = void 0;
|
|
var socket_io_client_1 = cjsExports;
|
|
var menuBar_1 = menuBar;
|
|
var tabController_1 = tabController;
|
|
var morphux_1 = requireIndex();
|
|
var dashboard_camerarunner_1 = dashboard_camerarunner;
|
|
var logsHandler_1 = logsHandler;
|
|
var calibration_1 = calibration;
|
|
var dashboard_unity_1 = dashboard_unity;
|
|
var socket = (0, socket_io_client_1.io)('/');
|
|
var Main = /** @class */ (function () {
|
|
function Main() {
|
|
this.socket = socket;
|
|
this.MenuBar = new menuBar_1.MenuBar(this);
|
|
this.TabController = new tabController_1.TabController(this);
|
|
this.Logs = new logsHandler_1.LogsHandler(this);
|
|
this.Calibration = new calibration_1.Calibration(this);
|
|
this.DashboardCameraRunner = new dashboard_camerarunner_1.DashboardCameraRunner(this);
|
|
this.DashboardUnityRunner = new dashboard_unity_1.DashboardUnity(this);
|
|
if (window.location.search.includes('debug')) {
|
|
window.SN = this;
|
|
console.log('Debug mode enabled');
|
|
}
|
|
}
|
|
return Main;
|
|
}());
|
|
exports.Main = main$1.Main = Main;
|
|
morphux_1.MorphFeature.Loader({ active: true, message: 'Connecting to server...' });
|
|
socket.on('connect', function () {
|
|
console.log('Connected to server');
|
|
morphux_1.MorphFeature.Loader({ active: false });
|
|
});
|
|
new Main();
|
|
|
|
exports["default"] = main$1;
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
return exports;
|
|
|
|
})({});
|
|
//# sourceMappingURL=script.js.map
|