@hpcc-js/util 3.4.1 → 3.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -2223
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +4 -4
- package/src/dispatch.ts +9 -3
- package/src/index.ts +1 -0
- package/src/utf8ToBase64.ts +47 -0
- package/types/dispatch.d.ts +2 -1
- package/types/index.d.ts +1 -0
- package/types/utf8ToBase64.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/util",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"description": "hpcc-js - Utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@xmldom/xmldom": "0.9.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@hpcc-js/esbuild-plugins": "^1.
|
|
44
|
+
"@hpcc-js/esbuild-plugins": "^1.7.0"
|
|
45
45
|
},
|
|
46
46
|
"repository": {
|
|
47
47
|
"type": "git",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"bugs": {
|
|
54
54
|
"url": "https://github.com/hpcc-systems/Visualization/issues"
|
|
55
55
|
},
|
|
56
|
-
"homepage": "https://github.com/hpcc-systems/Visualization/tree/
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"homepage": "https://github.com/hpcc-systems/Visualization/tree/main/packages/util",
|
|
57
|
+
"gitHead": "0289b8552e19395a8da9b70a154821cf70ce42e7"
|
|
58
58
|
}
|
package/src/dispatch.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { IObserverHandle } from "./observer.ts";
|
|
2
2
|
import { root } from "./platform.ts";
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type RequestAnimationFrame = (callback: FrameRequestCallback) => number | undefined;
|
|
5
5
|
export type CancelAnimationFrame = (handle: number) => void | undefined;
|
|
6
6
|
|
|
7
|
-
let requestAnimationFrame:
|
|
7
|
+
let requestAnimationFrame: RequestAnimationFrame;
|
|
8
8
|
// let cancelAnimationFrame: CancelAnimationFrame;
|
|
9
9
|
|
|
10
10
|
(function () {
|
|
@@ -53,6 +53,7 @@ export class Dispatch<T extends Message = Message> {
|
|
|
53
53
|
private _observerID: number = 0;
|
|
54
54
|
private _observers: ObserverAdapter<T>[] = [];
|
|
55
55
|
private _messageBuffer: T[] = [];
|
|
56
|
+
private _rafHandle: number | undefined = undefined;
|
|
56
57
|
|
|
57
58
|
constructor() {
|
|
58
59
|
}
|
|
@@ -72,6 +73,7 @@ export class Dispatch<T extends Message = Message> {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
private dispatchAll() {
|
|
76
|
+
this._rafHandle = undefined;
|
|
75
77
|
this.dispatch(this.messages());
|
|
76
78
|
this.flush();
|
|
77
79
|
}
|
|
@@ -95,12 +97,16 @@ export class Dispatch<T extends Message = Message> {
|
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
send(msg: T) {
|
|
100
|
+
if (!this.hasObserver()) return;
|
|
98
101
|
this.dispatch([msg]);
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
post(msg: T) {
|
|
105
|
+
if (!this.hasObserver()) return;
|
|
102
106
|
this._messageBuffer.push(msg);
|
|
103
|
-
|
|
107
|
+
if (this._rafHandle === undefined) {
|
|
108
|
+
this._rafHandle = requestAnimationFrame(() => this.dispatchAll());
|
|
109
|
+
}
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
attach(callback: Callback<T>, type?: MessageConstructor<T>): IObserverHandle {
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
2
|
+
|
|
3
|
+
function toUTF8Bytes(value: string): Uint8Array {
|
|
4
|
+
if (typeof TextEncoder !== "undefined") {
|
|
5
|
+
return new TextEncoder().encode(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const encoded = encodeURIComponent(value);
|
|
9
|
+
const bytes: number[] = [];
|
|
10
|
+
for (let i = 0; i < encoded.length; ++i) {
|
|
11
|
+
if (encoded[i] === "%") {
|
|
12
|
+
bytes.push(parseInt(encoded.substring(i + 1, i + 3), 16));
|
|
13
|
+
i += 2;
|
|
14
|
+
} else {
|
|
15
|
+
bytes.push(encoded.charCodeAt(i));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return Uint8Array.from(bytes);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function bytesToBase64(bytes: Uint8Array): string {
|
|
22
|
+
let output = "";
|
|
23
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
24
|
+
const byte1 = bytes[i];
|
|
25
|
+
const hasByte2 = i + 1 < bytes.length;
|
|
26
|
+
const hasByte3 = i + 2 < bytes.length;
|
|
27
|
+
const byte2 = hasByte2 ? bytes[i + 1] : 0;
|
|
28
|
+
const byte3 = hasByte3 ? bytes[i + 2] : 0;
|
|
29
|
+
|
|
30
|
+
output += BASE64_ALPHABET[byte1 >> 2];
|
|
31
|
+
output += BASE64_ALPHABET[((byte1 & 0x03) << 4) | (byte2 >> 4)];
|
|
32
|
+
output += hasByte2 ? BASE64_ALPHABET[((byte2 & 0x0f) << 2) | (byte3 >> 6)] : "=";
|
|
33
|
+
output += hasByte3 ? BASE64_ALPHABET[byte3 & 0x3f] : "=";
|
|
34
|
+
}
|
|
35
|
+
return output;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function utf8ToBase64(value: string = ""): string {
|
|
39
|
+
const normalized = value == null ? "" : String(value);
|
|
40
|
+
|
|
41
|
+
const maybeBuffer = (globalThis as any)?.Buffer;
|
|
42
|
+
if (maybeBuffer?.from) {
|
|
43
|
+
return maybeBuffer.from(normalized, "utf8").toString("base64");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return bytesToBase64(toUTF8Bytes(normalized));
|
|
47
|
+
}
|
package/types/dispatch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IObserverHandle } from "./observer.ts";
|
|
2
|
-
export type
|
|
2
|
+
export type RequestAnimationFrame = (callback: FrameRequestCallback) => number | undefined;
|
|
3
3
|
export type CancelAnimationFrame = (handle: number) => void | undefined;
|
|
4
4
|
export declare class Message {
|
|
5
5
|
get canConflate(): boolean;
|
|
@@ -13,6 +13,7 @@ export declare class Dispatch<T extends Message = Message> {
|
|
|
13
13
|
private _observerID;
|
|
14
14
|
private _observers;
|
|
15
15
|
private _messageBuffer;
|
|
16
|
+
private _rafHandle;
|
|
16
17
|
constructor();
|
|
17
18
|
private observers;
|
|
18
19
|
private messages;
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function utf8ToBase64(value?: string): string;
|