@dan-uni/dan-any 0.7.6 → 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__ = {};
@@ -254,6 +255,7 @@ class UniDM {
254
255
  this.options = options || this.options;
255
256
  const def = new UniDM();
256
257
  if (void 0 === this.options.dmid || true === this.options.dmid) this.options.dmid = createDMID;
258
+ this.content = String(this.content);
257
259
  if (!this.SOID) this.SOID = def.SOID;
258
260
  if (!this.progress) this.progress = def.progress;
259
261
  if (!this.mode) this.mode = def.mode;
@@ -1432,7 +1434,17 @@ const splitGrids = ({ fontSize, padding, playResY, bottomSpace })=>{
1432
1434
  };
1433
1435
  };
1434
1436
  const measureTextWidth = (()=>{
1435
- 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();
1436
1448
  const supportTextMeasure = !!canvasContext.measureText("\u4E2D");
1437
1449
  if (supportTextMeasure) return (fontName, fontSize, bold, text)=>{
1438
1450
  canvasContext.font = `${bold ? 'bold' : 'normal'} ${fontSize}px ${fontName}`;