@midscene/shared 0.7.2 → 0.7.3-beta-20241104100519.0

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/es/img.js CHANGED
@@ -1,27 +1,74 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
1
22
  // src/img/info.ts
2
23
  import assert from "assert";
3
- import { Buffer } from "buffer";
24
+ import { Buffer as Buffer2 } from "buffer";
4
25
  import { readFileSync } from "fs";
5
- import Jimp from "jimp";
6
- async function imageInfo(image) {
7
- let jimpImage;
8
- if (typeof image === "string") {
9
- jimpImage = await Jimp.read(image);
10
- } else if (Buffer.isBuffer(image)) {
11
- jimpImage = await Jimp.read(image);
12
- } else {
13
- throw new Error("Invalid image input: must be a string path or a Buffer");
14
- }
15
- const { width, height } = jimpImage.bitmap;
16
- assert(
17
- width && height,
18
- `Invalid image: ${typeof image === "string" ? image : "Buffer"}`
19
- );
20
- return { width, height };
26
+
27
+ // src/img/get-jimp.ts
28
+ var ifInBrowser = typeof window !== "undefined";
29
+ function getJimp() {
30
+ return __async(this, null, function* () {
31
+ if (ifInBrowser) {
32
+ yield import("jimp/browser/lib/jimp.js");
33
+ return window.Jimp;
34
+ }
35
+ return (yield import("jimp")).default;
36
+ });
21
37
  }
22
- async function imageInfoOfBase64(imageBase64) {
23
- const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, "");
24
- return imageInfo(Buffer.from(base64Data, "base64"));
38
+
39
+ // src/img/info.ts
40
+ function imageInfo(image) {
41
+ return __async(this, null, function* () {
42
+ const Jimp = yield getJimp();
43
+ let jimpImage;
44
+ if (typeof image === "string") {
45
+ jimpImage = yield Jimp.read(image);
46
+ } else if (Buffer2.isBuffer(image)) {
47
+ jimpImage = yield Jimp.read(image);
48
+ } else if (image instanceof Jimp) {
49
+ jimpImage = image;
50
+ } else {
51
+ throw new Error("Invalid image input: must be a string path or a Buffer");
52
+ }
53
+ const { width, height } = jimpImage.bitmap;
54
+ assert(
55
+ width && height,
56
+ `Invalid image: ${typeof image === "string" ? image : "Buffer"}`
57
+ );
58
+ return { width, height, jimpImage };
59
+ });
60
+ }
61
+ function imageInfoOfBase64(imageBase64) {
62
+ return __async(this, null, function* () {
63
+ const buffer = yield bufferFromBase64(imageBase64);
64
+ return imageInfo(buffer);
65
+ });
66
+ }
67
+ function bufferFromBase64(imageBase64) {
68
+ return __async(this, null, function* () {
69
+ const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, "");
70
+ return Buffer2.from(base64Data, "base64");
71
+ });
25
72
  }
