@hprint/core 0.0.6 → 0.0.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.mjs CHANGED
@@ -336,7 +336,7 @@ var Sn = {
336
336
  ctrlKey: 17,
337
337
  altKey: 18,
338
338
  metaKey: 91
339
- }, vt = {
339
+ }, _t = {
340
340
  16: !1,
341
341
  18: !1,
342
342
  17: !1,
@@ -374,8 +374,8 @@ function Or(f, r) {
374
374
  }
375
375
  function Er(f) {
376
376
  var r = f.keyCode || f.which || f.charCode, g = ft.indexOf(r);
377
- if (g >= 0 && ft.splice(g, 1), f.key && f.key.toLowerCase() === "meta" && ft.splice(0, ft.length), (r === 93 || r === 224) && (r = 91), r in vt) {
378
- vt[r] = !1;
377
+ if (g >= 0 && ft.splice(g, 1), f.key && f.key.toLowerCase() === "meta" && ft.splice(0, ft.length), (r === 93 || r === 224) && (r = 91), r in _t) {
378
+ _t[r] = !1;
379
379
  for (var _ in $t)
380
380
  $t[_] === r && (It[_] = !1);
381
381
  }
@@ -422,9 +422,9 @@ function qi(f, r, g, _) {
422
422
  var y;
423
423
  if (r.scope === g || r.scope === "all") {
424
424
  y = r.mods.length > 0;
425
- for (var C in vt)
426
- Object.prototype.hasOwnProperty.call(vt, C) && (!vt[C] && r.mods.indexOf(+C) > -1 || vt[C] && r.mods.indexOf(+C) === -1) && (y = !1);
427
- (r.mods.length === 0 && !vt[16] && !vt[18] && !vt[17] && !vt[91] || y || r.shortcut === "*") && r.method(f, r) === !1 && (f.preventDefault ? f.preventDefault() : f.returnValue = !1, f.stopPropagation && f.stopPropagation(), f.cancelBubble && (f.cancelBubble = !0));
425
+ for (var C in _t)
426
+ Object.prototype.hasOwnProperty.call(_t, C) && (!_t[C] && r.mods.indexOf(+C) > -1 || _t[C] && r.mods.indexOf(+C) === -1) && (y = !1);
427
+ (r.mods.length === 0 && !_t[16] && !_t[18] && !_t[17] && !_t[91] || y || r.shortcut === "*") && r.method(f, r) === !1 && (f.preventDefault ? f.preventDefault() : f.returnValue = !1, f.stopPropagation && f.stopPropagation(), f.cancelBubble && (f.cancelBubble = !0));
428
428
  }
429
429
  }
430
430
  }
@@ -434,15 +434,15 @@ function Ki(f, r) {
434
434
  if ((_ === 93 || _ === 224) && (_ = 91), ft.indexOf(_) === -1 && _ !== 229 && ft.push(_), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach(function(o) {
435
435
  var h = zi[o];
436
436
  f[o] && ft.indexOf(h) === -1 ? ft.push(h) : !f[o] && ft.indexOf(h) > -1 ? ft.splice(ft.indexOf(h), 1) : o === "metaKey" && f[o] && ft.length === 3 && (f.ctrlKey || f.shiftKey || f.altKey || (ft = ft.slice(ft.indexOf(h))));
437
- }), _ in vt) {
438
- vt[_] = !0;
437
+ }), _ in _t) {
438
+ _t[_] = !0;
439
439
  for (var y in $t)
440
440
  $t[y] === _ && (It[y] = !0);
441
441
  if (!g) return;
442
442
  }
443
- for (var C in vt)
444
- Object.prototype.hasOwnProperty.call(vt, C) && (vt[C] = f[zi[C]]);
445
- f.getModifierState && !(f.altKey && !f.ctrlKey) && f.getModifierState("AltGraph") && (ft.indexOf(17) === -1 && ft.push(17), ft.indexOf(18) === -1 && ft.push(18), vt[17] = !0, vt[18] = !0);
443
+ for (var C in _t)
444
+ Object.prototype.hasOwnProperty.call(_t, C) && (_t[C] = f[zi[C]]);
445
+ f.getModifierState && !(f.altKey && !f.ctrlKey) && f.getModifierState("AltGraph") && (ft.indexOf(17) === -1 && ft.push(17), ft.indexOf(18) === -1 && ft.push(18), _t[17] = !0, _t[18] = !0);
446
446
  var T = pe();
447
447
  if (g)
448
448
  for (var c = 0; c < g.length; c++)
@@ -611,11 +611,11 @@ const Lr = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a
611
611
  function Fr(f) {
612
612
  return typeof f == "string" && Lr.test(f);
613
613
  }
614
- var mt = [];
614
+ var vt = [];
615
615
  for (var Je = 0; Je < 256; ++Je)
616
- mt.push((Je + 256).toString(16).substr(1));
616
+ vt.push((Je + 256).toString(16).substr(1));
617
617
  function Rr(f) {
618
- var r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, g = (mt[f[r + 0]] + mt[f[r + 1]] + mt[f[r + 2]] + mt[f[r + 3]] + "-" + mt[f[r + 4]] + mt[f[r + 5]] + "-" + mt[f[r + 6]] + mt[f[r + 7]] + "-" + mt[f[r + 8]] + mt[f[r + 9]] + "-" + mt[f[r + 10]] + mt[f[r + 11]] + mt[f[r + 12]] + mt[f[r + 13]] + mt[f[r + 14]] + mt[f[r + 15]]).toLowerCase();
618
+ var r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, g = (vt[f[r + 0]] + vt[f[r + 1]] + vt[f[r + 2]] + vt[f[r + 3]] + "-" + vt[f[r + 4]] + vt[f[r + 5]] + "-" + vt[f[r + 6]] + vt[f[r + 7]] + "-" + vt[f[r + 8]] + vt[f[r + 9]] + "-" + vt[f[r + 10]] + vt[f[r + 11]] + vt[f[r + 12]] + vt[f[r + 13]] + vt[f[r + 14]] + vt[f[r + 15]]).toLowerCase();
619
619
  if (!Fr(g))
620
620
  throw TypeError("Stringified UUID is invalid");
621
621
  return g;
@@ -20826,7 +20826,7 @@ gl_FragColor.rgb *= color.a;
20826
20826
  })();
