@dan-uni/dan-any 0.7.7 → 0.7.8

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 CHANGED
@@ -8,7 +8,8 @@ import { Expose, plainToInstance } from "class-transformer";
8
8
  import { IsDate, IsEmail, IsEnum, IsInt, IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min, validateOrReject } from "class-validator";
9
9
  import hh_mm_ss from "hh-mm-ss";
10
10
  import jssha from "jssha";
11
- import { createCanvas } from "canvas";
11
+ import { Canvas as external_fabric_Canvas } from "fabric";
12
+ import { StaticCanvas } from "fabric/node";
12
13
  import { brotliCompressSync, brotliDecompressSync, gunzipSync, gzipSync } from "node:zlib";
13
14
  import { decode, encode as external_base16384_encode } from "base16384";
14
15
  var __webpack_require__ = {};
@@ -1433,7 +1434,17 @@ const splitGrids = ({ fontSize, padding, playResY, bottomSpace })=>{
1433
1434
  };
1434
1435
  };
1435
1436
  const measureTextWidth = (()=>{
1436
- const canvasContext = createCanvas(50, 50).getContext('2d');
1437
+ let isWeb;
1438
+ try {
1439
+ isWeb = !!window;
1440
+ } catch {
1441
+ isWeb = false;
1442
+ }
1443
+ const Canvas = isWeb ? external_fabric_Canvas : StaticCanvas;
1444
+ const canvasContext = new Canvas(void 0, {
1445
+ width: 50,
1446
+ height: 50
1447
+ }).getContext();
1437
1448
  const supportTextMeasure = !!canvasContext.measureText("\u4E2D");
1438
1449
  if (supportTextMeasure) return (fontName, fontSize, bold, text)=>{
1439
1450
  canvasContext.font = `${bold ? 'bold' : 'normal'} ${fontSize}px ${fontName}`;