customized-fabric 1.0.1 → 1.0.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/package.json +2 -1
- package/lib/ClipartObject/constants.js +0 -12
- package/lib/ClipartObject/index.js +0 -145
- package/lib/ClipartObject/interfaces.js +0 -2
- package/lib/ImagePlaceholderObject/constants.js +0 -12
- package/lib/ImagePlaceholderObject/index.js +0 -140
- package/lib/ImagePlaceholderObject/interfaces.js +0 -2
- package/lib/TextInputObject/constants.js +0 -13
- package/lib/TextInputObject/index.js +0 -188
- package/lib/TextInputObject/interfaces.js +0 -2
- package/lib/constants.js +0 -12
- package/lib/interfaces.js +0 -19
- package/lib/objectId/bson_value.js +0 -12
- package/lib/objectId/constants.js +0 -107
- package/lib/objectId/error.js +0 -79
- package/lib/objectId/index.js +0 -281
- package/lib/objectId/parser/utils.js +0 -31
- package/lib/objectId/utils/byte_utils.js +0 -28
- package/lib/objectId/utils/node_byte_utils.js +0 -98
- package/lib/objectId/utils/web_byte_utils.js +0 -124
- package/lib/utils.js +0 -90
@@ -1,124 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.webByteUtils = exports.webMathRandomBytes = void 0;
|
4
|
-
const error_1 = require("../error");
|
5
|
-
function isReactNative() {
|
6
|
-
const { navigator } = globalThis;
|
7
|
-
return typeof navigator === "object" && navigator.product === "ReactNative";
|
8
|
-
}
|
9
|
-
/** @internal */
|
10
|
-
function webMathRandomBytes(byteLength) {
|
11
|
-
if (byteLength < 0) {
|
12
|
-
throw new RangeError(`The argument 'byteLength' is invalid. Received ${byteLength}`);
|
13
|
-
}
|
14
|
-
return exports.webByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
|
15
|
-
}
|
16
|
-
exports.webMathRandomBytes = webMathRandomBytes;
|
17
|
-
/** @internal */
|
18
|
-
const webRandomBytes = (() => {
|
19
|
-
const { crypto } = globalThis;
|
20
|
-
if (crypto != null && typeof crypto.getRandomValues === "function") {
|
21
|
-
return (byteLength) => {
|
22
|
-
// @ts-expect-error: crypto.getRandomValues cannot actually be null here
|
23
|
-
// You cannot separate getRandomValues from crypto (need to have this === crypto)
|
24
|
-
return crypto.getRandomValues(exports.webByteUtils.allocate(byteLength));
|
25
|
-
};
|
26
|
-
}
|
27
|
-
else {
|
28
|
-
if (isReactNative()) {
|
29
|
-
const { console } = globalThis;
|
30
|
-
console?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.");
|
31
|
-
}
|
32
|
-
return webMathRandomBytes;
|
33
|
-
}
|
34
|
-
})();
|
35
|
-
const HEX_DIGIT = /(\d|[a-f])/i;
|
36
|
-
/** @internal */
|
37
|
-
exports.webByteUtils = {
|
38
|
-
toLocalBufferType(potentialUint8array) {
|
39
|
-
const stringTag = potentialUint8array?.[Symbol.toStringTag] ??
|
40
|
-
Object.prototype.toString.call(potentialUint8array);
|
41
|
-
if (stringTag === "Uint8Array") {
|
42
|
-
return potentialUint8array;
|
43
|
-
}
|
44
|
-
if (ArrayBuffer.isView(potentialUint8array)) {
|
45
|
-
return new Uint8Array(potentialUint8array.buffer.slice(potentialUint8array.byteOffset, potentialUint8array.byteOffset + potentialUint8array.byteLength));
|
46
|
-
}
|
47
|
-
if (stringTag === "ArrayBuffer" ||
|
48
|
-
stringTag === "SharedArrayBuffer" ||
|
49
|
-
stringTag === "[object ArrayBuffer]" ||
|
50
|
-
stringTag === "[object SharedArrayBuffer]") {
|
51
|
-
return new Uint8Array(potentialUint8array);
|
52
|
-
}
|
53
|
-
throw new error_1.BSONError(`Cannot make a Uint8Array from ${String(potentialUint8array)}`);
|
54
|
-
},
|
55
|
-
allocate(size) {
|
56
|
-
if (typeof size !== "number") {
|
57
|
-
throw new TypeError(`The "size" argument must be of type number. Received ${String(size)}`);
|
58
|
-
}
|
59
|
-
return new Uint8Array(size);
|
60
|
-
},
|
61
|
-
equals(a, b) {
|
62
|
-
if (a.byteLength !== b.byteLength) {
|
63
|
-
return false;
|
64
|
-
}
|
65
|
-
for (let i = 0; i < a.byteLength; i++) {
|
66
|
-
if (a[i] !== b[i]) {
|
67
|
-
return false;
|
68
|
-
}
|
69
|
-
}
|
70
|
-
return true;
|
71
|
-
},
|
72
|
-
fromNumberArray(array) {
|
73
|
-
return Uint8Array.from(array);
|
74
|
-
},
|
75
|
-
fromBase64(base64) {
|
76
|
-
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
77
|
-
},
|
78
|
-
toBase64(uint8array) {
|
79
|
-
return btoa(exports.webByteUtils.toISO88591(uint8array));
|
80
|
-
},
|
81
|
-
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
|
82
|
-
fromISO88591(codePoints) {
|
83
|
-
return Uint8Array.from(codePoints, (c) => c.charCodeAt(0) & 0xff);
|
84
|
-
},
|
85
|
-
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
|
86
|
-
toISO88591(uint8array) {
|
87
|
-
return Array.from(Uint16Array.from(uint8array), (b) => String.fromCharCode(b)).join("");
|
88
|
-
},
|
89
|
-
fromHex(hex) {
|
90
|
-
const evenLengthHex = hex.length % 2 === 0 ? hex : hex.slice(0, hex.length - 1);
|
91
|
-
const buffer = [];
|
92
|
-
for (let i = 0; i < evenLengthHex.length; i += 2) {
|
93
|
-
const firstDigit = evenLengthHex[i];
|
94
|
-
const secondDigit = evenLengthHex[i + 1];
|
95
|
-
if (!HEX_DIGIT.test(firstDigit)) {
|
96
|
-
break;
|
97
|
-
}
|
98
|
-
if (!HEX_DIGIT.test(secondDigit)) {
|
99
|
-
break;
|
100
|
-
}
|
101
|
-
const hexDigit = Number.parseInt(`${firstDigit}${secondDigit}`, 16);
|
102
|
-
buffer.push(hexDigit);
|
103
|
-
}
|
104
|
-
return Uint8Array.from(buffer);
|
105
|
-
},
|
106
|
-
toHex(uint8array) {
|
107
|
-
return Array.from(uint8array, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
108
|
-
},
|
109
|
-
fromUTF8(text) {
|
110
|
-
return new TextEncoder().encode(text);
|
111
|
-
},
|
112
|
-
toUTF8(uint8array, start, end) {
|
113
|
-
return new TextDecoder("utf8", { fatal: false }).decode(uint8array.slice(start, end));
|
114
|
-
},
|
115
|
-
utf8ByteLength(input) {
|
116
|
-
return exports.webByteUtils.fromUTF8(input).byteLength;
|
117
|
-
},
|
118
|
-
encodeUTF8Into(buffer, source, byteOffset) {
|
119
|
-
const bytes = exports.webByteUtils.fromUTF8(source);
|
120
|
-
buffer.set(bytes, byteOffset);
|
121
|
-
return bytes.byteLength;
|
122
|
-
},
|
123
|
-
randomBytes: webRandomBytes,
|
124
|
-
};
|
package/lib/utils.js
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getObject = exports.lockAllObjects = exports.lockObject = exports.loadImageFromFile = exports.isFontLoaded = exports.loadFontFromUrl = void 0;
|
4
|
-
const fabric_1 = require("fabric");
|
5
|
-
const constants_1 = require("./constants");
|
6
|
-
const _1 = require(".");
|
7
|
-
const ImagePlaceholderObject_1 = require("./ImagePlaceholderObject");
|
8
|
-
const loadFontFromUrl = async (name, url) => {
|
9
|
-
if (!name || !url)
|
10
|
-
return;
|
11
|
-
const font = new FontFace(name, `url(${url})`);
|
12
|
-
await font.load();
|
13
|
-
document.fonts.add(font);
|
14
|
-
};
|
15
|
-
exports.loadFontFromUrl = loadFontFromUrl;
|
16
|
-
const isFontLoaded = (name) => {
|
17
|
-
let isLoaded = false;
|
18
|
-
document.fonts.forEach((font) => {
|
19
|
-
if (name == font.family) {
|
20
|
-
isLoaded = true;
|
21
|
-
}
|
22
|
-
});
|
23
|
-
return isLoaded;
|
24
|
-
};
|
25
|
-
exports.isFontLoaded = isFontLoaded;
|
26
|
-
const loadImageFromFile = (image) => {
|
27
|
-
return new Promise((resolve) => {
|
28
|
-
const reader = new FileReader();
|
29
|
-
reader.onload = function (event) {
|
30
|
-
const image = new Image();
|
31
|
-
image.src = event?.target?.result;
|
32
|
-
image.onload = function () {
|
33
|
-
resolve(new fabric_1.fabric.Image(image));
|
34
|
-
};
|
35
|
-
};
|
36
|
-
reader.readAsDataURL(image);
|
37
|
-
});
|
38
|
-
};
|
39
|
-
exports.loadImageFromFile = loadImageFromFile;
|
40
|
-
const lockObject = (object, locked, selectable) => {
|
41
|
-
object.set({
|
42
|
-
hasControls: !locked,
|
43
|
-
lockMovementX: locked,
|
44
|
-
lockMovementY: locked,
|
45
|
-
lockRotation: locked,
|
46
|
-
lockScalingX: locked,
|
47
|
-
lockScalingY: locked,
|
48
|
-
lockUniScaling: locked,
|
49
|
-
lockSkewingX: locked,
|
50
|
-
lockSkewingY: locked,
|
51
|
-
lockScalingFlip: locked,
|
52
|
-
locked: locked,
|
53
|
-
selectable: selectable ?? !locked,
|
54
|
-
});
|
55
|
-
};
|
56
|
-
exports.lockObject = lockObject;
|
57
|
-
const lockAllObjects = (canvas, locked) => {
|
58
|
-
canvas._objects.map((object) => {
|
59
|
-
(0, exports.lockObject)(object, locked);
|
60
|
-
});
|
61
|
-
};
|
62
|
-
exports.lockAllObjects = lockAllObjects;
|
63
|
-
const getObject = (object, options) => {
|
64
|
-
switch (object.type) {
|
65
|
-
case constants_1.OBJECT_TYPES.textInput: {
|
66
|
-
const textInputObject = new _1.TextInput({
|
67
|
-
...object,
|
68
|
-
hideStroke: options?.isOriginal,
|
69
|
-
});
|
70
|
-
return textInputObject;
|
71
|
-
}
|
72
|
-
case constants_1.OBJECT_TYPES.clipart: {
|
73
|
-
const clipartObject = new _1.Clipart({
|
74
|
-
...object,
|
75
|
-
hideStroke: options?.isOriginal,
|
76
|
-
});
|
77
|
-
return clipartObject;
|
78
|
-
}
|
79
|
-
case constants_1.OBJECT_TYPES.imagePlaceHolder: {
|
80
|
-
const imagePlaceHolderObject = new ImagePlaceholderObject_1.ImagePlaceholder({
|
81
|
-
...object,
|
82
|
-
hideStroke: options?.isOriginal,
|
83
|
-
});
|
84
|
-
return imagePlaceHolderObject;
|
85
|
-
}
|
86
|
-
default:
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
};
|
90
|
-
exports.getObject = getObject;
|