26
73
  function base64Encoded(image, withHeader = true) {
27
74
  const imageBuffer = readFileSync(image);
@@ -41,32 +88,53 @@ function base64ToPngFormat(base64) {
41
88
  }
42
89
 
43
90
  // src/img/transform.ts
44
- import { Buffer as Buffer2 } from "buffer";
45
- import Jimp2 from "jimp";
46
- async function saveBase64Image(options) {
47
- const { base64Data, outputPath } = options;
48
- const base64Image = base64Data.split(";base64,").pop() || base64Data;
49
- const imageBuffer = Buffer2.from(base64Image, "base64");
50
- const image = await Jimp2.read(imageBuffer);
51
- await image.writeAsync(outputPath);
91
+ import { Buffer as Buffer3 } from "buffer";
92
+ function saveBase64Image(options) {
93
+ return __async(this, null, function* () {
94
+ const { base64Data, outputPath } = options;
95
+ const base64Image = base64Data.split(";base64,").pop() || base64Data;
96
+ const imageBuffer = Buffer3.from(base64Image, "base64");
97
+ const Jimp = yield getJimp();
98
+ const image = yield Jimp.read(imageBuffer);
99
+ yield image.writeAsync(outputPath);
100
+ });
52
101
  }
53
- async function transformImgPathToBase64(inputPath) {
54
- const image = await Jimp2.read(inputPath);
55
- const buffer = await image.getBufferAsync(Jimp2.MIME_PNG);
56
- return buffer.toString("base64");
102
+ function transformImgPathToBase64(inputPath) {
103
+ return __async(this, null, function* () {
104
+ const Jimp = yield getJimp();
105
+ const image = yield Jimp.read(inputPath);
106
+ const buffer = yield image.getBufferAsync(Jimp.MIME_PNG);
107
+ return buffer.toString("base64");
108
+ });
57
109
  }
58
- async function resizeImg(inputData, newSize) {
59
- const isBase64 = typeof inputData === "string";
60
- const imageBuffer = isBase64 ? Buffer2.from(inputData.split(";base64,").pop() || inputData, "base64") : inputData;
61
- const image = await Jimp2.read(imageBuffer);
62
- const { width, height } = image.bitmap;
63
- if (!width || !height) {
64
- throw Error("Undefined width or height from the input image.");
65
- }
66
- const finalNewSize = newSize || calculateNewDimensions(width, height);
67
- image.resize(finalNewSize.width, finalNewSize.height);
68
- const resizedBuffer = await image.getBufferAsync(Jimp2.MIME_PNG);
69
- return isBase64 ? resizedBuffer.toString("base64") : resizedBuffer;
110
+ function resizeImg(inputData, newSize) {
111
+ return __async(this, null, function* () {
112
+ if (typeof inputData === "string")
113
+ throw Error("inputData is base64, use resizeImgBase64 instead");
114
+ const Jimp = yield getJimp();
115
+ const image = yield Jimp.read(inputData);
116
+ const { width, height } = image.bitmap;
117
+ if (!width || !height) {
118
+ throw Error("Undefined width or height from the input image.");
119
+ }
120
+ const finalNewSize = newSize || calculateNewDimensions(width, height);
121
+ image.resize(finalNewSize.width, finalNewSize.height);
122
+ const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_PNG);
123
+ return resizedBuffer;
124
+ });
125
+ }
126
+ function resizeImgBase64(inputData, newSize) {
127
+ return __async(this, null, function* () {
128
+ const splitFlag = ";base64,";
129
+ const dataSplitted = inputData.split(splitFlag);
130
+ if (dataSplitted.length !== 2) {
131
+ throw Error("Invalid base64 data");
132
+ }
133
+ const imageBuffer = Buffer3.from(dataSplitted[1], "base64");
134
+ const buffer = yield resizeImg(imageBuffer, newSize);
135
+ const content = buffer.toString("base64");
136
+ return `${dataSplitted[0]}${splitFlag}${content}`;
137
+ });
70
138
  }
71
139
  function calculateNewDimensions(originalWidth, originalHeight) {
72
140
  const maxWidth = 2048;
@@ -87,169 +155,183 @@ function calculateNewDimensions(originalWidth, originalHeight) {
87
155
  height: Math.round(newHeight)
88
156
  };
89
157
  }
90
- async function trimImage(image) {
91
- const jimpImage = await Jimp2.read(
92
- Buffer2.isBuffer(image) ? image : Buffer2.from(image)
93
- );
94
- const { width, height } = jimpImage.bitmap;
95
- if (width <= 3 || height <= 3) {
96
- return null;
97
- }
98
- const trimmedImage = jimpImage.autocrop();
99
- const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap;
100
- const trimOffsetLeft = (width - trimmedWidth) / 2;
101
- const trimOffsetTop = (height - trimmedHeight) / 2;
102
- if (trimOffsetLeft === 0 && trimOffsetTop === 0) {
103
- return null;
104
- }
105
- return {
106
- trimOffsetLeft: -trimOffsetLeft,
107
- trimOffsetTop: -trimOffsetTop,
108
- width: trimmedWidth,
109
- height: trimmedHeight
110
- };
158
+ function trimImage(image) {
159
+ return __async(this, null, function* () {
160
+ const Jimp = yield getJimp();
161
+ const jimpImage = yield Jimp.read(
162
+ Buffer3.isBuffer(image) ? image : Buffer3.from(image)
163
+ );
164
+ const { width, height } = jimpImage.bitmap;
165
+ if (width <= 3 || height <= 3) {
166
+ return null;
167
+ }
168
+ const trimmedImage = jimpImage.autocrop();
169
+ const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap;
170
+ const trimOffsetLeft = (width - trimmedWidth) / 2;
171
+ const trimOffsetTop = (height - trimmedHeight) / 2;
172
+ if (trimOffsetLeft === 0 && trimOffsetTop === 0) {
173
+ return null;
174
+ }
175
+ return {
176
+ trimOffsetLeft: -trimOffsetLeft,
177
+ trimOffsetTop: -trimOffsetTop,
178
+ width: trimmedWidth,
179
+ height: trimmedHeight
180
+ };
181
+ });
111
182
  }
112
183
 
113
184
  // src/img/box-select.ts
114
185
  import assert2 from "assert";
115
- import { Buffer as Buffer3 } from "buffer";
116
- import Jimp3 from "jimp";
117
- var createSvgOverlay = (elements, imageWidth, imageHeight) => {
118
- const createPngOverlay = async (elements2, imageWidth2, imageHeight2) => {
119
- const image = new Jimp3(imageWidth2, imageHeight2, 0);
120
- const colors = [
121
- { rect: 4278190335, text: 4294967295 }
122
- // red, white
123
- // { rect: 0x0000ffff, text: 0xffffffff }, // blue, white
124
- // { rect: 0x8b4513ff, text: 0xffffffff }, // brown, white
125
- ];
126
- const boxPadding = 5;
127
- for (let index = 0; index < elements2.length; index++) {
128
- const element = elements2[index];
129
- const color = colors[index % colors.length];
130
- const paddedRect = {
131
- left: Math.max(0, element.rect.left - boxPadding),
132
- top: Math.max(0, element.rect.top - boxPadding),
133
- width: Math.min(
134
- imageWidth2 - element.rect.left,
135
- element.rect.width + boxPadding * 2
136
- ),
137
- height: Math.min(
138
- imageHeight2 - element.rect.top,
139
- element.rect.height + boxPadding * 2
140
- )
141
- };
142
- image.scan(
143
- paddedRect.left,
144
- paddedRect.top,
145
- paddedRect.width,
146
- paddedRect.height,
147
- function(x, y, idx) {
148
- if (x === paddedRect.left || x === paddedRect.left + paddedRect.width - 1 || y === paddedRect.top || y === paddedRect.top + paddedRect.height - 1) {
149
- this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
150
- this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
151
- this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
152
- this.bitmap.data[idx + 3] = color.rect & 255;
153
- }
154
- }
155
- );
156
- const textWidth = element.indexId.toString().length * 8;
157
- const textHeight = 12;
158
- const rectWidth = textWidth + 5;
159
- const rectHeight = textHeight + 4;
160
- let rectX = paddedRect.left - rectWidth;
161
- let rectY = paddedRect.top + paddedRect.height / 2 - textHeight / 2 - 2;
162
- const checkOverlap = (x, y) => {
163
- return elements2.slice(0, index).some((otherElement) => {
164
- return x < otherElement.rect.left + otherElement.rect.width && x + rectWidth > otherElement.rect.left && y < otherElement.rect.top + otherElement.rect.height && y + rectHeight > otherElement.rect.top;
165
- });
166
- };
167
- const isWithinBounds = (x, y) => {
168
- return x >= 0 && x + rectWidth <= imageWidth2 && y >= 0 && y + rectHeight <= imageHeight2;
169
- };
170
- if (checkOverlap(rectX, rectY) || !isWithinBounds(rectX, rectY)) {
171
- if (!checkOverlap(paddedRect.left, paddedRect.top - rectHeight - 2) && isWithinBounds(paddedRect.left, paddedRect.top - rectHeight - 2)) {
172
- rectX = paddedRect.left;
173
- rectY = paddedRect.top - rectHeight - 2;
174
- } else if (!checkOverlap(
175
- paddedRect.left,
176
- paddedRect.top + paddedRect.height + 2
177
- ) && isWithinBounds(
178
- paddedRect.left,
179
- paddedRect.top + paddedRect.height + 2
180
- )) {
181
- rectX = paddedRect.left;
182
- rectY = paddedRect.top + paddedRect.height + 2;
183
- } else if (!checkOverlap(
184
- paddedRect.left + paddedRect.width + 2,
185
- paddedRect.top
186
- ) && isWithinBounds(paddedRect.left + paddedRect.width + 2, paddedRect.top)) {
187
- rectX = paddedRect.left + paddedRect.width + 2;
188
- rectY = paddedRect.top;
189
- } else {
190
- rectX = paddedRect.left;
191
- rectY = paddedRect.top + 2;
186
+ var cachedFont = null;
187
+ var createSvgOverlay = (elements, imageWidth, imageHeight) => __async(void 0, null, function* () {
188
+ const Jimp = yield getJimp();
189
+ const image = new Jimp(imageWidth, imageHeight, 0);
190
+ const colors = [
191
+ { rect: 4278190335, text: 4294967295 }
192
+ // red, white
193
+ // { rect: 0x0000ffff, text: 0xffffffff }, // blue, white
194
+ // { rect: 0x8b4513ff, text: 0xffffffff }, // brown, white
195
+ ];
196
+ const boxPadding = 5;
197
+ for (let index = 0; index < elements.length; index++) {
198
+ const element = elements[index];
199
+ const color = colors[index % colors.length];
200
+ const paddedRect = {
201
+ left: Math.max(0, element.rect.left - boxPadding),
202
+ top: Math.max(0, element.rect.top - boxPadding),
203
+ width: Math.min(
204
+ imageWidth - element.rect.left,
205
+ element.rect.width + boxPadding * 2
206
+ ),
207
+ height: Math.min(
208
+ imageHeight - element.rect.top,
209
+ element.rect.height + boxPadding * 2
210
+ )
211
+ };
212
+ image.scan(
213
+ paddedRect.left,
214
+ paddedRect.top,
215
+ paddedRect.width,
216
+ paddedRect.height,
217
+ function(x, y, idx) {
218
+ if (x === paddedRect.left || x === paddedRect.left + paddedRect.width - 1 || y === paddedRect.top || y === paddedRect.top + paddedRect.height - 1) {
219
+ this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
220
+ this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
221
+ this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
222
+ this.bitmap.data[idx + 3] = color.rect & 255;
192
223
  }
193
224
  }
194
- image.scan(rectX, rectY, rectWidth, rectHeight, function(x, y, idx) {
195
- this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
196
- this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
197
- this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
198
- this.bitmap.data[idx + 3] = color.rect & 255;
225
+ );
226
+ const textWidth = element.indexId.toString().length * 8;
227
+ const textHeight = 12;
228
+ const rectWidth = textWidth + 5;
229
+ const rectHeight = textHeight + 4;
230
+ let rectX = paddedRect.left - rectWidth;
231
+ let rectY = paddedRect.top + paddedRect.height / 2 - textHeight / 2 - 2;
232
+ const checkOverlap = (x, y) => {
233
+ return elements.slice(0, index).some((otherElement) => {
234
+ return x < otherElement.rect.left + otherElement.rect.width && x + rectWidth > otherElement.rect.left && y < otherElement.rect.top + otherElement.rect.height && y + rectHeight > otherElement.rect.top;
199
235
  });
200
- const font = await Jimp3.loadFont(Jimp3.FONT_SANS_16_WHITE);
201
- image.print(
202
- font,
203
- rectX,
204
- rectY,
205
- {
206
- text: element.indexId.toString(),
207
- alignmentX: Jimp3.HORIZONTAL_ALIGN_CENTER,
208
- alignmentY: Jimp3.VERTICAL_ALIGN_MIDDLE
209
- },
210
- rectWidth,
211
- rectHeight
212
- );
236
+ };
237
+ const isWithinBounds = (x, y) => {
238
+ return x >= 0 && x + rectWidth <= imageWidth && y >= 0 && y + rectHeight <= imageHeight;
239
+ };
240
+ if (checkOverlap(rectX, rectY) || !isWithinBounds(rectX, rectY)) {
241
+ if (!checkOverlap(paddedRect.left, paddedRect.top - rectHeight - 2) && isWithinBounds(paddedRect.left, paddedRect.top - rectHeight - 2)) {
242
+ rectX = paddedRect.left;
243
+ rectY = paddedRect.top - rectHeight - 2;
244
+ } else if (!checkOverlap(
245
+ paddedRect.left,
246
+ paddedRect.top + paddedRect.height + 2
247
+ ) && isWithinBounds(paddedRect.left, paddedRect.top + paddedRect.height + 2)) {
248
+ rectX = paddedRect.left;
249
+ rectY = paddedRect.top + paddedRect.height + 2;
250
+ } else if (!checkOverlap(paddedRect.left + paddedRect.width + 2, paddedRect.top) && isWithinBounds(paddedRect.left + paddedRect.width + 2, paddedRect.top)) {
251
+ rectX = paddedRect.left + paddedRect.width + 2;
252
+ rectY = paddedRect.top;
253
+ } else {
254
+ rectX = paddedRect.left;
255
+ rectY = paddedRect.top + 2;
256
+ }
213
257
  }
214
- return image.getBufferAsync(Jimp3.MIME_PNG);
215
- };
216
- return createPngOverlay(elements, imageWidth, imageHeight);
217
- };
218
- var compositeElementInfoImg = async (options) => {
219
- const { inputImgBase64, elementsPositionInfo } = options;
220
- const imageBuffer = Buffer3.from(inputImgBase64, "base64");
221
- const image = await Jimp3.read(imageBuffer);
222
- const { width, height } = image.bitmap;
258
+ image.scan(rectX, rectY, rectWidth, rectHeight, function(x, y, idx) {
259
+ this.bitmap.data[idx + 0] = color.rect >> 24 & 255;
260
+ this.bitmap.data[idx + 1] = color.rect >> 16 & 255;
261
+ this.bitmap.data[idx + 2] = color.rect >> 8 & 255;
262
+ this.bitmap.data[idx + 3] = color.rect & 255;
263
+ });
264
+ try {
265
+ cachedFont = cachedFont || (yield Jimp.loadFont(Jimp.FONT_SANS_16_WHITE));
266
+ } catch (error) {
267
+ console.error("Error loading font", error);
268
+ }
269
+ image.print(
270
+ cachedFont,
271
+ rectX,
272
+ rectY,
273
+ {
274
+ text: element.indexId.toString(),
275
+ alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
276
+ alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
277
+ },
278
+ rectWidth,
279
+ rectHeight
280
+ );
281
+ }
282
+ return image;
283
+ });
284
+ var compositeElementInfoImg = (options) => __async(void 0, null, function* () {
285
+ assert2(options.inputImgBase64, "inputImgBase64 is required");
286
+ let width = 0;
287
+ let height = 0;
288
+ let jimpImage;
289
+ const Jimp = yield getJimp();
290
+ if (options.size) {
291
+ width = options.size.width;
292
+ height = options.size.height;
293
+ }
294
+ if (!width || !height) {
295
+ const info = yield imageInfoOfBase64(options.inputImgBase64);
296
+ width = info.width;
297
+ height = info.height;
298
+ jimpImage = info.jimpImage;
299
+ } else {
300
+ const imageBuffer = yield bufferFromBase64(options.inputImgBase64);
301
+ jimpImage = yield Jimp.read(imageBuffer);
302
+ }
223
303
  if (!width || !height) {
224
304
  throw Error("Image processing failed because width or height is undefined");
225
305
  }
226
- const svgOverlay = await createSvgOverlay(
227
- elementsPositionInfo,
228
- width,
229
- height
230
- );
231
- return await Jimp3.read(imageBuffer).then(async (image2) => {
232
- const svgImage = await Jimp3.read(svgOverlay);
233
- return image2.composite(svgImage, 0, 0, {
234
- mode: Jimp3.BLEND_SOURCE_OVER,
306
+ const { elementsPositionInfo } = options;
307
+ const result = yield Promise.resolve(jimpImage).then((image) => __async(void 0, null, function* () {
308
+ const svgOverlay = yield createSvgOverlay(
309
+ elementsPositionInfo,
310
+ width,
311
+ height
312
+ );
313
+ const svgImage = yield Jimp.read(svgOverlay);
314
+ const compositeImage = yield image.composite(svgImage, 0, 0, {
315
+ mode: Jimp.BLEND_SOURCE_OVER,
235
316
  opacitySource: 1,
236
317
  opacityDest: 1
237
318
  });
238
- }).then((compositeImage) => {
239
- return compositeImage.getBufferAsync(Jimp3.MIME_PNG);
240
- }).then((buffer) => {
241
- return buffer.toString("base64");
242
- }).catch((error) => {
319
+ return compositeImage;
320
+ })).then((compositeImage) => __async(void 0, null, function* () {
321
+ const base64 = yield compositeImage.getBase64Async(Jimp.MIME_PNG);
322
+ return base64;
323
+ })).catch((error) => {
243
324
  throw error;
244
325
  });
245
- };
246
- var processImageElementInfo = async (options) => {
326
+ return result;
327
+ });
328
+ var processImageElementInfo = (options) => __async(void 0, null, function* () {
247
329
  const base64Image = options.inputImgBase64.split(";base64,").pop();
248
330
  assert2(base64Image, "base64Image is undefined");
249
331
  const [
250
332
  compositeElementInfoImgBase64,
251
333
  compositeElementInfoImgWithoutTextBase64
252
- ] = await Promise.all([
334
+ ] = yield Promise.all([
253
335
  compositeElementInfoImg({
254
336
  inputImgBase64: options.inputImgBase64,
255
337
  elementsPositionInfo: options.elementsPositionInfo
@@ -263,16 +345,18 @@ var processImageElementInfo = async (options) => {
263
345
  compositeElementInfoImgBase64,
264
346
  compositeElementInfoImgWithoutTextBase64
265
347
  };
266
- };
348
+ });
267
349
  export {
268
350
  base64Encoded,
269
351
  base64ToPngFormat,
352
+ bufferFromBase64,
270
353
  calculateNewDimensions,
271
354
  compositeElementInfoImg,
272
355
  imageInfo,
273
356
  imageInfoOfBase64,
274
357
  processImageElementInfo,
275
358
  resizeImg,
359
+ resizeImgBase64,
276
360
  saveBase64Image,
277
361
  transformImgPathToBase64,
278
362
  trimImage
@@ -0,0 +1,3 @@
1
+ declare const _default: {};
2
+
3
+ export { _default as default };
package/dist/es/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // src/index.ts
2
- function src_default() {
3
- return "hello world";
4
- }
2
+ var src_default = {};
5
3
  export {
6
4
  src_default as default
7
5
  };
@@ -0,0 +1,4 @@
1
+ declare const ifInBrowser: boolean;
2
+ declare function uuid(): string;
3
+
4
+ export { ifInBrowser, uuid };
@@ -0,0 +1,13 @@
1
+ // src/utils.ts
2
+ import { randomUUID } from "crypto";
3
+ var ifInBrowser = typeof window !== "undefined";
4
+ function uuid() {
5
+ if (ifInBrowser) {
6
+ return Math.random().toString(36).substring(2, 15);
7
+ }
8
+ return randomUUID();
9
+ }
10
+ export {
11
+ ifInBrowser,
12
+ uuid
13
+ };
@@ -0,0 +1,13 @@
1
+ declare const TEXT_SIZE_THRESHOLD = 9;
2
+ declare const TEXT_MAX_SIZE = 40;
3
+ declare const CONTAINER_MINI_HEIGHT = 3;
4
+ declare const CONTAINER_MINI_WIDTH = 3;
5
+ declare enum NodeType {
6
+ CONTAINER = "CONTAINER Node",
7
+ FORM_ITEM = "FORM_ITEM Node",
8
+ BUTTON = "BUTTON Node",
9
+ IMG = "IMG Node",
10
+ TEXT = "TEXT Node"
11
+ }
12
+
13
+ export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, NodeType, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD };
@@ -0,0 +1,14 @@
1
+ interface PkgInfo {
2
+ name: string;
3
+ version: string;
4
+ dir: string;
5
+ }
6
+ declare function getRunningPkgInfo(dir?: string): PkgInfo | null;
7
+ /**
8
+ * Find the nearest package.json file recursively
9
+ * @param {string} dir - Home directory
10
+ * @returns {string|null} - The most recent package.json file path or null
11
+ */
12
+ declare function findNearestPackageJson(dir: string): string | null;
13
+
14
+ export { findNearestPackageJson, getRunningPkgInfo };