Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
williamngan committed May 2, 2024
1 parent 98327b0 commit 7618f11
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 23 deletions.
1 change: 1 addition & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ declare class Util {
static arrayCheck(pts: PtLikeIterable, minRequired?: number): boolean;
static iterToArray(it: Iterable<any>): any[];
static isMobile(): boolean;
static uniqueId(useCrypto?: boolean): string;
}

/*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
Expand Down
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ declare class Util {
static arrayCheck(pts: PtLikeIterable, minRequired?: number): boolean;
static iterToArray(it: Iterable<any>): any[];
static isMobile(): boolean;
static uniqueId(useCrypto?: boolean): string;
}

/*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
Expand Down
36 changes: 29 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3250,6 +3250,13 @@ var _Util = class _Util {
static isMobile() {
return /iPhone|iPad|Android/i.test(navigator.userAgent);
}
/**
* Generate a time-based unique ID or a crypto-based ID.
* @returns
*/
static uniqueId(useCrypto = false) {
return useCrypto && crypto ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).substring(2);
}
};
_Util._warnLevel = "mute";
var Util = _Util;
Expand Down Expand Up @@ -5862,34 +5869,49 @@ var CanvasSpace2 = class extends MultiTouchSpace {
this._initialResize = false;
let _selector = null;
let _existed = false;
this.id = "pt";
this.id = Util.uniqueId();
if (elem instanceof Element) {
_selector = elem;
this.id = "pts_existing_space";
this.id = _selector.id || this.id;
} else {
let id = elem;
id = elem[0] === "#" || elem[0] === "." ? elem : "#" + elem;
_selector = document.querySelector(id);
_existed = true;
this.id = id.substr(1);
}
if (!_selector) {
this._container = this._createElement("div", this.id + "_container");
this._canvas = this._createElement("canvas", this.id);
this._container.appendChild(this._canvas);
document.body.appendChild(this._container);
_existed = false;
} else if (_selector.nodeName.toLowerCase() != "canvas") {
this._container = _selector;
this._canvas = this._createElement("canvas", this.id + "_canvas");
this._container.appendChild(this._canvas);
this._initialResize = true;
} else {
this._canvas = _selector;
this._container = _selector.parentElement;
this._autoResize = false;
_existed = true;
}
if (!_existed) {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === "childList" && mutation.addedNodes.length) {
for (let node of mutation.addedNodes) {
if (node === this._canvas) {
this._ready(callback);
observer.disconnect();
return;
}
}
}
});
});
observer.observe(this._container, { childList: true });
this._container.appendChild(this._canvas);
} else {
this._ready(callback);
}
setTimeout(this._ready.bind(this, callback), 100);
this._ctx = this._canvas.getContext("2d");
}
/**
Expand Down
36 changes: 29 additions & 7 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3182,6 +3182,13 @@ var _Util = class _Util {
static isMobile() {
return /iPhone|iPad|Android/i.test(navigator.userAgent);
}
/**
* Generate a time-based unique ID or a crypto-based ID.
* @returns
*/
static uniqueId(useCrypto = false) {
return useCrypto && crypto ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).substring(2);
}
};
_Util._warnLevel = "mute";
var Util = _Util;
Expand Down Expand Up @@ -5794,34 +5801,49 @@ var CanvasSpace2 = class extends MultiTouchSpace {
this._initialResize = false;
let _selector = null;
let _existed = false;
this.id = "pt";
this.id = Util.uniqueId();
if (elem instanceof Element) {
_selector = elem;
this.id = "pts_existing_space";
this.id = _selector.id || this.id;
} else {
let id = elem;
id = elem[0] === "#" || elem[0] === "." ? elem : "#" + elem;
_selector = document.querySelector(id);
_existed = true;
this.id = id.substr(1);
}
if (!_selector) {
this._container = this._createElement("div", this.id + "_container");
this._canvas = this._createElement("canvas", this.id);
this._container.appendChild(this._canvas);
document.body.appendChild(this._container);
_existed = false;
} else if (_selector.nodeName.toLowerCase() != "canvas") {
this._container = _selector;
this._canvas = this._createElement("canvas", this.id + "_canvas");
this._container.appendChild(this._canvas);
this._initialResize = true;
} else {
this._canvas = _selector;
this._container = _selector.parentElement;
this._autoResize = false;
_existed = true;
}
if (!_existed) {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === "childList" && mutation.addedNodes.length) {
for (let node of mutation.addedNodes) {
if (node === this._canvas) {
this._ready(callback);
observer.disconnect();
return;
}
}
}
});
});
observer.observe(this._container, { childList: true });
this._container.appendChild(this._canvas);
} else {
this._ready(callback);
}
setTimeout(this._ready.bind(this, callback), 100);
this._ctx = this._canvas.getContext("2d");
}
/**
Expand Down
36 changes: 29 additions & 7 deletions dist/pts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,13 @@ See https://github.com/williamngan/pts for details. */
static isMobile() {
return /iPhone|iPad|Android/i.test(navigator.userAgent);
}
/**
* Generate a time-based unique ID or a crypto-based ID.
* @returns
*/
static uniqueId(useCrypto = false) {
return useCrypto && crypto ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).substring(2);
}
};
_Util._warnLevel = "mute";
var Util = _Util;
Expand Down Expand Up @@ -5894,34 +5901,49 @@ See https://github.com/williamngan/pts for details. */
this._initialResize = false;
let _selector = null;
let _existed = false;
this.id = "pt";
this.id = Util.uniqueId();
if (elem instanceof Element) {
_selector = elem;
this.id = "pts_existing_space";
this.id = _selector.id || this.id;
} else {
let id = elem;
id = elem[0] === "#" || elem[0] === "." ? elem : "#" + elem;
_selector = document.querySelector(id);
_existed = true;
this.id = id.substr(1);
}
if (!_selector) {
this._container = this._createElement("div", this.id + "_container");
this._canvas = this._createElement("canvas", this.id);
this._container.appendChild(this._canvas);
document.body.appendChild(this._container);
_existed = false;
} else if (_selector.nodeName.toLowerCase() != "canvas") {
this._container = _selector;
this._canvas = this._createElement("canvas", this.id + "_canvas");
this._container.appendChild(this._canvas);
this._initialResize = true;
} else {
this._canvas = _selector;
this._container = _selector.parentElement;
this._autoResize = false;
_existed = true;
}
if (!_existed) {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === "childList" && mutation.addedNodes.length) {
for (let node of mutation.addedNodes) {
if (node === this._canvas) {
this._ready(callback);
observer.disconnect();
return;
}
}
}
});
});
observer.observe(this._container, { childList: true });
this._container.appendChild(this._canvas);
} else {
this._ready(callback);
}
setTimeout(this._ready.bind(this, callback), 100);
this._ctx = this._canvas.getContext("2d");
}
/**
Expand Down
2 changes: 1 addition & 1 deletion dist/pts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pts.min.js.map

Large diffs are not rendered by default.

0 comments on commit 7618f11

Please sign in to comment.