20827
20827
  })(si)), si;
20828
20828
  }
20829
- var _t = No(), ue = /* @__PURE__ */ ((f) => (f.ONE = "selectOne", f.MULTI = "selectMultiple", f.CANCEL = "selectCancel", f))(ue || {}), te = /* @__PURE__ */ ((f) => (f.EMPTY = "", f.ONE = "one", f.MULTI = "multiple", f))(te || {});
20829
+ var mt = No(), ue = /* @__PURE__ */ ((f) => (f.ONE = "selectOne", f.MULTI = "selectMultiple", f.CANCEL = "selectCancel", f))(ue || {}), te = /* @__PURE__ */ ((f) => (f.EMPTY = "", f.ONE = "one", f.MULTI = "multiple", f))(te || {});
20830
20830
  function fr(f) {
20831
20831
  f && f.forEach((r) => {
20832
20832
  r.objects ? fr(r.objects) : r.type === "text" && (r.type = "textbox");
@@ -20843,7 +20843,7 @@ const ge = class ge {
20843
20843
  _emitSelectEvent() {
20844
20844
  if (!this.canvas)
20845
20845
  throw TypeError("还未初始化");
20846
- const r = this.canvas.getActiveObjects().filter((g) => !(g instanceof _t.fabric.GuideLine));
20846
+ const r = this.canvas.getActiveObjects().filter((g) => !(g instanceof mt.fabric.GuideLine));
20847
20847
  r && r.length === 1 ? (this.selectedMode = te.ONE, this.editor.emit(ue.ONE, r)) : r && r.length > 1 ? (this.selectedMode = te.MULTI, this.editor.emit(ue.MULTI, r)) : this.editor.emit(ue.CANCEL);
20848
20848
  }
20849
20849
  getSelectMode() {
@@ -20863,7 +20863,7 @@ const ge = class ge {
20863
20863
  renderITextPath(r) {
20864
20864
  r.forEach((g) => {
20865
20865
  const _ = this.canvas.getObjects().find((y) => y.id === g.id);
20866
- _ && _t.fabric.Path.fromObject(g.path, (y) => {
20866
+ _ && mt.fabric.Path.fromObject(g.path, (y) => {
20867
20867
  _.set("path", y);
20868
20868
  });
20869
20869
  });
@@ -20974,7 +20974,7 @@ const ge = class ge {
20974
20974
  saveSvg() {
20975
20975
  this.editor.hooksEntity.hookSaveBefore.callAsync("", () => {
20976
20976
  const { fontOption: r, svgOption: g } = this._getSaveSvgOption();
20977
- _t.fabric.fontPaths = {
20977
+ mt.fabric.fontPaths = {
20978
20978
  ...r
20979
20979
  };
20980
20980
  const _ = this.canvas.toSVG(g), y = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(_)}`;
@@ -21006,6 +21006,26 @@ const ge = class ge {
21006
21006
  });
21007
21007
  });
21008
21008
  }
21009
+ getSVG(r) {
21010
+ return new Promise((g) => {
21011
+ this.editor.hooksEntity.hookSaveBefore.callAsync("", () => {
21012
+ this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
21013
+ const { fontOption: _, svgOption: y } = this._getSaveSvgOption({
21014
+ ignoreFont: !0,
21015
+ width: r?.width,
21016
+ height: r?.height
21017
+ });
21018
+ mt.fabric.fontPaths = {
21019
+ ..._
21020
+ };
21021
+ const C = this.canvas.toSVG(y);
21022
+ this.editor.hooksEntity.hookSaveAfter.callAsync(
21023
+ C,
21024
+ () => g(C)
21025
+ );
21026
+ });
21027
+ });
21028
+ }
21009
21029
  preview() {
21010
21030
  return new Promise((r) => {
21011
21031
  this.editor.hooksEntity.hookSaveBefore.callAsync("", () => {
@@ -21022,27 +21042,28 @@ const ge = class ge {
21022
21042
  return new Promise((r) => {
21023
21043
  });
21024
21044
  }
21025
- _getSaveSvgOption() {
21026
- const r = this.canvas.getObjects().find((l) => l.id === "workspace");
21027
- let g = this.canvas.getObjects().filter((l) => l.type == "textbox").map((l) => l.fontFamily);
21028
- g = Array.from(new Set(g));
21029
- const _ = this.editor.getPlugin("FontPlugin").cacheList, y = {};
21030
- for (const l of g) {
21031
- const a = _.find((t) => t.name === l);
21032
- y[l] = a.file;
21033
- }
21034
- console.log("_getSaveSvgOption", y);
21035
- const { left: C, top: T, width: c, height: i } = r;
21045
+ _getSaveSvgOption(r) {
21046
+ const g = this.canvas.getObjects().find((a) => a.id === "workspace");
21047
+ let _ = this.canvas.getObjects().filter((a) => a.type == "textbox").map((a) => a.fontFamily);
21048
+ _ = Array.from(new Set(_));
21049
+ const y = this.editor.getPlugin("FontPlugin").cacheList, C = {};
21050
+ if (!r?.ignoreFont)
21051
+ for (const a of _) {
21052
+ const t = y.find((n) => n.name === a);
21053
+ C[a] = t.file;
21054
+ }
21055
+ console.log("_getSaveSvgOption", C);
21056
+ const { left: T, top: c, width: i, height: l } = g;
21036
21057
  return {
21037
- fontOption: y,
21058
+ fontOption: C,
21038
21059
  svgOption: {
21039
- width: c,
21040
- height: i,
21060
+ width: r?.width ?? i,
21061
+ height: r?.height ?? l,
21041
21062
  viewBox: {
21042
- x: C,
21043
- y: T,
21044
- width: c,
21045
- height: i
21063
+ x: T,
21064
+ y: c,
21065
+ width: i,
21066
+ height: l
21046
21067
  }
21047
21068
  }
21048
21069
  };
@@ -21080,6 +21101,7 @@ ge.pluginName = "ServersPlugin", ge.apis = [
21080
21101
  "saveSvg",
21081
21102
  "saveImg",
21082
21103
  "getBase64",
21104
+ "getSVG",
21083
21105
  "clear",
21084
21106
  "preview",
21085
21107
  "staticPreview",
@@ -22067,7 +22089,7 @@ class ea extends br {
22067
22089
  return g ? super.off(r, g) : this;
22068
22090
  }
22069
22091
  }
22070
- _t.fabric.Rect = _t.fabric.util.createClass(_t.fabric.Rect, {
22092
+ mt.fabric.Rect = mt.fabric.util.createClass(mt.fabric.Rect, {
22071
22093
  type: "rect",
22072
22094
  initialize: function(f) {
22073
22095
  f || (f = {}), this.callSuper("initialize", f);
@@ -22077,11 +22099,11 @@ _t.fabric.Rect = _t.fabric.util.createClass(_t.fabric.Rect, {
22077
22099
  this.rx = 1 / this.scaleX * r, this.ry = 1 / this.scaleY * r, this.callSuper("_render", f);
22078
22100
  }
22079
22101
  });
22080
- _t.fabric.Rect.fromObject = function(f, r) {
22081
- return _t.fabric.Object._fromObject("Rect", f, r);
22102
+ mt.fabric.Rect.fromObject = function(f, r) {
22103
+ return mt.fabric.Object._fromObject("Rect", f, r);
22082
22104
  };
22083
- const ia = _t.fabric.Rect;
22084
- _t.fabric.Textbox = _t.fabric.util.createClass(_t.fabric.Textbox, {
22105
+ const ia = mt.fabric.Rect;
22106
+ mt.fabric.Textbox = mt.fabric.util.createClass(mt.fabric.Textbox, {
22085
22107
  type: "textbox",
22086
22108
  _renderChars: function(f, r, g, _, y, C) {
22087
22109
  var T = this.getHeightOfLine(C), c = this.textAlign.indexOf("justify") !== -1, i, l, a = "", t, n = 0, e, o = this.path, h = !c && this.charSpacing === 0 && this.isEmptyStyles(C) && !o, s = this.direction === "ltr", u = this.direction === "ltr" ? 1 : -1, d, m = r.canvas.getAttribute("dir");
@@ -22099,7 +22121,7 @@ _t.fabric.Textbox = _t.fabric.util.createClass(_t.fabric.Textbox, {
22099
22121
  return;
22100
22122
  }
22101
22123
  for (var p = 0, v = g.length - 1; p <= v; p++)
22102
- e = p === v || this.charSpacing || o, a += g[p], t = this.__charBounds[C][p], n === 0 ? (_ += u * (t.kernedWidth - t.width), n += t.width) : n += t.kernedWidth, c && !e && this._reSpaceAndTab.test(g[p]) && (e = !0), e || (i = i || this.getCompleteStyleDeclaration(C, p), l = this.getCompleteStyleDeclaration(C, p + 1), e = _t.fabric.util.hasStyleChanged(
22124
+ e = p === v || this.charSpacing || o, a += g[p], t = this.__charBounds[C][p], n === 0 ? (_ += u * (t.kernedWidth - t.width), n += t.width) : n += t.kernedWidth, c && !e && this._reSpaceAndTab.test(g[p]) && (e = !0), e || (i = i || this.getCompleteStyleDeclaration(C, p), l = this.getCompleteStyleDeclaration(C, p + 1), e = mt.fabric.util.hasStyleChanged(
22103
22125
  i,
22104
22126
  l,
22105
22127
  !1
@@ -22133,11 +22155,11 @@ _t.fabric.Textbox = _t.fabric.util.createClass(_t.fabric.Textbox, {
22133
22155
  }
22134
22156
  }
22135
22157
  });
22136
- _t.fabric.Textbox.fromObject = function(f, r) {
22158
+ mt.fabric.Textbox.fromObject = function(f, r) {
22137
22159
  const { text: g } = f;
22138
- return r(new _t.fabric.Textbox(g, f));
22160
+ return r(new mt.fabric.Textbox(g, f));
22139
22161
  };
22140
- const na = _t.fabric.Rect, ra = _t.fabric;
22162
+ const na = mt.fabric.Rect, ra = mt.fabric;
22141
22163
  export {
22142
22164
  ia as CustomRect,
22143
22165
  na as CustomTextbox,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hprint/core",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -33,7 +33,7 @@
33
33
  "hotkeys-js": "~3.8.9",
34
34
  "tapable": "~2.3.0",
35
35
  "uuid": "~8.3.2",
36
- "@hprint/shared": "0.0.6"
36
+ "@hprint/shared": "0.0.8"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "vite build",